private void btnConfirmRecharge_Click(object sender, EventArgs e)
        {
            bool resUkey = base.CheckUKey();
            if (!resUkey)
            {
                return;
            }
            if (base._CurrentCardInfo == null)
            {
                this.ShowWarningMessage("请重新读卡。");
                btnRead.Focus();
                return;
            }
            if (string.IsNullOrEmpty(tbxRechargeMoney.Text.Trim()))
            {
                this.ShowWarningMessage("请输入充值金额。");
                tbxRechargeMoney.Focus();
                tbxRechargeMoney.SelectAll();
                return;
            }

            decimal fRecharge;//实际充值金额
            #region 检查实际充值金额

            bool res = decimal.TryParse(tbxRechargeMoney.Text.Trim(), out fRecharge);
            if (!res)
            {
                this.ShowWarningMessage("请检查充值金额的格式。");
                tbxRechargeMoney.Focus();
                tbxRechargeMoney.SelectAll();
                return;
            }
            if (fRecharge <= 0)
            {
                this.ShowWarningMessage("充值金额需大于0,请重新输入。");
                tbxRechargeMoney.Focus();
                tbxRechargeMoney.SelectAll();
                return;
            }
            else if (fRecharge > Common.DefineConstantValue.MaxRechargeVal)
            {
                this.ShowWarningMessage("充值金额不能大于" + Common.DefineConstantValue.MaxRechargeVal.ToString() + ",请重新输入。");
                tbxRechargeMoney.Focus();
                tbxRechargeMoney.SelectAll();
                return;
            }

            #endregion

            decimal fPreCost;//当次欠费,显示为负数
            #region 检查当次欠费

            bool resPreCost = decimal.TryParse(labPreCost.Text, out fPreCost);
            if (!resPreCost)
            {
                this.ShowWarningMessage("充值金额需大于0,请重新输入。");
                btnRead.Focus();
                return;
            }

            #endregion

            if (base._CurrentCardInfo == null)
            {
                ShowWarningMessage("原卡信息异常,请重新读卡确认。");
                btnRead.Focus();
                return;
            }
            if (this._CurrentPairInfo == null)
            {
                ShowWarningMessage("卡信息异常,请重新读卡确认。");
                btnRead.Focus();
                return;
            }
            if (base._CurrentCardUserInfo == null)
            {
                ShowWarningMessage("卡用户信息异常,请重新读卡确认");
                btnRead.Focus();
                return;
            }

            decimal fAdvanceMoney = decimal.Zero;
            RechargeRecord_rcr_Info searchAdvance = new RechargeRecord_rcr_Info();
            //searchAdvance.rcr_cCardID = this._CurrentCardInfo.CardSourceID;
            searchAdvance.rcr_cUserID = this._CurrentCardUserInfo.cus_cRecordID;
            searchAdvance.rcr_cRechargeType = Common.DefineConstantValue.ConsumeMoneyFlowType.Recharge_AdvanceMoney.ToString();
            RechargeRecord_rcr_Info advanceRecharge = this._IRechargeRecordBL.SearchRecords(searchAdvance).FirstOrDefault();
            if (advanceRecharge != null)
            {
                fAdvanceMoney = advanceRecharge.rcr_fRechargeMoney;
            }

            //确认页面
            dlgConfirmInfo dlg = new dlgConfirmInfo();
            dlg.CardInfo = base._CurrentCardInfo;
            dlg.UserInfo = base._CurrentCardUserInfo;
            dlg.IsPrinted = cbxPrint.Checked;
            dlg.RechargeMoney = fRecharge;
            dlg.AdvanceMoney = fAdvanceMoney;
            if (ckbIsSyncUnPay.Checked)
            {
                dlg.PreCostMoney = fPreCost;
            }
            else
            {
                dlg.PreCostMoney = decimal.Zero;
            }

            if (dlg.ShowDialog() == DialogResult.OK)
            {
                this.Cursor = Cursors.WaitCursor;

                decimal fRechargeDeduct = decimal.Zero;
                if (ckbIsSyncUnPay.Checked)
                {
                    fRechargeDeduct = fRecharge + fPreCost;//已经扣除的预付款数据
                    if (fRechargeDeduct < fRecharge)
                        fPreCost = Math.Abs(fPreCost);
                    else
                        fPreCost = 0;
                }
                else
                {
                    fRechargeDeduct = fRecharge;
                    fPreCost = 0;
                }

                //卡信息再次验证
                ConsumeCardInfo cardInfo = this._Reader.ReadCardInfo(base._CardInfoSection, base._SectionPwd);
                #region 卡片信息再次验证

                if (cardInfo == null)
                {
                    ShowWarningMessage("充值失败。" + Environment.NewLine + "无法确认充值卡信息,请重新读卡再试。");
                    this.Cursor = Cursors.Default;
                    return;
                }
                if (cardInfo.CardSourceID != dlg.CardInfo.CardSourceID)
                {
                    ShowWarningMessage("充值失败。" + Environment.NewLine + "充值卡信息已变更,请重新读卡再试。");
                    this.Cursor = Cursors.Default;
                    return;
                }

                #endregion

                //修正卡显示资料
                #region 修正卡显示资料
                try
                {
                    string strOldCardName = cardInfo.Name.Trim();
                    string strCurrentCardName = (this._CurrentPairInfo.CardOwner.ClassInfo.GradeInfo.gdm_cAbbreviation + this._CurrentPairInfo.CardOwner.cus_cChaName).Trim();
                    if (strOldCardName != strCurrentCardName)
                    {
                        ConsumeCardInfo changeCardInfo = new ConsumeCardInfo();
                        changeCardInfo.CardBalance = this._CurrentCardInfo.CardBalance;
                        changeCardInfo.CardNo = this._CurrentCardInfo.CardNo;
                        changeCardInfo.CardPwd = this._CurrentCardInfo.CardPwd;
                        changeCardInfo.CardSourceID = this._CurrentCardInfo.CardSourceID;
                        changeCardInfo.CardBalance = this._CurrentCardInfo.CardBalance;
                        changeCardInfo.Name = strCurrentCardName;

                        //年级信息发生变更,修改对应信息
                        ReturnValueInfo rvChangeCardInfo = this._Reader.WriteCardInfo(base._CardInfoSection, base._SectionPwd, changeCardInfo);
                    }
                }
                catch (Exception)
                { }
                #endregion

                //先进行【卡物理充值】
                ReturnValueInfo rvInfo = this._Reader.Recharge(base._CardInfoSection, base._SectionPwd, fRechargeDeduct);
                if (rvInfo.boolValue && !rvInfo.isError)
                {
                    //卡物理充值成功,继续进行充值记录上传操作
                    RechargeRecord_rcr_Info rechargeRecord = new RechargeRecord_rcr_Info();
                    #region 实体赋值

                    rechargeRecord.rcr_cRecordID = Guid.NewGuid();
                    rechargeRecord.rcr_cCardID = cardInfo.CardSourceID;
                    rechargeRecord.rcr_cRechargeType = DefineConstantValue.ConsumeMoneyFlowType.Recharge_PersonalRealTime.ToString();
                    rechargeRecord.rcr_cStatus = DefineConstantValue.ConsumeMoneyFlowStatus.Finished.ToString();
                    rechargeRecord.rcr_cUserID = this._CurrentCardUserInfo.cus_cRecordID;
                    rechargeRecord.rcr_dRechargeTime = DateTime.Now;//TODO:应该修改为跟服务器时间
                    rechargeRecord.rcr_fRechargeMoney = fRechargeDeduct;//扣减欠费得到的当次实际充值金额
                    rechargeRecord.PreCostMoney = fPreCost;//需要缴付的欠款金额
                    //<--卡实际充值后余额=卡当前余额+实际充值金额
                    rechargeRecord.rcr_fBalance = base._CurrentCardInfo.CardBalance + fRechargeDeduct;
                    //--->
                    rechargeRecord.IsNeedSyncAccount = ckbIsSyncUnPay.Checked;//是否需要同步账户,主要用以分别透支金额这些系统额外金额的记录登记
                    rechargeRecord.rcr_cAdd = this.UserInformation.usm_cUserLoginID;
                    rechargeRecord.rcr_cLast = rechargeRecord.rcr_cAdd;
                    rechargeRecord.rcr_dLastDate = rechargeRecord.rcr_dRechargeTime;

                    #endregion

                    //卡充值成功后,将充值信息写入充值记录表
                    rvInfo = this._IRechargeRecordBL.InsertRechargeRecord(rechargeRecord);
                    ComputePreCost(this._CurrentPairInfo);

                    if (rvInfo.boolValue && !rvInfo.isError)
                    {
                        //成功录入充值记录后提示成功
                        this.Cursor = Cursors.Default;
                        this.ShowInformationMessage("充值成功。");

                        if (cbxPrint.Checked)
                        {
                            RechargeDetail rdInfo = new RechargeDetail();
                            rdInfo.CardNo = Int32.Parse(this.labCardNo.Text);
                            rdInfo.OperationTime = System.DateTime.Now;
                            rdInfo.Operator = this.UserInformation.usm_cUserLoginID;
                            rdInfo.RechargeValue = fRecharge;
                            rdInfo.UserName = this.labUserName.Text;
                            rdInfo.ClassName = this.labClassName.Text;
                            //打印小票
                            PrintTicket(rdInfo);
                        }

                        resetAllControls();
                        this.Invoke(new DLG_GetRechargeHistory(BindRechargeList));

                        DateTime? dtSysNow = DateTime.Now;//使用系统时间作准,避免因客户机时间不同步造成操作异常
                        if (rvInfo.ValueObject != null)
                        {
                            dtSysNow = Convert.ToDateTime(rvInfo.ValueObject);
                        }
                        if (dtSysNow == null)
                        {
                            dtSysNow = DateTime.Now;
                        }
                        ResetMealPlanning(base._CurrentCardUserInfo, dtSysNow);

                        btnRead.Focus();
                        return;
                    }
                    else
                    {
                        ShowErrorMessage("上传充值记录失败,需要进行回滚扣费,请摆放好卡片后,点击确定。");
                        ConsumeCardInfo cardInfoRollback = this._Reader.ReadCardInfo(base._CardInfoSection, base._SectionPwd);
                        if (cardInfoRollback.CardSourceID != cardInfo.CardSourceID)
                        {
                            ShowWarningMessage("卡片信息不符合,请核对后重新放卡,原卡片卡号为:" + cardInfo.CardNo.ToString() + ",卡信息为:" + cardInfo.Name);
                            cardInfoRollback = this._Reader.ReadCardInfo(base._CardInfoSection, base._SectionPwd);
                            if (cardInfoRollback.CardSourceID == cardInfo.CardSourceID)
                            {
                                //录入充值记录失败,则需要将原先充入的卡金额扣除,如果卡已被取走,则需等待后台自动同步金额
                                rvInfo = this._Reader.Recharge(base._CardInfoSection, base._SectionPwd, fRechargeDeduct * -1);
                                if (rvInfo.boolValue && !rvInfo.isError)
                                {
                                    ShowInformationMessage("回滚扣费成功,可重新进行充值。");
                                    return;
                                }
                                else
                                {
                                    ShowWarningMessage("回滚扣费失败,请联系系统管理员处理问题卡片。");
                                }
                            }
                            else
                            {
                                ShowWarningMessage("核对信息失败,请联系系统管理员处理问题卡片。");
                            }
                        }
                        else
                        {
                            rvInfo = this._Reader.Recharge(base._CardInfoSection, base._SectionPwd, fRechargeDeduct * -1);
                            if (rvInfo.boolValue && !rvInfo.isError)
                            {
                                ShowInformationMessage("回滚扣费成功,可重新进行充值。");
                                return;
                            }
                            else
                            {
                                ShowWarningMessage("回滚扣费失败,请联系系统管理员处理问题卡片。");
                            }
                        }

                        resetAllControls();
                        this.Cursor = Cursors.Default;
                        this.ShowInformationMessage("充值失败。" + rvInfo.messageText);
                        btnRead.Focus();
                        return;
                    }
                }
                else
                {
                    resetAllControls();
                    this.Cursor = Cursors.Default;
                    this.ShowInformationMessage("充值失败。" + rvInfo.messageText);
                    btnRead.Focus();
                    return;
                }
            }
        }
        private void btnConfirmRecharge_Click(object sender, EventArgs e)
        {
            bool resUkey = base.CheckUKey();
            if (!resUkey)
            {
                return;
            }

            if (string.IsNullOrEmpty(tbxTransferMoney.Text.Trim()))
            {
                this.ShowWarningMessage("请输入充值金额。");
                tbxTransferMoney.Focus();
                return;
            }
            decimal fRecharge;
            bool res = decimal.TryParse(tbxTransferMoney.Text.Trim(), out fRecharge);
            if (!res)
            {
                this.ShowWarningMessage("请检查充值金额的格式。");
                tbxTransferMoney.Focus();
                return;
            }
            if (fRecharge <= 0)
            {
                this.ShowWarningMessage("充值金额需大于0,请重新输入。");
                tbxTransferMoney.Focus();
                return;
            }
            else if (fRecharge > Common.DefineConstantValue.MaxRechargeVal)
            {
                this.ShowWarningMessage("充值金额不能大于" + Common.DefineConstantValue.MaxRechargeVal.ToString() + ",请重新输入。");
                tbxTransferMoney.Focus();
                tbxTransferMoney.SelectAll();
                return;
            }

            //帐号余额
            ConsumeCardInfo ccInfo = new ConsumeCardInfo();
            ccInfo.CardBalance = decimal.Parse(this.labAccountBalance.Text);

            //查卡号
            UserCardPair_ucp_Info ucpInfo = new UserCardPair_ucp_Info();
            ucpInfo.ucp_cCUSID = this._CurrentUser.cus_cRecordID;
            List<UserCardPair_ucp_Info> ucpList = _IUserCardPairBL.SearchRecords(ucpInfo);
            if (ucpList != null && ucpList.Count > 0)
            {
                ucpList = ucpList.OrderBy(p => p.ucp_dAddDate).ToList();
                ccInfo.CardNo = ucpList[0].ucp_iCardNo.ToString();
            }
            else
            {
                if (MessageBox.Show("该用户未发卡,确认继续进行操作?", "提示", MessageBoxButtons.YesNo) == DialogResult.Yes)
                {

                }
                else
                {
                    return;
                }
            }

            dlgConfirmInfo dlg = new dlgConfirmInfo();
            dlg.RechargeMoney = fRecharge;
            dlg.UserInfo = this._CurrentUser;
            dlg.PreCostMoney = computePreCost(this._CurrentUser.cus_cRecordID);
            dlg.CardInfo = ccInfo;
            dlg.IsPrinted = cbxPrint.Checked;
            dlg.IsSkipPreCost = true;

            if (dlg.ShowDialog() == DialogResult.OK)
            {
                this.Cursor = Cursors.WaitCursor;
                try
                {
                    PreRechargeRecord_prr_Info preRechargeInfo = new PreRechargeRecord_prr_Info();
                    preRechargeInfo.prr_cAdd = base.UserInformation.usm_cUserLoginID;
                    preRechargeInfo.prr_cLast = base.UserInformation.usm_cUserLoginID;
                    preRechargeInfo.prr_cRechargeType = Common.DefineConstantValue.ConsumeMoneyFlowType.Recharge_PersonalTransfer.ToString();
                    preRechargeInfo.prr_cRecordID = Guid.NewGuid();
                    preRechargeInfo.prr_cStatus = Common.DefineConstantValue.ConsumeMoneyFlowStatus.WaitForAcceptTransfer.ToString();
                    preRechargeInfo.prr_cUserID = this._CurrentUser.cus_cRecordID;
                    preRechargeInfo.prr_dRechargeTime = DateTime.Now;
                    preRechargeInfo.prr_fRechargeMoney = fRecharge;

                    ReturnValueInfo rvInfo = this._IPreRechargeRecordBL.Save(preRechargeInfo, Common.DefineConstantValue.EditStateEnum.OE_Insert);
                    if (rvInfo.boolValue && !rvInfo.isError)
                    {
                        this.ShowInformationMessage("转账成功,请通知卡用户进行卡充值。");

                        if (cbxPrint.Checked)
                        {
                            RechargeDetail rdInfo = new RechargeDetail();
                            //rdInfo.CardNo = Int32.Parse(this.labCardNo.Text);
                            rdInfo.OperationTime = System.DateTime.Now;
                            rdInfo.Operator = this.UserInformation.usm_cUserLoginID;
                            rdInfo.RechargeValue = fRecharge;
                            rdInfo.UserName = this.labUserName.Text;
                            rdInfo.ClassName = this.labClassName.Text;
                            //打印小票
                            PrintTicket(rdInfo);
                        }

                    }
                    else
                    {
                        base.ShowErrorMessage("转账失败。" + rvInfo.messageText);
                    }
                }
                catch (Exception ex)
                {
                    this.Cursor = Cursors.Default;
                    this.ShowErrorMessage(ex);
                }

                ResetAllControls();
                this.Cursor = Cursors.Default;
            }
        }