以文本方式查看主题

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

--  作者:13865161910
--  发布时间:2014/12/17 22:22:00
--  [求助] 查询(筛选)代码如何设计

窗口界面设计如下,实现条件查询功能

 


图片点击可在新窗口打开查看此主题相关图片如下:pic0001.jpg
图片点击可在新窗口打开查看

 

afterload 事件代码如下:

以下内容为程序代码:

1 Dim cc As WinForm.ComboBox = e.Form.Controls("车厂")
2 cc.ComboList = DataTables("车型资料表").GetComboListString("车厂")
3
4 Tables("车型资料表").Filter = ""

 

查询 click事件代码如下:

 

以下内容为程序代码:

1 Dim cc As WinForm.ComboBox = e.Form.Controls("车厂")
2 Dim cx As WinForm.ComboBox = e.Form.Controls("车型")
3 Dim pl As WinForm.TextBox = e.Form.Controls("排量")
4 Dim nf As WinForm.TextBox = e.Form.Controls("年份")
5
6 Tables("车型资料表").Filter="车厂 = \'" & cc.Text & "\' and 车型 = \'" & cx.Text & "\' and 排量 like \'*" & pl.Text & "*\' and 适用年份 like \'*" & nf.Text & "*\'"

 

问题:当【排量】【适用年份】对应的文本列的内容为空值时,搜索到的内容为空白,只有当该两列同时填充数值后,才能实现查询功能到对应的数据列,如图

 
 


图片点击可在新窗口打开查看此主题相关图片如下:pic0002.jpg
图片点击可在新窗口打开查看

图片点击可在新窗口打开查看此主题相关图片如下:pic0003.jpg
图片点击可在新窗口打开查看

图片点击可在新窗口打开查看此主题相关图片如下:pic0004.jpg
图片点击可在新窗口打开查看
[此贴子已经被作者于2014-12-18 8:54:41编辑过]

--  作者:有点甜
--  发布时间:2014/12/17 22:29:00
--  

 查询语句不要这样写,要这样写

 

 http://www.foxtable.com/help/topics/1058.htm

 


--  作者:13865161910
--  发布时间:2014/12/17 22:40:00
--  

帮助中这样写道:

1、插入一个组合框,改名为“cmbProduct”,列表项目设为“PD01|PD02|PD03|PD04|PD05”,用于输入要筛选的产品。
2、插入一个组合框,改名为“cmbCustomer”,列表项目设为“CS01|CS02|CS03|CS04|CS05”,用于输入要筛选的客户。
3、插入一个组合框,改名为“cmbEmployee”,列表项目设为“EP01|EP02|EP03|EP04|EP05”,用于输入要筛选的雇员。

 

请教,列表项目设为“PD01|PD02|PD03|PD04|PD05”,我的该列项目很多,难道要全部在属性的【列表项目】——【自定义项目】中一一列出吗?

 

 

并且 我有两个内容是需要进行模糊查找,需要使用textbox控件进行查找  如何进行筛选代码设计呢?

[此贴子已经被作者于2014-12-17 22:46:34编辑过]

--  作者:有点甜
--  发布时间:2014/12/17 23:20:00
--  

 

Dim cc As WinForm.ComboBox = e.Form.Controls("车厂")
Dim cx As WinForm.ComboBox = e.Form.Controls("车型")
Dim pl As WinForm.TextBox = e.Form.Controls("排量")
Dim nf As WinForm.TextBox = e.Form.Controls("年份")

Dim filter As String = "1=1"
If cc.Text > "" Then
    filter &= " and 车厂 = \'" & cc.Text & "\'"
End If
If cx.Text > "" Then
    filter &= " and 车型 = \'" & cx.Text & "\' "
End If
If pl.Text > "" Then
    filter &= " and  排量 like \'*" & pl.Text & "*\' "
End If
If pl.Text > "" Then
    filter &= " and  适用年份 like \'*" & nf.Text & "*\'"
End If

Tables("车型资料表").Filter = filter

[此贴子已经被作者于2014-12-17 23:20:30编辑过]

--  作者:13865161910
--  发布时间:2014/12/18 9:39:00
--  
感谢大大提供的代码帮助,现在设计的差不多了,只不过出了个小问题:
以下内容为程序代码:

1 Dim cc As WinForm.ComboBox = e.Form.Controls("车厂")
2 Dim cx As WinForm.ComboBox = e.Form.Controls("车型")
3 Dim pl As WinForm.TextBox = e.Form.Controls("排量")
4 Dim nf As WinForm.TextBox = e.Form.Controls("年份")
5 Dim filter As String = "1=1"
6 If cc.Text > "" Then
7 filter &= " and 车厂 = \'" & cc.Text & "\'"
8 End If
9 If cx.Text > "" Then
10 filter &= " and 车型 = \'" & cx.Text & "\' "
11 End If
12 If pl.Text > "" Then
13 filter &= " and 排量 like \'*" & pl.Text & "*\' "
14 End If
15 If pl.Text > "" Then
16 filter &= " and 适用年份 like \'*" & nf.Text & "*\'"
17 End If
18 Tables("车型资料表").Filter = filter


执行上述代码后,如果排量textbox内容或年份textbox内容有其中一项为空值,总无法一起查询到,截图给您看下:

图片点击可在新窗口打开查看此主题相关图片如下:pic01.jpg
图片点击可在新窗口打开查看

图片点击可在新窗口打开查看此主题相关图片如下:pic02.jpg
图片点击可在新窗口打开查看

图片点击可在新窗口打开查看此主题相关图片如下:pic03.jpg
图片点击可在新窗口打开查看


--  作者:有点甜
--  发布时间:2014/12/18 9:55:00
--  

写错了

 

Dim cc As WinForm.ComboBox = e.Form.Controls("车厂")
Dim cx As WinForm.ComboBox = e.Form.Controls("车型")
Dim pl As WinForm.TextBox = e.Form.Controls("排量")
Dim nf As WinForm.TextBox = e.Form.Controls("年份")

Dim filter As String = "1=1"
If cc.Text > "" Then
    filter &= " and 车厂 = \'" & cc.Text & "\'"
End If
If cx.Text > "" Then
    filter &= " and 车型 = \'" & cx.Text & "\' "
End If
If pl.Text > "" Then|
    filter &= " and  排量 like \'*" & pl.Text & "*\' "
End If
If nf.Text > "" Then
    filter &= " and  适用年份 like \'*" & nf.Text & "*\'"
End If

Tables("车型资料表").Filter = filter