Exemplo n.º 1
0
 private void btnCardLose_Click(object sender, EventArgs e)
 {
     try
     {
         if (dataGridView1.SelectedRows.Count > 0)
         {
             vwAssCard        ass1    = dataGridView1.SelectedRows[0].DataBoundItem as vwAssCard;
             tbAssociator     ass     = null;
             tbAssociatorCard assCard = null;
             tbIntegral       ig      = null;
             using (AMSEntities amsContext = new AMSEntities())
             {
                 //数据操作
                 ass     = amsContext.tbAssociator.FirstOrDefault(a => a.iAssID == ass1.iAssID);
                 assCard = amsContext.tbAssociatorCard.FirstOrDefault(a => a.iAssID == ass1.iAssID && a.vcAssCardID == ass1.vcAssCardID);
                 ig      = amsContext.tbIntegral.FirstOrDefault(i => i.iAssID == ass1.iAssID && i.vcAssCardID == ass1.vcAssCardID);
             }
             if (ass == null)
             {
                 throw new Exception("未找到会员信息");
             }
             if (assCard == null)
             {
                 throw new Exception("未找到会员卡信息");
             }
             if (assCard.cCardState != ConstApp.CST_1)
             {
                 throw new Exception("此会员卡无法做挂失操作");
             }
             if (ass.vcAssState != ConstApp.AST_1)
             {
                 throw new Exception("此会员无法做挂失操作");
             }
             if (ig == null)
             {
                 throw new Exception("获取会员积分信息错误无法做挂失");
             }
             frmCardLose cardLose = new frmCardLose();
             cardLose.ass        = ass;
             cardLose.assCard    = assCard;
             cardLose.ig         = ig;
             cardLose.ControlBox = false;
             cardLose.ShowDialog();
         }
         else
         {
             Helper.ShowInfo(this, "请查询或搜索会员,并选择会员");
         }
     }
     catch (Exception ex)
     {
         ErrorLog.Write(this, ex);
     }
 }
Exemplo n.º 2
0
        private void btnReadCard_Click(object sender, EventArgs e)
        {
            int ret = 0;

            try
            {
                //从设备读取卡号信息
                //开始卡操作----------------------------------
                string strCardNo = "";
                ret = Helper.ReadCard(ref strCardNo);
                if (ret != 0)
                {
                    throw new Exception("卡操作异常");
                }
                //strCardNo = "00106";
                txtAssCardID.Text = strCardNo;
                if (string.IsNullOrEmpty(txtAssCardID.Text))
                {
                    throw new Exception("请读取卡号");
                }

                using (AMSEntities amsContext = new AMSEntities())
                {
                    //数据操作
                    assCard = amsContext.tbAssociatorCard.FirstOrDefault(a => a.vcAssCardID == txtAssCardID.Text && a.cCardState == "1");
                    if (assCard == null)
                    {
                        throw new Exception("该会员卡信息不存在,或不在正常使用状态,请重试!");
                    }
                    ass = amsContext.tbAssociator.FirstOrDefault(a => a.iAssID == assCard.iAssID);
                    if (ass == null)
                    {
                        throw new Exception("该会员卡的会员资料不存在,请检查!");
                    }
                    ig = amsContext.tbIntegral.FirstOrDefault(i => i.iAssID == assCard.iAssID && i.vcAssCardID == assCard.vcAssCardID);
                    if (ig == null)
                    {
                        throw new Exception("获取会员卡积分错误,请重试!");
                    }
                }
                //txtAssCardID.Text = assCard.vcAssCardID;
                txtAssName.Text = ass.vcAssName;
                txtBalance.Text = ig.nBalance.ToString();
                txtFillFee.Focus();
            }
            catch (Exception ex)
            {
                ErrorLog.Write(this, ex);
                Helper.ShowError(this, Helper.PutCardError(ret));
            }
        }
Exemplo n.º 3
0
        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();
            }
        }
Exemplo n.º 4
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();
            }
        }
Exemplo n.º 5
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);
            }
        }
Exemplo n.º 6
0
        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);
            }
        }
Exemplo n.º 7
0
        private void btnCardFree_Click(object sender, EventArgs e)
        {
            DbConnection  conn  = null;
            DbTransaction trans = null;

            try
            {
                if (dataGridView1.SelectedRows.Count > 0)
                {
                    vwAssCard ass1 = dataGridView1.SelectedRows[0].DataBoundItem as vwAssCard;
                    if (ass1.cCardState != ConstApp.CST_2)
                    {
                        throw new Exception("此会员卡无法做解挂操作");
                    }
                    using (AMSEntities amsContext = new AMSEntities())
                    {
                        conn = amsContext.Connection;
                        if (conn.State != ConnectionState.Open)
                        {
                            conn.Open();
                        }

                        using (trans = conn.BeginTransaction(IsolationLevel.ReadCommitted))
                        {
                            //事务数据操作或其它一致性操作


                            tbAssociator     ass     = amsContext.tbAssociator.FirstOrDefault(a => a.iAssID == ass1.iAssID);
                            tbAssociatorCard assCard = amsContext.tbAssociatorCard.FirstOrDefault(a => a.iAssID == ass1.iAssID && a.vcAssCardID == ass1.vcAssCardID);
                            tbIntegral       ig      = amsContext.tbIntegral.FirstOrDefault(i => i.vcAssCardID == assCard.vcAssCardID && i.iAssID == assCard.iAssID);

                            if (ass == null)
                            {
                                throw new Exception("未找到会员信息");
                            }
                            if (assCard == null)
                            {
                                throw new Exception("未找到会员卡信息");
                            }

                            if (ig == null)
                            {
                                throw new Exception("获取会员卡积分错误,请重试");
                            }
                            string strInfo = "会员卡号:" + assCard.vcAssCardID
                                             + "\n会员姓名:" + ass.vcAssName
                                             + "\n当前余额:" + ig.nBalance
                                             + "\n身份证号:" + ass.vcAssNbr
                                             + "\n公司名称:" + ass.vcCompanyName;
                            if (DialogResult.Yes == MessageBox.Show(this, strInfo, "解挂信息确认", MessageBoxButtons.YesNo, MessageBoxIcon.Information))
                            {
                                assCard.cCardState    = ConstApp.CST_1;
                                assCard.dtCardExpDate = null;
                                assCard.vcOperID      = GlobalParams.oper.vcOperID;
                                assCard.dtOperDate    = DateTime.Now;

                                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  = "OT014";
                                //busiLog.vcLinkSerial = billInvoice.iBillNo;
                                amsContext.AddTotbBusiLog(busiLog);
                                Helper.Save(amsContext);
                                trans.Commit();
                                Helper.ShowInfo(this, "会员卡解挂成功");
                            }
                        }
                    }
                }
                else
                {
                    Helper.ShowInfo(this, "请查询或搜索会员,并选择会员");
                }
            }
            catch (Exception ex)
            {
                ErrorLog.Write(this, ex);
            }
            finally
            {
                if (conn != null)
                {
                    conn.Close();
                }
            }
        }
Exemplo n.º 8
0
        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();
                }
            }
        }
Exemplo n.º 9
0
        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);
            }
        }
Exemplo n.º 10
0
        private void btnRead_Click(object sender, EventArgs e)
        {
            int ret = 0;

            try
            {
                //调用读卡函数
                string strAssCardID = "";
                ret = Helper.ReadCard(ref strAssCardID);
                //strAssCardID = "00104";//测试用

                if (ret != 0)
                {
                    throw new Exception("卡操作异常");
                }

                if (strAssCardID == "")
                {
                    throw new Exception("所刷卡卡号为空,请检查该卡片是否正确或被损坏!");
                }

                using (AMSEntities amsContext = new AMSEntities())
                {
                    tbAssociatorCard asscard1 = amsContext.tbAssociatorCard.FirstOrDefault(ac => ac.vcAssCardID == strAssCardID);
                    if (asscard1 == null)
                    {
                        throw new Exception("该会员卡信息不存在,请检查!");
                    }
                    if (asscard1.cCardState != "1")
                    {
                        throw new Exception("该会员卡处于非正常在用状态,不能进行积分兑换!");
                    }
                    tbIntegral intg1 = amsContext.tbIntegral.FirstOrDefault(ig => ig.iAssID == asscard1.iAssID && ig.vcAssCardID == asscard1.vcAssCardID);
                    if (intg1 == null)
                    {
                        throw new Exception("获取会员卡余额和积分错误,请重试!");
                    }
                    tbAssociator ass1 = amsContext.tbAssociator.FirstOrDefault(a => a.iAssID == asscard1.iAssID);
                    if (ass1 == null)
                    {
                        throw new Exception("会员基本信息不存在,请重试!");
                    }
                    string     strGoodsCode = cmbIgEXGoods.SelectedValue.ToString();
                    tbCommCode IgExGoods1   = amsContext.tbCommCode.FirstOrDefault(cc => cc.vcCommSign == "EX" && cc.vcCommCode == strGoodsCode);
                    if (IgExGoods1 == null)
                    {
                        txtIgExCost.Text = "";
                        throw new Exception("获取积分兑换项目异常!");
                    }
                    else
                    {
                        txtIgExCost.Text = IgExGoods1.vcComments;
                    }
                    txtCardID.Text    = asscard1.vcAssCardID;
                    txtAssID.Text     = asscard1.iAssID.ToString();
                    txtAssName.Text   = ass1.vcAssName;
                    txtCurCharge.Text = intg1.nBalance.ToString();
                    txtCurIg.Text     = intg1.iIgValue.ToString();
                    cmbIgEXGoods.Focus();
                    btnAdd.Enabled   = true;
                    btnDel.Enabled   = true;
                    btnPrint.Enabled = true;
                    btnRead.Enabled  = false;
                }
            }
            catch (Exception ex)
            {
                ErrorLog.Write(this, ex, "刷卡错误");
                Helper.ShowError(this, Helper.ReadCardError(ret));
            }
        }
Exemplo n.º 11
0
        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, "积分兑换异常");
            }
        }
Exemplo n.º 12
0
        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, "打印异常");
            }
        }
Exemplo n.º 13
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();
                }
            }
        }
Exemplo n.º 14
0
        private void frmCardAdd_Load(object sender, EventArgs e)
        {
            try
            {
                cmbAssLevel.DataSource    = GlobalParams.CommCode.Where(cc => cc.vcCommSign == ConstApp.AST).ToList();
                cmbAssLevel.DisplayMember = "vcCommName";
                cmbAssLevel.ValueMember   = "vcCommCode";

                cmbCardState.DataSource    = GlobalParams.CommCode.Where(cc => cc.vcCommSign == ConstApp.CST).ToList();
                cmbCardState.DisplayMember = "vcCommName";
                cmbCardState.ValueMember   = "vcCommCode";

                List <tbCommCode> agf = GlobalParams.CommCode.Where(cc => cc.vcCommSign == ConstApp.AGF).ToList <tbCommCode>();
                if (agf.Count < 1)
                {
                    throw new Exception("补发卡工本费参数有误,请检查参数设置!");
                }
                tbCommCode ccagf = agf[0];
                if (!Helper.IsNum(ccagf.vcCommCode.Trim()))
                {
                    throw new Exception("补发卡工本费参数有误,请检查参数设置!");
                }
                dBusiFee = Convert.ToDecimal(ccagf.vcCommCode.Trim());
                if (string.IsNullOrEmpty(AssCardID))
                {
                    throw new Exception("请首先查询选择可进行补发卡的会员卡信息");
                }
                lblAgf.Text = dBusiFee.ToString();
                using (AMSEntities amsContext = new AMSEntities())
                {
                    assCard = amsContext.tbAssociatorCard.FirstOrDefault(ac => ac.vcAssCardID == AssCardID && ac.iAssID == AssID);
                    if (assCard == null)
                    {
                        throw new Exception("未找到相应的会员卡信息,请重试");
                    }
                    ass = amsContext.tbAssociator.FirstOrDefault(a => a.iAssID == AssID);
                    if (ass == null)
                    {
                        throw new Exception("未找到相应的会员信息,请重试");
                    }
                    ig = amsContext.tbIntegral.FirstOrDefault(i => i.iAssID == AssID && i.vcAssCardID == AssCardID);
                    txtAssCardID.Text = assCard.vcAssCardID;
                    txtAssName.Text   = ass.vcAssName;
                    if (ig != null)
                    {
                        txtBalance.Text = ig.nBalance.ToString();
                        txtIg.Text      = ig.iIgValue.ToString();
                    }
                    cmbAssLevel.SelectedValue  = ass.vcAssState;
                    cmbCardState.SelectedValue = assCard.cCardState;

                    dtpPutCardDate.Value = Convert.ToDateTime(assCard.dtCardPutDate);
                    dtpExpDate.Value     = Convert.ToDateTime(assCard.dtCardExpDate);
                }
            }
            catch (Exception ex)
            {
                btnPrint.Enabled   = false;
                btnCardAdd.Enabled = false;
                lblCardAdd.Visible = false;
                txtCardAdd.Visible = false;
                ErrorLog.Write(this, ex);
            }
        }