Example #1
0
        public override bool RechargeMoney(decimal p_dMoney)
        {
            try
            {
                byte bSection = 1;
                Dictionary <byte, List <byte> > dicSection = EquipmentGeneral.GetCardSectionPieceList();

                #region 读第1块

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

                byte[] arrData  = new byte[16];
                int    iResRead = YuChuanDevice.rf_read(dicSection[bSection][0], arrData);
                if (iResRead != 0)
                {
                    //读数失败
                    return(false);
                }
                string strPiece4 = YuChuanDevice.ChangeHexToString(arrData);
                if (strPiece4.Length != 32)
                {
                    //读取块数据不完整,不足32位
                    return(false);
                }
                decimal dMoney = EquipmentGeneral.HexMoneyToDouble(strPiece4.Substring(0, 8));

                #endregion

                dMoney = dMoney + p_dMoney;

                #region 写入第1块数据

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

                //卡内金额
                string strCardVal = EquipmentGeneral.IntToHex((int)(dMoney * 100), 8).PadRight(8, '0');
                strCardVal = strCardVal.Substring(6, 2) + strCardVal.Substring(4, 2) + strCardVal.Substring(2, 2) + strCardVal.Substring(0, 2);

                //卡内金额反码
                string strComplement = EquipmentGeneral.GetComplement(strCardVal);

                string strPieceData = strCardVal + strComplement + strCardVal + this._strPosValCRC;
                if (strPieceData.Length != 32)
                {
                    return(false);
                }

                arrData = YuChuanDevice.ChangeStrToHex(strPieceData);
                int iRes = YuChuanDevice.rf_write(dicSection[bSection][0], arrData);
                if (iRes == 0)
                {
                    YuChuanDevice.rf_beep(_iBeepInterval);
                }
                else
                {
                    return(false);
                }

                #endregion

                #region 读第2块

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

                arrData  = new byte[16];
                iResRead = YuChuanDevice.rf_read(dicSection[bSection][1], arrData);
                if (iResRead != 0)
                {
                    //读数失败
                    return(false);
                }
                string strPiece5 = YuChuanDevice.ChangeHexToString(arrData);
                if (strPiece5.Length != 32)
                {
                    //读取块数据不完整,不足32位
                    return(false);
                }
                dMoney = EquipmentGeneral.HexMoneyToDouble(strPiece5.Substring(0, 8));

                #endregion

                dMoney = dMoney + p_dMoney;

                #region 写入第2块数据

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

                //备份金额
                string strCardBakVal = EquipmentGeneral.IntToHex((int)(dMoney * 100), 8).PadRight(8, '0');
                strCardBakVal = strCardBakVal.Substring(6, 2) + strCardBakVal.Substring(4, 2) + strCardBakVal.Substring(2, 2) + strCardBakVal.Substring(0, 2);

                //卡内金额反码
                string strBakComplement = EquipmentGeneral.GetComplement(strCardBakVal);

                strPieceData = strCardBakVal + strBakComplement + strCardBakVal + this._strPosValBakCRC;
                if (strPieceData.Length != 32)
                {
                    return(false);
                }

                arrData = YuChuanDevice.ChangeStrToHex(strPieceData);
                iRes    = YuChuanDevice.rf_write(dicSection[bSection][1], arrData);
                if (iRes == 0)
                {
                    YuChuanDevice.rf_beep(_iBeepInterval);
                }
                else
                {
                    return(false);
                }

                #endregion
            }
            catch (Exception ex)
            {
                return(false);
            }

            return(true);
        }