static void Main(string[] args) { try { ThaiNationalIDCardReader cardReader = new ThaiNationalIDCardReader(); PersonalPhoto personalPhoto = cardReader.GetPersonalPhoto(); Console.WriteLine($"CitizenID: {personalPhoto.CitizenID}"); Console.WriteLine($"ThaiPersonalInfo: {personalPhoto.ThaiPersonalInfo}"); Console.WriteLine($"EnglishPersonalInfo: {personalPhoto.EnglishPersonalInfo}"); Console.WriteLine($"DateOfBirth: {personalPhoto.DateOfBirth}"); Console.WriteLine($"Sex: {personalPhoto.Sex}"); Console.WriteLine($"AddressInfo: {personalPhoto.AddressInfo}"); Console.WriteLine($"IssueDate: {personalPhoto.IssueDate}"); Console.WriteLine($"ExpireDate: {personalPhoto.ExpireDate}"); Console.WriteLine($"Issuer: {personalPhoto.Issuer}"); Console.WriteLine($"Photo: {personalPhoto.Photo}"); } catch (Exception e) { Console.WriteLine(e); } Console.WriteLine("Please any key to exit..."); Console.ReadKey(true); }
//timer read smartcard private void timer_checkReadsmartcard_Tick(object sender, EventArgs e) { while (true) { try { cardReader = null; personalPhoto = null; cardReader = new ThaiNationalIDCardReader(); personalPhoto = cardReader.GetPersonalPhoto(); if (personalPhoto.CitizenID == Patients.IDCard) { ReadOmron9020 formreaddata_bp9020 = new ReadOmron9020(); this.Hide(); formreaddata_bp9020.Show(); timer_checkReadsmartcard.Stop(); return; } Readsmartcard(personalPhoto); msg = " Read smartcard suecess ...."; LogMessage(); //log file } catch (Exception ex) { error = "Id card not inserted "; LogMessageError(); Console.WriteLine("Not insert smartcard reader...", ex); } } }
public PersonalPhoto GetPersonalPhoto() { MemoryStream stream = new MemoryStream(); try { Open(); Personal personal = GetPersonalInfo(); PersonalPhoto personalPhoto = new PersonalPhoto(personal); byte[][] photoCommand = apdu.PhotoCommand; byte[] responseBuffer; for (int i = 0; i < photoCommand.Length; i++) { responseBuffer = SendCommand(photoCommand[i]); stream.Write(responseBuffer, 0, responseBuffer.Length); } stream.Seek(0, SeekOrigin.Begin); personalPhoto.Photo = string.Format($"data:image/jpeg;base64,{Convert.ToBase64String(stream.ToArray())}"); return(personalPhoto); } catch (Exception e) { throw e; } finally { stream.Dispose(); Close(); } }
//timer form smartcard public void timer_checksmartcard_Tick(object sender, EventArgs e) { while (true) { try { cardReader = null; personalPhoto = null; cardReader = new ThaiNationalIDCardReader(); // new method personalPhoto = cardReader.GetPersonalPhoto(); if (i == 1) { return; } if (personalPhoto.CitizenID == Patients.IDCard) { Readdata_result(); //call api return; } } catch { msg = "when not insert smart card return to Insertsmart Defualt"; InsertSmartCard forminsertsmart = new InsertSmartCard(); forminsertsmart.Show(); timer_checksmartcard.Stop(); } break; } }
//read smartcard private void Readsmartcard(PersonalPhoto personalPhoto) { Refresh(); string idcard = personalPhoto.CitizenID; var thai_fullname = personalPhoto.ThaiPersonalInfo; string th_firstname = thai_fullname.FirstName; string th_lastname = thai_fullname.LastName; string th_prefix = thai_fullname.Prefix; string th_midlename = thai_fullname.MiddleName; var en_fullname = personalPhoto.EnglishPersonalInfo; string en_firstname = en_fullname.FirstName; string en_lastname = en_fullname.LastName; string en_prefix = en_fullname.Prefix; string en_midlename = en_fullname.MiddleName; DateTime dateofbirth = personalPhoto.DateOfBirth; var gender = personalPhoto.Sex; // sex when 1 = ชาย , 2 = หญิง if (gender == "1") { gender = "ชาย"; } else { gender = "หญิง"; } var address = personalPhoto.AddressInfo; string houseno = address.HouseNo; //บ้านเลขที่ string valiageno = address.VillageNo; //หมู่ที่ string lane = address.Lane; // ตรอก ซอย if (lane == null) { lane = "-"; } string road = address.Road; //ถนน if (road == null) { lane = "-"; } string subdistrat = address.SubDistrict; //ตำบล string district = address.District; //อำเภอ string province = address.Province; //จังหวัด DateTime issuedate = personalPhoto.IssueDate; //วันออกบัตร DateTime expire = personalPhoto.ExpireDate; //วันหมดอายุ string issure = personalPhoto.Issuer; //สถานที่ออกบัตร var photo = personalPhoto.Photo; //photo Patients.IDCard = idcard; Patients.Th_prefix = th_prefix; Patients.Th_firstname = th_firstname; Patients.Th_lastname = th_lastname; Patients.Th_midlename = th_midlename; Patients.En_prefix = en_prefix; Patients.En_firstname = en_firstname; Patients.En_lastname = en_lastname; Patients.En_midlename = en_midlename; Patients.Gender = gender; //address Patients.Houseno = houseno; Patients.Valaigeno = valiageno; Patients.Lane = lane; Patients.Road = road; Patients.Subdistrict = subdistrat; Patients.District = district; Patients.Province = province; // patient.DateOfbrith = dateofbirth; Patients.Issure = issure; //สถานที่ออกบัตร string convert_dateofbrith = Formatdate(dateofbirth); string convert_issuedate = Formatdate(issuedate); string convert_expire = Formatdate(expire); Patients.DateOfbrith = convert_dateofbrith; Patients.Issuedate = convert_issuedate; Patients.Expire = convert_expire; }