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