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

📄 tread_readcard.pas

📁 pasa人力资源考勤管理系统
💻 PAS
字号:
unit tread_readcard;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls,ADODB,DB, ComCtrls, DBTables;

type
  readcard = class(TThread)
  private
    { Private declarations }
  protected
    procedure Execute; override;
    procedure paint;
  end;

implementation

uses datamol,main,readrecord;
{ Important: Methods and properties of objects in VCL can only be used in a
  method called using Synchronize, for example,

      Synchronize(UpdateCaption);

  and UpdateCaption could look like,

    procedure readcard.UpdateCaption;
    begin
      Form1.Caption := 'Updated in a thread';
    end; }

{ readcard }

procedure readcard.Execute;
var
  i,j:integer;
begin
with Datamod do
begin
with formreadrecord do
begin
  Animate1.Active:=True;
  pbar1.visible:=true;
  label1.visible:=true;
  speedbutton1.enabled:=false;
  speedbutton2.enabled:=false;
  try
  log:=ExtractFilePath(Application.ExeName)+'log\readcarderr.log';
  p:=extractfilepath(application.exename)+'log\readcard.log';
  assignfile(f,p);
  append(f);
  if not fileexists(log) then
  begin
     i:=filecreate(log);
     if handle>0 then
        Fileclose(Handle);
  end;
  assignfile(logfile,log);
  append(logfile);
  append(f);
  query1.close;
  query1.sql.clear;
  query1.sql.add('if exists (select * from dbo.sysobjects where id = object_id(N''[dbo].[tt]'') and OBJECTPROPERTY(id, N''IsUserTable'') = 1) drop table [dbo].[tt]');
  query1.sql.add('create table tt ( t1 varchar(30))');
  query1.execsql;
  PBar1.Max:=listbox1.items.count;
  PBar1.Position:=0;
  PBar1.Step:=1;
  adoclock.Close;
  adoclock.CommandText:='select * from atd09010 where yndefault=''1'' ';
  adoclock.Open;
  if adoclock.Eof then
  begin
     Application.messagebox('你还没有设定卡钟类别,请进入[参数设定]-->[考勤基本设定]中的[卡钟参数设定]进行设定.','Warning',mb_ok+mb_iconwarning);
     close;
     exit;
  end;
  for j:=listbox1.items.count-1 downto 0 do
  begin  //for listbox
   if FileExists(listbox1.items[j]) then
   begin//文件存在
    try
        label1.Caption:='正在读取原始资料文件.....';
        label1.update;
        writeln(f,'---------------------------------------------------------');
        writeln(f,'开始读取文件'+listbox1.items[j]+'中的打卡数据:'+formatdatetime('yyyy/mm/dd hh:mm:ss',now));
        query1.close;
        query1.sql.clear;
        query1.sql.add('BULK INSERT tt FROM '''+listbox1.items[j]+''' WITH ( DATAFILETYPE = ''char'', FIELDTERMINATOR = '''', ROWTERMINATOR = ''\n'' ) ');
        query1.sql.add('insert into atd15010 (macname, cardno, recdate, rectime, state, recdatetime, readok) select substring(t1,'+inttostr(adoclockmacb.asinteger)+','+inttostr(adoclockmace.asinteger)+') macname, '+
                       'substring(t1,'+inttostr(adoclockcardb.asinteger)+','+inttostr(adoclockcarde.asinteger)+') cardno, substring(t1,'+inttostr(adoclockyearb.asinteger)+','+inttostr(adoclockyeare.asinteger)+')+''/''+substring(t1,'+inttostr(adoclockmonthb.asinteger)+',2)+''/''+'+
                       'substring(t1,'+inttostr(adoclockdayb.asinteger)+',2) recdate,substring(t1,'+inttostr(adoclocktimeb.asinteger)+',2)+'':''+substring(t1,'+inttostr(adoclocktimee.asinteger)+',2) rectime,substring(t1,'+inttostr(adoclockstateb.asinteger)+','+inttostr(adoclockstatee.asinteger)+') state, '+
                       'substring(t1,'+inttostr(adoclockyearb.asinteger)+','+inttostr(adoclockyeare.asinteger)+')+''/''+substring(t1,'+inttostr(adoclockmonthb.asinteger)+',2)+''/''+substring(t1,'+inttostr(adoclockdayb.asinteger)+',2)+'' ''+'+
                       'substring(t1,'+inttostr(adoclocktimeb.asinteger)+',2)+'':''+substring(t1,'+inttostr(adoclocktimee.asinteger)+',2) recdatetime,0 from tt where len(t1)='+inttostr(adoclocktextlength.asinteger)+' ');
        query1.sql.savetofile('c:\xx.sql');
        query1.execsql;
        //删除重复记录
        label1.Caption:='正在整理刷卡记录...';
        label1.Update;
        writeln(f,'从文件'+listbox1.items[j]+'中共读取了'+inttostr(pbar1.max)+'笔刷卡数据!');
        writeln(f,'结束读取文件'+listbox1.items[j]+'中的打卡数据:'+formatdatetime('yyyy/mm/dd hh:mm:ss',now));
        writeln(f,'---------------------------------------------------------');
    except
      writeln(f,pchar('读取文件'+listbox1.items[j])+'时出错'+formatdatetime('yyyy/mm/dd',now)+' ');
    end;
   end else  //if fileexist
   Application.MessageBox(pchar('文件'+listbox1.items[j]+'不存在,请重新选择!'),'文件不存在',mb_iconstop+mb_ok);
   listbox1.Items.Delete(j);
   listbox1.update;
   pbar1.stepit;
  end;  //for listbox
  finally
     Animate1.Active:=False;
     pbar1.visible:=false;
     label1.visible:=false;
     speedbutton1.enabled:=true;
     speedbutton2.enabled:=false;
     closefile(f);
     closefile(logfile);
     query1.close;
     query1.sql.text:='Drop table tt';
     query1.execsql;
     terminate;
  end;
end;   //with formreadrecdord
end;   //with datamod
end;

procedure readcard.paint;
begin
   //formmain.update;
end;

end.

⌨️ 快捷键说明

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