/// <summary>
        /// 读取卡信息
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void tbnReadCard_Click(object sender, EventArgs e)
        {
            try
            {
                if (!readCardFlag)
                {
                    string[] mary1 = readBlock(RFIDClass.ReadCardAndReturnStatus(CurrentUser.Current.PassWordKey, Convert.ToInt32(1)));
                    if (mary1[4] != "0")
                    {
                        throw new Exception(RFIDClass.ConvertMeassByStatus(Convert.ToInt32(mary1[4])));
                    }
                    readCardFlag = true;
                    string[] mary2 = readBlock(RFIDClass.ReadCardAndReturnStatus(CurrentUser.Current.PassWordKey, Convert.ToInt32(2)));
                    string[] mary3 = readBlock(RFIDClass.ReadCardAndReturnStatus(CurrentUser.Current.PassWordKey, Convert.ToInt32(3)));
                    string[] mary4 = readBlock(RFIDClass.ReadCardAndReturnStatus(CurrentUser.Current.PassWordKey, Convert.ToInt32(4)));
                    string[] mary5 = readBlock(RFIDClass.ReadCardAndReturnStatus(CurrentUser.Current.PassWordKey, Convert.ToInt32(5)));
                    string[] mary6 = readBlock(RFIDClass.ReadCardAndReturnStatus(CurrentUser.Current.PassWordKey, Convert.ToInt32(6)));
                    lblNum.Text             = mary1[0]; //卡内编号;
                    this.tbxCardNum.Text    = mary4[1]; //卡面编号
                    this.lblMessage.Visible = true;

                    //读卡成功
                    readCardFlag = false;
                }
            }
            catch (Exception ep)
            {
                // SystemMessageInfo info = new SystemMessageInfo();
                // info.Content = string.Format(_objSystemMessage.GetInfoByCode("readCardFail").ToString(), ep.Message);
                // MessageBoxForm.Show(info, MessageBoxButtons.OK);

                MessageBoxForm.Show(ep.Message, MessageBoxButtons.OK);
                readCardFlag = false;
            }
        }
示例#2
0
        /// <summary>
        /// 进行读卡操作
        /// </summary>
        private void ReadCard()
        {
            //先读取卡内信息
            CardInfoBLL _cardBll = new CardInfoBLL();
            int         status   = -1; //保存读取后返回的一个状态

            Bouwa.ITSP2V31.Model.CardInfo _cardInfo = _cardBll.GetCardInfoByCard(Bouwa.Helper.CurrentUser.Current.PassWordKey, out status);
            try
            {
                string   password = CurrentUser.Current.PassWordKey;
                bool     flag     = false;
                string[] mary1    = StringUtil.readBlock(RFIDClass.ReadCardAndReturnStatus(password, Convert.ToInt32(1)));
                if (mary1[4] == "11" || mary1[4] == "12")
                {
                    flag     = true;
                    password = SystemConstant.StringEmpty;
                    mary1    = StringUtil.readBlock(RFIDClass.ReadCardAndReturnStatus(password, Convert.ToInt32(1)));
                }
                if (mary1[4] != "0")
                {
                    throw new Exception(RFIDClass.ConvertMeassByStatus(Convert.ToInt32(mary1[4])));
                }

                if (string.IsNullOrEmpty(_cardInfo.card_id))
                {
                    MessageBoxForm.Show("未读取到卡信息,请将卡放到读卡器上!", MessageBoxButtons.OK);
                    return;
                }
                //执行查询
                BindingSource bs           = new BindingSource();
                Hashtable     objHashtable = new Hashtable();
                objHashtable.Add("no", _cardInfo.no);
                objHashtable.Add("cost_type", (int)_cardInfo.cost_type); //扣费类型
                objHashtable.Add("card_id", _cardInfo.card_id);          //卡内编号
                //objHashtable.Add("saas_id", CurrentUser.Current.SAASID);

                IList <Bouwa.ITSP2V31.Model.CardInfo> CardInfo = _objCardInfoBLL.SearchByCondition(objHashtable, null, 1, 1, "[status] DESC", ref _objSystemMessageInfo);

                //说明注册过了
                if (CardInfo != null && CardInfo.Count > 0)
                {
                    Bouwa.ITSP2V31.Win.CardInfo.View frmCardInfoEdit = new Bouwa.ITSP2V31.Win.CardInfo.View();

                    frmCardInfoEdit.Parameter.Add("ActionType", ActionType.View.ToString("D"));
                    frmCardInfoEdit.Parameter.Add("Id", CardInfo[0].id.ToString());
                    frmCardInfoEdit.StartPosition = FormStartPosition.CenterScreen;
                    frmCardInfoEdit.ShowDialog(this);
                }//说明未注册
                else
                {
                    MessageBoxForm.Show("停车卡未在后台注册,请联系管理员!", MessageBoxButtons.OK);
                }
            }
            catch (Exception ex)
            {
                Bouwa.Helper.Class.Log.WriterLine(Bouwa.Helper.Class.ELevel.error, "读卡出现异常", ex.Message);
                MessageBoxForm.Show(_cardBll.ConvertMeassByStatus(status), MessageBoxButtons.OK);
            }
        }
示例#3
0
        /// <summary>
        /// 重新读取卡信息
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnReload_Click(object sender, EventArgs e)
        {
            try
            {
                string password = CurrentUser.Current.PassWordKey;
                bool   flag     = false;

                string[] mary1 = StringUtil.readBlock(RFIDClass.ReadCardAndReturnStatus(password, Convert.ToInt32(1)));
                if (mary1[4] == "11" || mary1[4] == "12")
                {
                    flag     = true;
                    password = SystemConstant.StringEmpty;
                    mary1    = StringUtil.readBlock(RFIDClass.ReadCardAndReturnStatus(password, Convert.ToInt32(1)));
                }
                if (mary1[4] != "0")
                {
                    throw new Exception(RFIDClass.ConvertMeassByStatus(Convert.ToInt32(mary1[4])));
                }
                //string[] mary6 = StringUtil.readBlock(RFIDClass.ReadCardAndReturnStatus(CurrentUser.Current.PassWordKey, Convert.ToInt32(6)));
                //判断当前读的卡是否能初始化的条件; 1: 卡状态为空卡255 ;2:卡状态为已充值,但最后操作时间为空
                string cardStatus = string.IsNullOrEmpty(mary1[2]) ? "" : mary1[2].ToString();
                //判断如果长度是16
                if (cardStatus.Length >= 16)
                {
                    cardStatus = HelperClass.getCardStatus(cardStatus.Substring(13, 1));
                }
                else
                {
                    cardStatus = Bouwa.ITSP2V31.Model.CardTypeInfo.CardTypeInfoDefaultCardStatus.空白卡.ToString("D");
                }

                if (cardStatus.Equals(CardTypeInfo.CardTypeInfoDefaultCardStatus.空白卡.ToString("D")) ||
                    (cardStatus.Equals(CardTypeInfo.CardTypeInfoDefaultCardStatus.已充值.ToString("D")) && string.IsNullOrEmpty(HelperClass.DecryptByString(mary1[3] == null ? "" : mary1[3].ToString()))) ||
                    flag || "InitAgain".Equals(buttonTag)
                    )
                {
                    //把RFID卡内编号赋值给卡内编号控件
                    _objCardId           = mary1[0];
                    this.tbxCardNum.Text = string.Empty;
                }
                else
                {
                    this.Close();
                    Bouwa.ITSP2V31.Win.CardType.CardTypeInitFail frmCardType = new Bouwa.ITSP2V31.Win.CardType.CardTypeInitFail();
                    //把RFID卡内编号加入到Paramter参数中
                    frmCardType.Parameter.Add("cardNum", mary1[0]);
                    frmCardType.Parameter.Add("ActionType", ActionType.Init.ToString("D"));
                    frmCardType.Parameter.Add("Id", _objId.ToString());
                    frmCardType.StartPosition = FormStartPosition.CenterScreen;
                    frmCardType.ShowDialog(this);
                }
            }
            catch (Exception ep)
            {
                MessageBoxForm.Show(ep.Message, MessageBoxButtons.OK);
                return;
            }
            SetFormFromInfo(_objId);
        }
        /// <summary>
        /// 初始化写卡数据
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void tbnWriteCard_Click(object sender, EventArgs e)
        {
            string d        = Guid.NewGuid().ToString("N");
            string password = CurrentUser.Current.PassWordKey;

            try
            {
                bool     flag  = false;
                string[] mary1 = StringUtil.readBlock(RFIDClass.ReadCardAndReturnStatus(password, Convert.ToInt32(1)));
                if (mary1[4] == "11" || mary1[4] == "12")
                {
                    flag     = true;
                    password = SystemConstant.StringEmpty;
                    mary1    = StringUtil.readBlock(RFIDClass.ReadCardAndReturnStatus(password, Convert.ToInt32(1)));
                }
                if (mary1[4] != "0")
                {
                    throw new Exception(RFIDClass.ConvertMeassByStatus(Convert.ToInt32(mary1[4])));
                }

                string cardStatus = string.IsNullOrEmpty(mary1[2])?"":mary1[2];
                //判断如果长度是16
                if (cardStatus.Length >= 16)
                {
                    cardStatus = HelperClass.getCardStatus(cardStatus.Substring(13, 1));
                }
                else
                {
                    cardStatus = Bouwa.ITSP2V31.Model.CardTypeInfo.CardTypeInfoDefaultCardStatus.空白卡.ToString("D");
                }
                //如果是从重新初始化的按钮进入,则跳过下面判断
                if (!(Bouwa.ITSP2V31.Model.CardTypeInfo.CardTypeInfoDefaultCardStatus.空白卡.ToString("D").Equals(cardStatus) ||
                      (cardStatus.Equals(CardTypeInfo.CardTypeInfoDefaultCardStatus.已充值.ToString("D")) && string.IsNullOrEmpty(HelperClass.DecryptByString(mary1[3] == null ? "" : mary1[3].ToString()))) ||
                      flag))
                {
                    this.lblNum.Text = string.Empty;
                    MessageBoxForm.Show("此卡非空卡,请更换卡!", MessageBoxButtons.OK);
                    return;
                }
                if (!mary1[0].Equals(this.lblNum.Text))
                {
                    //MessageBoxForm.Show(_objSystemMessage.GetInfoByCode("ReadNoSameCard"), MessageBoxButtons.OK);
                    MessageBoxForm.Show("读取停车卡和待写入卡不是同一张卡,不能被写入!", MessageBoxButtons.OK);
                    return;
                }
                if (string.IsNullOrEmpty(this.lblNum.Text))
                {
                    this.lblNum.Text = string.Empty;
                    MessageBoxForm.Show("未读取到卡内编号,请重试!", MessageBoxButtons.OK);
                    return;
                }
                if (string.IsNullOrEmpty(this.tbxCardNum.Text))
                {
                    MessageBoxForm.Show("卡面编号不能为空,请重新输入!", MessageBoxButtons.OK);
                    return;
                }


                //判断卡面编号输入是否合法
                Regex rx = new Regex("^[\u4E00-\u9FA5]+$");
                if (rx.IsMatch(this.tbxCardNum.Text.Trim()))
                {
                    MessageBoxForm.Show("卡面编号必须是数字或者字母,请重新输入!", MessageBoxButtons.OK);
                    return;
                }
                //判断输入的值是否超过预定的最大值
                string      maxValue        = "0";
                Hashtable   table           = new Hashtable();
                CardTypeBLL _objCardTypeBLL = new CardTypeBLL();
                table.Add("tcit_system", (int)CurrentUser.Current.PARKING_SYSTEM);
                table.Add("tcit_type", (int)CurrentUser.Current.PARK_BACKSTAGE);
                //判断上限分钟是否大于预设值
                if (this.lblCostType.Text.Equals(Bouwa.ITSP2V31.Model.CardInfo.CardTypeInfoCostType.限时卡.ToString("D")))
                {
                    table.Add("tcit_code", CurrentUser.Current.MaxTime);

                    maxValue = _objCardTypeBLL.GetRegisterType(table, null);
                    int   max   = 0;
                    Regex regex = new Regex("[^0-9]");
                    if (string.IsNullOrEmpty(this.tbxOverPlus.Text))
                    {
                        MessageBoxForm.Show("剩余时间不能为空!", MessageBoxButtons.OK);
                        return;
                    }
                    if (regex.IsMatch(maxValue))
                    {
                        MessageBoxForm.Show("限时预设值格式不正确,无法继续充值,请联系管理员!", MessageBoxButtons.OK);
                        return;
                    }
                    if (regex.IsMatch(this.tbxOverPlus.Text))
                    {
                        MessageBoxForm.Show("剩余时间必须为数字,请重新输入!", MessageBoxButtons.OK);
                        return;
                    }
                    max = Convert.ToInt32(this.tbxOverPlus.Text);
                    if (Convert.ToInt32(this.tbxOverPlus.Text) > Convert.ToInt32(this.tbxMax.Text))
                    {
                        MessageBoxForm.Show("剩余时间不能大于上限时间!", MessageBoxButtons.OK);
                        return;
                    }
                    if (Convert.ToInt32(this.tbxOverPlus.Text) > max)
                    {
                        MessageBoxForm.Show("剩余时间不能大于预设最大" + maxValue + "分!", MessageBoxButtons.OK);
                        return;
                    }
                }
                //判断剩余次数是否大于预设值
                else if (this.lblCostType.Text.Equals(Bouwa.ITSP2V31.Model.CardInfo.CardTypeInfoCostType.限次卡.ToString("D")))
                {
                    table.Add("tcit_code", CurrentUser.Current.MaxDegree);

                    maxValue = _objCardTypeBLL.GetRegisterType(table, null);
                    int   max   = 0;
                    Regex regex = new Regex("[^0-9]");
                    if (string.IsNullOrEmpty(this.tbxOverPlus.Text))
                    {
                        MessageBoxForm.Show("剩余次数不能为空!", MessageBoxButtons.OK);
                        return;
                    }
                    if (regex.IsMatch(maxValue))
                    {
                        MessageBoxForm.Show("次数预设值格式不正确,无法继续初始化,请联系管理员!", MessageBoxButtons.OK);
                        return;
                    }
                    if (regex.IsMatch(this.tbxOverPlus.Text))
                    {
                        MessageBoxForm.Show("剩余次数必须为数字,请重新输入!", MessageBoxButtons.OK);
                        return;
                    }
                    max = Int32.Parse(this.tbxOverPlus.Text);
                    if (Convert.ToInt32(this.tbxOverPlus.Text) > Convert.ToInt32(this.tbxMax.Text))
                    {
                        MessageBoxForm.Show("剩余次数不能大于上限次数!", MessageBoxButtons.OK);
                        return;
                    }
                    if (Convert.ToInt32(this.tbxOverPlus.Text) > Convert.ToInt32(maxValue))
                    {
                        MessageBoxForm.Show("剩余次数不能大于预设最大" + maxValue + "次!", MessageBoxButtons.OK);
                        return;
                    }
                }
                //判断剩余金额是否大于预设值
                else if (this.lblCostType.Text.Equals(Bouwa.ITSP2V31.Model.CardInfo.CardTypeInfoCostType.金额卡.ToString("D")))
                {
                    table.Add("tcit_code", CurrentUser.Current.MaxMoney);

                    maxValue = _objCardTypeBLL.GetRegisterType(table, null);
                    decimal max            = new Decimal(0.00);
                    Regex   RegDecimalSign = new Regex("^[+-]?[0-9]+[.]?[0-9]+$");
                    if (string.IsNullOrEmpty(this.tbxOverPlus.Text))
                    {
                        MessageBoxForm.Show("剩余次数不能为空!", MessageBoxButtons.OK);
                        return;
                    }
                    if (!RegDecimalSign.IsMatch(maxValue))
                    {
                        MessageBoxForm.Show("次数预设值格式不正确,无法继续初始化,请联系管理员!", MessageBoxButtons.OK);
                        return;
                    }
                    if (!RegDecimalSign.IsMatch(this.tbxOverPlus.Text))
                    {
                        MessageBoxForm.Show("剩余次数必须为数字,请重新输入!", MessageBoxButtons.OK);
                        return;
                    }
                    max = Convert.ToDecimal(this.tbxOverPlus.Text);
                    if (Convert.ToDecimal(this.tbxOverPlus.Text) > Convert.ToDecimal(this.tbxMax.Text))
                    {
                        MessageBoxForm.Show("剩余金额不能大于上限金额!", MessageBoxButtons.OK);
                        return;
                    }
                    if (Convert.ToDecimal(this.tbxOverPlus.Text) > max)
                    {
                        MessageBoxForm.Show("剩余金额不能大于上限金额" + maxValue + "元!", MessageBoxButtons.OK);
                        return;
                    }
                }
                StringBuilder sb = new StringBuilder();
                //初始化写入密码
                RFIDClass.UpdateCardPassWordAndReturnStatus(this.lblNum.Text, 1, SystemConstant.StringEmpty, CurrentUser.Current.PassWordKey);

                //写入扩展的SAASID
                if (!"0".Equals(SystemConstant.saas_type.SAAS_TYPE.ToString("D")))
                {
                    sb.Append(StringUtil.formatDataString(Convert.ToInt32(lblExtSaasId.Text), 3));
                }
                //写入系统编号
                sb.Append(SystemConstant.system_type.CS_SYSTEM.ToString("D"));
                //写入剩余金额及剩余次数及剩余时间,限期卡为5个0,限时卡前面是小时数,最后一位是分钟数数
                if (this.lblCostType.Text.Equals(Bouwa.ITSP2V31.Model.CardInfo.CardTypeInfoCostType.限期卡.ToString("D")))
                {
                    sb.Append(StringUtil.formatDataString(0, 5));
                }
                else if (this.lblCostType.Text.Equals(Bouwa.ITSP2V31.Model.CardInfo.CardTypeInfoCostType.限时卡.ToString("D")))
                {
                    string hours   = Convert.ToString(Convert.ToInt32(this.tbxOverPlus.Text) / 60);      //根据输入分钟数,输入数字除60取余计算出小时数
                    string minutes = Convert.ToString(Convert.ToInt32(this.tbxOverPlus.Text) % 60 / 10); //根据输入数字除60取模,然后再除以10,得到分钟数,1代表10分钟,2代表20分钟,依次类推

                    sb.Append(StringUtil.formatDataString(Convert.ToInt32(hours + minutes), 5));
                }
                else if (this.lblCostType.Text.Equals(Bouwa.ITSP2V31.Model.CardInfo.CardTypeInfoCostType.金额卡.ToString("D")))
                {
                    //格式化金额的存储,前4位保存整数,后1位保存小数点后面第一位
                    string money = Convert.ToDecimal(this.tbxOverPlus.Text).ToString("0.0");
                    sb.Append(StringUtil.formatDataString(Convert.ToInt32(money.Replace(".", "")), 5));
                }
                else
                {
                    sb.Append(StringUtil.formatDataString(Convert.ToInt32(this.tbxOverPlus.Text), 5));
                }
                //写入卡面编号
                sb.Append(StringUtil.formatDataString(this.tbxCardNum.Text, 7));
                //写入第一扇区的第零块
                writeBlock(1, 0, sb.ToString());
                sb = new StringBuilder();
                //写入生效日期
                sb.Append(DateTime.Parse(this.lblEffectDate.Text).ToString("yyMMdd"));
                //写入最晚日期
                sb.Append(DateTime.Parse(this.lblOutDate.Text).ToString("yyMMdd"));
                //写入扣费类型
                sb.Append(this.lblCostType.Text.ToString());
                //写入停车卡状态
                sb.Append(Bouwa.ITSP2V31.Model.CardTypeInfo.CardTypeInfoDefaultCardStatus.已充值.ToString("D"));
                //写入卡类型
                sb.Append(StringUtil.formatDataString(this.lblExtCardTypeId.Text.ToString(), 2));
                //写入第一扇区的第一块
                writeBlock(1, 1, sb.ToString());
                //把最后操作时间写入第一扇区的第二块
                sb = new StringBuilder();
                sb.Append(DateTime.Now.ToString("yyyyMMddHHmmss"));
                writeBlock(1, 2, sb.ToString());

                RFIDClass.IssueSound(50); //发出声音代表完成
                //将该卡信息写入后台数据库
                Hashtable cardInfo = new Hashtable();
                //插入初始化记录
                Hashtable htCardInfo = new Hashtable();
                //主键
                cardInfo.Add("id", Guid.NewGuid());
                htCardInfo.Add("id", Guid.NewGuid().ToString());
                //saasId
                if (!string.IsNullOrEmpty(this.lblSaasId.Text))
                {
                    cardInfo.Add("saas_id", new Guid(this.lblSaasId.Text));
                    htCardInfo.Add("saas_id", this.lblSaasId.Text);
                }
                //卡内编号
                if (!string.IsNullOrEmpty(this.lblNum.Text))
                {
                    cardInfo.Add("card_id", this.lblNum.Text);
                    htCardInfo.Add("card_id", Guid.Empty.ToString());
                }
                else
                {
                    MessageBoxForm.Show("未读取到卡内编号,请重试!", MessageBoxButtons.OK);
                    return;
                }
                //卡面编号
                if (!string.IsNullOrEmpty(this.tbxCardNum.Text.Trim()))
                {
                    cardInfo.Add("no", StringUtil.formatDataString(this.tbxCardNum.Text, 7));
                    htCardInfo.Add("no", StringUtil.formatDataString(this.tbxCardNum.Text, 7));
                }
                else
                {
                    MessageBoxForm.Show("卡面编号不能为空,请重新输入!", MessageBoxButtons.OK);
                    return;
                }
                //批次
                if (!string.IsNullOrEmpty(this.tbxLotNum.Text))
                {
                    cardInfo.Add("batch", this.tbxLotNum.Text);
                }
                //停车卡类型
                if (!string.IsNullOrEmpty(this.lblCardTypeId.Text))
                {
                    cardInfo.Add("card_type", _objId.ToString());
                }
                cardInfo.Add("status", Bouwa.ITSP2V31.Model.CardTypeInfo.CardTypeInfoDefaultCardStatus.已充值.ToString("D"));
                //生效日期
                if (!string.IsNullOrEmpty(this.lblEffectDate.Text))
                {
                    cardInfo.Add("efffect_date", Convert.ToDateTime(this.lblEffectDate.Text));
                }
                //最晚到期
                if (!string.IsNullOrEmpty(this.lblOutDate.Text))
                {
                    cardInfo.Add("end_date", Convert.ToDateTime(this.lblOutDate.Text));
                }

                //停车卡用途
                if (!string.IsNullOrEmpty(this.lblPurpose.Text))
                {
                    cardInfo.Add("purpose", Convert.ToInt32(this.lblPurpose.Text));
                    //cardInfo.purpose = 0;
                }
                //注册类型
                if (!string.IsNullOrEmpty(this.lblSubmitType.Text))
                {
                    cardInfo.Add("submit_type", Convert.ToInt32(this.lblSubmitType.Text));
                }
                //扣费类型
                if (!string.IsNullOrEmpty(this.lblCostType.Text))
                {
                    cardInfo.Add("cost_type", Convert.ToInt32(this.lblCostType.Text));
                    htCardInfo.Add("cost_type", Convert.ToInt32(this.lblCostType.Text));
                }
                //初始化操作日志,仅对非空白卡进行写数据

                string message = SystemConstant.StringEmpty;
                //剩余操作次数
                if (this.lblCostType.Text.Equals(CardTypeInfo.CardTypeInfoCostType.限次卡.ToString("D")))
                {
                    cardInfo.Add("times", Convert.ToInt32(this.tbxOverPlus.Text));
                    //备注信息
                    cardInfo.Add("memo", this.tbxCardNum.Text + "初始化成功!");
                    htCardInfo.Add("volume", Convert.ToInt32(this.tbxOverPlus.Text));
                    //htCardInfo.Add("operation_memo", String.Format(_objSystemMessage.GetInfoByCode("InitMemo").Content, this.tbxCardNum.Text, String.Format(_objSystemMessage.GetInfoByCode("InitTime").Content, this.tbxOverPlus.Text)));
                    message = "InitTime";
                }
                else
                {
                    cardInfo.Add("times", 0);
                }
                //剩余操作金额
                if (this.lblCostType.Text.Equals(CardTypeInfo.CardTypeInfoCostType.金额卡.ToString("D")))
                {
                    cardInfo.Add("money", Convert.ToDecimal(this.tbxOverPlus.Text));
                    //备注信息
                    cardInfo.Add("memo", this.tbxCardNum.Text + "初始化成功!");
                    htCardInfo.Add("volume", Convert.ToDecimal(this.tbxOverPlus.Text));
                    // htCardInfo.Add("operation_memo", String.Format(_objSystemMessage.GetInfoByCode("InitMemo").Content, this.tbxCardNum.Text, String.Format(_objSystemMessage.GetInfoByCode("InitMoney").Content, this.tbxOverPlus.Text)));
                    message = "InitMoney";
                }
                else
                {
                    cardInfo.Add("money", 0);
                }
                //剩余计费时间
                if (this.lblCostType.Text.Equals(CardTypeInfo.CardTypeInfoCostType.限时卡.ToString("D")))
                {
                    cardInfo.Add("charges_date", Convert.ToInt32(this.tbxOverPlus.Text));
                    //备注信息
                    cardInfo.Add("memo", this.tbxCardNum.Text + "初始化成功!");
                    htCardInfo.Add("volume", Convert.ToInt32(this.tbxOverPlus.Text));
                    //htCardInfo.Add("operation_memo", String.Format(_objSystemMessage.GetInfoByCode("InitMemo").Content, this.tbxCardNum.Text, String.Format(_objSystemMessage.GetInfoByCode("InitDegree").Content, this.tbxOverPlus.Text)));
                    message = "InitDegree";
                }
                else
                {
                    cardInfo.Add("charges_date", 0);
                }
                //剩余计费时间
                if (this.lblCostType.Text.Equals(CardTypeInfo.CardTypeInfoCostType.限期卡.ToString("D")))
                {
                    //备注信息
                    cardInfo.Add("memo", this.tbxCardNum.Text + "初始化成功!");
                    htCardInfo.Add("volume", Convert.ToDateTime(this.lblOutDate.Text).ToString("yyyyMMdd"));
                    //htCardInfo.Add("operation_memo", "初始化成功!");
                    message = "InitDate";
                }
                htCardInfo.Add("operation_memo_init", _objSystemMessage.GetInfoByCode("InitMemo").Content);
                htCardInfo.Add("operation_type_init", 1);

                if (this.ddlStatus.Text == CardTypeInfo.CardTypeInfoDefaultCardStatus.已充值.ToString())
                {
                    htCardInfo.Add("operation_type_payment", 5);
                    htCardInfo.Add("operation_memo_payment", string.Format(_objSystemMessage.GetInfoByCode(message).Content, this.tbxOverPlus.Text));
                }


                //初始化人员ID
                cardInfo.Add("create_user", CurrentUser.Current.UserId);
                htCardInfo.Add("operation_user", CurrentUser.Current.UserId);
                //初始化时间
                cardInfo.Add("create_time", DateTime.Now);
                htCardInfo.Add("operation_time", DateTime.Now.ToString());
                htCardInfo.Add("modity_user", CurrentUser.Current.UserId);
                htCardInfo.Add("modity_time", DateTime.Now.ToString());
                // htCardInfo.Add("operation_type","1");
                htCardInfo.Add("address_type", "1");
                htCardInfo.Add("network_id", CurrentUser.Current.NetWorkID);
                string mes = _objCardInfoBLL.ChangeCardInitAndBack(cardInfo, htCardInfo, null, ref _objSystemMessageInfo);

                if ("换卡操作成功!".Equals(mes))
                {
                    MessageBoxForm.Show("停车卡[" + this.tbxCardNum.Text + "]换卡成功!", MessageBoxButtons.OK);
                    this.Close();
                }
                else if ("换卡操作失败!".Equals(mes))
                {
                    //写入停车卡状态
                    RFIDClass.UpdateCardPassWordAndReturnStatus(this.lblNum.Text, 1, password, SystemConstant.StringEmpty);
                    writeBlock(1, 0, "");
                    writeBlock(1, 1, "");
                    writeBlock(1, 2, "");
                    MessageBoxForm.Show("停车卡[" + this.tbxCardNum.Text + "]换卡失败!", MessageBoxButtons.OK);
                }
            }
            catch (Exception ex)
            {
                //写入停车卡状态
                RFIDClass.UpdateCardPassWordAndReturnStatus(this.lblNum.Text, 1, password, SystemConstant.StringEmpty);
                writeBlock(1, 0, "");
                writeBlock(1, 1, "");
                writeBlock(1, 2, "");
                MessageBoxForm.Show(ex.Message, MessageBoxButtons.OK);
            }
        }
示例#5
0
        /// <summary>
        /// 进行读卡操作
        /// </summary>
        private void ReadCard()
        {
            //先读取卡内信息
            CardInfoBLL _cardBll = new CardInfoBLL();
            int         status   = -1; //保存读取后返回的一个状态

            Bouwa.ITSP2V31.Model.CardInfo _cardInfo = _cardBll.GetCardInfoByCard(Bouwa.Helper.CurrentUser.Current.PassWordKey, out status);
            try
            {
                //string[] mary1 = StringUtil.readBlock(RFIDClass.ReadCardAndReturnStatus(CurrentUser.Current.PassWordKey, Convert.ToInt32(1)));
                //if (mary1[4] != "0")
                //{
                //    //MessageBoxForm.Show(RFIDClass.ConvertMeassByStatus(Convert.ToInt32(mary1[4])));
                //    throw new Exception(RFIDClass.ConvertMeassByStatus(Convert.ToInt32(mary1[4])));
                //}
                ////string[] mary6 = StringUtil.readBlock(RFIDClass.ReadCardAndReturnStatus(CurrentUser.Current.PassWordKey, Convert.ToInt32(6)));
                ////判断当前读的卡是否能初始化的条件; 1: 卡状态为空卡255 ;2:卡状态为已充值,但最后操作时间为空
                //string cardStatus = mary1[2].ToString();
                //if (cardStatus.Length >= 16)
                //{
                //    cardStatus = HelperClass.getCardStatus(cardStatus.Substring(13, 1));
                //}
                //else
                //{
                //    cardStatus = Bouwa.ITSP2V31.Model.CardTypeInfo.CardTypeInfoDefaultCardStatus.空白卡.ToString("D");
                //}

                //if (cardStatus.Equals(CardTypeInfo.CardTypeInfoDefaultCardStatus.空白卡.ToString("D"))
                //    || (cardStatus.Equals(CardTypeInfo.CardTypeInfoDefaultCardStatus.已充值.ToString("D")) && string.IsNullOrEmpty(HelperClass.DecryptByString(mary1[3])))
                //    ||  _cardInfo ==null
                //    )
                //{
                //    Bouwa.ITSP2V31.WIN.CardType.CardTypeList frmCardType = new Bouwa.ITSP2V31.WIN.CardType.CardTypeList();
                //    MessageBoxForm.Show("停车卡还未初始化,需先初始化停车卡!", MessageBoxButtons.OK);

                //    frmCardType.StartPosition = FormStartPosition.CenterScreen;

                //    frmCardType.ShowDialog(this);
                //    return;
                //}
                //再去读取一次
                if (status == 11 || status == 12)
                {
                    _cardInfo = _cardBll.GetCardInfoByCard(string.Empty, out status);
                }
                if (status != 0)
                {
                    MessageBoxForm.Show(RFIDClass.ConvertMeassByStatus(status), MessageBoxButtons.OK);
                    return;
                }
                else if (_cardInfo == null)
                {
                    MessageBoxForm.Show("此卡为空卡,请先进行初始化!", MessageBoxButtons.OK);
                    return;
                }
                //执行查询
                BindingSource bs           = new BindingSource();
                Hashtable     objHashtable = new Hashtable();
                objHashtable.Add("no", _cardInfo.no);
                objHashtable.Add("cost_type", (int)_cardInfo.cost_type); //扣费类型
                objHashtable.Add("card_id", _cardInfo.card_id);          //卡内编号
                //objHashtable.Add("saas_id", CurrentUser.Current.SAASID);

                IList <Bouwa.ITSP2V31.Model.CardInfo> CardInfo = _objCardInfoBLL.SearchByCondition(objHashtable, null, 1, 1, "[status] DESC", ref _objSystemMessageInfo);

                //说明注册过了
                if (CardInfo != null && CardInfo.Count > 0)
                {
                    Bouwa.ITSP2V31.Win.CardInfo.View frmCardInfoEdit = new Bouwa.ITSP2V31.Win.CardInfo.View();

                    frmCardInfoEdit.Parameter.Add("ActionType", ActionType.View.ToString("D"));
                    frmCardInfoEdit.Parameter.Add("Id", CardInfo[0].id.ToString());
                    frmCardInfoEdit.StartPosition = FormStartPosition.CenterScreen;
                    frmCardInfoEdit.ShowDialog(this);
                }//说明未注册
                else
                {
                    //Bouwa.ITSP2V31.WIN.CardType.CardTypeList frmCardType = new Bouwa.ITSP2V31.WIN.CardType.CardTypeList();
                    //MessageBoxForm.Show("停车卡还未初始化,需先初始化停车卡!", MessageBoxButtons.OK);
                    MessageBoxForm.Show("后台未找到停车卡信息,请联系管理员!", MessageBoxButtons.OK);
                    //frmCardType.StartPosition = FormStartPosition.CenterScreen;
                    //frmCardType.ShowDialog(this);
                    return;
                }
            }
            catch (Exception ex)
            {
                Bouwa.Helper.Class.Log.WriterLine(Bouwa.Helper.Class.ELevel.error, "读卡出现异常", ex.Message);
                MessageBoxForm.Show(_cardBll.ConvertMeassByStatus(status), MessageBoxButtons.OK);
            }
        }
        /// <summary>
        /// 对停车卡充值
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void tbnInit_Click(object sender, EventArgs e)
        {
            Bouwa.Helper.BaseForm frmCardType = new BaseForm();
            ToolStripButton       button      = (ToolStripButton)sender;

            //读取卡内编号
            try
            {
                string   password = CurrentUser.Current.PassWordKey;
                bool     flag     = false;
                string[] mary1    = StringUtil.readBlock(RFIDClass.ReadCardAndReturnStatus(password, Convert.ToInt32(1)));
                if (mary1[4] == "11" || mary1[4] == "12")
                {
                    flag     = true;
                    password = SystemConstant.StringEmpty;
                    mary1    = StringUtil.readBlock(RFIDClass.ReadCardAndReturnStatus(password, Convert.ToInt32(1)));
                }
                if (mary1[4] != "0")
                {
                    throw new Exception(RFIDClass.ConvertMeassByStatus(Convert.ToInt32(mary1[4])));
                }
                //string[] mary6 = StringUtil.readBlock(RFIDClass.ReadCardAndReturnStatus(CurrentUser.Current.PassWordKey, Convert.ToInt32(6)));
                //判断当前读的卡是否能初始化的条件; 1: 卡状态为空卡255 ;2:卡状态为已充值,但最后操作时间为空
                string cardStatus = string.IsNullOrEmpty(mary1[2]) ? "" : mary1[2].ToString();
                if (cardStatus.Length >= 16)
                {
                    cardStatus = HelperClass.getCardStatus(cardStatus.Substring(13, 1));
                }
                else
                {
                    cardStatus = Bouwa.ITSP2V31.Model.CardTypeInfo.CardTypeInfoDefaultCardStatus.空白卡.ToString("D");
                }
                if (cardStatus.Equals(CardTypeInfo.CardTypeInfoDefaultCardStatus.空白卡.ToString("D")) ||
                    (cardStatus.Equals(CardTypeInfo.CardTypeInfoDefaultCardStatus.已充值.ToString("D")) && string.IsNullOrEmpty(HelperClass.DecryptByString(mary1[3]))) ||
                    flag || "InitAgain".Equals(button.Tag)
                    )
                {
                    frmCardType = new Bouwa.ITSP2V31.Win.CardType.CardTypeInit();
                    //把RFID卡内编号加入到Paramter参数中
                    frmCardType.Parameter.Add("cardNum", mary1[0]);
                }
                else
                {
                    frmCardType = new Bouwa.ITSP2V31.Win.CardType.CardTypeInitFail();
                    //把RFID卡内编号加入到Paramter参数中
                    frmCardType.Parameter.Add("cardNum", mary1[0]);
                    //把RFID卡得卡面编号加入到Parameter参数中
                    frmCardType.Parameter.Add("cardCode", mary1[1] == null?"":mary1[1].Substring(9));
                }
            }
            catch (Exception ep)
            {
                MessageBoxForm.Show(ep.Message, MessageBoxButtons.OK);
                return;
            }
            if (button.Tag.Equals("Init") || button.Tag.Equals("InitAgain"))
            {
                frmCardType.Parameter.Add("ActionType", ActionType.Init.ToString("D"));
                frmCardType.Parameter.Add("ButtonType", button.Tag.ToString());
            }
            frmCardType.Parameter.Add("Id", dgvMain.SelectedRows[0].Cells["Id"].Value.ToString());
            frmCardType.StartPosition = FormStartPosition.CenterScreen;
            frmCardType.ShowDialog(this);
        }
示例#7
0
        /// <summary>
        /// 为控件赋值
        /// </summary>
        /// <param name="theId"></param>
        private void SetFormFromInfo(Guid theId)
        {
            //_objCardTypeInfo = _objCardTypeBLL.GetById(theId, null, ref _objSystemMessageInfo);
            string password = CurrentUser.Current.PassWordKey;
            bool   flag     = false;

            string[] mary1 = StringUtil.readBlock(RFIDClass.ReadCardAndReturnStatus(password, Convert.ToInt32(1)));
            if (mary1[4] == "11" || mary1[4] == "12")
            {
                flag     = true;
                password = SystemConstant.StringEmpty;
                mary1    = StringUtil.readBlock(RFIDClass.ReadCardAndReturnStatus(password, Convert.ToInt32(1)));
            }
            if (mary1[4] != "0")
            {
                throw new Exception(RFIDClass.ConvertMeassByStatus(Convert.ToInt32(mary1[4])));
            }
            Hashtable objHashtable = new Hashtable();

            objHashtable.Add("no", (mary1[1] == null || string.IsNullOrEmpty(mary1[1])) ? "" : mary1[1].Substring(9));
            objHashtable.Add("cost_type", (mary1[2] == null || string.IsNullOrEmpty(mary1[2])) ? "0" : mary1[2].Substring(12, 1)); //扣费类型
            objHashtable.Add("card_id", mary1[0]);                                                                                 //卡内编号
            this.tbxNum.Text = objHashtable["no"].ToString();
            string overPlus = (mary1[1] == null || string.IsNullOrEmpty(mary1[1])) ? "0" : mary1[1].Substring(4, 5);               //剩余金额/剩余次数/剩余分钟
            string overDate = (mary1[2] == null || string.IsNullOrEmpty(mary1[2])) ? "0" : mary1[2].Substring(6, 6);               //最晚日期

            this.ddlStatus.SelectedValue = (mary1[2] == null || string.IsNullOrEmpty(mary1[2])) ? "0" : mary1[2].Substring(13, 1);
            string costType = objHashtable["cost_type"].ToString();

            IList <Bouwa.ITSP2V31.Model.CardInfo> cardInfo = _objCardInfoBLL.SearchByCondition(objHashtable, null, 1, 1, "[status] DESC", ref _objSystemMessageInfo);

            Bouwa.ITSP2V31.Model.CardInfo cardMessage = null;
            if (cardInfo != null && cardInfo.Count > 0)
            {
                cardMessage                      = cardInfo[0];
                this.tbxCardType.Text            = cardMessage.CardType;
                this.tbxLotNo.Text               = cardMessage.batch;
                this.ddlCostType.SelectedValue   = cardMessage.cost_type;
                this.ddlSubmitType.SelectedValue = cardMessage.submit_type;
                this.ddlPurpose.SelectedValue    = cardMessage.purpose;
                this.dtpEffectDate.Text          = cardMessage.efffect_date.ToString("yyyy-MM-dd");
                this.dtpOutDate.Text             = cardMessage.end_date.ToString("yyyy-MM-dd");
            }
            //if (_objCardTypeInfo != null)
            //{
            //    this.tbxNum.Text = _objCardId;
            //    this.tbxLotNo.Text = _objCardTypeInfo.Batch;
            //    this.tbxCardType.Text = _objCardTypeInfo.Name;
            //    this.ddlStatus.SelectedValue = _objCardTypeInfo.Status;
            //    //this.lblSaasId.Text = _objCardTypeInfo.SaasId.ToString();
            //    //this.lblCardTypeId.Text = _objCardTypeInfo.Id.ToString();
            //    this.ddlCostType.SelectedValue = _objCardTypeInfo.CostType.ToString("D");
            //    this.ddlPurpose.SelectedValue = _objCardTypeInfo.Purpose;
            //    this.ddlSubmitType.SelectedValue = _objCardTypeInfo.SubmitType;
            //    this.dtpEffectDate.Text = _objCardTypeInfo.EffectDate.ToString();
            //    this.dtpOutDate.Text = _objCardTypeInfo.OutDate.ToString();
            //    //判断剩余金额字段是否可更改
            //    if (_objCardTypeInfo.DefaultChange == CardTypeInfo.CardTypeInfoDefaultChange.可变)
            //    {
            //        this.tbxPlusOver.ReadOnly = false;
            //    }
            //    else
            //    {
            //        this.tbxPlusOver.ReadOnly = true;
            //    }

            //}
            if (cardMessage != null)
            {
                if (costType.Equals(CardTypeInfo.CardTypeInfoCostType.限时卡.ToString("D")))
                {
                    this.lblPlusOver.Text     = "剩余时间:";
                    this.lblPlusOverUnit.Text = this.lblMaxUnit.Text = "分钟";
                    this.tbxMax.Text          = "上限时间:";
                    this.tbxPlusOver.Text     = Convert.ToString(60 * Convert.ToInt32(overPlus.Substring(0, 4)) + Convert.ToInt32(overPlus.Substring(5)) * 10);
                    this.tbxMax.Text          = cardMessage.MaxChargesDate.ToString();
                }
                else if (costType.Equals(CardTypeInfo.CardTypeInfoCostType.限次卡.ToString("D")))
                {
                    this.lblPlusOver.Text     = "剩余次数:";
                    this.lblPlusOverUnit.Text = this.lblMaxUnit.Text = "次";
                    this.lblMax.Text          = "上限次数:";
                    this.tbxPlusOver.Text     = overPlus.ToString();
                    this.tbxMax.Text          = cardMessage.MaxTimes.ToString();
                }
                else if (costType.Equals(CardTypeInfo.CardTypeInfoCostType.限期卡.ToString("D")))
                {
                    this.lblPlusOver.Text        = "到期日期:";
                    this.tbxPlusOver.Text        = cardMessage.end_date.ToString("yyyy-MM-dd");
                    this.lblPlusOverUnit.Visible = this.lblMax.Visible =
                        this.tbxMax.Visible      = this.lblMaxUnit.Visible = false;
                }
                else
                {
                    this.tbxPlusOver.Text = Convert.ToDecimal(float.Parse(overPlus) / 10).ToString("0.00");
                    this.tbxMax.Text      = cardMessage.MaxMoney.ToString();
                }
            }
        }
 /// <summary>
 /// 根据状态返回对应的错误信息
 /// </summary>
 /// <param name="status">状态值</param>
 /// <returns>返回对应的错误信息值</returns>
 public string ConvertMeassByStatus(int status)
 {
     return(RFIDClass.ConvertMeassByStatus(status));
 }