以文本方式查看主题

-  Foxtable(狐表)  (http://foxtable.net/bbs/index.asp)
--  专家坐堂  (http://foxtable.net/bbs/list.asp?boardid=2)
----  多出一个“投入成本1”  (http://foxtable.net/bbs/dispbbs.asp?boardid=2&id=121244)

--  作者:nbsugu_z
--  发布时间:2018/7/2 14:44:00
--  多出一个“投入成本1”

Dim bd1 As New GroupTableBuilder("统计表B1",DataTables("材料入库登记"))
        Dim dt1 As fxDataSource
        bd1.Groups.AddDef("项目分类")
       bd1.Groups.AddDef("内容","成本类型")
        bd1.Totals.AddDef("成本分离_成本金额","投入成本")
        bd1.Totals.AddDef("数量")
        dt1 = bd1.BuildDataSource()
       
        Dim bd2 As New GroupTableBuilder("统计表B2",DataTables("项目其他费用支出"))
        Dim dt2  As fxDataSource
        bd2.Groups.AddDef("项目分类")
       bd2.Groups.AddDef("内容","成本类型")
               
        bd2.Totals.AddDef("金额","投入成本")
        dt2 = bd2.BuildDataSource()
       
        Dim arr() As String = {"项目分类","成本类型"}
        dt1.Combine(arr,dt2,arr)
               
        dt1.show("统计表B") \'将统计结果绑定到Table
        Dim t As Table = Tables("统计表B")
       
                With Tables("统计表B")
            .MergeMode = MergeModeEnum.Standard
            .MergeCols.Clear()
            .MergeCols.Add("项目分类")
           .MergeCols.Add("成本类型")
           
            .MergeSort = "项目分类"
            .AllowMerge = True
        End With
       
        Dim g As Subtotalgroup
        t.SubtotalGroups.Clear()
        t.GroupAboveData = False
        t.TreeVisible = False
        t.SpillNode = True
       
        g = New Subtotalgroup
        g.Aggregate = AggregateEnum.Sum
        g.GroupOn = "*"
        g.TotalOn = "数量,投入成本"
        g.Caption = "总计"
        t.SubtotalGroups.Add(g)
       
        g = New Subtotalgroup
       g.Aggregate = AggregateEnum.Sum
        g.GroupOn = "项目分类"
        g.TotalOn = "数量,投入成本"
        g.Caption = "{0} 小计"
        t.SubtotalGroups.Add(g)
        t.Subtotal()
       
        MainTable = t
       
        \'以下显示格式
        Tables("统计表B").cols("数量").DataCol.setFormat("#,###.00")
        Tables("统计表b").cols("投入成本").DataCol.setFormat("#,###.00")
               
               
        \'结束

 

 

老师,为什么多出一个“投入成本1”列,我目的是加到“投入成本”列中去。我有二张表取数,内容列为不同成本名称。目的,按项目、成本大类合并到一个统计表中去,求修改代码


图片点击可在新窗口打开查看此主题相关图片如下:汇总表.png
图片点击可在新窗口打开查看

--  作者:有点甜
--  发布时间:2018/7/2 14:57:00
--  

参考,用 Merge

 

http://www.foxtable.com/webhelp/scr/2320.htm

 

或者是,你不要Combine,在第一张表直接addnew增加第二张表的数据。


--  作者:nbsugu_z
--  发布时间:2018/7/2 15:05:00
--  看不懂
能不能帮我修改一下代码?
--  作者:有点甜
--  发布时间:2018/7/2 15:54:00
--  

Dim bd1 As New GroupTableBuilder("统计表B1",DataTables("材料入库登记"))
bd1.Groups.AddDef("项目分类")
bd1.Groups.AddDef("内容","成本类型")
bd1.Totals.AddDef("成本分离_成本金额","投入成本")
bd1.Totals.AddDef("数量")
bd1.Build

Dim bd2 As New GroupTableBuilder("统计表B2",DataTables("项目其他费用支出"))
Dim dt2  As fxDataSource
bd2.Groups.AddDef("项目分类")
bd2.Groups.AddDef("内容","成本类型")
bd2.Totals.AddDef("金额","投入成本")
bd2.Build

Dim t1 As Table = Tables("统计表B1")
Dim t2 As Table = Tables("统计表B2")

For Each r As Row In t2.rows
    Dim nr As Row = t1.addnew
    nr("项目分类") = r("项目分类")
    nr("成本类型") = r("成本类型")
    nr("投入成本") = r("投入成本")
Next

With t1
    .MergeMode = MergeModeEnum.Standard
    .MergeCols.Clear()
    .MergeCols.Add("项目分类")
    .MergeCols.Add("成本类型")
   
    .MergeSort = "项目分类"
    .AllowMerge = True
End With

Dim g As Subtotalgroup
t1.SubtotalGroups.Clear()
t1.GroupAboveData = False
t1.TreeVisible = False
t1.SpillNode = True

g = New Subtotalgroup
g.Aggregate = AggregateEnum.Sum
g.GroupOn = "*"
g.TotalOn = "数量,投入成本"
g.Caption = "总计"
t1.SubtotalGroups.Add(g)

g = New Subtotalgroup
g.Aggregate = AggregateEnum.Sum
g.GroupOn = "项目分类"
g.TotalOn = "数量,投入成本"
g.Caption = "{0} 小计"
t1.SubtotalGroups.Add(g)
t1.Subtotal()

MainTable = t1

\'以下显示格式
t1.cols("数量").DataCol.setFormat("#,###.00")
t1.cols("投入成本").DataCol.setFormat("#,###.00")