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("毛需求")
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)("毛需求")
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)("毛需求")
Next
End If
End If
End Select
此主题相关图片如下:c2b192ae-8fe0-4a93-83d6-3fb60bd0897b.png