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

📄 main.~pas

📁 一个Delphi写的跟考勤机门禁机收款机的接品软件源码
💻 ~PAS
📖 第 1 页 / 共 5 页
字号:
        msg.Caption := format(SISSOEUCOMD, [pclk.Port]);
      end
      else
      begin
        edInspector.Caption := SINU;
        msg.Caption := format(SISSAOEeSS, [pclk.Port, pclk.clock_id]);
      end;
    end
    else{ if CheckConnectClock(hPort, pclk.clock_id) then}
    begin
      msg.Caption := SAOOK;
      Result := True;
    end{
    else
    begin
      try
        CloseHandle(hPort);
      except
      end;
      hPort := 0;
      pclk.hPort := 0;
      Result := 0;
      edInspector.Caption := SINU;
    end};
    pclk.Connected := CheckHandle(pclk.hPort);
    i := clbDevs.Items.IndexOfObject(TObject(pclk));
    if i<>-1 then
    begin
      if Result then
      begin
        if pclk.Model=0 then
          clbDevs.Items[i] := format(SSCOMDISSEGUGI, [pclk.Port, pclk.clock_id])
        else
          clbDevs.Items[i] := format('COM%d-%.2x(%d%s %1.2n)', [pclk.Port, pclk.clock_id, pclk.Model, arICID[pclk.cls], pclk.Fireware]);
      end
      else
        clbDevs.Items[i] := format(SSCOMDISSIN, [pclk.Port, pclk.clock_id])
    end;
    if Result then
    begin
      if (pclk.model=680) then
      begin
        btnMoneySum.Caption := SIuNUGIU;
        btnMoneySum.Tag := 0;
      end else
      begin
        btnMoneySum.Caption := SIGAEUAEB;
        btnMoneySum.Tag := 1;
      end;
      btnRead.Enabled:=GetClockSupports(pclk.hPort, fiStoreRecord);
      btnClearData.Enabled:=btnRead.Enabled;
      btnSetTime.Enabled:=GetClockSupports(pclk.hPort, fiClockTime);
  //    btnGetTime.Enabled:=btnSetTime.Enabled;
      if not btnRead.Enabled then
      begin
        btnSetAdmin.Enabled:=GetClockSupports(pclk.hPort, fiAdminCard);
        btnSetMark.Enabled:=GetClockSupports(pclk.hPort, fiHaveMark);
        btnRealCollect.Enabled:=GetClockSupports(pclk.hPort, fiRealTime);
        btnSetClockId.Enabled:=GetClockSupports(pclk.hPort, fiChangeClockId);
      end else
      begin
        btnSetAdmin.Enabled:=True;
        btnSetMark.Enabled:=True;
        btnSetClockId.Enabled:=True;
        btnRealCollect.Enabled:=True;
      end;
      btnSetPwd.Enabled:=GetClockSupports(pclk.hPort, fiICReader);
      R:=GetClockSupports(pclk.hPort, fiConsumption);
      tsConsumption.TabVisible:=R;
      tsPeriods.TabVisible:=pclk.VerOrd>2;
      tsPriceList.TabVisible:=GetClockSupports(pclk.hPort, fiPriceList);
    end;
  finally
    Screen.Cursor := SaveCursor;
    msg.Update;
  end;
end;

procedure TfrmMain.ReadData(pclk: PClockInfo; bFast: Boolean; MultiClock: Boolean);
type
  TLine=record
    Card: string;
    EmpId: string;
    TimeStr: string;
    mark: char;
    Flag: Integer;
    CardTimes: Integer;
    consume: Integer;
    balance: Integer;
  end;
var
  i, nLine,
    Count, ERCount, ErrorCount: Integer; //正确数据总数, 错误数据总数, 重试次数
  Right: Boolean;
  Mark: Char;
  ERRFile: string;
  Lines: array[0..20] of TLine;//新门禁机允许一次读400条记录

  procedure CreateAndOpenFiles;
  begin
    FileName := GetStoredFileName(pclk);
{$I-}
    AssignFile(F, FileName);
    FileMode := 2;
    Reset(F);
    if IOResult=0 then
      Append(F)
    else
      ReWrite(F);
{$I+}
    if IOResult<>0 then
    begin
      MsgBox(Screen.ActiveForm.Handle, pchar(format(SOOIASSEU, [FileName])), pchar(SIaE), MB_OK+MB_ICONERROR);
      Exit;
    end;
    {接收日志}

{$I-}
    AssignFile(FLog, LogFile);
    FileMode := 1;
    Reset(FLog);
    if IOResult=0 then
      Append(FLog)
    else
      ReWrite(FLog);
    {接收日志}
{$I+}
    if IOResult<>0 then
    begin
      MsgBox(Screen.ActiveForm.Handle, pchar(format(SOOEOOIASSEU, [LogFile])), pchar(SIaE), MB_OK+MB_ICONERROR);
      Exit;
    end;
{$I-}
    ERRFile := IncludeTrailingBackslash(Dir)+'ERR'+FormatDateTime('yyyyMMdd', Date)+'.txt';
    AssignFile(F2, ERRFile);
    Append(F2);
{$I+}
    if IOResult<>0 then
      Rewrite(F2);

    WriteLn(Flog, '----------------------  TimeClock Ver. 1.1  -----------------------');
    WriteLn(FLog, ShortDayNames[DayOfWeek(Date)]+'  '+FormatDateTime(LongDateFormat+' '+LongTimeFormat, Now));
  end;

  function ReadTextLine: Integer;
  var
    i, Flag, CardTimes, CardGroup: Integer;
    CardBuf, TimeBuf: array[0..50] of char;
    Buf: array[0..$10] of TICRecord;
  begin
    Result := 0;
    if ((pclk.VerOrd>2) or
        ((ClockVerOrd(pclk.Model)=2) and (pclk.Fireware>=FW128))) then //是否支持快速读数据
    begin
      Flag := 0;
      FillChar(Buf, SizeOf(Buf), 0);
      Result := BatchReadRecord(pclk.hPort, Buf);
      if Result>=0 then
      begin
        Right := True;
        for i := 0 to Result-1 do
        begin
          SetString(Lines[i].Card, PChar(@Buf[i].Card), StrLen(@Buf[i].Card));
          SetString(Lines[i].TimeStr, PChar(@buf[i].TimeString), StrLen(@Buf[i].TimeString));
          SetString(Lines[i].EmpId, PChar(@Buf[i].EmpId), StrLen(@Buf[i].EmpId));
          if (pclk.Fireware>FW128)or(Chr(lo(Buf[i].mark))in [#20..#255]) then
            Lines[i].Mark := chr(lo(Buf[i].mark))
          else
            Lines[i].Mark := Mark; //chr(lo(Buf[i].mark));//批读卡没有Mark
          Lines[i].Flag := Buf[i].flag;
          Lines[i].CardTimes := Buf[i].cardTimes;
          Lines[i].consume := Buf[i].consume;
          Lines[i].balance := buf[i].balance;
        end;
      end;
    end
    else //普通读数据
    begin
      Flag := 0;
      if ((ClockVerOrd(pclk.Model)=2) and(pclk.Fireware>=FW125)) or
         (pclk.VerOrd>2) then
        Right := ReadStandardRecord(pclk.hPort, CardBuf, TimeBuf, Mark, Flag, CardTimes, CardGroup)//880专用
      else
        Right := ReadRecord(pclk.hPort, CardBuf, TimeBuf, Mark, (Count=1)or(ErrorCount>0)); //读第一条记录
      if (Right)and(StrPos(CardBuf, 'OVER')=nil) then
      begin
        Result := 1;
        Lines[0].Card := PChar(@CardBuf);
        Lines[0].TimeStr := PChar(@TimeBuf);
        Lines[0].EmpId := '';
        Lines[0].mark := Mark;
        Lines[0].Flag := Flag;
        Lines[0].CardTimes := CardTimes;
        Lines[0].consume := 0;
        Lines[0].balance := 0;
      end;
    end;
    if not Right then
      Result := -1;
  end;

  procedure SaveTextLine(Value: Integer);
  var
    Line, sYear, sMonth, sDay, sHour, sMin, sSec, sWeek: string;
    sign_time: TDateTime;
    Correct: Boolean;
    
    function RecordCorrect: Boolean;
    var
      year, month, day, hour, min, sec: WORD;
    begin
      try
        year := StrToInt(sYear);
        month := StrToInt(sMonth);
        day := StrToInt(sDay);
        hour := StrToInt(sHour);
        min := StrToInt(sMin);
        sec := StrToIntDef(sSec, 0);
        sign_time:=Encodedate(year, month, day)+Encodetime(hour, min, sec, 0);
        sweek:=IntToStr(DayOfWeek(sign_time)-1);
        Result := True;
      except
        on EConvertError do
          Result := False;
      end;
    end;
  begin
    if pclk.VerOrd>1 then
    begin
      if (not (pclk.CardLen in [0, 16])) then//卡号自动补零
      begin
        if Length(Lines[Value].Card)>pclk.CardLen then
          Lines[Value].Card := Copy(Lines[Value].Card, Length(Lines[Value].Card)-pclk.CardLen+1, pclk.CardLen)
        else if (Length(Lines[Value].Card)<pclk.CardLen)and(StrToIntDef(Lines[Value].Card, -1)>=0) then
        begin
          Lines[Value].Card:=format('%.*u', [pclk.CardLen, StrToIntDef(Lines[Value].Card, 0)]);
        end;
      end;
    end;
    sYear := Copy(Lines[Value].TimeStr, 1, 4);
    sMonth := Copy(Lines[Value].TimeStr, 5, 2);
    sDay := Copy(Lines[Value].TimeStr, 7, 2);
    sHour := Copy(Lines[Value].TimeStr, 9, 2);
    sMin := Copy(Lines[Value].TimeStr, 11, 2);
    sSec := Copy(Lines[Value].TimeStr, 13, 2);
    if sSec='' then sSec := '00';
    Correct:=RecordCorrect;
    if cbUseFMT.Checked then
    begin
      Line := edFMTStr.Text;
      Line := StringReplace(Line, FDevice, IntToHex(pclk.clock_id, 2), [rfIgnoreCase, rfReplaceAll]);
      Line := StringReplace(Line, FCard, Lines[Value].Card, [rfIgnoreCase, rfReplaceAll]);
      Line := StringReplace(Line, Ftab, #9, [rfIgnoreCase, rfReplaceAll]); //表格符
      Line := StringReplace(Line, FYear, sYear, [rfIgnoreCase, rfReplaceAll]); //四位数年份
      Line := StringReplace(Line, FYear2, Copy(sYear, 3, 2), [rfIgnoreCase, rfReplaceAll]); //两位数年份
      Line := StringReplace(Line, Fmonth, sMonth, [rfIgnoreCase, rfReplaceAll]);
      Line := StringReplace(Line, FDay, sDay, [rfIgnoreCase, rfReplaceAll]);
      Line := StringReplace(Line, FHour, sHour, [rfIgnoreCase, rfReplaceAll]);
      Line := StringReplace(Line, FMin, sMin, [rfIgnoreCase, rfReplaceAll]);
      Line := StringReplace(Line, FSec, sSec, [rfIgnoreCase, rfReplaceAll]);
      if not (Lines[Value].mark in [#$20..#$7F]) then Lines[Value].mark:=#32;
      Line := StringReplace(Line, FMark, Lines[Value].Mark, [rfIgnoreCase, rfReplaceAll]);
      Line := StringReplace(Line, FFlag, format('%.1u', [Lines[Value].Flag and $0F]), [rfIgnoreCase, rfReplaceAll]);
      Line := StringReplace(Line, FEmpId, Lines[Value].EmpId, [rfIgnoreCase, rfReplaceAll]);
      Line := StringReplace(Line, FWeek, SWeek, [rfIgnoreCase, rfReplaceAll]);
      Line := StringReplace(Line, FDoor, '', [rfIgnoreCase, rfReplaceAll]);
      Line := StringReplace(Line, FTimes, format('%.3u', [Lines[Value] .CardTimes]), [rfIgnoreCase, rfReplaceAll]);
      Line := StringReplace(Line, FBalance, format('%.5u', [Lines[Value].balance]), [rfIgnoreCase, rfReplaceAll]);
      Line := StringReplace(Line, FConsume, format('%.5u', [Lines[Value].consume]), [rfIgnoreCase, rfReplaceAll]);
    end
    else
    begin
      Line := format('%s'#9'%14.14s'#9'%.2x'#9'%1.1s'#9'%1.1u', [Lines[Value].Card, Lines[Value].TimeStr, pclk.clock_id, Lines[Value].Mark, Lines[Value].Flag and $0F]);
      if Lines[Value].consume<>0 then
      begin
        Line:=Line+format(#9'%.3u'#9'%.5u'#9'%.5u', [Lines[Value].CardTimes, Lines[Value].balance, Lines[Value].consume]);
      end;
    end;
    if Correct then
    begin
      inc(Count);
      WriteLn(F, Line);
    end else
    begin
      Inc(ErrorCount);
      Inc(ERCount);
      WriteLn(F2, Line);
    end;
  end;

var
  nSize: Cardinal;
  hHandle: THandle;
  S: string;
  CurTime:Double;
begin
  ErrorCount := 0;
  begin
    if (pclk.CardLen=0) or (pclk.DispCardLen=0) then
    begin
      ReadCardLength(pclk.hPort, pclk.dispCardLen, pclk.CardLen);
    end;
    if (not bFast)and(pclk.VerOrd>1)and (pclk.cls>0) and(pclk.Fireware<FW128)and(pclk.CardLen<16) then
      if (pclk.CardLen<>5) then
      begin
        if MsgBox(Screen.ActiveForm.Handle, PChar(SAICEeOUOEOEyYCGeEyYAEEeIECNEeOA), msg_infor, MB_YESNO or MB_ICONWARNING)=IDYES then
          SetCardLength(pclk.hPort, 16, 16)
        else
        begin
          Exit;
        end;
      end;
    ReadClockMark(pclk.hPort, pclk.Mark);
    if pclk.Mark in [#20..#255] then
      Mark := pclk.Mark
    else
      Mark := '0';
    Self.Update;
    dlgProgress.msg.Caption:=SOyOUAEoOEOIGoCeEO;
    dlgProgress.ProgressBar.Position:=0;
    dlgProgress.Animate.Active:=True;
    if (pclk.VerOrd>1) and ReadClockRecordTotal(pclk.hPort, i) then
    begin
      dlgProgress.ProgressBar.Max:=i;
      dlgProgress.msg2.Caption:=format(SIECAUEyIDIo, [i]);
    end else
    begin
      dlgProgress.ProgressBar.Max:=100;
      dlgProgress.msg2.Caption:='';
    end;
    dlgProgress.Show;
    dlgProgress.Update;
    dlgProgress.bCanClose:=True;
    try
      CreateAndOpenFiles;
      if bFast and (pclk.VerOrd>2) then
      begin
        ERAsyncSelect(pclk.hPort, Handle, WM_READALLDATA, FED_NOTIFY);
        try
          dlgProgress.bCanClose:=False;
          i:=ReadAllRecord(pclk.hPort, pclk, nil, nil);
//          i:=ReadAllRecordAsFile(pclk.hPort, pclk.clock_id, 'E:\Data.txt', Self.Handle, True, nil);
        finally
          dlgProgress.bCanClose:=True;
          ERAsyncSelect(pclk.hPort, Handle, 0, FED_NOTIFY);
        end;
        if (i=0) then
        begin
          if (not MultiClock) then MsgBox(Screen.ActiveForm.Handle, PChar(SEeISSEyY), msg_information, MB_ICONINFORMATION)
        end else if (i>0) then
        begin
          if cbAutoClearClock.Checked then
            ClearAllReadCard(pclk.hPort)
          else if (MultiClock)  then
            ClearAllReadCard(pclk.hPort)
          else
          begin
            if (MsgBox(Screen.ActiveForm.Handle, PChar(format(SAEeEADIoEyYONOyAEECNOEeCaY, [i])), msg_information, MB_YESNO or MB_ICONQUESTION or MB_DEFBUTTON1)=IDYES) then
              ClearAllReadCard(pclk.hPort)
            else
              ReadClockTime(pclk.hPort,  CurTime);
          end;
        end else if (i=-1)or(i=-2) then
          MsgBox(Screen.ActiveForm.Handle, PChar(SIGAIIo), msg_error, MB_ICONERROR)
        else if i=-3 then
          MsgBox(Screen.ActiveForm.Handle, PChar(SIGAGNeIIo), msg_error, MB_ICONERROR)
        else if i=-4 then
          MsgBox(Screen.ActiveForm.Handle, PChar(SOEOYIOGO), msg_error, MB_ICONERROR)
        else if i=-5 then//不支持的命令
          bFast:=False//改为小批量读取
        else
          MsgBox(Screen.ActiveForm.Handle, PChar(SIOIIo), msg_error, MB_ICONERROR);
      end else
      begin
        bFast:=False;
      end;
      if not bFast then//小批量读取数据
      begin
        Count := 1;
        ERCount := 0;
        dlgProgress.msg.Caption := Format(SOyOUAESSEyY, [pclk.Port, pclk.clock_id]);
        dlgProgress.msg.Update;
        repeat
          Application.ProcessMessages;

⌨️ 快捷键说明

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