-- 作者:wh420
-- 发布时间:2014/6/9 14:52:00
--
再请教,假设这样一段代码如何用函数来调用?
Dim
dt
As
DataTable Dim
b
As
New
GroupTableBuilder("统计表1",DataTables("订单")) b.Groups.AddDef("日期",DateGroupEnum.Year,"年") b.Groups.AddDef("日期",DateGroupEnum.Month,"月") b.Groups.AddDef("产品") b.Totals.AddDef("客户",AggregateEnum.Count,"订单数")
dt = b.Build(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
|
-- 作者:有点甜
-- 发布时间:2014/6/9 14:57:00
--
做一个内部函数,参考2楼,贴入代码,即可。
Dim dt As DataTable Dim b As New GroupTableBuilder("统计表1",DataTables("订单")) b.Groups.AddDef("日期",DateGroupEnum.Year,"年") b.Groups.AddDef("日期",DateGroupEnum.Month,"月") b.Groups.AddDef("产品") b.Totals.AddDef("客户",AggregateEnum.Count,"订单数")
dt = b.Build(False) Dim trv As WinForm.TreeView = Forms("窗口xxx").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
|