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("出库件数")
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("出库数量")
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
库存表里这段代码执行后当记录里面当保存后再修改数量,库存数量就发生错误,他不再累加之前面数量.
请老师指教出什么问题