procedure Tsearch.Button1Click(Sender: TObject);
var
sqlstr,sqlname,sqldate,sqltyp:string;
begin
main.query1.close;
main.query1.sql.clear;
sqlstr:='select * from main ';
if edit1.text='' then
sqlname:=''
else sqlname:=' where '+' name like'+'''%'+edit1.Text+'%''';
if (dateedit1.text='') and (dateedit2.text='') then
sqldate:=''
else if (dateedit1.text='') and (dateedit2.text<>'') then
sqldate:=' and gdate<='+datetostr(dateedit2.date)+''''
else if (dateedit1.text<>'') and (dateedit2.text='') then
sqldate:=' and gdate>='+datetostr(dateedit1.date)+''''
else if (dateedit1.text<>'') and (dateedit2.text<>'') then
begin
if dateedit1.date>dateedit2.date then
showmessage('起始时间不能大于结束时间!')
else
sqldate:=' and gdate>='+''''+datetostr(dateedit1.date)+''''+' and date<='+''''+datetostr(dateedit2.Date)+'''';
end;
main.Query1.SQL.Text:=sqlstr+sqlname+sqldate;
main.Query1.Open;
close;
if main.Query1.recordcount=0 then
showmessage('没有查询到符合条件的数据.');
end;