示例#1
0
        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();
        }
示例#2
0
        private void addMember()
        {
            string msg;

            if (!Validate(out msg))
            {
                Helper.ShowErrorMsg(msg);
                return;
            }
            DateTime dtNow = DateTime.Now;

            this.Member.UserId     = this.Oper.UserId;
            this.Member.CreateDate = dtNow;
            this.Member.DeptId     = this.Dept.DeptId;

            int oldcount = Uow.Cards.GetAll().Where(w => w.CardNo == this.CardNo).Count();

            if (oldcount > 0)
            {
                Helper.ShowErrorMsg(this.CardNo + ":卡号已存在");
                return;
            }
            this.Card.CardNo = this.CardNo;
            if (this.IsCardLevelAuto)
            {
                var cardLevel = Uow.CardLevels.GetAll().Where(w => w.IsDefault &&
                                                              (w.DeptId == this.Dept.DeptId || w.DeptId == Guid.Empty)).OrderBy(o => o.Code).FirstOrDefault();
                if (cardLevel == null)
                {
                    Helper.ShowErrorMsg("请设置无积分时的默认卡级别");
                    return;
                }
                this.Card.CardLevel = cardLevel.Id;
            }
            else
            {
                this.Card.CardLevel = this.SelectedCardLevel.Id;
            }
            this.Card.CardType   = this.SelectedCardType.Id;
            this.Card.CreateDate = dtNow;
            this.Card.DeptId     = this.Dept.DeptId;
            this.Card.UserId     = this.Oper.UserId;

            this.Member.MemberName = this.MemberName;

            if (!this.SelectedCardType.IsVirtual)
            {
                StringBuilder sb = new StringBuilder(33);
                sb.Append(this.CardNo);
//#if DEBUG
//                int st = 0;
//#else
                int st = CardRef.CoolerPutCard(sb);
//#endif
                if (st != 0)
                {
                    Helper.ShowErrorMsg(CardRef.GetStr(st));
                    return;
                }
            }
            using (TransactionScope transaction = new TransactionScope())
            {
                Uow.Members.Add(this.Member);
                Uow.Commit();

                this.Card.Member = this.Member.Id;
                Uow.Cards.Add(this.Card);
                Uow.Commit();

                DXInfo.Models.MembersLog memberLog = Mapper.Map <DXInfo.Models.Members, DXInfo.Models.MembersLog>(Member);
                memberLog.MemberId = Member.Id;
                Uow.MembersLog.Add(memberLog);

                DXInfo.Models.CardsLog cardsLog = Mapper.Map <DXInfo.Models.Cards, DXInfo.Models.CardsLog>(Card);
                cardsLog.CardId = Card.Id;
                Uow.CardsLog.Add(cardsLog);

                Uow.Commit();
                transaction.Complete();
            }
            if (this.SelectedCardType.IsMoney)
            {
                MessageBoxResult mr = MessageBox.Show("添加新会员成功,是否充值?", "充值提示", MessageBoxButton.YesNo, MessageBoxImage.Question);
                if (mr == MessageBoxResult.Yes)
                {
                    var cmp = ServiceLocator.Current.GetInstance <PutCardInMondeyUserControl>();
                    this.NavigationUserControl(cmp);
                }
            }
            else
            {
                Helper.ShowSuccMsg("添加新会员成功。");
            }
            this.InitObject();
        }