//---------------------------------------------------------------------------

#include <vcl.h>
#pragma hdrstop

#include "Unit1.h"
#include <stdio.h>
#include <FileCtrl.hpp>
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma link "SYNCARDOCXLib_OCX"
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
        : TForm(Owner)
{
}
//---------------------------------------------------------------------------

void __fastcall TForm1::Button16Click(TObject *Sender)
{
        Application->Terminate();        
}
//---------------------------------------------------------------------------

void __fastcall TForm1::Button15Click(TObject *Sender)
{
        ListBox1->Items->Clear();        
}
//---------------------------------------------------------------------------

void __fastcall TForm1::Button4Click(TObject *Sender)
{
        char sMsg[1024];
        WideString cPath="";
        int nRet;
        nRet = SynCardOcx1->SetPhotoPath(0,cPath) ;
        if(nRet == 0)
        {
                sprintf(sMsg,"%s  照片保存路径设置为C:,nRet = %d",Now().DateTimeString(),nRet);
        }
        else
        {
                sprintf(sMsg,"%s  设置照片保存路径失败,nRet = %d",Now().DateTimeString(),nRet);
        }
        ListBox1->Items->Add(sMsg);
}
//---------------------------------------------------------------------------

void __fastcall TForm1::Button5Click(TObject *Sender)
{
        char sMsg[1024];
        WideString cPath="";
        int nRet;
        nRet = SynCardOcx1->SetPhotoPath(1,cPath) ;
        if(nRet == 0)
        {
                sprintf(sMsg,"%s  照片保存路径设置当前路径:,nRet = %d",Now().DateTimeString(),nRet);
        }
        else
        {
                sprintf(sMsg,"%s  设置照片保存路径失败,nRet = %d",Now().DateTimeString(),nRet);
        }
        ListBox1->Items->Add(sMsg);
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button6Click(TObject *Sender)
{
        char sMsg[1024];
        AnsiString Path="C:\\";
        WideString cPath="";
        int nRet;
        if(SelectDirectory("请选择目录","",Path))
        {
                cPath = WideString(Path);
        }
        else
        {
                cPath = "C:\\";
        }
        nRet = SynCardOcx1->SetPhotoPath(2,cPath);
        if(nRet == 0)
        {
                sprintf(sMsg,"%s  照片保存路径设置为:%s,nRet = %d",Now().DateTimeString(),Path.data(),nRet);
        }
        else
        {
                sprintf(sMsg,"%s  设置照片保存路径失败,nRet = %d",Now().DateTimeString(),nRet);
        }

        ListBox1->Items->Add(sMsg);

}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button7Click(TObject *Sender)
{
        char sMsg[1024];
        int nRet;
        nRet = SynCardOcx1->SetPhotoType(0);
        if(nRet == 0)
        {
                sprintf(sMsg,"%s  照片保存格式设置为Bmp:,nRet = %d",Now().DateTimeString(),nRet);
        }
        else
        {
                sprintf(sMsg,"%s  设置照片保存格式失败,nRet = %d",Now().DateTimeString(),nRet);
        }
        ListBox1->Items->Add(sMsg);

}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button8Click(TObject *Sender)
{
        char sMsg[1024];
        int nRet;
        nRet = SynCardOcx1->SetPhotoType(1);
        if(nRet == 0)
        {
                sprintf(sMsg,"%s  照片保存格式设置为Jpeg:,nRet = %d",Now().DateTimeString(),nRet);
        }
        else
        {
                sprintf(sMsg,"%s  设置照片保存格式失败,nRet = %d",Now().DateTimeString(),nRet);
        }
        ListBox1->Items->Add(sMsg);
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button9Click(TObject *Sender)
{
        char sMsg[1024];
        int nRet;
        nRet = SynCardOcx1->SetPhotoType(2);
        if(nRet == 0)
        {
                sprintf(sMsg,"%s  照片保存格式设置为base64:,nRet = %d",Now().DateTimeString(),nRet);
        }
        else
        {
                sprintf(sMsg,"%s  设置照片保存格式失败,nRet = %d",Now().DateTimeString(),nRet);
        }
        ListBox1->Items->Add(sMsg);

}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button10Click(TObject *Sender)
{
        char sMsg[1024];
        int nRet;
        nRet = SynCardOcx1->SetPhotoName(0);
        if(nRet == 0)
        {
                sprintf(sMsg,"%s  照片保存文件名设置为tmp:,nRet = %d",Now().DateTimeString(),nRet);
        }
        else
        {
                sprintf(sMsg,"%s  设置照片保存文件名失败,nRet = %d",Now().DateTimeString(),nRet);
        }
        ListBox1->Items->Add(sMsg);

}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button11Click(TObject *Sender)
{
        char sMsg[1024];
        int nRet;
        nRet = SynCardOcx1->SetPhotoName(1);
        if(nRet == 0)
        {
                sprintf(sMsg,"%s  照片保存文件名设置为姓名:,nRet = %d",Now().DateTimeString(),nRet);
        }
        else
        {
                sprintf(sMsg,"%s  设置照片保存文件名失败,nRet = %d",Now().DateTimeString(),nRet);
        }
        ListBox1->Items->Add(sMsg);
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button12Click(TObject *Sender)
{
        char sMsg[1024];
        int nRet;
        nRet = SynCardOcx1->SetPhotoName(2);
        if(nRet == 0)
        {
                sprintf(sMsg,"%s  照片保存文件名设置为身份证号:,nRet = %d",Now().DateTimeString(),nRet);
        }
        else
        {
                sprintf(sMsg,"%s  设置照片保存文件名失败,nRet = %d",Now().DateTimeString(),nRet);
        }
        ListBox1->Items->Add(sMsg);
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button13Click(TObject *Sender)
{
        char sMsg[1024];
        int nRet;
        nRet = SynCardOcx1->SetPhotoName(3);
        if(nRet == 0)
        {
                sprintf(sMsg,"%s  照片保存文件名设置为姓名_身份证号:,nRet = %d",Now().DateTimeString(),nRet);
        }
        else
        {
                sprintf(sMsg,"%s  设置照片保存文件名失败,nRet = %d",Now().DateTimeString(),nRet);
        }
        ListBox1->Items->Add(sMsg);
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button1Click(TObject *Sender)
{
        char sMsg[1024];
        int nPort=0;
        nPort = SynCardOcx1->FindReader();
        if(nPort ==0)
        {
                Button2->Enabled = false;
                Button3->Enabled = false;
                Button14->Enabled = false;
                sprintf(sMsg,"%s  没有找到读卡器",Now().DateTimeString());
        }
        else
        {
                Beep(4000,200);
                Button2->Enabled = true;
                Button3->Enabled = true;
                Button14->Enabled = true;
                if(nPort > 1000)
                {
                        sprintf(sMsg,"%s  读卡器连接在USB %d 上",Now().DateTimeString(),nPort );
                }
                else
                {
                        sprintf(sMsg,"%s  读卡器连接在串口 %d 上",Now().DateTimeString(),nPort);
                }
        }
        ListBox1->Items->Add(sMsg);
}
//---------------------------------------------------------------------------

void __fastcall TForm1::Button3Click(TObject *Sender)
{
        String sSAMID;
        sSAMID = Now().DateTimeString() + "  SAMID为:" + SynCardOcx1->GetSAMID();
        ListBox1->Items->Add(sSAMID);
}
//---------------------------------------------------------------------------

void __fastcall TForm1::Button2Click(TObject *Sender)
{
        char sMsg[1024];
        String sMsg2;
        int nRet;
        SynCardOcx1->SetReadType(0);
        nRet = SynCardOcx1->ReadCardMsg();
        if(nRet == 0)
        {
                sprintf(sMsg, "%s  读取身份证信息成功!",Now().DateTimeString());
		ListBox1->Items->Add(sMsg);
                sMsg2 = Now().DateTimeString() + "  姓名:" + SynCardOcx1->NameA;
                ListBox1->Items->Add(sMsg2);
                sMsg2 = Now().DateTimeString() + "  性别:" + SynCardOcx1->Sex;
		ListBox1->Items->Add(sMsg2);
                sMsg2 = Now().DateTimeString() + "  民族:" + SynCardOcx1->Nation;
		ListBox1->Items->Add(sMsg2);
                sMsg2 = Now().DateTimeString() + "  出生:" + SynCardOcx1->Born;
		ListBox1->Items->Add(sMsg2);
                sMsg2 = Now().DateTimeString() + "  住址:" + SynCardOcx1->Address;
		ListBox1->Items->Add(sMsg2);
                sMsg2 = Now().DateTimeString() + "  身份证号:" + SynCardOcx1->CardNo;
		ListBox1->Items->Add(sMsg2);
                sMsg2 = Now().DateTimeString() + "  发证机关:" + SynCardOcx1->Police;
		ListBox1->Items->Add(sMsg2);
                sMsg2 = Now().DateTimeString() + "  有效期开始:" + SynCardOcx1->UserLifeB;
		ListBox1->Items->Add(sMsg2);
                sMsg2 = Now().DateTimeString() + "  有效期结束:" + SynCardOcx1->UserLifeE;
		ListBox1->Items->Add(sMsg2);
                sMsg2 = Now().DateTimeString() + "  照片:" + SynCardOcx1->PhotoName;
		ListBox1->Items->Add(sMsg2);
        }
        else
        {
                sprintf(sMsg,"%s  读取身份证信息错误!",Now().DateTimeString());
        	ListBox1->Items->Add(sMsg);
        }
}
//---------------------------------------------------------------------------

void __fastcall TForm1::Button14Click(TObject *Sender)
{
        SynCardOcx1->SetLoopTime(1000);
        SynCardOcx1->SetReadType(1);
}
//---------------------------------------------------------------------------

void __fastcall TForm1::SynCardOcx1CardIn(TObject *Sender, long State)
{
        char sMsg[1024];
        String sMsg2;
        if(State == 1)
        {
                sprintf(sMsg, "%s  读取身份证信息成功!",Now().DateTimeString());
		ListBox1->Items->Add(sMsg);
                sMsg2 = Now().DateTimeString() + "  姓名:" + SynCardOcx1->NameA;
                ListBox1->Items->Add(sMsg2);
                sMsg2 = Now().DateTimeString() + "  性别:" + SynCardOcx1->Sex;
		ListBox1->Items->Add(sMsg2);
                sMsg2 = Now().DateTimeString() + "  民族:" + SynCardOcx1->Nation;
		ListBox1->Items->Add(sMsg2);
                sMsg2 = Now().DateTimeString() + "  出生:" + SynCardOcx1->Born;
		ListBox1->Items->Add(sMsg2);
                sMsg2 = Now().DateTimeString() + "  住址:" + SynCardOcx1->Address;
		ListBox1->Items->Add(sMsg2);
                sMsg2 = Now().DateTimeString() + "  身份证号:" + SynCardOcx1->CardNo;
		ListBox1->Items->Add(sMsg2);
                sMsg2 = Now().DateTimeString() + "  发证机关:" + SynCardOcx1->Police;
		ListBox1->Items->Add(sMsg2);
                sMsg2 = Now().DateTimeString() + "  有效期开始:" + SynCardOcx1->UserLifeB;
		ListBox1->Items->Add(sMsg2);
                sMsg2 = Now().DateTimeString() + "  有效期结束:" + SynCardOcx1->UserLifeE;
		ListBox1->Items->Add(sMsg2);
                sMsg2 = Now().DateTimeString() + "  照片:" + SynCardOcx1->PhotoName;
		ListBox1->Items->Add(sMsg2);
        }
}
//---------------------------------------------------------------------------

