DataColChanged事件代码:
Select Case e.DataCol.Name
Case "单位代码","上期结余资金","门诊金额","住院金额"
Dim dr As DataRow
Dim mr As DataRow = e.DataRow
Dim drs As List(of DataRow)
dr = e.DataTable.Find("[_SortKey] < " & mr("_SortKey") & " And [单位代码] = '" & mr("单位代码") & "'", "[_SortKey] Desc")
If dr Is Nothing Then
mr("上期结余资金") = mr("本期结余资金")
mr("本期结余资金") = mr("上期结余资金") - mr("门诊金额")- mr("住院金额")
dr = mr
End If
drs = e.DataTable.Select("[_SortKey] >= " & dr("_SortKey") & " And [单位代码] = '" & dr("单位代码") & "'", "[_SortKey]")
For i As Integer = 1 To drs.Count - 1
drs(i)("上期结余资金") = drs(i)("本期结余资金")
drs(i)("本期结余资金") = drs(i-1)("本期结余资金") + drs(i)("上期结余资金") - drs(i)("门诊金额")- drs(i)("住院金额")
Next
If e.DataCol.Name = "单位代码" AndAlso e.OldValue IsNot Nothing AndAlso e.OldValue <> e.NewValue Then
dr = e.DataTable.Find("[_SortKey] < " & mr("_SortKey") & " And [单位代码] = '" & e.OldValue & "'", "[_SortKey] Desc")
If dr Is Nothing Then
dr = e.DataTable.Find("[单位代码] = '" & e.OldValue & "'", "[_SortKey]")
If dr IsNot Nothing Then
dr("上期结余资金") = dr("本期结余资金")
dr("本期结余资金") = dr("上期结余资金") - dr("门诊金额")- dr("住院金额")
End If
End If
If dr IsNot Nothing Then
drs = e.DataTable.Select("[_SortKey] >= " & dr("_SortKey") & " And [单位代码] = '" & dr("单位代码") & "'", "[_SortKey]")
For i As Integer = 1 To drs.Count - 1
drs(i)("上期结余资金") = drs(i)("本期结余资金")
drs(i)("本期结余资金") = drs(i-1)("本期结余资金") + drs(i)("上期结余资金") - drs(i)("门诊金额")- drs(i)("住院金额")
Next
End If
End If
End Select
表事件DataRowDeleting的代码:
e.DataRow("本期结余资金") = 0
e.DataRow("门诊金额") = 0
e.DataRow("住院金额") = 0
表事件AfterMoveRow的代码:
Dim Key As Decimal
Dim Index As Integer
Dim Filter As String
Dim r As Row
Index = Math.Min(e.OldIndex, e.NewIndex)
Key = e.Table.Rows(Index)("_SortKey")
r = e.Table.Rows(e.NewIndex)
Filter = "[_SortKey] >= " & Key & " And [单位代码] = '" & r("单位代码") & "'"
e.Table.DataTable.DataCols("上期结余资金").RaiseDataColChanged(Filter)