关于高效的流水帐设计,如果计算时考虑到到有未加载的数据时,应该如何处理?
我用如下这样的代码,发现不行,请问应该要如何做才可以呢?求大家帮忙看看。
Dim dr1 As DataRow
Dim mr As DataRow = e.DataRow
Dim drs As List(of DataRow)
If mr.IsNull("盘点数") = False Then
mr("物料需求结存数量") = mr("盘点数")+ mr("物料进货数量") - mr("物料需求数量")
dr1 = mr
Else
dr1 = e.DataTable.SQLFind("[_SortKey] < " & mr("_SortKey") & " And [材料编码] = '" & mr("材料编码") & "'", "[_SortKey] Desc")
If dr1 Is Nothing Then
mr("物料需求结存数量") = mr("物料进货数量") - mr("物料需求数量")
dr1 = mr
End If
End If
drs = e.DataTable.SQLSelect("[_SortKey] >= " & dr1("_SortKey") & " And [材料编码] = '" & dr1("材料编码") & "'", "[_SortKey]")
For i As Integer = 1 To drs.Count - 1
drs(i)("物料需求结存数量") = drs(i-1)("物料需求结存数量") + drs(i)("物料进货数量") - drs(i)("物料需求数量")
Next
e.DataTable.SQLUpdate(drs)
e.DataTable.Load
If e.DataCol.Name = "材料编码" AndAlso e.OldValue IsNot Nothing AndAlso e.OldValue <> e.NewValue Then
dr1 = e.DataTable.SQLFind("[_SortKey] < " & mr("_SortKey") & " And [材料编码] = '" & e.OldValue & "'", "[_SortKey] Desc")
If dr1 Is Nothing Then
dr1 = e.DataTable.SQLFind("[材料编码] = '" & e.OldValue & "'", "[_SortKey]")
If dr1 IsNot Nothing And dr1.IsNull("盘点数") = False Then
dr1("物料需求结存数量") = dr1("盘点数") + dr1("物料进货数量") - dr1("物料需求数量")
ElseIf dr1 IsNot Nothing And dr1.IsNull("盘点数") = True Then
dr1("物料需求结存数量") = dr1("物料进货数量") - dr1("物料需求数量")
End If
End If
If dr1 IsNot Nothing Then
drs = e.DataTable.SQLSelect("[_SortKey] >= " & dr1("_SortKey") & " And [材料编码] = '" & dr1("材料编码") & "'", "[_SortKey]")
For i As Integer = 1 To drs.Count - 1
drs(i)("物料需求结存数量") = drs(i-1)("物料需求结存数量") + drs(i)("物料进货数量") - drs(i)("物料需求数量")
Next
e.DataTable.SQLUpdate(drs)
e.DataTable.Load
End If
End If