Пример #1
0
 // Method Setting Draw Distribution
 public void SetDistribution(PrizeTierDistribution distribution)
 {
     if (distribution != null)
     {
         Distribution = distribution;
     }
 }
Пример #2
0
 // Constructor
 public Draw()
 {
     id++;
     ID           = id;
     DrawResults  = new List <int>();
     Tickets      = new List <LotteryTicket>();
     Distribution = new PrizeTierDistribution();
 }
Пример #3
0
        // Method setting Prize Money Categories for each draw
        public void SetPrizeTierDistribution()
        {
            decimal previousMoneyBank = 0;
            decimal moneyDistributed  = 0;
            decimal prize             = 0;
            decimal moneyLeft         = 0;
            decimal moneyLeftSum      = 0;
            decimal charityMoney      = 0;
            decimal moneyPerTicket    = 0;

            try
            {
                foreach (Draw draw in Draws)
                {
                    draw.SetMoneyBank(previousMoneyBank);

                    var distribution = new PrizeTierDistribution();

                    distribution.SetPrizeTiers(draw);
                    draw.SetDistribution(distribution);

                    foreach (PrizeTier prizeTier in draw.Distribution.PrizeTiers)
                    {
                        prize = prizeTier.PrizeMoney;

                        if (prizeTier.Tickets.Count != 0)
                        {
                            moneyDistributed = prize;
                            moneyPerTicket   = (moneyDistributed / prizeTier.Tickets.Count);
                        }
                        else
                        {
                            moneyDistributed = 0;
                            moneyPerTicket   = 0;
                        }

                        prizeTier.SetMoneyDistributed(moneyDistributed);

                        prizeTier.Tickets.ForEach(t => t.AddWinningAmount(moneyPerTicket));

                        moneyLeft     = prize - moneyDistributed;
                        moneyLeftSum += moneyLeft;
                    }

                    charityMoney = draw.MoneyBank * 0.07m;
                    distribution.AddCharityMoney(charityMoney);

                    if (draw.MoneyBank <= Draw.MaxMoneyBank)
                    {
                        previousMoneyBank = moneyLeftSum - charityMoney;
                    }
                    else
                    {
                        moneyLeft         = 0;
                        moneyLeftSum      = 0;
                        previousMoneyBank = 0;
                    }
                }
            }
            catch (ArgumentNullException ex)
            {
                Console.WriteLine(ex.Message);
            }
        }