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

📄 gatecard.pas

📁 一个Delphi写的跟考勤机门禁机收款机的接品软件源码
💻 PAS
字号:
unit GateCard;

interface

uses
  Windows, SysUtils, Classes, Graphics, Controls, Forms,
  EastRiver, StdCtrls, Mask, ComCtrls, ExtCtrls, PrjConst;

type
  TdlgGateCard = class(TForm)
    lbCardId: TLabel;
    lbEmpId: TLabel;
    edCardNo: TMaskEdit;
    edEmpId: TMaskEdit;
    btnOK: TButton;
    btnCancel: TButton;
    plPeriods: TPanel;
    lvPeriods: TListView;
    btnAdd: TButton;
    btnDelete: TButton;
    plPwd: TPanel;
    lbLevel: TLabel;
    lbPwd: TLabel;
    cbLevel: TComboBox;
    cbONE: TCheckBox;
    cbTHREE: TCheckBox;
    cbTWO: TCheckBox;
    cbFOUR: TCheckBox;
    edPwd: TMaskEdit;
    cbPeriods: TCheckBox;
    procedure FormShow(Sender: TObject);
    procedure FormDestroy(Sender: TObject);
    procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean);
    procedure btnAddClick(Sender: TObject);
    procedure btnDeleteClick(Sender: TObject);
    procedure lvPeriodsDblClick(Sender: TObject);
    procedure edEmpIdKeyPress(Sender: TObject; var Key: Char);
    procedure cbPeriodsClick(Sender: TObject);
  private
    { Private declarations }
    FKind: Integer;
  public
    { Public declarations }
    Fpclk: PClockInfo;
    b880Style: Boolean;
    SaveModel: Integer;
    function Execute(pclk: PClockInfo;var CardNo, EmpId, pwd, periods: string;var Right: Integer; iKind: Integer): Boolean;
  end;

var
  dlgGateCard: TdlgGateCard;

implementation

uses Main, Functions, Periods;

{$R *.DFM}
const
  PeriodsHeight:Integer=120;

function TdlgGateCard.Execute(pclk: PClockInfo;var CardNo, EmpId, pwd, periods: string;var Right: Integer; iKind: Integer): Boolean;
var
  i: Integer;
  Strs: TStrings;
begin
  if not Assigned(dlgGateCard) then
    dlgGateCard := TdlgGateCard.Create(Application);
  Self:=dlgGateCard;
  FKind:=iKind;
  fpclk:=pclk;
  if pclk.model<>SaveModel then
    cbPeriods.Checked:=not (pclk.VerOrd>2);
  edCardNo.SelStart := 0;
  edCardNo.SelectAll;
  if ShowModal = mrOK then
  begin
    if  (lvPeriods.Items.Count=0)or (not  cbPeriods.Checked ) then
     Application.MessageBox(pchar(TimePeriod),Pchar(self.caption),MB_IconWarning);    
    SaveModel:=pclk.model;
    CardNo:=edCardNo.Text;
    EmpId:=edEmpId.Text;
    b880Style:=cbPeriods.Checked;
    if b880Style then
    begin
      pwd:='';
      Strs:=TStringList.Create;
      try
        for i:=0 to lvPeriods.Items.Count-1 do
        begin
          Strs.Add(lvPeriods.Items[i].Caption+lvPeriods.Items[i].SubItems[0]);
        end;
        StrsToPeriods(Strs, Periods);
      finally
        Strs.Free;
      end;
    end else
    begin
      pwd:=edPwd.Text;
      Right:=0;
      if cbONE.Checked then Right:=Right or 1;
      if cbTWO.Checked then Right:=Right or 2;
      if cbTHREE.Checked then Right:=Right or 4;
      if cbFOUR.Checked then Right:=Right or 8;
      Right:=Right or (cbLevel.ItemIndex shl 4);
    end;
    Result := True;
  end else
    Result:=False;
end;

procedure TdlgGateCard.FormShow(Sender: TObject);
  procedure GrayControl(lb: TLabel; Control: TMaskEdit; Enable: Boolean);
  begin
    if Enable then
    begin
      lb.Enabled:=True;
      Control.Enabled:=True;
      Control.Color:=clWindow
    end else
    begin
      lb.Enabled:=False;
      Control.Enabled:=False;
      Control.Color:=clBtnFace;
    end;
  end;
begin
  if edCardNo.CanFocus then edCardNo.SetFocus;
  case FKind of
    0:{白名单}
      begin
        GrayControl(lbCardId, edCardNo, True);
        GrayControl(lbEmpId, edEmpId, GetClockSupports(fpclk.hPort, fiHaveEmpId));
        plPwd.Visible:=False;
        plPeriods.Visible:=False;
      end;
    1:{黑名单}
      begin
        GrayControl(lbCardId, edCardNo, True);
        GrayControl(lbEmpId, edEmpId, False);
        plPwd.Visible:=False;
        plPeriods.Visible:=False;
      end;
    2:{门禁通行名单}
      begin
        GrayControl(lbCardId, edCardNo, True);
        GrayControl(lbEmpId, edEmpId, GetClockSupports(fpclk.hPort, fiHaveEmpId));
      end;
  end;
end;

procedure TdlgGateCard.FormDestroy(Sender: TObject);
begin
  dlgGateCard:=nil;
end;

procedure TdlgGateCard.FormCloseQuery(Sender: TObject;
  var CanClose: Boolean);
begin
  if ModalResult=mrOK then
  begin
    if edCardNo.Text='' then
    begin
      if edCardNo.Canfocus then edCardNo.SetFocus;
      Raise Exception.Create(SCeEaEeA);
    end;
    if (FKind=2)and (fpclk.VerOrd>2)and(Length(edPwd.Text)<>4) and ((fpclk.clock_type=980) or (fpclk.clock_type=981)  ) then
    begin
      ModalResult:=mrNONE;
      if edPwd.Canfocus then edPwd.SetFocus;
      Raise Exception.Create(SCeEaEeAAAUAe);
    end;
  end;
end;

procedure TdlgGateCard.btnAddClick(Sender: TObject);
var
  sBegin, SEnd: String;
begin
  if dlgPeriods.Execute(sbegin, send) then
  begin
    with lvPeriods.Items.Add do
    begin
      Caption:=sBegin;
      SubItems.Add(SEnd);
    end;
  end;
end;

procedure TdlgGateCard.btnDeleteClick(Sender: TObject);
begin
  if lvPeriods.Selected<>nil then
    lvPeriods.Selected.Delete;
end;

procedure TdlgGateCard.lvPeriodsDblClick(Sender: TObject);
var
  sBegin, SEnd: String;
begin
  if lvPeriods.Selected<>nil then
  with lvPeriods.Selected do
  begin
    if not Assigned(dlgPeriods) then dlgPeriods:=TdlgPeriods.Create(Application);
    dlgPeriods.meBegin.Text:=Caption;
    dlgPeriods.meEnd.Text:=SubItems[0];
    if dlgPeriods.Execute(sbegin, send) then
    begin
      Caption:=sBegin;
      SubItems[0]:=SEnd;
    end;
  end;
end;

procedure TdlgGateCard.edEmpIdKeyPress(Sender: TObject; var Key: Char);
begin
  if not (key in [#8, '0'..'9']) then Key:=#0;
end;

procedure TdlgGateCard.cbPeriodsClick(Sender: TObject);
begin
  b880Style:=cbPeriods.Checked;
  plPeriods.Visible:=b880Style;
  plPwd.Visible:=not b880Style;
end;

end.

⌨️ 快捷键说明

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