/// <summary> /// 写卡片基本信息 /// </summary> /// <param name="p_intPort"></param> /// <param name="p_objCard"></param> /// <returns></returns> public static bool WriteCardInfo(int p_intPort, PaymentCard p_objCard) { bool lUserValid = p_objCard.Valid; string l_strCarNo = CardNoToHex(p_objCard.No, lUserValid); string l_strDate = p_objCard.ExpiryDate.Value.ToString("yyMMdd"); string l_strName = GetNameCode(p_objCard.Name); string l_strData = l_strCarNo + l_strDate + p_objCard.FunctionCode + l_strName; //string l_strMoneyLimit = EquipmentGeneral.IntToHex(int.Parse((p_objCard.LimitRemainder * 100).ToString()), 8); //string l_strMaxPayment = EquipmentGeneral.IntToHex(int.Parse((p_objCard.DailyMaxPayment * 100).ToString()), 8); string l_strMoneyLimit = EquipmentGeneral.IntToHex((int)(p_objCard.LimitRemainder * 100), 8); string l_strMaxPayment = EquipmentGeneral.IntToHex((int)(p_objCard.DailyMaxPayment * 100), 8); string l_strPaymentCount = EquipmentGeneral.IntToHex(p_objCard.Span1PaymentCount) + EquipmentGeneral.IntToHex(p_objCard.Span2PaymentCount) + EquipmentGeneral.IntToHex(p_objCard.Span3PaymentCount) + EquipmentGeneral.IntToHex(p_objCard.Span4PaymentCount); string l_strType = EquipmentGeneral.IntToHex(Convert.ToInt32(char.Parse(p_objCard.Type))); l_strData = l_strData + l_strMoneyLimit + p_objCard.PaymentPassword + l_strMaxPayment + l_strPaymentCount + l_strType; byte bSection = 0; WriteCard(p_intPort, EquipmentGeneral.GetCardSectionPieceList()[bSection][1].ToString(), 2, l_strData); bSection = 1; CleanCardMoney(p_intPort, EquipmentGeneral.GetCardSectionPieceList()[bSection][0]); AddCardMoney(p_intPort, EquipmentGeneral.GetCardSectionPieceList()[bSection][0], (int)(p_objCard.Money * 100)); bSection = 2; CleanCardMoney(p_intPort, EquipmentGeneral.GetCardSectionPieceList()[bSection][0]); AddCardMoney(p_intPort, EquipmentGeneral.GetCardSectionPieceList()[bSection][0], (int)(p_objCard.Subsidize * 100)); return(true); }
/// <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); }
public override bool WriteInitPosVal(decimal dMoney) { YuChuanDevice.rf_beep(_iBeepInterval); byte bSection; try { bSection = 4; Dictionary <byte, List <byte> > dicSect = EquipmentGeneral.GetCardSectionPieceList(); #region 写入初始消费金额数据 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); } byte[] arrData = YuChuanDevice.ChangeStrToHex(strPieceData); int iRes = YuChuanDevice.rf_write(dicSect[bSection][0], arrData); if (iRes != 0) { return(false); } #endregion #region 写入备份消费金额数据 if (!ReadCardsPrepare(bSection)) { return(false); } strPieceData = strCardVal + strComplement + strCardVal + this._strPosValCRC; if (strPieceData.Length != 32) { return(false); } arrData = YuChuanDevice.ChangeStrToHex(strPieceData); iRes = YuChuanDevice.rf_write(dicSect[bSection][1], arrData); if (iRes != 0) { return(false); } #endregion bSection = 5; #region 写入初始消费金额数据(备份扇区) if (!ReadCardsPrepare(bSection)) { return(false); } strPieceData = strCardVal + strComplement + strCardVal + this._strPosValBakCRC; if (strPieceData.Length != 32) { return(false); } arrData = YuChuanDevice.ChangeStrToHex(strPieceData); iRes = YuChuanDevice.rf_write(dicSect[bSection][0], arrData); if (iRes != 0) { return(false); } #endregion #region 写入备份消费金额数据(备份扇区) if (!ReadCardsPrepare(bSection)) { return(false); } strPieceData = strCardVal + strComplement + strCardVal + this._strPosValBakCRC; if (strPieceData.Length != 32) { return(false); } arrData = YuChuanDevice.ChangeStrToHex(strPieceData); iRes = YuChuanDevice.rf_write(dicSect[bSection][1], arrData); if (iRes != 0) { return(false); } #endregion bSection = 6; #region 写入消费记录初始数据(0号位置) if (!ReadCardsPrepare(bSection)) { return(false); } strPieceData = DateTime.Now.AddDays(-1).ToString("yyMMdd01"); strPieceData = strPieceData.PadLeft(24, '0').PadRight(32, '0'); if (strPieceData.Length != 32) { return(false); } arrData = YuChuanDevice.ChangeStrToHex(strPieceData); iRes = YuChuanDevice.rf_write(dicSect[bSection][0], arrData); if (iRes != 0) { return(false); } #endregion #region 写入消费记录初始数据(1号位置) if (!ReadCardsPrepare(bSection)) { return(false); } arrData = YuChuanDevice.ChangeStrToHex(strPieceData); iRes = YuChuanDevice.rf_write(dicSect[bSection][1], arrData); if (iRes != 0) { return(false); } #endregion #region 写入消费记录初始数据(2号位置) if (!ReadCardsPrepare(bSection)) { return(false); } string strPieceDataTmp = string.Empty.PadLeft(30, '0') + "AA"; arrData = YuChuanDevice.ChangeStrToHex(strPieceDataTmp); iRes = YuChuanDevice.rf_write(dicSect[bSection][2], arrData); if (iRes != 0) { return(false); } #endregion bSection = 7; #region 写入备份消费记录初始数据(0号位置) if (!ReadCardsPrepare(bSection)) { return(false); } if (strPieceData.Length != 32) { return(false); } arrData = YuChuanDevice.ChangeStrToHex(strPieceData); iRes = YuChuanDevice.rf_write(dicSect[bSection][0], arrData); if (iRes != 0) { return(false); } #endregion #region 写入备份消费记录初始数据(1号位置) if (!ReadCardsPrepare(bSection)) { return(false); } arrData = YuChuanDevice.ChangeStrToHex(strPieceData); iRes = YuChuanDevice.rf_write(dicSect[bSection][1], arrData); if (iRes != 0) { return(false); } #endregion #region 写入备份消费记录初始数据(2号位置) if (!ReadCardsPrepare(bSection)) { return(false); } arrData = YuChuanDevice.ChangeStrToHex(strPieceDataTmp); iRes = YuChuanDevice.rf_write(dicSect[bSection][2], arrData); if (iRes != 0) { return(false); } #endregion } catch (Exception ex) { throw ex; } YuChuanDevice.rf_beep(_iBeepInterval); return(true); }
public override bool RechargeSubsidize(decimal p_dMoney) { try { byte bSection = 2; 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 strPiece8 = YuChuanDevice.ChangeHexToString(arrData); if (strPiece8.Length != 32) { //读取块数据不完整,不足32位 return(false); } decimal dMoney = EquipmentGeneral.HexMoneyToDouble(strPiece8.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._strSubValCRC; 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 strPiece9 = YuChuanDevice.ChangeHexToString(arrData); if (strPiece9.Length != 32) { //读取块数据不完整,不足32位 return(false); } dMoney = EquipmentGeneral.HexMoneyToDouble(strPiece9.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._strSubValBakCRC; 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); }
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); }
public override bool WriteInitSubzVal(decimal dMoney) { Dictionary <byte, List <byte> > dicSect = EquipmentGeneral.GetCardSectionPieceList(); byte bSection = 2; YuChuanDevice.rf_beep(_iBeepInterval); try { #region 写入初始水控金额数据 if (!ReadCardsPrepare(bSection)) { return(false); } //水控金额 string strSubVal = EquipmentGeneral.IntToHex((int)(dMoney * 100), 8).PadRight(8, '0'); strSubVal = strSubVal.Substring(6, 2) + strSubVal.Substring(4, 2) + strSubVal.Substring(2, 2) + strSubVal.Substring(0, 2); //水控金额反码 string strSubComplement = EquipmentGeneral.GetComplement(strSubVal); string strPieceData = strSubVal + strSubComplement + strSubVal + this._strSubValCRC; if (strPieceData.Length != 32) { return(false); } byte[] arrData = YuChuanDevice.ChangeStrToHex(strPieceData); int iRes = YuChuanDevice.rf_write(dicSect[bSection][0], arrData); if (iRes != 0) { return(false); } #endregion #region 写入备份水控金额数据 if (!ReadCardsPrepare(bSection)) { return(false); } strPieceData = strSubVal + strSubComplement + strSubVal + this._strSubValBakCRC; if (strPieceData.Length != 32) { return(false); } arrData = YuChuanDevice.ChangeStrToHex(strPieceData); iRes = YuChuanDevice.rf_write(dicSect[bSection][1], arrData); if (iRes != 0) { return(false); } #endregion } catch (Exception ex) { throw ex; } YuChuanDevice.rf_beep(_iBeepInterval); return(true); }