Exemple #1
0
        /// <summary>
        ///     添加奖品
        /// </summary>
        /// <param name="prizebetting">奖品信息</param>
        /// <returns>业务操作结果</returns>
        public OperationResult Add(PrizePhoto prizephoto)
        {
            int rcount = PrizePhotoRepository.Insert(prizephoto);

            if (rcount > 0)
            {
                return(new OperationResult(OperationResultType.Success, "添加奖品图片成功。", prizephoto));
            }
            else
            {
                return(new OperationResult(OperationResultType.Warning, "添加奖品图片失败。"));
            }
        }
Exemple #2
0
        private void button1_Click(object sender, EventArgs e)
        {
            var memberSet = AccountContract.Members.ToList();

            // 构造奖品
            List <Prize> prizelist = new List <Prize>();

            for (int i = 1; i < 30; i++)
            {
                Random rnd   = new Random((int)DateTime.Now.Ticks + i);
                var    prize = new Prize()
                {
                    Name = "奖品名称奖品名称" + i.ToString(), Description = "奖品描述奖品描述奖品描述奖品描述奖品描述奖品描述奖品描述奖品描述奖品描述奖品描述" + i.ToString(), AddDate = DateTime.Now
                };
                var memberArray = memberSet.ToArray();
                var member      = memberArray[rnd.Next(0, memberArray.Length)];
                prize.Member = member;
                //prize.Photo = StreamUtil.Base64ToBytes(StaticStrings.demoImageBase64String);
                prizelist.Add(prize);
            }
            PrizeRepository.Insert(prizelist);

            //DbSet<Prize> prizeSet = context.Set<Prize>();
            //prizeSet.AddOrUpdate(prizelist.ToArray());
            //context.SaveChanges();

            // 构造奖品
            List <PrizePhoto> photos = new List <PrizePhoto>();
            var prizeArray           = prizelist.ToArray();

            for (int i = 0; i < prizelist.Count; i++)
            {
                Random     rnd    = new Random((int)DateTime.Now.Ticks + i);
                PrizePhoto pphoto = new PrizePhoto
                {
                    Name  = "e26b4610-58fb-4ceb-ac72-a3f700c7c301.jpg",
                    Prize = prizeArray[rnd.Next(0, prizeArray.Length)]
                };

                photos.Add(pphoto);
            }
            PrizePhotoRepository.Insert(photos);
            //DbSet<PrizePhoto> pPhotoSet = context.Set<PrizePhoto>();
            //pPhotoSet.AddOrUpdate(photos.ToArray());
            //context.SaveChanges();

            var prizes = PrizeContract.Prizes.ToList();

            var prizeOrdersCount          = PrizeOrderContract.PrizeOrders.Count();
            List <PrizeOrder> prizeOrders = new List <PrizeOrder>();
            bool poAdded = false;

            if (prizeOrdersCount == 0)
            {
                for (int i = 0; i < prizes.Count; i++)
                {
                    Random rnd = new Random((int)DateTime.Now.Ticks + i);
                    //var member = AccountContract.Members.Skip(rnd.Next(0, prizesCount)).Take(1);
                    var prize      = prizes[i];
                    var prizeOrder = new PrizeOrder()
                    {
                        Prize         = prize,
                        RevealTypeNum = rnd.Next(3) + 1,
                        //RevealStateNum = rnd.Next(4) + 1,
                        RevealStateNum = (int)RevealState.UnDrawn,
                        SortOrder      = i + 1,
                        IsDeleted      = false,
                        AddDate        = DateTime.Now
                    };
                    switch (prizeOrder.RevealTypeNum)
                    {
                    case (int)RevealType.Timing:
                        prizeOrder.Extend = new PrizeOrderExtend()
                        {
                            LaunchTime    = DateTime.Now.AddMinutes(10),
                            MinLuckyCount = 1,
                            LuckyCount    = 5,
                            //,LuckyPercent = 2
                        };
                        break;

                    case (int)RevealType.Answer:
                        prizeOrder.Extend = new PrizeOrderExtend()
                        {
                            PrizeAsking = new PrizeAsking()
                            {
                                Question = "好声音冠军是谁?", Answer = "梁博"
                            },
                            MinLuckyCount = 1,
                            LuckyCount    = 5,
                            AnswerRevealConditionTypeNum = rnd.Next(2) + 1,
                            //,LuckyPercent = 2
                        };
                        switch (prizeOrder.Extend.AnswerRevealConditionTypeNum)
                        {
                        case (int)AnswerRevealConditionType.Timing:
                            prizeOrder.Extend.LaunchTime = DateTime.Now.AddMinutes(10);
                            break;

                        case (int)AnswerRevealConditionType.Quota:
                            prizeOrder.Extend.PoolCount = 50;
                            break;
                        }
                        break;

                    case (int)RevealType.Quota:
                        prizeOrder.Extend = new PrizeOrderExtend()
                        {
                            PoolCount     = 10,
                            MinLuckyCount = 1,
                            LuckyCount    = 5
                                            //,LuckyPercent = 2
                        };
                        break;
                    }

                    prizeOrders.Add(prizeOrder);
                }
                poAdded = true;
            }
            OperationResult result = new OperationResult(OperationResultType.NoChanged);

            if (poAdded)
            {
                result = PrizeOrderContract.Add(prizeOrders);
            }
            if (result.ResultType == OperationResultType.Success || !poAdded)
            {
                if (PrizeBettingContract.PrizeBettings.Count() == 0)
                {
                    var members = AccountContract.Members.OrderBy(po => po.Id).Skip(2).ToList();
                    var porders = PrizeOrderContract.PrizeOrders.ToList();

                    List <PrizeBetting> prizeBettings = new List <PrizeBetting>();
                    for (int i = 0; i < porders.Count; i++)
                    {
                        var prizeorder = porders[i];
                        for (int j = 0; j < members.Count; j++)
                        {
                            var member       = members[j];
                            var prizeBetting = new PrizeBetting()
                            {
                                PrizeOrder = prizeorder,
                                Member     = member,
                                Address    = "青岛市市南区江西路软件大厦",
                                Phone      = "18829876354",
                                IsDeleted  = false,
                                AddDate    = DateTime.Now
                            };
                            prizeBettings.Add(prizeBetting);
                        }
                    }
                    PrizeBettingContract.Add(prizeBettings);
                }
                MessageBox.Show("构造奖单数据成功");
                btnCreateData.Enabled = false;
            }
            else
            {
                MessageBox.Show(result.Message);
            }
        }