📄 gatherrecthread.pas
字号:
end;
end else begin
if Node > 2 then
begin
showstr :='设备号:' + inttostr(devid) + '握手失败!请管理员查看线路或设备是否出现故障!';
synchronize(show);
result := false;
exit;
end;
end;
end;
end;
end;
function TGatherRecThread.CheckBrushTime(s: string): boolean;
var
i: Integer;
begin
result := false;
for i := 1 to length(s) do
begin
if s[i] in ['0'..'9'] then
result := true
else
begin
result := false;
exit;
end;
end;
end;
procedure TGatherRecThread.AddRec(sCardNo, dOpDate, sReaderId: string);
var
fn: string;
ADOQuery1: TADOQuery;
begin
fn := getCurrentDayFileName();
if not FileExists(fn) then
begin
if not CreateDB(fn) then exit;
end;
ADOQuery1 := TADOQuery.Create(Nil);
try
with ADOQuery1 do
begin
ConnectionString := 'DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=' + fn + '; Mode=ReadWrite' + '; Persist Security Info=False';
SQL.Clear;
SQL.Add('select * from infolog where cardno = ''' + sCardNo + ''' and opdate between' + ' #' + FormatDateTime('yyyy-mm-dd hh::mm::ss', StrToDateTime(dOpDate) - ReBrushTime/(60*24)) + '# and #' + FormatDateTime('yyyy-mm-dd hh::MM::SS', StrToDateTime(dOpDate)) + '#');
Open;
if RecordCount = 0 then
begin
SQL.Clear;
SQL.Text := 'insert into infolog (cardno, readerid, opdate, activestate, recadddate) values (''' + sCardNo + ''', ''' + sReaderId + ''', ''' + dOpDate + ''', ''' + '1' + ''',''' + DateTimeToStr(Now) + '''' + ')';
ExecSQL;
end;
end;
finally
FreeAndNil(ADOQuery1);
end;
end;
function TGatherRecThread.CreateDB(fn: string): BOOLEAN;
var
CreateAccess: OLEVariant;
ADOQuery1: TADOQuery;
begin
CreateAccess := CreateOLEObject('ADOX.Catalog');
CreateAccess.Create('Provider=Microsoft.Jet.OLEDB.4.0;Data Source=' + fn + '; Mode=ReadWrite');
ADOQuery1 := TADOQuery.Create(Nil);
try
with ADOQuery1 do
begin
ConnectionString := 'DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=' + fn + '; Mode=ReadWrite' + '; Persist Security Info=False'; //设置数据源
SQL.Text := 'CREATE TABLE [infolog] ([ID] Counter CONSTRAINT [ID] PRIMARY KEY,[cardno] CHAR(10) NOT NULL, [readerid] CHAR(12) NOT NULL, [opdate] DATETIME NULL, [activestate] CHAR(2) NOT NULL, [uploaddate] DATETIME NULL, [recadddate] DATETIME NULL)';
// SQL.Text := 'CREATE TABLE [infolog] ([cardno] CHAR(10) NOT NULL, [readerid] CHAR(12) NOT NULL, [opdate] DATETIME NOT NULL, [activestate] CHAR(2) NOT NULL, [uploaddate] DATETIME NULL)';
try
begin
ExecSQL;
result := true;
end;
except
on EOleException do
begin
result := False;
Abort;
end;
end;
end;
finally
FreeAndNil(ADOQuery1);
end;
end;
function TGatherRecThread.getalgorism(hexString: String): String;
var
Cardno,BrushTime,StrTime,NumStr: string;
begin
NumStr := '9000000000';
Cardno := IntToStr(StrToInt('$' + Copy(Record_Data, 1, 2)
+ Copy(Record_Data, 5, 2) + Copy(Record_Data, 3, 2)));
BrushTime := '20' + Copy(Record_Data, 7, 2) + '-' + Copy(Record_Data, 9, 2)
+ '-' + Copy(Record_Data, 11, 2) + ' ' + Copy(Record_Data, 13, 2)
+ ':' + Copy(Record_Data, 15, 2) + ':' + Copy(Record_Data, 17, 2);
StrTime := '20' + Copy(Record_Data, 7, 2) + Copy(Record_Data, 9, 2)
+ Copy(Record_Data, 11, 2) + Copy(Record_Data, 13, 2)
+ Copy(Record_Data, 15, 2) + Copy(Record_Data, 17, 2);
Cardno := Copy(NumStr,1,10 - Length(Cardno)) + Cardno;
result := Cardno + BrushTime + StrTime;
end;
function TGatherRecThread.getCurrentDayFileName: string;
var
FileNamePath: string;
begin
FileNamePath := ExtractFilePath(Paramstr(0));
CreateDirectory(PChar((FileNamePath) + 'Log'), nil);
FileNamePath := FileNamePath + 'Log\' + FormatDateTime('yyyy', Now) + IntToStr(WeekOf(Now)) + '.out';
result := FileNamePath;
end;
function TGatherRecThread.Checkday: Integer;
begin
if Dayofweek(Now) = 1 then
result := 7
else
result := Dayofweek(Now) - 1;
end;
function TGatherRecThread.getnewreadid(readid: string; bushdatetime: TDateTime): string;
var
i,idplace,nicetyplace: integer;
sendstate,bushtime,inoutstr: string;
inouttime,checkdayofweek: TStrings;
iscontext: boolean;
begin
iscontext := false;
idplace := StrToInt(Copy(readid, 2, 1)); //A or B
nicetyplace := StrToInt(LeftStr(readid, 1));
bushtime := FormatDateTime('HH:MM', bushdatetime);
inouttime := TStringlist.Create;
checkdayofweek := TStringlist.Create;
try
begin
checkdayofweek.CommaText := inifile.ReadString('check2', 'value', '');
for i := 0 to checkdayofweek.Count - 1 do
begin
if Checkday = StrToInt(checkdayofweek[i]) then
begin
iscontext := true;
break;
end else
iscontext := false;
end;
if iscontext then
begin
case Checkday of
1: inoutstr := Inifile.ReadString('one', 'value', ''); //星期一
2: inoutstr := Inifile.ReadString('two', 'value', ''); //星期二
3: inoutstr := Inifile.ReadString('three', 'value', ''); //星期三
4: inoutstr := Inifile.ReadString('four', 'value', ''); //星期四
5: inoutstr := Inifile.ReadString('five', 'value', ''); //星期五
6: inoutstr := Inifile.ReadString('six', 'value', ''); //星期六
7: inoutstr := Inifile.ReadString('seven', 'value', ''); //星期日
end;
inouttime.CommaText := inoutstr;
case idplace of
1: begin //A
BoolAdd := True;
case nicetyplace of
3: begin //Aty
for i := 0 to (inouttime.Count - 1) div 2 do
begin
if (StrToTime(bushtime) >= StrToTime(inouttime[2*i])) and (StrToTime(bushtime) <= StrToTime(inouttime[2*i+1])) then
begin
sendstate := '1';
readid[2] := IntToStr(i + 1)[1];
case i of
0,2,4: readid[1] := '1'; //in
else begin
readid[1] := '2'; //out
end;
end;
break;
end else begin
sendstate := '8';
readid[2] := '7';
end;
end;
end;
else begin
for i := 0 to (inouttime.Count - 1) div 2 do
begin
if (StrToTime(bushtime) >= StrToTime(inouttime[2*i])) and (StrToTime(bushtime) <= StrToTime(inouttime[2*i+1])) then
begin
case i of
0,2,4: begin
if nicetyplace = 1 then
begin
sendstate := '1';
readid[2] := IntToStr(i + 1)[1]; //in
end else begin
sendstate := '8';
readid[2] := '7'; //in except
readid[1] := '2';
end;
end else begin
if nicetyplace = 2 then
begin
sendstate := '1';
readid[2] := IntToStr(i + 1)[1]; //in //out
end else begin
sendstate := '8';
readid[2] := IntToStr(i + 1)[1]; //in except
readid[1] := '1';
end;
end;
end;
break;
end else begin
sendstate := '8';
readid[2] := '7';
end;
end;
end;
end;
end;
2: begin //B
case nicetyplace of
3: begin //Bty
for i := 0 to (inouttime.Count - 1) div 2 do
begin
if (StrToTime(bushtime) >= StrToTime(inouttime[2*i])) and (StrToTime(bushtime) <= StrToTime(inouttime[2*i+1])) then
begin
BoolAdd := True;
sendstate := '1';
readid[2] := IntToStr(i + 1)[1];
case i of
0,2,4: readid[1] := '1'; //Bin
else
readid[1] := '2'; //Bout
end;
break;
end else
BoolAdd := False;
end;
end;
else begin
for i := 0 to (inouttime.Count - 1) div 2 do
begin
if (StrToTime(bushtime) >= StrToTime(inouttime[2*i])) and (StrToTime(bushtime) <= StrToTime(inouttime[2*i+1])) then
begin
BoolAdd := True;
sendstate := '1';
case i of
0,2,4: begin
if nicetyplace = 1 then
readid[2] := IntToStr(i + 1)[1] //in
else Begin
readid[2] := '7'; //in except
readid[1] := '2';
end;
end else begin
if nicetyplace = 2 then
readid[2] := IntToStr(i + 1)[1] //out
else begin
readid[2] := '7'; //in except
readid[1] := '1';
end;
end;
end;
break;
end else
BoolAdd := False;
end;
end;
end;
end;
3: begin //Ash
BoolAdd := True;
sendstate := '1';
if nicetyplace = 1 then
begin
readid[2] := '8'; //in except
readid[1] := '4';
end else begin
readid[2] := '9'; //out except
readid[1] := '5';
end;
end;
end;
if BoolAdd then
begin
result := LeftStr(readid, 1) + sendstate + RightStr(readid, 10);
end;
end else begin
BoolAdd := true;
result := LeftStr(readid, 1) + '17' + RightStr(readid, 9);
end;
end;
finally
freeandnil(inouttime);
freeandnil(checkdayofweek);
end;
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -