private void btnAddCard_Click(object sender, EventArgs e) { DbConnection conn = null; DbTransaction trans = null; int ret = 0; try { if (ass == null) { throw new Exception("请首先查询并选择会员进行发卡!"); } if (txtCardNo.Text.Trim().Length < 5) { throw new Exception("请输入卡号,卡号必须5位"); } using (AMSEntities amsContext = new AMSEntities()) { conn = amsContext.Connection; if (conn.State != ConnectionState.Open) { conn.Open(); } int i = amsContext.tbAssociatorCard.Count(ac => ac.vcAssCardID == txtCardNo.Text); if (i > 0) { throw new Exception(txtCardNo.Text + "此会员卡号已在用"); } using (trans = conn.BeginTransaction(IsolationLevel.ReadCommitted)) { //事务数据操作或其它一致性操作 tbAssociator assm = amsContext.tbAssociator.FirstOrDefault(a => a.iAssID == ass.iAssID); if (assm == null) { throw new Exception("未找到发卡会员"); } tbAssociatorCard assCard = new tbAssociatorCard(); assCard.cCardState = "1"; assCard.dtCardEffDate = DateTime.Now; //assCard.dtCardExpDate = DateTime.Now; assCard.dtCardPutDate = DateTime.Now; assCard.iAssID = ass.iAssID; assCard.vcAssCardID = txtCardNo.Text; assCard.vcAssPwd = "123456"; assCard.vcCardLevel = "*"; assCard.vcOperID = GlobalParams.oper.vcOperID; assCard.dtOperDate = DateTime.Now; amsContext.AddTotbAssociatorCard(assCard); tbIntegral ig = new tbIntegral(); ig.iAssID = Convert.ToInt32(ass.iAssID); ig.iIgValue = 0; ig.nBalance = 0; ig.vcAssCardID = txtCardNo.Text; amsContext.AddTotbIntegral(ig); assm.vcAssState = "1"; assm.vcOperID = GlobalParams.oper.vcOperID; assm.dtOperDate = DateTime.Now; tbBusiLog busiLog = new tbBusiLog(); busiLog.iAssID = ass.iAssID; busiLog.dtOperDate = DateTime.Now; busiLog.iAssID = ass.iAssID; busiLog.vcAssCardID = txtCardNo.Text; busiLog.vcAssName = ass.vcAssName; busiLog.vcLinkSerial = null; busiLog.vcOperName = GlobalParams.oper.vcOperName; busiLog.vcOperID = GlobalParams.oper.vcOperID; busiLog.vcOperType = "OT001"; amsContext.AddTotbBusiLog(busiLog); Helper.Save(amsContext); //开始卡操作---------------------------------- ret = Helper.PutCard(txtCardNo.Text); if (ret != 0) { throw new Exception("卡操作异常"); } trans.Commit(); } DialogResult dr = MessageBox.Show(this, "发卡成功,是否继续发卡?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Information); if (dr == DialogResult.Yes) { ass = amsContext.tbAssociator.FirstOrDefault(a => a.vcAssState == ConstApp.AST_0); if (ass == null) { throw new Exception("无未发卡会员,请退出发卡界面"); } } } } catch (Exception ex) { //异常操作 ErrorLog.Write(this, ex); Helper.ShowError(this, Helper.PutCardError(ret)); } finally { if (conn != null) { conn.Close(); } } }
private void btnCardAdd_Click(object sender, EventArgs e) { DbConnection conn = null; DbTransaction trans = null; int ret = 0; try { if (string.IsNullOrEmpty(txtCardAdd.Text)) { throw new Exception("请输入补卡卡号"); } if (txtCardAdd.Text.Length < 5) { throw new Exception("会员卡卡号必须是5位"); } if (ass == null || assCard == null || ig == null) { throw new Exception("请首先查询会员,并选择某个会员卡进行会员卡挂失操作"); } if (billInvoice == null) { throw new Exception("请首先打印回执"); } using (AMSEntities amsContext = new AMSEntities()) { conn = amsContext.Connection; conn.Open(); int count = amsContext.tbAssociatorCard.Count(ac => ac.vcAssCardID == txtCardAdd.Text); if (count > 0) { throw new Exception(txtCardAdd.Text + "此会员卡号已在用"); } //起事务 using (trans = conn.BeginTransaction()) { //更新老卡 tbAssociatorCard oldAssCard = amsContext.tbAssociatorCard.FirstOrDefault(ac => ac.vcAssCardID == assCard.vcAssCardID && ac.iAssID == assCard.iAssID); if (oldAssCard == null) { throw new Exception("未找到老卡信息"); } oldAssCard.cCardState = ConstApp.CST_3; oldAssCard.vcOperID = GlobalParams.oper.vcOperID; oldAssCard.dtOperDate = DateTime.Now; oldAssCard.vcComments = "新卡号:" + txtCardAdd.Text;//txtAssCardID.Text; //插入新卡 tbAssociatorCard newAssCard = new tbAssociatorCard(); newAssCard.cCardState = "1"; newAssCard.dtCardEffDate = DateTime.Now; newAssCard.dtCardPutDate = DateTime.Now; newAssCard.iAssID = assCard.iAssID; newAssCard.vcAssCardID = txtCardAdd.Text;//txtAssCardID.Text; newAssCard.vcAssPwd = "123456"; newAssCard.vcCardLevel = assCard.vcCardLevel; newAssCard.vcOperID = GlobalParams.oper.vcOperID; newAssCard.dtOperDate = DateTime.Now; newAssCard.vcComments = "老卡号:" + oldAssCard.vcAssCardID; amsContext.AddTotbAssociatorCard(newAssCard); ////插入一条充值记录,充值金额为老卡的余额,vcOperType=‘OT003’ //tbFillFee fillFee = new tbFillFee(); //fillFee.dtFillDate = DateTime.Now; //fillFee.iAssID = assCard.iAssID;//assCard.iAssID;//Convert.ToInt64(AssID); ////fillFee.iFillSerial //fillFee.nBalance = ig.nBalance;// +iFillFee + iExtraFee; //fillFee.nFillFee = ig.nBalance;//Convert.ToDecimal(iFillFee); //fillFee.nLastBalance = 0;//ig.nBalance; //fillFee.nPromFee = 0;// iExtraFee; //fillFee.vcAssCardID = txtAssCardID.Text;// AssCardID; ////fillFee.vcComments = txtComments.Text; //fillFee.vcOperID = GlobalParams.oper.vcOperID; //fillFee.vcOperType = "OT003"; //amsContext.AddTotbFillFee(fillFee); tbIntegral newIg = new tbIntegral(); newIg.iAssID = Convert.ToInt32(newAssCard.iAssID); newIg.iIgValue = ig.iIgValue; newIg.nBalance = ig.nBalance; newIg.vcAssCardID = newAssCard.vcAssCardID; amsContext.AddTotbIntegral(newIg); tbIntegral oldIg = amsContext.tbIntegral.FirstOrDefault(i => i.vcAssCardID == ig.vcAssCardID && i.iAssID == ig.iAssID); if (oldIg == null) { throw new Exception("未找到老卡积分信息"); } oldIg.nBalance = 0; oldIg.iIgValue = 0; tbBusiFee busiFee = new tbBusiFee(); busiFee.dtOperDate = DateTime.Now; busiFee.iAssID = newAssCard.iAssID; //busiFee.iSerial = busiFee.nFee = dBusiFee; busiFee.vcAssCardID = newAssCard.vcAssCardID; busiFee.vcFeeCode = "GB001"; busiFee.vcOperID = GlobalParams.oper.vcOperID; busiFee.vcSvcCode = "OT003"; amsContext.AddTotbBusiFee(busiFee); Helper.Save(amsContext);//保存获取流水号 tbBillInvoice updateBillInvoice = amsContext.tbBillInvoice.FirstOrDefault(b => b.iBillNo == billInvoice.iBillNo); if (updateBillInvoice == null) { throw new Exception("获取帐单出错"); } updateBillInvoice.vcEffFlag = "1"; updateBillInvoice.vcLinkSerial = busiFee.iSerial;//fillFee.iFillSerial; tbBusiLog busiLog = new tbBusiLog(); busiLog.iAssID = ass.iAssID; busiLog.dtOperDate = DateTime.Now; busiLog.vcAssCardID = assCard.vcAssCardID; busiLog.vcAssName = ass.vcAssName; busiLog.vcOperName = GlobalParams.oper.vcOperName; busiLog.vcOperID = GlobalParams.oper.vcOperID; busiLog.vcOperType = "0T003"; busiLog.vcLinkSerial = busiFee.iSerial; //fillFee.iFillSerial; amsContext.AddTotbBusiLog(busiLog); Helper.Save(amsContext); //卡操作-------------------------------------------------------------------------- ret = Helper.PutCard(txtCardAdd.Text); if (ret != 0) { throw new Exception("卡操作异常"); } trans.Commit(); } } ass = null; assCard = null; ig = null; billInvoice = null; Helper.ShowInfo(this, "补发卡成功"); } catch (Exception ex) { ErrorLog.Write(this, ex); Helper.ShowError(this, Helper.PutCardError(ret)); } finally { if (conn != null) { conn.Close(); } } }