📄 unit_attendmanager.pas
字号:
unit Unit_AttendManager;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ExtCtrls, Grids, ComCtrls, Buttons, StdCtrls, Menus;
type
Tfrm_attendmanager = class(TForm)
PageControl1: TPageControl;
sht_Normal: TTabSheet;
sht_Special: TTabSheet;
sg_Normal: TStringGrid;
Panel1: TPanel;
sbtn_front: TSpeedButton;
sbtn_back: TSpeedButton;
sbtn_save: TSpeedButton;
sbtn_delete: TSpeedButton;
sbtn_close: TSpeedButton;
Panel2: TPanel;
Splitter1: TSplitter;
GroupBox2: TGroupBox;
Label10: TLabel;
Label12: TLabel;
SpeedButton2: TSpeedButton;
edt_UserId: TEdit;
edt_Password: TEdit;
GroupBox1: TGroupBox;
Label4: TLabel;
sbtn_Search: TSpeedButton;
Label3: TLabel;
Label2: TLabel;
Label1: TLabel;
dtp_DateEnd: TDateTimePicker;
dtp_DateStart: TDateTimePicker;
edt_Empname: TEdit;
edt_Empno: TEdit;
GroupBox3: TGroupBox;
Label5: TLabel;
Label6: TLabel;
Label7: TLabel;
Label8: TLabel;
Label9: TLabel;
sg_Special: TStringGrid;
sbtn_edit: TSpeedButton;
PopupMenu1: TPopupMenu;
N1: TMenuItem;
procedure sg_NormalSelectCell(Sender: TObject; ACol, ARow: Integer;
var CanSelect: Boolean);
procedure sg_SpecialSelectCell(Sender: TObject; ACol, ARow: Integer;
var CanSelect: Boolean);
procedure SpeedButton2Click(Sender: TObject);
procedure sbtn_SearchClick(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
procedure sbtn_closeClick(Sender: TObject);
procedure sbtn_editClick(Sender: TObject);
procedure sbtn_saveClick(Sender: TObject);
procedure sbtn_deleteClick(Sender: TObject);
procedure edt_EmpnoExit(Sender: TObject);
procedure sbtn_backClick(Sender: TObject);
procedure sbtn_frontClick(Sender: TObject);
procedure N1Click(Sender: TObject);
procedure sg_SpecialMouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
private
{ Private declarations }
function CheckAdministrator(userid,password:string):boolean;
procedure MakeInputEnabled(temp:boolean);
procedure SearchNormalInfo();
procedure SearchSpecialInfo();
public
{ Public declarations }
procedure attendmanager_ref();
end;
var
frm_attendmanager: Tfrm_attendmanager;
implementation
uses unit_DataModule,unit_TotalPublic,PublicFunOrPro,unit_selectreason,Unit_PublicFunction;
{$R *.dfm}
{*************************用户自定义过程***********************}
procedure Tfrm_attendmanager.MakeInputEnabled(temp:boolean);
begin
edt_Empno.Enabled :=temp;
edt_Empname.Enabled :=temp;
dtp_DateStart.Enabled :=temp;
dtp_DateEnd.Enabled :=temp;
sbtn_Search.Enabled :=temp;
end;
procedure Tfrm_attendmanager.attendmanager_ref ();
begin
pagecontrol1.ActivePage := sht_Normal;
with sg_Normal do
begin
cells[0,0]:='考勤日期';
cells[1,0]:='上午上班';
cells[2,0]:='上午下班';
cells[3,0]:='下午上班';
cells[4,0]:='下午下班';
cells[5,0]:='晚上上班';
cells[6,0]:='晚上下班';
end;
with sg_Special do
begin
cells[0,0]:='考勤日期';
cells[1,0]:='原因序号';
cells[2,0]:='原因描述';
cells[3,0]:='开始时间';
cells[4,0]:='结束时间';
end;
dtp_datestart.Date := Date;
dtp_dateend.Date := Date+1;
sbtn_edit.Enabled := GetPower(SysUserId,'考勤管理','修改权');
sbtn_delete.Enabled := sbtn_edit.Enabled ;
end;
procedure Tfrm_attendmanager.SearchNormalInfo ();
var
i:integer;
begin
StringGridClear(sg_Normal);
with dmod.qrydata do
begin
Close;
SQL.Text :='select att_date,pre_morning,aft_morning,pre_afternoon,aft_afternoon,pre_evening,aft_evening '+
' from normalattend where emp_no='+#39+trim(edt_Empno.Text)+#39+
' and att_date between '+#39+DateToStr(dtp_datestart.Date)+#39+
' and '+#39+DateTostr(dtp_dateend.Date)+#39;
Open;
i:=1;
while not eof do
begin
with sg_Normal do
begin
cells[0,i]:= FieldByName('att_date').AsString ;
if FieldByName('pre_morning').AsString<>'' then
cells[1,i]:= TimeToStr(StrToDateTime(FieldByName('pre_morning').AsString))
else
cells[1,i]:='';
if FieldByName('aft_morning').AsString<>'' then
cells[2,i]:= TimeToStr(StrToDateTime(FieldByName('aft_morning').AsString))
else
cells[2,i]:='';
if FieldByName('pre_afternoon').AsString<>'' then
cells[3,i]:= TimeToStr(StrToDateTime(FieldByName('pre_afternoon').AsString))
else
cells[3,i]:='';
if FieldByName('aft_afternoon').AsString<>'' then
cells[4,i]:= TimeToStr(StrToDateTime(FieldByName('aft_afternoon').AsString))
else
cells[4,i]:='';
if FieldByName('pre_evening').AsString<>'' then
cells[5,i]:= TimeToStr(StrToDateTime(FieldByName('pre_evening').AsString))
else
cells[5,i]:='';
if FieldByName('aft_evening').AsString<>'' then
cells[6,i]:= TimeToStr(StrToDateTime(FieldByName('aft_evening').AsString))
else
cells[6,i]:='';
end;
inc(i);
next;
end;
end;
if i<>1 then sg_Normal.RowCount :=i+1;
end;
procedure Tfrm_attendmanager.SearchSpecialInfo ();
var
i:integer;
begin
StringGridClear(sg_Special);
with dmod.qrydata do
begin
Close;
SQL.Text :='select att_date,specialattend.reason_id,reason_remark,time_start,time_end from specialattend,specialreason where'+
' specialattend.reason_id=specialreason.reason_id and emp_no='+#39+trim(edt_Empno.Text)+#39+
' and att_date between '+#39+DateToStr(dtp_datestart.Date)+#39+
' and '+#39+DateTostr(dtp_dateend.Date)+#39;
Open;
i:=1;
while not eof do
begin
with sg_Special do
begin
cells[0,i]:= FieldByName('att_date').AsString ;
cells[1,i]:= FieldByName('reason_id').AsString ;
cells[2,i]:= FieldByName('reason_remark').AsString ;
if FieldByName('time_start').AsString<>'' then
cells[3,i]:= TimeToStr(StrToDateTime(FieldByName('time_start').AsString))
else
cells[3,i]:='';
if FieldByName('time_end').AsString <>'' then
cells[4,i]:= TimeToStr(StrToDateTime(FieldByName('time_end').AsString))
else
cells[4,i]:='';
end;
inc(i);
next;
end;
end;
if i<>1 then sg_Special.RowCount :=i+1;
end;
function Tfrm_attendmanager.CheckAdministrator(userid,password:string):boolean;
begin
if (userid<>'') and (password<>'') then
begin
result:=true;
end else
begin
MessageBox(handle,'用户名和密码缺一不可,请重试!','提示',mb_ok+mb_iconinformation);
result:=false;
end;
end;
{*************************用户自定义过程***********************}
procedure Tfrm_attendmanager.sg_NormalSelectCell(Sender: TObject; ACol,
ARow: Integer; var CanSelect: Boolean);
begin
if ARow = sg_Normal.RowCount - 1 then
CanSelect:= false
else
begin
sbtn_back.Enabled := true;
sbtn_front.Enabled := true;
if ARow = sg_Normal.RowCount - 2 then sbtn_back.Enabled := false;
if ARow = 1 then sbtn_front.Enabled := false;
CanSelect := true;
end;
end;
procedure Tfrm_attendmanager.sg_SpecialSelectCell(Sender: TObject; ACol,
ARow: Integer; var CanSelect: Boolean);
begin
if ARow = sg_Special.RowCount - 1 then
CanSelect:= false
else
begin
sbtn_back.Enabled := true;
sbtn_front.Enabled := true;
if ARow = sg_Special.RowCount - 2 then sbtn_back.Enabled := false;
if ARow = 1 then sbtn_front.Enabled := false;
CanSelect := true;
end;
end;
procedure Tfrm_attendmanager.SpeedButton2Click(Sender: TObject);
begin
if CheckAdministrator(edt_UserId.Text ,edt_Password.Text ) then
begin
MessageBox(handle,'管理员验证通过,可以进行考勤管理!','提示',mb_ok+mb_iconinformation);
MakeInputEnabled(true);
end else
begin
MessageBox(handle,'管理员验证失败,请重试!','提示',mb_ok+mb_iconinformation);
MakeInputEnabled(false);
end;
end;
procedure Tfrm_attendmanager.sbtn_SearchClick(Sender: TObject);
begin
if pagecontrol1.ActivePage = sht_Normal then
SearchNormalInfo
else
SearchSpecialInfo;
end;
procedure Tfrm_attendmanager.FormClose(Sender: TObject;
var Action: TCloseAction);
begin
action:=cafree;
frm_attendmanager:=nil;
end;
procedure Tfrm_attendmanager.sbtn_closeClick(Sender: TObject);
begin
close;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -