public Frmsfxx(ref IDCardData CardMsg) : this() { lblxm.Text = ""; lblxb.Text = ""; lblmz.Text = ""; lblcsrq.Text = ""; lbljtdz.Text = ""; lblsfzh.Text = ""; lblqfjg.Text = ""; lblyxq.Text = ""; pictureBox1.Image = null; if (pictureBox1.Image != null) { pictureBox1.Image.Dispose(); } lblxm.Text = CardMsg.Name.Trim(); lblxb.Text = CardMsg.Sex; lblmz.Text = CardMsg.Nation; lblcsrq.Text = CardMsg.Born.Trim();//.Substring(0, 4) + "年" + CardMsg.Born.Trim().Substring(4, 2) +"月"+ CardMsg.Born.Trim().Substring(6, 2)+"日"; lbljtdz.Text = CardMsg.Address; lblsfzh.Text = CardMsg.IDCardNo; lblqfjg.Text = CardMsg.GrantDept; lblyxq.Text = CardMsg.UserLifeEnd + "----" + CardMsg.UserLifeEnd; pictureBox1.Image = Image.FromFile(CardMsg.PhotoFileName); }
public bool ReadCard(ref IDCardData _idcarddata, ref string msg) { int ret; StringBuilder data = new StringBuilder(); string cardno = ""; int icdev = InitComm(1001); if (icdev == 1) { IDCardData cardData = new IDCardData(); //读身份证号 StringBuilder sbMsg = new StringBuilder(); StringBuilder sbCode = new StringBuilder(); sbMsg.Length = 127; ret = IDCard_SetDeviceParam("JingLun", "1001", "9600", sbCode); ret = IDCard_OpenDevice(sbCode); ret = IDCard_ReadIDCardMsg(5000, sbMsg, sbCode); if (ret != 0) { CloseComm(); msg = "初始化错误"; return(false); } string personInfo = ""; if (ret == 0) { personInfo = sbMsg.ToString(); string[] personNo = personInfo.Split(new char[] { '|' }); cardno = personNo[4].ToString(); _idcarddata.Name = personNo[0].Trim(); _idcarddata.Sex = personNo[1].Trim(); _idcarddata.Nation = personNo[2].Trim(); string bornday = personNo[3].Trim().Substring(0, 4) + "-" + personNo[3].Trim().Substring(4, 2) + "-" + personNo[3].Trim().Substring(6, 2); _idcarddata.Born = bornday; _idcarddata.IDCardNo = personNo[4].Trim(); _idcarddata.Address = personNo[5].Trim(); _idcarddata.GrantDept = personNo[6].Trim(); _idcarddata.UserLifeBegin = personNo[7].Trim(); _idcarddata.UserLifeEnd = personNo[8].Trim(); } //读身份证管理号 StringBuilder serial = new StringBuilder(); ret = (ReadIINSNDN(serial) ^ 1); if (ret == 0) { string personMNo = serial.ToString(); _idcarddata.reserved = personMNo; } else { } CloseComm(); return(true); } else { return(false); } }
/// <summary> /// 将CardMsg信息 设置到控件 /// </summary> /// <param name="CardMsg"></param> /// <param name="txtName">姓名</param> /// <param name="combXb">性别</param> /// <param name="txtYear">(出生年月)年</param> /// <param name="txtMonth">(出生年月)月</param> /// <param name="txtDay">(出生年月)日</param> /// <param name="txtDz">住址、地址</param> /// <param name="txtSfz">身份证号</param> /// <param name="comMz">民族</param> /// <returns></returns> public void ReadCardToControl(IDCardData CardMsg, Control txtName, Control combXb, Control txtYear, Control txtMonth, Control txtDay, Control txtDz, Control txtSfz, Control comMz) { bool flag = false; PubFun.ReadCardToControl(CardMsg, txtName, combXb, txtYear, txtMonth, txtDay, txtDz, txtSfz, comMz); }
public bool ReadCard(ref IDCardData _idcarddata, ref string msg) { Guid name = Guid.NewGuid(); string folder = CardFactory.GetIniString("身份证扫描器", "运行目录", AppDomain.CurrentDomain.BaseDirectory + "ClientWindow.ini"); string exe = folder + "\\tsIdCardReader.exe"; string file = folder + "\\" + name + ".txt"; //启动读身份证的程序 Process.Start(exe, name.ToString()); while (true) { if (Process.GetProcessesByName("tsIdCardReader").Length == 0) { break; } } string xml = ""; while (true) { if (System.IO.File.Exists(file)) { using (System.IO.StreamReader sr = new System.IO.StreamReader(file, Encoding.UTF8)) { xml = sr.ReadLine(); sr.Close(); } System.IO.File.Delete(file); break; } } _idcarddata = new IDCardData(); //System.Windows.Forms.MessageBox.Show( xml ); if (!string.IsNullOrEmpty(xml)) { System.Xml.XmlDocument document = new System.Xml.XmlDocument(); document.LoadXml(xml); _idcarddata.Address = document.SelectSingleNode("IDCardData/Address").InnerText; _idcarddata.Born = document.SelectSingleNode("IDCardData/Born").InnerText; _idcarddata.GrantDept = document.SelectSingleNode("IDCardData/GrantDept").InnerText; _idcarddata.IDCardNo = document.SelectSingleNode("IDCardData/IDCardNo").InnerText; _idcarddata.Name = document.SelectSingleNode("IDCardData/Name").InnerText; _idcarddata.Nation = document.SelectSingleNode("IDCardData/Nation").InnerText; _idcarddata.PhotoFileName = document.SelectSingleNode("IDCardData/PhotoFileName").InnerText; _idcarddata.reserved = document.SelectSingleNode("IDCardData/reserved").InnerText; _idcarddata.Sex = document.SelectSingleNode("IDCardData/Sex").InnerText; _idcarddata.UserLifeBegin = document.SelectSingleNode("IDCardData/UserLifeBegin").InnerText; _idcarddata.UserLifeEnd = document.SelectSingleNode("IDCardData/UserLifeEnd").InnerText; } msg = string.IsNullOrEmpty(xml) ? "读取身份证信息失败" : ""; return(string.IsNullOrEmpty(xml) ? false : true); }
public bool ReadCardToControl(ref IDCardData CardMsg, ref string msg, bool errAutoMsg, System.Windows.Forms.Control txtName, System.Windows.Forms.Control combXb, System.Windows.Forms.Control txtYear, System.Windows.Forms.Control txtMonth, System.Windows.Forms.Control txtDay, System.Windows.Forms.Control txtDz, System.Windows.Forms.Control txtSfz, System.Windows.Forms.Control comMz) { bool flag = this.ReadCard(ref CardMsg, ref msg); if (flag) { this.ReadCardToControl(CardMsg, txtName, combXb, txtYear, txtMonth, txtDay, txtDz, txtSfz, comMz); } else if (errAutoMsg == true) { throw new Exception(msg); } return(true); }
public bool ReadCardToControl(ref IDCardData CardMsg, ref string msg, bool errAutoMsg, System.Windows.Forms.Control txtName, System.Windows.Forms.Control combXb, System.Windows.Forms.Control txtYear, System.Windows.Forms.Control txtMonth, System.Windows.Forms.Control txtDay, System.Windows.Forms.Control txtDz, System.Windows.Forms.Control txtSfz, System.Windows.Forms.Control comMz) { bool flag = this.ReadCard(ref CardMsg, ref msg); if (flag) { this.ReadCardToControl(CardMsg, txtName, combXb, txtYear, txtMonth, txtDay, txtDz, txtSfz, comMz); } else if (errAutoMsg == true) { MessageBox.Show(msg, "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Hand); } return(flag); }
private void button1_Click(object sender, EventArgs e) { Icard card = CardFactory.NewCard(CardFactory.CardKind.ShenSi); IDCardData cardinfo = new IDCardData(); string err = ""; bool t = card.ReadCard(ref cardinfo, ref err); if (t) { MessageBox.Show(cardinfo.Name); } else { MessageBox.Show(err); } }
/// <summary> /// 读取身份证信息 /// </summary> /// <param name="CardMsg">IDCardData身份证信息</param> /// <param name="msg">提示信息</param> /// <returns>返回false表示有错误</returns> public bool ReadCard(ref IDCardData CardMsg, ref string msg) { bool bok = Openport(out msg); if (bok == false) { return(bok); } String sText; byte[] pucIIN = new byte[4]; byte[] pucSN = new byte[8]; int nRet = Syn_OpenPort(iPort); if (nRet == 0) { nRet = Syn_GetSAMStatus(iPort, 0); nRet = Syn_StartFindIDCard(iPort, ref pucIIN[0], 0); nRet = Syn_SelectIDCard(iPort, ref pucSN[0], 0); nRet = Syn_ReadMsg(iPort, 0, ref CardMsg); if (nRet == 0) { nRet = Syn_ClosePort(iPort); nRet = Syn_ResetSAM(iPort, 0); CardMsg.Address = CardMsg.Address.Trim(); CardMsg.Name = CardMsg.Name.Trim(); CardMsg.GrantDept = CardMsg.GrantDept.Trim(); CardMsg.Born = CardMsg.Born.Trim().Substring(0, 4) + "年" + CardMsg.Born.Trim().Substring(4, 2) + "月" + CardMsg.Born.Trim().Substring(6, 2) + "日"; CardMsg.Sex = CardMsg.Sex == "2"?"女":"男"; return(true); } else { sText = "读二代证信息错误!"; msg = sText.ToString(); Syn_ClosePort(iPort); return(false); } } else { sText = "打开端口错误"; msg = sText.ToString(); Syn_ClosePort(iPort); return(false); } }
public bool ReadCard(ref IDCardData _idcarddata, ref string msg) { try { Int32 result = OpenCardReader(port, 0x02); if (result != 0) { msg = "打卡设备端口失败"; return(false); } PERSONINFOW info = new PERSONINFOW(); result = GetPersonMsgW(ref info, ""); if (result != 0) { msg = "读身份证失败"; return(false); } _idcarddata = new IDCardData(); _idcarddata.Address = info.address; _idcarddata.Born = string.Format("{0}-{1}-{2}", info.birthday.Substring(0, 4), info.birthday.Substring(4, 2), info.birthday.Substring(6, 2)); _idcarddata.GrantDept = info.police; _idcarddata.IDCardNo = info.cardId; _idcarddata.Name = info.name; _idcarddata.Nation = info.nation + "族"; _idcarddata.Sex = info.sex; _idcarddata.UserLifeBegin = info.validStart; _idcarddata.UserLifeEnd = info.validEnd; msg = "读取成功"; return(true); } catch { msg = "未知的错误"; return(false); } finally { CloseCardReader(); } }
/// <summary> /// 将CardMsg信息 设置到控件 /// </summary> /// <param name="CardMsg"></param> /// <param name="txtName">姓名</param> /// <param name="combXb">性别</param> /// <param name="txtYear">(出生年月)年</param> /// <param name="txtMonth">(出生年月)月</param> /// <param name="txtDay">(出生年月)日</param> /// <param name="txtDz">住址、地址</param> /// <param name="txtSfz">身份证号</param> /// <param name="comMz">民族</param> /// <returns></returns> public static void ReadCardToControl(IDCardData CardMsg, Control txtName, Control combXb, Control txtYear, Control txtMonth, Control txtDay, Control txtDz, Control txtSfz, Control comMz) { bool flag = false; if (txtName != null && CardMsg.Name != null) { txtName.Text = CardMsg.Name; //姓名 } if (combXb != null && CardMsg.Sex != null) { combXb.Text = CardMsg.Sex; //性别 } if (txtYear != null && CardMsg.Born != null) { txtYear.Text = CardMsg.Born.Substring(0, 4); //出生日期 //.Substring(0, 4) + "年" + CardMsg.Born.Trim().Substring(4, 2) +"月"+ CardMsg.Born.Trim().Substring(6, 2)+"日"; } if (txtMonth != null && CardMsg.Born != null) { txtMonth.Text = CardMsg.Born.Substring(5, 2); //出生日期 } if (txtDay != null && CardMsg.Born != null) { txtDay.Text = CardMsg.Born.Substring(8, 2); //出生日期 } if (txtDz != null && CardMsg.Address != null) { txtDz.Text = CardMsg.Address; //地址 } if (txtSfz != null && CardMsg.IDCardNo != null) { txtSfz.Text = CardMsg.IDCardNo; //身份证 } if (comMz != null && CardMsg.Nation != null) { comMz.Text = CardMsg.Nation; //民族 } }
public void ReadCardToControl(IDCardData CardMsg, System.Windows.Forms.Control txtName, System.Windows.Forms.Control combXb, System.Windows.Forms.Control txtYear, System.Windows.Forms.Control txtMonth, System.Windows.Forms.Control txtDay, System.Windows.Forms.Control txtDz, System.Windows.Forms.Control txtSfz, System.Windows.Forms.Control comMz) { bool flag = false; PubFun.ReadCardToControl(CardMsg, txtName, combXb, txtYear, txtMonth, txtDay, txtDz, txtSfz, comMz); }
public static extern int Syn_ReadCard(out IDCardData pIDCardData, int Rmode);
public static extern int Syn_ReadMsg(int iPortID, int iIfOpen, ref IDCardData pIDCardData);
/// <summary> /// 读取身份证信息 /// </summary> /// <param name="CardMsg">IDCardData身份证信息</param> /// <param name="msg">提示信息</param> /// <returns>返回false表示有错误</returns> public bool ReadCard(ref IDCardData CardMsg, ref string msg) { try { #region 打开端口-验证卡-读卡 bool bok = Openport(out msg); if (bok == false) { return(bok); } byte cmd = 67; //0x43 //验证卡 int nRet = UCommand(ref cmd, ref iPort, ref para1, ref para2); //验证卡 if (nRet != 62171) { msg = "验证卡失败,请重新放卡再试"; return(false); } cmd = 68; //0x44 读卡内信息 nRet = UCommand(ref cmd, ref iPort, ref para1, ref para2); //读卡 Closeport(iPort); #endregion #region 读取信息 if (nRet == 62171) { #region 读取详细信息 string fileName = Application.StartupPath + "\\wx.txt"; //获取文件路径 System.IO.StreamReader streamReader = new System.IO.StreamReader(fileName, Encoding.GetEncoding("GBK")); //将文件定义编码 string[] sData = streamReader.ReadToEnd().ToString().Split(new string[] { "\r\n" }, StringSplitOptions.None); //将字符串截取并存入到数组当中 streamReader.Close(); if (sData.Length >= 9) { CardMsg.Name = sData[0].Trim();//将身份信息赋值 CardMsg.Sex = sData[1].Trim(); CardMsg.Nation = sData[2].Trim(); CardMsg.Born = sData[3].Trim(); CardMsg.Born = Convert.ToDateTime(CardMsg.Born).ToString("yyyy年MM月dd日"); CardMsg.Address = sData[4].Trim(); CardMsg.IDCardNo = sData[5].Trim(); CardMsg.GrantDept = sData[6].Trim(); CardMsg.UserLifeBegin = sData[7].Trim(); CardMsg.UserLifeBegin = Convert.ToDateTime(CardMsg.UserLifeBegin).ToString("yyyyMMdd"); CardMsg.UserLifeEnd = sData[8].Trim(); CardMsg.UserLifeEnd = Convert.ToDateTime(CardMsg.UserLifeEnd).ToString("yyyyMMdd"); CardMsg.PhotoFileName = Application.StartupPath + "\\zp.bmp";//获取照片文件路径 return(true); } else { msg = "读取身份证信息不完整"; return(false); } #endregion } else if (nRet == -5) { msg = "神思读卡器没有授权"; return(false); } else { msg = "读卡失败"; return(false); } #endregion } catch (Exception ex) { throw new Exception("发生错误" + ex.Message); } }
public static extern int Syn_ReadFPMsg(int iPortID, int iIfOpen, ref IDCardData pIDCardData, ref byte cFPhotoname);
/// <summary> /// 读取身份证信息 /// </summary> /// <param name="CardMsg">IDCardData身份证信息</param> /// <param name="msg">提示信息</param> /// <returns>返回false表示有错误</returns> public bool ReadCard(ref IDCardData CardMsg, ref string msg) { bool bok = FindUSBReader(out msg); if (bok == false) { return(bok); } int nRet, nPort, iPhotoType; String sText; byte[] cPath = new byte[255]; byte[] pucIIN = new byte[4]; byte[] pucSN = new byte[8]; nPort = iPort; Syn_SetPhotoPath(1, ref cPath[0]); //设置照片路径 iOption 路径选项 0=C:\ 1=当前路径 2=指定路径 //cPhotoPath 绝对路径,仅在iOption=2时有效 iPhotoType = 0; Syn_SetPhotoType(0); //0 = bmp ,1 = jpg , 2 = base64 , 3 = WLT ,4 = 不生成 Syn_SetPhotoName(2); // 生成照片文件名 0=tmp 1=姓名 2=身份证号 3=姓名_身份证号 //Syn_SetSexType(1); // 0=卡中存储的数据 1=解释之后的数据,男、女、未知 Syn_SetNationType(1);// 0=卡中存储的数据 1=解释之后的数据 2=解释之后加"族" //Syn_SetBornType(1); // 0=YYYYMMDD,1=YYYY年MM月DD日,2=YYYY.MM.DD,3=YYYY-MM-DD,4=YYYY/MM/DD //Syn_SetUserLifeBType(1); // 0=YYYYMMDD,1=YYYY年MM月DD日,2=YYYY.MM.DD,3=YYYY-MM-DD,4=YYYY/MM/DD //Syn_SetUserLifeEType(1, 1); // 0=YYYYMMDD(不转换),1=YYYY年MM月DD日,2=YYYY.MM.DD,3=YYYY-MM-DD,4=YYYY/MM/DD, //// 0=长期 不转换, 1=长期转换为 有效期开始+50年 if (Syn_OpenPort(nPort) == 0) { if (Syn_SetMaxRFByte(nPort, 60, 0) == 0) { nRet = Syn_StartFindIDCard(nPort, ref pucIIN[0], 0); nRet = Syn_SelectIDCard(nPort, ref pucSN[0], 0); nRet = Syn_ReadMsg(nPort, 0, ref CardMsg); if (nRet == 0) { //stmp = Convert.ToString(System.DateTime.Now) + " 姓名:" + CardMsg.Name; //listBox1.Items.Add(stmp); //stmp = Convert.ToString(System.DateTime.Now) + " 性别:" + CardMsg.Sex; //listBox1.Items.Add(stmp); //stmp = Convert.ToString(System.DateTime.Now) + " 民族:" + CardMsg.Nation; //listBox1.Items.Add(stmp); //stmp = Convert.ToString(System.DateTime.Now) + " 出生日期:" + CardMsg.Born; //listBox1.Items.Add(stmp); //stmp = Convert.ToString(System.DateTime.Now) + " 地址:" + CardMsg.Address; //listBox1.Items.Add(stmp); //stmp = Convert.ToString(System.DateTime.Now) + " 身份证号:" + CardMsg.IDCardNo; //listBox1.Items.Add(stmp); //stmp = Convert.ToString(System.DateTime.Now) + " 发证机关:" + CardMsg.GrantDept; //listBox1.Items.Add(stmp); //stmp = Convert.ToString(System.DateTime.Now) + " 有效期开始:" + CardMsg.UserLifeBegin; //listBox1.Items.Add(stmp); //stmp = Convert.ToString(System.DateTime.Now) + " 有效期结束:" + CardMsg.UserLifeEnd; //listBox1.Items.Add(stmp); //stmp = Convert.ToString(System.DateTime.Now) + " 照片文件名:" + CardMsg.PhotoFileName; CardMsg.Address = CardMsg.Address.Trim(); CardMsg.Name = CardMsg.Name.Trim(); CardMsg.GrantDept = CardMsg.GrantDept.Trim(); //Syn_DelPhotoFile(); CardMsg.Born = CardMsg.Born.Trim().Substring(0, 4) + "年" + CardMsg.Born.Trim().Substring(4, 2) + "月" + CardMsg.Born.Trim().Substring(6, 2) + "日"; CardMsg.Sex = CardMsg.Sex == "2" ? "女" : "男"; bok = true; } else { sText = "读二代证信息错误!"; msg = sText.ToString(); bok = false; } } } else { msg = Convert.ToString(System.DateTime.Now) + " 打开端口失败"; bok = false; } Syn_ClosePort(nPort); return(bok); }