在操作通过目录树进行数据筛选时提示的,一般出现在打开窗口后, 第一次筛选报错。(但有时候又不报错,所以不解了)
Dim wc As WinForm.Control = e.Sender
If Typeof wc Is winForm.TreeView
Tables("生产数据查询_Table1").DataSource = DataTables("生产信息子表")
Tables("生产数据查询_Table1").GrandTotal = False
Dim dt As DataTable = DataTables("生产信息子表")
Dim tv1 As WinForm.TreeView = e.Form.Controls("TreeView1")
Dim tv2 As WinForm.TreeView = e.Form.Controls("TreeView2")
Dim tv3 As WinForm.TreeView = e.Form.Controls("TreeView3")
Dim flr As String
Select Case e.Sender.Name
Case "TreeView1"
If tv1.SelectedNode.Name <> "" And left(tv1.SelectedNode.Name,2) <> "所有"
Dim year As Integer = tv1.SelectedNode.DataRow("年")
Dim month As Integer = tv1.SelectedNode.DataRow("月")
If tv1.SelectedNode.Level = 0
Dim y1 As Date = new Date(year,1,1)
Dim y2 As Date = new Date(year,12,31)
vars("flr1") = "订单日期 >= #" & y1 & "# and 订单日期<= #" & y2 & "#"
Else
Dim m1 As Date = new Date(year,month,1)
Dim m2 As Date = new Date(year,month,Date.DaysInMonth(year,month))
vars("flr1") = "订单日期 >= #" & m1 & "# and 订单日期<= #" & m2 & "#"
End If
Else
vars("flr1") = ""
End If
Case "TreeView2"
If tv2.SelectedNode.Name <> "" And left(tv2.SelectedNode.Name,2) <> "所有"
If tv2.SelectedNode.Level = 0
vars("flr2") = "订单编号 = '" & tv2.SelectedNode.Name & "'"
Else
vars("flr2") = "订单编号 = '" & tv2.SelectedNode.ParentNode. Name & "' and 产品名称= '" & tv2.SelectedNode.Name & "'"
End If
Else
vars("flr2") = ""
End If
Case "TreeView3"
If tv3.SelectedNode.Name <> "" And left(tv3.SelectedNode.Name,2) <> "所有"
If tv3.SelectedNode.Level = 0
vars("flr3") = "生产工序 = '" & tv3.SelectedNode.Name & "'"
Else
vars("flr3") = "生产工序 = '" & tv3.SelectedNode.ParentNode. Name & "' and 生产组别= '" & tv3.SelectedNode.Name & "'"
End If
Else
vars("flr3") = ""
End If
End Select
For i As Integer = 1 To 3
If vars("flr" & i) > "" Then
flr + = " And " & vars("flr" & i)
End If
Next
If flr > "" Then
flr = flr.SubString(5)
Else
flr = ""
End If
Tables("生产数据查询_Table1").Filter = flr
End If