예제 #1
0
        private void BtnReadCard_Click(object sender, EventArgs e)
        {
            if (_CurrentAction.Equals(EAction.Edit))
            {
                //修改资料
                this._LastCard = GetCardModel(false, out string strErrMessage);
                if (this._LastCard == null)
                {
                    CMessageBox.ShowError(strErrMessage, Config.DialogTitle);
                    return;
                }

                if (MessageBox.Show("确定要保存修改吗?", Config.DialogTitle, MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
                {
                    return;
                }
                IDAL.ICard objDAL  = DALFactory.DALFactory.Card();
                bool       bIfSucc = objDAL.Update(this._LastCard, out string strErrorInfo);
                if (bIfSucc)
                {
                    CMessageBox.ShowError(string.Format("恭喜您,保存成功!"), Config.DialogTitle);
                }
                else
                {
                    CMessageBox.ShowError(string.Format("保存失败,错误如下:\r\n{0}", strErrorInfo), Config.DialogTitle);
                }
            }
            else
            {
                //读卡
                if (CardConfiger.GetInstance().Switch.Equals(ConfigerBase.ESwitch.CLOSE))
                {
                    if (MessageBox.Show("制卡串口当前已关闭,请先开启后再重试,确定现在开启吗?", Config.DialogTitle, MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
                    {
                        return;
                    }
                    CardConfiger.GetInstance().Start(RunVariable.CurrentSetting.WriteComProperty);
                }
                else
                {
                    if (MessageBox.Show("确定现在读卡吗?", Config.DialogTitle, MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
                    {
                        return;
                    }
                    if (!CardConfiger.GetInstance().ReadCard(out string strErrMessage))
                    {
                        CMessageBox.ShowError(string.Format("读卡失败,错误如下:\r\n{0}", strErrMessage), Config.DialogTitle);
                    }
                }
            }
        }
예제 #2
0
 /// <summary>
 /// 回调方法-配置器当写卡返回时
 /// </summary>
 private void CardViewForm_OnWriteCardReponse(uint iCardNo, string strErrInfo)
 {
     if (this._LastCard == null)
     {
         return;
     }
     if (iCardNo != uint.MaxValue && string.IsNullOrEmpty(strErrInfo))
     {
         try
         {
             this.Invoke(new EventHandler(delegate
             {
                 txtCardNo.Text        = iCardNo.ToString();
                 this._LastCard.CardNo = iCardNo;
                 //保存数据库
                 IDAL.ICard objDAL = DALFactory.DALFactory.Card();
                 if (!_UpdateFlag)
                 {
                     int iNewID = objDAL.Add(this._LastCard, out string strErrorInfo);
                     if (iNewID <= 0)
                     {
                         CMessageBox.ShowError(string.Format("恭喜您,写卡成功,但是保存卡片数据到数据库失败,错误如下:\r\n{0}!", strErrorInfo), Config.DialogTitle);
                         return;
                     }
                 }
                 else
                 {
                     bool bIfSucc = objDAL.Update(this._LastCard, out string strErrorInfo);
                     if (!bIfSucc)
                     {
                         CMessageBox.ShowError(string.Format("恭喜您,写卡成功,但是保存卡片数据到数据库失败,错误如下:\r\n{0}!", strErrorInfo), Config.DialogTitle);
                         return;
                     }
                 }
                 Manager.GetInstance().CardDataChangeNotice();
                 CMessageBox.ShowSucc(string.Format("恭喜您,写卡和保存卡片数据到数据库都成功!"), Config.DialogTitle);
             }));
         }