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("[日期] < #" & mr("日期") & "# And [科目] = '" & mr("科目") & "'", "日期 desc, 制单时间 desc")
If dr Is Nothing Then
mr("余额") = mr("增") - mr("减")
dr = mr
End If
drs = e.DataTable.Select("[日期] >= #" & dr("日期") & "# And [科目] = '" & dr("科目") & "'", "[日期], 制单时间")
For i As Integer = 1 To drs.Count - 1
drs(i)("余额") = drs(i-1)("余额") + drs(i)("增") - drs(i)("减")
Next
If e.DataCol.Name = "科目" AndAlso e.OldValue IsNot Nothing AndAlso e.OldValue <> e.NewValue Then
dr = e.DataTable.Find("[日期] <= #" & mr("日期") & "# And [科目] = '" & e.OldValue & "'", "日期 desc , 制单时间 desc ")
If dr Is Nothing Then
dr = e.DataTable.Find("[科目] = '" & e.OldValue & "'", "[日期] desc, 制单时间 desc")
If dr IsNot Nothing Then
dr("余额") = dr("增") - dr("减")
End If
End If
If dr IsNot Nothing Then
drs = e.DataTable.Select("[日期] >= #" & dr("日期") & "# And [科目] = '" & dr("科目") & "'", "日期, 制单时间")
For i As Integer = 1 To drs.Count - 1
drs(i)("余额") = drs(i-1)("余额") + drs(i)("增") - drs(i)("减")
Next
End If
End If
Case "日期"
If e.OldValue IsNot Nothing AndAlso e.OldValue <> e.NewValue Then
Dim dr As DataRow
Dim mr As DataRow = e.DataRow
Dim drs As List(of DataRow)
Dim d As Date = e.OldValue
If e.OldValue > e.NewValue Then d = e.NewValue
dr = e.DataTable.Find("[日期] < #" & d & "# And [科目] = '" & mr("科目") & "'", "日期 desc , 制单时间 desc ")
If dr Is Nothing Then
dr = e.DataTable.Find("[科目] = '" & mr("科目") & "'", "[日期], 制单时间")
If dr IsNot Nothing Then
dr("余额") = dr("增") - dr("减")
End If
End If
If dr IsNot Nothing Then
drs = e.DataTable.Select("[日期] >= #" & dr("日期") & "# And [科目] = '" & dr("科目") & "'", "日期, 制单时间")
For i As Integer = 1 To drs.Count - 1
drs(i)("余额") = drs(i-1)("余额") + drs(i)("增") - drs(i)("减")
Next
End If
End If
End Select