public static void CreateCXMLDocument(string excelFilename, Team t) { if (File.Exists(excelFilename)) { File.Delete(excelFilename); } XLWorkbook xLWorkbook = new XLWorkbook(); IXLWorksheet iXLWorksheet = xLWorkbook.Worksheets.Add(t.TeamName.NormalizeString().Left(31)); iXLWorksheet.Cell("A1").Value = (t.TeamName); iXLWorksheet.Cell("A1").Style.Font.FontSize = (16.0); iXLWorksheet.Cell("A1").Style.Font.FontColor = (XLColor.DarkBlue); iXLWorksheet.Cell("A1").Hyperlink = (new XLHyperlink("http://www.transfermarkt.com/" + t.Url)); List<Player> lineupPlayers = new List<Player>(); if (t.Players != null) lineupPlayers = t.Players.Where(p => p.Lineup == Player.LineUpStatus.YES).ToList(); Player emptyGoalkeeper = new Player() { MainPosition = "GK", Statistics = new List<Statistics>() { new Statistics() { }, new Statistics() { }, new Statistics() { }, new Statistics() { } } }; Player emptyDefender = new Player() { MainPosition = "CB", Statistics = new List<Statistics>() { new Statistics() { }, new Statistics() { }, new Statistics() { }, new Statistics() { } } }; Player emptyMidfielder = new Player() { MainPosition = "DM", Statistics = new List<Statistics>() { new Statistics() { }, new Statistics() { }, new Statistics() { }, new Statistics() { } } }; Player emptyAttacker = new Player() { MainPosition = "SS", Statistics = new List<Statistics>() { new Statistics() { }, new Statistics() { }, new Statistics() { }, new Statistics() { } } }; int gkCount = 5; int dfCount = 14; int mfCount = 14; int atCount = 14; var goalkeepers = lineupPlayers.Where(lp => lp.MainPosition == "GK"); var defenders = lineupPlayers.Where(lp => lp.MainPosition == "CB" || lp.MainPosition == "LB" || lp.MainPosition == "RB"); var midfielders = lineupPlayers.Where(lp => lp.MainPosition == "DM" || lp.MainPosition == "CM" || lp.MainPosition == "LM" || lp.MainPosition == "RM" || lp.MainPosition == "AM"); var attackers = lineupPlayers.Where(lp => lp.MainPosition == "LW" || lp.MainPosition == "RW" || lp.MainPosition == "CF" || lp.MainPosition == "SS"); lineupPlayers = new List<Player>(); for (int i = 0; i < gkCount; i++) if (i < goalkeepers.Count()) lineupPlayers.Add(goalkeepers.ElementAt(i)); else lineupPlayers.Add(emptyGoalkeeper); for (int i = 0; i < dfCount; i++) if (i < defenders.Count()) lineupPlayers.Add(defenders.ElementAt(i)); else lineupPlayers.Add(emptyDefender); for (int i = 0; i < mfCount; i++) if (i < midfielders.Count()) lineupPlayers.Add(midfielders.ElementAt(i)); else lineupPlayers.Add(emptyMidfielder); for (int i = 0; i < atCount; i++) if (i < attackers.Count()) lineupPlayers.Add(attackers.ElementAt(i)); else lineupPlayers.Add(emptyAttacker); try { int playersCount = lineupPlayers.Count(); for (int i = 0; i < playersCount; i++) { Player player = lineupPlayers.ElementAt(i); iXLWorksheet.Row(i * 5 + 1).Style.Fill.BackgroundColor = (XLColor.AshGrey); iXLWorksheet.Column("A").Width = (12.0); iXLWorksheet.Column("B").Width = (30.0); iXLWorksheet.Column("D").Width = (3.0); iXLWorksheet.Column("E").Width = (3.0); iXLWorksheet.Column("F").Width = (3.0); iXLWorksheet.Column("G").Width = (3.0); iXLWorksheet.Column("H").Width = (3.0); iXLWorksheet.Column("I").Width = (3.0); iXLWorksheet.Column("J").Width = (3.0); iXLWorksheet.Column("K").Width = (3.0); iXLWorksheet.Column("L").Width = (3.0); if (player.MainPosition == "GK") { iXLWorksheet.Cell("A" + (i * 5 + 2).ToString()).Style.Fill.BackgroundColor = (XLColor.LightGreen); iXLWorksheet.Cell("A" + (i * 5 + 3).ToString()).Style.Fill.BackgroundColor = (XLColor.LightGreen); iXLWorksheet.Cell("A" + (i * 5 + 4).ToString()).Style.Fill.BackgroundColor = (XLColor.LightGreen); iXLWorksheet.Cell("A" + (i * 5 + 5).ToString()).Style.Fill.BackgroundColor = (XLColor.LightGreen); } else { if (player.MainPosition == "CB" || player.MainPosition == "LB" || player.MainPosition == "RB") { iXLWorksheet.Cell("A" + (i * 5 + 2).ToString()).Style.Fill.BackgroundColor = (XLColor.BabyBlue); iXLWorksheet.Cell("A" + (i * 5 + 3).ToString()).Style.Fill.BackgroundColor = (XLColor.BabyBlue); iXLWorksheet.Cell("A" + (i * 5 + 4).ToString()).Style.Fill.BackgroundColor = (XLColor.BabyBlue); iXLWorksheet.Cell("A" + (i * 5 + 5).ToString()).Style.Fill.BackgroundColor = (XLColor.BabyBlue); } else { if (player.MainPosition == "DM" || player.MainPosition == "CM" || player.MainPosition == "LM" || player.MainPosition == "RM" || player.MainPosition == "AM") { iXLWorksheet.Cell("A" + (i * 5 + 2).ToString()).Style.Fill.BackgroundColor = (XLColor.Orange); iXLWorksheet.Cell("A" + (i * 5 + 3).ToString()).Style.Fill.BackgroundColor = (XLColor.Orange); iXLWorksheet.Cell("A" + (i * 5 + 4).ToString()).Style.Fill.BackgroundColor = (XLColor.Orange); iXLWorksheet.Cell("A" + (i * 5 + 5).ToString()).Style.Fill.BackgroundColor = (XLColor.Orange); } else { if (player.MainPosition == "LW" || player.MainPosition == "RW" || player.MainPosition == "CF" || player.MainPosition == "SS") { iXLWorksheet.Cell("A" + (i * 5 + 2).ToString()).Style.Fill.BackgroundColor = (XLColor.Red); iXLWorksheet.Cell("A" + (i * 5 + 3).ToString()).Style.Fill.BackgroundColor = (XLColor.Red); iXLWorksheet.Cell("A" + (i * 5 + 4).ToString()).Style.Fill.BackgroundColor = (XLColor.Red); iXLWorksheet.Cell("A" + (i * 5 + 5).ToString()).Style.Fill.BackgroundColor = (XLColor.Red); } } } } iXLWorksheet.Cell("C" + (i * 5 + 1).ToString()).Value = ("PO"); iXLWorksheet.Cell("D" + (i * 5 + 1).ToString()).Value = ("GO"); iXLWorksheet.Cell("E" + (i * 5 + 1).ToString()).Value = ("AG"); iXLWorksheet.Cell("F" + (i * 5 + 1).ToString()).Value = ("AS"); iXLWorksheet.Cell("G" + (i * 5 + 1).ToString()).Value = ("ZK"); iXLWorksheet.Cell("H" + (i * 5 + 1).ToString()).Value = ("ZC"); iXLWorksheet.Cell("I" + (i * 5 + 1).ToString()).Value = ("CK"); iXLWorksheet.Cell("J" + (i * 5 + 1).ToString()).Value = ("SN"); iXLWorksheet.Cell("K" + (i * 5 + 1).ToString()).Value = ("SF"); iXLWorksheet.Cell("L" + (i * 5 + 1).ToString()).Value = ("MI"); iXLWorksheet.Cell("M" + (i * 5 + 1).ToString()).Value = ("UU"); iXLWorksheet.Cell("N" + (i * 5 + 1).ToString()).Value = ("GU"); iXLWorksheet.Cell("O" + (i * 5 + 1).ToString()).Value = ("AU"); iXLWorksheet.Cell("P" + (i * 5 + 1).ToString()).Value = ("MU"); iXLWorksheet.Cell("Q" + (i * 5 + 1).ToString()).Value = ("MPG"); iXLWorksheet.Cell("M" + (i * 5 + 1).ToString()).Style.Alignment.Horizontal = (0); iXLWorksheet.Cell("N" + (i * 5 + 1).ToString()).Style.Alignment.Horizontal = (0); iXLWorksheet.Cell("O" + (i * 5 + 1).ToString()).Style.Alignment.Horizontal = (0); iXLWorksheet.Cell("P" + (i * 5 + 1).ToString()).Style.Alignment.Horizontal = (0); iXLWorksheet.Cell("Q" + (i * 5 + 1).ToString()).Style.Alignment.Horizontal = (0); string text = player.MainPosition; if (player.SecondaryPositions != null && player.SecondaryPositions.Count > 0) { text += " ("; for (int j = 0; j < player.SecondaryPositions.Count; j++) { text += player.SecondaryPositions[j]; if (j < player.SecondaryPositions.Count - 1) { text += ","; } } text += ")"; } iXLWorksheet.Cell("A" + (i * 5 + 2).ToString()).Value = (text); iXLWorksheet.Cell("A" + (i * 5 + 3).ToString()).Value = ("[" + player.PlayerNr + "] " + player.PrefferedFoot); if (player.Statistics !=null && player.Statistics[0] != null) { if (player.Statistics[0].GoalsScoredTopLeague == "0") { iXLWorksheet.Cell("A" + (i * 5 + 4).ToString()).Value = ("0.000001"); } else { iXLWorksheet.Cell("A" + (i * 5 + 4).ToString()).Value = (player.Statistics[0].GoalsScoredTopLeague); } if (player.Statistics[0].MinutesPerGoalTopLeague == "0") { iXLWorksheet.Cell("A" + (i * 5 + 5).ToString()).Value = ("0.000001"); } else { iXLWorksheet.Cell("A" + (i * 5 + 5).ToString()).Value = (player.Statistics[0].MinutesPerGoalTopLeague); } } iXLWorksheet.Cell("A" + (i * 5 + 3).ToString()).Style.Alignment.Horizontal = XLAlignmentHorizontalValues.Left; iXLWorksheet.Cell("B" + (i * 5 + 2).ToString()).Hyperlink = new XLHyperlink("http://www.transfermarkt.com/" + player.TmUrl); iXLWorksheet.Cell("B" + (i * 5 + 2).ToString()).Value = (player.Name + ", " + player.Age); iXLWorksheet.Cell("B" + (i * 5 + 2).ToString()).Style.Font.Bold = (true); iXLWorksheet.Cell("B" + (i * 5 + 3).ToString()).Style.Alignment.Horizontal = XLAlignmentHorizontalValues.Left; iXLWorksheet.Cell("B" + (i * 5 + 3).ToString()).Value = (player.Injury); iXLWorksheet.Cell("B" + (i * 5 + 3).ToString()).Style.Alignment.Horizontal = XLAlignmentHorizontalValues.Left; iXLWorksheet.Cell("B" + (i * 5 + 4).ToString()).Value = player.Contract; iXLWorksheet.Cell("B" + (i * 5 + 4).ToString()).Style.Alignment.Horizontal = XLAlignmentHorizontalValues.Left; var cv = (player.MarketValue); if (player.NationalPlayer != null) cv += " / " + player.NationalPlayer; iXLWorksheet.Cell("B" + (i * 5 + 5).ToString()).Value = cv; iXLWorksheet.Cell("B" + (i * 5 + 5).ToString()).Style.Alignment.Horizontal = XLAlignmentHorizontalValues.Left; if (player.NationalPlayerUrl != null) iXLWorksheet.Cell("B" + (i * 5 + 5).ToString()).Hyperlink = new XLHyperlink("http://www.transfermarkt.com/" + player.NationalPlayerUrl); if (player.Matches != null) { for (int k = 0; k < player.Matches.Count; k++) { Match match = player.Matches[k]; if (match.Description != null) { iXLWorksheet.Columns("C").Width = 20.0; iXLWorksheet.Cell("C" + (i * 5 + k + 2).ToString()).Value = match.Description; } else { iXLWorksheet.Columns("C").Width = (3.0); iXLWorksheet.Cell("C" + (i * 5 + k + 2).ToString()).Value = match.Position; iXLWorksheet.Cell("D" + (i * 5 + k + 2).ToString()).Value = match.Goals; iXLWorksheet.Cell("E" + (i * 5 + k + 2).ToString()).Value = match.OwnGoals; iXLWorksheet.Cell("F" + (i * 5 + k + 2).ToString()).Value = match.Assists; iXLWorksheet.Cell("G" + (i * 5 + k + 2).ToString()).Value = match.YellowCards; iXLWorksheet.Cell("H" + (i * 5 + k + 2).ToString()).Value = match.YellowRedCards; iXLWorksheet.Cell("I" + (i * 5 + k + 2).ToString()).Value = match.RedCards; iXLWorksheet.Cell("J" + (i * 5 + k + 2).ToString()).Value = match.SubstitutedOn; iXLWorksheet.Cell("K" + (i * 5 + k + 2).ToString()).Value = match.SubstitutedOff; iXLWorksheet.Cell("L" + (i * 5 + k + 2).ToString()).Value = match.MinutesPlayed; } } } if (player.Statistics != null) { for (int l = 0; l < player.Statistics.Count; l++) { Statistics statistics = player.Statistics[l]; if (statistics == null) { statistics = new Statistics(); } iXLWorksheet.Cell("M" + (i * 5 + l + 2).ToString()).Style.Alignment.Horizontal = (0); iXLWorksheet.Cell("N" + (i * 5 + l + 2).ToString()).Style.Alignment.Horizontal = (0); iXLWorksheet.Cell("O" + (i * 5 + l + 2).ToString()).Style.Alignment.Horizontal = (0); iXLWorksheet.Cell("P" + (i * 5 + l + 2).ToString()).Style.Alignment.Horizontal = (0); iXLWorksheet.Cell("Q" + (i * 5 + l + 2).ToString()).Style.Alignment.Horizontal = (0); iXLWorksheet.Cell("M" + (i * 5 + l + 2).ToString()).Style.Font.Bold = (true); iXLWorksheet.Cell("N" + (i * 5 + l + 2).ToString()).Style.Font.Bold = (true); iXLWorksheet.Cell("O" + (i * 5 + l + 2).ToString()).Style.Font.Bold = (true); iXLWorksheet.Cell("P" + (i * 5 + l + 2).ToString()).Style.Font.Bold = (true); iXLWorksheet.Cell("Q" + (i * 5 + l + 2).ToString()).Style.Font.Bold = (true); iXLWorksheet.Cell("M" + (i * 5 + l + 2).ToString()).Style.Fill.BackgroundColor = DocumentBuilder.seasonColors[l]; iXLWorksheet.Cell("N" + (i * 5 + l + 2).ToString()).Style.Fill.BackgroundColor = DocumentBuilder.seasonColors[l]; iXLWorksheet.Cell("O" + (i * 5 + l + 2).ToString()).Style.Fill.BackgroundColor = DocumentBuilder.seasonColors[l]; iXLWorksheet.Cell("P" + (i * 5 + l + 2).ToString()).Style.Fill.BackgroundColor = DocumentBuilder.seasonColors[l]; iXLWorksheet.Cell("Q" + (i * 5 + l + 2).ToString()).Style.Fill.BackgroundColor = DocumentBuilder.seasonColors[l]; if (statistics.GamesPlayed == null) { statistics.GamesPlayed = "0.000001"; } else { if (statistics.GamesPlayed == "0") { statistics.GamesPlayed = "0.000001"; } } if (statistics.GoalsScored == null) { statistics.GoalsScored = "0.000001"; } else { if (statistics.GoalsScored == "0") { statistics.GoalsScored = "0.000001"; } } if (statistics.Assists == null) { statistics.Assists = "0.000001"; } else { if (statistics.Assists == "0") { statistics.Assists = "0.000001"; } } if (statistics.MinutesPlayed == null) { statistics.MinutesPlayed = "1"; } else { if (statistics.MinutesPlayed == "0") { statistics.MinutesPlayed = "1"; } } if (statistics.MinutesPerGoal == null) { statistics.MinutesPerGoal = "0.000001"; } else { if (statistics.MinutesPerGoal == "0") { statistics.MinutesPerGoal = "0.000001"; } } iXLWorksheet.Cell("M" + (i * 5 + l + 2).ToString()).Value = statistics.GamesPlayed.Replace("-", "0.000001"); iXLWorksheet.Cell("N" + (i * 5 + l + 2).ToString()).Value = statistics.GoalsScored.Replace("-", "0.000001"); iXLWorksheet.Cell("O" + (i * 5 + l + 2).ToString()).Value = statistics.Assists.Replace("-", "0.000001"); iXLWorksheet.Cell("P" + (i * 5 + l + 2).ToString()).Value = statistics.MinutesPlayed.Replace("-", "0.000001"); iXLWorksheet.Cell("Q" + (i * 5 + l + 2).ToString()).Value = statistics.MinutesPerGoal.Replace("-", "0.000001"); } } } CreateSummaryTable(iXLWorksheet.Cell("H237")); MemoryStream ms = new MemoryStream(); xLWorkbook.SaveAs(ms); FileStream file = new FileStream(excelFilename, FileMode.Create, FileAccess.Write); ms.WriteTo(file); file.Close(); ms.Close(); } catch (Exception ex) { Logger.Exception(ex); MessageBox.Show(ex.Message); } }
public static string GetTeamArchiveFileName(Competition c,Team t) { return "\\cache\\arhiva\\" + c.CompetitionCountry.NormalizeString()+ "\\" + c.CompetitionName.NormalizeString()+ "\\" + t.TeamName.NormalizeString()+ ".xlsx"; }
public static string GetTeamTempDataFileName(Team t) { return "\\cache\\" + t.TeamId.ToString() + "_tmp.txt"; }
private async Task LoadPlayers(Team team) { try { _playerLoadingInProgress = true; lbUnamapped.Visible = false; lblUnmapped.Visible = false; this.dgvPlayers.DataSource = null; this.tbStatus.Clear(); this.pbLoadingPlayers.Visible = true; if (team.Players == null) team.Players = await DataLoader.LoadPlayersAsync(team.TeamId); _cachedStats = LoadCachedData(team); foreach (var p in team.Players) { var pl = _cachedStats.Where(cs => cs.PlayerId == p.PlayerId).FirstOrDefault(); if (pl != null) p.CurrentSeasonStatistics = pl.CurrentSeasonStatistics; } if (team.GameLineups != null) { List<string> matchedPlayers = SetLineupStatus(team); List<string> unmatchedPlayers = new List<string>(); foreach (string s in team.GameLineups) { if (matchedPlayers.Contains(s.ToLower()) == false) unmatchedPlayers.Add(s); } lbUnamapped.DataSource = unmatchedPlayers; if (unmatchedPlayers.Count > 0) { lbUnamapped.Visible = true; lblUnmapped.Visible = true; } else { lbUnamapped.Visible = false; lblUnmapped.Visible = false; } } else { DetermineLineupStatus(team); lbUnamapped.Visible = false; lblUnmapped.Visible = false; } this.pbLoadingPlayers.Visible = false; dgvPlayers.AutoGenerateColumns = false; dgvPlayers.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.None; dgvPlayers.Columns.Clear(); DataGridViewTextBoxColumn c = new DataGridViewTextBoxColumn(); c.Width = 30; c.DataPropertyName = "PlayerNr"; dgvPlayers.Columns.Add(c); c = new DataGridViewTextBoxColumn(); c.DataPropertyName = "Name"; c.Width = 125; dgvPlayers.Columns.Add(c); c = new DataGridViewTextBoxColumn(); c.DataPropertyName = "MainPosition"; c.Width = 30; dgvPlayers.Columns.Add(c); c = new DataGridViewTextBoxColumn(); c.DataPropertyName = "UU"; c.Width = 30; dgvPlayers.Columns.Add(c); c = new DataGridViewTextBoxColumn(); c.DataPropertyName = "MU"; c.Width = 40; dgvPlayers.Columns.Add(c); c = new DataGridViewTextBoxColumn(); c.DataPropertyName = "UG"; c.Width = 30; dgvPlayers.Columns.Add(c); DataGridViewButtonColumn bc = new DataGridViewButtonColumn() { UseColumnTextForButtonValue = true, Text = "TMS", Width = 40 }; dgvPlayers.Columns.Add(bc); c = new DataGridViewTextBoxColumn(); c.AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; c.DataPropertyName = "Injury"; dgvPlayers.Columns.Add(c); dgvPlayers.DataSource = team.Players; foreach (DataGridViewRow dgvr in dgvPlayers.Rows) { dgvr.Cells[7].Style = new DataGridViewCellStyle() { Font = new Font(FontFamily.GenericSansSerif, 8, FontStyle.Italic) }; Player player = (Player)dgvr.DataBoundItem; if (player.Injury != null) for (int i = 0; i < dgvr.Cells.Count; i++) dgvr.Cells[i].ToolTipText = player.Injury; if (player.CurrentSeasonStatistics != null) { dgvr.Cells[3].Value = player.CurrentSeasonStatistics.GamesPlayed; dgvr.Cells[4].Value = player.CurrentSeasonStatistics.MinutesPlayed; dgvr.Cells[5].Value = player.CurrentSeasonStatistics.GoalsScored; } if (player.Lineup == Player.LineUpStatus.YES) { dgvr.Cells[0].Style.BackColor = Color.LightGreen; dgvr.Cells[1].Style.BackColor = Color.LightGreen; } else if (player.Lineup == Player.LineUpStatus.UNKNOWN) { dgvr.Cells[0].Style.BackColor = Color.Orange; dgvr.Cells[1].Style.BackColor = Color.Orange; } if (player.MainPosition == "GK") { dgvr.Cells[2].Style.BackColor = (Color.LightGreen); } else { if (player.MainPosition == "CB" || player.MainPosition == "LB" || player.MainPosition == "RB") { dgvr.Cells[2].Style.BackColor = Color.Aqua; } else { if (player.MainPosition == "DM" || player.MainPosition == "CM" || player.MainPosition == "LM" || player.MainPosition == "RM" || player.MainPosition == "AM") { dgvr.Cells[2].Style.BackColor = Color.Orange; } else { if (player.MainPosition == "LW" || player.MainPosition == "RW" || player.MainPosition == "CF" || player.MainPosition == "SS") { dgvr.Cells[2].Style.BackColor = Color.Red; } } } } } if (dgvPlayers.Rows.Count > 0) dgvPlayers.Rows[0].Selected = false; string text; text = cbCurrentSeason.SelectedItem.ToString(); for (int i = 0; i < team.Players.Count; i++) { string text2 = team.Players[i].TmUrl.Substring(1); string text3 = text2.Substring(0, text2.IndexOf("/")); team.Players[i].PlayerStatsUrl = text3 + "/leistungsdaten/spieler/" + team.Players[i].PlayerId + "/saison/" + text + "/plus/1"; } } catch (Exception ex) { Logger.Exception(ex); MessageBox.Show(ex.Message); } _playerLoadingInProgress = false; }
private async Task GetPlayersData(Player p, Team team) { StreamWriter streamWriter = null, currentSeasonData = null; try { if (p.Lineup == Player.LineUpStatus.YES) { Statistics statistics = new Statistics(); p.Statistics = new List<Statistics>(); p.Matches = new List<Match>(); streamWriter = new StreamWriter(Application.StartupPath + Helper.GetTeamDataFileName(team), true); currentSeasonData = new StreamWriter(Application.StartupPath + Helper.GetTeamTempDataFileName(team), true); bool currentSeason = true; bool flag2 = false; for (int i = 0; i < 4; i++) { string year; year = ((int)cbCurrentSeason.SelectedItem - i).ToString(); bool flag3 = false; Statistics statistics2 = new Statistics(); if (!currentSeason) { List<Player> list = ( from cs in this._cachedStats where cs.PlayerId.Equals(p.PlayerId) select cs).ToList<Player>(); if (list.Count > 0) { if (list.First().Statistics != null) { List<Statistics> list2 = ( from ss in list.First<Player>().Statistics where ss.Year.Equals(year) select ss).ToList<Statistics>(); if (list2.Count > 0) { flag3 = true; statistics2 = list2.ElementAt(0); p.Statistics.Add(statistics2); p.SecondaryPositions = list.First<Player>().SecondaryPositions.ToList<string>(); p.PrefferedFoot = list.First<Player>().PrefferedFoot; } } } } if (!flag3 || currentSeason) { statistics2.Year = ((int)cbCurrentSeason.SelectedItem - i).ToString(); string text = p.TmUrl.Substring(1); string text2 = text.Substring(0, text.IndexOf("/")); string playerStatsUrl = text2 + "/leistungsdaten/spieler/" + p.PlayerId + "/saison/" + year + "/plus/1"; statistics = await DataLoader.LoadPlayerStatisticsAsync(playerStatsUrl, currentSeason, year, p.MainPosition); if (statistics != null && statistics.Contract != null) p.Contract = statistics.Contract; if (statistics != null && statistics.NationalPlayer != null) p.NationalPlayer = statistics.NationalPlayer; if (statistics != null && statistics.NationalPlayerUrl != null) p.NationalPlayerUrl = statistics.NationalPlayerUrl; if (!currentSeason && !flag2) { flag2 = true; List<string> secondaryPositions = new List<string>(); AdditionalPlayerData additionalPlayerData = await DataLoader.LoadAdditionPlayerDataAsync(text2 + "/profil/spieler/" + p.PlayerId); p.PrefferedFoot = additionalPlayerData.PrefferedFoot; p.SecondaryPositions = additionalPlayerData.SecondaryPositions; } var playerData = p.PlayerId + "|" + year + "-" + statistics.GamesPlayed.Replace("-", "0") + "-" + statistics.GoalsScored.Replace("-", "0") + "-" + statistics.Assists.Replace("-", "0") + "-" + statistics.MinutesPlayed.Replace(".", "").Replace("-", "0.000001") + "-" + statistics.MinutesPerGoal.Replace(".", "").Replace("-", "0.000001") + "-" + p.PrefferedFoot; if (statistics != null && !currentSeason && statistics.GamesPlayed != null) { streamWriter.Write(playerData); string text4 = ""; foreach (string current in p.SecondaryPositions) text4 = text4 + "," + current; if (text4 != "") streamWriter.Write("-" + text4.Substring(1)); streamWriter.Write(Environment.NewLine); } p.Statistics.Add(statistics); if (currentSeason && statistics != null) { if(statistics.Matches!=null) p.Matches = statistics.Matches.OrderByDescending(m => m.Date).Take(4).ToList(); currentSeason = false; currentSeasonData.WriteLine(playerData); } } } this._counter++; } } catch (Exception ex) { Logger.Exception(ex); MessageBox.Show(ex.Message); } finally { if (streamWriter != null) streamWriter.Dispose(); if (currentSeasonData != null) currentSeasonData.Dispose(); } }
private void lbTeams_SelectedIndexChanged(object sender, EventArgs e) { if (_generatingInProgress == false && _playerLoadingInProgress == false && _scheduleUpdateInProgress == false && _competitionUpdateInProgress == false) { cbCurrentSeason.SelectedIndex = 0; this._selectedTeam = (Team)this.lbTeams.SelectedItem; if (_selectedTeam != null) { var competition = _cachedCompetitions.Where(cc => cc.CompetitionId == _selectedTeam.CompetitionId).FirstOrDefault(); this._selectedCompetition = competition; LoadArchive(competition); } } }
private void UpdateTeamAlternativeName(Team t) { try { StreamReader sr = new StreamReader(Application.StartupPath + Helper.GetTeamListFileName()); List<string> lines = new List<string>(); while (sr.EndOfStream == false) { string line = sr.ReadLine(); if (line.Contains(t.TeamId + "|" + t.TeamName)) { line += "|" + t.AlternativeName; } lines.Add(line); } sr.Close(); StreamWriter sw = new StreamWriter(Application.StartupPath + Helper.GetTeamListFileName()); foreach (string s in lines) { sw.WriteLine(s); } sw.Close(); } catch (Exception ex) { Logger.Exception(ex); MessageBox.Show(ex.Message); } }
private async Task AzurirajLigu(bool bundleMode) { var existingTeams = (List<Team>)lbTeams.DataSource; _competitionUpdateInProgress = true; AllowControls(false); bool status = await AzurirajArhivu(_selectedTeam.CompetitionId,bundleMode); if (status == true) { lbTeams.DataSource = existingTeams; for (int i = 0; i < lbTeams.Items.Count; i++) { _selectedTeam = existingTeams[i]; lbTeams.SelectedIndex = i; await LoadPlayers(_selectedTeam); if (_competitionUpdateInProgress == false) break; _generatingInProgress = true; await GenerateExcel(_selectedTeam, false); _generatingInProgress = false; if (_competitionUpdateInProgress == false) break; } } _competitionUpdateInProgress = false; AllowControls(true); }
private async void lbTeams_Click(object sender, EventArgs e) { if (_generatingInProgress == false && lbTeams.SelectedItem != null) { AllowControls(false); _selectedTeam = (Team)this.lbTeams.SelectedItem; if (_selectedTeam.Schedule == null) { _scheduleUpdateInProgress = true; List<Match> schedule = await DataLoader.LoadSchedule(_cachedTeams, _selectedTeam, cbCurrentSeason.SelectedItem.ToString()); _selectedTeam.Schedule = schedule; _scheduleUpdateInProgress = false; } await LoadPlayers(_selectedTeam); AllowControls(true); } }
private async Task GenerateExcel(Team team, bool automatic = false) { try { var comp = _cachedCompetitions.Where(cc => cc.CompetitionId == team.CompetitionId).FirstOrDefault(); if (comp == null) { MessageBox.Show("Izabrani tim nije mapiran. Mapiraj tim pa pokuĊĦaj opet!"); return; } var fileName = Application.StartupPath + Helper.GetTeamArchiveFileName(comp, team); if (File.Exists(fileName)) if (Helper.IsFileLocked(new FileInfo(fileName))) { MessageBox.Show("Arhiva '" + fileName + "' je otvorena. Zatvori je pa pokusaj opet."); return; } if (team == null) return; if (team.Players == null) return; if (automatic == false) { foreach (DataGridViewRow r in dgvPlayers.Rows) { Player p = (Player)r.DataBoundItem; team.Players.Where(pp => pp.PlayerId == p.PlayerId).FirstOrDefault().Lineup = p.Lineup; } } if (automatic == false) { if (team.GameLineups != null && team.Players.Where(p => p.Lineup == Player.LineUpStatus.YES).Count() < 11) { DialogResult dr = MessageBox.Show( "Neki od igraca iz najavljenog sastava nisu mapirani. Nastaviti generisanje dokumenta bez njih ?", "Pitanje", MessageBoxButtons.YesNo); if (dr != DialogResult.Yes) return; } } this._counter = 0; this.tbStatus.Visible = true; this._cachedStats = LoadCachedData(team); var pcd = _cachedStats.FirstOrDefault(); if (pcd != null && cbCurrentSeason.SelectedIndex == 0) { int maxYear = int.Parse(pcd.Statistics.Max(s => s.Year)); cbCurrentSeason.SelectedItem = maxYear + 1; } var currentSeasonData = new FileInfo(Application.StartupPath + Helper.GetTeamTempDataFileName(team)); if (currentSeasonData.Exists == true) currentSeasonData.Delete(); foreach (Player p in team.Players) { this.tbStatus.Text = (this._counter + 1).ToString() + " od " + team.Players.Where(pl => pl.Lineup == TMS.Player.LineUpStatus.YES).Count() + " - " + p.Name; if (automatic == false) { foreach (DataGridViewRow dgvr in dgvPlayers.Rows) { CurrentPlayer = p; if (dgvr.DataBoundItem == CurrentPlayer) dgvPlayers.CurrentCell = dgvr.Cells[0]; } } await GetPlayersData(p, team); if (_generatingInProgress == false) return; if (automatic == false) UpdatePlayersGrid(p.PlayerId); } DocumentBuilder.CreateCXMLDocument(fileName, team); Process.Start(fileName); } catch (Exception ex) { Logger.Exception(ex); MessageBox.Show(ex.Message); } }
private List<string> SetLineupStatus(Team team) { List<string> matchedPlayers = new List<string>(); try { List<string> gameLineups; if (team.GameLineups == null) return matchedPlayers; else gameLineups = team.GameLineups.ConvertAll(d => d.ToLower()); foreach (Player p in team.Players) { p.Lineup = Player.LineUpStatus.NO; string name = p.Name; name = Helper.RemoveDiacritics(name.ToLower(), false); if (gameLineups.Contains(name.ToLower())) { if (!matchedPlayers.Contains(name)) matchedPlayers.Add(name); p.Lineup = Player.LineUpStatus.YES; } else { name = p.Name; name = Helper.RemoveDiacritics(name.ToLower(), true); if (gameLineups.Contains(name.ToLower())) { if (!matchedPlayers.Contains(name)) matchedPlayers.Add(name); p.Lineup = Player.LineUpStatus.YES; } else { int matchCount = 0; string[] nameparts = name.Replace('-', ' ').Split(' '); foreach (string lineupPlayer in gameLineups) { matchCount = 0; string[] lpNameParts = lineupPlayer.Replace('-', ' ').Split(' '); foreach (string lpnp in lpNameParts) { foreach (string np in nameparts) { if (np == lpnp) { matchCount++; } } if (matchCount > 1) { if (!matchedPlayers.Contains(lineupPlayer)) matchedPlayers.Add(lineupPlayer); p.Lineup = Player.LineUpStatus.YES; break; } else if (matchCount == 1) { int cc = Helper.CommonCharacters(name, lineupPlayer); decimal pc = (cc * 2m) / (name.Length + lineupPlayer.Length); if ((pc * 100) > COMMON_CHARACTER_MATCH_PERCENTAGE) { if (!matchedPlayers.Contains(lineupPlayer)) matchedPlayers.Add(lineupPlayer); p.Lineup = Player.LineUpStatus.YES; } else p.Lineup = Player.LineUpStatus.UNKNOWN; } } } name = Helper.RemoveDiacritics(name, false); nameparts = name.Replace('-', ' ').Split(' '); foreach (string lineupPlayer in gameLineups) { matchCount = 0; string[] lpNameParts = lineupPlayer.Replace('-', ' ').Split(' '); foreach (string lpnp in lpNameParts) { foreach (string np in nameparts) { if (np == lpnp) { matchCount++; } } if (matchCount > 1) { if (!matchedPlayers.Contains(lineupPlayer)) matchedPlayers.Add(lineupPlayer); p.Lineup = Player.LineUpStatus.YES; } else if (matchCount == 1) { int cc = Helper.CommonCharacters(name, lineupPlayer); decimal pc = (cc * 2m) / (name.Length + lineupPlayer.Length); if ((pc * 100) > COMMON_CHARACTER_MATCH_PERCENTAGE) { if (!matchedPlayers.Contains(lineupPlayer)) matchedPlayers.Add(lineupPlayer); p.Lineup = Player.LineUpStatus.YES; } else p.Lineup = Player.LineUpStatus.UNKNOWN; } } } } } } } catch (Exception ex) { Logger.Exception(ex); MessageBox.Show(ex.Message); } return matchedPlayers; }
private void DetermineLineupStatus(Team t) { try { foreach (var p in t.Players) { var comment = p.Injury; p.Lineup = Player.LineUpStatus.YES; #region position //NO POSITION SET var position = p.MainPosition; if (position == "") p.Lineup = Player.LineUpStatus.UNKNOWN; #endregion positions if (comment != null && position != "GK") { string dateS; DateTime date; bool status; var nextGame = t.Schedule.Where(s => s.Date > DateTime.Now).OrderBy(s => s.Date).FirstOrDefault(); #region suspension if (comment.ToLower().Contains("suspension") || comment.ToLower().Contains("leave") || comment.ToLower().Contains("no eligibility")) { string[] parts = Regex.Split(comment, " - "); var suspensionUntil = parts[1]; var competitionName = parts[2]; if (suspensionUntil != "") { suspensionUntil = comment.Substring(comment.ToLower().IndexOf(" until ") + 7); dateS = suspensionUntil.Substring(0, suspensionUntil.IndexOf(" - ")).Trim(); status = DateTime.TryParseExact(dateS, "MMM d, yyyy", null, DateTimeStyles.None, out date); if (status == true) { if (nextGame != null) { if (nextGame.Date.HasValue && nextGame.Date < date && (t.CompetitionName == competitionName || competitionName == "cross-competition")) p.Lineup = Player.LineUpStatus.NO; } else { if (t.CompetitionName == competitionName || competitionName == "cross-competition") p.Lineup = Player.LineUpStatus.UNKNOWN; } } else p.Lineup = Player.LineUpStatus.UNKNOWN; } else { if (t.CompetitionName == competitionName || competitionName == "cross-competition") p.Lineup = Player.LineUpStatus.NO; } } #endregion suspension #region injury //INJURY if (comment.ToLower().Contains("return unknown")) { p.Lineup = Player.LineUpStatus.NO; } else if (comment.ToLower().Contains("return")) { if (comment.ToLower().IndexOf(" on ") != -1) { dateS = comment.Substring(comment.ToLower().IndexOf(" on ") + 4); status = DateTime.TryParseExact(dateS, "MMM d, yyyy", null, DateTimeStyles.None, out date); if (status == true) { //var nextGame = t.Schedule.Where(s => s.Date > DateTime.Now).OrderBy(s=>s.Date).FirstOrDefault(); if (nextGame != null) { if (nextGame.Date.HasValue && nextGame.Date < date) p.Lineup = Player.LineUpStatus.NO; } else p.Lineup = Player.LineUpStatus.UNKNOWN; } else p.Lineup = Player.LineUpStatus.UNKNOWN; } else p.Lineup = Player.LineUpStatus.UNKNOWN; } } #endregion injury } } catch (Exception ex) { Logger.Exception(ex); MessageBox.Show(ex.Message); } }
private async Task LoadLineups() { try { if (lbMatches.SelectedRows.Count == 1) { SelectedGame = (Game)lbMatches.SelectedRows[0].DataBoundItem; lbMatches.Enabled = false; lbTeams.DataSource = null; lbTeams.Items.Clear(); pbLoadingTeams.Visible = true; SelectedGameLinups = await DataLoader.LoadLineupsAsync(SelectedGame.LineupUrl); pbLoadingTeams.Visible = false; lbMatches.Enabled = true; List<Team> listBoxSource = new List<Team>(); List<Team> teams = FindTeamsByName(SelectedGame.Home, SelectedGame.CompetitionId); if (teams.Count() == 0) { Team t = new Team(); t.TeamName = SelectedGame.Home; t.CompetitionName = "NEMAPIRANO"; teams.Add(t); } foreach (Team t in teams) { if (SelectedGameLinups != null) t.GameLineups = SelectedGameLinups.HomeLineup; t.Tag = "H"; listBoxSource.Add(t); } teams = FindTeamsByName(SelectedGame.Away, SelectedGame.CompetitionId); if (teams.Count() == 0) { Team t = new Team(); t.TeamName = SelectedGame.Away; t.CompetitionName = "NEMAPIRANO"; teams.Add(t); } foreach (Team t in teams) { if (SelectedGameLinups != null) t.GameLineups = SelectedGameLinups.AwayLineup; t.Tag = "A"; listBoxSource.Add(t); } lbTeams.DataSource = listBoxSource; this.lbTeams.DisplayMember = "TeamFullName"; this.lbTeams.ValueMember = "TeamId"; } } catch (Exception ex) { Logger.Exception(ex); MessageBox.Show(ex.Message); } }
private List<Player> LoadCachedData(Team team) { this._cachedStats = new List<Player>(); try { //LOADING PREVIOUS SEASON DATA if (File.Exists(Application.StartupPath + Helper.GetTeamDataFileName(team))) { StreamReader streamReader = new StreamReader(Application.StartupPath + Helper.GetTeamDataFileName(team)); string a = ""; Player player = new Player(); player.Statistics = new List<Statistics>(); while (!streamReader.EndOfStream) { string input = streamReader.ReadLine(); string[] array = Regex.Split(input, "\\|"); string text = array[0]; if (a != text) { player = new Player(); player.PlayerId = int.Parse(text); player.Statistics = new List<Statistics>(); this._cachedStats.Add(player); } Statistics statistics = new Statistics(); string[] array2 = Regex.Split(array[1], "-"); statistics.Year = array2[0]; statistics.GamesPlayed = array2[1]; statistics.GoalsScored = array2[2]; statistics.Assists = array2[3]; statistics.MinutesPlayed = array2[4]; statistics.MinutesPerGoal = array2[5]; player.Statistics.Add(statistics); if (array2.Length > 6) { player.PrefferedFoot = array2[6]; } player.SecondaryPositions = new List<string>(); if (array2.Length > 7) { string input2 = array2[7]; string[] array3 = Regex.Split(input2, ","); string[] array4 = array3; for (int i = 0; i < array4.Length; i++) { string item = array4[i]; player.SecondaryPositions.Add(item); } } a = text; } streamReader.Close(); } //LOADING CURRENT SEASON DATA if (File.Exists(Application.StartupPath + Helper.GetTeamTempDataFileName(team))) { StreamReader streamReader = new StreamReader(Application.StartupPath + Helper.GetTeamTempDataFileName(team)); while (!streamReader.EndOfStream) { string input = streamReader.ReadLine(); string[] array = Regex.Split(input, "\\|"); string text = array[0]; int playerId = int.Parse(text); Statistics statistics = new Statistics(); string[] array2 = Regex.Split(array[1], "-"); statistics.Year = array2[0]; statistics.GamesPlayed = array2[1]; statistics.GoalsScored = array2[2]; statistics.Assists = array2[3]; statistics.MinutesPlayed = array2[4]; statistics.MinutesPerGoal = array2[5]; var existing = _cachedStats.Where(cs => cs.PlayerId == playerId).FirstOrDefault(); if (existing != null) existing.CurrentSeasonStatistics = statistics; else { Player player = new Player(); player.PlayerId = int.Parse(text); player.CurrentSeasonStatistics = statistics; _cachedStats.Add(player); } } streamReader.Close(); } } catch (Exception ex) { Logger.Exception(ex); MessageBox.Show(ex.Message); } return this._cachedStats; }