combobox1  combobox2 edit1(datetimeedit1)  combobox9
combobox3  combobox4 edit2(datetimeedit2)  combobox10
combobox5  combobox6 edit3(datetimeedit3)  combobox11
combobox7  combobox8 edit4(datetimeedit4)  
其中combobox1 3 5 7.用于设置查询的关键字
其中combobox2 4 6 8.用于设置= > <> >= <= like <=条件
edit1(datetimeedit1)等用于设置输入的查询内容
combobox9 10 11用于设置逻辑关系
请问以下有什么好的实现方法,我有好多查询都一样,但是设及参数太多,有不知道怎么定义过程或函

解决方案 »

  1.   

    var
      sb_jjbgl_cx: Tsb_jjbgl_cx;
      Str1,Str3,Str5,Str7:string;//查询变量
      i1,i3,i5,i7:string;//取下拉框中的值
    implementationuses sb_azjls, sb_jjbgls;{$R *.dfm}
      

  2.   


    procedure Tsb_jjbgl_cx.FormClose(Sender: TObject;
      var Action: TCloseAction);
    begin
      action:=cafree;
      sb_jjbgl_cx:=nil;
    end;procedure Tsb_jjbgl_cx.ComboBox1Change(Sender: TObject);
    begin
     i1:='';
     case combobox1.ItemIndex of
      0: i1:='sbbh';
      1: i1:='sbmc';
      2: i1:='jbrq';
      3: i1:='jiaobr';
      4: i1:='jiebr';
      end;
    //========以上是获得下拉框中的值=============
        dbdatetimeediteh1.Visible:=false;
        edit1.visible:=true;combobox2.Enabled:=true;
     if combobox1.text='交班日期' then
      begin
       combobox2.Clear;
       combobox2.Items.Add('=');
       combobox2.Items.Add('<>');
       combobox2.Items.Add('>');
       combobox2.Items.Add('<');
       combobox2.Items.Add('>=');
       combobox2.Items.Add('<=');
      end
     else
      begin
       combobox2.Clear;
       combobox2.Items.Add('=');
       combobox2.Items.Add('<>');
       combobox2.Items.Add('模糊查询');
      end;
    end;
      

  3.   

    unit sb_jjbgl_cxs;interfaceuses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, StdCtrls, Buttons, Mask, DBCtrlsEh, ExtCtrls;
    procedure Tsb_jjbgl_cx.BitBtn1Click(Sender: TObject);
    var k:string;
    begin
      if (combobox1.Text='') then
      begin
        application.MessageBox('请输入查询条件','提示!',mb_ok);
        exit;
      end;
      if (combobox9.Text<>'')and((combobox3.Text='')or (combobox4.text=''))then
      begin
         application.MessageBox('不符合多条查询的条件','提示!',mb_ok);
         exit;
      end;//---------------
      if (combobox10.Text<>'')and((combobox5.Text='')or (combobox6.text=''))then
      begin
         application.MessageBox('不符合多条查询的条件','提示!',mb_ok);
         exit;
      end;//----------
      if (combobox11.Text<>'')and ((combobox7.Text='')or (combobox8.Text=''))then
      begin
         application.MessageBox('不符合多条查询的条件','提示!',mb_ok);
         exit;
      end;//-------------
      //----------------------------------------
      if (combobox1.Text<>'') and
        ((trim(edit1.Text)='') and (dbdatetimeediteh1.Text='    -  -  '))then
         begin
            application.MessageBox('查询条件不完全,请输入查询条件','提示!',mb_ok);
            exit;
         end;//---------------------------------------------------------------------
      if (combobox3.Text<>'') and
        ((trim(edit2.Text)='') and (dbdatetimeediteh2.Text='    -  -  '))then
         begin
            application.MessageBox('查询条件不完全,请输入查询条件','提示!',mb_ok);
            exit;
         end;//---------------------------------------------------------------------
      if (combobox5.Text<>'') and
       ((trim(edit3.Text)='') and (dbdatetimeediteh3.Text='    -  -  '))then
         begin
            application.MessageBox('查询条件不完全,请输入查询条件','提示!',mb_ok);
            exit;
         end;
      if (combobox7.Text<>'') and
       ((trim(edit4.Text)='') and (dbdatetimeediteh4.Text='    -  -  '))then
         begin
            application.MessageBox('查询条件不完全,请输入查询条件','提示!',mb_ok);
            exit;
         end;
     //-----------------------------------------------------------------------------
       str1:=' '; k:=' ';
        if combobox2.Text='模糊查询' then
        begin
           str1:=i1+' '+' like '+' '+''''+trim(edit1.Text)+'%'+'''';
        end
        else
        begin
           str1:=i1+' '+trim(combobox2.Text)+' '+''''+trim(edit1.Text)+'''';
        end;
        if combobox1.Text='交班日期'then
        begin
           str1:=i1+' '+trim(combobox2.Text)+' '+''''+trim(dbdatetimeediteh1.Text)+'''';
        end;
       case combobox9.ItemIndex of
        0: str1:=str1+' and ';
        1: str1:=STR1+' or ';
      end;//-----------------------
      k:=str1+' '+str3+' '+str5+' '+str7;
      sb_jjbgl.ClientDataSet1.close; //好像只能查一遍
      sb_jjbgl.ClientDataSet1.CommandText:='select * from sb_jjbjl where '+k;
      sb_jjbgl.ClientDataSet1.Open;
      if sb_jjbgl.ClientDataSet1.RecordCount=0 then
      begin
         if application.MessageBox('没有找到符合条件的记录'+#13#10+'是否重新搜索?','询问?',mb_okcancel+mb_iconquestion)=idok then
         begin
           combobox1.Text:='';combobox3.Text:='';combobox5.Text:='';combobox7.Text:='';
           combobox3.Enabled:=false;combobox5.Enabled:=false;combobox7.Enabled:=false;
         //-----------------------------------------------------------------------------
           combobox2.Enabled:=false;combobox4.Enabled:=false;combobox6.Enabled:=false;combobox8.Enabled:=false;
           combobox2.Clear;combobox4.Clear;combobox6.Clear;combobox8.Clear;
        //--------------------------------------------------------------------------
           edit1.Text:='';edit2.Text:='';edit3.Text:='';edit4.Text:='';
           edit1.Visible:=true;edit2.Visible:=true;edit3.Visible:=true;edit4.Visible:=true;
           edit1.Enabled:=false;edit2.Enabled:=false;edit3.Enabled:=false;edit4.Enabled:=false;
       //-----------------------------------------------------------------------------
           dbdatetimeediteh1.Visible:=false;dbdatetimeediteh2.Visible:=false;
           dbdatetimeediteh3.Visible:=false;dbdatetimeediteh4.Visible:=false;
           dbdatetimeediteh1.Text:='    -  -  ';dbdatetimeediteh2.Text:='    -  -  ';
           dbdatetimeediteh3.Text:='    -  -  ';dbdatetimeediteh4.Text:='    -  -  ';
       //------------------------------------------------------------------------------