Example #1
0
        public IICCardModel ReadCard()
        {
            HDICCardModel cardModel = new HDICCardModel(false);
            int           iport     = 1001;

            try
            {
                ReadCardRetVal ret = new ReadCardRetVal();
                ret.init();


                ret = InitComm(ref iport);

                if (ret.retVal == 0)
                {
                    //在这循环处理对应的内容
                    ret.init();
                    int xh = 0;
                    while (true)
                    {
                        //华大的设备需要放卡才会有反馈,默认20次不行需退出,不能死循环
                        ret = Authenticate();
                        if (ret.retVal == 0)
                        {
                            break;
                        }
                        xh++;
                        if (xh > 20)
                        {
                            break;
                        }
                        System.Threading.Thread.Sleep(200);
                    }
                    if (ret.retVal == 0)
                    {
                        ret.init();

                        cardModel = Read_BaseInfo(iport);
                    }
                }
                cardModel.ErrorMessage = GetReadCardMessage(ret.retVal);
            }
            catch (Exception ex)
            {
                cardModel.ErrorMessage = "读卡失败:" + ex.Message;
            }
            finally
            {
                CloseComm(iport);
            }
            return(cardModel);
        }
Example #2
0
        private HDICCardModel Read_BaseInfo(int iport)
        {
            HDICCardModel cardModel = new HDICCardModel(false);

            try
            {
                StringBuilder pBmpData = new StringBuilder(100);
                pBmpData.Append(System.Environment.CurrentDirectory);
                pBmpData.Append(@"\zp.bmp");
                StringBuilder pName       = new StringBuilder(100);
                StringBuilder pSex        = new StringBuilder(10);
                StringBuilder pNation     = new StringBuilder(50);
                StringBuilder pBirth      = new StringBuilder(20);
                StringBuilder pAddress    = new StringBuilder(100);
                StringBuilder pCertNo     = new StringBuilder(40);
                StringBuilder pDepartment = new StringBuilder(50);
                StringBuilder pEffectdata = new StringBuilder(20);
                StringBuilder pExpire     = new StringBuilder(20);
                int           retVal      = HD_Read_BaseMsg(pBmpData, pName, pSex, pNation, pBirth, pAddress, pCertNo, pDepartment, pEffectdata, pExpire);
                if (retVal == 0)
                {
                    cardModel.Address = pAddress.ToString().Trim();
                    //跟之前的新中新卡具值一致处理 1900年01月01日
                    string birth = pBirth.ToString().Trim();
                    cardModel.Birthday = ToDateTime(birth);
                    cardModel.Issuer   = pDepartment.ToString().Trim();
                    cardModel.ICCard   = pCertNo.ToString().Trim();
                    cardModel.Sex      = pSex.ToString().Trim();
                    //新中新 1 男, 2 女
                    if (cardModel.Sex == "女")
                    {
                        cardModel.SexCode = "2";
                    }
                    else
                    {
                        cardModel.SexCode = "1";
                    }
                    cardModel.Nation             = pNation.ToString().Trim();
                    cardModel.Name               = pName.ToString().Trim();
                    cardModel.StartEffectiveDate = ToDateTime(pEffectdata.ToString().Trim());
                    cardModel.EndEffectiveDate   = ToDateTime(pExpire.ToString().Trim());
                    cardModel.State              = true;
                    //carddata.PhotoFileName = pBmpData.ToString();
                }
            }
            catch (Exception ex)
            {
                cardModel.ErrorMessage = ex.Message;
            }
            return(cardModel);
        }