第一步:窗口的AfterLoad事件代码改为:
Dim cmd As New SQLCommand
Dim dt As DataTable
cmd.CommandText = "SELECT DISTINCT 产品, Year(日期) As 年, Month(日期) As 月 From {订单}"
dt = cmd.ExecuteReader()
Dim trv As WinForm.TreeView = e.Form.Controls("TreeView1")
trv.BuildTree(dt, "产品|年|月")
第二步:目录树的NodeMouseDoubleClick事件代码改为:
Dim Value()As String
Dim Filter As String
Dim d1 As Date
Dim d2 As Date
Value = e.Node.FullPath.Split("\")
Select Case e.Node.Level
Case 0
Filter ="产品 = '" & Value(0) & "'"
Case 1
Dim y As Integer = value(1)
d1 = New Date(y,1,1) '取得该年的第一天
d2 = new Date(y,12,31) '取得该年的最后一天
Filter = "产品 = '" & Value(0) & "' And 日期 >= #" & d1 & "# And 日期 <= #" & d2 & "#"
Case 2
Dim y As Integer = value(1)
Dim m As Integer = value(2)
d1 = New Date(y, m, 1) '取得该月的第一天
d2 = new Date(y, m, Date.DaysInMonth(y,m)) '取得该月的最后一天
Filter = "产品 = '" & Value(0) & "' And 日期 >= #" & d1 & "# And 日期 <= #" & d2 & "#"
End Select
Tables("订单").Filter = Filter