-- 作者:denghui69986
-- 发布时间:2023/5/11 18:03:00
-- 累计统计
表上按两列,生产批号,工序名称,求和累计工序名称上的“生产数量”不知那里不对,老师帮忙看看,谢谢
代码下面这样,
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("生产批号") & "\' and [工序名称] = \'" & mr("工序名称") & "\'", "[_SortKey] Desc") If dr Is Nothing Then mr("累计数量") = mr("生产数量") dr = mr End If drs = e.DataTable.Select("[_SortKey] >= " & dr("_SortKey") & " And [生产批号] = \'" & dr("生产批号") & "\' and [工序名称] = \'" & mr("工序名称") & "\'", "[_SortKey]") For i As Integer = 1 To drs.Count - 1 drs(i)("累计数量") = drs(i - 1)("结余累计") drs(i)("累计数量") = e.DataTable.Compute("sum(生产数量)", "[_SortKey] <= " & drs(i)("_SortKey") & " And [生产批号] = \'" & dr("生产批号") & "\' and [工序名称] = \'" & mr("工序名称") & "\'") 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 & "\' and [工序名称] = \'" & mr("工序名称") & "\'", "[_SortKey] Desc") If dr Is Nothing Then dr = e.DataTable.Find("[生产批号] = \'" & e.OldValue & "\' and [工序名称] = \'" & mr("工序名称") & "\'", "[_SortKey]") If dr IsNot Nothing Then dr("累计数量") = dr("生产数量") End If End If
此主题相关图片如下:截图123.png
|
-- 作者:denghui69986
-- 发布时间:2023/5/12 18:00:00
--
把这代码放进我上面发的测试里面
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("生产批号") & "\' and [工序名称] = \'" & mr("工序名称") & "\'", "[_SortKey] Desc") If dr Is Nothing Then mr("累计数量") = mr("生产数量") dr = mr End If drs = e.DataTable.Select("[_SortKey] >= " & dr("_SortKey") & " And [生产批号] = \'" & dr("生产批号") & "\' and [工序名称] = \'" & mr("工序名称") & "\'", "[_SortKey]") For i As Integer = 1 To drs.Count - 1 drs(i)("累计数量") = drs(i - 1)("累计数量") + drs(i)("生产数量") drs(i)("累计数量") = e.DataTable.Compute("sum(生产数量)", "[_SortKey] <= " & drs(i)("_SortKey") & " And [生产批号] = \'" & dr("生产批号") & "\' and [工序名称] = \'" & mr("工序名称") & "\'") 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 & "\' and [工序名称] = \'" & mr("工序名称") & "\'", "[_SortKey] Desc") If dr Is Nothing Then dr = e.DataTable.Find("[生产批号] = \'" & e.OldValue & "\' and [工序名称] = \'" & mr("工序名称") & "\'", "[_SortKey]") If dr IsNot Nothing Then dr("累计数量") = dr("生产数量") End If End If If dr IsNot Nothing Then drs = e.DataTable.Select("[_SortKey] >= " & dr("_SortKey") & " And [生产批号] = \'" & dr("生产批号") & "\' and [工序名称] = \'" & mr("工序名称") & "\'", "[_SortKey]") For i As Integer = 1 To drs.Count - 1 drs(i)("累计数量") = drs(i - 1)("累计数量") + drs(i)("生产数量") drs(i)("累计数量") = e.DataTable.Compute("sum(生产数量)", "[_SortKey] <= " & drs(i)("_SortKey") & " And [生产批号] = \'" & dr("生产批号") & "\' and [工序名称] = \'" & mr("工序名称") & "\'") Next End If End If 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 & "\' and [生产批号] = \'" & mr("生产批号") & "\'", "[_SortKey] Desc") If dr Is Nothing Then dr = e.DataTable.Find("[工序名称] = \'" & e.OldValue & "\' and [生产批号] = \'" & mr("生产批号") & "\'", "[_SortKey]") If dr IsNot Nothing Then dr("累计数量") = dr("生产数量") End If End If If dr IsNot Nothing Then drs = e.DataTable.Select("[_SortKey] >= " & dr("_SortKey") & " And [工序名称] = \'" & dr("工序名称") & "\' and [生产批号] = \'" & mr("生产批号") & "\'", "[_SortKey]") For i As Integer = 1 To drs.Count - 1 drs(i)("累计数量") = drs(i - 1)("累计数量") + drs(i)("生产数量") drs(i)("累计数量") = e.DataTable.Compute("sum(生产数量)", "[_SortKey] <= " & drs(i)("_SortKey") & " And [工序名称] = \'" & dr("工序名称") & "\' and [生产批号] = \'" & mr("生产批号") & "\'") Next End If End If End Select
If e.DataCol.Name = "累计数量" OrElse e.DataCol.Name = "订单数量" OrElse e.DataCol.Name = "累计数量"Then If (e.DataRow("累计数量")) > e.DataRow("订单数量") Then messagebox.show("注意:你输入生产数量已经超出订单数值!!!!") End If End If
|