如图片,如果加多一个产品ID,这段该怎么修改呢?
此主题相关图片如下:流水账.png
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("例子二").SQLCompute("Sum(入库)","[_SortKey] < " & mr("_SortKey") & " And 产品 = '" & mr("产品") & "'")
ck = DataTables("例子二").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("例子二").SQLCompute("Sum(入库)","[_SortKey] < " & mr("_SortKey") & " And 产品 = '" & e.OldValue & "'")
ck = DataTables("例子二").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