以文本方式查看主题

-  Foxtable(狐表)  (http://foxtable.com/bbs/index.asp)
--  专家坐堂  (http://foxtable.com/bbs/list.asp?boardid=2)
----  [求助]如何查询  (http://foxtable.com/bbs/dispbbs.asp?boardid=2&id=91490)

--  作者:kjkui
--  发布时间:2016/10/12 9:13:00
--  [求助]如何查询
Dim xz As WinForm.ComboBox = e.Form.Controls("选择")
Dim btn1 As WinForm.DateTimePicker = Forms("窗口1").Controls("StartDate")
Dim btn2 As WinForm.DateTimePicker = Forms("窗口1").Controls("EndDate")
 If xz.value = "今天"
    Dim y As Integer = Date.Today.Year
    Dim d As Date = Date.Today
    btn1.value = d
    btn2.value = d
    
End If

If xz.value = "本周"
    
    Dim y As Integer = Date.Today.Year
    Dim w As Integer = Date.Today.DayOfWeek \'算出今天是星期几
    Dim dt1 As Date = Date.Today.AddDays(-w) \'获取本周的第一天
    Dim dt2 As Date = Date.Today.AddDays(6 - w) \'获取本周的最后一天
    btn1.value = dt1
    btn2.value = dt2
   
End If    
If xz.value = "全部"
    e.Form.Controls("EndDate").Value = Nothing
    e.Form.Controls("StartDate").Value = Nothing

End If
一个下拉框有多个值,选择某个值,会出现对应的时间范围,现在的代码必须先选择“全部”,再选择其他的值才可以查询对应的值,如何修改(应该是if语句的错误??)

--  作者:有点蓝
--  发布时间:2016/10/12 9:18:00
--  
上面代码没有问题,代码放在什么事件的?

完整代码贴出来

--  作者:kjkui
--  发布时间:2016/10/12 9:23:00
--  

刚刚的代码在ValueChanged事件中

其中在TextChanged事件中写的是

Dim Filter As String


With e.Form.Controls("选择")

    Dim xz As WinForm.ComboBox = e.Form.Controls("选择")   

    If xz.value = "全部"

        Tables("订单管理").ApplyFilter = False

        Dim btn3 As WinForm.DateTimePicker = Forms("窗口1").Controls("StartDate")

        Dim btn4 As WinForm.DateTimePicker = Forms("窗口1").Controls("EndDate")

        btn3.Enabled = True

        btn4.Enabled = True

        e.Form.Controls("EndDate").Value = Nothing

        e.Form.Controls("StartDate").Value = Nothing

        

        Tables("订单管理").Filter = Filter

        

    End If

    If xz.value = "今天"

        Dim y As Integer = Date.Today.Year

        Dim d As Date = Date.Today \'当前时间

        Filter = "时间 = \'" & d & "\' And 时间 = \'" & d & "\'"

        Tables("订单管理").Filter = Filter

        

    End If

If xz.value = "本周"
        Dim y As Integer = Date.Today.Year
        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
        Filter = "时间 >= \'" & dt1 & "\' And 时间 <= \'" & dt2 & "\'"
        Tables("订单管理").Filter = Filter
        
    End If
End With
With e.Form.Controls("StartDate")
    If .Value IsNot Nothing Then
        If Filter >"" Then
            Filter = Filter & " And "
        End If
        Filter = Filter & "时间 >= \'" & .Value & "\'"
    End If
End With
With e.Form.Controls("EndDate")
    If .Value IsNot Nothing Then
        If Filter >"" Then
            Filter = Filter & " And "
        End If
        Filter = Filter & "时间 <= \'" & .Value & "\'"
    End If
End With
If Filter > "" Then
    Tables("订单管理").Filter = Filter
End If



--  作者:有点蓝
--  发布时间:2016/10/12 9:54:00
--  

去掉ValueChanged事件代码


TextChanged事件写代码


Dim Filter As String
Dim btn3 As WinForm.DateTimePicker =e.Form.Controls("StartDate")
Dim btn4 As WinForm.DateTimePicker = e.Form.Controls("EndDate")
Select Case e.Form.Controls("选择").Text
    Case "全部"
        btn3.Enabled = True
        btn4.Enabled = True
        btn3.Value = Nothing
        btn3.Value = Nothing
    Case "今天"
        btn3.Value = Date.Today
        btn3.Value = Date.Today
        Filter = "时间 = \'" & Date.Today & "\'"
        
    Case "本周"
        Dim w As Integer = Date.Today.DayOfWeek \'算出今天是星期几
        Dim dt1 As Date = Date.Today.AddDays(-w) \'获取本周的第一天
        Dim dt2 As Date = Date.Today.AddDays(6 - w) \'获取本周的最后一天
        btn3.Value = dt1
        btn3.Value = dt2
        Filter = "时间 >= \'" & dt1 & "\' And 时间 <= \'" & dt2 & "\'"
        
End Select
Tables("订单管理").Filter = Filter