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("数量")
dr = mr
End If
drs = e.DataTable.Select("[_SortKey] >= " & dr("_SortKey") & " And [型号] = '" & dr("型号") & "'", "[_SortKey]")
For i As Integer = 1 To drs.Count - 1
If drs(i)("状态") = "借方" Then
drs(i)("余额") = drs(i-1)("余额") + drs(i)("价格") * drs(i)("数量")
Else
drs(i)("余额") = drs(i-1)("余额") - drs(i)("价格") * drs(i)("数量")
End If
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("数量")
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
If drs(i)("状态") = "借方" Then
drs(i)("余额") = drs(i-1)("余额") + drs(i)("价格") * drs(i)("数量")
Else
drs(i)("余额") = drs(i-1)("余额") - drs(i)("价格") * drs(i)("数量")
End If
Next
End If
End If
End Select