コード例 #1
0
ファイル: CardAddViewModel.cs プロジェクト: zhenghua75/DXInfo
        protected override void AfterSelectResult()
        {
            base.AfterSelectResult();
            if (this.SelectedResult == null)
            {
                return;
            }
            if (this.Detail == null)
            {
                this.Detail = new CardAddPageDetail();
            }
            dynamic c  = this.SelectedResult;//CardList.SelectedItem;
            Guid    id = c.Id;

            DXInfo.Models.Cards card = Uow.Cards.GetById(g => g.Id == id);
            var d = Uow.CardLevels.GetById(g => g.Id == card.CardLevel);

            if (d != null)
            {
                card.SecondCardNo = d.BeginLetter;
            }
            this.Detail.Card = card;

            DXInfo.Models.NameCode nc = Uow.NameCode.GetAll().Where(w => w.Type == "CostFee").FirstOrDefault();
            if (nc != null)
            {
                this.Detail.Cost = Convert.ToDecimal(nc.Value);
            }
        }
コード例 #2
0
ファイル: CardAddViewModel.cs プロジェクト: zhenghua75/DXInfo
        private void cardAdd()
        {
            //补卡
            if (string.IsNullOrWhiteSpace(Detail.Card.SecondCardNo))
            {
                Helper.ShowErrorMsg("请输入补卡卡号");
                return;
            }
            if (Detail.Card.CardLevel == Guid.Empty || Detail.Card.CardLevel == null)
            {
                Helper.ShowErrorMsg("请选择卡级别");
                return;
            }

            //DXInfo.Models.aspnet_CustomProfile user = this.Oper;
            //Guid userId = user.UserId;
            if (!ClientCommon.CheckUser(this.Oper))
            {
                return;
            }

            var c = Uow.Cards.GetById(g => g.Id == Detail.Card.Id);

            if (!ClientCommon.CheckCard(c))
            {
                return;
            }

            var d = Uow.CardLevels.GetById(g => g.Id == Detail.Card.CardLevel);

            if (d == null)
            {
                Helper.ShowErrorMsg("卡级别信息错误");
                return;
            }
            if (!string.IsNullOrEmpty(d.BeginLetter))
            {
                if (!Detail.Card.SecondCardNo.StartsWith(d.BeginLetter))
                {
                    Helper.ShowErrorMsg("卡号必须以" + d.BeginLetter + "字母开头");
                    return;
                }
            }
            var cardType = Uow.CardTypes.GetById(g => g.Id == Detail.Card.CardType);

            if (cardType == null)
            {
                Helper.ShowErrorMsg("卡型信息错误");
                return;
            }
            string strComment;
            string strCardNoRule = ClientCommon.CardNoRule(cardType, out strComment);

            if (!Regex.IsMatch(Detail.Card.SecondCardNo, strCardNoRule))
            {
                if (!string.IsNullOrEmpty(d.BeginLetter))
                {
                    Helper.ShowErrorMsg(strComment + ",且必须以" + d.BeginLetter + "字母开头");
                    return;
                }
                else
                {
                    Helper.ShowErrorMsg(strComment);
                    return;
                }
            }
            var c1 = Uow.Cards.GetAll().Where(w => w.CardNo == Detail.Card.SecondCardNo).FirstOrDefault();

            if (c1 != null)
            {
                Helper.ShowErrorMsg("卡号已存在");
                return;
            }

            StringBuilder sb = new StringBuilder(33);

            sb.Append(Detail.Card.SecondCardNo);
//#if DEBUG
//            int st = 0;
//#else
            int st = CardRef.CoolerPutCard(sb);

//#endif
            if (st != 0)
            {
                MessageBox.Show(CardRef.GetStr(st));
                return;
            }
            int value = Convert.ToInt32(Detail.Card.Balance * 100);

//#if !DEBUG
            st = CardRef.CoolerRechargeCard(sb, value);
//#endif
            //充值
            if (st != 0)
            {
                MessageBox.Show(CardRef.GetStr(st));
                return;
            }
            DateTime dtNow = DateTime.Now;

            using (TransactionScope transaction = new TransactionScope())
            {
                DXInfo.Models.Cards newcard = new DXInfo.Models.Cards();
                newcard.CardNo     = Detail.Card.SecondCardNo;
                newcard.CardLevel  = Detail.Card.CardLevel;
                newcard.CardType   = Detail.Card.CardType;
                newcard.CreateDate = dtNow;
                newcard.UserId     = this.Oper.UserId;
                newcard.DeptId     = this.Dept.DeptId;
                newcard.Balance    = Detail.Card.Balance;
                newcard.Member     = Detail.Card.Member;
                newcard.CardPwd    = Detail.Card.CardPwd;
                newcard.Comment    = c.Comment;
                Uow.Cards.Add(newcard);
                Uow.Commit();

                DXInfo.Models.CardsLog cardsLog = Mapper.Map <DXInfo.Models.Cards, DXInfo.Models.CardsLog>(newcard);
                cardsLog.CardId     = newcard.Id;
                cardsLog.CreateDate = dtNow;
                cardsLog.UserId     = this.Oper.UserId;
                cardsLog.DeptId     = this.Dept.DeptId;
                Uow.CardsLog.Add(cardsLog);


                c.SecondCardNo = Detail.Card.SecondCardNo;
                c.AddDate      = dtNow;
                c.AddDeptId    = this.Dept.DeptId;
                c.AddUserId    = this.Oper.UserId;
                c.Status       = 2;
                Uow.Cards.Update(c);

                DXInfo.Models.CardsLog cardsLog1 = Mapper.Map <DXInfo.Models.Cards, DXInfo.Models.CardsLog>(c);
                cardsLog1.CardId     = c.Id;
                cardsLog1.CreateDate = dtNow;
                cardsLog1.UserId     = this.Oper.UserId;
                cardsLog1.DeptId     = this.Dept.DeptId;
                Uow.CardsLog.Add(cardsLog1);

                DXInfo.Models.Recharges recharge = new DXInfo.Models.Recharges();
                recharge.Amount       = Detail.Card.Balance;
                recharge.Balance      = Detail.Card.Balance;
                recharge.CreateDate   = DateTime.Now;
                recharge.DeptId       = this.Dept.DeptId;
                recharge.UserId       = this.Oper.UserId;
                recharge.LastBalance  = 0;
                recharge.Donate       = 0;
                recharge.RechargeType = 1;
                recharge.Card         = newcard.Id;
                Uow.Recharges.Add(recharge);

                if (Detail.Cost > 0)
                {
                    recharge              = new DXInfo.Models.Recharges();
                    recharge.Amount       = Detail.Cost;
                    recharge.Balance      = 0;
                    recharge.CreateDate   = DateTime.Now;
                    recharge.DeptId       = this.Dept.DeptId;
                    recharge.UserId       = this.Oper.UserId;
                    recharge.LastBalance  = 0;
                    recharge.Donate       = 0;
                    recharge.RechargeType = 3;
                    recharge.Card         = newcard.Id;

                    Uow.Recharges.Add(recharge);
                }
                var qpt = Uow.CardPoints.GetAll().Where(w => w.Card == Detail.Card.Id);
                if (qpt.Count() > 0)
                {
                    decimal pt = qpt.Sum(s => s.Point);
                    if (pt != 0)
                    {
                        DXInfo.Models.CardPoints cp = new DXInfo.Models.CardPoints();
                        cp.Card       = newcard.Id;
                        cp.CreateDate = dtNow;
                        cp.DeptId     = this.Dept.DeptId;
                        cp.Point      = pt;
                        cp.UserId     = this.Oper.UserId;
                        cp.PointType  = 1;
                        Uow.CardPoints.Add(cp);
                    }
                }
                Uow.Commit();
                transaction.Complete();
            }
            MessageBox.Show("补卡成功");
            this.query();
            Detail = new CardAddPageDetail();
        }