窗口AfterLoad事件:
Dim cmd As New SQLCommand
Dim dt As DataTable
cmd.CommandText = "SELECT DISTINCT Year(日期) As 年, Month(日期) As 月,Day(日期) As 日 From {订单}"
dt = cmd.ExecuteReader()
Dim trv As WinForm.TreeView = e.Form.Controls("TreeView1")
trv.BuildTree(dt, "年|月|日")
目录树NodeMouseClick事件:
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
Dim y As Integer = value(0)
d1 = New Date(y,1,1) '取得该年的第一天
d2 = new Date(y,12,31) '取得该年的最后一天
Filter = "日期 >= #" & d1 & "# And 日期 <= #" & d2 & "#"
Case 1
Dim y As Integer = value(0)
Dim m As Integer = value(1)
d1 = New Date(y, m, 1) '取得该月的第一天
d2 = new Date(y, m, Date.DaysInMonth(y,m)) '取得该月的最后一天
Filter = "日期 >= #" & d1 & "# And 日期 <= #" & d2 & "#"
Case 2
Dim y As Integer = value(0)
Dim m As Integer = value(1)
Dim d As Integer = Value(2)
Dim dt As new Date(y,m,d)
Filter = "日期 = #" & dt & "#"
End Select
Tables("订单").Filter = Filter