这段代码在以前的项目中可以正常运行,移植到新项目后有问题,分析了半天还是没搞定。
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("[日] < " & mr("日") & " And [物料] = '" & mr("物料") & "'", "[日]")
If dr Is Nothing Then
mr("库存_数量") = mr("入仓_数量") - mr("出仓_数量")
'mr("库存_金额") = mr("入仓_金额") - mr("出仓_金额")
dr = mr
End If
drs = e.DataTable.Select("[日] >= " & dr("日") & " And [物料] = '" & dr("物料") & "'", "[日]")
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("[日] < " & mr("日") & " And [物料] = '" & e.OldValue & "'", "[日]")
If dr Is Nothing Then
dr = e.DataTable.Find("[物料] = '" & e.OldValue & "'", "[日]")
If dr IsNot Nothing Then
dr("库存_数量") = dr("入仓_数量") - dr("出仓_数量")
'dr("库存_金额") = dr("入仓_金额") - dr("出仓_金额")
End If
End If
If dr IsNot Nothing Then
drs = e.DataTable.Select("[日] >= " & dr("日") & " And [物料] = '" & dr("物料") & "'", "[日]")
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
此主题相关图片如下:snap1.jpg