unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, OleCtrls, SYNCARDOCXLib_TLB, StdCtrls, FileCtrl;
type
  TForm1 = class(TForm)
    ListBox1: TListBox;
    GroupBox2: TGroupBox;
    Button4: TButton;
    Button5: TButton;
    Button6: TButton;
    GroupBox3: TGroupBox;
    Button7: TButton;
    Button8: TButton;
    Button9: TButton;
    GroupBox4: TGroupBox;
    Button10: TButton;
    Button11: TButton;
    Button12: TButton;
    Button13: TButton;
    Button1: TButton;
    Button2: TButton;
    Button3: TButton;
    Button14: TButton;
    Button15: TButton;
    Button16: TButton;
    SynCardOcx1: TSynCardOCX;
    procedure Button16Click(Sender: TObject);
    procedure Button15Click(Sender: TObject);
    procedure Button1Click(Sender: TObject);
    procedure Button3Click(Sender: TObject);
    procedure Button4Click(Sender: TObject);
    procedure Button5Click(Sender: TObject);
    procedure Button6Click(Sender: TObject);
    procedure Button7Click(Sender: TObject);
    procedure Button8Click(Sender: TObject);
    procedure Button9Click(Sender: TObject);
    procedure Button10Click(Sender: TObject);
    procedure Button11Click(Sender: TObject);
    procedure Button12Click(Sender: TObject);
    procedure Button13Click(Sender: TObject);
    procedure Button14Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure SynCardOcx1CardIn(ASender: TObject; State: Integer);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.Button16Click(Sender: TObject);
begin
  Application.Terminate;
end;

procedure TForm1.Button15Click(Sender: TObject);
begin
  ListBox1.Items.Clear;
end;

procedure TForm1.Button1Click(Sender: TObject);
  var
  nPort:integer;
begin
  nPort := SynCardOcx1.FindReader();
  if nPort = 0 then begin
    ListBox1.Items.Add( DateTimeToStr(now())+ '  没有找到读卡器' );
    Button2.Enabled := False;
    Button3.Enabled := False;
    Button14.Enabled := False;
  end else begin
    Windows.Beep(4000,200);
    Button2.Enabled := True;
    Button3.Enabled := True;
    Button14.Enabled := True;
    if nPort>1000 then begin
      ListBox1.Items.Add( DateTimeToStr(Now())+'  读卡器连接在USB ' + IntToStr(nPort) + ' 上');
    end else begin
      ListBox1.Items.Add( DateTimeToStr(Now())+'  读卡器连接在COM ' + IntToStr(nPort) + ' 上');
    end;
  end;
end;

procedure TForm1.Button3Click(Sender: TObject);
var
  sSAMID:string;
begin
  sSAMID:=SynCardOcx1.GetSAMID();
  ListBox1.Items.Add(DateTimeToStr(Now())+'  SAM模块ID为:'+ sSAMID);
end;

procedure TForm1.Button4Click(Sender: TObject);
var
  nRet:Integer;
  sPath:string;
begin
  nRet := SynCardOcx1.SetPhotoPath(0,sPath);
  if nRet = 0 then begin
    ListBox1.Items.Add(DateTimeToStr(Now())+'  照片保存路径设置为C:,nRet = '+IntToStr(nRet) );
  end else begin
    ListBox1.Items.Add(DateTimeToStr(Now())+'  照片保存路径设置失败:,nRet = '+IntToStr(nRet) );
  end;
end;

procedure TForm1.Button5Click(Sender: TObject);
var
  nRet:Integer;
  sPath:string;
begin
  nRet := SynCardOcx1.SetPhotoPath(1,sPath);
  if nRet = 0 then begin
    ListBox1.Items.Add(DateTimeToStr(Now())+'  照片保存路径设置当前路径:,nRet = '+IntToStr(nRet) );
  end else begin
    ListBox1.Items.Add(DateTimeToStr(Now())+'  照片保存路径设置当前路径:,nRet = '+IntToStr(nRet) );
  end;
end;

procedure TForm1.Button6Click(Sender: TObject);
var
  nRet:Integer;
  sPath:string;
begin
  sPath:='C:\';
  SelectDirectory('选择路径：','',sPath);
  nRet := SynCardOcx1.SetPhotoPath(2,sPath);
  if nRet = 0 then begin
    ListBox1.Items.Add(DateTimeToStr(Now())+'  照片保存路径设置为:'+ sPath+' ,nRet = '+IntToStr(nRet) );
  end else begin
    ListBox1.Items.Add(DateTimeToStr(Now())+'  照片保存路径设置错误:,nRet = '+IntToStr(nRet) );
  end;
end;

procedure TForm1.Button7Click(Sender: TObject);
var
  nRet:Integer;
begin
  nRet := SynCardOcx1.SetPhotoType(0);
  if nRet = 0 then begin
    ListBox1.Items.Add(DateTimeToStr(Now())+'  照片保存格式为Bmp,nRet = ' + IntToStr(nRet));
  end else begin
    ListBox1.Items.Add(DateTimeToStr(Now())+'  照片保存格式设置失败,nRet = ' + IntToStr(nRet));
  end;
end;

procedure TForm1.Button8Click(Sender: TObject);
var
  nRet:Integer;
begin
  nRet := SynCardOcx1.SetPhotoType(1);
  if nRet = 0 then begin
    ListBox1.Items.Add(DateTimeToStr(Now())+'  照片保存格式为Jpeg,nRet = ' + IntToStr(nRet));
  end else begin
    ListBox1.Items.Add(DateTimeToStr(Now())+'  照片保存格式设置失败,nRet = ' + IntToStr(nRet));
  end;
end;

procedure TForm1.Button9Click(Sender: TObject);
var
  nRet:Integer;
begin
  nRet := SynCardOcx1.SetPhotoType(2);
  if nRet = 0 then begin
    ListBox1.Items.Add(DateTimeToStr(Now())+'  照片保存格式为Base64,nRet = ' + IntToStr(nRet));
  end else begin
    ListBox1.Items.Add(DateTimeToStr(Now())+'  照片保存格式设置失败,nRet = ' + IntToStr(nRet));
  end;
end;

procedure TForm1.Button10Click(Sender: TObject);
var
  nRet:Integer;
begin
  nRet := SynCardOcx1.SetPhotoName(0);
  if nRet = 0 then begin
    ListBox1.Items.Add(DateTimeToStr(Now())+'  照片保存文件名格式为tmp,nRet = ' + IntToStr(nRet));
  end else begin
    ListBox1.Items.Add(DateTimeToStr(Now())+'  照片保存文件名格式设置失败,nRet = ' + IntToStr(nRet));
  end;
end;

procedure TForm1.Button11Click(Sender: TObject);
var
  nRet:Integer;
begin
  nRet := SynCardOcx1.SetPhotoName(1);
  if nRet = 0 then begin
    ListBox1.Items.Add(DateTimeToStr(Now())+'  照片保存文件名格式为姓名,nRet = ' + IntToStr(nRet));
  end else begin
    ListBox1.Items.Add(DateTimeToStr(Now())+'  照片保存文件名格式设置失败,nRet = ' + IntToStr(nRet));
  end;
end;

procedure TForm1.Button12Click(Sender: TObject);
var
  nRet:Integer;
begin
  nRet := SynCardOcx1.SetPhotoName(2);
  if nRet = 0 then begin
    ListBox1.Items.Add(DateTimeToStr(Now())+'  照片保存文件名格式为身份证号,nRet = ' + IntToStr(nRet));
  end else begin
    ListBox1.Items.Add(DateTimeToStr(Now())+'  照片保存文件名格式设置失败,nRet = ' + IntToStr(nRet));
  end;
end;

procedure TForm1.Button13Click(Sender: TObject);
var
  nRet:Integer;
begin
  nRet := SynCardOcx1.SetPhotoName(3);
  if nRet = 0 then begin
    ListBox1.Items.Add(DateTimeToStr(Now())+'  照片保存文件名格式为姓名_身份证号,nRet = ' + IntToStr(nRet));
  end else begin
    ListBox1.Items.Add(DateTimeToStr(Now())+'  照片保存文件名格式设置失败,nRet = ' + IntToStr(nRet));
  end;
end;

procedure TForm1.Button14Click(Sender: TObject);
begin
  SynCardOcx1.SetLoopTime(1000);
  SynCardOcx1.SetReadType(1);
end;

procedure TForm1.Button2Click(Sender: TObject);
var
  nRet:Integer;
begin
  SynCardOcx1.SetReadType(0);
  nRet := SynCardOcx1.ReadCardMsg();
  if nRet = 0 then begin
    ListBox1.Items.Add(DateTimeToStr(Now())+'  读取身份证信息成功');
    ListBox1.Items.Add(DateTimeToStr(Now())+'  姓名：'+SynCardOcx1.NameA);
    ListBox1.Items.Add(DateTimeToStr(Now())+'  性别：'+SynCardOcx1.Sex);
    ListBox1.Items.Add(DateTimeToStr(Now())+'  民族：'+SynCardOcx1.Nation);
    ListBox1.Items.Add(DateTimeToStr(Now())+'  出生日期：'+SynCardOcx1.Born);
    ListBox1.Items.Add(DateTimeToStr(Now())+'  地址：'+SynCardOcx1.Address);
    ListBox1.Items.Add(DateTimeToStr(Now())+'  身份证号：'+SynCardOcx1.CardNo);
    ListBox1.Items.Add(DateTimeToStr(Now())+'  有效期开始：'+SynCardOcx1.UserLifeB);
    ListBox1.Items.Add(DateTimeToStr(Now())+'  有效期结束：'+SynCardOcx1.UserLifeE);
    ListBox1.Items.Add(DateTimeToStr(Now())+'  发证机关：'+SynCardOcx1.Police);
    ListBox1.Items.Add(DateTimeToStr(Now())+'  照片文件名：'+SynCardOcx1.PhotoName);
  end else begin
    ListBox1.Items.Add(DateTimeToStr(Now())+'  读取身份证信息错误');
  end;
end;

procedure TForm1.SynCardOcx1CardIn(ASender: TObject; State: Integer);
begin
  if State=1 then begin
    ListBox1.Items.Add(DateTimeToStr(Now())+'  读取身份证信息成功');
    ListBox1.Items.Add(DateTimeToStr(Now())+'  姓名：'+SynCardOcx1.NameA);
    ListBox1.Items.Add(DateTimeToStr(Now())+'  性别：'+SynCardOcx1.Sex);
    ListBox1.Items.Add(DateTimeToStr(Now())+'  民族：'+SynCardOcx1.Nation);
    ListBox1.Items.Add(DateTimeToStr(Now())+'  出生日期：'+SynCardOcx1.Born);
    ListBox1.Items.Add(DateTimeToStr(Now())+'  地址：'+SynCardOcx1.Address);
    ListBox1.Items.Add(DateTimeToStr(Now())+'  身份证号：'+SynCardOcx1.CardNo);
    ListBox1.Items.Add(DateTimeToStr(Now())+'  有效期开始：'+SynCardOcx1.UserLifeB);
    ListBox1.Items.Add(DateTimeToStr(Now())+'  有效期结束：'+SynCardOcx1.UserLifeE);
    ListBox1.Items.Add(DateTimeToStr(Now())+'  发证机关：'+SynCardOcx1.Police);
    ListBox1.Items.Add(DateTimeToStr(Now())+'  照片文件名：'+SynCardOcx1.PhotoName);
  end;

end;

end.
