Beispiel #1
0
        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);
            }
        }
Beispiel #2
0
        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();
                }
            }
        }