private void btnCardReturn_Click(object sender, EventArgs e) { //退卡 DbConnection conn = null; DbTransaction trans = null; try { if (string.IsNullOrEmpty(txtPwd.Text)) { throw new Exception("请输入会员卡密码"); } if (!assCard.vcAssPwd.Equals(txtPwd.Text)) { throw new Exception("会员卡密码不正确"); } DialogResult dr = MessageBox.Show(this, "请确认:\n退卡卡号:" + assCard.vcAssCardID, "提示", MessageBoxButtons.YesNo); if (dr == DialogResult.Yes) { using (AMSEntities amsContext = new AMSEntities()) { conn = amsContext.Connection; if (conn.State != ConnectionState.Open) { conn.Open(); } using (trans = conn.BeginTransaction(IsolationLevel.ReadCommitted)) { //事务数据操作或其它一致性操作 decimal dReturnFee = decimal.Round(ig.nBalance * 2 / 10, 2); decimal dFee = ig.nBalance - dReturnFee; tbFillFee fillFee = new tbFillFee(); fillFee.dtFillDate = DateTime.Now; fillFee.iAssID = assCard.iAssID; //fillFee.iFillSerial fillFee.nBalance = 0; // +iFillFee + iExtraFee; fillFee.nFillFee = -ig.nBalance; //-dFee;//Convert.ToDecimal(iFillFee); fillFee.nLastBalance = ig.nBalance; fillFee.nPromFee = 0; // -dReturnFee;//iExtraFee; fillFee.vcAssCardID = assCard.vcAssCardID; // AssCardID; fillFee.vcComments = txtComments.Text; fillFee.vcOperID = GlobalParams.oper.vcOperID; fillFee.vcOperType = "OT004"; amsContext.AddTotbFillFee(fillFee); Helper.Save(amsContext); tbBusiFee busiFee = new tbBusiFee(); busiFee.dtOperDate = DateTime.Now; busiFee.iAssID = assCard.iAssID; //busiFee.iSerial = busiFee.nFee = dReturnFee; busiFee.vcAssCardID = assCard.vcAssCardID; busiFee.vcFeeCode = "GB002"; busiFee.vcOperID = GlobalParams.oper.vcOperID; busiFee.vcSvcCode = "OT004"; amsContext.AddTotbBusiFee(busiFee); tbIntegral igm = amsContext.tbIntegral.FirstOrDefault(i => i.iAssID == ig.iAssID && i.vcAssCardID == ig.vcAssCardID); if (igm == null) { throw new Exception("未找到会员积分信息"); } igm.nBalance = 0; igm.iIgValue = 0; tbBusiLog busiLog = new tbBusiLog(); busiLog.dtOperDate = DateTime.Now; busiLog.iAssID = assCard.iAssID; busiLog.vcAssCardID = assCard.vcAssCardID; busiLog.vcAssName = txtAssName.Text; busiLog.vcOperName = GlobalParams.oper.vcOperName; busiLog.vcOperID = GlobalParams.oper.vcOperID; busiLog.vcOperType = "OT004"; busiLog.vcLinkSerial = fillFee.iFillSerial; amsContext.AddTotbBusiLog(busiLog); tbAssociator assm = amsContext.tbAssociator.FirstOrDefault(a => a.iAssID == ass.iAssID); if (assm == null) { throw new Exception("未找到会员信息"); } assm.vcAssState = ConstApp.AST_0; assm.dtOperDate = DateTime.Now; assm.vcOperID = GlobalParams.oper.vcOperID; tbAssociatorCard assCardm = amsContext.tbAssociatorCard.FirstOrDefault(ac => ac.iAssID == assCard.iAssID && ac.vcAssCardID == assCard.vcAssCardID); if (assCardm == null) { throw new Exception("未找到会员卡信息"); } //if (assCardm.cCardState != ConstApp.CST_1) // throw new Exception("会员卡不在正常使用状态,无法挂失"); assCardm.cCardState = ConstApp.CST_0; assCardm.dtCardExpDate = DateTime.Now; assCardm.vcOperID = GlobalParams.oper.vcOperID; assCardm.dtOperDate = DateTime.Now; if (billInvoice == null) { throw new Exception("请首先打印回执"); } tbBillInvoice billInvoicem = amsContext.tbBillInvoice.FirstOrDefault(b => b.iBillNo == billInvoice.iBillNo); billInvoicem.vcEffFlag = "1"; billInvoicem.vcLinkSerial = fillFee.iFillSerial; Helper.Save(amsContext); trans.Commit(); } } btnPrint.Enabled = false; btnCardReturn.Enabled = false; txtPwd.Enabled = false; billInvoice = null; MessageBox.Show(this, "会员卡退卡成功", "提示"); } } catch (Exception ex) { ErrorLog.Write(this, ex); } }
private void btnFillFee_Click(object sender, EventArgs e) { DbConnection conn = null; DbTransaction trans = null; try { if (ass == null || assCard == null || ig == null) { throw new Exception("请首先读取会员卡信息!"); } if (billInvoice == null) { throw new Exception("请首先打印回执"); } int iFillFee = Convert.ToInt32(txtFillFee.Value); if (iFillFee < 1000) { throw new Exception("充值金额必须是大于1000元的整数"); } var fillProm = GlobalParams.FillProm.FirstOrDefault(f => f.iCelling > iFillFee && f.iFloor <= iFillFee); if (fillProm == null) { throw new Exception("获取优惠比率出错,请检查优惠比率配置是否正确!"); } int iExtraFee = iFillFee * fillProm.iRate / 100; string str = "请确认,是否在" + assCard.vcAssCardID + "卡上充入下面金额:\n充值金额:" + iFillFee.ToString() + "\n赠送金额:" + iExtraFee.ToString() + "\n最终充值金额:" + (iFillFee + iExtraFee).ToString(); if (MessageBox.Show(this, str, "充值确认", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { using (AMSEntities amsContext = new AMSEntities()) { conn = amsContext.Connection; if (conn.State != ConnectionState.Open) { conn.Open(); } using (trans = conn.BeginTransaction(IsolationLevel.ReadCommitted)) { //事务数据操作或其它一致性操作 var igm = amsContext.tbIntegral.FirstOrDefault(i => i.vcAssCardID == assCard.vcAssCardID && i.iAssID == assCard.iAssID); if (igm == null) { throw new Exception("获取会员卡积分错误,请重试!"); } tbFillFee fillFee = new tbFillFee(); fillFee.dtFillDate = DateTime.Now; fillFee.iAssID = assCard.iAssID; //fillFee.iFillSerial fillFee.nBalance = ig.nBalance + iFillFee + iExtraFee; fillFee.nFillFee = Convert.ToDecimal(iFillFee); fillFee.nLastBalance = ig.nBalance; fillFee.nPromFee = iExtraFee; fillFee.vcAssCardID = assCard.vcAssCardID;// AssCardID; fillFee.vcComments = txtComments.Text; fillFee.vcOperID = GlobalParams.oper.vcOperID; fillFee.vcOperType = "OT002"; amsContext.AddTotbFillFee(fillFee); Helper.Save(amsContext); igm.nBalance = Convert.ToDecimal(fillFee.nBalance); if (billInvoice == null) { throw new Exception("获取账单出错,请先打印回执"); } tbBillInvoice billInvoicem = amsContext.tbBillInvoice.FirstOrDefault(b => b.iBillNo == billInvoice.iBillNo); billInvoicem.vcLinkSerial = fillFee.iFillSerial; billInvoicem.vcEffFlag = "1"; tbBusiLog busiLog = new tbBusiLog(); busiLog.dtOperDate = DateTime.Now; busiLog.iAssID = assCard.iAssID; busiLog.vcAssCardID = assCard.vcAssCardID; busiLog.vcAssName = txtAssName.Text; busiLog.vcOperName = GlobalParams.oper.vcOperName; busiLog.vcOperID = GlobalParams.oper.vcOperID; busiLog.vcOperType = "0T002"; busiLog.vcLinkSerial = fillFee.iFillSerial; amsContext.AddTotbBusiLog(busiLog); Helper.Save(amsContext); trans.Commit(); } } txtAssName.Text = ""; txtAssCardID.Text = ""; txtComments.Text = ""; txtBalance.Text = ""; txtExtraFee.Text = ""; txtFillFee.Value = 1000; txtSum.Text = ""; ass = null; assCard = null; ig = null; fillProm = null; billInvoice = null; Helper.ShowInfo(this, "会员卡充值成功!"); } } catch (Exception ex) { ErrorLog.Write(this, ex); } }