예제 #1
0
        private void handleContestRounds(int i_nContestId)
        {
            m_nNumberOfRounds = calcNumberOfContestRounds(i_nContestId);
            TableHockeyContestHandler m_handler = new TableHockeyContestHandler();

            m_handler.handleContestRounds(i_nContestId, m_nNumberOfRounds);
        }
예제 #2
0
        public void handleContestRounds(int i_nContestId, int i_nNumberOfRounds)
        {
            using (var context = new TableHockeyData.UHSSWEB_DEVEntities())
            {
                var roundsQuery = from p in context.TableHockeyContestRound
                                  where p.ContestId == i_nContestId
                                  select p;

                if (roundsQuery.ToList().Count() != i_nNumberOfRounds)
                {
                    //Number of players or repetitions in current contest has changed,
                    //or a new game had been created.
                    //Drop any existing contest rounds and regenerate.
                    if (roundsQuery.ToList().Count > 0)
                    {
                        foreach (TableHockeyContestRound m_round in (List <TableHockeyContestRound>)roundsQuery.ToList())
                        {
                            foreach (TableHockeyGame m_game in m_round.TableHockeyGame.ToList())
                            {
                                context.TableHockeyGame.Remove(m_game);
                            }
                            context.TableHockeyContestRound.Remove(m_round);
                        }
                        context.SaveChanges();
                    }
                    TableHockeyContestHandler      m_contestHandler             = new TableHockeyContestHandler();
                    List <TableHockeyContestRound> m_lstTableHockeyContestRound = m_contestHandler.getTableHockeyContestRoundList(i_nContestId, i_nNumberOfRounds);
                    foreach (TableHockeyContestRound m_round in m_lstTableHockeyContestRound)
                    {
                        context.TableHockeyContestRound.Add(m_round);
                    }
                }
                context.SaveChanges();
            }
        }
예제 #3
0
        private bool ValidateEnteredEndGames(List <TableHockeyContestRound> m_enteredRounds, out Dictionary <int, int> m_dictPlayersToNextRound)
        {
            int m_nGamesPerRound = m_currentContest.numberOfRounds;

            m_nContestId = m_currentContest.ContestId;
            //Get round for current round number.
            TableHockeyContestRound m_currentRound = m_enteredRounds.Where(g => g.RoundNumber == m_nCurrentRoundNumber).FirstOrDefault();

            //If everything validates, save results to database and display next round.
            m_dictPlayersToNextRound = TableHockeyContestHandler.getPlayersToNextRound(m_currentRound, m_nGamesPerRound);
            int m_nPlayersToNextRound = m_enteredRounds[0].TableHockeyGame.Count / m_nGamesPerRound;

            return(m_dictPlayersToNextRound.Count == m_nPlayersToNextRound);
        }
예제 #4
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;
            }
        }
        protected void ResultsRepeater_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
            {
                PlaceHolder PlaceHolder1 = (PlaceHolder)e.Item.FindControl("PlaceHolder1");

                // declare/obtain the value of i given the DataItem
                // e.g.,
                TableHockeyContestRound m_round = (TableHockeyContestRound)e.Item.DataItem;
                Dictionary <int, uc.ucViewEndGameSeries> m_ucList;
                if (Session["pgContestSummary.ucList"] != null)
                {
                    m_ucList = (Dictionary <int, uc.ucViewEndGameSeries>)Session["pgContestSummary.ucList"];
                }
                else
                {
                    m_ucList = new Dictionary <int, uc.ucViewEndGameSeries>();
                }

                for (int m_nCurrentTableNumber = 1; m_nCurrentTableNumber <= m_nMaxNumberOfConcurrentGames; m_nCurrentTableNumber++)
                {
                    List <TableHockeyGame> m_gamesOnCurrentTable = m_round.TableHockeyGame.Where(g => g.TableNumber == m_nCurrentTableNumber).ToList();
                    if (m_gamesOnCurrentTable.Count > 0)
                    {
                        TableHockeyContestRound m_roundGame = new TableHockeyContestRound();
                        Mapper.Map(m_round, m_roundGame);
                        m_roundGame.TableHockeyGame = m_gamesOnCurrentTable;
                        uc.ucViewEndGameSeries uc = (uc.ucViewEndGameSeries)LoadControl("~/uc/ucViewEndGameSeries.ascx");
                        uc.InitControl(m_roundGame, 25 * (m_round.RoundNumber - 1));
                        uc.m_nTableNumber = m_nCurrentTableNumber;
                        int m_nNumberOfRounds = Convert.ToInt32(Session["pgContestSummary.m_nNumberOfRounds"]);
                        //Get qualifying players from current round.
                        Dictionary <int, int> m_playersToNextRound = TableHockeyContestHandler.getPlayersToNextRound(m_round, m_gamesOnCurrentTable.Count);
                        if (m_playersToNextRound.Count > 0)
                        {
                            //Get qualifying player for current table number.
                            int m_nQualifyingPlayerForCurrentTableNumber = m_playersToNextRound[m_nCurrentTableNumber];
                            if (m_round.isFinalRound)
                            {
                                m_ucList.Add(8, uc);
                                Session["pgContestSummary.ucList"] = m_ucList;
                            }
                            if (m_round.RoundNumber == (m_nNumberOfRounds - 1))
                            {
                                //Get previous round.
                                TableHockeyContestRound m_prevRound = (TableHockeyContestRound)Session["pgContestSummary.previousRound"];
                                //Match qualifying player id with either home or away player.
                                if ((m_nCurrentTableNumber == 1) && ((m_nQualifyingPlayerForCurrentTableNumber == m_prevRound.TableHockeyGame.ElementAt(0).HomePlayerId) || (m_nQualifyingPlayerForCurrentTableNumber == m_prevRound.TableHockeyGame.ElementAt(0).AwayPlayerId)))
                                {
                                    m_ucList.Add(4, uc);
                                }
                                if ((m_nCurrentTableNumber == 2) && ((m_nQualifyingPlayerForCurrentTableNumber == m_prevRound.TableHockeyGame.ElementAt(0).HomePlayerId) || (m_nQualifyingPlayerForCurrentTableNumber == m_prevRound.TableHockeyGame.ElementAt(0).AwayPlayerId)))
                                {
                                    m_ucList.Add(12, uc);
                                }
                                //TODO: Analogt för följande omgångar. Traversera över m_playersToNextRound
                                Session["pgContestSummary.ucList"] = m_ucList;
                            }
                            if (m_round.RoundNumber == (m_nNumberOfRounds - 2))
                            {
                                //Get previous round.
                                TableHockeyContestRound m_prevRound = (TableHockeyContestRound)Session["pgContestSummary.previousRound"];
                                List <TableHockeyGame>  m_prevGamesOnCurrentTable = m_prevRound.TableHockeyGame.Where(g => g.TableNumber == m_nCurrentTableNumber).ToList();
                                if ((m_nCurrentTableNumber == 1) &&
                                    ((m_nQualifyingPlayerForCurrentTableNumber == m_prevRound.TableHockeyGame.ElementAt(0).HomePlayerId) || (m_nQualifyingPlayerForCurrentTableNumber == m_prevRound.TableHockeyGame.ElementAt(0).AwayPlayerId) || (m_nQualifyingPlayerForCurrentTableNumber == m_prevRound.TableHockeyGame.ElementAt(m_gamesOnCurrentTable.Count).HomePlayerId) || (m_nQualifyingPlayerForCurrentTableNumber == m_prevRound.TableHockeyGame.ElementAt(m_gamesOnCurrentTable.Count).AwayPlayerId)))
                                {
                                    m_ucList.Add(2, uc);
                                }
                                if ((m_nCurrentTableNumber == 2) &&
                                    ((m_nQualifyingPlayerForCurrentTableNumber == m_prevRound.TableHockeyGame.ElementAt(0).HomePlayerId) || (m_nQualifyingPlayerForCurrentTableNumber == m_prevRound.TableHockeyGame.ElementAt(0).AwayPlayerId) || (m_nQualifyingPlayerForCurrentTableNumber == m_prevRound.TableHockeyGame.ElementAt(m_gamesOnCurrentTable.Count).HomePlayerId) || (m_nQualifyingPlayerForCurrentTableNumber == m_prevRound.TableHockeyGame.ElementAt(m_gamesOnCurrentTable.Count).AwayPlayerId)))
                                {
                                    m_ucList.Add(6, uc);
                                }
                                if ((m_nCurrentTableNumber == 3) &&
                                    ((m_nQualifyingPlayerForCurrentTableNumber == m_prevRound.TableHockeyGame.ElementAt(0).HomePlayerId) || (m_nQualifyingPlayerForCurrentTableNumber == m_prevRound.TableHockeyGame.ElementAt(0).AwayPlayerId) || (m_nQualifyingPlayerForCurrentTableNumber == m_prevRound.TableHockeyGame.ElementAt(m_gamesOnCurrentTable.Count).HomePlayerId) || (m_nQualifyingPlayerForCurrentTableNumber == m_prevRound.TableHockeyGame.ElementAt(m_gamesOnCurrentTable.Count).AwayPlayerId)))
                                {
                                    m_ucList.Add(10, uc);
                                }
                                if ((m_nCurrentTableNumber == 4) &&
                                    ((m_nQualifyingPlayerForCurrentTableNumber == m_prevRound.TableHockeyGame.ElementAt(0).HomePlayerId) || (m_nQualifyingPlayerForCurrentTableNumber == m_prevRound.TableHockeyGame.ElementAt(0).AwayPlayerId) || (m_nQualifyingPlayerForCurrentTableNumber == m_prevRound.TableHockeyGame.ElementAt(m_gamesOnCurrentTable.Count).HomePlayerId) || (m_nQualifyingPlayerForCurrentTableNumber == m_prevRound.TableHockeyGame.ElementAt(m_gamesOnCurrentTable.Count).AwayPlayerId)))
                                {
                                    m_ucList.Add(14, uc);
                                }
                                Session["pgContestSummary.ucList"] = m_ucList;
                            }
                            if (m_round.RoundNumber == (m_nNumberOfRounds - 3))
                            {
                                //Get previous round.
                                //TODO:  Fixa för åttondel analogt med kvartsfinal ovan! Gnetigt men det går! 2013-07-23.
                                TableHockeyContestRound m_prevRound = (TableHockeyContestRound)Session["pgContestSummary.previousRound"];
                                List <TableHockeyGame>  m_prevGamesOnCurrentTable = m_prevRound.TableHockeyGame.Where(g => g.TableNumber == m_nCurrentTableNumber).ToList();
                                if ((m_nCurrentTableNumber == 1) && ((m_nQualifyingPlayerForCurrentTableNumber == m_prevRound.TableHockeyGame.ElementAt(0).HomePlayerId) || (m_nQualifyingPlayerForCurrentTableNumber == m_prevRound.TableHockeyGame.ElementAt(0).AwayPlayerId)))
                                {
                                    m_ucList.Add(1, uc);
                                }
                                if ((m_nCurrentTableNumber == 2) && ((m_nQualifyingPlayerForCurrentTableNumber == m_prevRound.TableHockeyGame.ElementAt(0).HomePlayerId) || (m_nQualifyingPlayerForCurrentTableNumber == m_prevRound.TableHockeyGame.ElementAt(0).AwayPlayerId)))
                                {
                                    m_ucList.Add(3, uc);
                                }
                                if ((m_nCurrentTableNumber == 3) && ((m_nQualifyingPlayerForCurrentTableNumber == m_prevRound.TableHockeyGame.ElementAt(0).HomePlayerId) || (m_nQualifyingPlayerForCurrentTableNumber == m_prevRound.TableHockeyGame.ElementAt(0).AwayPlayerId)))
                                {
                                    m_ucList.Add(5, uc);
                                }
                                if ((m_nCurrentTableNumber == 4) && ((m_nQualifyingPlayerForCurrentTableNumber == m_prevRound.TableHockeyGame.ElementAt(0).HomePlayerId) || (m_nQualifyingPlayerForCurrentTableNumber == m_prevRound.TableHockeyGame.ElementAt(0).AwayPlayerId)))
                                {
                                    m_ucList.Add(7, uc);
                                }
                                if ((m_nCurrentTableNumber == 5) && ((m_nQualifyingPlayerForCurrentTableNumber == m_prevRound.TableHockeyGame.ElementAt(0).HomePlayerId) || (m_nQualifyingPlayerForCurrentTableNumber == m_prevRound.TableHockeyGame.ElementAt(0).AwayPlayerId)))
                                {
                                    m_ucList.Add(9, uc);
                                }
                                if ((m_nCurrentTableNumber == 6) && ((m_nQualifyingPlayerForCurrentTableNumber == m_prevRound.TableHockeyGame.ElementAt(0).HomePlayerId) || (m_nQualifyingPlayerForCurrentTableNumber == m_prevRound.TableHockeyGame.ElementAt(0).AwayPlayerId)))
                                {
                                    m_ucList.Add(11, uc);
                                }
                                if ((m_nCurrentTableNumber == 7) && ((m_nQualifyingPlayerForCurrentTableNumber == m_prevRound.TableHockeyGame.ElementAt(0).HomePlayerId) || (m_nQualifyingPlayerForCurrentTableNumber == m_prevRound.TableHockeyGame.ElementAt(0).AwayPlayerId)))
                                {
                                    m_ucList.Add(13, uc);
                                }
                                if ((m_nCurrentTableNumber == 8) && ((m_nQualifyingPlayerForCurrentTableNumber == m_prevRound.TableHockeyGame.ElementAt(0).HomePlayerId) || (m_nQualifyingPlayerForCurrentTableNumber == m_prevRound.TableHockeyGame.ElementAt(0).AwayPlayerId)))
                                {
                                    m_ucList.Add(15, uc);
                                }
                                Session["pgContestSummary.ucList"] = m_ucList;
                            }
                        }
                    }
                }
                Session["pgContestSummary.previousRound"] = m_round;
                if (m_round.isFirstRound)
                {
                    for (int iCount = 1; iCount < 15; iCount++)
                    {
                        uc.ucViewEndGameSeries m_uc;
                        if (m_ucList.ContainsKey(iCount))
                        {
                            m_uc = m_ucList[iCount];
                            PlaceHolder1.Controls.Add(m_uc);
                        }
                    }
                    string m_sEndGameHtml = GetSummary(divUcEndGamePlaceHolder);
                    Session["pgContestSummary.endGameHTML"] = m_sEndGameHtml;
                }
            }
        }