以文本方式查看主题

-  Foxtable(狐表)  (http://foxtable.net/bbs/index.asp)
--  专家坐堂  (http://foxtable.net/bbs/list.asp?boardid=2)
----  累计统计  (http://foxtable.net/bbs/dispbbs.asp?boardid=2&id=186551)

--  作者: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
图片点击可在新窗口打开查看

--  作者:有点蓝
--  发布时间:2023/5/11 20:21:00
--  
已有数据重置一下列。代码执行什么地方有问题?
--  作者:denghui69986
--  发布时间:2023/5/12 7:28:00
--  
老师帮忙看看那里问题,谢谢
 下载信息  [文件大小:   下载次数: ]
图片点击可在新窗口打开查看点击浏览该文件:desktop.zip


--  作者:有点蓝
--  发布时间:2023/5/12 8:44:00
--  
项目没有任何代码呀
--  作者:denghui69986
--  发布时间:2023/5/12 8:49:00
--  

就是一楼那代码

 


--  作者:有点蓝
--  发布时间:2023/5/12 8:51:00
--  
1楼代码不完整,请重新发。既然做了例子,应该把代码放入例子,至少保证例子拿来就可以测试,并且自己测试过这个例子确实有同样的问题
[此贴子已经被作者于2023/5/12 8:54:18编辑过]

--  作者:denghui69986
--  发布时间:2023/5/12 9:14:00
--  
谢谢,现在找到方法了
--  作者:hbfnmxb
--  发布时间:2023/5/12 17:04:00
--  
如何解决,分享一下,学习学习
--  作者: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


--  作者:hbfnmxb
--  发布时间:2023/5/12 18:38:00
--  
放到“测试”里面的什么位置?谢谢请指教
看了一下,没找到订单数量列

[此贴子已经被作者于2023/5/12 18:43:11编辑过]