以文本方式查看主题

-  Foxtable(狐表)  (http://foxtable.com/bbs/index.asp)
--  专家坐堂  (http://foxtable.com/bbs/list.asp?boardid=2)
----  [求助]统计结果有错  (http://foxtable.com/bbs/dispbbs.asp?boardid=2&id=79521)

--  作者:huhu
--  发布时间:2016/1/4 10:57:00
--  [求助]统计结果有错
If e.DataCol.name = "入库单号" Then
    If e.DataRow.GetChildRows("预入库单").Count = 0 Then
        Dim ddr As DataRow = DataTables("预入库单").Find ("预入库单号 = \'" & e.DataRow("入库单号") & "\' and 行号 = \'" & e.DataRow("行号") & "\'")
        If ddr IsNot Nothing Then
            If ddr("预入库单号") = e.DataRow("入库单号")
                Dim sum As Integer
                sum = DataTables("工单明细").Compute("sum(预入库数量)","入库单号 = \'" & ddr("预入库单号") & "\' and 行号 = \'" & e.DataRow("行号") & "\'")
                ddr("总数量") = sum
            End If
        Else
            Dim dr As DataRow = DataTables("预入库单").AddNew()
            dr("预入库单号") = e.DataRow("入库单号")
            dr("总数量") = e.DataRow("预入库数量")
            dr("行号") = e.DataRow("行号")
        End If
    End If
End If

请问这段代码哪里有错?怎么在预入库单统计的总数量与工单明细的预入库数量不相等呢?

--  作者:大红袍
--  发布时间:2016/1/4 11:01:00
--  

这句代码去掉

 

If e.DataRow.GetChildRows("预入库单").Count = 0 Then


--  作者:huhu
--  发布时间:2016/1/4 12:02:00
--  
DataTables("工单明细").save
If e.DataCol.name = "入库单号" Then
    Dim ddr As DataRow = DataTables("预入库单").Find ("预入库单号 = \'" & e.DataRow("入库单号") & "\' and 行号 = \'" & e.DataRow("行号") & "\'")
    If ddr IsNot Nothing Then
        If ddr("预入库单号") = e.DataRow("入库单号")
            Dim sum As Integer
            sum = DataTables("工单明细").Compute("sum(预入库数量)","入库单号 = \'" & ddr("预入库单号") & "\' and 行号 = \'" & e.DataRow("行号") & "\'")
            ddr("总数量") = sum
        End If
    Else
        Dim dr As DataRow = DataTables("预入库单").AddNew()
        dr("预入库单号") = e.DataRow("入库单号")
        dr("行号") = e.DataRow("行号")
        dr("总数量") = DataTables("工单明细").Compute("sum(预入库数量)","入库单号 = \'" & dr("预入库单号") & "\' and 行号 = \'" & dr("行号") & "\'")
    End If
End If

怎么统计的结果还不正确。总数量每次都是1.没有进行求和统计。

--  作者:大红袍
--  发布时间:2016/1/4 12:04:00
--  

1、重置列;

 

2、做个例子上来测试,别人看不懂你的逻辑。