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

📄 unit_attenstat.pas

📁 主要用于美容院的内部管理.有使用说明.下载后查看其功能!
💻 PAS
📖 第 1 页 / 共 2 页
字号:
unit Unit_Attenstat;

interface

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

type
  Tfrm_attendstat = class(TForm)
    Panel1: TPanel;
    PageControl1: TPageControl;
    sht_StatList: TTabSheet;
    sht_statdetail: TTabSheet;
    sg_Statistic: TStringGrid;
    sg_Detail: TStringGrid;
    sbtn_front: TSpeedButton;
    sbtn_back: TSpeedButton;
    SpeedButton2: TSpeedButton;
    Splitter1: TSplitter;
    StatusBar1: TStatusBar;
    Panel2: TPanel;
    sbtn_print: TSpeedButton;
    sbtn_Show: TSpeedButton;
    ListBox1: TListBox;
    Splitter2: TSplitter;
    Panel3: TPanel;
    GroupBox1: TGroupBox;
    Label4: TLabel;
    Label5: TLabel;
    Label6: TLabel;
    Label7: TLabel;
    Label10: TLabel;
    Label11: TLabel;
    sbtn_attendstat: TSpeedButton;
    Label3: TLabel;
    Label2: TLabel;
    Label1: TLabel;
    cbb_Year: TComboBox;
    cbb_Month: TComboBox;
    procedure sbtn_attendstatClick(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure SpeedButton2Click(Sender: TObject);
    procedure sg_StatisticSelectCell(Sender: TObject; ACol, ARow: Integer;
      var CanSelect: Boolean);
    procedure sbtn_ShowClick(Sender: TObject);
    procedure PageControl1Changing(Sender: TObject;
      var AllowChange: Boolean);
    procedure sbtn_backClick(Sender: TObject);
    procedure sbtn_frontClick(Sender: TObject);
    procedure sg_DetailSelectCell(Sender: TObject; ACol, ARow: Integer;
      var CanSelect: Boolean);
    procedure sbtn_printClick(Sender: TObject);
  private
    //pre_morning,aft_morning,pre_afternoon,aft_afternoon,pre_evening,aft_evening:TDateTime;
    time_set:array of string;
    temp_MinDate,temp_MaxDate:string;
    
    procedure GetDetailNormalAttendInfo(temp_Empno,temp_Empname,temp_MinDate,temp_MaxDate:string);
    procedure GetDetailSpecialAttendInfo(temp_Empno,temp_Empname,temp_MinDate,temp_MaxDate:string);
    function  GetAttendTimeSet:boolean;
    procedure SaveAttendStatistic;
    { Private declarations }
  public
    { Public declarations }
    temp_yearmonth:string;
    procedure attendstat_ref;
  end;

var
  frm_attendstat: Tfrm_attendstat;

implementation
  uses unit_DataModule,unit_TotalPublic,PublicFunOrPro;
{$R *.dfm}

{*******************用户过程定义********************}
procedure Tfrm_attendstat.attendstat_ref ;
begin
  with sg_statistic do
  begin
    cells[0,0] := '员工编号';
    cells[1,0] := '员工姓名';
    cells[2,0] := '总共工作';
    cells[3,0] := '总共出勤';
    cells[4,0] := '上午迟到';
    cells[5,0] := '上午早退';
    cells[6,0] := '下午迟到';
    cells[7,0] := '下午早退';
    cells[8,0] := '晚上迟到';
    cells[9,0] := '晚上早退';
    cells[10,0]:= '总共迟到';
    cells[11,0]:= '总共早退';
    cells[12,0]:= '特殊考勤';
  end;

  with sg_Detail do
  begin
    cells[0,0] := '员工编号';
    cells[1,0] := '员工编号';
    cells[2,0] := '考勤日期';
    cells[3,0] := '上午上班';
    cells[4,0] := '上午下班';
    cells[5,0] := '下午上班';
    cells[6,0] := '下午下班';
    cells[7,0] := '晚上上班';
    cells[8,0] := '晚上下班';
  end;

  sbtn_attendstat.Enabled := GetPower(SysUserId,'考勤统计','修改权');
  sbtn_print.Enabled  := GetPower(SysUserId,'考勤统计','打印权');
end;

procedure Tfrm_attendstat.GetDetailNormalAttendInfo(temp_Empno,temp_Empname,temp_MinDate,temp_MaxDate:string);
var
  i:integer;
begin
  if sg_Statistic.Cells[0,sg_Statistic.row]='' then exit;

  pagecontrol1.ActivePage := sht_statdetail;
  
  with dmod.qrydata do
  begin
    Close;
    SQL.Text :='select * from NormalAttend where emp_no='+#39+temp_Empno+#39+
               ' and att_date between '+#39+temp_MinDate+#39+' and '+#39+temp_MaxDate+#39;
    Open;
    i:=1;
    while not eof do
    begin
      with sg_Detail do
      begin
        cells[0,i]:=temp_Empno;
        cells[1,i]:=temp_Empname;
        cells[2,i]:=FieldByName('att_date').AsString ;
        cells[3,i]:=TimeToStr(FieldByName('pre_morning').AsDateTime) ;
        cells[4,i]:=TimeToStr(FieldByName('aft_morning').AsDateTime) ;
        cells[5,i]:=TimeToStr(FieldByName('pre_afternoon').AsDateTime) ;
        cells[6,i]:=TimeToStr(FieldByName('aft_afternoon').AsDateTime) ;
        cells[7,i]:=TimeToStr(FieldByName('pre_evening').AsDateTime) ;
        cells[8,i]:=TimeToStr(FieldByName('aft_evening').AsDateTime) ;
      end;
      inc(i);
      next;
    end;
  end;
  if i<>1 then sg_Detail.RowCount :=i+1;
end;

procedure Tfrm_attendstat.GetDetailSpecialAttendInfo(temp_Empno,temp_Empname,temp_MinDate,temp_MaxDate:string);
begin
  ListBox1.Clear ;
  ListBox1.Items.Add('特殊考勤记录');
   
  with dmod.qrydata do
  begin
    Close;
    SQL.Text :='select a.att_date,a.time_start,a.time_end,r.reason_remark from SpecialAttend a,SpecialReason r where a.reason_id=r.reason_id'+
               ' and a.emp_no='+#39+temp_Empno+#39+' and a.att_date between '+#39+temp_MinDate+#39+' and '+#39+temp_MaxDate+#39;
    Open;
    while not eof do
    begin
      ListBox1.Items.Add(FieldByName('att_date').AsString);
      Listbox1.Items.Add(TimeToStr(FieldByName('time_start').AsDateTime)+'-'+TimeToStr(FieldByName('time_end').AsDateTime));
      Listbox1.Items.Add(FieldByName('reason_remark').AsString);
      ListBox1.Items.Add('----------');

      next;
    end;
  end;
end;

function Tfrm_attendStat.GetAttendTimeSet :boolean;
var
  i,array_length:integer;
begin
  result:=true;
  //得到正确的时间设置,至少为4条记录
  with dmod.qrydata do
  begin
    Close;
    SQL.Text :='select count(*) as count from attendtime';
    Open;
    array_length:=FieldByName('count').AsInteger ;
  end;

  if array_length<4 then
  begin
    MessageBox(handle,'你还没有设置正确的考勤时间,无法统计!','提示',mb_ok+mb_iconinformation);
    result:=false;
    exit;
  end;
  //设置动态标准时间数组
  SetLength(time_set,array_length);

  //得到标准考勤时间
  with dmod.qrydata do
  begin
    Close;
    SQL.Text :='select * from attendtime order by order_by';
    Open;
    i:=0;
    while not Eof do
    begin
      time_set[i]:=TimeToStr(FieldByName('time_time').AsDateTime);
      inc(i);
      next;
    end;
    result:=true;
  end;
end;

procedure Tfrm_attendstat.SaveAttendStatistic ;
var
  i:integer;
begin
  try
    dmod.Database.StartTransaction ;
    with dmod.qrydata do
    begin
      Close;
      SQL.Text :='select count(*) as count from EmployeeAttendStatistic where year_month='+#39+temp_yearmonth+#39;
      Open;
      if FieldByName('count').AsInteger >0 then
      begin
        Close;
        SQL.Text :='delete from EmployeeAttendStatistic where year_month='+#39+temp_yearmonth+#39;
        ExecSQL;
      end;

      for i:=1 to sg_Statistic.rowcount-2 do
      begin
        Close;
        SQL.Text :='insert into EmployeeAttendStatistic(emp_no,year_month,total_work,total_attend,late_morning,'+
                   'early_morning,late_afternoon,early_afternoon,late_evening,early_evening,total_late,total_early,'+
                   'special_attend) values(:empno,:yearmonth,:totalwork,:totalattend,:latemorning,:earlymorning,'+
                   ':lateafternoon,:earlyafternoon,:lateevening,:earlyevening,:totallate,:totalearly,:specialattend)';
        ParamByName('empno').AsString      :=sg_Statistic.Cells[0,i];
        ParamByName('yearmonth').AsString  :=temp_yearmonth;
        ParamByName('totalwork').AsInteger    :=StrToInt(sg_Statistic.Cells[2,i]);
        ParamByName('totalattend').AsInteger  :=StrToInt(sg_Statistic.Cells[3,i]);
        ParamByName('latemorning').AsInteger  :=StrToInt(sg_Statistic.Cells[4,i]);
        ParamByName('earlymorning').AsInteger :=StrToInt(sg_Statistic.Cells[5,i]);
        ParamByName('lateafternoon').AsInteger:=StrToInt(sg_Statistic.Cells[6,i]);
        ParamByName('earlyafternoon').AsInteger:=StrToInt(sg_Statistic.Cells[7,i]);
        ParamByName('lateevening').AsInteger   :=StrToInt(sg_Statistic.Cells[8,i]);
        ParamByName('earlyevening').AsInteger  :=StrToInt(sg_Statistic.Cells[9,i]);
        ParamByName('totallate').AsInteger     :=StrToInt(sg_Statistic.Cells[10,i]);
        ParamByName('totalearly').AsInteger    :=StrToInt(sg_Statistic.Cells[11,i]);
        ParamByName('specialattend').AsInteger :=StrToInt(sg_Statistic.Cells[12,i]);
        ExecSQL;
      end;
    end;
  finally
    try
      dmod.Database.Commit ;
    except
      dmod.Database.Rollback ;
    end;
  end;

end;

⌨️ 快捷键说明

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