311 lines
7.9 KiB
ObjectPascal
311 lines
7.9 KiB
ObjectPascal
|
|
unit U_SalaryList;
|
|||
|
|
|
|||
|
|
interface
|
|||
|
|
|
|||
|
|
uses
|
|||
|
|
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
|
|||
|
|
Dialogs, StdCtrls, ExtCtrls, ComCtrls, ToolWin, cxStyles, cxCustomData,
|
|||
|
|
cxGraphics, cxFilter, cxData, cxDataStorage, cxEdit, DB, cxDBData, ADODB,
|
|||
|
|
cxGridCustomPopupMenu, cxGridPopupMenu, cxGridLevel, cxClasses, cxControls,
|
|||
|
|
cxGridCustomView, cxGridCustomTableView, cxGridTableView, cxGridDBTableView,
|
|||
|
|
cxGrid, DBClient, cxTextEdit, DateUtils, cxLookAndFeels,
|
|||
|
|
cxLookAndFeelPainters, cxNavigator, U_BaseList, dxSkinsCore,
|
|||
|
|
dxSkinsDefaultPainters, dxDateRanges, dxSkinWXI, dxScrollbarAnnotations,
|
|||
|
|
dxBarBuiltInMenu;
|
|||
|
|
|
|||
|
|
type
|
|||
|
|
TfrmSalaryList = class(TfrmBaseList)
|
|||
|
|
ToolBar1: TToolBar;
|
|||
|
|
TBRafresh: TToolButton;
|
|||
|
|
TBAdd: TToolButton;
|
|||
|
|
TBEdit: TToolButton;
|
|||
|
|
TBExport: TToolButton;
|
|||
|
|
TBClose: TToolButton;
|
|||
|
|
cxGridPopupMenu1: TcxGridPopupMenu;
|
|||
|
|
ADOQueryCmd: TADOQuery;
|
|||
|
|
ADOQueryMain: TADOQuery;
|
|||
|
|
ADOQueryTemp: TADOQuery;
|
|||
|
|
DataSource1: TDataSource;
|
|||
|
|
Order_Main: TClientDataSet;
|
|||
|
|
Panel1: TPanel;
|
|||
|
|
Label1: TLabel;
|
|||
|
|
YMDate: TDateTimePicker;
|
|||
|
|
cxGrid1: TcxGrid;
|
|||
|
|
Tv1: TcxGridDBTableView;
|
|||
|
|
v1EEName: TcxGridDBColumn;
|
|||
|
|
v1D01: TcxGridDBColumn;
|
|||
|
|
v1D02: TcxGridDBColumn;
|
|||
|
|
v1D03: TcxGridDBColumn;
|
|||
|
|
v1D04: TcxGridDBColumn;
|
|||
|
|
v1D05: TcxGridDBColumn;
|
|||
|
|
v1D06: TcxGridDBColumn;
|
|||
|
|
v1D07: TcxGridDBColumn;
|
|||
|
|
v1D08: TcxGridDBColumn;
|
|||
|
|
v1D09: TcxGridDBColumn;
|
|||
|
|
v1D10: TcxGridDBColumn;
|
|||
|
|
v1D11: TcxGridDBColumn;
|
|||
|
|
v1D12: TcxGridDBColumn;
|
|||
|
|
v1D13: TcxGridDBColumn;
|
|||
|
|
v1D14: TcxGridDBColumn;
|
|||
|
|
v1D15: TcxGridDBColumn;
|
|||
|
|
v1D16: TcxGridDBColumn;
|
|||
|
|
v1D17: TcxGridDBColumn;
|
|||
|
|
v1D18: TcxGridDBColumn;
|
|||
|
|
v1D19: TcxGridDBColumn;
|
|||
|
|
v1D20: TcxGridDBColumn;
|
|||
|
|
v1D21: TcxGridDBColumn;
|
|||
|
|
v1D22: TcxGridDBColumn;
|
|||
|
|
v1D23: TcxGridDBColumn;
|
|||
|
|
v1D24: TcxGridDBColumn;
|
|||
|
|
v1D25: TcxGridDBColumn;
|
|||
|
|
v1D26: TcxGridDBColumn;
|
|||
|
|
v1D27: TcxGridDBColumn;
|
|||
|
|
v1D28: TcxGridDBColumn;
|
|||
|
|
v1D29: TcxGridDBColumn;
|
|||
|
|
v1D30: TcxGridDBColumn;
|
|||
|
|
v1D31: TcxGridDBColumn;
|
|||
|
|
v1DHJ: TcxGridDBColumn;
|
|||
|
|
cxGrid1Level1: TcxGridLevel;
|
|||
|
|
procedure FormDestroy(Sender: TObject);
|
|||
|
|
procedure FormClose(Sender: TObject; var Action: TCloseAction);
|
|||
|
|
procedure FormCreate(Sender: TObject);
|
|||
|
|
procedure FormShow(Sender: TObject);
|
|||
|
|
procedure TBCloseClick(Sender: TObject);
|
|||
|
|
procedure TBRafreshClick(Sender: TObject);
|
|||
|
|
procedure TBAddClick(Sender: TObject);
|
|||
|
|
procedure TBEditClick(Sender: TObject);
|
|||
|
|
procedure TBExportClick(Sender: TObject);
|
|||
|
|
procedure YMDateChange(Sender: TObject);
|
|||
|
|
procedure Tv1CellDblClick(Sender: TcxCustomGridTableView; ACellViewInfo: TcxGridTableDataCellViewInfo; AButton: TMouseButton; AShift: TShiftState; var AHandled: Boolean);
|
|||
|
|
private
|
|||
|
|
FYMonth: string; //<2F><>ǰ<EFBFBD><C7B0><EFBFBD><EFBFBD>(yyyymm)
|
|||
|
|
FInitFlag: Boolean;
|
|||
|
|
procedure InitGrid();
|
|||
|
|
function DayField(i: Integer): string;
|
|||
|
|
function CalcRowHJ(): Double;
|
|||
|
|
function GetFocusedDay(): Integer;
|
|||
|
|
{ Private declarations }
|
|||
|
|
public
|
|||
|
|
{ Public declarations }
|
|||
|
|
end;
|
|||
|
|
|
|||
|
|
var
|
|||
|
|
frmSalaryList: TfrmSalaryList;
|
|||
|
|
|
|||
|
|
implementation
|
|||
|
|
|
|||
|
|
uses
|
|||
|
|
U_DataLink, U_RTFun, U_SalaryInPut;
|
|||
|
|
|
|||
|
|
{$R *.dfm}
|
|||
|
|
function TfrmSalaryList.GetFocusedDay(): Integer;
|
|||
|
|
var
|
|||
|
|
FCol: TcxGridColumn;
|
|||
|
|
FFieldName: string;
|
|||
|
|
begin
|
|||
|
|
Result := 0;
|
|||
|
|
if Tv1.Controller = nil then
|
|||
|
|
Exit;
|
|||
|
|
FCol := Tv1.Controller.FocusedColumn;
|
|||
|
|
if FCol = nil then
|
|||
|
|
Exit;
|
|||
|
|
if not (FCol is TcxGridDBColumn) then
|
|||
|
|
Exit;
|
|||
|
|
FFieldName := TcxGridDBColumn(FCol).DataBinding.FieldName;
|
|||
|
|
if Length(FFieldName) <> 3 then
|
|||
|
|
Exit;
|
|||
|
|
if FFieldName[1] <> 'D' then
|
|||
|
|
Exit;
|
|||
|
|
if not TryStrToInt(Copy(FFieldName, 2, 2), Result) then
|
|||
|
|
begin
|
|||
|
|
Result := 0;
|
|||
|
|
Exit;
|
|||
|
|
end;
|
|||
|
|
if (Result < 1) or (Result > 31) then
|
|||
|
|
Result := 0;
|
|||
|
|
end;
|
|||
|
|
|
|||
|
|
procedure TfrmSalaryList.FormCreate(Sender: TObject);
|
|||
|
|
begin
|
|||
|
|
inherited;
|
|||
|
|
FInitFlag := True;
|
|||
|
|
YMDate.Date := SGetServerDate(ADOQueryTemp);
|
|||
|
|
FInitFlag := False;
|
|||
|
|
end;
|
|||
|
|
|
|||
|
|
procedure TfrmSalaryList.FormDestroy(Sender: TObject);
|
|||
|
|
begin
|
|||
|
|
inherited;
|
|||
|
|
frmSalaryList := nil;
|
|||
|
|
end;
|
|||
|
|
|
|||
|
|
procedure TfrmSalaryList.FormClose(Sender: TObject; var Action: TCloseAction);
|
|||
|
|
begin
|
|||
|
|
inherited;
|
|||
|
|
Action := caFree;
|
|||
|
|
end;
|
|||
|
|
|
|||
|
|
procedure TfrmSalaryList.FormShow(Sender: TObject);
|
|||
|
|
begin
|
|||
|
|
inherited;
|
|||
|
|
ReadCxGrid(Trim(Self.Caption), Tv1, 'OA<4F><41><EFBFBD><EFBFBD>');
|
|||
|
|
InitGrid();
|
|||
|
|
end;
|
|||
|
|
|
|||
|
|
procedure TfrmSalaryList.TBCloseClick(Sender: TObject);
|
|||
|
|
begin
|
|||
|
|
Close;
|
|||
|
|
WriteCxGrid(Trim(Self.Caption), Tv1, 'OA<4F><41><EFBFBD><EFBFBD>');
|
|||
|
|
end;
|
|||
|
|
|
|||
|
|
procedure TfrmSalaryList.TBRafreshClick(Sender: TObject);
|
|||
|
|
begin
|
|||
|
|
InitGrid();
|
|||
|
|
end;
|
|||
|
|
|
|||
|
|
procedure TfrmSalaryList.TBAddClick(Sender: TObject);
|
|||
|
|
var
|
|||
|
|
FDay: Integer;
|
|||
|
|
begin
|
|||
|
|
FDay := GetFocusedDay();
|
|||
|
|
if FDay = 0 then
|
|||
|
|
FDay := DayOf(YMDate.Date);
|
|||
|
|
try
|
|||
|
|
frmSalaryInPut := TfrmSalaryInPut.Create(Application);
|
|||
|
|
with frmSalaryInPut do
|
|||
|
|
begin
|
|||
|
|
PState := 0;
|
|||
|
|
FYMonth := Self.FYMonth;
|
|||
|
|
FInitDay := FDay;
|
|||
|
|
if ShowModal = 1 then
|
|||
|
|
InitGrid();
|
|||
|
|
end;
|
|||
|
|
finally
|
|||
|
|
frmSalaryInPut.Free;
|
|||
|
|
end;
|
|||
|
|
end;
|
|||
|
|
|
|||
|
|
procedure TfrmSalaryList.TBEditClick(Sender: TObject);
|
|||
|
|
var
|
|||
|
|
FDay: Integer;
|
|||
|
|
begin
|
|||
|
|
FDay := GetFocusedDay();
|
|||
|
|
if FDay = 0 then
|
|||
|
|
FDay := DayOf(YMDate.Date);
|
|||
|
|
try
|
|||
|
|
frmSalaryInPut := TfrmSalaryInPut.Create(Application);
|
|||
|
|
with frmSalaryInPut do
|
|||
|
|
begin
|
|||
|
|
PState := 1;
|
|||
|
|
FYMonth := Self.FYMonth;
|
|||
|
|
FInitDay := FDay;
|
|||
|
|
if ShowModal = 1 then
|
|||
|
|
InitGrid();
|
|||
|
|
end;
|
|||
|
|
finally
|
|||
|
|
frmSalaryInPut.Free;
|
|||
|
|
end;
|
|||
|
|
end;
|
|||
|
|
|
|||
|
|
procedure TfrmSalaryList.TBExportClick(Sender: TObject);
|
|||
|
|
begin
|
|||
|
|
if ADOQueryMain.IsEmpty then
|
|||
|
|
Exit;
|
|||
|
|
TcxGridToExcel(Trim(Self.Caption), cxGrid1);
|
|||
|
|
end;
|
|||
|
|
|
|||
|
|
procedure TfrmSalaryList.YMDateChange(Sender: TObject);
|
|||
|
|
begin
|
|||
|
|
if FInitFlag then
|
|||
|
|
Exit;
|
|||
|
|
InitGrid();
|
|||
|
|
end;
|
|||
|
|
|
|||
|
|
procedure TfrmSalaryList.Tv1CellDblClick(Sender: TcxCustomGridTableView; ACellViewInfo: TcxGridTableDataCellViewInfo; AButton: TMouseButton; AShift: TShiftState; var AHandled: Boolean);
|
|||
|
|
begin
|
|||
|
|
if Order_Main.IsEmpty then
|
|||
|
|
Exit;
|
|||
|
|
TBEdit.Click;
|
|||
|
|
end;
|
|||
|
|
|
|||
|
|
function TfrmSalaryList.DayField(i: Integer): string;
|
|||
|
|
begin
|
|||
|
|
Result := 'D' + Format('%.2d', [i]);
|
|||
|
|
end;
|
|||
|
|
|
|||
|
|
procedure TfrmSalaryList.InitGrid();
|
|||
|
|
var
|
|||
|
|
i, FDays: Integer;
|
|||
|
|
FCol: TcxGridDBColumn;
|
|||
|
|
FDateStart: TDateTime;
|
|||
|
|
begin
|
|||
|
|
FYMonth := FormatDateTime('yyyymm', YMDate.Date);
|
|||
|
|
FDays := DaysInMonth(YMDate.Date);
|
|||
|
|
FDateStart := EncodeDate(StrToInt(Copy(FYMonth, 1, 4)), StrToInt(Copy(FYMonth, 5, 2)), 1);
|
|||
|
|
try
|
|||
|
|
ADOQueryMain.DisableControls;
|
|||
|
|
with ADOQueryMain do
|
|||
|
|
begin
|
|||
|
|
Filtered := False;
|
|||
|
|
Close;
|
|||
|
|
SQL.Clear;
|
|||
|
|
SQL.Add(' select E.EEID,E.EECode,E.EEName,E.Dept ');
|
|||
|
|
for i := 1 to 31 do
|
|||
|
|
SQL.Add(' ,max(case when day(S.GZRQ)=' + IntToStr(i) + ' then S.GZS end) as ' + DayField(i) + ' ');
|
|||
|
|
SQL.Add(' from SY_Employee E ');
|
|||
|
|
SQL.Add(' left join SY_Salary S on S.EEID=E.EEID ');
|
|||
|
|
SQL.Add(' and S.GZRQ>=' + quotedstr(FormatDateTime('yyyy-mm-dd', FDateStart)));
|
|||
|
|
SQL.Add(' and S.GZRQ<' + quotedstr(FormatDateTime('yyyy-mm-dd', IncMonth(FDateStart, 1))));
|
|||
|
|
SQL.Add(' where isnull(E.EEType,''<27><>ʽ'')<>''<27><>ְ'' or S.EEID is not null ');
|
|||
|
|
SQL.Add(' group by E.EEID,E.EECode,E.EEName,E.Dept ');
|
|||
|
|
SQL.Add(' order by E.EECode ');
|
|||
|
|
Open;
|
|||
|
|
end;
|
|||
|
|
SCreateCDS(ADOQueryMain, Order_Main);
|
|||
|
|
Order_Main.Close;
|
|||
|
|
Order_Main.FieldDefs.Add('DHJ', ftFloat);
|
|||
|
|
Order_Main.CreateDataSet;
|
|||
|
|
TFloatField(Order_Main.FieldByName('DHJ')).DisplayFormat := '0.##';
|
|||
|
|
SInitCDSData(ADOQueryMain, Order_Main);
|
|||
|
|
//<2F><><EFBFBD><EFBFBD>С<EFBFBD><D0A1>
|
|||
|
|
with Order_Main do
|
|||
|
|
begin
|
|||
|
|
DisableControls;
|
|||
|
|
First;
|
|||
|
|
while not Eof do
|
|||
|
|
begin
|
|||
|
|
Edit;
|
|||
|
|
FieldByName('DHJ').Value := CalcRowHJ();
|
|||
|
|
Post;
|
|||
|
|
Next;
|
|||
|
|
end;
|
|||
|
|
First;
|
|||
|
|
EnableControls;
|
|||
|
|
end;
|
|||
|
|
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʾ<EFBFBD><CABE><EFBFBD><EFBFBD>
|
|||
|
|
for i := 1 to 31 do
|
|||
|
|
begin
|
|||
|
|
FCol := Tv1.GetColumnByFieldName(DayField(i));
|
|||
|
|
if FCol <> nil then
|
|||
|
|
FCol.Visible := (i <= FDays);
|
|||
|
|
end;
|
|||
|
|
finally
|
|||
|
|
ADOQueryMain.EnableControls;
|
|||
|
|
end;
|
|||
|
|
end;
|
|||
|
|
|
|||
|
|
function TfrmSalaryList.CalcRowHJ(): Double;
|
|||
|
|
var
|
|||
|
|
i: Integer;
|
|||
|
|
FVal: Double;
|
|||
|
|
begin
|
|||
|
|
Result := 0;
|
|||
|
|
for i := 1 to 31 do
|
|||
|
|
begin
|
|||
|
|
if TryStrToFloat(Trim(Order_Main.fieldbyname(DayField(i)).AsString), FVal) then
|
|||
|
|
Result := Result + FVal;
|
|||
|
|
end;
|
|||
|
|
end;
|
|||
|
|
|
|||
|
|
end.
|