以文本方式查看主题

-  Foxtable(狐表)  (http://foxtable.net/bbs/index.asp)
--  专家坐堂  (http://foxtable.net/bbs/list.asp?boardid=2)
----  [求助]自定义汇总模式  (http://foxtable.net/bbs/dispbbs.asp?boardid=2&id=113268)

--  作者:狐说八道
--  发布时间:2018/1/12 10:45:00
--  [求助]自定义汇总模式
老师,请问在帮助的自定义汇总模式中,如果我的分组列有三列(例如:产品,客户,雇员),下面这段代码该怎么改呢??

Dim r As Row
For
i As Integer = 0 To t.Rows.Count(True) - 1
    r = t.Rows(i,True)
    If
r.IsGroup \'如果是分组行
        Dim
f As String = "产品 = \'" & r("产品") &
"\'"
       
Dim v As String = " 订单数:" & t.Compute("Count(日期)",f)
        v = v & " 订购数量:" & t.Compute("Sum(数量)",f)
        v = v & " 订购金额:" & t.Compute("Sum(金额)",f)
        r("产品") = "产品:" & r("产品") & v
    End
If
Next


需要的效果是,如果是统计汇总第三级时,将前两级的名称补上,如果是统计汇总第二级时,将前一级的名称不上,例如:


PD01 - CS01 - EP01:  订单数量:100

PD01 - CS01 - EP02: 订单数量:100

PD01 - CS01:  订单数量:200


PD01 - CS02 - EP01:  订单数量:100

PD01 - CS02 - EP02: 订单数量:100

PD01 - CS02:  订单数量:200


PD01:  订单数量:400



--  作者:有点甜
--  发布时间:2018/1/12 11:09:00
--  

Dim t As Table = Tables("订单")
Dim g As Subtotalgroup
t.SubtotalGroups.Clear()
t.GroupAboveData = False
t.TreeVisible = False
g = New Subtotalgroup
g.Aggregate = AggregateEnum.Sum
g.GroupOn = "雇员"
g.Caption = "{0}"
t.SubtotalGroups.Add(g)
g = New Subtotalgroup
g.Aggregate = AggregateEnum.Sum
g.GroupOn = "客户"
g.Caption = "{0}"
t.SubtotalGroups.Add(g)
g = New Subtotalgroup
g.Aggregate = AggregateEnum.Sum
g.GroupOn = "产品"
g.Caption = "{0}"
t.SubtotalGroups.Add(g)
t.Subtotal()

Dim r As Row
For i As Integer = 0 To t.Rows.Count(True) - 1
    r = t.Rows(i,True)
    If r.IsGroup \'如果是分组行
        If r.Level = 0 Then
            Dim f As String = "产品 = \'" & r("产品") & "\'"
            Dim v As String = " 订单数:" & t.Compute("Count(日期)",f)
            v = v & " 订购数量:" & t.Compute("Sum(数量)",f)
            v = v & " 订购金额:" & t.Compute("Sum(金额)",f)
            r("产品") = r("产品") & ":" & v
        ElseIf r.Level = 1 Then
            Dim pr As Row = t.Rows(r.Index-2, True)
            Dim f As String = "产品 = \'" & pr("产品") & "\' and 客户 = \'" & pr("客户") & "\'"
            Dim v As String = " 订单数:" & t.Compute("Count(日期)",f)
            v = v & " 订购数量:" & t.Compute("Sum(数量)",f)
            v = v & " 订购金额:" & t.Compute("Sum(金额)",f)
            r("产品") = pr("产品") & "-" & pr("客户") & ":" & v
        ElseIf r.Level = 2 Then
            Dim pr As Row = t.Rows(r.Index-1, True)
            Dim f As String = "产品 = \'" & pr("产品") & "\' and 客户 = \'" & pr("客户") & "\' and 雇员 = \'" & pr("雇员") & "\'"
            Dim v As String = " 订单数:" & t.Compute("Count(日期)",f)
            v = v & " 订购数量:" & t.Compute("Sum(数量)",f)
            v = v & " 订购金额:" & t.Compute("Sum(金额)",f)
            r("产品") = pr("产品") & "-" & pr("客户") & "-" & pr("雇员") & ":" & v
        End If
    End If
Next


--  作者:狐说八道
--  发布时间:2018/1/12 11:46:00
--  
好的,谢谢有点甜老师