Dim dt As DataTable
Dim b As New GroupTableBuilder("统计表1",DataTables("预算明细查询表"))
b.Groups.AddDef("记录编号")
b.Groups.AddDef("下达年度")
b.Groups.AddDef("资金来源")
b.Groups.AddDef("预算下达部门")
b.Groups.AddDef("预算实施部门")
b.Groups.AddDef("预算资金性质")
b.Groups.AddDef("一级科目")
b.Groups.AddDef("二级科目")
b.Groups.AddDef("三级科目")
b.Groups.AddDef("四级科目")
b.Groups.AddDef("五级科目")
b.Groups.AddDef("六级科目")
b.Groups.AddDef("七级科目")
b.Totals.AddDef("预算下达金额",AggregateEnum.sum,"预算下达金额")
dt = b.Build(False)
Dim trv As WinForm.TreeView = e.Form.Controls("TreeView2")
trv.BuildTree(dt,"预算资金性质|一级科目|二级科目|三级科目|四级科目|五级科目|六级科目|七级科目")
trv.StopRedraw
For Each n As WinForm.TreeNode In trv.Nodes
Functions.Execute("DelEmptyNode",n)
Next
For Each nd As WinForm.TreeNode In trv.AllNodes
Dim yszjxz As String = nd.DataRow("预算资金性质")
Dim km1 As String = nd.DataRow("一级科目")
Dim km2 As String = nd.DataRow("二级科目")
Dim km3 As String = nd.DataRow("三级科目")
Dim km4 As String = nd.DataRow("四级科目")
Dim km5 As String = nd.DataRow("五级科目")
Dim km6 As String = nd.DataRow("六级科目")
Dim km7 As String = nd.DataRow("七级科目")
Select Case nd.Level
Case 0
msgbox("0")
nd.Text = nd.text & "------------" & dt.Compute("Sum(预算下达金额)","预算资金性质 = '" & yszjxz & "'") & "万元"
Case 1
msgbox("1")
nd.Text = nd.text & "------------" & dt.Compute("Sum(预算下达金额)","预算资金性质='" & yszjxz & "'and 一级科目='" & km1 & "'") & "万元"
Case 2
msgbox("2")
nd.Text = nd.text & "------------" & dt.Compute("Sum(预算下达金额)","预算资金性质='" & yszjxz & "'and 一级科目='" & km1 & "'and 二级科目 ='" & km2 & "'") & "万元"
Case 3
msgbox("3")
nd.Text = nd.text & "------------" & dt.Compute("Sum(预算下达金额)","预算资金性质='" & yszjxz & "'and 一级科目='" & km1 & "'and 二级科目 ='" & km2 & "' and 三级科目 = '" & km3 & "'") & "万元"
Case 4
msgbox("4")
nd.Text = nd.text & "------------" & dt.Compute("Sum(预算下达金额)","预算资金性质='" & yszjxz & "'and 一级科目='" & km1 & "'and 二级科目 ='" & km2 & "'and 三级科目= '" & km3 & "'and 四级科目= '" & km4 & "'") & "万元"
Case 5
msgbox("5")
nd.Text = nd.text & "------------" & dt.Compute("Sum(预算下达金额)","预算资金性质='" & yszjxz & "'and 一级科目='" & km1 & "'and 二级科目 ='" & km2 & "'and 三级科目= '" & km3 & "'and 四级科目= '" & km4 & "'and 五级科目= '" & km5 & "'") & "万元"
Case 6
msgbox("6")
nd.Text = nd.text & "------------" & dt.Compute("Sum(预算下达金额)","预算资金性质='" & yszjxz & "'and 一级科目='" & km1 & "'and 二级科目 ='" & km2 & "'and 三级科目= '" & km3 & "'and 四级科目= '" & km4 & "'and 五级科目= '" & km5 & "'and 六级科目= '" & km6 & "'") & "万元"
Case 7
msgbox("7")
If km7 IsNot Nothing Then
nd.Text = nd.text & "------------" & dt.Compute("Sum(预算下达金额)","预算资金性质='" & yszjxz & "'and 一级科目='" & km1 & "'and 二级科目 ='" & km2 & "'and 三级科目= '" & km3 & "'and 四级科目= '" & km4 & "'and 五级科目= '" & km5 & "'and 六级科目= '" & km6 & "'and 七级科目= '" & km7 & "'") & "万元"
Else
Return
End If
End Select
Next
trv.Nodes.Insert("加载所有行","加载所有行(" & dt.Compute("Sum(预算下达金额)") & "万元)",0)
trv.ResumeRedraw
[此贴子已经被作者于2016/8/24 22:20:55编辑过]