public FootballersDataSet.FootballersDataTable MapFootballers(IEnumerable <Footballer> footballers) { var footballersDataTable = new FootballersDataSet().Footballers; foreach (var footballer in footballers) { var row = footballersDataTable.NewFootballersRow(); row.FirstName = footballer.first_name; row.Surname = footballer.second_name; row.Position = ((Positions)footballer.element_type).ToString(); row.Team = ((Teams)footballer.team).ToString(); row.Cost = (decimal)footballer.now_cost / 10; row.PointsLstRnd = footballer.event_points; row.TotalPoints = footballer.total_points; row.AveragePoints = decimal.Parse(footballer.points_per_game, NumberStyles.Any); row.AvgPointsPound = (row.AveragePoints / row.Cost) * (footballer.minutes / 1000); row.TotPointsPound = (row.TotalPoints / row.Cost) * (footballer.minutes / 1000); //row.AvgPointsPound = footballer.AvgPointsDollar; //row.TotPointsPound = footballer.TotPointsDollar; row.TransfersOut = footballer.transfers_out; row.YellowCards = footballer.yellow_cards; row.GoalsConceded = footballer.goals_conceded; //row.GoalsConcededPts = footballer.GoalsConcededPts; row.Saves = footballer.saves; //row.SavesPts = footballer.SavesPts; row.GoalsScored = footballer.goals_scored; row.ValueSeason = decimal.Parse(footballer.value_season); row.TransfersOutRnd = footballer.transfers_out_event; row.PriceRise = footballer.cost_change_start; row.PriceFallRnd = footballer.cost_change_event_fall; row.PriceFall = footballer.cost_change_start_fall; row.ValueForm = decimal.Parse(footballer.value_form); row.PenaltiesMissed = footballer.penalties_missed; row.Form = decimal.Parse(footballer.form); row.Bonus = footballer.bonus; row.CleanSheets = footballer.clean_sheets; row.Assists = footballer.assists; row.SelectedByPcent = decimal.Parse(footballer.selected_by_percent); row.TransfersIn = footballer.transfers_in; row.OwnGoals = footballer.own_goals; row.EAIndex = footballer.ea_index; row.PenaltiesSaved = footballer.penalties_saved; row.DreamTeamCount = footballer.dreamteam_count; row.MinutesPlayed = footballer.minutes; row.TransfersInRound = footballer.transfers_in_event; row.PriceRiseRound = footballer.cost_change_event; row.RedCards = footballer.red_cards; row.BPS = footballer.bps; row.News = footballer.news; row.Influence = decimal.Parse(footballer.influence); row.Creativity = decimal.Parse(footballer.creativity); row.Threat = decimal.Parse(footballer.threat); row.Status = char.Parse(footballer.status); row.InDreamteam = footballer.in_dreamteam; row.Photo = System.IO.Path.GetFileNameWithoutExtension(footballer.photo); row.ID = footballer.id; footballersDataTable.AddFootballersRow(row); } return footballersDataTable; }
public MainForm(FootballersDataSet.FootballersDataTable footballersDataTable, List<Event> events) { // Initialise the form and set up our stream from constructor InitializeComponent(); _footballersDataTable = footballersDataTable; //Setup a list of Teams,Positions and Price var teams = new HashSet<string>(); var positions = new HashSet<string>(); var price = new HashSet<decimal>(); // Find out what event we are at int index = 0; while (true) { if (!events[index].finished) { break; } index++; } // create a list of all our footballer ID's List<int> footballers = new List<int>(); // If we have a team then we need to load it into our program if (Properties.Settings.Default.TeamNumber != -1) { var proxy = client.Proxy; client.UseDefaultCredentials = true; client.Proxy.Credentials = CredentialCache.DefaultCredentials; Stream stream = client.OpenRead("https://fantasy.premierleague.com/drf/entry/" + Properties.Settings.Default.TeamNumber + "/event/" + (index) +"/picks"); using (StreamReader reader = new StreamReader(stream)) { root = (MyTeam)JsonConvert.DeserializeObject(reader.ReadLine(), typeof(MyTeam)); } if (root != null) { foreach (var f in root.picks) { footballers.Add(f.element); } } } else { rdoTeam.Enabled = false; } foreach (var row in _footballersDataTable.AsEnumerable()) { teams.Add(row.Team); positions.Add(row.Position); price.Add(row.Cost); if (footballers.Contains(row.ID)) { row.MyTeam = true; } switch (row.Position) { case "Goalkeeper": totGK += row.TotalPoints; break; case "Defender": totDEF += row.TotalPoints; break; case "Midfielder": totMID += row.TotalPoints; break; case "Forward": totFWD += row.TotalPoints; break; default: break; } totPlayers += 1; } //Display the stats lblTotGK.Text = totGK.ToString(); lblTotDef.Text = totDEF.ToString(); lblTotMids.Text = totMID.ToString(); lblTotFwds.Text = totFWD.ToString(); lblTotPlayers.Text = totPlayers.ToString(); var teamArr = teams.ToArray(); Array.Sort(teamArr); var priceArr = price.ToArray(); Array.Sort(priceArr); Array.Reverse(priceArr); // Initialising the Team Combo Box cboTeams.Items.Add("ALL"); cboTeams.Items.AddRange(teamArr.ToArray()); // Initialising the Positions Combo Box cboPositions.Items.Add("ALL"); cboPositions.Items.AddRange(positions.ToArray()); // Initialising the Price Combo Box cboPrice.Items.Add("ALL"); cboPrice.Items.AddRange(priceArr.Cast<object>().ToArray()); //Setting the initial Combo Box indexes to 0 cboPrice.SelectedIndex = 0; cboTeams.SelectedIndex = 0; cboPositions.SelectedIndex = 0; dbgPlayers.DataSource = _footballersDataTable; //Freezing the Surname column so it stays when scrolling the data Horizontally dbgPlayers.Columns["surname"].Frozen = true; //Setting the News Column so we can see all the contents dbgPlayers.Columns["news"].Width = 250; //Hiding some fields from the end user dbgPlayers.Columns["status"].Visible = false; dbgPlayers.Columns["InDreamteam"].Visible = false; dbgPlayers.Columns["MyTeam"].Visible = false; dbgPlayers.Columns["Photo"].Visible = false; dbgPlayers.Columns["ID"].Visible = false; //Setting the All view to checked by default so we display all the data rdoAll.Checked = true; //Using my helper method to set the Datagrid View to Double buffered for performance improvements dbgPlayers.DoubleBuffered(true); // Put each of the columns into programmatic sort mode so we can implement our own custom sort foreach (DataGridViewColumn column in dbgPlayers.Columns) { column.SortMode = DataGridViewColumnSortMode.Programmatic; } //Utilise our column selector class DataGridViewColumnSelector cs = new DataGridViewColumnSelector(dbgPlayers); // Temp disable while we load team //rdoTeam.Enabled = false; lblCurrentRound.Text = events[index].id.ToString(); lblDeadline.Text = events[index].deadline_time_formatted; // Use the system setting if it exists to go get our Team number so we can load our team in var team = Properties.Settings.Default.TeamNumber; }