以文本方式查看主题 - Foxtable(狐表) (http://foxtable.com/bbs/index.asp) -- 专家坐堂 (http://foxtable.com/bbs/list.asp?boardid=2) ---- [求助] (http://foxtable.com/bbs/dispbbs.asp?boardid=2&id=42948) |
-- 作者:ybzou3r -- 发布时间:2013/11/26 21:42:00 -- [求助] 请教前辈,我有一个订单列表,里面有订单录入日期,建了一个查询窗口,查询条件里有下拉列表框录入日期,我想做成这样的效果,点录入日期下拉列表框后显示有当天,最近三天,本周,上周,本月,上月,本季度,本年,所有,当我选择下拉列表框后,窗口里的表按我的选择自动筛选,请教这个代码应该怎么写,请前辈赐教。 |
-- 作者:有点甜 -- 发布时间:2013/11/26 21:44:00 -- 参考年月日的筛选写法。 |
-- 作者:ybzou3r -- 发布时间:2013/11/26 22:36:00 -- 前辈帮我看看这个代码应该怎么优化 Dim y As Integer = Date.Today.Year Dim sy As Integer = (y-1) Dim sy1 As New Date(sy, 1, 1) Dim sy2 As New Date(sy, 12, 31) Dim y1 As New Date(y, 1, 1) Dim y2 As New Date(y, 12, 31) Dim q As Integer = (Date.Today.Month - 1) \\ 3 + 1 \'计算现在是第几个季度Dim dt1 As New Date(y, 3 * (q - 1) + 1, 1) \'获取本季度的第一天 Dim q1 As New Date(y, 3 * (q - 1) + 1, 1) \'获取本季度的第一天 Dim q2 As New Date(y, 3 * q, Date.DaysInMonth(2011,3 * q)) \'获取本季度的最后一天 Dim m As Integer = Date.Today.Month Dim m1 As New Date(y, m, 1) Dim m2 As New Date(y, m, Date.DaysInMonth(y, m)) \'获取本月的最后一天 Dim w As Integer = Date.Today.DayOfWeek \'算出今天是星期几 Dim dt1 As Date = Date.Today.AddDays(-w) \'获取本周的第一天 Dim dt2 As Date = Date.Today.AddDays(6 - w) \'获取本周的最后一天 Dim Filter As String If txt = "当天" Then Filter = "录入日期 >= #" & dt1 & "# And 录入日期 <= #" & dt1 & "#" tbl.Filter = Filter End If If txt = "本周" Then Filter = "录入日期 >= #" & dt1 & "# And 录入日期 <= #" & dt2 & "#" tbl.Filter = Filter End If If txt = "本月" Then Filter = "录入日期 >= #" & m1 & "# And 录入日期 <= #" & m2 & "#" tbl.Filter = Filter End If If txt = "本季度" Then Filter = "录入日期 >= #" & q1 & "# And 录入日期 <= #" & q2 & "#" tbl.Filter = Filter End If If txt = "本年" Then Filter = "录入日期 >= #" & y1 & "# And 录入日期 <= #" & y2 & "#" tbl.Filter = Filter End If If txt = "上年" Then Filter = "录入日期 >= #" & sy1 & "# And 录入日期 <= #" & sy2 & "#" tbl.Filter = Filter End If If txt = "所有" Then Filter = "" tbl.Filter = Filter End If |
-- 作者:有点甜 -- 发布时间:2013/11/26 22:53:00 -- 只能这样写了。 你把上面的获取日期的代码,分别放在 if 判断语句里面就行了。
|