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

📄 archmain.~pas

📁 档案信息管理系统
💻 ~PAS
字号:
//用于管理员工档案的代码,其中包括添加,删除,修改,查询,打印
//主要操作的数据库为StuffTable。

unit ArchMain;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, ComCtrls, ToolWin, Menus, StdCtrls, Buttons, ExtCtrls, Grids,
  DBGrids, DBCtrls, Mask;

type
  TStuffMain = class(TForm)
    PageControl1: TPageControl;
    tsInputArch: TTabSheet;
    tsMemo: TTabSheet;
    tsAdvancedSearch: TTabSheet;
    Splitter1: TSplitter;
    Splitter2: TSplitter;
    Label1: TLabel;
    edArchNo: TEdit;
    Label2: TLabel;
    edName: TEdit;
    Label3: TLabel;
    Label4: TLabel;
    Label7: TLabel;
    edDgree: TEdit;
    Label8: TLabel;
    edPosistion: TEdit;
    Label9: TLabel;
    Label10: TLabel;
    edAdress: TEdit;
    Label6: TLabel;
    edTelNo: TEdit;
    Label11: TLabel;
    Label5: TLabel;
    gbGender: TComboBox;
    gbDepName: TComboBox;
    edMemo: TMemo;
    Label12: TLabel;
    Label13: TLabel;
    edCompName: TEdit;
    edCompDep: TEdit;
    Label16: TLabel;
    cbCompOp: TComboBox;
    edCompArch: TEdit;
    Label14: TLabel;
    cbCompGender: TComboBox;
    Label17: TLabel;
    cbCompBirthday: TComboBox;
    Label15: TLabel;
    edCompDegree: TEdit;
    Label20: TLabel;
    cbCompCT: TComboBox;
    Label18: TLabel;
    Label19: TLabel;
    edCompBirthday: TMaskEdit;
    edCompJST: TMaskEdit;
    edCompJET: TMaskEdit;
    edCompCreateTime: TMaskEdit;
    edBirthday: TMaskEdit;
    edJobStartDate: TMaskEdit;
    edJobEndDate: TMaskEdit;
    GroupBox1: TGroupBox;
    DBGrid1: TDBGrid;
    GroupBox2: TGroupBox;
    btNewArch: TBitBtn;
    btModifyArch: TBitBtn;
    btDelArch: TBitBtn;
    btPrintArch: TBitBtn;
    btResetArch: TBitBtn;
    btSearchArch: TBitBtn;
    procedure FormShow(Sender: TObject);
    procedure btNewArchClick(Sender: TObject);
    procedure DBGrid1CellClick(Column: TColumn);
    procedure btModifyArchClick(Sender: TObject);
    procedure btResetArchClick(Sender: TObject);
    procedure btDelArchClick(Sender: TObject);
    procedure btSearchArchClick(Sender: TObject);
    procedure btPrintArchClick(Sender: TObject);
    procedure tsAdvancedSearchShow(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);

  private
    { Private declarations }
  public
    printPage :String;   //指明当前处于哪个页面,根据不同的页面,打印的内容不同
    //在形成输入和选择界面时,首先加载可供选择的部门信息
    procedure LoadDepName();
    //根据情况选择各个按钮的活动状态
    procedure SetControlEnable(const nStuff,mStuff,dStuff,rStuff,sStuff,pStuff :Boolean);
  end;
var
  StuffMain: TStuffMain;
implementation
uses ArchDataClass,ArchDataModule,PrintSetup,printMemo,MainForm;
{$R *.dfm}

//从部门数据库中加载部门信息
procedure TStuffMain.LoadDepName();
var
    recordNumber , i: integer;
    depName : string;

begin
    recordNumber :=MainDataModule.DepTable.RecordCount;
    MainDataModule.DepTable.First;
    for i :=1 to recordNumber do
    begin
      depName :=MainDataModule.DepTable.FieldByName('DepName').AsString;
      gbDepName.Items.Add(depName);
      MainDataModule.DepTable.Next;
    end;
end;

procedure TStuffMain.FormShow(Sender: TObject);
begin
//------------------------------------------------
//根据当前最后一条记录的档案号自动生成档案号
    MainDataModule.DepTable.Filtered :=false;
    LoadDepName;
    MainDataModule.StuffTable.Last;
    edArchNo.Text :=IntToStr(MainDataModule.StuffTable.FieldByName('ArchiveNo').AsInteger+1);
//----------------------------------------------------------
    SetControlEnable(true,false,false,true,false,false);
end;

//----------------------------
//添加一条新的档案记录
//------------------------------
procedure TStuffMain.btNewArchClick(Sender: TObject);
var
  StuffInfo :InputStuffInfo;
  stuffManager :StuffDBManager;
begin
//创建一个用于管理输入信息的类StuffInfo,
//该类定义于ArchDataClass单元中
  StuffInfo :=InputStuffInfo.Create;
//创建一个用于实现数据库操作的类StuffManager,
//该类定义于ArchDataClass单元中
  StuffManager :=StuffDBManager.Create;
//合法性检查
  if StuffInfo.ValidCheck <> 1  then
      begin
        if StuffInfo.ValidCheck=2 then
           begin
             Application.MessageBox('输入的数据类型错误,请重新输入','输入错误',MB_OK);
             exit;
           end
        else
           if Application.MessageBox('确认要添加该记录吗','确认操作',MB_OKCANCEL)=1 then
           begin
               StuffInfo.SetStuffInfo;
               StuffManager.AddModifyStuffInfo(1,StuffInfo);
           end
      end
      else
        begin
          Application.MessageBox('上述信息不能为空,请重新输入','输入错误',MB_OK);
          exit;
        end;
//清空输入框中的内容
      StuffInfo.ZeroStuffInput;
      StuffInfo.Free;
      StuffManager.Free;
      MainDataModule.StuffQuery.Active :=False;
      MainDataModule.StuffQuery.Active :=True;
      PageControl1.ActivePage :=tsInputArch;
      SetControlEnable(true,false,false,true,false,false);
end;

//------------------------------------------------------
//当用户单击记录列表时,将所选记录的信息加载到输入框中
//以便继续对其进行修改
//------------------------------------------------------
procedure TStuffMain.DBGrid1CellClick(Column: TColumn);
var
  StuffInfo :InputStuffInfo;
begin
  StuffInfo :=InputStuffInfo.Create;
  StuffInfo.LoadStuffInfo;
  StuffInfo.Free;
  SetControlEnable(false,true,true,true,true,true);
//----------------------------------------------
//记录当前所选记录,以备后面打印该记录的信息
//-----------------------------------------------
  MainDataModule.selectRecord.Active :=false;
  MainDataModule.selectRecord.Active :=true;
  MainDataModule.selectRecord.Filtered :=false;
  MainDataModule.selectRecord.Filter :='ArchiveNo = '+IntToSTr(MainDataModule.StuffQuery.FieldByName('ArchiveNo').AsInteger);
  MainDataModule.selectRecord.Filtered :=true;
//--------------------------------------------------
end;

//------------------------------------------------
//修改一条记录内容
//-----------------------
procedure TStuffMain.btModifyArchClick(Sender: TObject);
var
  StuffInfo :InputStuffInfo;
  stuffManager :StuffDBManager;
begin
  StuffInfo :=InputStuffInfo.Create;
  StuffManager :=StuffDBManager.Create;
  if StuffInfo.ValidCheck <> 1  then
      begin
        if StuffInfo.ValidCheck=2 then
           begin
             Application.MessageBox('输入的数据类型错误,请重新输入','输入错误',MB_OK);
             exit;
           end
        else
           if Application.MessageBox('确认要修改该记录吗','确认操作',MB_OKCANCEL)=1 then
           begin
               StuffInfo.SetStuffInfo;
               StuffManager.AddModifyStuffInfo(2,StuffInfo);
           end
      end
      else
        begin
          Application.MessageBox('上述信息不能为空,请重新输入','输入错误',MB_OK);
          exit;
        end;
      StuffInfo.ZeroStuffInput;
      StuffInfo.Free;
      StuffManager.Free;
///////////////////////////////
//重新激活查询 StuffQuery
////////////////////////////////
      MainDataModule.StuffQuery.Active :=False;
      MainDataModule.StuffQuery.Active :=True;
//////////////////////////////////////
      PageControl1.ActivePage :=tsInputArch;//基本信息页面下
      SetControlEnable(true,false,false,true,false,false);
end;

//////////////////////
//重置输入框中的信息
//////////////////////
procedure TStuffMain.btResetArchClick(Sender: TObject);
var
    StuffInfo : InputStuffInfo;
begin
    StuffInfo :=InputStuffInfo.Create;
    StuffInfo.ZeroStuffInput;
    StuffInfo.Free;
    SetControlEnable(true,false,false,true,false,false);
end;


/////////////////////
//删除一条存在的记录
/////////////////////
procedure TStuffMain.btDelArchClick(Sender: TObject);
  Var
    StuffInfo : InputStuffInfo;
    StuffManager :StuffDBManager;
begin
    StuffInfo :=InputStuffInfo.Create;
    StuffManager :=StuffDBManager.Create;
    if Application.MessageBox('确认要删除当前记录吗','确认操作',MB_OKCANCEL)=1 then
        StuffManager.DelStuffInfo;
    StuffInfo.ZeroStuffInput;
    MainDataModule.StuffTable.First;
    PageControl1.ActivePage :=tsInputArch;
    StuffInfo.Free;
    StuffManager.Free;
    MainDataModule.StuffQuery.Active :=false;
    MainDataModule.StuffQuery.Active :=true;
    SetControlEnable(true,false,false,true,false,false);
end;

/////////////////////////
//设置各个按钮的活动属性
////////////////////////
procedure TStuffMain.SetControlEnable(const nStuff,mStuff,dStuff,rStuff,sStuff,pStuff:Boolean);
begin
    btNewArch.Enabled :=nStuff;
    btResetArch.Enabled :=rStuff;
    btPrintArch.Enabled :=pStuff;
    btModifyArch.Enabled :=mStuff;
    btDelArch.Enabled :=dStuff;
    btSearchArch.Enabled :=sStuff;
end;

/////////////////////
//完成档案的查询操作
/////////////////////
procedure TStuffMain.btSearchArchClick(Sender: TObject);
var
  SqlStr :AnsiString; //查询字符串
  Condition :ConditionInfo; //管理查询输入框中的内容
  strlength :integer;  //查询字符串的长度
  StuffInfo :InputStuffInfo; //管理输入框中的内容
begin
    Condition :=ConditionInfo.Create;
    if Condition.ValidCheck()=1 then
      begin
        Application.MessageBox('日期输入格式错误,请重新输入','错误的输入',MB_OK);
        exit;
      end;
//    重置StuffQuery的filter属性
    MainDataModule.StuffQuery.Active :=false;
    MainDataModule.StuffQuery.Filter :='';
    MainDataModule.StuffQuery.Active :=true;
//拼接查询字符串
    SqlStr :='';
    if cbCompOp.Text <>'' then
        SqlStr :='ArchiveNo'+cbCompOp.Text;
    if edCompArch.Text <>'' then
        SqlStr :=SqlStr+edCompArch.Text+' AND ';
    if edCompName.Text <>''then
        SqlStr :=SqlStr+'Name='+quotedStr(edCompName.Text)+' AND ';
    if cbCompGender.Text <>''then
        SqlStr :=SqlStr+'Gender='+quotedStr(cbCompGender.Text)+' AND ';
    if cbCompBirthday.Text <>'' then
        SqlStr :=SqlStr+'Birthday'+cbCompBirthday.Text;
    if edCompBirthday.Text <> '  -  -  ' then
        SqlStr :=SqlStr+quotedStr(edCompBirthday.Text)+' AND ';
    if edCompDegree.Text<> ''then
        SqlStr :=SqlStr+'Degree='+quotedStr(edCompDegree.Text)+' AND ';
    if cbCompCT.Text<> ''then
        SqlStr :=SqlStr+'CreateTime'+cbCompCT.Text;
    if edCompCreateTime.Text <>'  -  -  'then
        SqlStr :=SqlStr+quotedStr(edCompCreateTime.Text)+' AND ';
    if edCompJST.Text<>'  -  -  ' then
        SqlStr :=SqlStr+quotedStr(edCompJST.Text)+' AND ';
    if edCompJET.Text <>'  -  -  ' then
        SqlStr :=SqlStr+quotedStr(edCompJET.Text)+' And ';
    strLength :=Length(SqlStr);
    strLength :=StrLength-5;
    SqlStr :=Copy(SqlStr,1,strLength);
//设置Filter属性,完成查询
    MainDataModule.StuffQuery.Filter :=SqlStr;
    MainDataModule.StuffQuery.Filtered :=true;
    Condition.ZeroContionInput;
    Condition.Free;
    if MainDataModule.StuffQuery.RecordCount = 0 then
      SetControlEnable(false,false,false,false,true,false)
    else
      SetControlEnable(false,false,false,false,true,true);
    StuffInfo :=InputStuffInfo.Create;
    StuffInfo.ZeroStuffInput;
end;

//实现打印
procedure TStuffMain.btPrintArchClick(Sender: TObject);
begin
    if (MainDataModule.StuffQuery.RecordCount = 0) and (MainDataModule.selectRecord.RecordCount =0) then
    begin
      Application.MessageBox('没有想查看的记录','空记录',MB_OK);
      exit;
    end;
    PrintSetupForm :=TPrintSetupForm.Create(Application);
    PrintSetupForm.Show;
end;

procedure TStuffMain.tsAdvancedSearchShow(Sender: TObject);
begin
   SetControlEnable(false,false,false,true,true,false);
end;

procedure TStuffMain.FormClose(Sender: TObject; var Action: TCloseAction);
begin
//设置菜单选项的有效性
   ArchMainForm.archsearch.Enabled :=true;
   ArchMainForm.archMenu.Enabled :=true;
   StuffMain.Release;
end;

end.

⌨️ 快捷键说明

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