📄 laboragefrm.pas
字号:
unit LaborageFrm;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
ChildGridFrm, Grids, DBGrids, ExtCtrls, StdCtrls, DBCtrls, Menus, DB,
PrnDbgeh, DBGridEh, Quickrpt, Qrctrls, Math;
resourcestring
sError='计算公式有错,请查找错误原!!';
sPrintDate='打印日期:';
sSum='合计';
sYear='年';
sMonth='月';
sDay=' 日 ';
sCorpName='利利时装厂';
sCaption='工资条打印';
sCaption1='工资发放表';
sCaption2='工资汇总表';
sFilter='报表导出';
sOption='打印选项';
sPrinter='打印';
sBasePay='底薪';
sWorkDate='工作日历';
sJBGZ='基本工资|';
sCalc='正在计算第';
sCalc1='位的工资';
sDelete='这是一个空表,不能用删除命令!';
type
TLaborageForm = class(TChildGridform)
Label1: TLabel;
Label2: TLabel;
btDelete: TButton;
btFilter: TButton;
btReCount: TButton;
btReport: TButton;
btExit: TButton;
Label3: TLabel;
cbFilter: TComboBox;
Button1: TButton;
dbng: TDBNavigator;
pmClose: TPopupMenu;
pmiClose: TMenuItem;
pmiLaborage1: TMenuItem;
pmiLaborage2: TMenuItem;
pmiLaborage3: TMenuItem;
QRLabel1: TQRLabel;
QRDBText1: TQRDBText;
DBGridEh1: TDBGridEh;
PrintDBGridEh1: TPrintDBGridEh;
Label4: TLabel;
Label5: TLabel;
Button2: TButton;
procedure ApplayUpdates(DataSet: TDataSet);
procedure btReCountClick(Sender: TObject);
procedure btDeleteClick(Sender: TObject);
procedure cbFilterChange(Sender: TObject);
procedure pmiCloseClick(Sender: TObject);
procedure btFilterClick(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure btReportClick(Sender: TObject);
procedure pmiLaborage2Click(Sender: TObject);
procedure pmiLaborage3Click(Sender: TObject);
procedure pmiLaborage1Click(Sender: TObject);
procedure FormDestroy(Sender: TObject);
procedure FormKeyPress(Sender: TObject; var Key: Char);
procedure FormCreate(Sender: TObject);
procedure FormResize(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
procedure DBGridEh1Exit(Sender: TObject);
procedure Button2Click(Sender: TObject);
private
{ Private declarations }
FYear, FMonth, FDay:Word;
FReport : TQuickRep;
procedure SetDate(Date:TDateTime);
procedure SetReport(Value : TQuickRep);
public
{ Public declarations }
property Date:TDateTime write SetDate;
property Report : TQuickRep read FReport write SetReport;
end;
type
Myarray=array [0..45] of integer;
var
ParentClientHeight:integer;
ParentClientWidth:integer;
LxButton1Left, LxButton1Top:integer;
LxButton2Left, LxButton2Top:integer;
LxButton3Left, LxButton3Top:integer;
LxButton4Left, LxButton4Top:integer;
LxButton5Left, LxButton5Top:integer;
LxdbngLeft:integer; LxdbngTop:integer;
LxDBGridEh1Height, LxDBGridEh1Width, LxDBGridEh1Top:integer;
OldColumnWidth:Myarray;
NewColumn1Width:Myarray;
LaborageForm: TLaborageForm;
implementation
uses unDM2, Dialog, SumFrm, FilterFrm, ProjectFilterFrm, Globals,
PrintOptionFrm, ReportFrm;
{$R *.DFM}
procedure TLaborageForm.ApplayUpdates(DataSet: TDataSet);
begin
DM2.Database.ApplyUpdates([DM2.qryLaborage1]);
end;
procedure TLaborageForm.SetReport(Value : TQuickRep);
begin
FReport:=Value;
end;
procedure TLaborageForm.SetDate(Date:TDateTime);
var
i:Integer;
begin
top:=10;
cbFilter.ItemIndex:=0;
DecodeDate(Date,FYear,FMonth,FDay);
DM2.qryLaborage1.Filtered:=False;
// DM2.qryLaborage1.AfterPost:=ApplayUpdates;
DBGridEh1.DataSource:=DM2.dsLaborage1;
DM2.qryLaborage1.Close;
DM2.qryLaborage1.Params[0].AsInteger:=FYear;
DM2.qryLaborage1.Params[1].AsInteger:=FMonth;
DM2.qryLaborage1.Open;
if ((Caption<>Pchar(sCaption1)) and (Caption<>Pchar(sCaption2))) then
i:=5
else if Caption=Pchar(sCaption1) then begin
i:=6;
DM2.qryLaborage1.Close;
DM2.qryLaborage1.Params[0].AsInteger:=FYear;
DM2.qryLaborage1.Params[1].AsInteger:=FMonth;
DM2.qryLaborage1.Open;
DBGridEh1.DataSource:=DM2.dsLaborage1;
DBGridEh1.Options:=[dgEditing,dgAlwaysShowEditor,dgTitles,dgIndicator,dgColumnResize,dgColLines,dgRowLines,dgTabs,dgConfirmDelete,dgRowSelect,dgCancelOnExit,dgMultiSelect];
DBGridEh1.Columns.Clear;
DBGridEh1.columns.Add;
DBGridEh1.Columns[0].FieldName:='DepName';
DBGridEh1.Columns[0].Footer.Value:=Pchar(sSum);
DBGridEh1.Columns[0].Footer.ValueType:=fvtStaticText;
DBGridEh1.columns.Add;
DBGridEh1.Columns[1].FieldName:='Name';
DBGridEh1.Columns[1].Footer.ValueType:=fvtCount;
DBGridEh1.columns.Add;
DBGridEh1.Columns[2].FieldName:='Duty';
DBGridEh1.columns.Add;
DBGridEh1.Columns[3].FieldName:='BasePay';
DBGridEh1.Columns[3].Title.Caption:=Pchar(sJBGZ+sBasePay);
DBGridEh1.Columns[3].Color:=clInfoBk;
DBGridEh1.columns.Add;
DBGridEh1.Columns[4].FieldName:='CQ0';
DBGridEh1.Columns[4].Title.Caption:=Pchar(sJBGZ+sWorkDate);
DBGridEh1.Columns[4].Color:=clInfoBk;
DBGridEh1.columns.Add;
DBGridEh1.Columns[5].FieldName:='PiecePay';
DBGridEh1.Columns[5].Color:=clInfoBk;
DBGridEh1.Columns[5].Footer.ValueType:=fvtSum;
end else if Caption=Pchar(sCaption2) then begin
i:=3;
DBGridEh1.Columns.Clear;
DBGridEh1.DataSource:=DM2.dsLaborageSum;
DBGridEh1.Options:=[dgEditing,dgAlwaysShowEditor,dgTitles,dgIndicator,dgColumnResize,dgColLines,dgRowLines,dgTabs,dgConfirmDelete,dgRowSelect,dgCancelOnExit,dgMultiSelect];
DBGridEh1.columns.Add;
DBGridEh1.Columns[0].FieldName:='DepName';
DBGridEh1.Columns[0].Footer.Value:=Pchar(sSum);
DBGridEh1.Columns[0].Footer.ValueType:=fvtStaticText;
DBGridEh1.columns.Add;
DBGridEh1.Columns[1].FieldName:='BasePay';
DBGridEh1.Columns[1].Color:=clInfoBk;
DBGridEh1.Columns[1].Footer.ValueType:=fvtSum;
DBGridEh1.columns.Add;
DBGridEh1.Columns[2].FieldName:='PiecePay';
DBGridEh1.Columns[2].Color:=clInfoBk;
DBGridEh1.Columns[2].Footer.ValueType:=fvtSum;
end;
Label2.Caption:=IntToStr(FYear)+Pchar(sYear)+IntToStr(FMonth)+Pchar(sMonth);
DM2.qryFormula.Close;
DM2.qryFormula.SQL.Clear;
DM2.qryFormula.SQL.Add('Select ProjectName,ProjectNo From Project Where ProjectNo<>');
DM2.qryFormula.SQL.Add('''');
DM2.qryFormula.SQL.Add('''');
DM2.qryFormula.SQL.Add('and Direction=True and used=True and DeleteFlag=True');
DM2.qryFormula.SQL.Add(' Order by labno');
DM2.qryFormula.Open;
While not DM2.qryFormula.Eof do begin
DBGridEh1.Columns.Add;
DBGridEh1.Columns[i].Title.Caption:=DM2.qryFormula.Fields[0].AsString;
DBGridEh1.Columns[i].FieldName:=DM2.qryFormula.Fields[1].AsString;
DM2.query1.Close;
DM2.query1.SQL.Clear;
DM2.query1.SQL.Add('Select ProjectNo From Formula where ProjectNo=:ProjectNo');
DM2.query1.Params[0].Value:=DM2.qryFormula.Fields[1].AsString;
DM2.query1.Open;
if not DM2.query1.Fields[0].IsNull then begin
DBGridEh1.Columns[i].ReadOnly:=True;
DBGridEh1.Columns[i].Color:=clInfoBk;
end;
DBGridEh1.Columns[i].Footer.ValueType:=fvtSum;
DBGridEh1.Columns[i].Footer.WordWrap:=True;
DM2.qryFormula.Next;
inc(i);
end;
DBGridEh1.columns.Add;
DBGridEh1.Columns[i].FieldName:='ShouldPay';
DBGridEh1.Columns[i].ReadOnly:=True;
DBGridEh1.Columns[i].Color:=clInfoBk;
DBGridEh1.Columns[i].Footer.ValueType:=fvtSum;
DBGridEh1.Columns[i].Footer.WordWrap:=True;
inc(i);
DM2.qryFormula.Close;
DM2.qryFormula.SQL.Clear;
DM2.qryFormula.SQL.Add('Select ProjectName,ProjectNo From Project Where ProjectNo<>');
DM2.qryFormula.SQL.Add('''');
DM2.qryFormula.SQL.Add('''');
DM2.qryFormula.SQL.Add('and Direction=False and used=True and DeleteFlag=True');
DM2.qryFormula.SQL.Add(' Order by labno');
DM2.qryFormula.Open;
While not DM2.qryFormula.Eof do begin
DBGridEh1.columns.Add;
DBGridEh1.Columns[i].Title.Caption:=DM2.qryFormula.Fields[0].AsString;
DBGridEh1.Columns[i].FieldName:=DM2.qryFormula.Fields[1].AsString;
DBGridEh1.Columns[i].Footer.ValueType:=fvtSum;
DBGridEh1.Columns[i].Footer.WordWrap:=True;
DM2.qryFormula.Next;
inc(i);
end;
DBGridEh1.columns.Add;
DBGridEh1.Columns[i].FieldName:='Pay';
DBGridEh1.Columns[i].ReadOnly:=True;
DBGridEh1.Columns[i].Color:=clInfoBk;
DBGridEh1.Columns[i].Footer.ValueType:=fvtSum;
DBGridEh1.Columns[i].Footer.WordWrap:=True;
inc(i);
DBGridEh1.columns.Add;
DBGridEh1.Columns[i].FieldName:='ActualPay';
DBGridEh1.Columns[i].ReadOnly:=True;
DBGridEh1.Columns[i].Color:=clInfoBk;
DBGridEh1.Columns[i].Footer.ValueType:=fvtSum;
DBGridEh1.Columns[i].Footer.WordWrap:=True;
for i:=0 to DBGridEh1.FieldCount-1 do begin
DBGridEh1.columns[i].Title.Alignment:=taCenter;
end;
for i:=0 to DBGridEh1.FieldCount-1 do begin
OldColumnWidth[i]:=DBGridEh1.columns[i].Width;
NewColumn1Width[i]:=DBGridEh1.columns[i].Width;
end;
DBGridEh1.Refresh;
DBGridEh1.SumList.Active:=True;
DBGridEh1.Refresh;
end;
procedure TLaborageForm.btReCountClick(Sender: TObject);
type TProjectRec=record
result:boolean;
expression:string;
end;
var
i, j, l, m, Counter, iStart, iEnd: integer;
StartDate, EndDate : TDateTime;
ProjectRec : array [0..30] of TProjectRec;
expression, aaa, oldCaption : String;
Total:Double;
begin
inherited;
iStart := GetTickCount;
Label5.Caption :='';
DBGridEh1.SumList.Active:=False;
if btReCount.Caption<>Pchar(sOption) then begin
SumForm:=TSumForm.Create(Self);
SumForm.Animate1.FileName:=OldDir+'\Play.avi';
SumForm.Animate1.Active:=True;
SumForm.Show;
SumForm.Update;
StartDate:=EncodeDate(Fyear,Fmonth,1);
if FMonth<>12 then
EndDate:=EncodeDate(Fyear,Fmonth+1,1)-1
else
EndDate:=EncodeDate(Fyear,Fmonth,31);
DM2.qryFormula.Close;
DM2.qryFormula.SQL.Clear;
DM2.qryFormula.SQL.Add('select ProjectNo,Text from Formula');
DM2.qryFormula.Open;
with DM2.qryLaborage do begin
Close;
SQL.Clear;
SQL.Add('Select ProjectName,ProjectNo From Project Where ProjectNo<>');
SQL.Add('''');
SQL.Add('''');
SQL.Add(' order by projectName');
Open;
end;
i:=0;
while not Dm2.qryFormula.Eof do begin
ProjectRec[i].result:=True;
if trim(DM2.qryFormula.Fields[0].AsString)='ActualPay' then
ProjectRec[i].expression:=(trim(DM2.qryFormula.Fields[0].AsString))+'=Round('
else
ProjectRec[i].expression:=(trim(DM2.qryFormula.Fields[0].AsString))+'=(';
expression:=DM2.qryFormula.Fields[1].AsString;
aaa:='';
for j:=1 to length(expression) do begin
if (j=1) and (ord(copy(expression,j,1)[1])<48) and (ord(copy(expression,j,1)[1])<>40) then begin
messagedlg(Pchar(sError),mtConfirmation, [mbOK], 0);
abort;
end;
if (aaa<>'') and (aaa = '底薪') then begin
ProjectRec[i].expression:=ProjectRec[i].expression + 'BasePay' + copy(expression,j,1);
aaa := '';
Continue;
end;
if (aaa<>'') and (aaa='计件工资') then begin
ProjectRec[i].expression:=ProjectRec[i].expression + 'PiecePay' + copy(expression,j,1);
aaa := '';
Continue;
end;
if (aaa<>'') and (aaa='应发合计') then begin
ProjectRec[i].expression:=ProjectRec[i].expression + 'ShouldPay' + copy(expression,j,1);
aaa := '';
Continue;
end;
if (ord(copy(expression,j,1)[1])<48) and (aaa<>'') then begin
if Dm2.qryLaborage.Locate('ProjectName',aaa,[loCaseInsensitive,loPartialKey]) then
ProjectRec[i].expression:=ProjectRec[i].expression + trim(dm2.qryLaborage.fields[1].AsString) + copy(expression,j,1)
else
ProjectRec[i].expression:=ProjectRec[i].expression + aaa + copy(expression,j,1);
aaa:='';
end else
aaa:=aaa+copy(expression,j,1);
if (j=length(expression)) and (aaa<>'') then begin
if Dm2.qryLaborage.Locate('ProjectName',aaa,[loCaseInsensitive,loPartialKey]) then
ProjectRec[i].expression:=ProjectRec[i].expression + trim(dm2.qryLaborage.fields[1].AsString) + ')'
else if aaa='应扣合计'then
ProjectRec[i].expression:=ProjectRec[i].expression + 'Pay' + ')'
else
ProjectRec[i].expression := copy(ProjectRec[i].expression,1,length(ProjectRec[i].expression)-1) + ')';
end;
end;
Dm2.qryFormula.Next;
inc(i);
end;
Counter:=i;
// 以上为求出计算公式,眕奻峈莶堤数呾鼠宒
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -