''首先生成统计表
Dim dt5 As DataTable
Dim b5 As New sqlGroupTableBuilder("统计表材料领用表","材料领用表")
b5.C
b5.Groups.AddDef("日期",DateGroupEnum.Year,"年")
b5.Groups.AddDef("日期",DateGroupEnum.Month,"月")
b5.Groups.AddDef("日期",DateGroupEnum.day,"日")
b5.Groups.AddDef("领料单位")
b5.Groups.AddDef("序号")
b5.Groups.AddDef("领料人")
b5.Totals.AddDef("序号",AggregateEnum.Count,"次数") '根据客户列来统计记录数,也就是订单数
dt5 = b5.Build(True) '参数设置为True,生成一个临时表,不在主界面显示
'然后根据统计表生成目录树
Dim trv5 As WinForm.TreeView = e.Form.Controls("TreeView1")
trv5.BuildTree(dt5, "年|月|领料单位|领料人")
trv5.StopRedraw
For Each nd As WinForm.TreeNode In trv5.AllNodes
Dim Year As Integer = nd.DataRow("年")
Dim Month As Integer = nd.DataRow("月")
Dim day As Integer = nd.DataRow("日")
Dim Product51 As String = nd.DataRow("领料单位")
Dim Product52 As String = nd.DataRow("序号")
Dim Product6 As String = nd.DataRow("领料人")
Select Case nd.Level
Case 0
nd.Text = nd.text & "(" & dt5.Compute("Sum(次数)","年 = " & Year) & ")"
Case 1
nd.Text = nd.text & "(" & dt5.Compute("Sum(次数)","年 = " & Year & " And 月 = " & Month) & ")"
Case 2
nd.Text = nd.text & "(" & dt5.Compute("Sum(次数)","年 = " & Year & " And 月 = " & Month & " And 领料单位 = '" & nd.Text & "'") & ")"
Case 3
nd.Text = nd.text & "(" & dt5.Compute("Sum(次数)","年 = " & Year & " And 月 = " & Month & " And 领料单位 = '" & Product51 & "' And 领料人 = '" & nd.Text & "'") & ")"
Case 4
nd.Text = nd.text & "(" & nd.DataRow("次数") & ")"
End Select
Next
trv5.Nodes.Insert("所有行","所有行(" & dt5.Compute("Sum(次数)") & ")",0)
trv5.ResumeRedraw