Exemplo n.º 1
0
        /// <summary>
        /// Each method below displays the appropriate
        /// table that correponds to each MainWindow button.
        /// The only exception is the DisplayCompare method.
        /// That method displays the compare window.
        /// </summary>

        private void DisplayPassingStats(object sender, RoutedEventArgs e)
        {
            List <object> stats = new List <object>();

            if (searchBar.Text.Equals(""))
            {
                List <Player> players = controller.PlayerSort(4);
                for (int i = players.Count - 1; i >= 0; i--)
                {
                    int passingYds    = players[i].SeasonStats.PassingYds;
                    int passingTds    = players[i].SeasonStats.PassingTds;
                    int interceptions = players[i].SeasonStats.Interceptions;
                    if (passingYds != 0 || passingTds != 0 || interceptions != 0)
                    {
                        stats.Add(new PassingStats(players[i].Name, passingYds, passingTds, interceptions));
                    }
                }
            }
            else
            {
                try
                {
                    Player player = controller.GetPlayer(searchBar.Text);
                    stats.Add(new PassingStats(player.Name, player.SeasonStats.PassingYds,
                                               player.SeasonStats.PassingTds, player.SeasonStats.Interceptions));
                }
                catch (Exception)
                {
                    MessageBox.Show("Player not found", "Error");
                }
            }
            DataContext = new DataGridTable(stats);
        }
 private void AddPlayer(object sender, RoutedEventArgs e)
 {
     try
     {
         Header1.DataContext = new TextboxText()
         {
             textdata = "Player"
         };
         Player p = controller.GetPlayer(searchBar.Text);
         //adds the player to the list
         if (compareList.Count < 5)
         {
             compareList.Add(p);
             countTemp++;
             if (countTemp == 1)
             {
                 OneA.DataContext = new TextboxText()
                 {
                     textdata = compareList.ElementAt(0).Name
                 };
                 Btn1.Visibility = System.Windows.Visibility.Visible;
             }
             else if (countTemp == 2)
             {
                 TwoA.DataContext = new TextboxText()
                 {
                     textdata = compareList.ElementAt(1).Name
                 };
                 Btn2.Visibility = System.Windows.Visibility.Visible;
             }
             else if (countTemp == 3)
             {
                 ThreeA.DataContext = new TextboxText()
                 {
                     textdata = compareList.ElementAt(2).Name
                 };
                 Btn3.Visibility = System.Windows.Visibility.Visible;
             }
             else if (countTemp == 4)
             {
                 FourA.DataContext = new TextboxText()
                 {
                     textdata = compareList.ElementAt(3).Name
                 };
                 Btn4.Visibility = System.Windows.Visibility.Visible;
             }
             else if (countTemp == 5)
             {
                 FiveA.DataContext = new TextboxText()
                 {
                     textdata = compareList.ElementAt(4).Name
                 };
                 Btn5.Visibility = System.Windows.Visibility.Visible;
             }
         }
         else
         {
             MessageBox.Show("Can only compare 5 players at a time.");
         }
         Clear();
     }
     catch (Exception)
     {
         MessageBox.Show("Not a valid player name.");
     }
 }