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

📄 gzffbz.pas

📁 人事管理
💻 PAS
字号:
unit gzffbz;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, Buttons, Grids, DBGrids, DB, ADODB, Mask, DBCtrls;

type
  Tfrmgzffbz = class(TForm)
    GroupBox1: TGroupBox;
    Label1: TLabel;
    Label2: TLabel;
    Label3: TLabel;
    Label4: TLabel;
    Label5: TLabel;
    edposition: TEdit;
    edgz: TEdit;
    edjj: TEdit;
    edgl: TEdit;
    writebtn: TBitBtn;
    modifybtn: TBitBtn;
    refreshbtn: TBitBtn;
    cancelbtn: TBitBtn;
    GroupBox2: TGroupBox;
    DBGrid1: TDBGrid;
    DataSource1: TDataSource;
    adgzffbzqry: TADOQuery;
    savebtn: TBitBtn;
    Label6: TLabel;
    ComboBox1: TComboBox;
    Edit1: TEdit;
    procedure FormCreate(Sender: TObject);
    procedure refreshbtnClick(Sender: TObject);
    procedure cancelbtnClick(Sender: TObject);
    procedure writebtnClick(Sender: TObject);
    procedure edgzKeyPress(Sender: TObject; var Key: Char);
    procedure edjjKeyPress(Sender: TObject; var Key: Char);
    procedure edglKeyPress(Sender: TObject; var Key: Char);
    procedure modifybtnClick(Sender: TObject);
    procedure savebtnClick(Sender: TObject);
    procedure ComboBox1Change(Sender: TObject);
   
 private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  frmgzffbz: Tfrmgzffbz;

implementation

uses datarsgl;

{$R *.dfm}

procedure Tfrmgzffbz.FormCreate(Sender: TObject);
begin
with dmrsgl.ygjbzlqry  do
begin
close;
sql.Clear;
sql.Add('select * from employeer');
open;
first;
while not eof do
begin
combobox1.Items.Add(fieldbyname('number').AsString);
next;
end; 
end;
adgzffbzqry.Connection:=dmrsgl.adorsgl;
adgzffbzqry.close;
adgzffbzqry.sql.Clear;
adgzffbzqry.sql.Add('select * from gzffbz');
adgzffbzqry.open;
datasource1.DataSet:=adgzffbzqry;
dbgrid1.DataSource:=datasource1;
dbgrid1.Columns[0].Field:=datasource1.DataSet.FieldByName('number');
dbgrid1.Columns[0].Width:=datasource1.DataSet.Fields[0].DisplayWidth+20;
dbgrid1.Columns[1].Field:=datasource1.DataSet.FieldByName('ygbm');
dbgrid1.Columns[1].Width:=datasource1.DataSet.Fields[1].DisplayWidth+20;
dbgrid1.Columns[2].Field:=datasource1.DataSet.FieldByName('position');
dbgrid1.Columns[2].Width:=datasource1.DataSet.Fields[2].DisplayWidth+20;
dbgrid1.Columns[3].Field:=datasource1.DataSet.FieldByName('work_time');
dbgrid1.Columns[3].Width:=datasource1.DataSet.Fields[3].DisplayWidth+20;
dbgrid1.Columns[4].Field:=datasource1.DataSet.FieldByName('yggz');
dbgrid1.Columns[4].Width:=datasource1.DataSet.Fields[4].DisplayWidth+20;
dbgrid1.Columns[5].Field:=datasource1.DataSet.FieldByName('ygjj');
dbgrid1.Columns[5].Width:=datasource1.DataSet.Fields[5].DisplayWidth+20;
end;
procedure Tfrmgzffbz.refreshbtnClick(Sender: TObject);
begin
adgzffbzqry.Connection:=dmrsgl.adorsgl;       //加载系统数据资料
adgzffbzqry.close;
adgzffbzqry.sql.Clear;
adgzffbzqry.sql.Add('select * from gzffbz');
adgzffbzqry.open;
datasource1.DataSet:=adgzffbzqry;
dbgrid1.DataSource:=datasource1;
dbgrid1.Columns[0].Field:=datasource1.DataSet.FieldByName('number');
dbgrid1.Columns[0].Width:=datasource1.DataSet.Fields[0].DisplayWidth+20;
dbgrid1.Columns[1].Field:=datasource1.DataSet.FieldByName('ygbm');
dbgrid1.Columns[1].Width:=datasource1.DataSet.Fields[1].DisplayWidth+20;
dbgrid1.Columns[2].Field:=datasource1.DataSet.FieldByName('position');
dbgrid1.Columns[2].Width:=datasource1.DataSet.Fields[2].DisplayWidth+20;
dbgrid1.Columns[3].Field:=datasource1.DataSet.FieldByName('work_time');
dbgrid1.Columns[3].Width:=datasource1.DataSet.Fields[3].DisplayWidth+20;
dbgrid1.Columns[4].Field:=datasource1.DataSet.FieldByName('yggz');
dbgrid1.Columns[4].Width:=datasource1.DataSet.Fields[4].DisplayWidth+20;
dbgrid1.Columns[5].Field:=datasource1.DataSet.FieldByName('ygjj');
dbgrid1.Columns[5].Width:=datasource1.DataSet.Fields[5].DisplayWidth+20;
end;

procedure Tfrmgzffbz.cancelbtnClick(Sender: TObject);
begin
close;
end;

procedure Tfrmgzffbz.writebtnClick(Sender: TObject);
begin
if combobox1.Text='' then
   begin
   messagedlg('编号不能为空',mterror,[mbyes],0);
   combobox1.SetFocus;
   exit;
   end
else
   begin
   if edposition.Text='' then
      begin
      messagedlg('具体职务不能为空.',mterror,[mbyes],0);
      edposition.SetFocus;
      exit;
      end
   else
      begin
      if edgz.Text='' then
         begin
         messagedlg('工资不能为空.',mterror,[mbyes],0);
         edgz.SetFocus;
         exit;
         end
      else
         begin
         if edjj.Text='' then
            begin
            messagedlg('奖金不能为空.',mterror,[mbyes],0);
            edjj.SetFocus;
            exit;
            end
         else
            begin
            if edgl.Text='' then
               begin
               messagedlg('工龄不能为空.',mterror,[mbyes],0);
               edgl.SetFocus;
               exit;
               end;
            end;
        end;
      end;
    end;
adgzffbzqry.Connection:=dmrsgl.adorsgl;
adgzffbzqry.Close;
adgzffbzqry.SQL.Clear;
adgzffbzqry.SQL.add('select * from gzffbz where number='+quotedstr(combobox1.Text));
adgzffbzqry.Open;
if adgzffbzqry.recordcount<>0 then
begin
messagedlg('已存在相同编号的数据记录,请重试.',mterror,[mbyes],0);
exit;
end
else
adgzffbzqry.Append;
adgzffbzqry.FieldByName('number').AsString:=trim(combobox1.Text);
adgzffbzqry.FieldByName('ygbm').AsString:=trim(edit1.Text);
adgzffbzqry.FieldByName('position').AsString:=trim(edposition.Text);
adgzffbzqry.FieldByName('work_time').AsInteger:=strtoint(trim(edgl.Text));
adgzffbzqry.FieldByName('yggz').AsInteger:=strtoint(trim(edgz.Text));
adgzffbzqry.FieldByName('ygjj').AsInteger:=strtoint(trim(edjj.Text));
if messagedlg('确认录入所写数据资料吗?',mtconfirmation,[mbyes,mbno],0)=mryes then
begin
adgzffbzqry.Post;
combobox1.Text:='';
edit1.Text:='';
edgz.Text:='';
edgl.Text:='';
edposition.Text:='';
edjj.Text:='';
combobox1.SetFocus;
end
else
messagedlg('你已取消本次录入操作.',mtinformation,[mbyes],0);
adgzffbzqry.Cancel;
combobox1.Text:='';
edit1.Text:='';
edgz.Text:='';
edgl.Text:='';
edposition.Text:='';
edjj.Text:='';
combobox1.SetFocus;
end;

procedure Tfrmgzffbz.edgzKeyPress(Sender: TObject; var Key: Char);
begin
if not(key in ['0'..'9',#8]) then
showmessage('请输入正确的数据,本项只能输入数字.');
end;

procedure Tfrmgzffbz.edjjKeyPress(Sender: TObject; var Key: Char);
begin
if not(key in ['0'..'9',#8]) then
showmessage('请输入正确的数据,本项只能输入数字.');
end;

procedure Tfrmgzffbz.edglKeyPress(Sender: TObject; var Key: Char);
begin
if not(key in ['0'..'9',#8]) then
showmessage('请输入正确的数据,本项只能输入数字.');
end;



procedure Tfrmgzffbz.modifybtnClick(Sender: TObject);
begin
combobox1.SetFocus;
savebtn.Visible:=true;
modifybtn.Visible:=false;
end;
procedure Tfrmgzffbz.savebtnClick(Sender: TObject);
begin
try
if combobox1.Text<>'' then
begin
adgzffbzqry.Connection:=dmrsgl.adorsgl;
adgzffbzqry.Close;
adgzffbzqry.SQL.Clear;
adgzffbzqry.SQL.add('select * from gzffbz');
adgzffbzqry.Open;
adgzffbzqry.Edit;
adgzffbzqry.FieldByName('number').AsString:=trim(combobox1.Text);
adgzffbzqry.FieldByName('ygbm').AsString:=trim(edit1.Text);
adgzffbzqry.FieldByName('position').AsString:=trim(edposition.Text);
adgzffbzqry.FieldByName('work_time').AsInteger:=strtoint(trim(edgl.Text));
adgzffbzqry.FieldByName('yggz').AsInteger:=strtoint(trim(edgz.Text));
adgzffbzqry.FieldByName('ygjj').AsInteger:=strtoint(trim(edjj.Text));
 if messagedlg('保存修改好的数据资料吗?',mtconfirmation,[mbyes,mbno],0)=mryes then
 begin
 adgzffbzqry.Post;
 combobox1.Text:='';
 edit1.Text:='';
 edgz.Text:='';
 edgl.Text:='';
 edposition.Text:='';
 edjj.Text:='';
 modifybtn.Visible:=true;
 savebtn.Visible:=false;
 combobox1.SetFocus;
 end
 else
 begin
 messagedlg('修改操作已经取消,请重新修改.',mtinformation,[mbyes],0);
 adgzffbzqry.Cancel;
 combobox1.Text:='';
 edit1.Text:='';
 edgz.Text:='';
 edgl.Text:='';
 edposition.Text:='';
 edjj.Text:='';
 modifybtn.Visible:=true;
 savebtn.Visible:=false;
 combobox1.SetFocus;
 end;
end 
else                                        //采用异常处理,可避免系统终止
showmessage('请填写完整部门资料.');
except
on edatabaseerror do
close;
end;
end;


procedure Tfrmgzffbz.ComboBox1Change(Sender: TObject);
begin
adgzffbzqry.Connection:=dmrsgl.adorsgl;   //读去该部门的数据资料
adgzffbzqry.Close;
adgzffbzqry.SQL.Clear;
adgzffbzqry.SQL.add('select * from gzffbz where number='+quotedstr(combobox1.Text));
adgzffbzqry.Open;
if adgzffbzqry.RecordCount<>0 then
begin
edit1.Text:=adgzffbzqry.fieldbyname('ygbm').AsString;
edposition.Text:=adgzffbzqry.fieldbyname('position').AsString;
edgz.Text:=inttostr(adgzffbzqry.FieldByName('yggz').AsInteger);
edjj.Text:=inttostr(adgzffbzqry.FieldByName('ygjj').AsInteger);
edgl.Text:=inttostr(adgzffbzqry.FieldByName('work_time').AsInteger);
end
else
messagedlg('该部门的数据还没录入到系统,稍后再试.',mterror,[mbyes],0);
modifybtn.Visible:=false;
savebtn.Visible:=true;
end;

end.

⌨️ 快捷键说明

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