Select Case e.DataCol.Name
Case "固定额度","临时额度"
e.DataRow("额度")=e.DataRow("固定额度")+e.DataRow("临时额度")
Case "余额"
If e.DataRow("银行卡类别")="信用卡" Then
If e.DataRow("可用额度")<0 Then
MessageBox.Show("当前透支" & e.DataRow("可用额度") & "元")
End If
End If
Case "收入","支出","银行卡卡号","额度"
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("收入") - 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-1)("余额") + drs(i)("收入") - drs(i)("支出")
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("[_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
drs(i)("余额") = drs(i-1)("余额") + drs(i)("收入") - drs(i)("支出")
drs(i)("可用额度") = drs(i-1)("可用额度") + drs(i)("收入") - drs(i)("支出")
Next
End If
End If
End Select
End Select