Select Case e.DataCol.Name
Case "账户", "借", "贷"
Dim drs As List(Of DataRow)
Dim Filter As String
Filter = "[_SortKey] >= " & e.DataRow("_SortKey") & " And [账户] = '" & e.DataRow("账户") & "'"
drs = e.DataTable.Select(Filter)
For Each dr As DataRow In drs
Filter = "[_SortKey] <= " & dr("_SortKey") & " And [账户] = '" & dr("账户") & "'"
Dim Val1 As Double = e.DataTable.Compute("Sum(借)", Filter)
Dim Val2 As Double = e.DataTable.Compute("Sum(贷)", Filter)
dt = DataTables("各种账户的名称").AddNew()
dr("余额") = Val1 - Val2
Next
Dim dt As DataRow = DataTables("各种账户的名称").Find("账户= '" & e.DataRow("账户") & "'")
If dt Is Nothing Then
dt = DataTables("各种账户的名称").AddNew()
dt("账户") = e.DataRow("账户")
End If
Dim dr2 As DataRow = e.DataTable.find("账户= '" & e.DataRow("账户") & "'", "[_SortKey] desc")
dt("余额") = dr2("余额")
If e.DataCol.Name = "账户" AndAlso e.OldValue IsNot Nothing AndAlso e.OldValue <> e.NewValue Then
Filter = "[_SortKey] > " & e.DataRow("_SortKey") & " And [账户] = '" & e.OldValue & "'"
drs = e.DataTable.Select(Filter)
For Each dr As DataRow In drs
Filter = "[_SortKey] <= " & dr("_SortKey") & " And [账户] = '" & dr("账户借") & "'"
Dim Val1 As Double = e.DataTable.Compute("Sum(借)", Filter)
Dim Val2 As Double = e.DataTable.Compute("Sum(贷)", Filter)
dt = DataTables("各种账户的名称").AddNew()
dr("余额") = Val1 - Val2
dt("余额") = dr("余额")
Next
dt = DataTables("各种账户的名称").Find("账户= '" & e.OldValue & "'")
If dt Is Nothing Then
dt = DataTables("各种账户的名称").AddNew()
dt("账户") = e.OldValue
End If
dr2 = e.DataTable.find("账户= '" & e.OldValue & "'", "[_SortKey] desc")
dt("余额") = dr2("余额")
End If
End Select