コード例 #1
0
        /// <summary>
        /// Processes a game.
        /// </summary>
        /// <param name="operation"></param>
        private static void ProcessGame(Game currentGame, Operation operation)
        {
            try
            {
                _gameType = currentGame.GetGameType();

                if ( _gameType == GameType.ForfeitForRulesViolation )
                {
                    // In a forfeit for a rules violation, the team originally declared the winner is required to
                    // have their win exchanged for a loss, with the win going to their opponent. With this in mind,
                    // the next few steps make the winner the loser and the loser the winner.
                    string temp = currentGame.Loser;
                    currentGame.Loser = currentGame.Winner;
                    currentGame.Winner = temp;

                    decimal tempScore = currentGame.LoserScore;
                    currentGame.LoserScore = currentGame.WinnerScore;
                    currentGame.WinnerScore = tempScore;

                    decimal tempAdjustedScore = currentGame.LoserAdjustedScore;
                    currentGame.LoserAdjustedScore = currentGame.WinnerAdjustedScore;
                    currentGame.WinnerAdjustedScore = tempAdjustedScore;
                }

                // Now it's time to find the winner's and loser's rows in the Teams table so I can update them.
                SortedList<string, Team> winnerAndLoser = currentGame.GetWinnerAndLoser();
                Team winner = winnerAndLoser["Winner"];
                Team loser = winnerAndLoser["Loser"];

                ProcessTeams(winner, loser, operation, currentGame);
            }
            catch ( Exception ex )
            {
                Globals.ShowExceptionMessage(ex);
            }
        }
コード例 #2
0
        /// <summary>
        /// Processes the two teams involved in the specified game.
        /// </summary>
        /// <param name="winner"></param>
        /// <param name="loser"></param>
        /// <param name="operation"></param>
        /// <param name="currentGame"></param>
        private static void ProcessTeams(Team winner, Team loser, Operation operation, Game currentGame)
        {
            try
            {
                if ( (winner == null) && (loser == null) )
                {
                    throw new Exception("Neither team could be found in the database.");
                }

                EditDataFromAllGames(winner, loser, operation, currentGame);

                if ( IsGameOutOfClass(winner, loser) )
                {
                    // One of the two teams is out of state, or the two teams are in different classifications,
                    // or one of the teams is an independent.
                    EditDataFromGamesOutOfClassification(winner, loser, operation, currentGame);
                }
                else
                {
                    // Both teams are in state and in the same classification.
                    EditDataFromGamesInClassification(winner, loser, operation, currentGame);

                    if ( currentGame.IsDistrictGame )
                    {
                        EditDataFromDistrictGames(winner, loser, operation, currentGame);
                    }
                    else if ( currentGame.IsPlayoffGame )
                    {
                        EditDataFromPlayoffGames(winner, loser, operation, currentGame);
                    }
                }
            }
            catch ( Exception ex )
            {
                Globals.ShowExceptionMessage(ex);
            }
        }
コード例 #3
0
 /// <summary>
 /// Edits each team's data (wins, losses) from district games.
 /// </summary>
 /// <param name="winner"></param>
 /// <param name="loser"></param>
 /// <param name="operation"></param>
 /// <param name="currentGame"></param>
 private static void EditWinLossDataFromDistrictGames(Team winner, Team loser, Operation operation, Game currentGame)
 {
     try
     {
         winner.DistrictWins = operation(winner.DistrictWins, 1);
         loser.DistrictLosses = operation(loser.DistrictLosses, 1);
     }
     catch ( Exception ex )
     {
         Globals.ShowExceptionMessage(ex);
     }
 }
コード例 #4
0
 /// <summary>
 /// Edits each team's data (wins, losses) from playoff games.
 /// </summary>
 /// <param name="winner"></param>
 /// <param name="loser"></param>
 /// <param name="operation"></param>
 /// <param name="currentGame"></param>
 private static void EditWinLossDataFromPlayoffGames(Team winner, Team loser, Operation operation, Game currentGame)
 {
     try
     {
         if ( _gameType != GameType.ForfeitForRulesViolation )
         {
             winner.PlayoffWins = operation(winner.PlayoffWins, 1);
             loser.PlayoffLosses = operation(loser.PlayoffLosses, 1);
         }
     }
     catch ( Exception ex )
     {
         Globals.ShowExceptionMessage(ex);
     }
 }
コード例 #5
0
        /// <summary>
        /// Edits the DataModel's Teams table with data from the specified game.
        /// </summary>
        /// <param name="direction"></param>
        private static void EditTeams(Game currentGame, Direction direction)
        {
            try
            {
                Operation operation;

                // Decide whether the teams need to be edited up or down.
                // Up for new game, down then up for edited game, down for deleted game.
                switch ( direction )
                {
                    case Direction.Up:
                        operation = new Operation(Arithmetic.Add);
                        break;

                    case Direction.Down:
                        operation = new Operation(Arithmetic.Subtract);
                        break;

                    default:
                        throw new ArgumentException("direction");
                }

                ProcessGame(currentGame, operation);
            }
            catch ( Exception ex )
            {
                Globals.ShowExceptionMessage(ex);
            }
        }
コード例 #6
0
        /// <summary>
        /// Edits each team's data (wins, losses, and first level rating points) from all games.
        /// </summary>
        /// <param name="winner"></param>
        /// <param name="loser"></param>
        /// <param name="operation"></param>
        /// <param name="currentGame"></param>
        private static void EditWinLossDataFromAllGames(Team winner, Team loser, Operation operation, Game currentGame)
        {
            try
            {
                if ( winner != null )
                {
                    winner.Wins = operation(winner.Wins, 1);

                    if ( _gameType == GameType.NonForfeit )
                    {
                        winner.RatingPointGames = operation(winner.RatingPointGames, 1);
                        winner.RatingPointsFirstLevel = operation(winner.RatingPointsFirstLevel, currentGame.WinnerRatingPoints);
                        winner.RatingPointsFirstLevelAverage = Arithmetic.Divide(winner.RatingPointsFirstLevel, winner.RatingPointGames);
                    }
                }

                if ( loser != null )
                {
                    loser.Losses = operation(loser.Losses, 1);

                    loser.RatingPointGames = operation(loser.RatingPointGames, 1);
                    // No need to increment/decrement loser.RatingPointsFirstLevel,
                    // for the operation will always be y = x + 0 or y = x - 0.
                    loser.RatingPointsFirstLevelAverage = Arithmetic.Divide(loser.RatingPointsFirstLevel, loser.RatingPointGames);
                }
            }
            catch ( Exception ex )
            {
                Globals.ShowExceptionMessage(ex);
            }
        }
コード例 #7
0
        /// <summary>
        /// Edits each team's data (games, points for, points against) from playoff games.
        /// </summary>
        /// <param name="winner"></param>
        /// <param name="loser"></param>
        /// <param name="operation"></param>
        /// <param name="currentGame"></param>
        /// <param name="winnerScore"></param>
        /// <param name="loserScore"></param>
        private static void EditDataFromPlayoffGames(Team winner, Team loser, Operation operation, Game currentGame)
        {
            try
            {
                EditWinLossDataFromPlayoffGames(winner, loser, operation, currentGame);

                if ( _gameType == GameType.NonForfeit )
                {
                    winner.PlayoffGames = operation(winner.PlayoffGames, 1);
                    winner.PlayoffPointsFor = operation(winner.PlayoffPointsFor, currentGame.WinnerScore);
                    winner.PlayoffPointsAgainst = operation(winner.PlayoffPointsAgainst, currentGame.LoserScore);

                    loser.PlayoffGames = operation(loser.PlayoffGames, 1);
                    loser.PlayoffPointsFor = operation(loser.PlayoffPointsFor, currentGame.LoserScore);
                    loser.PlayoffPointsAgainst = operation(loser.PlayoffPointsAgainst, currentGame.WinnerScore);
                }
            }
            catch ( Exception ex )
            {
                Globals.ShowExceptionMessage(ex);
            }
        }
コード例 #8
0
        /// <summary>
        /// Edits each team's data (games, adjusted points for, adjusted point against) from all games
        /// against teams outside the state or outside their classification
        /// </summary>
        /// <param name="winner"></param>
        /// <param name="loser"></param>
        /// <param name="operation"></param>
        /// <param name="winnerAdjustedScore"></param>
        /// <param name="loserAdjustedScore"></param>
        private static void EditDataFromGamesOutOfClassification(Team winner, Team loser, Operation operation, Game currentGame)
        {
            try
            {
                if ( _gameType != GameType.ForfeitForFailureToAppear )
                {
                    if ( winner != null )
                    {
                        winner.OutOfClassificationGames = operation(winner.OutOfClassificationGames, 1);
                        winner.OutOfClassificationAdjustedPointsFor
                            = operation(winner.OutOfClassificationAdjustedPointsFor, currentGame.WinnerAdjustedScore);
                        winner.OutOfClassificationAdjustedPointsAgainst
                            = operation(winner.OutOfClassificationAdjustedPointsAgainst, currentGame.LoserAdjustedScore);
                    }

                    if ( loser != null )
                    {
                        loser.OutOfClassificationGames = operation(loser.OutOfClassificationGames, 1);
                        loser.OutOfClassificationAdjustedPointsFor
                            = operation(loser.OutOfClassificationAdjustedPointsFor, currentGame.LoserAdjustedScore);
                        loser.OutOfClassificationAdjustedPointsAgainst
                            = operation(loser.OutOfClassificationAdjustedPointsAgainst, currentGame.WinnerAdjustedScore);
                    }
                }
            }
            catch ( Exception ex )
            {
                Globals.ShowExceptionMessage(ex);
            }
        }
コード例 #9
0
        /// <summary>
        /// Edits each team's data (games, points for, points against) from district games.
        /// </summary>
        /// <param name="winner"></param>
        /// <param name="loser"></param>
        /// <param name="operation"></param>
        /// <param name="currentGame"></param>
        /// <param name="winnerScore"></param>
        /// <param name="loserScore"></param>
        private static void EditDataFromDistrictGames(Team winner, Team loser, Operation operation, Game currentGame)
        {
            try
            {
                EditWinLossDataFromDistrictGames(winner, loser, operation, currentGame);

                if ( _gameType != GameType.ForfeitForFailureToAppear )
                {
                    winner.DistrictGames = operation(winner.DistrictGames, 1);
                    winner.DistrictPointsFor = operation(winner.DistrictPointsFor, currentGame.WinnerScore);
                    winner.DistrictPointsAgainst = operation(winner.DistrictPointsAgainst, currentGame.LoserScore);

                    loser.DistrictGames = operation(loser.DistrictGames, 1);
                    loser.DistrictPointsFor = operation(loser.DistrictPointsFor, currentGame.LoserScore);
                    loser.DistrictPointsAgainst = operation(loser.DistrictPointsAgainst, currentGame.WinnerScore);
                }
            }
            catch ( Exception ex )
            {
                Globals.ShowExceptionMessage(ex);
            }
        }
コード例 #10
0
        /// <summary>
        /// Stores values from the selected game into a Game instance.
        /// </summary>
        private Game StoreOldGameValues()
        {
            Game oldGame = null;

            try
            {
                oldGame = new Game
                {
                    ID = 0,
                    Week = SelectedGame.Week,
                    Guest = SelectedGame.Guest,
                    GuestScore = SelectedGame.GuestScore,
                    GuestAdjustedScore = SelectedGame.GuestAdjustedScore,
                    Host = SelectedGame.Host,
                    HostScore = SelectedGame.HostScore,
                    HostAdjustedScore = SelectedGame.HostAdjustedScore,
                    IsDistrictGame = SelectedGame.IsDistrictGame,
                    IsPlayoffGame = SelectedGame.IsPlayoffGame,
                    IsForfeit = SelectedGame.IsForfeit,
                    Notes = SelectedGame.Notes
                };

                oldGame.DecideWinnerAndLoser();
            }
            catch ( Exception ex )
            {
                Globals.ShowExceptionMessage(ex);
            }

            return oldGame;
        }
コード例 #11
0
        /// <summary>
        /// Stores values from the data entry controls into a Game instance.
        /// </summary>
        /// <returns></returns>
        private Game StoreNewGameValues()
        {
            Game newGame = null;

            try
            {
                newGame = new Game
                {
                    ID = 0,
                    Week = this.Week,
                    Guest = this.Guest,
                    GuestScore = this.GuestScore,
                    GuestAdjustedScore = this.GuestAdjustedScore,
                    Host = this.Host,
                    HostScore = this.HostScore,
                    HostAdjustedScore = this.HostAdjustedScore,
                    IsDistrictGame = this.IsDistrictGame,
                    IsPlayoffGame = this.IsPlayoffGame,
                    IsForfeit = this.IsForfeit,
                    Notes = this.Notes
                };

                newGame.DecideWinnerAndLoser();
            }
            catch ( Exception ex )
            {
                Globals.ShowExceptionMessage(ex);
            }

            return newGame;
        }