コード例 #1
0
ファイル: Contest.cs プロジェクト: dovanduy/titan
        /// <summary>
        /// Gets 7 top members list for current contest
        /// 1st = [0]
        /// 2nd = [1]
        /// 3rd = [2]
        /// etc.
        /// </summary>
        public List <string> GetTopMembersList(int HowMany = 7)
        {
            List <string> result = new List <string>();

            //var AllParticipants = TableHelper.SelectRows<ContestParticipant>
            //    (TableHelper.MakeDictionary("ContestId", this.Id));

            var AllParticipants = GetAllMembersParticipating();

            AllParticipants.Sort(Comparison);

            for (int i = 0; i < HowMany; ++i)
            {
                if (AllParticipants.Count > i && AllParticipants[i].Points.GetRealTotals() > 0)
                {
                    result.Add(AllParticipants[i].Username + " <span style=\"font-size:8px\">(" +
                               ContestManager.GetActionProperObject(Type, AllParticipants[i].Points).ToString() + ") "
                               + AllParticipants[i].LatestAction.ToShortDateString() + "</span>");
                }
                else
                {
                    result.Add("-");
                }
            }

            return(result);
        }
コード例 #2
0
        public static string ReparseId(string input)
        {
            int id1 = input.IndexOf("%");

            string    id    = input[id1 + 1].ToString();
            PrizeType pType = (PrizeType)Convert.ToInt32(id);
            string    text  = input.Replace("%" + id + "%", ContestManager.GetPrizeName(pType));

            return(text);
        }
コード例 #3
0
        /// <summary>
        /// Gets 3 latest winners of this contest type
        /// 1st = [0]
        /// 2nd = [1]
        /// 3rd = [2]
        /// </summary>
        public static List <string> GetLastestWinners(ContestType Type)
        {
            List <string> result = new List <string>();

            var LatestWinners = TableHelper.SelectRows <ContestLatestWinners>
                                    (TableHelper.MakeDictionary("Type", (int)Type));

            if (LatestWinners.Count > 0)
            {
                string res1 = LatestWinners[0].Winner1;
                string res2 = LatestWinners[0].Winner2;
                string res3 = LatestWinners[0].Winner3;

                try
                {
                    res1 = ContestManager.ReparseId(res1);
                }
                catch (Exception ex) { }

                try
                {
                    res2 = ContestManager.ReparseId(res2);
                }
                catch (Exception ex) { }

                try
                {
                    res3 = ContestManager.ReparseId(res3);
                }
                catch (Exception ex) { }

                result.Add(res1);
                result.Add(res2);
                result.Add(res3);
            }
            else
            {
                result.Add("-"); result.Add("-"); result.Add("-");
            }

            return(result);
        }
コード例 #4
0
ファイル: Contest.cs プロジェクト: dovanduy/titan
 private string GeneratePrizeCode(Money Value)
 {
     return(" <b>" + ContestManager.GetPrizeProperObject(RewardType, Value).ToString() + "</b> ["
            + ContestManager.GetPrizeName(RewardType) + "]");
 }
コード例 #5
0
ファイル: Contest.cs プロジェクト: dovanduy/titan
        /// <summary>
        /// Finishes the contest, no need to save
        /// </summary>
        public void Finish()
        {
            try
            {
                this.Status = ContestStatus.Finished;

                //Pick up the winners
                //var AllParticipants = TableHelper.SelectRows<ContestParticipant>
                //   (TableHelper.MakeDictionary("ContestId", this.Id));
                var AllParticipants = GetAllMembersParticipating();

                AllContestLatestWinners HistoryContestData = new AllContestLatestWinners();
                HistoryContestData.ContestId            = this.Id;
                HistoryContestData.NumberOfParticipants = AllParticipants.Count;

                AllParticipants.Sort(Comparison);

                string winner1 = "-";
                string winner2 = "-";
                string winner3 = "-";

                if (AllParticipants.Count > 0)
                {
                    winner1 = "OK";
                }
                if (AllParticipants.Count > 1)
                {
                    winner2 = "OK";
                }
                if (AllParticipants.Count > 2)
                {
                    winner3 = "OK";
                }

                Money ZeroMoney = new Money(0);

                if (winner1 == "OK")
                {
                    if (AllParticipants[0].Points == ZeroMoney)
                    {
                        winner1 = "-";
                    }
                    else
                    {
                        Member Winner1 = new Member(AllParticipants[0].Username);
                        ContestManager.AwardMember(Winner1, this.RewardType, this.Prize1Value, 1);
                        winner1 = Winner1.Name + ": " + ContestManager.GetPrizeProperObject(this.RewardType, this.Prize1Value).ToString() + " [%" + (int)this.RewardType + "%]";
                    }
                }
                if (winner2 == "OK")
                {
                    if (AllParticipants[1].Points == ZeroMoney)
                    {
                        winner2 = "-";
                    }
                    else
                    {
                        Member Winner2 = new Member(AllParticipants[1].Username);
                        ContestManager.AwardMember(Winner2, this.RewardType, this.Prize2Value, 2);
                        winner2 = Winner2.Name + ": " + ContestManager.GetPrizeProperObject(this.RewardType, this.Prize2Value).ToString() + " [%" + (int)this.RewardType + "%]";
                    }
                }
                if (winner3 == "OK")
                {
                    if (AllParticipants[2].Points == ZeroMoney)
                    {
                        winner3 = "-";
                    }
                    else
                    {
                        Member Winner3 = new Member(AllParticipants[2].Username);
                        ContestManager.AwardMember(Winner3, this.RewardType, this.Prize3Value, 3);
                        winner3 = Winner3.Name + ": " + ContestManager.GetPrizeProperObject(this.RewardType, this.Prize3Value).ToString() + " [%" + (int)this.RewardType + "%]";
                    }
                }

                //Save contest history data
                foreach (var elem in AllParticipants)
                {
                    HistoryContestData.Participants += elem.Username + "(" + elem.Points.GetRealTotals().ToString() + "), ";
                }
                HistoryContestData.Winner1 = winner1;
                HistoryContestData.Winner2 = winner2;
                HistoryContestData.Winner3 = winner3;
                HistoryContestData.Save();

                ContestLatestWinners.AddAndClean(this.Type, winner1, winner2, winner3);
                this.Save();

                //Clean the contest data (ContestParticipants)
                TableHelper.DeleteRows <ContestParticipant>(TableHelper.MakeDictionary("ContestId", this.Id));
            }
            catch (Exception ex)
            {
                ErrorLogger.Log(ex);
            }
        }