以文本方式查看主题

-  Foxtable(狐表)  (http://foxtable.net/bbs/index.asp)
--  专家坐堂  (http://foxtable.net/bbs/list.asp?boardid=2)
----  请教老师纠正  (http://foxtable.net/bbs/dispbbs.asp?boardid=2&id=126587)

--  作者:xusuyang
--  发布时间:2018/10/24 19:06:00
--  请教老师纠正
  老师:我设计了一个“仓库动态库”表。其中包含"配件信息_配件编码"、"出入库信息_入库数量"、"出入库信息_出库数量"、"库存结余"

请问老师:1、在"配件信息_配件编码"列中当【配件编码】一致时,当在我第一行"出入库信息_入库数量"输入如2000时,在第一行的"库存结余"会显示2000;当在我第二行在"出入库信息_入库数量"输入如1800时,在第二行的"库存结余"会显示3800;此时,当我删除第一行"出入库信息_入库数量"输入如2000时,第一行的"库存结余"仍然显示2000;当在我第二行在"出入库信息_出库数量"输入如500时,第二行的"库存结余"显示是3300;请问如何实现:A、当我删除第一行"出入库信息_入库数量"输入如2000时,第一行的"库存结余"显示为“0”? B、当在我第二行在"出入库信息_出库数量"输入如500时,第二行的"库存结余"显示为“1300”?

原有代码:

Select Case e.DataCol.Name

    Case  "配件信息_配件编码","出入库信息_入库数量","出入库信息_出库数量"

        Dim drs  As  List(of DataRow)

        Dim Filter As String

        Filter =  "[_Identify] >= " & e.DataRow("_Identify") & " And [配件信息_配件编码] = \'" & e.DataRow("配件信息_配件编码") & "\'"

        drs = e.DataTable.Select(Filter)

        For Each dr As  DataRow  In drs

            Filter =  "[_Identify] <= " & dr("_Identify") & " And [配件信息_配件编码] = \'" & dr("配件信息_配件编码") & "\'"

            Dim Val1 As Double = e.DataTable.Compute("Sum(出入库信息_入库数量)",Filter)

            Dim Val2 As Double = e.DataTable.Compute("Sum(出入库信息_出库数量)",Filter)

            Dim Val3 As Double = e.DataTable.Compute("Sum(库存结余)",Filter & " And 出入库信息_入库数量 Is null And 出入库信息_出库数量 Is null")

            dr("库存结余") = Val1 - Val2 + val3

        Next

        If e.DataCol.Name = "配件信息_配件编码" AndAlso e.OldValue IsNot Nothing AndAlso e.OldValue <> e.NewValue  Then

            Filter =  "[_Identify] > " & e.DataRow("_Identify") & " And [配件信息_配件编码] = \'" & e.OldValue &  "\'"

            drs = e.DataTable.Select(Filter)

            For Each dr As  DataRow  In drs

                Filter =  "[_Identify] <= " & dr("_Identify") & " And [配件信息_配件编码] = \'" & dr("配件信息_配件编码") & "\'"

                Dim Val1 As Double = e.DataTable.Compute("Sum(出入库信息_入库数量)",Filter)

                Dim Val2 As Double = e.DataTable.Compute("Sum(出入库信息_出库数量)",Filter)

                Dim Val3 As Double = e.DataTable.Compute("Sum(库存结余)",Filter & " And 出入库信息_入库数量 Is null And 出入库信息_出库数量 Is null")

                dr("库存结余") = Val1 - Val2 + val3

            Next

        End If

    End  Select
请问上述代码如何修改能实现?或重新的代码如何写?

谢谢!!
--  作者:有点甜
--  发布时间:2018/10/24 19:13:00
--  

        For Each dr As  DataRow  In drs

            Filter =  "[_Identify] <= " & dr("_Identify") & " And [配件信息_配件编码] = \'" & dr("配件信息_配件编码") & "\'"

            Dim Val1 As Double = e.DataTable.Compute("Sum(出入库信息_入库数量)",Filter)

            Dim Val2 As Double = e.DataTable.Compute("Sum(出入库信息_出库数量)",Filter)

            Dim Val3 As Double = e.DataTable.Compute("Sum(库存结余)",Filter & " And 出入库信息_入库数量 Is null And 出入库信息_出库数量 Is null")

            dr("库存结余") = Val1 - Val2 + val3

        Next

 

改成

 

        For Each dr As  DataRow  In drs

            Filter =  "[_Identify] <= " & dr("_Identify") & " And [配件信息_配件编码] = \'" & dr("配件信息_配件编码") & "\'"

            Dim Val1 As Double = e.DataTable.Compute("Sum(出入库信息_入库数量)",Filter)

            Dim Val2 As Double = e.DataTable.Compute("Sum(出入库信息_出库数量)",Filter)

            dr("库存结余") = Val1 - Val2

        Next