⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 searchunit.pas

📁 人事管理源码 Delphi+ADO+Acce
💻 PAS
📖 第 1 页 / 共 2 页
字号:
    begin
      termlist.Items.Delete(termlist.ItemIndex);
      if (termlist.Items.Count > 0) then
        begin
         str := termlist.Items.Strings[0];
          if (copy(str,0,3) = 'and') or (copy(str,0,3) = 'or ') then
            begin
              str := copy(str,4,length(str));
              termlist.Items.Strings[0] :=  str;
            end;
        end;
    end;
end;

procedure TSearchForm.AddBtnClick(Sender: TObject);
var
  tempstr,Person,datatype:string;
  LogicOper:string;
begin
  inherited;
  if andradbtn.Checked then
    logicoper := 'and('
  else
    logicoper := 'or (';
    
  case tag of    //
    0: person := 'ZZ';
    1: person := 'NT';
    2: person := 'TY';
    3: person := 'TX';
    4: person := 'JS';
  end;    // case

  case Termitems.Tag of    //
    1: datatype := 'Stri';
    2: datatype := 'Numb';
    3: datatype := 'Date';
  end;    // case

  case Termitems.Tag of
    0:begin
        messagebox(application.Handle,'请选择搜索关键字!','提示',MB_OK+MB_ICONWARNING);
        Termitems.SetFocus;
      end;
    1:begin  //字符型
        if trim(stredit.Text) = '' then
          begin
            messagebox(application.Handle,'请输入搜索的字符!','提示',MB_OK+MB_ICONWARNING);
            stredit.SetFocus;
          end
        else
          begin
            if termlist.Items.Count = 0 then
              begin
                tempstr := '(' + GetField(Person,termitems.Text) + ' ' +
                           GetOper(datatype,OperList.Text) + ' ' +
                           '''' + '%' + trim(stredit.Text) + '%' + '''' + ')';
                termlist.Items.Add(tempstr);
              end
            else
              begin
                tempstr := logicoper + GetField(Person,Termitems.Text) + ' ' +
                           getoper(datatype,OperList.Text) +
                           '''' + '%' + trim(stredit.Text) + '%' + '''' + ')';
                termlist.Items.Add(tempstr);
              end;
          end;
      end;
    2:begin //数值型
        if trim(OperList.Text) <> '介于' then
          begin
            if trim(num1.Text) = '' then
              begin
                messagebox(application.Handle,'数据1不能为空!','提示',MB_OK+MB_ICONWARNING);
                num1.SetFocus;
              end
            else
              begin
                if termlist.Items.Count = 0 then
                  begin
                    tempstr := '(' + GetField(Person,Termitems.Text) + ' '+
                              getoper(datatype,OperList.Text) + ' ' +
                              trim(Num1.Text) + ')' ;
                    termlist.Items.Add(tempstr);
                  end
                else
                  begin
                  tempstr := logicoper + GetField(Person,Termitems.Text) + ' ' +
                             getoper(datatype,OperList.Text) + ' ' +
                             trim(Num1.Text) + ')';
                  termlist.Items.Add(tempstr);
                  end;
              end;
          end
        else
          begin
            if trim(num2.Text) = '' then
              begin
                messagebox(application.Handle,'数据2不能为空!','提示',MB_OK+MB_ICONWARNING);
                num2.SetFocus;
              end
            else
              begin
                if termlist.Items.Count = 0 then
                  begin
                    tempstr := '(' + GetField(Person,Termitems.Text) + ' '+
                              getoper(datatype,OperList.Text) + ' ' +
                              trim(Num1.Text) +
                              ' and ' +
                              trim(num2.Text)+ ')' ;
                    termlist.Items.Add(tempstr);
                  end
                else
                  begin
                    tempstr := logicoper + GetField(Person,Termitems.Text) + ' '+
                              getoper(datatype,OperList.Text) + ' ' +
                              trim(Num1.Text) +
                              ' and ' +
                              trim(num2.Text)+ ')' ;
                    termlist.Items.Add(tempstr);
                  end;
              end;
          end;

      end;
    3:begin //日期型
        if trim(OperList.Text) <> '介于' then
          begin
            if trim(date1.Text) = '' then
              begin
                messagebox(application.Handle,'日期1不能为空!','提示',MB_OK+MB_ICONWARNING);
                date1.SetFocus;
              end
            else
              begin
                if termlist.Items.Count = 0 then
                  begin
                    tempstr := '(' + GetField(Person,Termitems.Text) + ' '+
                              getoper(datatype,OperList.Text) +
                               '''' + trim(date1.Text) + '''' + ')' ;
                    termlist.Items.Add(tempstr);
                  end
                else
                  begin
                  tempstr := logicoper + GetField(Person,Termitems.Text) + ' ' +
                             getoper(datatype,OperList.Text) +
                             '''' + trim(date1.Text) + '''' + ')';
                  termlist.Items.Add(tempstr);
                  end;
              end;
          end
        else
          begin
            if trim(date2.Text) = '' then
              begin
                messagebox(application.Handle,'日期2不能为空!','提示',MB_OK+MB_ICONWARNING);
                date2.SetFocus;
              end
            else
              begin
                if termlist.Items.Count = 0 then
                  begin
                    tempstr := '(' + GetField(Person,Termitems.Text) + ' '+
                              getoper(datatype,OperList.Text) +
                              '''' + trim(date1.Text) + '''' +
                              ' and ' +
                              '''' + trim(date2.Text) + '''' + ')' ;
                    termlist.Items.Add(tempstr);
                  end
                else
                  begin
                    tempstr := logicoper + GetField(Person,Termitems.Text) + ' '+
                              getoper(datatype,OperList.Text) +
                              '''' + trim(date1.Text) + '''' +
                              ' and ' +
                              '''' + trim(date2.Text) + '''' + ')' ;
                    termlist.Items.Add(tempstr);
                  end;
              end;
          end;

      end;
  end;    // case
end;

procedure TSearchForm.date2Enter(Sender: TObject);
begin
  inherited;
  if trim(date1.Text) = '' then
    begin
      messagebox(application.Handle,'日期1不能为空!','提示',MB_OK+MB_ICONWARNING);
      date1.SetFocus;
    end;

end;

procedure TSearchForm.Num2Enter(Sender: TObject);
begin
  inherited;
  if trim(Num1.Text) = '' then
    begin
      messagebox(application.Handle,'数据1不能为空!','提示',MB_OK+MB_ICONWARNING);
      Num1.SetFocus;
    end;
end;

procedure TSearchForm.TermitemsChange(Sender: TObject);
var
  I: Integer;
  myitem:item;
  myitemfile:itemfile;
begin
  inherited;
  OperList.Clear;
  if fileexists(filepath+'searchitems.dat') then
    begin
      assignfile(myitemfile,filepath+'searchitems.dat');
      reset(myitemfile);
      for I := 0 to filesize(myitemfile) - 1 do    // Iterate
      begin
      seek(myitemfile,i);
      read(myitemfile,myitem);
        if myitem.CHname = Termitems.Text then
          begin
            if myitem.datatype ='Stri' then
              begin
                Termitems.Tag := 1;
                GetOperList('Stri');
              end
            else if myitem.datatype = 'Numb' then
              begin
                Termitems.Tag := 2;
                GetOperList('Numb');
              end
            else if myitem.datatype = 'Date' then
              begin
                Termitems.Tag := 3;
                GetOperList('Date');
              end;
          end;
      end;    // for
    end
  else
    begin
      messagebox(application.Handle,'文件不存在,不能完成初始化!','警告',MB_OK+MB_ICONWARNING);
      close;
    end;
end;

procedure TSearchForm.date1Enter(Sender: TObject);
begin
  inherited;
  if OperList.ItemIndex < 0 then
    begin
      messagebox(application.Handle,'请选择搜索关系!','提示',MB_OK+MB_ICONWARNING);
      OperList.SetFocus;
    end;
end;

procedure TSearchForm.OperListEnter(Sender: TObject);
begin
  inherited;
  if Termitems.ItemIndex < 0 then
    begin
      messagebox(application.Handle,'请选择项目!','提示',MB_OK+MB_ICONWARNING);
      Termitems.SetFocus;
    end;

end;

procedure TSearchForm.termlistClick(Sender: TObject);
begin
  inherited;
  caption := Termlist.Items.Strings[termlist.itemindex];
end;

procedure TSearchForm.SearchBtnClick(Sender: TObject);
var
  I,j : Integer;
  SelItems : tstrings;
  person,tempstr : string;
begin
  inherited;
  for j := 0 to searchitems.Items.Count - 1 do    // Iterate
  begin
    if searchitems.Checked[j] then
      break
    else
      begin
        messagebox(application.Handle,'至少要选择一个项目!','提示',MB_OK+MB_ICONWARNING);
        searchitems.SetFocus;
        exit;
      end;
  end;

  if termlist.Items.Count = 0 then
    begin
      messagebox(application.Handle,'缺少查询条件!','提示',MB_OK+MB_ICONWARNING);
      Termitems.SetFocus;
      exit;
    end;
    
    case tag of    //
    0: person := 'ZZ';
    1: person := 'NT';
    2: person := 'TY';
    3: person := 'TX';
    4: person := 'JS';
  end;    // case

  dataform.SearchQuy.SQL.Clear;
  dataform.SearchQuy.SQL.Add('select');
    selitems := tstringlist.Create;
  try
    for I := 0 to searchitems.Items.Count - 1 do    // 添加查询的项目
    begin
      if searchitems.Checked[i] then
        begin
          tempstr := GetField(person,trim(searchitems.Items.Strings[i]));
          if SelItems.Count = 0 then
            SelItems.Add('( '+tempstr+') as '+ searchitems.Items.Strings[i])
          else
            SelItems.Add(',( '+tempstr+') as '+ searchitems.Items.Strings[i]);
        end;
    end;    // for
    dataform.SearchQuy.SQL.AddStrings(SelItems);
  finally
    SelItems.Destroy;
  end;

  dataform.SearchQuy.SQL.Add('from main,dw');
  dataform.SearchQuy.SQL.Add('where');
  dataform.SearchQuy.SQL.AddStrings(termlist.Items);
  dataform.SearchQuy.SQL.Add('and(main.dw_id=dw.dw_id)');

  if tag <> 5 then
  dataform.SearchQuy.SQL.Add('and(ZT='+''''+person+''''+')');

  dataform.SearchQuy.Open;
  searchgrid.DestroyColumns;
  SearchGrid.CreateDefaultColumns(dataform.Searchquy,SearchGrid);
  savebtn.Enabled := true;
end;

procedure TSearchForm.SaveBtnClick(Sender: TObject);
begin
  inherited;
 if savedialog1.Execute then
  begin
    case savedialog1.FilterIndex of    //
      1:begin
          savedialog1.DefaultExt := 'xls';
          SearchGrid.SaveToXLS(savedialog1.FileName,true);
        end;
      2:begin
          savedialog1.DefaultExt := 'txt';
          SearchGrid.SaveToText(savedialog1.FileName,true,'|','|','|');
        end;
      3:begin
          savedialog1.DefaultExt := 'html';
          SearchGrid.SaveToHTML(savedialog1.FileName,true);
        end;
    end;    // case
  end;    // with
end;

procedure TSearchForm.CancelBtnClick(Sender: TObject);
begin
  inherited;
  close;
end;

procedure TSearchForm.OKBtnClick(Sender: TObject);
begin
  inherited;
  close;
end;

end.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -