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

📄 unit_attendconfig.pas

📁 用delphi开发的美容院管理系统
💻 PAS
📖 第 1 页 / 共 2 页
字号:
unit Unit_AttendConfig;

interface

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

type
  Tfrm_attendconfig = class(TForm)
    Panel1: TPanel;
    PageControl1: TPageControl;
    sht_Time: TTabSheet;
    sht_Reason: TTabSheet;
    sbtn_front: TSpeedButton;
    sbtn_back: TSpeedButton;
    sbtn_append: TSpeedButton;
    sbtn_edit: TSpeedButton;
    sbtn_save: TSpeedButton;
    sbtn_delete: TSpeedButton;
    sbtn_close: TSpeedButton;
    sg_Time: TStringGrid;
    Label2: TLabel;
    Label3: TLabel;
    sg_Reason: TStringGrid;
    Label4: TLabel;
    edt_Reasonid: TEdit;
    Label6: TLabel;
    mm_remark: TMemo;
    GroupBox1: TGroupBox;
    GroupBox2: TGroupBox;
    cbb_Timename: TComboBox;
    Label5: TLabel;
    Label7: TLabel;
    dtp_timetime: TMaskEdit;
    procedure sbtn_closeClick(Sender: TObject);
    procedure sbtn_appendClick(Sender: TObject);
    procedure sbtn_editClick(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure sbtn_saveClick(Sender: TObject);
    procedure sbtn_deleteClick(Sender: TObject);
    procedure sbtn_backClick(Sender: TObject);
    procedure sbtn_frontClick(Sender: TObject);
    procedure sg_TimeSelectCell(Sender: TObject; ACol, ARow: Integer;
      var CanSelect: Boolean);
    procedure sg_ReasonSelectCell(Sender: TObject; ACol, ARow: Integer;
      var CanSelect: Boolean);
  private
    { Private declarations }
    TimeAppendOrEdit,ReasonAppendOrEdit:boolean;
    Reasonid:string;
    procedure SearchTimeInfo();
    procedure ClearTimeInfo();
    procedure MakeTimeEnabled(temp:boolean);
    function  SaveTimeInfo():boolean;

    procedure SearchReasonInfo();
    procedure ClearReasonInfo();
    procedure MakeReasonEnabled(temp:boolean);
    function  SaveReasonInfo():boolean;
  public
    { Public declarations }
    procedure Time_ref;
    procedure Reason_ref;
  end;

var
  frm_attendconfig: Tfrm_attendconfig;

implementation

uses Unit_DataModule,unit_TotalPublic,PublicFunOrPro;

{$R *.dfm}

{***************时间设置******************}
procedure Tfrm_attendconfig.Time_ref;
begin
  with sg_Time do
  begin
    cells[0,0] := '时间名称';
    cells[1,0] := '时间设置';
  end;
  dtp_timetime.Text := TimeToStr(Now());
  SearchTimeInfo();

  sbtn_append.Enabled := GetPower(SysUserId,'考勤设置','修改权');
  sbtn_edit.Enabled   := sbtn_append.Enabled ;
  sbtn_delete.Enabled := sbtn_append.Enabled ;
end;
procedure Tfrm_attendconfig.SearchTimeInfo ();
var
  i:integer;
begin
  with dmod.qrydata do
  begin
    close;
    SQL.Text := 'select time_name,time_time from AttendTime order by order_by';
    Open;
    i:=1;
    while not eof do
    begin
      sg_Time.Cells[0,i] := FieldByName('time_name').AsString ;
      sg_Time.Cells[1,i] := TimeToStr(FieldbyName('time_time').AsDateTime) ;
      inc(i);
      next;
    end;
  end;
  if i<>1 then sg_Time.RowCount := i+1;
  sbtn_front.Enabled := false;
  sbtn_back.Enabled  := false;
  if sg_Time.RowCount >3 then sbtn_back.Enabled := true;
end;

function Tfrm_attendconfig.SaveTimeInfo():boolean;
var
  orderby:integer;
begin
  result := true;orderby:=0;
  
  if trim(cbb_timename.Text)='' then
  begin
    Messagebox(handle,'请选择设置的时间名称!','提示',mb_ok+mb_iconinformation);
    result:=false;
    cbb_timename.SetFocus ;
    exit;
  end;

  if TimeAppendOrEdit then
  with dmod.qrydata do
  begin
    close;
    SQL.Text := 'select count(*) as count from AttendTime where time_name=:timename';
    ParamByname('timename').AsString := trim(cbb_timename.Text);
    open;
    if FieldByName('count').AsInteger>0 then
    begin
      MessageBox(self.Handle ,'该时间设置名称已经存在,请重新确认!','提示',mb_ok+mb_iconinformation);
      cbb_timename.SetFocus ;
      result := false;
      exit;
    end;
  end;

  //设置orderby分别为1,2,3,4,5,6
  if trim(cbb_timename.Text)='上午上班' then
     orderby:=1
  else if  trim(cbb_timename.Text)='上午下班' then
     orderby:=2
  else if  trim(cbb_timename.Text)='下午上班' then
     orderby:=3
  else if  trim(cbb_timename.Text)='下午下班' then
     orderby:=4
  else if  trim(cbb_timename.Text)='晚上上班' then
     orderby:=5
  else if  trim(cbb_timename.Text)='晚上下班' then
     orderby:=6;

  try
    dmod.Database.StartTransaction ;
    with dmod.qrydata do
    begin
      close;
      SQL.Text := 'delete from AttendTime where time_name=:timename';
      ParamByName('timename').AsString := trim(cbb_timename.Text);
      ExecSQL;

      close;
      SQL.Text := 'insert into AttendTime(time_name,time_time,order_by) values(:timename,:timetime,:orderby)';
      ParamByName('timename').AsString := trim(cbb_Timename.Text );
      ParamByName('timetime').AsTime   := StrToTime(dtp_timetime.text);
      ParamByName('orderby').AsInteger := orderby;
      ExecSQL;
    end;
  finally
    try
      dmod.Database.Commit ;
    except
      dmod.Database.Rollback ;
      MessageBox(handle,'操作失败,请重试!','提示',mb_ok+mb_iconinformation);
      result:=false;
    end;
  end;
end;
procedure Tfrm_attendconfig.ClearTimeInfo();
begin
  cbb_timename.Text :='';
  dtp_timetime.Text :='';
end;
procedure Tfrm_attendconfig.MakeTimeEnabled(temp:boolean);
begin
  if sbtn_append.Enabled then
     sbtn_save.Enabled := true
  else
     sbtn_save.Enabled := false;
  sbtn_delete.Enabled  :=false;
  cbb_timename.Enabled := temp;
  dtp_timetime.Enabled := temp;
end;
{***************时间设置******************}

{***************原因设置******************}
procedure Tfrm_attendconfig.Reason_ref;
begin
  with sg_Reason do
  begin
    cells[0,0] := '理由序号';
    cells[1,0] := '理由描述';
  end;
  SearchReasonInfo();
end;
procedure Tfrm_attendconfig.SearchReasonInfo ();
var
  i:integer;
begin
  with dmod.qrydata do
  begin
    close;
    SQL.Text := 'select reason_id,reason_remark from specialreason';
    Open;
    i:=1;
    while not eof do
    begin
      sg_Reason.Cells[0,i] := FieldByName('reason_id').AsString ;
      sg_Reason.Cells[1,i] := FieldByName('reason_remark').AsString ;
      inc(i);
      next;
    end;
  end;
  if i<>1 then sg_Reason.RowCount := i+1;
  sbtn_front.Enabled := false;
  sbtn_back.Enabled  := false;
  if sg_Reason.RowCount >3 then sbtn_back.Enabled := true;
end;

function Tfrm_attendconfig.SaveReasonInfo():boolean;
begin
  result := true;
  if trim(mm_remark.Text)='' then
  begin
    Messagebox(handle,'请先填写不能考勤的原因!','提示',mb_ok+mb_iconinformation);
    result:=false;
    mm_remark.SetFocus ;
    exit;
  end;
  
  Reasonid:=trim(edt_Reasonid.Text );
  if ReasonAppendOrEdit then
  with dmod.qrydata do
  begin
    close;
    SQL.Text := 'select reason_id from specialreason where reason_id=:reasonid';
    ParamByName('reasonid').AsString := reasonid;
    Open;
    if not eof then  
    begin
      MessageBox(self.handle,'该时间设置序号已经存在,请重新确认!','提示',mb_ok+mb_iconinformation);
      edt_reasonid.SetFocus ;
      result:=false;
      exit;
    end;
  end;
  
  try
    dmod.Database.StartTransaction ;
    with dmod.qrydata do
    begin
      close;
      SQL.Text := 'delete from specialreason where reason_id=:reasonid';
      ParamByName('reasonid').AsString := reasonId;
      ExecSQL;

      close;
      SQL.Text := 'insert into specialreason(reason_id,reason_remark) values(:reasonid,:reasonremark)';
      ParamByName('reasonid').AsString := trim(edt_reasonid.Text );
      ParamByName('reasonremark').AsString := trim(mm_remark.Text );
      ExecSQL;
    end;
  finally
    try
      dmod.Database.Commit ;
    except
      dmod.Database.Rollback ;
      MessageBox(handle,'操作失败,请重试!','提示',mb_ok+mb_iconinformation);
      result:=false;
    end;
  end;
end;
procedure Tfrm_attendconfig.ClearReasonInfo();
begin
  edt_Reasonid.Text :='';
  mm_remark.Text :='';
end;
procedure Tfrm_attendconfig.MakeReasonEnabled(temp:boolean);
begin
  if sbtn_append.Enabled then
     sbtn_save.Enabled := true
  else
     sbtn_save.Enabled := false;
  sbtn_delete.Enabled  :=false;

  edt_Reasonid.Enabled := temp;
  mm_remark.Enabled := temp;
end;
{***************原因设置******************}
procedure Tfrm_attendconfig.sbtn_closeClick(Sender: TObject);
begin
  close;
end;

procedure Tfrm_attendconfig.sbtn_appendClick(Sender: TObject);
var
  i:integer;
  temp:string;
begin
  {*********************如果新建考勤设置**********************}
  if pagecontrol1.ActivePage = sht_Time then
  begin
    if (not TimeAppendOrEdit) and (not cbb_Timename.Enabled) and (cbb_Timename.Text<>'') then
    begin
      i:=MessageBox(handle,'你要保存操作的数据吗?','询问',mb_yesnocancel+mb_iconquestion);
      if i=6 then
      if not SaveTimeInfo then i:=2;
      if i=2 then exit;
    end;
    TimeAppendOrEdit:=true;
    sbtn_edit.Enabled :=true;
    MakeTimeEnabled(true);
    ClearTimeInfo();

⌨️ 快捷键说明

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