老师新年好!
请教一下,下边例子中,为什么CASE 2和CASE 3里,按年月筛选后的结果不是多选,而是只保留一个选项。
我想实现的结果是可以显示同一个联系人跨年度跨月份的记录。
比如,筛选后显示2018年11月和2019年1月的记录,
但以下代码筛选的结果只能显示其中一个月的记录,无法实现多选。
Dim trv As WinForm.TreeView = e.Sender
Dim flt As String
Dim ids As String
Dim nd0 As WinForm.TreeNode
Dim pd As WinForm.TreeNode
For Each nd0 In e.node.allNodes '清除子节点的选中标记
nd0.Checked = False
Next
pd = e.Node.ParentNode
Do While pd IsNot Nothing '清除父节点的选中标记
pd.Checked = False
pd = pd.ParentNode
Loop
For Each nd0 In trv.AllNodes
pd = nd0
Do While pd IsNot Nothing
If pd.Checked Then
If ids > "" Then
ids= ids & ","
End If
ids = ids & "'" & nd0.name & "'"
Exit Do
Else
pd = pd.ParentNode
End If
Loop
Next
Dim Year As Integer = e.Node.DataRow("年")
Dim Month As Integer = e.Node.DataRow("月")
Dim d1 As Date = New Date(Year,1,1) '取得该年的第一天
Dim d2 As Date= new Date(Year,12,31) '取得该年的最后一天
Dim dm1 As Date= New Date(Year, Month, 1) '取得该月的第一天
Dim dm2 As Date= new Date(Year, Month, Date.DaysInMonth(Year,Month)) '取得该月的最后一天
For Each nd As WinForm.TreeNode In trv.AllNodes
If nd.Checked Then
If flt > "" Then
flt = flt & " or " '注意用or而不是And
End If
Select Case nd.Level
Case 0
flt = flt & "( 类型 = '" & nd.DataRow("类型") & "')"
Case 1
flt = flt & "( 类型 = '" & nd.DataRow("类型") & "' And 联系人 = '" & nd.DataRow("联系人") & "')"
Case 2
flt = flt & "( 类型 = '" & nd.DataRow("类型") & "' And 联系人 = '" & nd.DataRow("联系人") & "' AND 日期 >= #" & d1 & "# And 日期 <= #" & d2 & "# )"
Case 3
flt = flt & "( 类型 = '" & nd.DataRow("类型") & "' And 联系人 = '" & nd.DataRow("联系人") & "' AND 日期 >= #" & dm1 & "# And 日期 <= #" & dm2 & "# )"
End Select
End If
Next
Dim T3 As WinForm.Table = e.Form.Controls("Table3")
T3.Table.Filter = flt