以文本方式查看主题

-  Foxtable(狐表)  (http://foxtable.net/bbs/index.asp)
--  专家坐堂  (http://foxtable.net/bbs/list.asp?boardid=2)
----  [求助]统计表出现重列  (http://foxtable.net/bbs/dispbbs.asp?boardid=2&id=107940)

--  作者:李连山
--  发布时间:2017/10/13 8:19:00
--  [求助]统计表出现重列

老师,因被统计字段取值不确定,设计一个通用统计,代码如下:

Dim dt As DataTable
dt = DataTables("ysd")
Dim bb As String = "金额" \' 指要统计的数量?金额
Dim bfl As String = "采购方式" \' 指要在表头分类统计的字段
Dim btj As String = "管理部门" \' 指要列表分类统计的项目

\'通用统计
Dim i As Integer = 0
Dim Pr1 As List(Of String)
Dim dt0 As fxDataSource
Dim dt1 As fxDataSource
Dim bd0 As New GroupTableBuilder("统计表1",dt)
Dim bd1 As New GroupTableBuilder("统计表1",dt)
Pr1 = Dt.GetValues(bfl)
For Each r As String In Pr1
    If r <> Nothing
        If i = 0
            bd0.Filter =  bfl & " = \'" & r & "\' "
            bd0.Groups.AddDef(btj)
            bd0.Totals.AddDef(bb,r)
            dt0 = bd0.BuildDataSource()
            i = i + 1
        Else
            bd1.Filter =  bfl & " = \'" & r & "\' "
            bd1.Groups.AddDef(btj)
            bd1.Totals.AddDef(bb,r)
            dt1 = bd1.BuildDataSource()
            dt0.Combine(btj,dt1,btj)
            i = i + 1
        End If
    End If
Next
Tables("通用时期报表_表").DataSource = dt0

 

结果会出现重复列,代码错在哪里。怎么实现?感谢

 下载信息  [文件大小:   下载次数: ]
图片点击可在新窗口打开查看点击浏览该文件:管理项目34.zip


--  作者:有点甜
--  发布时间:2017/10/13 9:12:00
--  

Dim dt As DataTable
dt = DataTables("ysd")
Dim bb As String = "金额" \'drxx1("统计列").split("|") \' 指要统计的数量?金额
Dim bfl As String = "采购方式" \' drxx1("表头分类字段").split("|") \' 指要表头分类统计的字段
Dim btj As String = "管理部门" \' drxx1("统计分类字段").split("|") \' 指要列表分类统计的项目

\'通用统计
Dim i As Integer = 0
Dim Pr1 As List(Of String) \' 表头分类取值
Pr1 = Dt.GetValues(bfl)
Dim dts(pr1.count-1) As fxDataSource
For Each r As String In Pr1
    If r <> Nothing
        If i = 0
            Dim bd As New GroupTableBuilder("统计表1",dt)
            bd.Filter =  bfl & " = \'" & r & "\' "
            bd.Groups.AddDef(btj) \'统计分类字段
            bd.Totals.AddDef(bb,r) \'对金额进行统计
            dts(i) = bd.BuildDataSource()
            i = i + 1
        Else
            Dim bd As New GroupTableBuilder("统计表1",dt)
            bd.Filter =  bfl & " = \'" & r & "\' "
            bd.Groups.AddDef(btj) \'统计分类字段
            bd.Totals.AddDef(bb,r) \'对金额进行统计
            dts(i) = bd.BuildDataSource()
            dts(0).Combine(btj,dts(i),btj)
            i = i + 1
        End If
    End If
Next
Tables("通用时期报表_表").DataSource = dts(0) \'将统计结果绑定到


--  作者:李连山
--  发布时间:2017/10/13 9:15:00
--  
谢了