Select Case e.DataCol.Name
Case "编号","存入","取出"
Dim dr As DataRow
Dim mr As DataRow = e.DataRow
Dim drs As List(of DataRow)
Dim jk As Integer
Dim ck As Integer
dr = e.DataTable.Find("[_SortKey] < " & mr("_SortKey") & " And [编号] = '" &
mr("编号") &
"'", "[_SortKey]
Desc")
If dr Is Nothing Then '如果是第一行,计算结存
jk = DataTables("表A").SQLCompute("Sum(存入)","[_SortKey]
< " & mr("_SortKey")
& " And 编号 = '" &
mr("编号") &
"'")
ck = DataTables("表A").SQLCompute("Sum(取出)","[_SortKey]
< " & mr("_SortKey")
& " And 编号 = '" &
mr("编号") &
"'")
mr("结存") = e.DataRow("存入") - e.DataRow("取出") + jk
- ck
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)("取出")
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 '如果找到,计算结存
jk =
DataTables("表A").SQLCompute("Sum(存入)","[_SortKey]
< " & mr("_SortKey")
& " And 编号 = '" &
e.OldValue & "'")
ck =
DataTables("表A").SQLCompute("Sum(取出)","[_SortKey]
< " & mr("_SortKey")
& " And 编号 = '" &
e.OldValue & "'")
dr("结存") = dr("存入")
- dr("取出") + jk
- ck
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)("取出")
Next
End If
End If
End Select
DataColChanged的流水账代码 如何转换成按钮形式 点击按钮后计算一次结存