Beispiel #1
0
        protected void ButtonSave_Click(object sender, EventArgs e)
        {
            //Check if all score textboxes have valid numbers entered.  If not, display error message.
            if (this.ucContestRound1.isRoundDataOk())
            {
                SaveEnteredGameResults();

                //Display final standings.

                if (m_currentContest == null)
                {
                    m_currentContest = (TableHockeyContest)Session["pgEditContestTable.m_currentContest"];
                }

                bool           isFinalRound = displayCurrentRound(m_nContestId, m_nCurrentRoundNumber);
                int            m_nNumberOfEndGamePlayers = (int)((m_currentContest.NumberOfPlayersToNextRound != null) && (m_currentContest.NumberOfPlayersToNextRound > 0) ? m_currentContest.NumberOfPlayersToNextRound : 100);
                TableViewModel m_tableViewModel          = new TableViewModel(m_nContestId, m_nCurrentRoundNumber);
                this.ucContestTable1.InitControl(m_tableViewModel.m_tableRows, isFinalRound, m_nNumberOfEndGamePlayers);
                Session["pgEditContestTable.m_nCurrentRoundNumber"] = m_nCurrentRoundNumber;
            }
            else
            {
                //Display error message.
                DisplayError();
            }
        }
Beispiel #2
0
        protected void ButtonSave_Click(object sender, EventArgs e)
        {
            //Check if all score textboxes have valid numbers entered.  If not, display error message.
            //Get scores from each end game uc and validate
            List <TableHockeyContestRound> m_enteredRounds = (List <TableHockeyContestRound>)Session["pgEditContestTableEndGame.m_rounds"];

            if (m_enteredRounds != null)
            {
                if (m_currentContest == null)
                {
                    m_currentContest = (TableHockeyContest)Session["pgEditContestTableEndGame.m_currentContest"];
                }
                Dictionary <int, int> m_dictPlayersToNextRound;
                if (ValidateEnteredEndGames(m_enteredRounds, out m_dictPlayersToNextRound))
                {
                    SaveEnteredGameResults();

                    //Display final standings.

                    if (m_currentContest == null)
                    {
                        m_currentContest = (TableHockeyContest)Session["pgEditContestTableEndGame.m_currentContest"];
                    }
                    //Force a re-get.
                    Session["pgEditContestTableEndGame.m_rounds"] = null;
                    bool isFinalRound = displayCurrentRound(m_nContestId, m_nCurrentRoundNumber);
                    Session["pgEditContestTableEndGame.m_nCurrentRoundNumber"] = m_nCurrentRoundNumber;
                }
                else
                {
                    //Display error message.
                    DisplayError();
                }
            }
        }
Beispiel #3
0
        //Generate contest rounds.
        private int calcNumberOfContestRounds(int i_nContestId)
        {
            //First, count the number of rounds to generate for particular contest.
            //If even amount of players n, and r repetitions, the number of rounds
            //will be r * (n - 1). TODO:  KOLLA UPP!!
            //If odd amount of players n, and r repetitions, the number of rounds
            //will be r * n.

            using (var context = new TableHockeyData.UHSSWEB_DEVEntities())
            {
                //Get contest details.
                TableHockeyContest m_contest = context.TableHockeyContest.First(c => c.ContestId == i_nContestId);
                int m_nNumberOfRepetitions   = m_contest.numberOfRounds;
                //Get players.
                var contestPlayersQuery = from p in context.TableHockeyPlayer
                                          join cp in context.TableHockeyContestPlayer on p.PlayerId equals cp.PlayerId
                                          where cp.ContestId == i_nContestId
                                          select new { p.PlayerId };

                int m_nPlayerCount = contestPlayersQuery.ToList().Count();

                //Determine number of rounds.
                int m_nNumberOfRounds = 0;
                if (!isOdd(m_nPlayerCount))
                {
                    m_nNumberOfRounds = m_nNumberOfRepetitions * (m_nPlayerCount - 1);
                }
                else
                {
                    m_nNumberOfRounds = m_nNumberOfRepetitions * m_nPlayerCount;
                }

                return(m_nNumberOfRounds);
            }
        }
Beispiel #4
0
        protected void ButtonNextRound_Click(object sender, EventArgs e)
        {
            //Get scores from each end game uc and validate
            List <TableHockeyContestRound> m_enteredRounds = (List <TableHockeyContestRound>)Session["pgEditContestTableEndGame.m_rounds"];

            if (m_enteredRounds != null)
            {
                if (m_currentContest == null)
                {
                    m_currentContest = (TableHockeyContest)Session["pgEditContestTableEndGame.m_currentContest"];
                }
                Dictionary <int, int> m_dictPlayersToNextRound;
                if (ValidateEnteredEndGames(m_enteredRounds, out m_dictPlayersToNextRound))
                {
                    SaveEnteredGameResults();
                    //Increment round number.
                    m_nCurrentRoundNumber++;
                    //Generate games for next round.
                    if (Session["pgEditContestTableEndGame.queueHandler"] != null)
                    {
                        TableHockeyEndGameQueueHandler m_queueHandler = (TableHockeyEndGameQueueHandler)Session["pgEditContestTableEndGame.queueHandler"];
                        m_queueHandler.nextRound(m_dictPlayersToNextRound);

                        //Clear round session.
                        Session["pgEditContestTableEndGame.m_rounds"] = null;
                        Session["ucEndGameSeries.m_round"]            = null;
                        Session["pgEditContestTableEndGame.m_nCurrentRoundNumber"] = m_nCurrentRoundNumber;
                        Session["pgEditContestTableEndGame.queueHandler"]          = m_queueHandler;
                        //Navigate to next round.
                        Response.Redirect("~/pgEditContestTableEndGame.aspx?ContestId=" + m_currentContest.ContestId);
                    }
                }
            }
        }
Beispiel #5
0
        protected void Page_Load(object sender, EventArgs e)
        {
            //Get contest id.
            if (!Page.IsPostBack)
            {
                m_nContestId = -1;
                m_sContestRoundPlaceholder = "Contest round [ROUND]"; //TODO:  Config setting!
                if (!String.IsNullOrEmpty(Request.QueryString["ContestId"]))
                {
                    m_nContestId = Convert.ToInt32(Request.QueryString["ContestId"]);
                    Session["pgEditContestTable.m_nContestId"] = m_nContestId;
                    //Get current contest
                    using (var context = new TableHockeyData.UHSSWEB_DEVEntities())
                    {
                        m_currentContest = context.TableHockeyContest.FirstOrDefault(i => i.ContestId == m_nContestId);
                    }
                    Session["pgEditContestTable.m_currentContest"] = m_currentContest;
                    //Find or regenerate contest rounds.
                    handleContestRounds(m_nContestId);
                    //Find or regenerate contest games.
                    handleContestGames(m_currentContest);
                    if (Session["pgEditContestTable.m_nCurrentRoundNumber"] != null)
                    {
                        m_nCurrentRoundNumber = (int)Session["pgEditContestTable.m_nCurrentRoundNumber"];
                    }
                    else
                    {
                        m_nCurrentRoundNumber = 1;
                    }
                    this.LabelContestHeader.Text = m_sContestRoundPlaceholder.Replace("[ROUND]", Convert.ToString(m_nCurrentRoundNumber));
                    //Init table user control
                    bool           isFinalRound = displayCurrentRound(m_nContestId, m_nCurrentRoundNumber);
                    int            m_nNumberOfEndGamePlayers = (int)((m_currentContest.NumberOfPlayersToNextRound != null) ? m_currentContest.NumberOfPlayersToNextRound : 100);
                    TableViewModel m_tableViewModel          = new TableViewModel(m_nContestId, m_nCurrentRoundNumber);
                    this.ucContestTable1.InitControl(m_tableViewModel.m_tableRows, false, m_nNumberOfEndGamePlayers);
                    Session["pgEditContestTable.m_nCurrentRoundNumber"] = m_nCurrentRoundNumber;
                }
                else
                {
                    Response.Redirect("~/pgMain.aspx");
                }
            }
            else
            {
                if (Session["pgEditContestTable.m_nCurrentRoundNumber"] != null)
                {
                    m_nCurrentRoundNumber = (int)Session["pgEditContestTable.m_nCurrentRoundNumber"];
                }
                else
                {
                    m_nCurrentRoundNumber = 1;
                }

                if (Session["pgEditContestTable.m_nContestId"] != null)
                {
                    m_nContestId = (int)Session["pgEditContestTable.m_nContestId"];
                }
            }
        }
 private void setContestHeader(int i_nContestId)
 {
     using (var context = new TableHockeyData.UHSSWEB_DEVEntities())
     {
         TableHockeyContest          m_contest          = context.TableHockeyContest.First(c => c.ContestId == i_nContestId);
         ViewModels.ContestViewModel m_contestViewModel = new ViewModels.ContestViewModel(m_contest);
         LabelContestHeader.Text      = m_contestViewModel.ContestHeader;
         LabelContestDescription.Text = m_contestViewModel.ContestDescription;
     }
 }
        private bool isPlayerOKToRemoveFromContest(int i_nPlayerId, int i_nContestId)
        {
            //Check for contest games for player.  Also check that contest is still open.

            using (var context = new TableHockeyData.UHSSWEB_DEVEntities())
            {
                TableHockeyGame    m_tableHockeyGame    = context.TableHockeyGame.FirstOrDefault(c => ((c.HomePlayerId == i_nPlayerId) || (c.AwayPlayerId == i_nPlayerId)) && (c.ContestId == m_nContestId));
                TableHockeyContest m_tableHockeyContest = context.TableHockeyContest.First(c => c.ContestId == i_nContestId);
                return((m_tableHockeyGame == null) && (m_tableHockeyContest.ContestDateClosed.Equals(DateTime.Parse("1900-01-01"))));
            }
        }
Beispiel #8
0
        private void handleContestGames(TableHockeyContest i_currentContest)
        {
            int i_nContestId = i_currentContest.ContestId;

            using (var context = new TableHockeyData.UHSSWEB_DEVEntities())
            {
                //Get contest games, if any.
                var gamesQuery = from g in context.TableHockeyGame
                                 where g.ContestId == i_nContestId
                                 select g;

                //Get contest players.
                var playersQuery = from p in context.TableHockeyContestPlayer
                                   where p.ContestId == i_nContestId
                                   select p;

                //Get contest games/players.

                List <TableHockeyGame>          m_games   = (List <TableHockeyGame>)gamesQuery.ToList();
                List <TableHockeyContestPlayer> m_players = (List <TableHockeyContestPlayer>)playersQuery.ToList();
                int m_nCorrectNumberOfGames = calcCorrectNumberOfEndGames(m_players);
                initEndGameQueueHandler(m_players, i_currentContest.numberOfRounds);

                //If we are to add new end games...
                List <TableHockeyGame> m_gamesForCurrentRound = getTableHockeyEndGameListForCurrentRound(i_currentContest, m_players);
                if (gamesQuery.ToList().Count < m_nCorrectNumberOfGames)
                {
                    if (m_games.Where(g => g.TableHockeyContestRoundId == m_gamesForCurrentRound[0].TableHockeyContestRoundId).FirstOrDefault() == null)
                    {
                        m_games.AddRange(m_gamesForCurrentRound);
                        //if (gamesQuery.ToList().Count > 0)
                        //{
                        //    //Game count mismatch. Remove games and re-generate game list.
                        //    foreach (TableHockeyGame m_game in m_games)
                        //    {
                        //        context.TableHockeyGame.Remove(m_game);
                        //    }
                        //    context.SaveChanges();
                        //}
                        foreach (TableHockeyGame m_game in m_games.Where(g => g.GameId == 0))
                        {
                            context.TableHockeyGame.Add(m_game);
                        }
                    }
                }
                context.SaveChanges();
            }
        }
Beispiel #9
0
        private int calcCorrectNumberOfEndGames(List <TableHockeyContestPlayer> i_players)
        {
            //Count the number of games to generate for end game.
            //This depends on the number of participating players and the number of games per round.

            int m_nPlayerCount = i_players.Count;

            if (m_currentContest == null)
            {
                m_currentContest = (TableHockeyContest)Session["pgEditContestTableEndGame.m_currentContest"];
            }

            int m_nGamesPerRound = m_currentContest.numberOfRounds;

            return((m_nPlayerCount - 1) * m_nGamesPerRound);
        }
Beispiel #10
0
 public void InitControl(TableHockeyData.TableHockeyContest i_TableHockeyContest)
 {
     if (i_TableHockeyContest != null)
     {
         //Edit existing contest
         m_contest = i_TableHockeyContest;
     }
     else
     {
         //Create new contest
         m_contest           = new TableHockeyContest();
         m_contest.ContestId = -1;
     }
     setUCGUI();
     Session["ucEditTableHockeyContest.m_contest"] = m_contest;
 }
        public TableHockeyContestViewModel(TableHockeyContest i_contest)
        {
            this.m_nContestId          = i_contest.ContestId;
            this.m_sContestName        = i_contest.ContestName;
            this.m_sContestLocation    = i_contest.ContestLocation;
            this.m_sContestDescription = i_contest.ContestDescription;
            this.m_sContestStarted     = i_contest.ContestDateOpened.ToString("yyyy-MM-dd");
            MembershipUser mu          = Membership.GetUser(i_contest.OwnerUserId.GetValueOrDefault());
            string         m_sUserName = "";

            if (mu != null)
            {
                m_sUserName = mu.UserName;
            }
            this.m_sUser = m_sUserName;
        }
Beispiel #12
0
        protected void ButtonPreviousRound_Click(object sender, EventArgs e)
        {
            if (m_currentContest == null)
            {
                m_currentContest = (TableHockeyContest)Session["pgEditContestTable.m_currentContest"];
            }

            //Display previous round.
            m_nCurrentRoundNumber--;
            bool           isFinalRound = displayCurrentRound(m_nContestId, m_nCurrentRoundNumber);
            int            m_nNumberOfEndGamePlayers = (int)((m_currentContest.NumberOfPlayersToNextRound != null) ? m_currentContest.NumberOfPlayersToNextRound : 100);
            TableViewModel m_tableViewModel          = new TableViewModel(m_nContestId, m_nCurrentRoundNumber);

            this.ucContestTable1.InitControl(m_tableViewModel.m_tableRows, false, m_nNumberOfEndGamePlayers);
            Session["pgEditContestTable.m_nCurrentRoundNumber"] = m_nCurrentRoundNumber;
        }
Beispiel #13
0
        protected void ButtonSaveContest_Click(object sender, EventArgs e)
        {
            using (var context = new TableHockeyData.UHSSWEB_DEVEntities())
            {
                if (this.ucEditTableHockeyContest1.m_currentContest.ContestId == -1)
                {
                    //New contest
                    context.TableHockeyContest.Add(this.ucEditTableHockeyContest1.m_currentContest);
                }
                else
                {
                    //Edit existing contest
                    TableHockeyContest m_currentContest = context.TableHockeyContest.FirstOrDefault(i => i.ContestId == this.ucEditTableHockeyContest1.m_currentContest.ContestId);
                    //Mapper.Map(this.ucEditTableHockeyContest1.m_currentContest, m_currentContest);
                    m_currentContest.ContestBinary              = this.ucEditTableHockeyContest1.m_currentContest.ContestBinary;
                    m_currentContest.ContestDateClosed          = this.ucEditTableHockeyContest1.m_currentContest.ContestDateClosed;
                    m_currentContest.ContestDateOpened          = this.ucEditTableHockeyContest1.m_currentContest.ContestDateOpened;
                    m_currentContest.ContestDescription         = this.ucEditTableHockeyContest1.m_currentContest.ContestDescription;
                    m_currentContest.ContestLocation            = this.ucEditTableHockeyContest1.m_currentContest.ContestLocation;
                    m_currentContest.ContestName                = this.ucEditTableHockeyContest1.m_currentContest.ContestName;
                    m_currentContest.GameLengthMinutes          = this.ucEditTableHockeyContest1.m_currentContest.GameLengthMinutes;
                    m_currentContest.isFinalGameContest         = this.ucEditTableHockeyContest1.m_currentContest.isFinalGameContest;
                    m_currentContest.isGoalDifferenceRanked     = this.ucEditTableHockeyContest1.m_currentContest.isGoalDifferenceRanked;
                    m_currentContest.NumberOfPlayersToNextRound = this.ucEditTableHockeyContest1.m_currentContest.NumberOfPlayersToNextRound;
                    m_currentContest.numberOfRounds             = this.ucEditTableHockeyContest1.m_currentContest.numberOfRounds;
                    m_currentContest.PointsLostGame             = this.ucEditTableHockeyContest1.m_currentContest.PointsLostGame;
                    m_currentContest.PointsTiedGame             = this.ucEditTableHockeyContest1.m_currentContest.PointsTiedGame;
                    m_currentContest.PointsWinningGame          = this.ucEditTableHockeyContest1.m_currentContest.PointsWinningGame;
                    //Also update closing date for any linked end game contest!
                    TableHockeyContest m_currentEndGameContest = context.TableHockeyContest.FirstOrDefault(i => i.EndGameForContestId == this.ucEditTableHockeyContest1.m_currentContest.ContestId);
                    if (m_currentEndGameContest != null)
                    {
                        m_currentEndGameContest.ContestDateClosed = this.ucEditTableHockeyContest1.m_currentContest.ContestDateClosed;
                    }
                }
                context.SaveChanges();
                Response.Redirect("~/pgMain.aspx");
            }

            //List<string> list = new List<string>();
            //list.Add("test");
            //list.Where(p => p.StartsWith("t")).ToList();

            //var test = from f in list
            //           where f.StartsWith("t")
            //           select f;
        }
 public ContestViewModel(TableHockeyContest i_Contest)
 {
     ContestId = i_Contest.ContestId;
     if (!string.IsNullOrEmpty(i_Contest.ContestName))
     {
         ContestDescription = i_Contest.ContestName;
     }
     if (!string.IsNullOrEmpty(i_Contest.ContestLocation))
     {
         ContestDescription += " (" + i_Contest.ContestLocation + ") ";
     }
     if (i_Contest.ContestDateOpened != null)
     {
         ContestDescription += i_Contest.ContestDateOpened.ToString("yyyy-MM-dd");
     }
     ContestHeader = "Contest (ID: " + Convert.ToString(ContestId) + ")";
 }
Beispiel #15
0
        private void handleContestGames(TableHockeyContest i_currentContest)
        {
            int i_nContestId = i_currentContest.ContestId;

            using (var context = new TableHockeyData.UHSSWEB_DEVEntities())
            {
                //Get contest games, if any.
                var gamesQuery = from g in context.TableHockeyGame
                                 where g.ContestId == i_nContestId
                                 select g;

                //Get contest players.
                var playersQuery = from p in context.TableHockeyContestPlayer
                                   where p.ContestId == i_nContestId
                                   select p;

                //Get contest games/players.

                List <TableHockeyGame>          m_games   = (List <TableHockeyGame>)gamesQuery.ToList();
                List <TableHockeyContestPlayer> m_players = (List <TableHockeyContestPlayer>)playersQuery.ToList();

                int m_nCorrectNumberOfUniqueGames = Convert.ToInt32(0.5 * i_currentContest.numberOfRounds * m_players.Count * (m_players.Count - 1));
                if (gamesQuery.ToList().Count != m_nCorrectNumberOfUniqueGames)
                {
                    if (gamesQuery.ToList().Count > 0)
                    {
                        //Game count mismatch. Remove games and re-generate game list.
                        foreach (TableHockeyGame m_game in m_games)
                        {
                            context.TableHockeyGame.Remove(m_game);
                        }
                        context.SaveChanges();
                    }
                    //Generate game list for entire contest.
                    m_games = getTableHockeyGameList(i_currentContest, m_players);
                    foreach (TableHockeyGame m_game in m_games)
                    {
                        context.TableHockeyGame.Add(m_game);
                    }
                }
                context.SaveChanges();
            }
        }
Beispiel #16
0
        public TableHockeyContest createDefaultEndGameTableHockeyContest(TableHockeyContest i_parentContest)
        {
            TableHockeyContest m_GUIContest = new TableHockeyContest();

            m_GUIContest.ContestDateOpened          = DateTime.Now;
            m_GUIContest.ContestDateClosed          = new DateTime(1900, 1, 1);
            m_GUIContest.ContestDescription         = i_parentContest.ContestDescription + " End Game";
            m_GUIContest.ContestName                = i_parentContest.ContestName + " End Game";
            m_GUIContest.ContestLocation            = i_parentContest.ContestLocation;
            m_GUIContest.GameLengthMinutes          = 5; //TODO: Setting!
            m_GUIContest.NumberOfPlayersToNextRound = -1;
            m_GUIContest.numberOfRounds             = 1; //TODO:  Setting?!
            m_GUIContest.PointsWinningGame          = -1;
            m_GUIContest.PointsTiedGame             = -1;
            m_GUIContest.PointsLostGame             = -1;
            m_GUIContest.isGoalDifferenceRanked     = false;
            m_GUIContest.isFinalGameContest         = true;
            m_GUIContest.OwnerUserId                = (Guid)i_parentContest.OwnerUserId;
            m_GUIContest.EndGameForContestId        = i_parentContest.ContestId;
            return(m_GUIContest);
        }
Beispiel #17
0
        private List <TableHockeyGame> getTableHockeyEndGameListForCurrentRound(TableHockeyContest i_contest, List <TableHockeyContestPlayer> i_contestPlayers)
        {
            //Get game list for end game. Always add full number of possible games per round. If a match series ends prematurely, games are returned as "scoreless".
            using (var context = new TableHockeyData.UHSSWEB_DEVEntities())
            {
                var roundsQuery = from r in context.TableHockeyContestRound
                                  where r.ContestId == i_contest.ContestId
                                  select r;

                List <TableHockeyContestRound> m_lstTableHockeyRounds = (List <TableHockeyContestRound>)roundsQuery.ToList();
                List <TableHockeyGame>         m_lstTableHockeyGames  = new List <TableHockeyGame>();

                int      m_nGamesPerRound = i_contest.numberOfRounds;
                DateTime m_dStartDate     = DateTime.Now;

                //Create game list for current round.

                TableHockeyContestRound m_round = m_lstTableHockeyRounds[m_queueHandler.m_nCurrentRoundNumber - 1];
                for (int k = 0; k < m_queueHandler.m_dictGamePlayersPerRound[m_queueHandler.m_nCurrentRoundNumber - 1].Count; k += 2)
                {
                    for (int i = 0; i < m_nGamesPerRound; i++)
                    {
                        TableHockeyGame m_currentGame = new TableHockeyGame();
                        m_currentGame.ContestId                 = i_contest.ContestId;
                        m_currentGame.GameStartDate             = m_dStartDate;
                        m_currentGame.isFinalGame               = i_contest.isFinalGameContest;
                        m_currentGame.TableNumber               = (int)(k / 2.0) + 1;
                        m_currentGame.TableHockeyContestRoundId = m_round.TableHockeyContestRoundId;
                        m_currentGame.HomePlayerId              = m_queueHandler.m_dictGamePlayersPerRound[m_queueHandler.m_nCurrentRoundNumber - 1].ElementAt(k).Key;
                        m_currentGame.AwayPlayerId              = m_queueHandler.m_dictGamePlayersPerRound[m_queueHandler.m_nCurrentRoundNumber - 1].ElementAt(k + 1).Key;
                        m_currentGame.IdlePlayerId              = -1;
                        m_lstTableHockeyGames.Add(m_currentGame);
                    }
                }
                return(m_lstTableHockeyGames);
            }
        }
Beispiel #18
0
        //private int getLowerPlayerCountRotationLimit()
        //{
        //    using (var context = new TableHockeyData.UHSSWEB_DEVEntities())
        //    {
        //        var querySetting = context.Settings.First(s => s.SettingDescription == "INT_NUMBER_OF_PLAYERS_ROTATION_LOWER_LIMIT");
        //        return (int)querySetting.ValueInt;
        //    }
        //}

        private List <TableHockeyGame> getTableHockeyGameList(TableHockeyContest i_contest, List <TableHockeyContestPlayer> i_contestPlayers)
        {
            using (var context = new TableHockeyData.UHSSWEB_DEVEntities())
            {
                var roundsQuery = from r in context.TableHockeyContestRound
                                  where r.ContestId == i_contest.ContestId
                                  select r;

                List <TableHockeyContestRound> m_lstTableHockeyRounds = (List <TableHockeyContestRound>)roundsQuery.ToList();
                List <TableHockeyGame>         m_lstTableHockeyGames  = new List <TableHockeyGame>();
                int                      m_nGamesPerRound             = getNumberOfGamesPerRound(i_contestPlayers.Count);
                DateTime                 m_dStartDate         = DateTime.Now;
                PlayerViewModelList      m_lstPlayerViewModel = new PlayerViewModelList(i_contestPlayers);
                TableHockeyQueueHandler2 m_queueHandler       = new TableHockeyQueueHandler2(m_lstPlayerViewModel.m_lstContestPlayerId, m_nGamesPerRound);

                foreach (TableHockeyContestRound m_round in m_lstTableHockeyRounds)
                {
                    for (int i = 0; i < m_nGamesPerRound; i++)
                    {
                        TableHockeyGame m_currentGame = new TableHockeyGame();
                        m_currentGame.ContestId                 = i_contest.ContestId;
                        m_currentGame.GameStartDate             = m_dStartDate;
                        m_currentGame.isFinalGame               = i_contest.isFinalGameContest;
                        m_currentGame.TableNumber               = i + 1;
                        m_currentGame.TableHockeyContestRoundId = m_round.TableHockeyContestRoundId;
                        m_currentGame.HomePlayerId              = m_queueHandler.m_lstCurrentHomePlayerId[i];
                        m_currentGame.AwayPlayerId              = m_queueHandler.m_lstCurrentAwayPlayerId[i];
                        m_currentGame.IdlePlayerId              = m_queueHandler.getIdlePlayer();
                        m_lstTableHockeyGames.Add(m_currentGame);
                    }
                    m_queueHandler.nextRound();
                }

                return(m_lstTableHockeyGames);
            }
        }
Beispiel #19
0
        protected void Page_Load(object sender, EventArgs e)
        {
            //Get contest id.
            if (!Page.IsPostBack)
            {
                m_nContestId = -1;
                m_sContestRoundPlaceholder = "Contest round [ROUND]"; //TODO:  Config setting!
                if (!String.IsNullOrEmpty(Request.QueryString["ContestId"]))
                {
                    m_nContestId = Convert.ToInt32(Request.QueryString["ContestId"]);
                    Session["pgEditContestTableEndGame.m_nContestId"] = m_nContestId;
                    //Get current contest
                    using (var context = new TableHockeyData.UHSSWEB_DEVEntities())
                    {
                        m_currentContest = context.TableHockeyContest.FirstOrDefault(i => i.ContestId == m_nContestId);
                    }

                    if (m_currentContest.EndGameForContestId == null)
                    {
                        Response.Redirect("~/pgMain.aspx");
                    }

                    Session["pgEditContestTableEndGame.m_currentContest"] = m_currentContest;
                    //Find or regenerate contest end game rounds. Just generate 1 + ([number of players] - 1) / 2 rounds.
                    Session["pgEditContestTable.m_currentContest"] = m_currentContest; //??
                    if (Session["pgEditContestTableEndGame.m_nCurrentRoundNumber"] != null)
                    {
                        m_nCurrentRoundNumber = (int)Session["pgEditContestTableEndGame.m_nCurrentRoundNumber"];
                    }
                    else
                    {
                        m_nCurrentRoundNumber = 1;
                    }
                    //Find or regenerate contest rounds.
                    handleContestRounds(m_nContestId);
                    //Find or regenerate contest end games.
                    handleContestGames(m_currentContest);
                    //Init end game ucs

                    this.LabelContestHeader.Text = m_sContestRoundPlaceholder.Replace("[ROUND]", Convert.ToString(m_nCurrentRoundNumber));
                    //Init table user control
                    bool isFinalRound = displayCurrentRound(m_nContestId, m_nCurrentRoundNumber);
                }
                else
                {
                    Response.Redirect("~/pgMain.aspx");
                }
                Session["ucEndGameSeries.hasChanges"] = false;
            }
            else
            {
                if (Session["pgEditContestTableEndGame.m_nCurrentRoundNumber"] != null)
                {
                    m_nCurrentRoundNumber = (int)Session["pgEditContestTableEndGame.m_nCurrentRoundNumber"];
                }
                else
                {
                    m_nCurrentRoundNumber = 1;
                }

                if (Session["pgEditContestTableEndGame.m_nContestId"] != null)
                {
                    m_nContestId = (int)Session["pgEditContestTableEndGame.m_nContestId"];
                }

                bool isFinalRound = displayCurrentRound(m_nContestId, m_nCurrentRoundNumber);
            }
        }
Beispiel #20
0
        private TableHockeyContest getUCGUI()
        {
            if (Session["ucEditTableHockeyContest.m_contest"] != null)
            {
                m_contest = (TableHockeyContest)Session["ucEditTableHockeyContest.m_contest"];
            }
            TableHockeyContest m_GUIContest = new TableHockeyContest();

            if (m_contest == null || m_contest.ContestId <= 0)
            {
                m_GUIContest.ContestId = -1;
            }
            else
            {
                m_GUIContest.ContestId = m_contest.ContestId;
            }
            if (!String.IsNullOrEmpty(TextBoxContestStartedDate.Text))
            {
                m_GUIContest.ContestDateOpened = Convert.ToDateTime(TextBoxContestStartedDate.Text);
            }
            else
            {
                m_GUIContest.ContestDateOpened = new DateTime(1900, 1, 1);
            }
            if (!String.IsNullOrEmpty(TextBoxContestClosedDate.Text))
            {
                m_GUIContest.ContestDateClosed = Convert.ToDateTime(TextBoxContestClosedDate.Text);
            }
            else
            {
                m_GUIContest.ContestDateClosed = new DateTime(1900, 1, 1);
            }
            if (!String.IsNullOrEmpty(TextBoxContestDescription.Text))
            {
                m_GUIContest.ContestDescription = TextBoxContestDescription.Text;
            }
            else
            {
                m_GUIContest.ContestDescription = "";
            }
            if (!String.IsNullOrEmpty(TextBoxContestName.Text))
            {
                m_GUIContest.ContestName = TextBoxContestName.Text;
            }
            else
            {
                m_GUIContest.ContestName = "";
            }
            if (!String.IsNullOrEmpty(TextBoxContestLocation.Text))
            {
                m_GUIContest.ContestLocation = TextBoxContestLocation.Text;
            }
            else
            {
                m_GUIContest.ContestLocation = "";
            }
            if (!String.IsNullOrEmpty(TextBoxNumberOfGameMinutes.Text))
            {
                m_GUIContest.GameLengthMinutes = Convert.ToInt32(TextBoxNumberOfGameMinutes.Text);
            }
            else
            {
                m_GUIContest.GameLengthMinutes = 5;  //TODO: Setting!
            }
            if (!String.IsNullOrEmpty(TextBoxNumberOfPlayersToNextRound.Text))
            {
                m_GUIContest.NumberOfPlayersToNextRound = Convert.ToInt32(TextBoxNumberOfPlayersToNextRound.Text);
            }
            else
            {
                m_GUIContest.NumberOfPlayersToNextRound = -1;
            }
            if (!String.IsNullOrEmpty(TextBoxNumberOfRounds.Text))
            {
                m_GUIContest.numberOfRounds = Convert.ToInt32(TextBoxNumberOfRounds.Text);
            }
            else
            {
                m_GUIContest.numberOfRounds = 1;       //TODO:  Setting?!
            }
            string[] m_sPointsWTL = { "2", "1", "0" }; //TODO:  Setting?!
            if (!String.IsNullOrEmpty(TextBoxPointsWinTieLoss.Text))
            {
                m_sPointsWTL = TextBoxPointsWinTieLoss.Text.Split('/');
                m_GUIContest.PointsWinningGame = Convert.ToInt32(m_sPointsWTL[0]);
                m_GUIContest.PointsTiedGame    = Convert.ToInt32(m_sPointsWTL[1]);
                m_GUIContest.PointsLostGame    = Convert.ToInt32(m_sPointsWTL[2]);
            }
            m_GUIContest.isGoalDifferenceRanked = (RadioButtonListGoalDifference.SelectedValue == "1");
            m_GUIContest.isFinalGameContest     = (RadioButtonListTypeOfContest.SelectedValue == "1");
            MembershipUser CurrentUser = Membership.GetUser(this.Page.User.Identity.Name);

            m_GUIContest.OwnerUserId       = (Guid)CurrentUser.ProviderUserKey;
            m_GUIContest.isPubliclyVisible = chbPubliclyVisible.Checked;
            Session["ucEditTableHockeyContest.m_contest"] = m_GUIContest;
            return(m_GUIContest);
        }
Beispiel #21
0
        protected void ButtonEndGame_Click(object sender, EventArgs e)
        {
            int m_nNumberOfRounds = -1;

            if (!int.TryParse(TextBoxEndGameRounds.Text.Trim(), out m_nNumberOfRounds))
            {
                this.cvEndGameRounds.IsValid = false;
                return;
            }

            this.cvEndGameRounds.IsValid = true;
            //Get selected players for end game.
            Dictionary <int, int> m_selectedPlayerIDs = this.ucContestTable1.CheckedPlayersToEndGame;

            if ((m_selectedPlayerIDs != null) && (m_selectedPlayerIDs.Count > 1))
            {
                this.cvEndGamePlayers.IsValid = true;
                if (m_currentContest == null)
                {
                    m_currentContest = (TableHockeyContest)Session["pgEditContestTable.m_currentContest"];
                }

                //Create new end game contest for current contest.
                TableHockeyContestHandler m_handler           = new TableHockeyContestHandler();
                TableHockeyContest        m_newEndGameContest = m_handler.createDefaultEndGameTableHockeyContest(m_currentContest);
                m_newEndGameContest.numberOfRounds = Convert.ToInt32(TextBoxEndGameRounds.Text);
                //Add selected players to end game contest.  Make sure to export final table standing for each player.
                int m_nEndGameContestId = -1;
                using (var context = new TableHockeyData.UHSSWEB_DEVEntities())
                {
                    //Create new end game only if no previous exists.
                    var queryExistingEndGame = context.TableHockeyContest.FirstOrDefault(c => c.EndGameForContestId == m_nContestId);
                    if (queryExistingEndGame == null)
                    {
                        context.TableHockeyContest.Add(m_newEndGameContest);
                        context.SaveChanges();
                    }
                }

                using (var context = new TableHockeyData.UHSSWEB_DEVEntities())
                {
                    //Add new players to end game if none exist.

                    var queryExistingEndGame = context.TableHockeyContest.FirstOrDefault(c => c.EndGameForContestId == m_nContestId);
                    if (queryExistingEndGame != null)
                    {
                        m_nEndGameContestId = queryExistingEndGame.ContestId;
                        var queryExistingPlayers = context.TableHockeyContestPlayer.FirstOrDefault(p => p.ContestId == m_nEndGameContestId);
                        //Only add players if none exist.
                        if (queryExistingPlayers == null)
                        {
                            foreach (KeyValuePair <int, int> kvp in m_selectedPlayerIDs)
                            {
                                TableHockeyContestPlayer m_contestPlayer = new TableHockeyContestPlayer();
                                m_contestPlayer.ContestId             = m_nEndGameContestId;
                                m_contestPlayer.PlayerId              = kvp.Value;
                                m_contestPlayer.FinalPreviousStanding = 1 + kvp.Key;
                                m_contestPlayer.isDummyContestPlayer  = false;
                                context.TableHockeyContestPlayer.Add(m_contestPlayer);
                            }
                            context.SaveChanges();
                        }
                    }
                }
                using (var context = new TableHockeyData.UHSSWEB_DEVEntities())
                {
                    //Create new end game only if no previous exists.
                    var queryExistingEndGame = context.TableHockeyContest.FirstOrDefault(c => c.EndGameForContestId == m_nContestId);
                    if (queryExistingEndGame != null)
                    {
                        TableHockeyContest m_endGame = (TableHockeyContest)queryExistingEndGame;
                        m_nEndGameContestId = m_endGame.ContestId;
                    }
                }
                Response.Redirect("~/pgEditContestTableEndGame.aspx?ContestId=" + m_nEndGameContestId);
            }
            else
            {
                this.cvEndGamePlayers.IsValid = false;
            }
        }
Beispiel #22
0
        public TableRowPlayerViewModel(List <TableHockeyGame> i_gamesToSummarize, PlayerViewModel i_player, TableHockeyContest i_contest)
        {
            this.PlayerId              = i_player.PlayerId;
            this.PlayerDescription     = i_player.FirstName + " " + i_player.LastName;
            this.Divider               = "-";
            this.TrendIndicatorType    = 0;
            this.NumberOfGamesPlayed   = 0;
            this.NumberOfGamesWon      = 0;
            this.NumberOfGamesTied     = 0;
            this.NumberOfGamesLost     = 0;
            this.NumberOfGoalsScored   = 0;
            this.NumberOfGoalsTendered = 0;
            this.GoalDifference        = 0;
            this.NumberOfPoints        = 0;

            //Get point settings.
            int m_nNumberOfPointsWinning;
            int m_nNumberOfPointsTie;
            int m_nNumberOfPointsLosing;

            m_nNumberOfPointsWinning = i_contest.PointsWinningGame;
            m_nNumberOfPointsTie     = i_contest.PointsTiedGame;
            m_nNumberOfPointsLosing  = i_contest.PointsLostGame;

            //Order by roundid to get games in chronological order.
            List <TableHockeyGame> m_orderedGamesList = i_gamesToSummarize.OrderBy(g => g.TableHockeyContestRoundId).ToList();

            for (int i = 0; i < m_orderedGamesList.Count; i++)
            {
                int m_nHomePlayerScore = -1;
                if (m_orderedGamesList.ElementAt(i).HomePlayerScore != null)
                {
                    m_nHomePlayerScore = (int)m_orderedGamesList.ElementAt(i).HomePlayerScore;
                }

                int m_nAwayPlayerScore = -1;
                if (m_orderedGamesList.ElementAt(i).AwayPlayerScore != null)
                {
                    m_nAwayPlayerScore = (int)m_orderedGamesList.ElementAt(i).AwayPlayerScore;
                }

                if ((m_nHomePlayerScore >= 0) && (m_nAwayPlayerScore >= 0))
                {
                    //Actual score entered
                    int m_nMyScore    = 0;
                    int m_nTheirScore = 0;

                    if (m_orderedGamesList.ElementAt(i).HomePlayerId == this.PlayerId)
                    {
                        m_nMyScore    = m_nHomePlayerScore;
                        m_nTheirScore = m_nAwayPlayerScore;
                    }
                    if (m_orderedGamesList.ElementAt(i).AwayPlayerId == this.PlayerId)
                    {
                        m_nMyScore    = m_nAwayPlayerScore;
                        m_nTheirScore = m_nHomePlayerScore;
                    }
                    if (m_nMyScore > m_nTheirScore)
                    {
                        //Player won
                        this.NumberOfPoints += m_nNumberOfPointsWinning;
                        this.NumberOfGamesWon++;
                    }
                    if (m_nMyScore < m_nTheirScore)
                    {
                        //Player lost
                        this.NumberOfPoints += m_nNumberOfPointsLosing;
                        this.NumberOfGamesLost++;
                    }
                    if (m_nMyScore == m_nTheirScore)
                    {
                        //Players tied
                        this.NumberOfPoints += m_nNumberOfPointsTie;
                        this.NumberOfGamesTied++;
                    }
                    this.NumberOfGamesPlayed++;
                    this.NumberOfGoalsScored   += m_nMyScore;
                    this.NumberOfGoalsTendered += m_nTheirScore;
                    this.GoalDifference         = (this.NumberOfGoalsScored - this.NumberOfGoalsTendered);
                }
            }
        }