'首先生成统计表
Dim dt1 As DataTable
Dim b As New GroupTableBuilder("统计表1",DataTables("稿件投稿"))
b.Groups.AddDef("所在单位")
b.Groups.AddDef("所在部门")
b.Groups.AddDef("刊登时间",DateGroupEnum.Year,"年")
b.Groups.AddDef("刊登时间",DateGroupEnum.Month,"月")
b.Groups.AddDef("稿件作者")
b.Groups.AddDef("文件类型")
b.Totals.AddDef("稿件作者",AggregateEnum.Count,"订单数") '根据客户列来统计记录数,也就是订单数
dt1 = b.Build(False) '参数设置为False,生成一个临时表,不在主界面显示
'b.build
'MainTable = Tables("统计表1")
'''然后根据统计表生成目录树
Dim trv As WinForm.TreeView = e.Form.Controls("TreeView1")
trv.BuildTree(dt1, "所在单位|所在部门|年|月|稿件作者|文件类型")
trv.StopRedraw
For Each nd As WinForm.TreeNode In trv.AllNodes
Dim szdw As String = nd.DataRow("所在单位")
Dim szbm As String = nd.DataRow("所在部门")
Dim Year As Integer = nd.DataRow("年")
Dim Month As Integer = nd.DataRow("月")
Dim Product As String = nd.DataRow("稿件作者")
Select Case nd.Level
Case 0
nd.Text = nd.text & "年(" & dt1.Compute("Sum(订单数)","年 = " & Year & " and 所在单位= "& szdw ) & "条)"
Case 1
nd.Text = nd.text & "月(" & dt1.Compute("Sum(订单数)","年 = " & Year & " and 所在单位= "& szdw &" And 所在部门 = "& szbm &" And 月 = " & Month) & "条)"
Case 2
nd.Text = nd.text & "(" & nd.DataRow("订单数") & "条)"
Case 3
nd.Text = nd.text & "(" & nd.DataRow("订单数") & "条)"
End Select
Next
trv.Nodes.Insert("显示所有行","显示所有行(" & dt1.Compute("Sum(订单数)") & "条)",0)
trv.ResumeRedraw