以文本方式查看主题

-  Foxtable(狐表)  (http://foxtable.net/bbs/index.asp)
--  专家坐堂  (http://foxtable.net/bbs/list.asp?boardid=2)
----  同表,根据双列(品名和型号规格两列)累计数量  (http://foxtable.net/bbs/dispbbs.asp?boardid=2&id=93606)

--  作者:xh2207
--  发布时间:2016/12/2 10:32:00
--  同表,根据双列(品名和型号规格两列)累计数量
品名 型号规格 数量 本品名累计数量
AAa   2 2
BBb   2 2
AAa   2 4
BBb   10 12

的代码如下:

datacolchanged

 

Select Case e.DataCol.Name
    Case "品名", "数量"
        Dim drs As List(of DataRow)
        Dim Filter As String
        Filter = "[_SortKey] >= " & e.DataRow("_SortKey") & " And [品名] = \'" & e.DataRow("品名") & "\'"
        drs = e.DataTable.Select(Filter)
        For Each dr As DataRow In drs
            Filter = "[_SortKey] <= " & dr("_SortKey") & " And [品名] = \'" & dr("品名") & "\'"
            Dim Val1 As Double = e.DataTable.Compute("Sum(数量)",Filter)
            dr("本品名型号规格累计") = Val1
        Next
        If e.DataCol.Name = "品名" AndAlso e.OldValue IsNot Nothing AndAlso e.OldValue <> e.NewValue Then
            Filter = "[_SortKey] > " & e.DataRow("_SortKey") & " And [品名] = \'" & e.OldValue & "\'"
            drs = e.DataTable.Select(Filter)
            For Each dr As DataRow In drs
                Filter = "[_SortKey] <= " & dr("_SortKey") & " And [品名] = \'" & dr("品名") & "\'"
                Dim Val1 As Double = e.DataTable.Compute("Sum(数量)",Filter)
                dr("本品名型号规格累计") = Val1
            Next
        End If
End Select

 

请问:根据品名和型号规格累计数量(即同品名和型号数量累加)的代码如何修改?谢谢!

要求的效果如下表:

品名 型号规格 数量 本品名累计数量 说明
AAa XX 2 2  
BBb HH 2 2  
AAa XX 2 4 第1行+第3行同品名规格累加
BBb HH 5 5 第2行+第4行同品名规格累加
AAa YY 2 2  
BBb GG 2 2  
AAa YY 4 6 第5行+第7行同品名规格累加
BBb GG 10 15 第6行+第8行同品名规格累加

 

 

 


--  作者:有点蓝
--  发布时间:2016/12/2 10:52:00
--  
试试

Select Case e.DataCol.Name
    Case "品名","型号规格", "数量"
        Dim drs As List(of DataRow)
        Dim Filter As String
        Filter = "[_SortKey] >= " & e.DataRow("_SortKey") & " And [品名] = \'" & e.DataRow("品名") & "\' and 型号规格 = \'" & e.DataRow("型号规格") & "\'"
        drs = e.DataTable.Select(Filter)
        For Each dr As DataRow In drs
            Filter = "[_SortKey] <= " & dr("_SortKey") & " And [品名] = \'" & dr("品名") & "\' and 型号规格 = \'" & dr("型号规格") & "\'"
            Dim Val1 As Double = e.DataTable.Compute("Sum(数量)",Filter)
            dr("本品名型号规格累计") = Val1
        Next
        Filter = ""
        If e.DataCol.Name = "品名" AndAlso e.OldValue IsNot Nothing  Then
            Filter = "[_SortKey] > " & e.DataRow("_SortKey") & " And [品名] = \'" & e.OldValue & "\' and 型号规格 = \'" & e.DataRow("型号规格") & "\'"
        ElseIf e.DataCol.Name = "型号规格" AndAlso e.OldValue IsNot Nothing  Then
            Filter = "[_SortKey] > " & e.DataRow("_SortKey") & " And [品名] = \'" & e.DataRow("品名") & "\' and 型号规格 = \'" & e.OldValue & "\'"
        End If
        If Filter > "" Then
            drs = e.DataTable.Select(Filter)
            For Each dr As DataRow In drs
                Filter = "[_SortKey] <= " & dr("_SortKey") & " And [品名] = \'" & dr("品名") & "\'and 型号规格 = \'" & dr("型号规格") & "\'"
                Dim Val1 As Double = e.DataTable.Compute("Sum(数量)",Filter)
                dr("本品名型号规格累计") = Val1
            Next
        End If
End Select

--  作者:xh2207
--  发布时间:2016/12/2 12:01:00
--  

行,谢谢了!