private void btnConfirmRefund_Click(object sender, EventArgs e) { bool resUkey = base.CheckUKey(); if (!resUkey) { return; } if (base._CurrentCardInfo == null) { this.ShowWarningMessage("请重新读卡。"); btnRead.Focus(); return; } if (string.IsNullOrEmpty(tbxRefundMoney.Text.Trim())) { this.ShowWarningMessage("请输入退款金额。"); tbxRefundMoney.Focus(); tbxRefundMoney.SelectAll(); return; } decimal fRefund; #region 处理退款金额 bool res = decimal.TryParse(tbxRefundMoney.Text.Trim(), out fRefund); if (!res) { this.ShowWarningMessage("请检查退款金额的格式。"); tbxRefundMoney.Focus(); tbxRefundMoney.SelectAll(); return; } if (fRefund <= 0) { this.ShowWarningMessage("退款金额需大于0,请重新输入。"); tbxRefundMoney.Focus(); tbxRefundMoney.SelectAll(); return; } else if (fRefund > Common.DefineConstantValue.MaxRechargeVal) { this.ShowWarningMessage("充值金额不能大于" + Common.DefineConstantValue.MaxRechargeVal.ToString() + ",请重新输入。"); tbxRefundMoney.Focus(); tbxRefundMoney.SelectAll(); return; } #endregion if (string.IsNullOrEmpty(tbxDesc.Text)) { ShowWarningMessage("请先输入退款原因。"); tbxDesc.Focus(); tbxDesc.SelectAll(); return; } decimal fPreCost = decimal.Zero; if (ckbPreCost.Checked) { fPreCost = decimal.Parse(labPreCost.Text); } dlgConfirmInfo dlg = new dlgConfirmInfo(); dlg.CardInfo = base._CurrentCardInfo; dlg.IsPrinted = cbxPrint.Checked; dlg.RefundMoney = fRefund; dlg.UserInfo = base._CurrentCardUserInfo; dlg.PreCostMoney = fPreCost; dlg.IsPrinted = cbxPrint.Checked; if (dlg.ShowDialog() == DialogResult.OK) { //卡信息再次验证 ConsumeCardInfo chkCardInfo = this._Reader.ReadCardInfo(base._CardInfoSection, base._SectionPwd); if (chkCardInfo == null || (chkCardInfo != null && chkCardInfo.CardSourceID != base._CurrentCardInfo.CardSourceID)) { this.ShowWarningMessage("卡片信息已变更,请重新读卡后操作。"); resetAllControls(); return; } this.Cursor = Cursors.WaitCursor; try { fRefund = fRefund - Math.Abs(fPreCost);//实际退款金额 = 用户键入的退款额 - 需交付的欠款额 //先进行物理卡充值 ReturnValueInfo rvInfo = this._Reader.Recharge(base._CardInfoSection, base._SectionPwd, fRefund); if (rvInfo.boolValue && !rvInfo.isError) { RechargeRecord_rcr_Info rechargeRecord = new RechargeRecord_rcr_Info(); #region 填充实体 rechargeRecord.rcr_cRecordID = Guid.NewGuid(); rechargeRecord.rcr_cUserID = this._CurrentCardUserInfo.cus_cRecordID; rechargeRecord.rcr_cCardID = chkCardInfo.CardSourceID; rechargeRecord.rcr_cRechargeType = DefineConstantValue.ConsumeMoneyFlowType.Refund_CardPersonalRealTime.ToString(); rechargeRecord.rcr_cStatus = DefineConstantValue.ConsumeMoneyFlowStatus.Finished.ToString(); rechargeRecord.rcr_dRechargeTime = DateTime.Now; rechargeRecord.rcr_fRechargeMoney = fRefund; rechargeRecord.rcr_fBalance = base._CurrentCardInfo.CardBalance + fRefund;//退款后卡余额 = 当前卡余额 + 退款金额 rechargeRecord.PreCostMoney = fPreCost;//未结算的欠款 rechargeRecord.rcr_cDesc = tbxDesc.Text; rechargeRecord.rcr_cAdd = this.UserInformation.usm_cUserLoginID; rechargeRecord.rcr_cLast = rechargeRecord.rcr_cAdd; rechargeRecord.rcr_dLastDate = rechargeRecord.rcr_dRechargeTime; rechargeRecord.IsNeedSyncAccount = ckbPreCost.Checked; #endregion //卡退款成功后,将退款信息写入充值记录表 rvInfo = this._IRechargeRecordBL.InsertRechargeRecord(rechargeRecord); if (rvInfo.boolValue && !rvInfo.isError) { //成功录入退款记录后提示成功 this.Cursor = Cursors.Default; this.ShowInformationMessage("退款成功。" + Environment.NewLine + "退款用户:" + this._CurrentCardUserInfo.cus_cChaName + ",退款金额:" + fRefund.ToString() + "元"); 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 = fRefund; rdInfo.UserName = this.labUserName.Text; rdInfo.ClassName = this.labClassName.Text; //打印小票 PrintTicket(rdInfo); } resetAllControls(); btnRead.Focus(); return; } else { ShowErrorMessage("上传充值记录失败,需要进行回滚扣费,请摆放好卡片后,点击确定。"); ConsumeCardInfo cardInfoRollback = this._Reader.ReadCardInfo(base._CardInfoSection, base._SectionPwd); if (cardInfoRollback.CardSourceID != chkCardInfo.CardSourceID) { ShowWarningMessage("卡片信息不符合,请核对后重新放卡,原卡片卡号为:" + chkCardInfo.CardNo.ToString() + ",卡信息为:" + chkCardInfo.Name); cardInfoRollback = this._Reader.ReadCardInfo(base._CardInfoSection, base._SectionPwd); if (cardInfoRollback.CardSourceID == chkCardInfo.CardSourceID) { //录入退款记录失败,则需要将原先充入的卡金额扣除,如果卡已被取走,则需等待后台自动同步金额 rvInfo = this._Reader.Recharge(base._CardInfoSection, base._SectionPwd, fRefund * -1); if (rvInfo.boolValue && !rvInfo.isError) { ShowInformationMessage("回滚扣费成功,可重新进行充值。"); return; } else { ShowWarningMessage("回滚扣费失败,请联系系统管理员处理问题卡片。"); } } else { ShowWarningMessage("核对信息失败,请联系系统管理员处理问题卡片。"); } } else { rvInfo = this._Reader.Recharge(base._CardInfoSection, base._SectionPwd, fRefund * -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; } } catch (Exception ex) { this.Cursor = Cursors.Default; this.ShowErrorMessage("退款失败。" + Environment.NewLine + ex); btnRead.Focus(); return; } } }
private void btnConfirmRefund_Click(object sender, EventArgs e) { if (string.IsNullOrEmpty(tbxRefundMoney.Text.Trim())) { this.ShowWarningMessage("请输入退款金额。"); tbxRefundMoney.Focus(); return; } decimal fRefund;//退款额 bool res = decimal.TryParse(tbxRefundMoney.Text.Trim(), out fRefund); if (!res) { this.ShowWarningMessage("请检查退款金额的格式。"); tbxRefundMoney.Focus(); return; } if (fRefund <= 0) { this.ShowWarningMessage("退款金额需大于0,请重新输入。"); tbxRefundMoney.Focus(); return; } else if (fRefund > Common.DefineConstantValue.MaxRechargeVal) { this.ShowWarningMessage("退款金额不能大于" + Common.DefineConstantValue.MaxRechargeVal.ToString() + ",请重新输入。"); tbxRefundMoney.Focus(); tbxRefundMoney.SelectAll(); return; } decimal fCardBalance = this._CurrentCardInfo.CardBalance;//卡内余额 decimal fPreCost = decimal.Parse(labPreCost.Text);//未结算预付款 decimal fAdvance = decimal.Zero;//透支额 //************计算卡内金额是否足以退款******************* #region 计算卡内金额是否足以退款 if (base._CurrentCardUserInfo.cus_cIdentityNum == Common.DefineConstantValue.CodeMasterDefine.KEY2_SIOT_CardUserIdentity_Student) { List<RechargeRecord_rcr_Info> listAdvance = this._IRechargeRecordBL.SearchRecords(new RechargeRecord_rcr_Info() { rcr_cUserID = base._CurrentCardUserInfo.cus_cRecordID, rcr_cRechargeType = Common.DefineConstantValue.ConsumeMoneyFlowType.Recharge_AdvanceMoney.ToString(), }); listAdvance = listAdvance.OrderByDescending(x => x.rcr_dRechargeTime).ToList(); if (listAdvance != null && listAdvance.Count > 0) { fAdvance = listAdvance[0].rcr_fRechargeMoney; } } if (ckbPreCost.Checked) { if (fCardBalance - fAdvance - Math.Abs(fPreCost) < fRefund) { ShowWarningMessage("卡余额不足以支付本次退款。"); return; } } else { if (fCardBalance - fAdvance < fRefund) { ShowWarningMessage("卡余额不足以支付本次退款。"); return; } } #endregion if (string.IsNullOrEmpty(tbxRefundDesc.Text)) { ShowWarningMessage("请先输入退款原因。"); tbxRefundDesc.Focus(); tbxRefundDesc.SelectAll(); return; } if (base._CurrentCardUserInfo == null) { this.ShowWarningMessage("当前卡用户信息异常,请重新读卡。"); btnReadCard.Focus(); return; } if (base.UserInformation == null) { this.ShowWarningMessage("当前操作用户信息异常,请重新登录。"); return; } dlgConfirmInfo dlg = new dlgConfirmInfo(); dlg.IsPrinted = cbxPrint.Checked; dlg.RefundMoney = fRefund * -1; if (ckbPreCost.Checked) { dlg.PreCostMoney = Math.Abs(fPreCost) * -1; } else { dlg.PreCostMoney = 0; } dlg.UserInfo = this._CurrentCardUserInfo; dlg.CardInfo = base._CurrentCardInfo; if (dlg.ShowDialog() == DialogResult.OK) { ConsumeCardInfo chkCardInfo = this._Reader.ReadCardInfo(base._CardInfoSection, base._SectionPwd); if (chkCardInfo == null || (chkCardInfo != null && chkCardInfo.CardSourceID != base._CurrentCardInfo.CardSourceID)) { this.ShowWarningMessage("卡片信息已变更,请重新读卡后操作。"); resetAllControls(); return; } this.Cursor = Cursors.WaitCursor; try { //物理卡充值 ReturnValueInfo rvInfo = this._Reader.Recharge(base._CardInfoSection, base._SectionPwd, (fRefund + Math.Abs(dlg.PreCostMoney)) * -1); if (rvInfo.boolValue && !rvInfo.isError) { RechargeRecord_rcr_Info rechargeInfo = new RechargeRecord_rcr_Info(); rechargeInfo.rcr_cRecordID = Guid.NewGuid(); rechargeInfo.rcr_cAdd = base.UserInformation.usm_cUserLoginID; rechargeInfo.rcr_cLast = base.UserInformation.usm_cUserLoginID; rechargeInfo.rcr_cCardID = chkCardInfo.CardSourceID; rechargeInfo.rcr_cDesc = tbxRefundDesc.Text; rechargeInfo.rcr_cRechargeType = Common.DefineConstantValue.ConsumeMoneyFlowType.Refund_PersonalCash.ToString(); rechargeInfo.rcr_cStatus = Common.DefineConstantValue.ConsumeMoneyFlowStatus.Finished.ToString(); rechargeInfo.rcr_cUserID = base._CurrentCardUserInfo.cus_cRecordID; rechargeInfo.rcr_dLastDate = DateTime.Now; rechargeInfo.rcr_dRechargeTime = DateTime.Now; rechargeInfo.rcr_fBalance = fCardBalance - (fRefund + Math.Abs(dlg.PreCostMoney)); rechargeInfo.rcr_fRechargeMoney = fRefund; if (ckbPreCost.Checked) { rvInfo = this._IRechargeRecordBL.CashRefund(rechargeInfo, dlg.PreCostMoney); } else { rvInfo = this._IRechargeRecordBL.CashRefund(rechargeInfo, 0); } if (rvInfo.boolValue && !rvInfo.isError) { this.Cursor = Cursors.Default; this.ShowInformationMessage("退款成功。" + Environment.NewLine + "退款用户:" + this._CurrentCardUserInfo.cus_cChaName + ",退款金额:" + fRefund.ToString() + "元"); resetAllControls(); return; } else { #region 退款回滚 ShowErrorMessage("上传退款记录失败,需要进行回滚扣费,请摆放好卡片后,点击确定。"); ConsumeCardInfo cardInfoRollback = this._Reader.ReadCardInfo(base._CardInfoSection, base._SectionPwd); if (cardInfoRollback.CardSourceID != chkCardInfo.CardSourceID) { ShowWarningMessage("卡片信息不符合,请核对后重新放卡,原卡片卡号为:" + chkCardInfo.CardNo.ToString() + ",卡信息为:" + chkCardInfo.Name); cardInfoRollback = this._Reader.ReadCardInfo(base._CardInfoSection, base._SectionPwd); if (cardInfoRollback.CardSourceID == chkCardInfo.CardSourceID) { //录入退款记录失败,则需要将原先充入的卡金额扣除,如果卡已被取走,则需等待后台自动同步金额 rvInfo = this._Reader.Recharge(base._CardInfoSection, base._SectionPwd, fRefund + Math.Abs(dlg.PreCostMoney)); if (rvInfo.boolValue && !rvInfo.isError) { ShowInformationMessage("回滚扣费成功,可重新进行充值。"); return; } else { ShowWarningMessage("回滚扣费失败,请联系系统管理员处理问题卡片。"); } } else { ShowWarningMessage("核对信息失败,请联系系统管理员处理问题卡片。"); } } else { rvInfo = this._Reader.Recharge(base._CardInfoSection, base._SectionPwd, fRefund + Math.Abs(dlg.PreCostMoney)); if (rvInfo.boolValue && !rvInfo.isError) { ShowInformationMessage("回滚扣费成功,可重新进行充值。"); return; } else { ShowWarningMessage("回滚扣费失败,请联系系统管理员处理问题卡片。"); } } #endregion } resetAllControls(); this.Cursor = Cursors.Default; this.ShowWarningMessage("现金退款失败。" + rvInfo.messageText); return; } else { resetAllControls(); this.Cursor = Cursors.Default; this.ShowWarningMessage("现金退款失败。" + rvInfo.messageText); return; } } catch (Exception ex) { this.Cursor = Cursors.Default; this.ShowErrorMessage("退款失败。" + Environment.NewLine + ex); return; } } }