📄 cwa550_02.pas.svn-base
字号:
unit Cwa550_02;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
Bas100_01, Db, StdCtrls, Buttons, wwdbdatetimepicker, Mask, ExtCtrls, ComCtrls,
ADODB, Menus, Variants, atScript, atPascal;
type
TCwa550_02Form = class(TBas100_01Form)
bbtnOk: TBitBtn;
bbtnExit: TBitBtn;
cbReCalc: TCheckBox;
qryHrm100: TADOQuery;
qryCwa120: TADOQuery;
qryCwa150: TADOQuery;
qryEmployee: TADOQuery;
PageControl1: TPageControl;
TabSheet1: TTabSheet;
TabSheet2: TTabSheet;
Bevel1: TBevel;
lblDept: TLabel;
lblFromEmpID: TLabel;
lblTo: TLabel;
lblYear: TLabel;
SpeedButton1: TSpeedButton;
SpeedButton2: TSpeedButton;
cbDepart: TComboBox;
edtFromEmpID: TEdit;
edtToEmpID: TEdit;
cbYear: TComboBox;
cbMonth: TComboBox;
qryHrm150: TADOQuery;
qryHrm150H150_001: TAutoIncField;
qryHrm150H150_002: TStringField;
qryHrm150H150_003: TStringField;
ProgressBar1: TProgressBar;
ProgressBar2: TProgressBar;
Label1: TLabel;
Label2: TLabel;
Bevel2: TBevel;
procedure FormCreate(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
procedure bbtnOkClick(Sender: TObject);
procedure bbtnExitClick(Sender: TObject);
procedure SpeedButton1Click(Sender: TObject);
procedure SpeedButton2Click(Sender: TObject);
procedure edtFromEmpIDKeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
procedure edtToEmpIDKeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
procedure cbYearChange(Sender: TObject);
procedure cbMonthChange(Sender: TObject);
private
AStartDate,AEndDate:TDateTime;
APeriod:Integer;
procedure CalcByTrans(AItemNo:Integer;AEmpNo,AYear,AMonth:Integer;AIsCheck:Boolean);
procedure CalcByFormalu(AItemNo:Integer;AEmpNo,AYear,AMonth,ADays,AHours:Integer);
procedure CalcByAuto(AItemNo:Integer;AEmpNo,AYear,AMonth:Integer);
procedure CalcCwa(AEmpNo,AYear,AMonth,ADays,AHours:Integer;AIsCheck:Boolean);
procedure SetInterface;
{ Private declarations }
public
{ Public declarations }
end;
var
Cwa550_02Form: TCwa550_02Form;
implementation
uses Wait, CommFun, SYSDATA, HwSelData;
{$R *.DFM}
//计算'迟到','早退','旷工'时间
// AEmpNo: 员工电脑编号
// ADate: 考勤日期
// AEmpName: 员工姓名 CalcTime(AEmpNo,ADate,AMin,ATime,AType); //计算时间
procedure CalcTime(AEmpNo:Integer;AID:string;ADate:TDateTime;AMin:array of integer;ATime:array of string;AType:array of integer);
var
ALate:Integer; //迟到时间
AEarly:Integer; //早退时间
AAbsend:Integer; //旷工时间
ATimeInt:array[1..6] of integer; //时间1-6
A1,A2,A3,A4,A5,A6:Integer; //上班时间1-6
begin
ATimeInt[1]:=StrToInt(copy(ATime[1],1,2))*60+StrToInt(copy(ATime[1],4,2));
ATimeInt[2]:=StrToInt(copy(ATime[2],1,2))*60+StrToInt(copy(ATime[2],4,2));
ATimeInt[3]:=StrToInt(copy(ATime[3],1,2))*60+StrToInt(copy(ATime[3],4,2));
ATimeInt[4]:=StrToInt(copy(ATime[4],1,2))*60+StrToInt(copy(ATime[4],4,2));
ATimeInt[5]:=StrToInt(copy(ATime[5],1,2))*60+StrToInt(copy(ATime[5],4,2));
ATimeInt[6]:=StrToInt(copy(ATime[6],1,2))*60+StrToInt(copy(ATime[6],4,2));
ALate:=0;
AEarly:=0;
AAbsend:=0;
if ATimeInt[1]=0 then ATimeInt[1]:=1440;
if ATimeInt[2]=0 then ATimeInt[2]:=1440;
if ATimeInt[3]=0 then ATimeInt[3]:=1440; //24:00
if ATimeInt[4]=0 then ATimeInt[4]:=1440;
if ATimeInt[5]=0 then ATimeInt[5]:=1440;
if ATimeInt[6]=0 then ATimeInt[6]:=1440;
//@A1 上午上班
//在正常上班时间(X>=ATimeInt[1]-AMin[2] and X<=ATimeInt[1]+AMin[1]) 范围内有刷卡记录,取最近的刷卡时间
if IsExists('select 1 from CWA510 where C510_001='+''''+AID+''''+' and C510_002='+GetDateString(ADate)+' and C510_005>='+IntToStr(ATimeInt[1]-AMin[2])+' and C510_005<='+IntToStr(ATimeInt[1]+AMin[1])) then
A1:=GetValue('select top 1 C510_005 from C510_001 where C510_001='+''''+AID+''''+' and C510_002='+GetDateString(ADate)+' C510_005>='+IntToStr(ATimeInt[1]-AMin[2])+' and C510_005<='+IntToStr(ATimeInt[1]+AMin[1])+' order by C510_005 desc')
else
begin
//在正常上班时间之外(X>ATimeInt[1]+AMin[1] and X<ATimeInt[2]-AMin[2])
if IsExists('select 1 from CWA510 where C550B_001='+IntToStr(AEmpNo)+' and C510_002='+GetDateString(ADate)+' and C510_005>'+IntToStr(ATimeInt[1]+AMin[1])+' and C510_005<'+IntToStr(ATimeInt[2]-AMin[2])) then
A1:=GetValue('select top 1 C510_005 from CWA510 where C510_001='+''''+AID+''''+' and C510_002='+GetDateString(ADate)+' and C510_005>'+IntToStr(ATimeInt[1]+AMin[1])+' and C510_005<'+IntToStr(ATimeInt[2]-AMin[2])+' order by C510_005')
else
A1:=0;
end;
//A2 上午下班
//在正常下班时间(X>@A1 and X>=ATimeInt[2]-AMin[1] and X<ATimeInt[3]-AMin[2]) 范围内有刷卡记录,取最近的刷卡时间
if IsExists('select 1 from CWA510 where C510_001='+''''+AID+''''+' and C510_002='+GetDateString(ADate)+' and C510_005>'+IntToStr(A1)+' and C510_005>='+IntToStr(ATimeInt[2]-AMin[1])+' and C510_005<'+IntToStr(ATimeInt[3]-AMin[2])) then
A2:=GetValue('select top 1 C510_005 from CWA510 where C510_001='+''''+AID+''''+' and C510_002='+GetDateString(ADate)+' and C510_005>'+IntToStr(A1)+' and C510_005>='+IntToStr(ATimeInt[2]-AMin[1])+' and C510_005<'+IntToStr(ATimeInt[3]-AMin[2])+' order by C510_005 desc')
else
begin
//在正常下班时间之外(X>@A1 and X<ATimeInt[2]-AMin[1]) 范围内有刷卡记录,取最近的刷卡时间
if IsExists('select 1 from CWA510 where C510_001='+''''+AID+''''+' and C510_002='+GetDateString(ADate)+' and C510_005>'+IntToStr(A1)+' and C510_005<'+IntToStr(ATimeInt[2]-AMin[1])) then
A2:=GetValue('select top 1 C510_005 from CWA510 where C510_001='+''''+AID+''''+' and C510_002='+GetDateString(ADate)+' and C510_005>'+IntToStr(A1)+' and C510_005<'+IntToStr(ATimeInt[2]-AMin[1])+' order by C510_005')
else
A2:=0;
end;
//A3 下午上班
//在正常上班时间(X>@A2 and X>=ATimeInt[3]-AMin[2] and X<=ATimeInt[3]+AMin[1]) 范围内有刷卡记录,取最近的刷卡时间
if IsExists('select 1 from CWA510 where C510_001='+''''+AID+''''+' and C510_002='+GetDateString(ADate)+' and C510_005>'+IntToStr(A2)+' and C510_005>='+IntToStr(ATimeInt[3]-AMin[2])+' and C510_005<='+IntToStr(ATimeInt[3]+AMin[1])) then
A3:=GetValue('select top 1 C510_005 from CWA510 where C510_001='+''''+AID+''''+' and C510_002='+GetDateString(ADate)+' and C510_005>'+IntToStr(A2)+' and C510_005>='+IntToStr(ATimeInt[3]-AMin[2])+' and C510_005<='+IntToStr(ATimeInt[3]+AMin[1])+' order by C510_005 desc')
else
begin
//在正常上班时间之外(X>@A2 and X>ATimeInt[3]+AMin[1] and X<ATimeInt[4]-AMin[2])
if IsExists('select 1 from CWA510 where C510_001='+''''+AID+''''+' and C510_002='+GetDateString(ADate)+' and C510_005>'+IntToStr(A2)+' and C510_005>'+IntToStr(ATimeInt[3]+AMin[1])+' and C510_005<'+IntToStr(ATimeInt[4]-AMin[2])) then
A3:=GetValue('select top 1 C510_005 from CWA510 where C510_001='+''''+AID+''''+' and C510_002='+GetDateString(ADate)+' and C510_005>'+IntToStr(A2)+' and C510_005>'+IntToStr(ATimeInt[3]+AMin[1])+' and C510_005<'+IntToStr(ATimeInt[4]-AMin[2])+' order by C510_005')
else
A3:=0;
end;
//A4 下午下班
//在正常下班时间(X>@A3 and X>=ATimeInt[4]-AMin[1] and X<ATimeInt[5]-AMin[2]) 范围内有刷卡记录,取最近的刷卡时间
if IsExists('select 1 from CWA510 where C510_001='+''''+AID+''''+' and C510_002='+GetDateString(ADate)+' and C510_005>'+IntToStr(A3)+' and C510_005>='+IntToStr(ATimeInt[4]-AMin[1])+' and C510_005<'+IntToStr(ATimeInt[5]-AMin[2])) then
A4:=GetValue('select top 1 C510_005 from CWA510 where C510_001='+''''+AID+''''+' and C510_002='+GetDateString(ADate)+' and C510_005>'+IntToStr(A3)+' and C510_005>='+IntToStr(ATimeInt[4]-AMin[1])+' and C510_005<'+IntToStr(ATimeInt[5]-AMin[2])+' order by C510_005 desc')
else
begin
//在正常下班时间之外(X>@A3 and X<ATimeInt[4]-AMin[1]) 范围内有刷卡记录,取最近的刷卡时间
if IsExists('select 1 from CWA510 where C510_001='+''''+AID+''''+' and C510_002='+GetDateString(ADate)+' and C510_005>'+IntToStr(A3)+' and C510_005<'+IntToStr(ATimeInt[4]-AMin[1])) then
A4:=GetValue('select top 1 C510_005 from CWA510 where C510_001='+''''+AID+''''+' and C510_002='+GetDateString(ADate)+' and C510_005>'+IntToStr(A3)+' and C510_005<'+IntToStr(ATimeInt[4]-AMin[1])+' order by C510_005')
else
A4:=0;
end;
//A5 晚上上班
//在正常上班时间(X>@A4 and X>=ATimeInt[5]-AMin[2] and X<=ATimeInt[5]+AMin[1]) 范围内有刷卡记录,取最近的刷卡时间
if IsExists('select 1 from CWA510 where C510_001='+''''+AID+''''+' and C510_002='+GetDateString(ADate)+' and C510_005>'+IntToStr(A4)+' and C510_005>='+IntToStr(ATimeInt[5]-AMin[2])+' and C510_005<='+IntToStr(ATimeInt[5]+AMin[1])) then
A5:=GetValue('select top 1 C510_005 from CWA510 where C510_001='+''''+AID+''''+' and C510_002='+GetDateString(ADate)+' and C510_005>'+IntToStr(A4)+' and C510_005>='+IntToStr(ATimeInt[5]-AMin[2])+' and C510_005<='+IntToStr(ATimeInt[5]+AMin[1])+' order by C510_005 desc')
else
begin
//在正常上班时间之外(X>@A4 and X>ATimeInt[5]+AMin[1] and X<ATimeInt[6]-AMin[2])
if IsExists('select 1 from CWA510 where C510_001='+''''+AID+''''+' and C510_002='+GetDateString(ADate)+' and C510_005>'+IntToStr(A4)+' and C510_005>'+IntToStr(ATimeInt[5]+AMin[1])+' and C510_005<'+IntToStr(ATimeInt[6]-AMin[2])) then
A5:=GetValue('select top 1 C510_005 from CWA510 where C510_001='+''''+AID+''''+' and C510_002='+GetDateString(ADate)+' and C510_005>'+IntToStr(A4)+' and C510_005>'+IntToStr(ATimeInt[5]+AMin[1])+' and C510_005<'+IntToStr(ATimeInt[6]-AMin[2])+' order by C510_005')
else
A5:=0;
end;
//A6 晚上下班
//在正常下班时间(X>@A5 and X>=ATimeInt[6]-AMin[1] and X<=ATimeInt[6]+AMin[2]) 范围内有刷卡记录,取最近的刷卡时间
if IsExists('select 1 from CWA510 where C510_001='+''''+AID+''''+' and C510_002='+GetDateString(ADate)+' and C510_005>'+IntToStr(A5)+' and C510_005>='+IntToStr(ATimeInt[6]-AMin[1])+' and C510_005<='+IntToStr(ATimeInt[6]+AMin[2])) then
A6:=GetValue('select top 1 C510_005 from CWA510 where C510_001='+''''+AID+''''+' and C510_002='+GetDateString(ADate)+' and C510_005>'+IntToStr(A5)+' and C510_005>='+IntToStr(ATimeInt[6]-AMin[1])+' and C510_005<='+IntToStr(ATimeInt[6]+AMin[2])+' order by C510_005 desc')
else
begin
//在正常下班时间之外(X>@A5 and X<ATimeInt[6]-AMin[1]) 范围内有刷卡记录,取最近的刷卡时间
if IsExists('select 1 from CWA510 where C510_001='+''''+AID+''''+' and C510_002='+GetDateString(ADate)+' and C510_005>'+IntToStr(A5)+' and C510_005<'+IntToStr(ATimeInt[6]-AMin[1])) then
A6:=GetValue('select top 1 C510_005 from CWA510 where C510_001='+''''+AID+''''+' and C510_002='+GetDateString(ADate)+' and C510_005>'+IntToStr(A5)+' and C510_005<'+IntToStr(ATimeInt[6]-AMin[1])+' order by C510_005')
else
A6:=0;
end;
// @I_DAT01,convert(char(2),@a1/60)+':'+convert(char(2),@a1-(@a1/60)*60),
// convert(char(2),@a2/60)+':'+convert(char(2),@a2-(@a2/60)*60),
// convert(char(2),@a3/60)+':'+convert(char(2),@a3-(@a3/60)*60),
// convert(char(2),@a4/60)+':'+convert(char(2),@a4-(@a4/60)*60),
// convert(char(2),@a5/60)+':'+convert(char(2),@a5-(@a5/60)*60),
// convert(char(2),@a6/60)+':'+convert(char(2),@a6-(@a6/60)*60)
if A1+A2+A3+A4+A5+A6<>0 then
begin
if A1=0 then A1:=ATimeInt[2];
if A3=0 then A3:=ATimeInt[4];
if A2=0 then A2:=ATimeInt[1];
if A4=0 then A4:=ATimeInt[3];
if A1-ATimeInt[1]-AMin[1]>0 then ALate:=A1-ATimeInt[1];
if A3-ATimeInt[3]-AMin[1]>0 then ALate:=ALate+(A3-ATimeInt[3]);
if ATimeInt[2]-A2-AMin[1]>0 then AEarly:=ATimeInt[2]-A2;
if ATimeInt[4]-A4-AMin[1]>0 then AEarly:=AEarly+(ATimeInt[4]-A4);
if (ALate+AEarly>=AMin[3]) and (ALate+AEarly<AMin[4]) then
AAbsend:=ALate+AEarly
else
if ALate+AEarly>=AMin[4] then AAbsend:=ALate+AEarly;
end else
begin
AAbsend:=(ATimeInt[4]-AMin[1])-(ATimeInt[3]-AMin[1])+(ATimeInt[2]-AMin[1])-(ATimeInt[1]-AMin[1]);
end;
if AAbsend<=0 then
begin
if ALate>0 then
begin
//考勤明细表(考勤日期,员工编号,考勤项目,数值,是否签卡,签卡人,已审核否)
SYSDM.qryQuery.Close;
SYSDM.qryQuery.SQL.Clear;
SYSDM.qryQuery.SQL.Add('insert into CWA550B(C550B_001,C550B_002,C550B_003,C550B_004,C550B_005,C550B_006,C550B_007)');
SYSDM.qryQuery.SQL.Add('select '+GetDateString(ADate)+','+IntToStr(AEmpNo)+',1'+IntToStr(ALate)+',0,null,0');
SYSDM.qryQuery.ExecSQL;
end;
if AEarly>0 then
begin
SYSDM.qryQuery.Close;
SYSDM.qryQuery.SQL.Clear;
SYSDM.qryQuery.SQL.Add('insert into CWA550B(C550B_001,C550B_002,C550B_003,C550B_004,C550B_005,C550B_006,C550B_007)');
SYSDM.qryQuery.SQL.Add('select '+GetDateString(ADate)+','+IntToStr(AEmpNo)+',2'+IntToStr(AEarly)+',0,null,0');
SYSDM.qryQuery.ExecSQL;
end;
end else
begin
SYSDM.qryQuery.Close;
SYSDM.qryQuery.SQL.Clear;
SYSDM.qryQuery.SQL.Add('insert into CWA550B(C550B_001,C550B_002,C550B_003,C550B_004,C550B_005,C550B_006,C550B_007)');
SYSDM.qryQuery.SQL.Add('select '+GetDateString(ADate)+','+IntToStr(AEmpNo)+',3'+IntToStr(AAbsend)+',0,null,0');
SYSDM.qryQuery.ExecSQL;
end;
end;
//按考勤事务处理
procedure TCwa550_02Form.CalcByTrans(AItemNo:Integer;AEmpNo,AYear,AMonth:Integer;AIsCheck:Boolean);
begin
//考勤明细表(考勤日期,员工编号,考勤项目,数值,是否签卡,签卡人,已审核否)
SYSDM.qryQuery.Close;
SYSDM.qryQuery.SQL.Clear;
SYSDM.qryQuery.SQL.Add('insert into CWA550B(C550B_001,C550B_002,C550B_003,C550B_004,C550B_005,C550B_006,C550B_007)');
SYSDM.qryQuery.SQL.Add('select C500_005,C500_004,C500_001,C500_008,0,null,0 ');
SYSDM.qryQuery.SQL.Add('from CWA500 where C500_001='+IntToStr(AItemNo));
SYSDM.qryQuery.SQL.Add(' and C500_005>='+GetDateString(AStartDate)+' and C500_005<='+GetDateString(AEndDate));
SYSDM.qryQuery.SQL.Add(' and C500_004='+IntToStr(AEmpNo));
if AIsCheck then SYSDM.qryQuery.SQL.Add(' and C500_010='+GetBoolean(True));
SYSDM.qryQuery.ExecSQL;
end;
//按公式计算
procedure TCwa550_02Form.CalcByFormalu(AItemNo:Integer;AEmpNo,AYear,AMonth,ADays,AHours:Integer);
var
AStringList:TStringList;
AItemID:string;
AFormaluString:string;
S:string;
Scripter:TatPascalScripter;
begin
AItemID:=qryCwa150.FieldByName('C150_002').AsString;
AFormaluString:=qryCwa150.FieldByName('C150_006').Value; //计算公式
AStringList:=TStringList.Create;
Scripter:=TatPascalScripter.Create(Application);
Scripter.Compiled:=True;
try
AStringList.Text:=ParseFormula(AFormaluString,AItemID,AItemNo,AStartDate,AEndDate,AEmpNo,AYear,AMonth,ADays,AHours);
Scripter.SourceCode.Clear;
Scripter.SourceCode.AddStrings(AStringList);
try
Scripter.Compile;
S:=VarToStr(Scripter.Execute);
if S='' then S:='0';
except
ShowMsg(Scripter.SourceCode.Text,1);
Abort;
end;
try
SYSDM.qryQuery.Close;
SYSDM.qryQuery.SQL.Clear;
SYSDM.qryQuery.SQL.Add('insert into CWA550A(C550A_001,C550A_002,C550A_003,C550A_004,C550A_005,C550A_006)');
SYSDM.qryQuery.SQL.Add('select '+IntToStr(AYear)+','+IntToStr(AMonth)+','+IntToStr(AEmpNo)+','+IntToStr(AItemNo)+','+S+',0');
SYSDM.qryQuery.ExecSQL;
except
ShowMsg(SYSDM.ADOC.Errors[0].Description+#13+SYSDM.qryQuery.SQL.Text,1);
Abort;
end;
finally
AStringList.Free;
Scripter.Free;
end;
end;
//按卡钟数据自动计算考勤
procedure TCwa550_02Form.CalcByAuto(AItemNo:Integer;AEmpNo,AYear,AMonth:Integer);
var
ADate:TDateTime;
ATime:array[1..6] of string;
AType:array[1..3] of integer;
AMin:array[1..4] of integer;
S:String;
AID:string;
begin
//允许刷卡误差时间(分钟)
S:=GetSysParams('CWA0001');
if S='' then AMin[1]:=0 else AMin[1]:=StrToInt(S);
//允许提前或推后刷卡时间(分钟)
S:=GetSysParams('CWA0003');
if S='' then AMin[2]:=0 else AMin[2]:=StrToInt(S);
//迟到(早退)多少分钟以上算旷工半天
S:=GetSysParams('CWA0002');
if S='' then AMin[3]:=0 else AMin[3]:=StrToInt(S);
//迟到(早退)多少分钟以上算旷工一天
S:=GetSysParams('CWA0004');
if S='' then AMin[4]:=0 else AMin[4]:=StrToInt(S);
//考勤资料计算("迟到","早退","旷工")
//按选择的范围先取卡钟数据(CWA510)
//与员工班次表(CWA120)比较,计算出"迟到","早退","旷工"
//时间,并将结果插入到表考勤计算表(CWA550)
qryCwa120.Close;
qryCwa120.SQL.Clear;
qryCwa120.SQL.Add('select * from CWA120 where C120_001='+IntToStr(AEmpNo)+' and C120_003>='+GetDateString(AStartDate)+' and C120_003<='+GetDateString(AEndDate));
qryCwa120.Open;
while not qryCwa120.Eof do
begin
ATime[1]:=qryCwa120.FieldByName('C120_004').AsString;
ATime[2]:=qryCwa120.FieldByName('C120_005').AsString;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -