下面的代码,是先获取本月所以订单,然后在筛选出选择日期的订单。是否有错,感觉有些臃肿,有可以优化高效一些吗?谢谢!
Dim y As Integer = Date.Today.Year
Dim m As Integer = Date.Today.Month
Dim dt1 As New Date(y, m, 1)
Dim dt2 As New Date(y, m, Date.DaysInMonth(y, m)) '获取本月的最后一天
Dim Filter As String
Filter = "截止日期 >= '" & dt1 & "' And 截止日期 <= '" & dt2 & "'"
DataTables("派工").LoadFilter = Filter
DataTables("派工").Load()
Tables("派工").Filter = "截止日期 = '" & e.Sender.Value & "'"
Static lst As List(of Date) '定义一个静态集合变量,用于存储选择的截止日期
If lst Is Nothing Then
lst = New List(of Date)
End If
If ModifierKey <> Keys.Control Then '如果没有按下Ctrl键
lst.Clear() '清除以前的截止日期
End If
If lst.Contains(e.Sender.Value) = False Then '如果集合不包括按下的截止日期
lst.Add(e.Sender.Value) '则向集合添加此截止日期
End If
If lst.Count = 1 Then '如果只选择了一个截止日期,则直接筛选此截止日期的派工
Tables("派工").Filter = "截止日期 = '" & e.Sender.Value & "'"
Else '否则用In运算符筛选选定的多个截止日期的派工
Dim v As String
For i As Integer = 0 To lst.Count - 1
v = v & "'" & lst(i) & "',"
Next
v = v.Trim(",")
Tables("派工").Filter = "截止日期 In (" & v & ")"
End If
Tables("派工").Filter &= " and 时段 <> '5取消'"
"
[此贴子已经被作者于2016/4/18 12:29:03编辑过]