コード例 #1
0
        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();
            }
        }
コード例 #2
0
ファイル: frmAssIgExchange.cs プロジェクト: zhenghua75/ams
        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, "积分兑换异常");
            }
        }