Foxtable(狐表)用户栏目专家坐堂 → [求助]如何查询


  共有2093人关注过本帖树形打印复制链接

主题:[求助]如何查询

帅哥哟,离线,有人找我吗?
kjkui
  1楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:婴狐 帖子:18 积分:196 威望:0 精华:0 注册:2016/9/26 15:20:00
[求助]如何查询  发帖心情 Post By: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语句的错误??)

 回到顶部
帅哥,在线噢!
有点蓝
  2楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:超级版主 帖子:110574 积分:562760 威望:0 精华:9 注册:2015/6/24 9:21:00
  发帖心情 Post By:2016/10/12 9:18:00 [只看该作者]

上面代码没有问题,代码放在什么事件的?

完整代码贴出来

 回到顶部
帅哥哟,离线,有人找我吗?
kjkui
  3楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:婴狐 帖子:18 积分:196 威望:0 精华:0 注册:2016/9/26 15:20:00
  发帖心情 Post By: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



 回到顶部
帅哥,在线噢!
有点蓝
  4楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:超级版主 帖子:110574 积分:562760 威望:0 精华:9 注册:2015/6/24 9:21:00
  发帖心情 Post By: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

 回到顶部