Esempio n. 1
0
        /// <summary>
        /// 写入卡片基本信息
        /// </summary>
        /// <param name="iCom"></param>
        /// <param name="iSection"></param>
        /// <param name="payCard"></param>
        /// <returns></returns>
        public static bool WriteCardBasicInfo(int iCom, byte bSection, PaymentCard payCard)
        {
            bool res = false;

            try
            {
                Dictionary <byte, List <byte> > dicSection = EquipmentGeneral.GetCardSectionPieceList();
                bool   bValid     = payCard.Valid;
                string l_strCarNo = CardNoToHex(payCard.No, bValid);
                string l_strDate  = payCard.ExpiryDate.Value.ToString("yyMMdd");
                string l_strName  = GetNameCode(payCard.Name);

                //功能
                string strFunc = string.Empty;
                if (payCard.FunctionCode.Length == 16)
                {
                    strFunc = EquipmentGeneral.BinToHex(payCard.FunctionCode).PadLeft(4, '0');
                }
                else if (payCard.FunctionCode.Length == 4)
                {
                    strFunc = payCard.FunctionCode;
                }
                else
                {
                    strFunc = string.Empty.PadRight(4, '0');
                }

                string l_strData = l_strCarNo + l_strDate + strFunc + l_strName;

                string l_strMoneyLimit   = EquipmentGeneral.IntToHex(int.Parse(((int)(payCard.LimitRemainder * 100)).ToString()), 8);
                string l_strMaxPayment   = EquipmentGeneral.IntToHex(int.Parse(((int)(payCard.DailyMaxPayment * 100)).ToString()), 8);
                string l_strPaymentCount = EquipmentGeneral.IntToHex(payCard.Span1PaymentCount) + EquipmentGeneral.IntToHex(payCard.Span2PaymentCount) + EquipmentGeneral.IntToHex(payCard.Span3PaymentCount) + EquipmentGeneral.IntToHex(payCard.Span4PaymentCount);
                string l_strType         = EquipmentGeneral.IntToHex(Convert.ToInt32(char.Parse(payCard.Type)));

                l_strData = l_strData + l_strMoneyLimit + payCard.PaymentPassword + l_strMaxPayment + l_strPaymentCount + l_strType;

                res = WriteCard(iCom, dicSection[bSection][1].ToString(), 2, l_strData);
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return(res);
        }
Esempio n. 2
0
        public override bool WriteInitUserBasicInfo(PaymentCard payCard)
        {
            YuChuanDevice.rf_beep(_iBeepInterval);
            byte bSection = 3;

            try
            {
                Dictionary <byte, List <byte> > dicSection = EquipmentGeneral.GetCardSectionPieceList();
                string strPieceData = string.Empty;

                #region 初始化第1块信息数据

                if (!ReadCardsPrepare(bSection))
                {
                    return(false);
                }

                //卡号
                string strCardNo = EquipmentGeneral.IntToHex(payCard.No, 4);
                strCardNo = strCardNo.Substring(2, 2) + strCardNo.Substring(0, 2);
                //状态值
                string strState = payCard.Valid ? "80" : "00";
                //注销时间
                string strRegDate = payCard.ExpiryDate.Value.ToString("yyMMdd");
                //功能
                string strFunc = string.Empty;
                if (payCard.FunctionCode.Length == 16)
                {
                    strFunc = EquipmentGeneral.BinToHex(payCard.FunctionCode).PadLeft(4, '0');
                }
                else if (payCard.FunctionCode.Length == 4)
                {
                    strFunc = payCard.FunctionCode;
                }
                else
                {
                    strFunc = string.Empty.PadRight(4, '0');
                }

                //姓名
                string strName = EquipmentGeneral.StrToHex(payCard.Name).PadRight(16, '0');

                strPieceData = strCardNo + strState + strRegDate + strFunc + strName;
                if (strPieceData.Length != 32)
                {
                    return(false);
                }

                byte[] arrData = YuChuanDevice.ChangeStrToHex(strPieceData);
                int    iRes    = YuChuanDevice.rf_write(dicSection[bSection][1], arrData);
                if (iRes != 0)
                {
                    return(false);
                }

                #endregion

                #region 初始化第2块信息数据

                if (!ReadCardsPrepare(bSection))
                {
                    return(false);
                }

                //卡内最低余额
                string strMinVal = EquipmentGeneral.IntToHex((int)(payCard.LimitRemainder * 100), 8);
                //每日最大消费额
                string strMaxPosVal = EquipmentGeneral.IntToHex((int)(payCard.DailyMaxPayment * 100), 8);
                //时段限次消费次数
                string strIntervalCount = EquipmentGeneral.IntToHex(payCard.Span1PaymentCount, 2) + EquipmentGeneral.IntToHex(payCard.Span2PaymentCount, 2) + EquipmentGeneral.IntToHex(payCard.Span3PaymentCount, 2) + EquipmentGeneral.IntToHex(payCard.Span4PaymentCount, 2);
                //卡片类型
                string strType = EquipmentGeneral.IntToHex(Convert.ToInt32(char.Parse(payCard.Type)), 2);

                strPieceData = strMinVal + payCard.PaymentPassword + strMaxPosVal + strIntervalCount + strType;
                if (strPieceData.Length != 32)
                {
                    return(false);
                }

                arrData = YuChuanDevice.ChangeStrToHex(strPieceData);
                iRes    = YuChuanDevice.rf_write(dicSection[bSection][2], arrData);
                if (iRes != 0)
                {
                    return(false);
                }

                #endregion
            }
            catch (Exception ex)
            {
                throw ex;
            }

            YuChuanDevice.rf_beep(_iBeepInterval);
            return(true);
        }