private void writeBlock(int cbShanQu, int kuai, string value)
 {
     int p = RFIDClass.WriterCardAndReturnStatus(this.lblNum.Text, CurrentUser.Current.PassWordKey, cbShanQu, kuai, HelperClass.EncryptByString(value));
 }
        /// <summary>
        /// 执行卡重置
        /// </summary>
        /// <param name="theCardTypeInfo">实体层对象</param>
        /// <param name="key">密码</param>
        /// <returns>0所有操作成功,1网络连接不成功,99是远程服务器方法存储失败,其他状态</returns>
        public int ResetCarInforAndCarHistoryByID(CardInfo _cardInfo, string key)
        {
            try
            {
                int cSector = 1; //保存要操作的扇区下标
                //先执行密码修改
                string[] mary = RFIDClass.UpdateCardPassWordAndReturnStatus(_cardInfo.card_id, cSector, key);
                if (mary[0] != "0") //修改密码错误就直接返回错误状态
                {
                    return(Convert.ToInt32(mary[0]));
                }
                else //成功继续往下走
                {
                    //先读卡
                    string[] mary1 = ConvertToBytes(RFIDClass.ReadCardAndReturnStatus(key, cSector));
                    //保存一份副本
                    string[] maryback = new string[3];
                    for (int i = 1; i < mary1.Length - 1; i++)
                    {
                        maryback[i - 1] = mary1[i];
                    }

                    //传入默认密码,执行初始化写入第一扇区
                    RFIDClass.WriterCardAndReturnStatus(_cardInfo.card_id, "", cSector, 0, "");
                    RFIDClass.WriterCardAndReturnStatus(_cardInfo.card_id, "", cSector, 1, "");
                    int p = RFIDClass.WriterCardAndReturnStatus(_cardInfo.card_id, "", cSector, 2, "");
                    if (p != 0) //如果出现异常就执行返回
                    {
                        return(p);
                    }
                    else //如果初始化卡成功,则执行下一步数据库录入
                    {
                        Dictionary <string, object> arr = new Dictionary <string, object>();
                        arr["ICode"]       = "ITSP2_RFID_CS_ResetCarInforAndCarHistory";
                        arr["IVer"]        = "1.0.0.1";
                        arr["card_id"]     = _cardInfo.card_id;
                        arr["no"]          = _cardInfo.no;
                        arr["modify_user"] = _cardInfo.modify_user;


                        DataTable table     = ConvertMethod.getDateTable("msgTable", arr);
                        string    Parameter = ConvertMethod.CDataToXml(table);

                        //加密xml进行返回
                        Parameter = HelperClass.EncryptDESByKey8(Parameter);
                        string resoue = _objICardInfoDAL.ResetCarInforAndCarHistoryByID(Parameter);


                        //先解密成xml格式
                        string str = HelperClass.DecryptDESByKey8(resoue);
                        //把字符串转换成表对象
                        DataSet parameterTable = ConvertMethod.CXmlToDataSet(str);
                        if (parameterTable.Tables[0].Rows[0]["msgCode"].ToString() == "卡重置成功!")
                        {
                            return(0); //未实现,默认全部成功
                        }
                        else
                        {
                            //否则就是失败,需要执行还原
                            RFIDClass.WriterCardAndReturnStatus(_cardInfo.card_id, "", cSector, 0, HelperClass.EncryptByString(maryback[0]));
                            RFIDClass.WriterCardAndReturnStatus(_cardInfo.card_id, "", cSector, 1, HelperClass.EncryptByString(maryback[1]));
                            RFIDClass.WriterCardAndReturnStatus(_cardInfo.card_id, "", cSector, 2, HelperClass.EncryptByString(maryback[2]));
                            RFIDClass.UpdateCardPassWordAndReturnStatus(_cardInfo.card_id, cSector, "", key); //修改密码
                            return(99);
                        }
                    }
                    //结束
                }
            }
            catch (Exception ex)
            {
                Bouwa.Helper.Class.Log.WriterLine(Bouwa.Helper.Class.ELevel.error, "方法名:ResetCarInforAndCarHistoryByID(CardInfo _cardInfo, string key),卡信息BLL层对数据操作时出现异常!", ex.Message);
                return(1);
            }
        }
        /// <summary>
        /// 执行退卡操作并写入卡历史表
        /// </summary>
        /// <param name="theCardTypeInfo">实体层对象</param>
        /// <param name="key">密码</param>
        /// <param name="isAdd">判断是否需要写入数据库</param>
        /// <returns>0所有操作成功,1网络连接不成功,99是远程服务器方法存储失败,其他状态</returns>
        public int UpdateCarInfoAndBackCardHistoryRecord(CardInfo _cardInfo, string key, bool isAdd)
        {
            try
            {
                Dictionary <string, object> arr = new Dictionary <string, object>();
                //先读卡
                string[] mary1 = ConvertToBytes(RFIDClass.ReadCardAndReturnStatus(key, 1));
                //先进行写卡
                int p = -1;
                //先修改卡内状态,退卡状态为 3
                p = RFIDClass.WriterCardAndReturnStatus(_cardInfo.card_id, key, 1, 1, HelperClass.EncryptByString(mary1[2].Substring(0, 13) + ((int)_cardInfo.status) + mary1[2].Substring(14)));
                //修改最后操作时间为当前时间
                p = RFIDClass.WriterCardAndReturnStatus(_cardInfo.card_id, key, 1, 2, HelperClass.EncryptByString(DateTime.Now.ToString("yyyyMMddHHmmss") + mary1[3].Substring(12)));
                //获得对应写入后台的文字描述
                if (_cardInfo.cost_type == CardInfo.CardTypeInfoCostType.金额卡)
                {
                    arr["volume"] = "-" + Convert.ToDecimal(_cardInfo.money).ToString("0.000").Substring(0, Convert.ToDecimal(_cardInfo.money).ToString("0.000").Length - 2); //量
                }
                else if (_cardInfo.cost_type == CardInfo.CardTypeInfoCostType.限次卡)
                {
                    arr["volume"] = "-" + _cardInfo.times; //量
                }
                else if (_cardInfo.cost_type == CardInfo.CardTypeInfoCostType.限期卡)
                {
                    arr["volume"] = _cardInfo.end_date.ToString("yyyyMMdd"); //量
                }
                else if (_cardInfo.cost_type == CardInfo.CardTypeInfoCostType.限时卡)
                {
                    int g = _cardInfo.charges_date / 60 * 10 + _cardInfo.charges_date % 60 / 10;
                    arr["volume"] = "-" + g; //量
                }
                if (isAdd)
                {
                    //判断写卡是否成功
                    if (p != 0)
                    {
                        return(p);
                    }
                    else
                    {
                        //执行数据库存放
                        arr["ICode"]          = "ITSP2_RFID_CS_UpdateCarInfoAndBackCardHistory";
                        arr["IVer"]           = "1.0.0.1";
                        arr["saas_id"]        = _cardInfo.saas_id;
                        arr["operation_type"] = "2"; //退卡
                        arr["card_id"]        = _cardInfo.id;
                        arr["no"]             = _cardInfo.no;
                        arr["address_type"]   = "1";
                        arr["network_id"]     = _cardInfo.Network_id;
                        arr["operation_memo"] = "退卡操作成功"; //操作事项
                        arr["operation_user"] = _cardInfo.modify_user;



                        DataTable table     = ConvertMethod.getDateTable("msgTable", arr);
                        string    Parameter = ConvertMethod.CDataToXml(table);

                        //加密xml进行返回
                        Parameter = HelperClass.EncryptDESByKey8(Parameter);
                        string resoue = _objICardInfoDAL.UpdateCarInfoAndBackCardHistoryRecord(Parameter);


                        //先解密成xml格式
                        string str = HelperClass.DecryptDESByKey8(resoue);
                        //把字符串转换成表对象
                        DataSet parameterTable = ConvertMethod.CXmlToDataSet(str);
                        if (parameterTable.Tables[0].Rows[0]["msgCode"].ToString() == "退卡操作成功!")
                        {
                            return(0); //未实现,默认全部成功
                        }
                        else
                        {
                            return(99);
                        }
                    }
                }
                else
                { //否则就是更改值,不进行数据库的存储
                    return(0);
                }
            }
            catch (Exception ex)
            {
                Bouwa.Helper.Class.Log.WriterLine(Bouwa.Helper.Class.ELevel.error, "方法名:UpdateCarInfoAndBackCardHistoryRecord(CardInfo _cardInfo, string key),卡信息BLL层对数据操作时出现异常!", ex.Message);
                return(1);
            }
        }
        /// <summary>
        /// 执行充值
        /// </summary>
        /// <param name="theCardTypeInfo">实体层对象</param>
        /// <param name="key">密码</param>
        /// <param name="value">充值的数目</param>
        /// <param name="isAdd">判断是否需要写入数据库</param>
        /// <returns>0所有操作成功,1网络连接不成功,99是远程服务器方法存储失败,其他状态</returns>
        public int Update(CardInfo _cardInfo, string key, string value, bool isAdd)
        {
            try
            {
                Dictionary <string, object> arr = new Dictionary <string, object>();
                //先读卡
                string[] mary1      = ConvertToBytes(RFIDClass.ReadCardAndReturnStatus(key, 1));
                string   inputValue = string.Empty;
                //先进行写卡
                int p = -1;
                if (_cardInfo.cost_type == CardInfo.CardTypeInfoCostType.金额卡)
                {
                    //获得要写入的值
                    inputValue = mary1[1].Substring(0, 4) + ConvertToStringByInt32(_cardInfo.money.ToString("0.000").Substring(0, _cardInfo.money.ToString("0.000").Length - 2).Replace(".", "")) + mary1[1].Substring(9);
                    p          = RFIDClass.WriterCardAndReturnStatus(_cardInfo.card_id, key, 1, 0, HelperClass.EncryptByString(inputValue));
                    //修改状态
                    p             = RFIDClass.WriterCardAndReturnStatus(_cardInfo.card_id, key, 1, 1, HelperClass.EncryptByString(mary1[2].Substring(0, 13) + "2" + mary1[2].Substring(14)));
                    arr["volume"] = Convert.ToDecimal(value).ToString("0.000").Substring(0, Convert.ToDecimal(value).ToString("0.000").Length - 2); //量
                    inputValue    = "充值" + Convert.ToDecimal(value).ToString("0.000").Substring(0, Convert.ToDecimal(value).ToString("0.000").Length - 2) + "0元";
                }
                else if (_cardInfo.cost_type == CardInfo.CardTypeInfoCostType.限次卡)
                {
                    //获得要写入的值
                    inputValue = mary1[1].Substring(0, 4) + ConvertToStringByInt32(_cardInfo.times.ToString()) + mary1[1].Substring(9);
                    p          = RFIDClass.WriterCardAndReturnStatus(_cardInfo.card_id, key, 1, 0, HelperClass.EncryptByString(inputValue));
                    //修改状态
                    p             = RFIDClass.WriterCardAndReturnStatus(_cardInfo.card_id, key, 1, 1, HelperClass.EncryptByString(mary1[2].Substring(0, 13) + "2" + mary1[2].Substring(14)));
                    arr["volume"] = value; //量
                    inputValue    = "增加" + value.ToString() + "次";
                }
                else if (_cardInfo.cost_type == CardInfo.CardTypeInfoCostType.限期卡)
                {
                    //获得要写入的值
                    inputValue    = mary1[2].Substring(0, 6) + _cardInfo.end_date.ToString("yyyyMMdd").Substring(2) + mary1[2].Substring(12, 1) + "2" + mary1[2].Substring(14);
                    p             = RFIDClass.WriterCardAndReturnStatus(_cardInfo.card_id, key, 1, 1, HelperClass.EncryptByString(inputValue)); //修改对应的最晚到期时间
                    arr["volume"] = _cardInfo.end_date.ToString("yyyyMMdd");                                                                    //量
                    inputValue    = "更新到期时间为" + _cardInfo.end_date.ToString("yyyy-MM-dd");
                }
                else if (_cardInfo.cost_type == CardInfo.CardTypeInfoCostType.限时卡)
                {
                    int g = _cardInfo.charges_date / 60 * 10 + _cardInfo.charges_date % 60 / 10;
                    //获得要写入的值
                    inputValue = mary1[1].Substring(0, 4) + ConvertToStringByInt32(g.ToString()) + mary1[1].Substring(9);
                    p          = RFIDClass.WriterCardAndReturnStatus(_cardInfo.card_id, key, 1, 0, HelperClass.EncryptByString(inputValue));

                    //修改状态
                    p             = RFIDClass.WriterCardAndReturnStatus(_cardInfo.card_id, key, 1, 1, HelperClass.EncryptByString(mary1[2].Substring(0, 13) + "2" + mary1[2].Substring(14)));
                    arr["volume"] = value; //量
                    inputValue    = "充值" + value.ToString() + "分钟";
                }
                if (isAdd)
                {
                    //判断写卡是否成功
                    if (p != 0)
                    {
                        return(p);
                    }
                    else
                    {
                        //执行数据库存放
                        arr["ICode"]          = "ITSP2_RFID_CS_CarHistoryInsert";
                        arr["IVer"]           = "1.0.0.1";
                        arr["saas_id"]        = _cardInfo.saas_id;
                        arr["operation_type"] = "5"; //充值
                        arr["card_id"]        = _cardInfo.id;
                        arr["no"]             = _cardInfo.no;
                        arr["address_type"]   = "1";
                        arr["network_id"]     = _cardInfo.Network_id;
                        arr["operation_memo"] = inputValue;               //操作事项
                        arr["operation_user"] = _cardInfo.modify_user;
                        arr["card_cost_type"] = (int)_cardInfo.cost_type; //当前充值卡的扣费类型


                        DataTable table     = ConvertMethod.getDateTable("msgTable", arr);
                        string    Parameter = ConvertMethod.CDataToXml(table);

                        //加密xml进行返回
                        Parameter = HelperClass.EncryptDESByKey8(Parameter);
                        string resoue = _objICardInfoDAL.InsertCarInformationHistoryRecord(Parameter);


                        //先解密成xml格式
                        string str = HelperClass.DecryptDESByKey8(resoue);
                        //把字符串转换成表对象
                        DataSet parameterTable = ConvertMethod.CXmlToDataSet(str);
                        if (parameterTable.Tables[0].Rows[0]["msgCode"].ToString() == "充值数据成功!")
                        {
                            return(0); //未实现,默认全部成功
                        }
                        else
                        {
                            return(99);
                        }
                    }
                }
                else
                { //否则就是更改值,不进行数据库的存储
                    return(0);
                }
            }
            catch (Exception ex)
            {
                Bouwa.Helper.Class.Log.WriterLine(Bouwa.Helper.Class.ELevel.error, "方法名:Update(CardInfo _cardInfo, string key),卡信息BLL层对数据操作时出现异常!", ex.Message);
                return(1);
            }
        }