private void btnRefreshReaderList_Click_1(object sender, EventArgs e) { cbxReaderList.Items.Clear(); cbxReaderList.SelectedIndex = -1; cbxReaderList.SelectedText = String.Empty; cbxReaderList.Text = string.Empty; cbxReaderList.Refresh(); try { ThaiIDCard idcard = new ThaiIDCard(); string[] readers = idcard.GetReaders(); if (readers == null) { return; } foreach (string r in readers) { cbxReaderList.Items.Add(r); } cbxReaderList.DroppedDown = true; } catch (Exception ex) { MessageBox.Show(ex.ToString()); } }
private void Form2_Load(object sender, EventArgs e) { showUserLogin.BeginInvoke(new MethodInvoker(delegate { showUserLogin.Text = fullname; })); showHosName.BeginInvoke(new MethodInvoker(delegate { showHosName.Text = hosName; })); userFullName.BeginInvoke(new MethodInvoker(delegate { userFullName.Text = ""; })); userIdcard.BeginInvoke(new MethodInvoker(delegate { userIdcard.Text = ""; })); userDiag.BeginInvoke(new MethodInvoker(delegate { userDiag.Text = ""; })); userRegular.BeginInvoke(new MethodInvoker(delegate { userRegular.Text = ""; })); userDoctor.BeginInvoke(new MethodInvoker(delegate { userDoctor.Text = ""; })); userAddress.BeginInvoke(new MethodInvoker(delegate { userAddress.Text = ""; })); userDateDiag.BeginInvoke(new MethodInvoker(delegate { userDateDiag.Text = ""; })); userHos.BeginInvoke(new MethodInvoker(delegate { userHos.Text = ""; })); try { Console.WriteLine("Form1 was loaded"); idcard = new ThaiIDCard(); cardReaders = idcard.GetReaders(); idcard.MonitorStart(cardReaders[0].ToString()); idcard.eventCardInserted += new handleCardInserted(CardInsertedCallback); idcard.eventCardRemoved += new handleCardRemoved(CardRemoveCallback); } catch (Exception ex) { notify.ForeColor = System.Drawing.Color.Red; notify.Text = "ไม่พบเครื่องอ่านบัตรสมาร์ตการ์ด"; } }
public void RefreshDriver() { CheckedListBox_Driver.Items.Clear(); try { Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None); idcard = new ThaiIDCard(); string[] readers = idcard.GetReaders(); if (readers.Length <= 0) { config.AppSettings.Settings.Remove("Driver"); config.AppSettings.Settings.Add("Driver", ""); config.Save(ConfigurationSaveMode.Modified); // Force a reload of a changed section. ConfigurationManager.RefreshSection("appSettings"); return; } foreach (string r in readers) { CheckedListBox_Driver.Items.Add(r); } for (int i = 0; i < CheckedListBox_Driver.Items.Count; i++) { CheckedListBox_Driver.SetItemChecked(i, true); } string item = ""; if (CheckedListBox_Driver.CheckedItems != null) { foreach (object itemChecked in CheckedListBox_Driver.CheckedItems) { if (item == "") { item = itemChecked.ToString(); } else { item += "," + itemChecked.ToString(); } //idcard.MonitorStart(itemChecked.ToString()); } } // Add an Application Setting. config.AppSettings.Settings.Remove("Driver"); config.AppSettings.Settings.Add("Driver", item); config.Save(ConfigurationSaveMode.Modified); // Force a reload of a changed section. ConfigurationManager.RefreshSection("appSettings"); } catch (Exception ex) { MessageBox.Show(ex.ToString()); } }
internal void ReadCard() { string status = ""; string data = ""; try { if (IDCardReader == null) { IDCardReader = new ThaiIDCard(); } string[] readers = IDCardReader.GetReaders(); if (readers == null || readers.Length == 0) { status = "Card reader not found. Please try plug out/in again."; return; } Personal personData = IDCardReader.readAll(); if (personData == null) { status = "Cannot read card. Please try again."; return; } data = "เลบบัตรประชาชน: " + personData.Citizenid + "\n" + "วันเกิด: " + personData.Birthday.ToString("dd/MM/yyyy") + "\n" + "เพศ: " + personData.Sex + "\n" + "ชื่อไทย: " + personData.Th_Prefix + personData.Th_Firstname + " " + personData.Th_Lastname + "\n" + "Name: " + personData.En_Prefix + personData.En_Firstname + " " + personData.En_Lastname + "\n" + "วันออกบัตร: " + personData.Issue.ToString("dd/MM/yyyy") + "\n" + "ผู้ออกบัตร: " + personData.Issuer + "\n" + "วันหมดอายุ: " + personData.Expire.ToString("dd/MM/yyyy") + "\n" + "ที่อยู่: " + personData.Address + "\n" + "บ้านเลขที่: " + personData.addrHouseNo + "\n" + "หมู่ที่: " + personData.addrVillageNo + "\n" + "ซอย: " + personData.addrLane + "\n" + "ถนน: " + personData.addrRoad + "\n" + "ตำบล: " + personData.addrTambol + "\n" + "อำเถอ: " + personData.addrAmphur + "\n" + "จังหวัด: " + personData.addrProvince + "\n"; } catch (Exception e) { status = e.Message; } finally { // update UI in main thread. Dispatcher.Invoke(() => { ProgressLabel.Content = status; CardData.Document.Blocks.Clear(); CardData.Document.Blocks.Add(new Paragraph(new Run(data))); }); } }
private void frmMain_Load(object sender, EventArgs e) { ThaiIDCard idcard = new ThaiIDCard(); //lbLibVersion.Text = "LibThaiIDCard version: " + idcard.Version(); string[] readers = idcard.GetReaders(); foreach (string r in readers) { idcard.MonitorStart(r); idcard.eventCardInsertedWithPhoto += new handleCardInserted(CardInserted); idcard.eventPhotoProgress += new handlePhotoProgress(photoProgress); } }
private void Form1_Load_1(object sender, EventArgs e) { pictureBox1.Visible = false; //this.TopMost = true; //this.FormBorderStyle = FormBorderStyle.None; //this.WindowState = FormWindowState.Maximized; try { Console.WriteLine("Form1 was loaded"); idcard = new ThaiIDCard(); cardReaders = idcard.GetReaders(); idcard.MonitorStart(cardReaders[0].ToString()); idcard.eventCardInserted += new handleCardInserted(CardInsertedCallback); idcard.eventCardRemoved += new handleCardRemoved(CardRemoveCallback); } catch (Exception ex) { Console.WriteLine(ex.Message); label1.Text = "ไม่พบเครื่องอ่านบัตรสมาร์ตการ์ด"; } }
private void btnRefreshReaderList_Click_1(object sender, EventArgs e) { cbxReaderList.Items.Clear(); cbxReaderList.SelectedIndex = -1; cbxReaderList.SelectedText = String.Empty; cbxReaderList.Text = string.Empty; cbxReaderList.Refresh(); ThaiIDCard idcard = new ThaiIDCard(); string[] readers = idcard.GetReaders(); if (readers == null) return; foreach (string r in readers) { cbxReaderList.Items.Add(r); } cbxReaderList.DroppedDown = true; }
private void LoadDeviceIdCard() { cbo_DeviceName.Items.Clear(); cbo_DeviceName.SelectedText = String.Empty; cbo_DeviceName.Text = string.Empty; cbo_DeviceName.Refresh(); var contextFactory = ContextFactory.Instance; using (var context = contextFactory.Establish(SCardScope.System)) { Console.WriteLine("Currently connected readers: "); var readerNames = context.GetReaders(); foreach (var readerName in readerNames) { try { using (var reader = context.ConnectReader(readerName, SCardShareMode.Shared, SCardProtocol.Any)) { var status = reader.GetStatus(); Debug.WriteLine(JsonConvert.SerializeObject(status)); AtrString = BitConverter.ToString(status.GetAtr()).Replace("-", ""); } } catch (Exception exception) { Debug.WriteLine( "No card inserted or reader '{0}' is reserved exclusively by another application.", readerName); Debug.WriteLine("Error message: {0} ({1})\n", exception.Message, exception.GetType()); } } } try { ThaiIDCard idcard = new ThaiIDCard(); string[] readers = idcard.GetReaders(); if (readers == null) { btnLoadCard.Enabled = false; return; } btnLoadCard.Enabled = true; foreach (string r in readers) { cbo_DeviceName.Items.Add(r); } Debug.WriteLine("Count", cbo_DeviceName.Items.Count.ToString()); if (cbo_DeviceName.Items.Count > 0) { cbo_DeviceName.SelectedIndex = 0; } else { cbo_DeviceName.Items.Add("None"); } cbo_DeviceName.DroppedDown = true; } catch (Exception ex) { cbo_DeviceName.Items.Add("None"); cbo_DeviceName.SelectedIndex = 0; Debug.WriteLine(ex.ToString()); } }
private void button1_Click(object sender, EventArgs e) { thaicard.GetReaders(); //readCard(); }