/// <summary> /// Computes all players in the NHL and populates the ranking grid /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void ComputeAll_Click(object sender, EventArgs e) { _dt.Rows.Clear(); foreach (var team in SelectionResources.TeamList) { foreach (var person in team.PersonList) { var player = new Player(ApiLoader.LoadPlayer(DateTime.Now.Year, person.Id), person); SeasonCalculator.CalculateExpectedSeason(player); if (player.HasSufficientInfo) { AddPlayerToDt(player); } } } BindGrid(); //Making the computeAll button invisible computeAllButton.Visible = false; //Making the export button visible exportButton.Visible = true; }
/// <summary> /// Calls the needed methods to calculate and print the player's expected season in the result textbox /// </summary> /// <param name="sender"></param> /// <param name="e"></param> public void ComputePlayer(object sender, EventArgs e) { if (playersSelect.SelectedItem == null) { return; } SelectionResources.PlayerIndex = playersSelect.SelectedIndex; computeButton.Enabled = false; var person = SelectionResources.PersonList[playersSelect.SelectedIndex]; //Check if the player hasn't already been loaded (avoiding to call the api again) if (!SelectionResources.PlayersMemory.Any(p => p.Id.Equals(SelectionResources.PersonList[playersSelect.SelectedIndex].Id))) { //Fetching the player through the player loader var player = new Player(ApiLoader.LoadPlayer(DateTime.Now.Year, person.Id), person); SeasonCalculator.CalculateExpectedSeason(player); //Adding player to the already calculated players if he has sufficient info if (player.HasSufficientInfo) { SelectionResources.PlayersMemory.Add(player); } //Printing the player's expected season to the result textbox result.Text = player.ToString(); } else { result.Text = SelectionResources.PlayersMemory.First(p => p.Id.Equals(person.Id)).ToString(); } }