当前位置:编程学习 > Delphi >>

delphi实现执勤表

按周循环排班, 员工人数及值班人数可自定义.

单元文件


[delphi]
unit Unit15; 
 
inte易做图ce 
 
uses 
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, 
  Dialogs, StdCtrls; 
 
type 
  TForm15 = class(TForm) 
    mmo1: TMemo; 
    cbb_Month: TComboBox; 
    procedure FormCreate(Sender: TObject); 
    procedure cbb_MonthChange(Sender: TObject); 
  private 
    type 
      //定义周  
      TWeekEnum = (wkSunday, wkMonday, wkTuesday, wkWednesday, wkThursday, wkFriday, wkSaturday); 
    const 
      //定义每周中各天的值班人数  
      weekArr: array[TWeekEnum] of Integer = (2, 1, 1, 1, 1, 1, 2); 
      //定义值班员工数  
      FEmployeeCount = 13; 
    { Private declarations } 
  private 
    FCurrEmployee : integer; 
  public 
    { Public declarations } 
  end; 
 
var 
  Form15: TForm15; 
 
implementation 
uses DateUtils; 
{$R *.dfm} 
procedure TForm15.FormCreate(Sender: TObject); 
var 
  i: Integer; 
begin 
  FCurrEmployee := 1; //从第1个员工开始  
 
  //初始化月份  
  cbb_Month.Clear; 
  for i := 1 to 12 do 
    cbb_Month.Items.Add(IntToStr(i)); 
 
  cbb_Month.ItemIndex := 0;   //从1月开始排班  
  cbb_MonthChange(cbb_Month); //触发排班事件  
end; 
 
procedure TForm15.cbb_MonthChange(Sender: TObject); 
  //获得当天值班的员工名单  
  function getEmployees(const AweekDay : TWeekEnum) : string; 
    function getEmployee: string; 
    begin 
      Result := Format('员工%d ', [FCurrEmployee]); 
 
      Inc(FCurrEmployee); 
      if FCurrEmployee > FEmployeeCount then 
        FCurrEmployee := 1; 
    end; 
  var 
    i: Integer; 
  begin 
    Result := ''; 
    for i := 0 to weekArr[AweekDay] do 
      Result := Result + getEmployee; 
  end; 
var 
  i: Integer; 
  vWeekDay: TWeekEnum; 
  days : integer; 
begin 
  //当月天数  
  days := DaysInAMonth(2013, strtoint(cbb_Month.Text)); 
  //当月第一天的星期起始数  
  vWeekDay := TWeekEnum(DayOfWeek(StrToDateTime('2013' + DateSeparator + cbb_Month.Text + DateSeparator + '01')) - 1); 
 
  //打印排班表  
  mmo1.Lines.BeginUpdate; 
  try 
    mmo1.clear; 
    for i := 1 to days do 
    begin 
      mmo1.Lines.Add(Format( '2013-%s-%d(星期%d), 值班员工:%s', 
        [cbb_Month.Text, i, Ord(vWeekDay), getEmployees(vWeekDay)] 
        )); 
 
      if vWeekDay = wkSaturday then 
        vWeekDay := wkSunday 
      else 
        vWeekDay := TWeekEnum(ord(vWeekDay) + 1); 
    end; 
  finally 
    mmo1.Lines.EndUpdate; 
  end; 
end; 
 
end. 

unit Unit15;

inte易做图ce

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls;

type
  TForm15 = class(TForm)
    mmo1: TMemo;
    cbb_Month: TComboBox;
    procedure FormCreate(Sender: TObject);
    procedure cbb_MonthChange(Sender: TObject);
  private
    type
      //定义周
      TWeekEnum = (wkSunday, wkMonday, wkTuesday, wkWednesday, wkThursday, wkFriday, wkSaturday);
    const
      //定义每周中各天的值班人数
      weekArr: array[TWeekEnum] of Integer = (2, 1, 1, 1, 1, 1, 2);
      //定义值班员工数
      FEmployeeCount = 13;
    { Private declarations }
  private
    FCurrEmployee : integer;
  public
    { Public declarations }
  end;

var
  Form15: TForm15;

implementation
uses DateUtils;
{$R *.dfm}
procedure TForm15.FormCreate(Sender: TObject);
var
  i: Integer;
begin
  FCurrEmployee := 1; //从第1个员工开始

  //初始化月份
  cbb_Month.Clear;
  for i := 1 to 12 do
    cbb_Month.Items.Add(IntToStr(i));

  cbb_Month.ItemIndex := 0;   //从1月开始排班
  cbb_MonthChange(cbb_Month); //触发排班事件
end;

procedure TForm15.cbb_MonthChange(Sender: TObject);
  //获得当天值班的员工名单
  function getEmployees(const AweekDay : TWeekEnum) : string;
    function getEmployee: string;
    begin
      Result := Format('员工%d ', [FCurrEmployee]);

      Inc(FCurrEmployee);
      if FCurrEmployee > FEmployeeCount then
        FCurrEmployee := 1;
    end;
  var
    i: Integer;
  begin
    Result := '';
    for i := 0 to weekArr[AweekDay] do
      Result := Result + getEmployee;
  end;
var
  i: Integer;
  vWeekDay: TWeekEnum;
  days : integer;
begin
  //当月天数
  days := DaysInAMonth(2013, strtoint(cbb_Month.Text));
  //当月第一天的星期起始数
  vWeekDay := TWeekEnum(DayOfWeek(StrToDateTime('2013' + DateSeparator + cbb_Month.Text + DateSeparator + '01')) - 1);

  //打印排班表
  mmo1.Lines.BeginUpdate;
  try
    mmo1.clear;
    for i := 1 to days do
    begin
      mmo1.Lines.Add(Format( '2013-%s-%d(星期%d), 值班员工:%s',
        [cbb_Month.Text, i, Ord(vWeekDay), getEmployees(vWeekDay)]

补充:软件开发 , Delphi ,
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,