请问在delphi中combobox和checkbox组合在一起实现某个功能怎么写?
请问在delphi中combobox和checkbox组合在一起实现某个功能怎么写?
一个combobox控件,内容分别是:客户,电话,地址
一个edit控件:输入;
一个checkbox控件:控件为选择项,后面为两个日期控件DateTimePicker1跟DateTimePicker2
如果是单独查询COMBOX1的内容为
adoquery1.Close;
adoquery1.SQL.Clear;
adoquery1.SQL.Add('select * from spsellsum where 客户 like ''%'+edit1.text+'%''');
adoquery1.Open;
其它类式
日期查询代码:
adoquery1.sql.close;
adoquery1.SQL.Add('select * from spsellsum where 销售日期>=:date1 and 销售日期<=:date2 ');
adoquery1.Parameters.ParamByName('date1').Value:=datetostr(datetimepicker1.Date);
adoquery1.Parameters.ParamByName('date2').Value:=datetostr(datetimepicker2.Date);
adoquery1.open;
现在我的问题是:
1。如果checkbox没有选中,查询内容只是combobox的条件,
2。如果checkbox有选中,查询内容是combobox的条件+ 两个DateTimePicker 条件。
现在Edit1Change应该要怎么写?
请帮忙写一下完整的判断条件代码
[解决办法]
if not CheckBox1.Checked thenbeginadoquery1.Close; adoquery1.SQL.Clear; adoquery1.SQL.Add('select * from spsellsum where 客户 like ''%'+edit1.text+'%'''); endelse beginadoquery1.sql.close; adoquery1.SQL.Add('select * from spsellsum where 客户 like ''%'+edit1.text+'%'' and 销售日期>=:date1 and 销售日期 <=:date2 '); adoquery1.Parameters.ParamByName('date1').Value:=datetostr(datetimepicker1.Date); adoquery1.Parameters.ParamByName('date2').Value:=datetostr(datetimepicker2.Date); end;adoquery1.open;
[解决办法]
if not CheckBox1.Checked then begin adoquery1.Close; adoquery1.SQL.Clear; adoquery1.SQL.Add('select * from spsellsum where 客户 like ''%'+edit1.text+'%'''); end else begin adoquery1.sql.close; adoquery1.SQL.Clear; adoquery1.SQL.Add('select * from spsellsum where '+ComboBox1.Text+ ' like ''%'+edit1.text+'%'' and 销售日期>=:date1 and 销售日期 <=:date2 '); adoquery1.Parameters.ParamByName('date1').Value:=datetostr(datetimepicker1.Date); adoquery1.Parameters.ParamByName('date2').Value:=datetostr(datetimepicker2.Date); end; adoquery1.open;
[解决办法]
还发现个问题
如果你combo中text和数据库中字段名相同没有必要判断每个combo选项情况
就算不同也可以用个array代替
adoquery1.SQL.Add('select * from spsellsum where'+combobox1.Text+' like ''%'+edit1.text+'%''');