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

📄 personnelsql.pas

📁 需要使用Delphi 7.0及以上版本才能将它们打开
💻 PAS
字号:
unit PersonnelSQL;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, ExtCtrls, RpDefine, RpRave, Grids, DBGrids;

type
  TPersonnelSQLFrm = class(TForm)
    Label1: TLabel;
    Panel1: TPanel;
    Panel2: TPanel;
    Panel3: TPanel;
    Label2: TLabel;
    ComboBox1: TComboBox;
    Label3: TLabel;
    Label4: TLabel;
    ComboBox3: TComboBox;
    Label5: TLabel;
    Label6: TLabel;
    Label7: TLabel;
    ComboBox6: TComboBox;
    Button1: TButton;
    Button2: TButton;
    ComboBox4: TComboBox;
    ComboBox2: TComboBox;
    ComboBox5: TComboBox;
    Label8: TLabel;
    presonG: TStringGrid;
    procedure Button2Click(Sender: TObject); 
    procedure Button1Click(Sender: TObject);



  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  PersonnelSQLFrm: TPersonnelSQLFrm;
  condition1,condition2,condition3:string;
  str,str1,str2,str3:string;
 
implementation
   uses PersonnelDataDM,PersonnelManage;
{$R *.dfm}

procedure TPersonnelSQLFrm.Button2Click(Sender: TObject);
begin
    PersonnelManageFrm.show;
    PersonnelSQLFrm.Close;
end;

procedure TPersonnelSQLFrm.Button1Click(Sender: TObject);
var i,j:integer;
begin
   //定义表格
   with presonG do
    begin
     cells[0,0]:='职工代码';
     cells[1,0]:='姓名';
     cells[2,0]:='性别';
     cells[3,0]:='出生日期';
     cells[4,0]:='籍贯';
     cells[5,0]:='民族';
     cells[6,0]:='政治面貌';
     cells[7,0]:='文化程度';
     cells[8,0]:='婚姻状况';
     cells[9,0]:='毕业院校';
     cells[10,0]:='所学专业';
     cells[11,0]:='个人专长';
     cells[12,0]:='工种';
     cells[13,0]:='职务';
     cells[14,0]:='家庭住址';
     cells[15,0]:='邮政编码';
     cells[16,0]:='住宅电话';
     cells[17,0]:='手机号码';
     cells[18,0]:='电子邮件';
     cells[19,0]:='身份证号码';
     cells[20,0]:='个人简历';
     cells[21,0]:='个人工作资料档案';
    end;
   str:='';

   //条件一查询
   str1:=Combobox1.Text;
   //查询条件转换
   if  str1='职工编号' then
      condition1:='EmployeeID';
   if  (condition1<>'') and (combobox2.Text<>'') then
         str:=str+' or '+condition1+'='+ combobox2.Text;

    //条件二查询
    str2:=Combobox3.Text;
    //查询条件转换
    if str2='姓名' then
        condition2:='Name';
    if str2='性别' then
        condition2:='Sex';
    if str2='籍贯' then
        condition2:='City';
    if str2='民族' then
        condition2:='Nation';
    if str2='政治面貌' then
        condition2:='Polity';
    if str2='文化程度' then
        condition2:='Culture';
    if str2='工种' then
        condition2:='WType';
    if str2='职务' then
        condition2:='Duty';
    if str2='邮政编码' then
        condition2:='Postalcode';
    if str2='身份证号码' then
        condition2:='IDcard';
    if  (condition2<>'') and (combobox4.Text<>'') then
         str:=str+' or '+condition2+'='''+ combobox4.Text+'''';

    //条件三查询
    str3:=Combobox5.Text;
    //查询条件转换
    if str3='姓名' then
        condition3:='Name';
    if str3='性别' then
        condition3:='Sex';
    if str3='籍贯' then
        condition3:='City';
    if str3='民族' then
        condition3:='Nation';
    if str3='政治面貌' then
        condition3:='Polity';
    if str3='文化程度' then
        condition3:='Culture';
    if str3='工种' then
        condition3:='WType';
    if str3='职务' then
        condition3:='Duty';
    if str3='邮政编码' then
        condition3:='Postalcode';
    if str3='身份证号码' then
        condition3:='IDcard';
    if str3='毕业院校' then
        condition3:='Graduate';
    if str3='所学专业' then
        condition3:='Spec';
    if str3='家庭住址' then
        condition3:='Address';
    if str3='住宅电话' then
        condition3:='HomePhone';
    if str3='手机号码' then
        condition3:='Mo_phone';
    if str3='电子邮件' then
        condition3:='Email';
    if  (condition3<>'') and (combobox6.Text<>'') then
         str:=str+' or '+condition3+' like ''%'+combobox6.Text+'%''';

   try
   with PersonnelData.ADOQuery1 do
      begin
       PersonnelData.ADOQuery1.Active:=false;
       close;
       SQL.clear;
       sql.add('Select * from preson_info where EmployeeID<'+'0'+str);
       open;
       PersonnelData.ADOQuery1.Active:=true;

       //清空表格
        with presonG do
          begin
          presonG.RowCount:=PersonnelData.ADOQuery1.RecordCount+1;
          for i:=1 to PersonnelData.ADOQuery1.RecordCount do
            for j:=0 to 21 do
             cells[j,i]:='';
          end;
       first;
        with presonG do
          for i:=1 to PersonnelData.ADOQuery1.RecordCount do
            begin
             cells[0,i]:=fieldbyname('EmployeeID').AsString;
             cells[1,i]:=fieldbyname('Name').AsString;
             cells[2,i]:=fieldbyname('Sex').AsString;
             cells[3,i]:=fieldbyname('Date').AsString;
             cells[4,i]:=fieldbyname('City').AsString;
             cells[5,i]:=fieldbyname('Nation').AsString;
             cells[6,i]:=fieldbyname('Polity').AsString;
             cells[7,i]:=fieldbyname('Culture').AsString;
             cells[8,i]:=fieldbyname('Marry').AsString;
             cells[9,i]:=fieldbyname('Graduate').AsString;
             cells[10,i]:=fieldbyname('Spec').AsString;
             cells[11,i]:=fieldbyname('Speci').AsString;
             cells[12,i]:=fieldbyname('WType').AsString;
             cells[13,i]:=fieldbyname('Duty').AsString;
             cells[14,i]:=fieldbyname('Address').AsString;
             cells[15,i]:=fieldbyname('Postalcode').AsString;
             cells[16,i]:=fieldbyname('HomePhone').AsString;
             cells[17,i]:=fieldbyname('Mo_phone').AsString;
             cells[18,i]:=fieldbyname('Email').AsString;
             cells[19,i]:=fieldbyname('IDcard').AsString;
             cells[20,i]:=fieldbyname('Resume').AsString;
             cells[21,i]:=fieldbyname('Work').AsString;
             next;
            end;
       end;
   except
    Application.MessageBox('查询语句有错误','异常错误',mb_iconwarning+mb_ok);
  end;
    //如果没有符合查询条件的数据,在窗体中提示
    if PersonnelData.ADOQuery1.RecordCount<1 then
       Application.MessageBox('没有找到符合条件的数据?','查询结果',MB_YESNO+MB_ICONQUESTION)

       
end;



end.

⌨️ 快捷键说明

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