public static bool MyPrint(List <tbBillInvoice> invoice, List <tbBillList> list) { for (int i = 0; i < invoice.Count; i++) { tbBillInvoice bill = invoice[i]; string strTypeName = ""; switch (bill.vcBillType) { case "BI001": strTypeName = "会员卡消费帐单"; break; case "BI002": strTypeName = "会员卡充值帐单"; break; case "BI003": strTypeName = "会员卡积分兑换帐单"; break; case "BI004": strTypeName = "会员卡挂失帐单"; break; case "BI005": strTypeName = "会员卡补卡帐单"; break; case "BI006": strTypeName = "会员卡退卡帐单"; break; } bill.vcBillType = strTypeName; } rptBIModle rpt = new rptBIModle(list); rpt.SetLicense("admin,admin,123456,VF4UHHMJ4WOHHV77I8HH"); string baseDir = AppDomain.CurrentDomain.BaseDirectory + AppDomain.CurrentDomain.RelativeSearchPath; rpt.LoadLayout(baseDir + "//rpx//BIModle.rpx"); rpt.DataSource = invoice; rpt.Run(); return(rpt.Document.Print(false, true, false)); }
private void txtCardID_KeyPress(object sender, System.Windows.Forms.KeyPressEventArgs e) { try { if (e.KeyChar != 13) { if (e.KeyChar == 8) { return; } if (e.KeyChar < 48 || e.KeyChar > 57) { e.Handled = true; return; } } else { string strCardID = txtCardID.Text.Trim(); if (strCardID == "") { throw new Exception("会员卡号不能为空!"); } using (AMSEntities amsContext = new AMSEntities()) { tbAssociatorCard asscard1 = amsContext.tbAssociatorCard.FirstOrDefault(ac => ac.vcAssCardID == strCardID && ac.cCardState == "1"); if (asscard1 == null) { throw new Exception("会员信息不符,请检查是否此会员卡不是正常在用!"); } tbAssociator ass1 = amsContext.tbAssociator.FirstOrDefault(ass => ass.iAssID == asscard1.iAssID); if (ass1 == null) { throw new Exception("会员信息不符,请检查是否此会员卡不是正常在用!"); } tbIntegral intg1 = amsContext.tbIntegral.FirstOrDefault(ig => ig.iAssID == asscard1.iAssID && ig.vcAssCardID == asscard1.vcAssCardID); if (intg1 == null) { throw new Exception("获取当前余额积分异常!"); } var dtMaxIgDate = (from item in amsContext.tbIntegralLog where item.iAssID == asscard1.iAssID && item.vcAssCardID == asscard1.vcAssCardID && item.vcIgType == "IG002" select item.dtIgDate).Max(); string maxConsSerial = ""; if (dtMaxIgDate != null) { maxConsSerial = (from item in amsContext.tbConsumption where item.iAssID == asscard1.iAssID && item.vcAssCardID == asscard1.vcAssCardID && item.dtConsDate > dtMaxIgDate && item.vcFlag == "0" select item.iConsSerial).Max().ToString(); } else { maxConsSerial = (from item in amsContext.tbConsumption where item.iAssID == asscard1.iAssID && item.vcAssCardID == asscard1.vcAssCardID && item.vcFlag == "0" select item.iConsSerial).Max().ToString(); } if (maxConsSerial == null || maxConsSerial == "") { throw new Exception("没有可返销的消费帐单记录!"); } long longcons = long.Parse(maxConsSerial); var conslist = from item in amsContext.tbConsumption where item.iConsSerial == longcons orderby item.iNO select new { item.vcGoodsCode, item.nGoodsPrice, item.nConsRate, item.iConsCount, item.nConsCharge2, item.vcComments }; if (conslist == null) { throw new Exception("没有可返销的消费帐单记录!"); } tbBillInvoice bill1 = amsContext.tbBillInvoice.FirstOrDefault(bl => bl.vcAssCardID == asscard1.vcAssCardID && bl.vcEffFlag == "1" && bl.vcLinkSerial == longcons); if (bill1 == null) { throw new Exception("没有可返销的消费帐单记录!"); } txtAssName.Text = ass1.vcAssName; txtBillNo.Text = bill1.iBillNo.ToString(); txtCurCharge.Text = intg1.nBalance.ToString(); txtCurIG.Text = intg1.iIgValue.ToString(); txtConsFee.Text = bill1.dTotalFee.ToString(); txtConsDate.Text = bill1.dtCreateDate.Value.ToShortDateString(); txtConsSerial.Text = maxConsSerial; txtAssID.Text = asscard1.iAssID.ToString(); dgvConsList.DataSource = conslist; dgvConsList.Columns["vcGoodsCode"].HeaderText = "消费项名称"; dgvConsList.Columns["nGoodsPrice"].HeaderText = "单价"; dgvConsList.Columns["nConsRate"].HeaderText = "折扣"; dgvConsList.Columns["iConsCount"].HeaderText = "数量"; dgvConsList.Columns["nConsCharge2"].HeaderText = "单项合计"; dgvConsList.Columns["vcComments"].HeaderText = "备注"; dgvConsList.AllowUserToAddRows = false; dgvConsList.AllowUserToDeleteRows = false; dgvConsList.AllowUserToResizeRows = false; dgvConsList.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.AllCells; dgvConsList.AutoSizeRowsMode = DataGridViewAutoSizeRowsMode.AllCells; dgvConsList.ReadOnly = true; dgvConsList.SelectionMode = DataGridViewSelectionMode.FullRowSelect; dgvConsList.RowHeadersWidthSizeMode = DataGridViewRowHeadersWidthSizeMode.AutoSizeToAllHeaders; btnRollBack.Enabled = true; } } } catch (Exception ex) { ErrorLog.Write(this, ex, "校验错误"); txtCardID.Focus(); } }
private void btnRollBack_Click(object sender, EventArgs e) { try { DialogResult dreocon = MessageBox.Show("请确定要将此消费帐单返销吗?", "系统提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (dreocon == DialogResult.Yes) { long conserialNo = 0; long igserialNo = 0; using (AMSEntities amscontext2 = new AMSEntities()) { tbConsserialNo conserial1 = new tbConsserialNo(); conserial1.vcFill = "0"; amscontext2.AddTotbConsserialNo(conserial1); tbIgSerialNo igserial1 = new tbIgSerialNo(); igserial1.vcFill = "0"; amscontext2.AddTotbIgSerialNo(igserial1); amscontext2.SaveChanges(); conserialNo = conserial1.iSerialNo; igserialNo = igserial1.iSerialNo; } using (AMSEntities amsContext = new AMSEntities()) { DateTime dtoperdate = DateTime.Now; long longassid = long.Parse(txtAssID.Text.Trim()); tbAssociatorCard asscard1 = amsContext.tbAssociatorCard.FirstOrDefault(ac => ac.iAssID == longassid && ac.cCardState == "1"); if (asscard1 == null) { throw new Exception("会员信息不符,请检查是否此会员卡不是正常在用,请重试!"); } tbIntegral intg1 = amsContext.tbIntegral.FirstOrDefault(ig => ig.iAssID == asscard1.iAssID && ig.vcAssCardID == asscard1.vcAssCardID); if (intg1 == null) { throw new Exception("获取当前余额积分异常,请重试!"); } var dtMaxIgDate = (from item in amsContext.tbIntegralLog where item.iAssID == asscard1.iAssID && item.vcAssCardID == asscard1.vcAssCardID && item.vcIgType == "IG002" select item.dtIgDate).Max(); string maxConsSerial = ""; if (dtMaxIgDate != null) { maxConsSerial = (from item in amsContext.tbConsumption where item.iAssID == asscard1.iAssID && item.vcAssCardID == asscard1.vcAssCardID && item.dtConsDate > dtMaxIgDate && item.vcFlag == "0" select item.iConsSerial).Max().ToString(); } else { maxConsSerial = (from item in amsContext.tbConsumption where item.iAssID == asscard1.iAssID && item.vcAssCardID == asscard1.vcAssCardID && item.vcFlag == "0" select item.iConsSerial).Max().ToString(); } if (maxConsSerial == null || maxConsSerial == "") { throw new Exception("没有可返销的消费帐单记录,请重试!"); } long longcons = long.Parse(maxConsSerial); var conslist = from item in amsContext.tbConsumption where item.iConsSerial == longcons orderby item.iNO select item; if (conslist == null) { throw new Exception("没有可返销的消费帐单记录!"); } tbBillInvoice bill1 = amsContext.tbBillInvoice.FirstOrDefault(bl => bl.vcAssCardID == asscard1.vcAssCardID && bl.vcEffFlag == "1" && bl.vcLinkSerial == longcons); if (bill1 == null) { throw new Exception("没有可返销的消费帐单记录!"); } tbIntegralLog iglog1 = amsContext.tbIntegralLog.FirstOrDefault(igg => igg.iLinkCons == longcons); if (iglog1 == null) { throw new Exception("没有可返销的消费帐单记录!"); } if (bill1.iBillNo.ToString() != txtBillNo.Text.Trim() || maxConsSerial != txtConsSerial.Text.Trim()) { throw new Exception("数据异常,请重试!"); } intg1.nBalance = intg1.nBalance + (decimal)bill1.dTotalFee; intg1.iIgValue = (int)intg1.iIgValue - (int)bill1.dIgGet; ObjectStateEntry ose = amsContext.ObjectStateManager.GetObjectStateEntry(intg1); foreach (var item in conslist) { item.vcFlag = "1"; item.iLink = conserialNo; item.dtOperDate = dtoperdate; item.vcComments += "-由操作员:" + GlobalParams.oper.vcOperName + ",返销"; tbConsumption cons1 = new tbConsumption(); cons1.iConsSerial = conserialNo; cons1.iNO = item.iNO; cons1.iAssID = item.iAssID; cons1.vcAssCardID = item.vcAssCardID; cons1.vcGoodsCode = item.vcGoodsCode; cons1.nGoodsPrice = -item.nGoodsPrice; cons1.iConsCount = item.iConsCount; cons1.nLastBalance = decimal.Parse(ose.OriginalValues["nBalance"].ToString()); cons1.nConsCharge1 = -item.nConsCharge1; cons1.nConsRate = item.nConsRate; cons1.nConsCharge2 = -item.nConsCharge2; cons1.nBalance = decimal.Parse(ose.CurrentValues["nBalance"].ToString()); cons1.dtConsDate = dtoperdate; cons1.dtOperDate = dtoperdate; cons1.vcFlag = "9"; cons1.iLink = item.iConsSerial; cons1.vcOperID = GlobalParams.oper.vcOperID; cons1.vcClass = GlobalParams.strClass; cons1.vcComments = ""; amsContext.AddTotbConsumption(cons1); } iglog1.vcComments += "-本次积分已被返销"; tbIntegralLog ignew = new tbIntegralLog(); ignew.iIgSerial = igserialNo; ignew.iNo = 1; ignew.iAssID = iglog1.iAssID; ignew.vcAssCardID = iglog1.vcAssCardID; ignew.iIgLast = int.Parse(ose.OriginalValues["iIgValue"].ToString()); ignew.dtIgDate = dtoperdate; ignew.vcIgName = "0"; ignew.vcIgType = "IG003"; ignew.iIgGet = -(int)bill1.dIgGet; ignew.iIgArrival = int.Parse(ose.CurrentValues["iIgValue"].ToString()); ignew.iLinkCons = conserialNo; ignew.vcOperID = GlobalParams.oper.vcOperID; ignew.vcComments = ""; amsContext.AddTotbIntegralLog(ignew); tbBusiLog busilog1 = new tbBusiLog(); busilog1.vcAssName = txtAssName.Text.Trim(); busilog1.vcAssCardID = intg1.vcAssCardID; busilog1.vcLinkSerial = conserialNo; busilog1.vcOperType = "OT012"; busilog1.vcOperID = GlobalParams.oper.vcOperID; busilog1.vcOperName = GlobalParams.oper.vcOperName; busilog1.dtOperDate = dtoperdate; busilog1.iAssID = intg1.iAssID; amsContext.AddTotbBusiLog(busilog1); amsContext.SaveChanges(); txtCardID.Text = ""; txtAssName.Text = ""; txtBillNo.Text = ""; txtCurCharge.Text = ""; txtCurIG.Text = ""; txtConsFee.Text = ""; txtConsDate.Text = ""; txtAssID.Text = ""; txtConsSerial.Text = ""; btnRollBack.Enabled = false; DataTable dtConsList = new DataTable(); dtConsList.Columns.Add("消费项名称"); dtConsList.Columns.Add("单价"); dtConsList.Columns.Add("折扣"); dtConsList.Columns.Add("数量"); dtConsList.Columns.Add("单项合计"); dtConsList.Columns.Add("备注"); dtConsList.PrimaryKey = new DataColumn[] { dtConsList.Columns["消费项名称"], dtConsList.Columns["单价"], dtConsList.Columns["折扣"] }; dgvConsList.DataSource = dtConsList; MessageBox.Show("本次消费帐单返销成功!", "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Information); txtCardID.Focus(); } } } catch (Exception ex) { ErrorLog.Write(this, ex, "返销异常"); this.Close(); } }
private void btnPrint_Click(object sender, EventArgs e) { //打印回执 DbConnection conn = null; DbTransaction trans = null; try { using (AMSEntities amsContext = new AMSEntities()) { conn = amsContext.Connection; if (conn.State != ConnectionState.Open) { conn.Open(); } using (trans = conn.BeginTransaction(IsolationLevel.ReadCommitted)) { //事务数据操作或其它一致性操作 tbBillSerialNo serialNo = new tbBillSerialNo(); serialNo.vcFill = "0"; amsContext.AddTotbBillSerialNo(serialNo); Helper.Save(amsContext); decimal dReturnFee = decimal.Round(ig.nBalance * 2 / 10, 2); decimal dFee = ig.nBalance - dReturnFee; tbBillList billList = new tbBillList(); billList.iBillNo = serialNo.iSerialNo; billList.iCount = 1; billList.iNO = 1; billList.nCharge = dFee; // ig.nBalance;// -dReturnFee; billList.nPrice = dFee; // ig.nBalance;// -dReturnFee; billList.nRate = 1; billList.vcGoodsName = "退还金额"; //billList.vcUnit = ""; amsContext.AddTotbBillList(billList); tbBillList billList2 = new tbBillList(); billList2.iBillNo = serialNo.iSerialNo; billList2.iCount = 1; billList2.iNO = 2; billList2.nCharge = dReturnFee; billList2.nPrice = dReturnFee; billList2.nRate = 1; billList2.vcGoodsName = "退卡费"; //billList.vcUnit = ""; amsContext.AddTotbBillList(billList2); billInvoice = new tbBillInvoice(); billInvoice.dCharge = ig.nBalance; //0;// ig.nBalance + iFillFee + iExtraFee; billInvoice.dIgGet = 0; billInvoice.dIgValue = 0; //ig.iIgValue; billInvoice.dLastCharge = ig.nBalance; billInvoice.dLastIg = ig.iIgValue; billInvoice.dMealFee = 0; billInvoice.dServiceFee = 0; billInvoice.dSumFee = ig.nBalance; // dFee;// ig.nBalance - dReturnFee;//0;// iFillFee + iExtraFee; billInvoice.dtCreateDate = DateTime.Now; billInvoice.dTotalFee = ig.nBalance; //dFee;// ig.nBalance - dReturnFee; ;//0;// iFillFee; billInvoice.dtPrintDate = DateTime.Now; billInvoice.iBillNo = serialNo.iSerialNo; billInvoice.vcAssCardID = assCard.vcAssCardID; billInvoice.vcAssName = ass.vcAssName;//txtAssName.Text; billInvoice.vcBillType = "BI006"; billInvoice.vcEffFlag = "0"; billInvoice.vcLinkSerial = null; billInvoice.vcOperName = GlobalParams.oper.vcOperName; billInvoice.vcOperID = GlobalParams.oper.vcOperID; billInvoice.vcPrintFlag = "1"; //billInvoice.vcReserve = ""; amsContext.AddTotbBillInvoice(billInvoice); Helper.Save(amsContext); //打印帐单----------------------------------- //打印帐单----------------------------------- List <tbBillInvoice> invoice = new List <tbBillInvoice>(); invoice.Add(billInvoice); List <tbBillList> list = new List <tbBillList>(); list.Add(billList); list.Add(billList2); Helper.MyPrint(invoice, list); trans.Commit(); } } btnPrint.Enabled = false; btnCardReturn.Enabled = false; txtPwd.Enabled = true; txtPwd.Focus(); Helper.ShowInfo(this, "打印回执成功,请输入会员卡密码,进行退卡操作"); } catch (Exception ex) { billInvoice = null; ErrorLog.Write(this, ex); } }
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 btnPrint_Click(object sender, EventArgs e) { DbConnection conn = null; DbTransaction trans = null; try { if (ass == null || assCard == null || ig == 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; txtExtraFee.Text = iExtraFee.ToString(); txtSum.Text = Convert.ToString(iFillFee + iExtraFee); if (assCard.cCardState != ConstApp.CST_1) { throw new Exception("此会员卡不在正常在用状态,无法充值"); } using (AMSEntities amsContext = new AMSEntities()) { conn = amsContext.Connection; if (conn.State != ConnectionState.Open) { conn.Open(); } using (trans = conn.BeginTransaction(IsolationLevel.ReadCommitted)) { //事务数据操作或其它一致性操作 tbBillSerialNo serialNo = new tbBillSerialNo(); serialNo.vcFill = "0"; amsContext.AddTotbBillSerialNo(serialNo); Helper.Save(amsContext); tbBillList billList1 = new tbBillList(); billList1.iBillNo = serialNo.iSerialNo;//lSerialNo; billList1.iCount = 1; billList1.iNO = 1; billList1.nCharge = Convert.ToDecimal(iFillFee); billList1.nPrice = Convert.ToDecimal(iFillFee); billList1.nRate = 1; billList1.vcGoodsName = "会员充值"; billList1.vcUnit = ""; amsContext.AddTotbBillList(billList1); tbBillList billList2 = new tbBillList(); billList2.iBillNo = serialNo.iSerialNo; billList2.iCount = 1; billList2.iNO = 2; billList2.nCharge = Convert.ToDecimal(iExtraFee); billList2.nPrice = Convert.ToDecimal(iExtraFee); billList2.nRate = 1; billList2.vcGoodsName = "赠款"; billList2.vcUnit = ""; amsContext.AddTotbBillList(billList2); billInvoice = new tbBillInvoice(); billInvoice.dCharge = ig.nBalance + iFillFee + iExtraFee; billInvoice.dIgGet = 0; billInvoice.dIgValue = ig.iIgValue; billInvoice.dLastCharge = ig.nBalance; billInvoice.dLastIg = ig.iIgValue; billInvoice.dMealFee = 0; billInvoice.dServiceFee = 0; billInvoice.dSumFee = iFillFee + iExtraFee; billInvoice.dtCreateDate = DateTime.Now; billInvoice.dTotalFee = iFillFee; billInvoice.dtPrintDate = DateTime.Now; billInvoice.iBillNo = serialNo.iSerialNo; billInvoice.vcAssCardID = assCard.vcAssCardID; billInvoice.vcAssName = txtAssName.Text; billInvoice.vcBillType = "BI002"; billInvoice.vcEffFlag = "0"; billInvoice.vcOperName = GlobalParams.oper.vcOperName; billInvoice.vcOperID = GlobalParams.oper.vcOperID; billInvoice.vcPrintFlag = "1"; amsContext.AddTotbBillInvoice(billInvoice); Helper.Save(amsContext); //打印 会员卡充值帐单------------------- //打印帐单----------------------------------- List <tbBillInvoice> invoice = new List <tbBillInvoice>(); invoice.Add(billInvoice); List <tbBillList> list = new List <tbBillList>(); list.Add(billList1); list.Add(billList2); Helper.MyPrint(invoice, list); trans.Commit(); } } Helper.ShowInfo(this, "打印回执成功"); } catch (Exception ex) { billInvoice = null; 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); } }
private void btnPrint_Click(object sender, EventArgs e) { //打印回执 DbConnection conn = null; DbTransaction trans = null; try { if (ass == null || assCard == null || ig == null) { throw new Exception("请首先查询会员,并选择某个会员卡进行会员卡挂失操作"); } if (ass.vcAssState != ConstApp.AST_1) { throw new Exception("此会员未发卡无法挂失"); } if (assCard.cCardState != ConstApp.CST_1) { throw new Exception("此会员卡不在正常在用状态,无法挂失"); } using (AMSEntities amsContext = new AMSEntities()) { conn = amsContext.Connection; if (conn.State != ConnectionState.Open) { conn.Open(); } using (trans = conn.BeginTransaction(IsolationLevel.ReadCommitted)) { //事务数据操作或其它一致性操作 tbBillSerialNo serialNo = new tbBillSerialNo(); serialNo.vcFill = "0"; amsContext.AddTotbBillSerialNo(serialNo); Helper.Save(amsContext); tbBillList billList = new tbBillList(); billList.iBillNo = serialNo.iSerialNo; billList.iCount = 1; billList.iNO = 1; billList.nCharge = 0; billList.nPrice = 0; billList.nRate = 1; billList.vcGoodsName = "会员卡挂失"; //billList.vcUnit = ""; amsContext.AddTotbBillList(billList); billInvoice = new tbBillInvoice(); billInvoice.dCharge = 0;// ig.nBalance + iFillFee + iExtraFee; billInvoice.dIgGet = 0; billInvoice.dIgValue = ig.iIgValue; billInvoice.dLastCharge = ig.nBalance; billInvoice.dLastIg = ig.iIgValue; billInvoice.dMealFee = 0; billInvoice.dServiceFee = 0; billInvoice.dSumFee = 0; // iFillFee + iExtraFee; billInvoice.dtCreateDate = DateTime.Now; billInvoice.dTotalFee = 0; // iFillFee; billInvoice.dtPrintDate = DateTime.Now; billInvoice.iBillNo = serialNo.iSerialNo; billInvoice.vcAssCardID = assCard.vcAssCardID; billInvoice.vcAssName = txtAssName.Text; billInvoice.vcBillType = "BI004"; billInvoice.vcEffFlag = "0"; billInvoice.vcLinkSerial = null; billInvoice.vcOperName = GlobalParams.oper.vcOperName; billInvoice.vcOperID = GlobalParams.oper.vcOperID; billInvoice.vcPrintFlag = "1"; //billInvoice.vcReserve = ""; amsContext.AddTotbBillInvoice(billInvoice); Helper.Save(amsContext); //打印帐单----------------------------------- List <tbBillInvoice> invoice = new List <tbBillInvoice>(); invoice.Add(billInvoice); List <tbBillList> list = new List <tbBillList>(); list.Add(billList); Helper.MyPrint(invoice, list); trans.Commit(); } } Helper.ShowInfo(this, "打印回执成功,请输入会员卡密码,进行挂失操作"); } catch (Exception ex) { billInvoice = null; ErrorLog.Write(this, ex); } }
private void btnCardLose_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("会员卡密码不正确"); } if (ass == null || assCard == null || ig == null) { throw new Exception("请首先查询会员,并选择某个会员卡进行会员卡挂失操作"); } if (billInvoice == null) { 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)) { //事务数据操作或其它一致性操作 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 = billInvoice.iBillNo; amsContext.AddTotbBusiLog(busiLog); Helper.Save(amsContext); 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 = "2"; 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 = busiLog.iSerial; Helper.Save(amsContext); trans.Commit(); } } billInvoice = null; ass = null; assCard = null; ig = null; MessageBox.Show(this, "会员卡挂失成功", "提示"); } } catch (Exception ex) { ErrorLog.Write(this, ex); } }
private void btnExOk_Click(object sender, EventArgs e) { try { if (dgvIgEx.Rows.Count == 0) { throw new Exception("没有任何积分兑换记录,请重新输入!"); } string strBillNo = txtBillNo.Text.Trim(); if (strBillNo == "") { throw new Exception("请先打印回执!"); } int AssID = int.Parse(txtAssID.Text.Trim()); string strCardID = txtCardID.Text.Trim(); int IgSum = int.Parse(txtIgSum.Text.Trim()); bool continueflg = true; using (AMSEntities amsContext = new AMSEntities()) { tbAssociatorCard asscard1 = amsContext.tbAssociatorCard.FirstOrDefault(ac => ac.iAssID == AssID && ac.vcAssCardID == strCardID); while (continueflg) { frmInputBox inbox = new frmInputBox("请输入会员卡密码:", "PWD"); inbox.ShowDialog(); if (GlobalParams.strInputBoxMes == "Cancel") { GlobalParams.strInputBoxMes = ""; return; } else { if (GlobalParams.strInputBoxMes == "") { MessageBox.Show("会员卡密码不能为空,请重新输入!", "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Error); } else { if (asscard1 == null) { MessageBox.Show("会员信息有误,请重试!", "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Error); } if (GlobalParams.strInputBoxMes != asscard1.vcAssPwd) { MessageBox.Show("输入的会员卡密码错误,请重试!", "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Error); } else { continueflg = false; } } } } tbIntegral intg1 = amsContext.tbIntegral.FirstOrDefault(ig => ig.iAssID == AssID && ig.vcAssCardID == strCardID); if (intg1 == null) { throw new Exception("获取会员卡积分错误,请重试!"); } if (intg1.iIgValue < IgSum) { throw new Exception("当前积分余额不足,请重新读卡后重试!"); } long billNo = long.Parse(strBillNo); tbBillInvoice bill1 = amsContext.tbBillInvoice.FirstOrDefault(bl => bl.iBillNo == billNo); if (bill1 == null) { throw new Exception("帐单不存在,请重试!"); } long igserialNo = 0; using (AMSEntities amscontext2 = new AMSEntities()) { tbIgSerialNo igserial1 = new tbIgSerialNo(); igserial1.vcFill = "0"; amscontext2.AddTotbIgSerialNo(igserial1); amscontext2.SaveChanges(); igserialNo = igserial1.iSerialNo; } DateTime dtoperdate = DateTime.Now; intg1.iIgValue = intg1.iIgValue - IgSum; ObjectStateEntry ose = amsContext.ObjectStateManager.GetObjectStateEntry(intg1); DataTable dtIgList = (DataTable)dgvIgEx.DataSource; int lastig = int.Parse(ose.OriginalValues["iIgValue"].ToString()); for (int i = 0; i < dtIgList.Rows.Count; i++) { tbIntegralLog intglog1 = new tbIntegralLog(); intglog1.iIgSerial = igserialNo; intglog1.iNo = i + 1; intglog1.iAssID = intg1.iAssID; intglog1.vcAssCardID = intg1.vcAssCardID; intglog1.iIgLast = lastig; intglog1.dtIgDate = dtoperdate; intglog1.vcIgName = dtIgList.Rows[i]["积分兑换项目"].ToString(); intglog1.vcIgType = "IG002"; intglog1.iIgGet = -(int.Parse(dtIgList.Rows[i]["兑换分值"].ToString())); intglog1.iIgArrival = lastig + intglog1.iIgGet; intglog1.iLinkCons = null; intglog1.vcOperID = GlobalParams.oper.vcOperID; intglog1.vcComments = dtIgList.Rows[i]["备注"].ToString(); amsContext.AddTotbIntegralLog(intglog1); lastig = (int)intglog1.iIgArrival; } bill1.vcLinkSerial = igserialNo; bill1.vcEffFlag = "1"; tbBusiLog busilog1 = new tbBusiLog(); busilog1.vcAssName = txtAssName.Text.Trim(); busilog1.vcAssCardID = intg1.vcAssCardID; busilog1.vcLinkSerial = igserialNo; busilog1.vcOperType = "OT013"; busilog1.vcOperID = GlobalParams.oper.vcOperID; busilog1.vcOperName = GlobalParams.oper.vcOperName; busilog1.dtOperDate = dtoperdate; busilog1.iAssID = intg1.iAssID; amsContext.AddTotbBusiLog(busilog1); amsContext.SaveChanges(); btnExOk.Enabled = false; btnPrint.Enabled = false; btnAdd.Enabled = false; btnDel.Enabled = false; btnRead.Enabled = true; txtIgSum.Text = "0"; txtBillNo.Text = ""; txtAssID.Text = ""; txtCardID.Text = ""; txtAssName.Text = ""; txtCurCharge.Text = ""; txtCurIg.Text = ""; DataTable dtIgExList = new DataTable(); dtIgExList.Columns.Add("积分兑换项目"); dtIgExList.Columns.Add("兑换分值"); dtIgExList.Columns.Add("备注"); dgvIgEx.DataSource = dtIgExList; MessageBox.Show("本次积分兑换成功!", "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Information); } } catch (Exception ex) { ErrorLog.Write(this, ex, "积分兑换异常"); } }
private void btnPrint_Click(object sender, EventArgs e) { //需要将生成的发票流水写到txtBillNo文本框中 DbConnection conn = null; DbTransaction trans = null; try { if (dgvIgEx.Rows.Count <= 0) { throw new Exception("没有任何兑换记录"); } using (AMSEntities amsContext = new AMSEntities()) { string strAssCardID = txtCardID.Text.Trim(); int strAssID = int.Parse(txtAssID.Text.Trim()); decimal deTolIg = decimal.Parse(txtIgSum.Text.Trim()); tbIntegral intg1 = amsContext.tbIntegral.FirstOrDefault(ig => ig.iAssID == strAssID && ig.vcAssCardID == strAssCardID); if (intg1 == null) { throw new Exception("会员余额积分异常!"); } if (intg1.iIgValue < deTolIg) { throw new Exception("当前积分余额不足,请重新刷卡后再试!"); } conn = amsContext.Connection; if (conn.State != ConnectionState.Open) { conn.Open(); } using (trans = conn.BeginTransaction(IsolationLevel.ReadCommitted)) { //事务数据操作或其它一致性操作 tbBillSerialNo serialNo = new tbBillSerialNo(); serialNo.vcFill = "0"; amsContext.AddTotbBillSerialNo(serialNo); Helper.Save(amsContext); List <tbBillList> list = new List <tbBillList>(); DataTable dtIgList = (DataTable)dgvIgEx.DataSource; for (int i = 0; i < dtIgList.Rows.Count; i++) { tbBillList billList = new tbBillList(); billList.iBillNo = serialNo.iSerialNo;//lSerialNo; billList.iNO = i + 1; billList.vcGoodsName = dtIgList.Rows[i]["积分兑换项目"].ToString(); billList.iCount = 1; billList.vcUnit = ""; billList.nPrice = decimal.Parse(dtIgList.Rows[i]["兑换分值"].ToString()); billList.nRate = 1; billList.nCharge = decimal.Parse(dtIgList.Rows[i]["兑换分值"].ToString()); amsContext.AddTotbBillList(billList); list.Add(billList); } DateTime dtoperdate = DateTime.Now; tbBillInvoice billInvoice = new tbBillInvoice(); billInvoice.iBillNo = serialNo.iSerialNo; billInvoice.vcAssName = txtAssName.Text.Trim(); billInvoice.vcAssCardID = strAssCardID; billInvoice.dtCreateDate = dtoperdate; billInvoice.dtPrintDate = dtoperdate; billInvoice.dLastCharge = intg1.nBalance; billInvoice.dLastIg = intg1.iIgValue; billInvoice.vcOperID = GlobalParams.oper.vcOperID; billInvoice.vcOperName = GlobalParams.oper.vcOperName; billInvoice.dSumFee = deTolIg; billInvoice.dServiceFee = 0; billInvoice.dMealFee = 0; billInvoice.dTotalFee = deTolIg; billInvoice.dCharge = intg1.nBalance; billInvoice.dIgValue = (decimal)intg1.iIgValue - deTolIg; billInvoice.dIgGet = -deTolIg; billInvoice.vcPrintFlag = "1"; billInvoice.vcBillType = "BI003"; billInvoice.vcEffFlag = "0"; amsContext.AddTotbBillInvoice(billInvoice); Helper.Save(amsContext); List <tbBillInvoice> invoice = new List <tbBillInvoice>(); invoice.Add(billInvoice); Helper.MyPrint(invoice, list); trans.Commit(); txtBillNo.Text = serialNo.iSerialNo.ToString(); } } cmbIgEXGoods.Enabled = false; txtComments.Enabled = false; btnAdd.Enabled = false; btnDel.Enabled = false; btnPrint.Enabled = false; btnRead.Enabled = false; btnExOk.Enabled = true; Helper.ShowInfo(this, "打印回执成功"); } catch (Exception ex) { ErrorLog.Write(this, ex, "打印异常"); } }
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(); } } }
private void btnReprint_Click(object sender, EventArgs e) { try { if (dgvResult.SelectedRows.Count != 1) { throw new Exception("请先选中一条帐单记录"); } string strBillNo = dgvResult.SelectedRows[0].Cells[0].Value.ToString().Trim(); long lbillno = 0; if (strBillNo == "") { throw new Exception("帐单流水有误"); } else { lbillno = long.Parse(strBillNo); } using (AMSEntities amsContext = new AMSEntities()) { tbBillInvoice bl1 = amsContext.tbBillInvoice.FirstOrDefault(a => a.iBillNo == lbillno); var querylist = from a in amsContext.tbBillList where a.iBillNo == lbillno select a; if (bl1 == null || querylist == null) { throw new Exception("获取帐单信息出错"); } List <tbBillList> list = new List <tbBillList>(); foreach (var dr in querylist) { tbBillList billList = new tbBillList(); billList.iBillNo = dr.iBillNo; billList.iNO = dr.iNO; billList.vcGoodsName = dr.vcGoodsName; billList.iCount = dr.iCount; billList.vcUnit = dr.vcUnit; billList.nPrice = dr.nPrice; billList.nRate = dr.nRate; billList.nCharge = dr.nCharge; list.Add(billList); } tbBillInvoice billInvoice = new tbBillInvoice(); billInvoice.iBillNo = bl1.iBillNo; billInvoice.vcAssName = bl1.vcAssName; billInvoice.vcAssCardID = bl1.vcAssCardID; billInvoice.dtCreateDate = bl1.dtCreateDate; billInvoice.dtPrintDate = bl1.dtPrintDate; billInvoice.dLastCharge = bl1.dLastCharge; billInvoice.dLastIg = bl1.dLastIg; billInvoice.vcLinkSerial = bl1.vcLinkSerial; billInvoice.vcOperID = bl1.vcOperID; billInvoice.vcOperName = bl1.vcOperName; billInvoice.dSumFee = bl1.dSumFee; billInvoice.dServiceFee = bl1.dServiceFee; billInvoice.dMealFee = bl1.dMealFee; billInvoice.dTotalFee = bl1.dTotalFee; billInvoice.dCharge = bl1.dCharge; billInvoice.dIgValue = bl1.dIgValue; billInvoice.dIgGet = bl1.dIgGet; billInvoice.vcPrintFlag = bl1.vcPrintFlag; billInvoice.vcBillType = bl1.vcBillType; billInvoice.vcEffFlag = bl1.vcEffFlag; List <tbBillInvoice> invoice = new List <tbBillInvoice>(); invoice.Add(billInvoice); Helper.MyPrint(invoice, list); bl1.vcPrintFlag = (int.Parse(bl1.vcPrintFlag) + 1).ToString(); bl1.dtPrintDate = DateTime.Now; Helper.Save(amsContext); } Helper.ShowInfo(this, "重新打印帐单成功"); } catch (Exception ex) { ErrorLog.Write(this, ex, "打印异常"); } }