Beispiel #1
0
 public static Status UserDecrypt(int nKeyID, byte[] pData, int nDataLen, byte[] pDecryptedData)
 {
     if (!IsUse)
     {
         return(Status.ESAM_SUCC);
     }
     try
     {
         System.Threading.Thread.Sleep(200);
         Status ret = Status.ESAM_SUCC;
         ret = (Status)ESAM_UserDecrypt(nKeyID, pData, nDataLen, pDecryptedData);
         //ret = (Status)ESAM_Decrypt(pData, nDataLen, pDecryptedData);
         if (ret != Status.ESAM_SUCC)
         {
             AppLog.Write("[Esam][UserDecrypt]" + ret.ToString(), AppLog.LogMessageType.Warn);
         }
         return(ret);
     }
     catch (Exception err)
     {
         AppLog.Write("[Esam][UserDecrypt]Error!\n" + err.ToString(), AppLog.LogMessageType.Error);
         return(Status.ESAM_FAIL);
     }
 }
Beispiel #2
0
 /// <summary>
 /// 读取此道信息
 /// </summary>
 /// <param name="track1"></param>
 /// <param name="track2"></param>
 /// <param name="track3"></param>
 /// <returns></returns>
 public static Status ReadCardTrack(ref string track1, ref string track2, ref string track3)
 {
     if (!IsUse)
     {
         return(Status.CARD_SUCC);
     }
     try
     {
         CardPos    cardPos = CardPos.CardOnErrorPos;
         BoxCardNum boxNum  = BoxCardNum.Null;
         Status     ret     = (Status)GetStatus(ref cardPos, ref boxNum);
         if (ret == Status.CARD_SUCC && cardPos == CardPos.CardOnTrackReadPos)
         {
             byte[] bTrack1 = new byte[128];
             byte[] bTrack2 = new byte[128];
             byte[] bTrack3 = new byte[128];
             ret = (Status)Card_ReadAll(bTrack1, bTrack2, bTrack3);
             if (ret == Status.CARD_SUCC)
             {
                 track1 = Encoding.Default.GetString(bTrack1).Trim();
                 track2 = Encoding.Default.GetString(bTrack2).Trim();
                 track3 = Encoding.Default.GetString(bTrack3).Trim();
             }
         }
         else
         {
             ret = Status.CARD_FAIL;
         }
         return(ret);
     }
     catch (System.Exception e)
     {
         AppLog.Write("[CardIssuer][ReadCardTrack]Error!", AppLog.LogMessageType.Error, e);
         return(Status.CARD_FAIL);
     }
 }
Beispiel #3
0
        public bool ReadICCard(ref string bmpfileName)
        {
            bool bUsbPort = false;
            //int intOpenPortRtn = 0;
            int rtnTemp     = 0;
            int pucIIN      = 0;
            int pucSN       = 0;
            int puiCHMsgLen = 0;
            int puiPHMsgLen = 0;


            objEDZ     = new clsEDZ();
            EdziPortID = int.Parse(Identifier.Port.Substring(3));
            ////检测usb口的机具连接,必须先检测usb
            //for (int iPort = 1001; iPort <= 1016; iPort++)
            //{
            //    intOpenPortRtn = SDT_OpenPort(iPort);
            //    if (intOpenPortRtn == 144)
            //    {
            //        EdziPortID = iPort;
            //        bUsbPort = true;
            //        break;
            //    }
            //}
            ////检测串口的机具连接
            //if (!bUsbPort)
            //{
            //    for (int iPort = 1; iPort <= 8; iPort++)
            //    {
            //        intOpenPortRtn = SDT_OpenPort(iPort);
            //        if (intOpenPortRtn == 144)
            //        {
            //            EdziPortID = iPort;
            //            bUsbPort = false;
            //            break;
            //        }
            //    }
            //}
            //if (intOpenPortRtn != 144)
            //{
            //    throw new Exception("端口打开失败,请检测相应的端口或者重新连接读卡器!");
            //    return false;
            //}
            //在这里,如果您想下一次不用再耗费检查端口的检查的过程,您可以把 EdziPortID 保存下来,可以保存在注册表中,也可以保存在配置文件中,我就不多写了,但是,
            //您要考虑机具连接端口被用户改变的情况哦

            //下面找卡
            rtnTemp = SDT_StartFindIDCard(EdziPortID, ref pucIIN, EdziIfOpen);
            if (rtnTemp != 159)
            {
                rtnTemp = SDT_StartFindIDCard(EdziPortID, ref pucIIN, EdziIfOpen);  //再找卡
                if (rtnTemp != 159)
                {
                    //AppLog.Write("未放卡或者卡未放好,请重新放卡!", AppLog.LogMessageType.Error);
                    //rtnTemp = SDT_ClosePort(EdziPortID);
                    //throw new Exception("未放卡或者卡未放好,请重新放卡!");
                    return(false);
                }
            }
            //选卡
            rtnTemp = SDT_SelectIDCard(EdziPortID, ref pucSN, EdziIfOpen);
            if (rtnTemp != 144)
            {
                rtnTemp = SDT_SelectIDCard(EdziPortID, ref pucSN, EdziIfOpen);  //再选卡
                if (rtnTemp != 144)
                {
                    AppLog.Write("读卡失败!", AppLog.LogMessageType.Error);
                    //rtnTemp = SDT_ClosePort(EdziPortID);
                    //throw new Exception("读卡失败!");
                    return(false);
                }
            }
            //注意,在这里,用户必须有应用程序当前目录的读写权限
            if (!Directory.Exists("IDCardInfo"))
            {
                Directory.CreateDirectory("IDCardInfo");
            }
            string FilePreName = DateTime.Now.ToString("MMddHHmmss");
            string txtName     = Path.Combine("IDCardInfo", FilePreName + ".txt");
            string wltName     = Path.Combine("IDCardInfo", FilePreName + ".wlt");
            string bmpName     = Path.Combine("IDCardInfo", FilePreName + ".bmp");

            bmpfileName = "IDCardInfo/" + FilePreName + ".bmp";
            //FileInfo objFile = new FileInfo("wz.txt");
            //if (objFile.Exists)
            //{
            //    objFile.Attributes = FileAttributes.Normal;
            //    objFile.Delete();
            //}
            //if (objFile.Exists)
            //{
            //    AppLog.Write("Delete \"wz.txt\" Failed!", AppLog.LogMessageType.Warn);
            //    return false;
            //}
            //objFile = new FileInfo("zp.bmp");
            //if (objFile.Exists)
            //{
            //    objFile.Attributes = FileAttributes.Normal;
            //    objFile.Delete();
            //}
            //if (objFile.Exists)
            //{
            //    AppLog.Write("Delete \"zp.bmp\" Failed!", AppLog.LogMessageType.Warn);
            //    return false;
            //}
            //objFile = new FileInfo("zp.wlt");
            //if (objFile.Exists)
            //{
            //    objFile.Attributes = FileAttributes.Normal;
            //    objFile.Delete();
            //}
            //if (objFile.Exists)
            //{
            //    AppLog.Write("Delete \"zp.wlt\" Failed!", AppLog.LogMessageType.Warn);
            //    return false;
            //}
            rtnTemp = SDT_ReadBaseMsgToFile(EdziPortID, txtName, ref puiCHMsgLen, wltName, ref puiPHMsgLen, EdziIfOpen);
            //rtnTemp = SDT_ReadBaseMsgToFile(EdziPortID, "wz.txt", ref puiCHMsgLen, "zp.wlt", ref puiPHMsgLen, EdziIfOpen);
            //rtnTemp = SDT_ReadBaseMsg(EdziPortID, "wz.txt", ref puiCHMsgLen, "zp.wlt", ref puiPHMsgLen, EdziIfOpen);
            if (rtnTemp != 144)
            {
                AppLog.Write("读卡失败!", AppLog.LogMessageType.Error);
                //rtnTemp = SDT_ClosePort(EdziPortID);
                //throw new Exception("读卡失败!");
                return(false);
            }
            //下面解析照片,注意,如果在C盘根目录下没有机具厂商的授权文件Termb.Lic,照片解析将会失败
            if (bUsbPort)
            {
                rtnTemp = GetBmp(wltName, 2);
            }
            //rtnTemp = GetBmp("zp.wlt", 2);
            else
            {
                rtnTemp = GetBmp(wltName, 1);
            }
            //rtnTemp = GetBmp("zp.wlt", 1);
            switch (rtnTemp)
            {
            case 0:
                //MessageBox.Show("调用sdtapi.dll错误!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
                AppLog.Write("调用sdtapi.dll错误!", AppLog.LogMessageType.Error);
                return(false);

            //throw new Exception("调用sdtapi.dll错误!");
            //break;
            case 1:       //正常
                break;

            case -1:
                //MessageBox.Show("相片解码错误!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
                AppLog.Write("相片解码错误!", AppLog.LogMessageType.Error);
                return(false);

            //throw new Exception("相片解码错误!");
            //break;
            case -2:
                //MessageBox.Show("wlt文件后缀错误!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
                AppLog.Write("wlt文件后缀错误!", AppLog.LogMessageType.Error);
                return(false);

            //throw new Exception("wlt文件后缀错误!");
            //break;
            case -3:
                //MessageBox.Show("wlt文件打开错误!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
                AppLog.Write("wlt文件打开错误!", AppLog.LogMessageType.Error);
                return(false);

            //throw new Exception("wlt文件打开错误!");
            //break;
            case -4:
                //MessageBox.Show("wlt文件格式错误!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
                AppLog.Write("wlt文件格式错误!", AppLog.LogMessageType.Error);
                return(false);

            //throw new Exception("wlt文件格式错误!");
            //break;
            case -5:
                //MessageBox.Show("软件未授权!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
                AppLog.Write("软件未授权!", AppLog.LogMessageType.Error);
                return(false);

            //throw new Exception("软件未授权!");
            //break;
            case -6:
                //MessageBox.Show("设备连接错误!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
                AppLog.Write("设备连接错误!", AppLog.LogMessageType.Error);
                return(false);
                //throw new Exception("设备连接错误!");
                //break;
            }
            //rtnTemp = SDT_ClosePort(EdziPortID);
            FileInfo   f  = new FileInfo(txtName);
            FileStream fs = f.OpenRead();

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

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

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

            objEDZ.BIRTH   = Convert.ToDateTime(strBird.Substring(0, 4) + "年" + strBird.Substring(4, 2) + "月" + strBird.Substring(6) + "日");
            objEDZ.ADDRESS = System.Text.UnicodeEncoding.Unicode.GetString(bt, 52, 70).Trim();
            objEDZ.IDC     = System.Text.UnicodeEncoding.Unicode.GetString(bt, 122, 36).Trim();
            objEDZ.REGORG  = System.Text.UnicodeEncoding.Unicode.GetString(bt, 158, 30).Trim();
            string strTem = System.Text.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;
            }
            File.Delete(txtName);
            if (File.Exists(txtName))
            {
                AppLog.Write("删除" + txtName + "文件失败!", AppLog.LogMessageType.Error);
            }

            //FileInfo objFile = new FileInfo(bmpName);
            //if (!objFile.Exists)
            //{
            //    AppLog.Write("照片解析失败,找不到照片文件!", AppLog.LogMessageType.Error);
            //    return false;
            //}
            //if (objFile.Exists)
            //{

            //    FileStream fss = new FileStream("zp.bmp", FileMode.Open);
            //    byte[] imgbyte = new byte[(int)objFile.Length];
            //    fss.Read(imgbyte, 0, (int)objFile.Length);
            //    fss.Close();
            //    MemoryStream ms = new MemoryStream(imgbyte);
            //    Image img = Image.FromStream(ms);
            //    objEDZ.PIC_Image = (Image)img.Clone();
            //    objEDZ.PIC_Byte = imgbyte;
            //    img.Dispose();
            //    ms.Dispose();
            //}

            //ReadICCardComplete(objEDZ);
            return(true);
        }
Beispiel #4
0
        /// <summary>
        /// 无限循环等待接收纸币
        /// </summary>
        /// <param name="cType">允许接收纸币范围指令</param>
        /// <param name="retValue">返回的结果</param>
        /// <returns></returns>
        public static Status CashPoll(ref PollRet retValue)
        {
            if (!IsUse)
            {
                return(Status.Success);
            }
            try
            {
                int iRet = EA_CASHCODE_Poll();
                EA_CASHCODE_ACK();
                switch (iRet)
                {
                case 1:
                    retValue = PollRet.One;
                    return(Status.Success);

                case 2:
                    retValue = PollRet.Two;
                    return(Status.Success);

                case 5:
                    retValue = PollRet.Five;
                    return(Status.Success);

                case 10:
                    retValue = PollRet.Ten;
                    return(Status.Success);

                case 20:
                    retValue = PollRet.Twenty;
                    return(Status.Success);

                case 50:
                    retValue = PollRet.Fifty;
                    return(Status.Success);

                case 100:
                    retValue = PollRet.Hundred;
                    return(Status.Success);

                case 0:
                    retValue = PollRet.InspectionFail;
                    return(Status.Failed);

                case -1:
                    retValue = PollRet.HappenError;
                    return(Status.Failed);

                case -3:
                    retValue = PollRet.IgnoreRet;
                    return(Status.Failed);

                default:
                    retValue = PollRet.InspectionFail;
                    return(Status.Failed);
                }
            }
            catch (System.Exception e)
            {
                AppLog.Write("[CashReset][CashPoll]Error!\n" + e.ToString(), AppLog.LogMessageType.Error);
                return(Status.Failed);
            }
        }