unit3.pas

来自「数据库编程 人事档案管理」· PAS 代码 · 共 123 行

PAS
123
字号
unit Unit3;

interface

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

type
  TForm3 = class(TForm)
    Query1: TQuery;
    DataSource1: TDataSource;
    DBGrid1: TDBGrid;
    RG: TRadioGroup;
    Edit1: TEdit;
    Button1: TButton;
    Button2: TButton;
    procedure Button2Click(Sender: TObject);
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form3: TForm3;

implementation

{$R *.dfm}

procedure TForm3.Button2Click(Sender: TObject);
begin
close;
end;

procedure TForm3.Button1Click(Sender: TObject);
var
temp:string;
mysql:string;
begin
case rg.ItemIndex of
0:begin
   if length(trim(edit1.Text ))=0 then
   begin
   messagedlg('没有输入人员编号,重新输入',mterror,[mbok],0);
   edit1.SetFocus ;
   exit;
   end;
   with query1 do
   begin
   close;
   sql.Clear ;
   sql.Add('select * from ''basicinfo''');
   sql.Add('where id=:id');
   parambyname('id').AsString :=trim(edit1.Text );
   open;
   if recordcount>0 then
   dbgrid1.Enabled :=true
   else
   begin
   messagedlg('所要查找的人员并不存在,请您重新核对',mtinformation,[mbok],0);
   dbgrid1.Enabled :=false;
   end;
   end;
   end;

1:begin
   if length(trim(edit1.Text ))=0 then
   begin
   messagedlg('没有输入人员姓名,重新输入',mterror,[mbok],0);
   edit1.SetFocus ;
   exit;
   end;
   temp:='%'+trim(edit1.Text )+'%';
   mysql:=format('select * from ''basicinfo'' where name like ''%s''',[temp]);
   with query1 do
   begin
   close;
   sql.Clear ;
   sql.Text :=mysql;
   open;
   if recordcount>0 then
   dbgrid1.Enabled :=true
   else
   begin
   messagedlg('所要查找的人员并不存在,请您重新核对',mtinformation,[mbok],0);
   dbgrid1.Enabled :=false;
   end;
   end;
   end;

2:begin
 if length(trim(edit1.Text ))=0 then
   begin
   messagedlg('没有输入人员性别,重新输入',mterror,[mbok],0);
   edit1.SetFocus ;
   exit;
   end;
   with query1 do
   begin
     temp:=edit1.text;
     close;
   sql.Clear ;
   sql.Add('select * from ''basicinfo''');
   sql.Add('where sex=:temp');
   parambyname('temp').AsString :=temp;
   open;
   if recordcount>0 then
   dbgrid1.Enabled :=true
   else
   begin
   messagedlg('所要查找的人员并不存在,请您重新核对',mtinformation,[mbok],0);
   dbgrid1.Enabled :=false;
   end;
   end;
   end;
   end;
end;

end.
 

⌨️ 快捷键说明

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