'首先生成统计表
Dim dt As DataTable
Dim b As New GroupTableBuilder("统计表1",DataTables("订单编码"))
b.Groups.AddDef("录入时间",DateGroupEnum.Year,"年")
b.Groups.AddDef("录入时间",DateGroupEnum.Month,"月")
'b.Groups.AddDef("录入时间",DateGroupEnum.Date,"日")
b.Groups.AddDef("组别")
b.Groups.AddDef("业务人员")
b.Totals.AddDef("业务人员",AggregateEnum.Count,"订单数") '根据客户列来统计记录数,也就是订单数
dt = b.Build(False) '参数设置为False,生成一个临时表,不在主界面显示
'然后根据统计表生成目录树
Dim trv2 As WinForm.TreeView = e.Form.Controls("TreeView2")
trv2.BuildTree(dt, "年|月|组别|业务人员")
trv2.StopRedraw
For Each nd As WinForm.TreeNode In trv2.AllNodes
Dim Year As Integer = nd.DataRow("年")
Dim Month As Integer = nd.DataRow("月")
Dim Product As String = nd.DataRow("组别")
Dim yewurenyuan As String = nd.DataRow("业务人员")
Select Case nd.Level
Case 0
nd.Text = nd.text & "年(" & dt.Compute("Sum(订单数)","年 = " & Year) & "单)"
Case 1
nd.Text = nd.text & "月(" & dt.Compute("Sum(订单数)","年 = " & Year & " And 月 = " & Month) & "单)"
Case 2
nd.Text = nd.text & "(" & dt.Compute("Sum(订单数)","年 = " & Year & " And 月 = " & Month & " And 组别 = '" & nd.DataRow("组别") & "'") & "单)"
Case 3
nd.Text = nd.text & "(" & dt.Compute("Sum(订单数)","年 = " & Year & " And 月 = " & Month & " And 组别 = '" & nd.DataRow("组别") & "' And 业务人员 = '" & nd.DataRow("业务人员") & "'") & "单)"
Case 4
nd.Text = nd.text & "(" & nd.DataRow("订单数") & "单)"
End Select
Next
trv2.Nodes.Insert("显示所有行","显示所有行(" & dt.Compute("Sum(订单数)") & "单)",0)