예제 #1
0
        private void ListCardReader()
        {
            byte[] szReaders = new byte[1024 * 2];
            int    size      = szReaders.Length;
            int    numreader = RDNID.getReaderListRD(szReaders, size);

            if (numreader <= 0)
            {
                return;
            }
            string s = CardHelper.ByteToString(szReaders);

            string[] readlist = s.Split(';');
            if (readlist != null)
            {
                for (int i = 0; i < readlist.Length; i++)
                {
                    CARD_READER = readlist[i];
                }
            }
        }
예제 #2
0
        private void ListCardReader()
        {
            byte[] szReaders = new byte[1024 * 2];
            int    size      = szReaders.Length;
            int    numreader = RDNID.getReaderListRD(szReaders, size);

            if (numreader <= 0)
            {
                return;
            }
            String s = CardHelper.ByteToString(szReaders);

            String[] readlist = s.Split(';');
            if (readlist != null)
            {
                for (int i = 0; i < readlist.Length; i++)
                {
                    m_ListReaderCard.Items.Add(readlist[i]);
                }

                m_ListReaderCard.SelectedIndex = 0;
            }
        }
예제 #3
0
        protected int ReadPIDCard()
        {
            try
            {
                string strTerminal = CARD_READER;
                if (string.IsNullOrEmpty(CARD_READER))
                {
                    strTerminal = "Identiv uTrust 2700 R Smart Card Reader 0";
                }
                CARD      = new PIDCard();
                CARD_TYPE = "PID";
                IntPtr obj = CardHelper.SelectReader(strTerminal);

                int nInsertCard = 0;
                nInsertCard = RDNID.connectCardRD(obj);
                if (nInsertCard != 0)
                {
                    String m;
                    m = String.Format(" error no {0} ", nInsertCard);
                    MessageBox.Show(m);

                    RDNID.disconnectCardRD(obj);
                    RDNID.deselectReaderRD(obj);
                    return(nInsertCard);
                }

                byte[] id  = new byte[30];
                int    res = RDNID.getNIDNumberRD(obj, id);
                if (res != DefineConstants.NID_SUCCESS)
                {
                    return(res);
                }
                string NIDNum = CardHelper.ByteToString(id);


                byte[] data = new byte[1024];
                res = RDNID.getNIDTextRD(obj, data, data.Length);
                if (res != DefineConstants.NID_SUCCESS)
                {
                    return(res);
                }

                string NIDData = CardHelper.ByteToString(data);
                if (NIDData == "")
                {
                    MessageBox.Show("Read Text error");
                }
                else
                {
                    string[] fields = NIDData.Split('#');
                    CARD.NO            = NIDNum;
                    CARD.TH_TITLE      = fields[(int)Enums.NID_FIELD.TITLE_T];
                    CARD.TH_FIRST_NAME = fields[(int)Enums.NID_FIELD.NAME_T];
                    CARD.TH_MID_NAME   = fields[(int)Enums.NID_FIELD.MIDNAME_T];
                    CARD.TH_LAST_NAME  = fields[(int)Enums.NID_FIELD.SURNAME_T];
                    CARD.EN_TITLE      = fields[(int)Enums.NID_FIELD.TITLE_E];
                    CARD.EN_FIRST_NAME = fields[(int)Enums.NID_FIELD.NAME_E];
                    CARD.EN_MID_NAME   = fields[(int)Enums.NID_FIELD.MIDNAME_E];
                    CARD.EN_LAST_NAME  = fields[(int)Enums.NID_FIELD.SURNAME_E];
                    CARD.BIRTH_DATE    = CardHelper.DateFormat(fields[(int)Enums.NID_FIELD.BIRTH_DATE]);
                    CARD.HOME_NO       = fields[(int)Enums.NID_FIELD.HOME_NO];
                    CARD.MOO           = fields[(int)Enums.NID_FIELD.MOO];
                    CARD.TROK          = fields[(int)Enums.NID_FIELD.TROK];
                    CARD.SOI           = fields[(int)Enums.NID_FIELD.SOI];
                    CARD.ROAD          = fields[(int)Enums.NID_FIELD.ROAD];
                    CARD.TUMBON        = fields[(int)Enums.NID_FIELD.TUMBON];
                    CARD.AMPHOE        = fields[(int)Enums.NID_FIELD.AMPHOE];
                    CARD.PROVINCE      = fields[(int)Enums.NID_FIELD.PROVINCE];

                    if (fields[(int)Enums.NID_FIELD.GENDER] == "1")
                    {
                        CARD.GENDER = "ชาย";
                    }
                    else
                    {
                        CARD.GENDER = "หญิง";
                    }
                }

                byte[] NIDPicture = new byte[1024 * 5];
                int    imgsize    = NIDPicture.Length;
                res = RDNID.getNIDPhotoRD(obj, NIDPicture, out imgsize);
                if (res != DefineConstants.NID_SUCCESS)
                {
                    return(res);
                }

                byte[] byteImage = NIDPicture;
                if (byteImage == null)
                {
                    MessageBox.Show("Read Photo error");
                }
                else
                {
                    //m_picPhoto
                    Image img = Image.FromStream(new MemoryStream(byteImage));
                    CARD.PHOTO      = new Bitmap(img, 270 - 2, 180 - 2);
                    CARD.CARD_IMAGE = img;
                    CARD.BYTE_IMAGE = byteImage;
                }
                RDNID.disconnectCardRD(obj);
                RDNID.deselectReaderRD(obj);
                READ_CARD_STATUS = true;
            }
            catch (Exception ex)
            {
                READ_CARD_STATUS = false;
                MessageBox.Show("ไม่พบเครื่องอ่านบัตรประชาชน หรืออ่านบัตรไม่สำเร็จ!!! " + ex.Message);
            }

            return(0);
        }
예제 #4
0
        protected int ReadPIDCard()
        {
            String strTerminal = m_ListReaderCard.GetItemText(m_ListReaderCard.SelectedItem);

            IntPtr obj = CardHelper.SelectReader(strTerminal);


            Int32 nInsertCard = 0;

            nInsertCard = RDNID.connectCardRD(obj);
            if (nInsertCard != 0)
            {
                String m;
                m = String.Format(" error no {0} ", nInsertCard);
                MessageBox.Show(m);

                RDNID.disconnectCardRD(obj);
                RDNID.deselectReaderRD(obj);
                return(nInsertCard);
            }


            //BindDataToScreen();
            byte[] id  = new byte[30];
            int    res = RDNID.getNIDNumberRD(obj, id);

            if (res != DefineConstants.NID_SUCCESS)
            {
                return(res);
            }
            String NIDNum = CardHelper.ByteToString(id);



            byte[] data = new byte[1024];
            res = RDNID.getNIDTextRD(obj, data, data.Length);
            if (res != DefineConstants.NID_SUCCESS)
            {
                return(res);
            }

            String NIDData = CardHelper.ByteToString(data);

            if (NIDData == "")
            {
                MessageBox.Show("Read Text error");
            }
            else
            {
                string[] fields = NIDData.Split('#');

                m_txtID.Text = NIDNum;                             // or use m_txtID.Text = fields[(int)NID_FIELD.NID_Number];

                string fullname = fields[(int)Enums.NID_FIELD.TITLE_T] + " " +
                                  fields[(int)Enums.NID_FIELD.NAME_T] + " " +
                                  fields[(int)Enums.NID_FIELD.MIDNAME_T] + " " +
                                  fields[(int)Enums.NID_FIELD.SURNAME_T];
                m_txtFullNameT.Text = fullname;

                fullname = fields[(int)Enums.NID_FIELD.TITLE_E] + " " +
                           fields[(int)Enums.NID_FIELD.NAME_E] + " " +
                           fields[(int)Enums.NID_FIELD.MIDNAME_E] + " " +
                           fields[(int)Enums.NID_FIELD.SURNAME_E];
                m_txtFullNameE.Text = fullname;

                m_txtBrithDate.Text = CardHelper.DateFormat(fields[(int)Enums.NID_FIELD.BIRTH_DATE]);

                m_txtAddress.Text = fields[(int)Enums.NID_FIELD.HOME_NO] + "   " +
                                    fields[(int)Enums.NID_FIELD.MOO] + "   " +
                                    fields[(int)Enums.NID_FIELD.TROK] + "   " +
                                    fields[(int)Enums.NID_FIELD.SOI] + "   " +
                                    fields[(int)Enums.NID_FIELD.ROAD] + "   " +
                                    fields[(int)Enums.NID_FIELD.TUMBON] + "   " +
                                    fields[(int)Enums.NID_FIELD.AMPHOE] + "   " +
                                    fields[(int)Enums.NID_FIELD.PROVINCE] + "   "
                ;
                if (fields[(int)Enums.NID_FIELD.GENDER] == "1")
                {
                    m_txtGender.Text = "ชาย";
                }
                else
                {
                    m_txtGender.Text = "หญิง";
                }
                m_txtIssueDate.Text  = CardHelper.DateFormat(fields[(int)Enums.NID_FIELD.ISSUE_DATE]);
                m_txtExpiryDate.Text = CardHelper.DateFormat(fields[(int)Enums.NID_FIELD.EXPIRY_DATE]);
                if ("99999999" == m_txtExpiryDate.Text)
                {
                    m_txtExpiryDate.Text = "99999999 ตลอดชีพ";
                }
                string m_txtIssueNum = fields[(int)Enums.NID_FIELD.ISSUE_NUM];
            }

            byte[] NIDPicture = new byte[1024 * 5];
            int    imgsize    = NIDPicture.Length;

            res = RDNID.getNIDPhotoRD(obj, NIDPicture, out imgsize);
            if (res != DefineConstants.NID_SUCCESS)
            {
                return(res);
            }

            byte[] byteImage = NIDPicture;
            if (byteImage == null)
            {
                MessageBox.Show("Read Photo error");
            }
            else
            {
                //m_picPhoto
                Image  img     = Image.FromStream(new MemoryStream(byteImage));
                Bitmap MyImage = new Bitmap(img, m_picPhoto.Width - 2, m_picPhoto.Height - 2);
                m_picPhoto.Image = (Image)MyImage;
            }

            RDNID.disconnectCardRD(obj);
            RDNID.deselectReaderRD(obj);
            return(0);
        }