请教老师:下图流水账代码
统计“一次烘焙”的材料没问题,根据代码可实现“烘焙余量”的自动计算
现在增加了“二次烘焙”材料,二次烘焙的材料数量是从“烘焙余量”结转的,但填写烘焙数量后,上一行一次烘焙“烘焙余量”要相应减少,也就是上一行一次烘焙“烘焙余量”是下面一行二次烘焙的库存
代码要怎么修改?
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("退回数量_根")
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)("退回数量_根")
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("退回数量_根")
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)("退回数量_根")
Next
End If
End If
End Select
[此贴子已经被作者于2023/4/12 15:57:52编辑过]