Dim du1 As WinForm.Table = e.Form.Controls("Table1")
Dim dt As DataTable
Dim b As New GroupTableBuilder("统计表1",du1.Table.DataTable)
b.Groups.AddDef("来往单位")
b.Groups.AddDef("日期",DateGroupEnum.Year,"年")
b.Groups.AddDef("日期",DateGroupEnum.Month,"月")
b.Groups.AddDef("日期",DateGroupEnum.Day,"日")
b.Totals.AddDef("单据编号",AggregateEnum.Count,"单据数")
dt = b.Build(True)
Dim tv As WinForm.TreeView = e.Form.Controls("TreeView1")
tv.BuildTree(dt,"来往单位|年|月|日")
tv.StopRedraw
For Each nd As WinForm.TreeNode In tv.AllNodes
Dim Product As String = nd.DataRow("来往单位")
Dim Year As Integer = nd.DataRow("年")
Dim Month As Integer = nd.DataRow("月")
Dim Day As Integer = nd.DataRow("日")
Select Case nd.Level
Case 0
nd.Text = nd.text & "单据(" & dt.Compute("Sum(单据数)","来往单位 = '" & Product & "'") & "条)"
Case 1
nd.Text = nd.text & "年(" & dt.Compute("Sum(单据数)","来往单位 = '" & Product & "'And 年 = " & Year) & "条)"
Case 2
nd.Text = nd.text & "月(" & dt.Compute("Sum(单据数)","来往单位 = '" & Product & "'And 年 = " & Year & " And 月 = " & Month) & "条)"
Case 3
nd.Text = nd.text & "日(" & dt.Compute("Sum(单据数)","来往单位 = '" & Product & "'And 年 = " & Year & " And 月 = " & Month & " And 日 = " & Day) & "条)"
End Select
Next
tv.Nodes.Insert("显示所有行","显示所有条件行(" & dt.Compute("Sum(单据数)") & "条)",0)
tv.ResumeRedraw
筛选代码:
Dim flt As String
Dim d1,d2,d3,d4,d5 As Date
Dim Year As Integer = e.Node.DataRow("年")
Dim Month As Integer = e.Node.DataRow("月")
Dim Day As Integer = e.Node.DataRow("日")
d1 = New Date(Year,1,1) '取得该年的第一天
d2 = new Date(Year,12,31) '取得该年的最后一天
d3 = New Date(Year, Month, 1) '取得该月的第一天
d4 = new Date(Year, Month, Date.DaysInMonth(Year,Month)) '取得该月的最后一天
d5 = New Date(Year, Month,Day)
For Each nd As WinForm.TreeNode In e.Sender.AllNodes
If nd.Checked = True Then
If flt > "" Then
flt = flt & " Or "
End If
If nd.Level = 0 Then
flt = flt & "(来往单位 = '" & nd.Name & "')"
End If
If nd.Level = 1 Then
flt = flt & "(来往单位 = '" & nd.ParentNode.Name & "'And 日期 >= #" & d1 & "# And 日期 <= #" & d2 & "#)"
End If
If nd.Level = 2Then
flt = flt & "(来往单位 = '" & nd.ParentNode.ParentNode.Name & "'And 日期 >= #" & d3 & "# And 日期 <= #" & d4 & "#)"
End If
If nd.Level = 3 Then
flt = flt & "(来往单位 = '" & nd.ParentNode.ParentNode.ParentNode.Name & "'And 日期 = #" & d5 & "#)"
End If
End If
e.Form.Controls("Table1").Table.Filter = flt
Next
MessageBox.Show(flt)