📄 timeclock.pas
字号:
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;
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;
frmMain.ADOQuery1.Close;
frmMain.ADOQuery1.SQL.Text := 'insert into temp_kqjlu values ('''+format('%s',[Lines[Value].Card])+''',dbo.f_ConvertTime('''+format('%14.14s',[Lines[Value].TimeStr])+'''),'+inttostr(pclk.clock_id)+')';
frmMain.ADOQuery1.ExecSQL;
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:=3;
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
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,DataProgressProc, WaitProc);
//i:=ReadAllRecord(pclk.hPort, pclk,nil,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)
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;
if bRuning=False then
begin
msg.Caption := Format(SOAOGOAEAEUAESSAEAEDIoEyY, [pclk.Port, pclk.clock_id, Count-1]);
Break;
end;
nLine := ReadTextLine;
if nLine>0 then
begin
for i := 0 to nLine-1 do
SaveTextLine(i); //保存文本
if (nLine>1) or ((nLine=1)and((Count+ERCount) mod 10=0)) then
begin
dlgProgress.ProgressBar.Position:=Count+ERCount-1;
dlgProgress.msg.Caption := format(SONAEDIoCA, [Count+ERCount-1]);
dlgProgress.Update;
end;
if ErrorCount>0 then
case rgOnError.ItemIndex of
0:{出错继续}
begin
ErrorCount:=0;
end;
1:{出错重试}
begin
Windows.Beep(2500, 150);
dlgProgress.msg.Caption := Format(SSSUAEyYIIoOyOUOEOUDI, [pclk.Port, pclk.clock_id, ErrorCount]);
end;
2:{出错重试三次继续}
begin
Windows.Beep(2500, 150);
if (pclk.VerOrd<>2)and(ErrorCount<=3) then
dlgProgress.msg.Caption := Format(SSSUAEyYIIoOyOUOEOUDI, [pclk.Port, pclk.clock_id, ErrorCount])
else
ErrorCount:=0;
end;
end;
end
else if (nLine=-1) then //读数据发生错误
begin
Inc(ErrorCount);
Windows.Beep(2500, 150);
case rgOnError.ItemIndex of
0:{出错继续}
begin
ErrorCount:=0;
end;
1:{出错重试}
begin
dlgProgress.msg.Caption := Format(SSSUAEyYIIoOyOUOEOUDI, [pclk.Port, pclk.clock_id, ErrorCount])
end;
2:{出错重试三次继续}
begin
if ErrorCount<=3 then
dlgProgress.msg.Caption := Format(SSSUAEyYIIoOyOUOEOUDI, [pclk.Port, pclk.clock_id, ErrorCount])
else
begin
ErrorCount:=0;
msg.Caption:=msg_error_quit;
msg.Update;
UnCallClock(pclk.hPort);
Sleep(500);
// if not CallClock(pclk.hPort, pclk.clock_id) then
Break;
end;
end;
end;
end
else
begin
Windows.Beep(2500, 100);
if Count+ERCount>1 then
begin
S:=format(SOUSSEIAEAEDIoEyYAEOUIASSOG, [pclk.Port, pclk.clock_id, Count-1, ExtractFileName(FileName)]);
if ERCount>0 then
S:=S+format(msg_saved_error_record, [ERCount, ExtractFileName(ERRFile)]);
msg.Caption := S;
end else
msg.Caption := SEeISSEyY1;
//WriteLn(FLog, msg.Caption);
//WriteLn(FLog, Endl);
Break;
end;
until False;
end;
finally
dlgProgress.Animate.Active:=False;
end;
end;
end;
procedure WaitProc(p: Pointer; dwMilliseconds: Integer);
begin
with dlgProgress do
begin
msg2.Caption:=format('正在读取第一批数据,大约需 %d 秒.', [dwMilliseconds div 1000]);
Update;
end;
end;
function DataProgressProc(p: Pointer; lpReadData: PReadData): Boolean;stdcall;
var
pclk: PClockInfo;
procedure SaveTextLine(ReadData: TReadData);
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
sYear := Copy(ReadData.TimeString, 1, 4);
sMonth := Copy(ReadData.TimeString, 5, 2);
sDay := Copy(ReadData.TimeString, 7, 2);
sHour := Copy(ReadData.TimeString, 9, 2);
sMin := Copy(ReadData.TimeString, 11, 2);
sSec := Copy(ReadData.TimeString, 13, 2);
if sSec='' then sSec := '00';
Correct:=RecordCorrect;
Line:=Format('%.2x#9%s#9%s#9%.5d#9%.5d#9%d#9%d',
[pclk.clock_id,lpReadData.TimeString,lpReadData.CardNo,
lpReadData.Consume,lpReadData.Balance,lpReadData.Times,
lpReadData.flag]);
frmMain.ADOQuery1.Close;
frmMain.ADOQuery1.SQL.Text := 'insert into temp_kqjlu values ('''+format('%s',[lpReadData.CardNo])+''',dbo.f_ConvertTime('''+format('%14.14s',[lpReadData.TimeString])+'''),'+inttostr(pclk.clock_id)+')';
frmMain.ADOQuery1.ExecSQL;
end;
begin
Result:=False;
pclk:=p;
if Assigned(lpReadData)and Assigned(pclk) then
with PClockInfo(pclk)^ do
begin
dlgProgress.bCancel:=False;
Application.ProcessMessages;
dlgProgress.UpDate;
dlgProgress.ProgressBar.Min:=0;
dlgProgress.ProgressBar.Max:=lpReadData.Record_total;
dlgProgress.ProgressBar.Position:=lpReadData.Record_index;
dlgProgress.msg.Caption:=format(SOyOUAEUDDIoCA, [lpReadData.Record_index, lpReadData.Record_total]);
if not lpReadData.Verify_Error then
SaveTextLine(lpReadData^)
else
begin
if (MessageBox(frmMain.Handle,'记录校验错误, 是否保存? ', '错误', MB_YESNO or MB_ICONERROR)=IDYES) then
SaveTextLine(lpReadData^);
if (MessageBox(frmMain.Handle, '是否继续接收? ','错误', MB_YESNO or MB_ICONERROR)=IDYES) then
lpReadData.Verify_Error:=False;
end;
if lpReadData.Verify_Error or (dlgProgress.bCancel) then
begin
Result:=False;
lpReadData.Verify_Error:=True;
end else
Result:=True;
end;
end;
procedure TfrmMain.btnOpenClick(Sender: TObject);
begin
if not Assigned(dlgHints) then
dlgHints := TdlgHints.Create(dlgHints);
try
dlgHints.msg.Caption := '正在接收数据,请等候……';
dlgHints.Show;
dlgHints.Update;
if not Assigned(frmTempRecord) then
frmTempRecord := TfrmTempRecord.Create(frmTempRecord);
frmTempRecord.ShowModal;
finally
dlgHints.Close;
end;
end;
procedure TfrmMain.cbDeciveChange(Sender: TObject);
begin
cbDecive_show;
end;
procedure TfrmMain.cbDecive_show;
var i:integer;
begin
try
if not Assigned(dlgHints) then
dlgHints := TdlgHints.Create(Self);
dlgHints.msg.Caption := '正在读取名单数据,请稍候……';
dlgHints.Show;
dlgHints.Update;
btnDeviceAdd.Enabled := false;
btnWriteDeviceCardList.Enabled := false;
btnClearDeviceList.Enabled := false;
btnReadFile.Enabled := false;
btnDeviceDelete.Enabled := false;
btnFindCard.Enabled := false;
lvDeviceCards.Items.Clear;
lvDeviceCards.Refresh;
pclk := PClockInfo(cbDecive.Items.Objects[cbDecive.ItemIndex]);
if not (OpenPort(pclk)) then
begin
cbDecive.ItemIndex := -1;
MsgBox(Handle, '该机器不在线,再重新选择!', msg_confirm, MB_ICONQUESTION);
end
else
begin
frmMain.ADOQuery1.Close;
frmMain.ADOQuery1.SQL.Text := 'select * from t_kqmingdan where Card_Type='+inttostr(cbListKind.ItemIndex)+' and DeciveNo='+inttostr(pclk.Clock_id)+' and if_student='+inttostr(cbCardUser.ItemIndex)+' order by md_id';
frmMain.ADOQuery1.Open;
if pclk.hPort<>0 then
begin
edInspector.Caption := SAU;
btnDeviceAdd.Enabled := true;
btnWriteDeviceCardList.Enabled := true;
btnClearDeviceList.Enabled := true;
btnReadFile.Enabled := true;
if (frmMain.ADOQuery1.RecordCount > 0) then
begin
btnDeviceDelete.Enabled := true;
btnFindCard.Enabled := true;
lvDeviceCards.Items.BeginUpdate;
lvDeviceCards.Items.Clear;
lvDeviceCards.Refresh;
try
for i:= 0 to frmMain.ADOQuery1.RecordCount -1 do
begin
with lvDeviceCards.Items.Add do
begin
Caption := (ADOQuery1.FieldByName('md_id').AsString);
SubItems.Add(ADOQuery1.FieldByName('CardID').AsString);
SubItems.Add(ADOQuery1.FieldByName('xj_bhao').AsString);
SubItems.Add(ADOQuery1.FieldByName('xs_xming').AsString);
if ADOQuery1.FieldByName('if_insert').AsString = '0' then
SubItems.Add('否')
else
SubItems.Add('是');
case strtoint(ADOQuery1.FieldByName('if_reg').AsString) of
1:
SubItems.Add('开户');
2:
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -