Example #1
0
 public string Read()
 {
     try
     {
         int i = idCard.InitDevice();
         if (i == 1001)
         {
             try
             {
                 EDZ    obj = idCard.ReadICCard(i);
                 string str = JsonConvert.SerializeObject(obj);
                 MessageBox.Show("读取成功" + str);
                 return(str);
             }
             catch
             {
                 MessageBox.Show("未放卡或卡未放好!请重新放卡!");
                 return("");
             }
         }
         MessageBox.Show("设备初始化未成功!请检查设备连接状态!");
         return("");
     }
     catch (Exception e)
     {
         MessageBox.Show("设备初始化未成功!请检查设备连接状态!");
         return("");
     }
 }
Example #2
0
 void idCard_ReadICCardComplete(EDZ objEDZ)
 {
     txtName.Text      = objEDZ.Name;
     this.txtNo.Text   = objEDZ.IDC;
     this.txtAdd.Text  = objEDZ.ADDRESS;
     txtFolk.Text      = objEDZ.NATION_CName;
     txtSign.Text      = objEDZ.REGORG;
     txtYearMonth.Text = objEDZ.BIRTH.ToLongDateString();
     //MemoryStream ms = new MemoryStream(objEDZ.PIC_Byte);
     //Image img = Image.FromStream(ms);
     //pictureBox1.Image = objEDZ.PIC_Image;
     MessageBox.Show(objEDZ.ToString());
 }
Example #3
0
        public EDZ ReadICCard(int iPort)
        {
            bool bUsbPort       = false;
            int  intOpenPortRtn = 0;
            int  rtnTemp        = 0;
            int  pucIIN         = 0;
            int  pucSN          = 0;
            int  puiCHMsgLen    = 0;
            int  puiPHMsgLen    = 0;

            objEDZ = new EDZ();


            if (iPort > 1000)
            {
                bUsbPort = true;
            }
            intOpenPortRtn = SDT_OpenPort(iPort);

            if (intOpenPortRtn != 144)
            {
                throw new Exception("端口打开失败,请检测相应的端口或者重新连接读卡器!");
            }
            //找卡
            rtnTemp = SDT_StartFindIDCard(EdziPortID, ref pucIIN, EdziIfOpen);
            if (rtnTemp != 159)
            {
                rtnTemp = SDT_StartFindIDCard(EdziPortID, ref pucIIN, EdziIfOpen);  //再找卡
                if (rtnTemp != 159)
                {
                    rtnTemp = SDT_ClosePort(EdziPortID);
                    throw new Exception("未放卡或者卡未放好,请重新放卡!");
                }
            }

            //选卡
            rtnTemp = SDT_SelectIDCard(EdziPortID, ref pucSN, EdziIfOpen);
            if (rtnTemp != 144)
            {
                rtnTemp = SDT_SelectIDCard(EdziPortID, ref pucSN, EdziIfOpen);  //再选卡
                if (rtnTemp != 144)
                {
                    rtnTemp = SDT_ClosePort(EdziPortID);
                    throw new Exception("读卡失败!");
                }
            }
            //注意,在这里,用户必须有应用程序当前目录的读写权限
            FileInfo objFile = new FileInfo("wz.txt");

            if (objFile.Exists)
            {
                objFile.Attributes = FileAttributes.Normal;
                objFile.Delete();
            }
            objFile = new FileInfo("zp.bmp");
            if (objFile.Exists)
            {
                objFile.Attributes = FileAttributes.Normal;
                objFile.Delete();
            }
            objFile = new FileInfo("zp.wlt");
            if (objFile.Exists)
            {
                objFile.Attributes = FileAttributes.Normal;
                objFile.Delete();
            }
            rtnTemp = SDT_ReadBaseMsgToFile(EdziPortID, "D:\\wz.txt", ref puiCHMsgLen, "D:\\zp.wlt", ref puiPHMsgLen, EdziIfOpen);
            if (rtnTemp != 144)
            {
                rtnTemp = SDT_ClosePort(EdziPortID);
                throw new Exception("读卡失败!");
                //return "读卡失败!";
            }

            FileInfo   f  = new FileInfo("D:\\wz.txt");
            FileStream fs = f.OpenRead();

            byte[] bt = new byte[fs.Length];
            fs.Read(bt, 0, (int)fs.Length);
            fs.Close();

            string str = UnicodeEncoding.Unicode.GetString(bt);

            objEDZ.Name        = UnicodeEncoding.Unicode.GetString(bt, 0, 30).Trim();
            objEDZ.Sex_Code    = UnicodeEncoding.Unicode.GetString(bt, 30, 2).Trim();
            objEDZ.NATION_Code = UnicodeEncoding.Unicode.GetString(bt, 32, 4).Trim();
            string strBird = UnicodeEncoding.Unicode.GetString(bt, 36, 16).Trim();

            objEDZ.BIRTH   = Convert.ToDateTime(strBird.Substring(0, 4) + "年" + strBird.Substring(4, 2) + "月" + strBird.Substring(6) + "日");
            objEDZ.ADDRESS = UnicodeEncoding.Unicode.GetString(bt, 52, 70).Trim();
            objEDZ.IDC     = UnicodeEncoding.Unicode.GetString(bt, 122, 36).Trim();
            objEDZ.REGORG  = UnicodeEncoding.Unicode.GetString(bt, 158, 30).Trim();
            string strTem = UnicodeEncoding.Unicode.GetString(bt, 188, bt.GetLength(0) - 188).Trim();

            objEDZ.STARTDATE = Convert.ToDateTime(strTem.Substring(0, 4) + "年" + strTem.Substring(4, 2) + "月" + strTem.Substring(6, 2) + "日");
            strTem           = strTem.Substring(8);
            if (strTem.Trim() != "长期")
            {
                objEDZ.ENDDATE = Convert.ToDateTime(strTem.Substring(0, 4) + "年" + strTem.Substring(4, 2) + "月" + strTem.Substring(6, 2) + "日");
            }
            else
            {
                objEDZ.ENDDATE = DateTime.MaxValue;
            }


            //ReadICCardComplete(objEDZ);
            return(objEDZ);
        }