'首先生成统计表 Dim dt As DataTable Dim b As New SQLGroupTableBuilder("统计表1","订单") b.Groups.AddDef("日期",DateGroupEnum.Year,"年") b.Groups.AddDef("日期",DateGroupEnum.Month,"月") b.Groups.AddDef("产品") b.Totals.AddExp("金额","单价 * 数量") dt = b.Build(False) '参数设置为False,生成一个临时表,不在主界面显示 '然后根据统计表生成目录树 Dim trv As WinForm.TreeView = e.Form.Controls("TreeView1") trv.BuildTree(dt, "年|月|产品") trv.StopRedraw For Each nd As WinForm.TreeNode In trv.AllNodes 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 & "年(" & dt.Compute("Sum(金额)","年 = " & Year) & ")" Case 1 nd.Text = nd.text & "月(" & dt.Compute("Sum(金额)","年 = " & Year & " And 月 = " & Month) & ")" Case 2 nd.Text = nd.text & "(" & nd.DataRow("金额") & ")" End Select Next trv.Nodes.Insert("加载所有行","加载所有行(" & dt.Compute("Sum(金额)") & "条)",0) trv.ResumeRedraw
|