public static void SaveEntryToFile(this MatchupEntryModel entry, string matchupEntryFile) { List <MatchupEntryModel> entries = GlobalConfig.MatchupEntryFile.FullFilePath().LoadFile().ConvertToMatchupEnrtyModels(); int currentId = 1; if (entries.Count > 0) { currentId = entries.OrderByDescending(x => x.Id).First().Id + 1; } entry.Id = currentId; entries.Add(entry); List <string> lines = new List <string>(); foreach (MatchupEntryModel e in entries) { string parent = ""; if (e.ParentMatchup != null) { parent = e.ParentMatchup.Id.ToString(); } string teamCompeting = ""; if (e.TeamCompeting != null) { teamCompeting = e.TeamCompeting.Id.ToString(); } lines.Add($"{ e.Id },{ teamCompeting },{ e.Score },{ parent }"); } //File.WriteAllLines(matchupEntryFile.FullFilePath(), lines); File.WriteAllLines(GlobalConfig.MatchupEntryFile.FullFilePath(), lines); }
public static void UpdateEntryToFile(this MatchupEntryModel entry) { List <MatchupEntryModel> entries = GlobalConfig.MatchupEntryFile.FullFilePath().LoadFile().ConvertToMatchupEntryModels(); MatchupEntryModel oldEntry = new MatchupEntryModel(); foreach (MatchupEntryModel e in entries) { if (e.Id == entry.Id) { oldEntry = e; } } entries.Remove(oldEntry); entries.Add(entry); List <string> lines = new List <string>(); foreach (MatchupEntryModel e in entries) { string parent = ""; if (e.ParentMatchup != null) { parent = e.ParentMatchup.Id.ToString(); } string teamCompeting = ""; if (e.TeamCompeting != null) { teamCompeting = e.TeamCompeting.Id.ToString(); } lines.Add($"{ e.Id },{ teamCompeting },{ e.Score },{ parent }"); } File.WriteAllLines(GlobalConfig.MatchupEntryFile.FullFilePath(), lines); //save to file }
public static List <MatchupEntryModel> ConvertToMatchupEntryModels(this List <string> lines) { List <MatchupEntryModel> output = new List <MatchupEntryModel>(); foreach (string line in lines) { string[] cols = line.Split(','); MatchupEntryModel me = new MatchupEntryModel(); me.Id = int.Parse(cols[0]); if (cols[1].Length == 0) { me.TeamCompeting = null; } else { me.TeamCompeting = LookupTeamById(int.Parse(cols[1])); } me.Score = double.Parse(cols[2]); int parentId = 0; if (int.TryParse(cols[3], out parentId)) { me.ParentMatchup = LookupMatchupById(parentId); } else { me.ParentMatchup = null; } output.Add(me); } return(output); }
public static void SaveEntryToFile(this MatchupEntryModel entry) { List <MatchupEntryModel> entries = GlobalConfig.MatchupEntryFile.FullFilePath().LoadFile().ConvertToMatchupEntryModels(); int currentId = 1; if (entries.Count > 0) { currentId = entries.OrderByDescending(x => x.Id).First().Id + 1; } entry.Id = currentId; entries.Add(entry); // Save to file List <string> lines = new List <string>(); foreach (MatchupEntryModel matchupE in entries) { string parent = string.Empty; if (matchupE.ParentMatchup != null) // Check if matchuEntry has parent matchup { parent = matchupE.ParentMatchup.Id.ToString(); } string teamCompeting = string.Empty; if (matchupE.TeamCompeting != null) { teamCompeting = matchupE.TeamCompeting.Id.ToString(); } lines.Add($"{matchupE.Id},{teamCompeting},{matchupE.Score},{parent}"); } File.WriteAllLines(GlobalConfig.MatchupEntryFile.FullFilePath(), lines); }
public static List <MatchupEntryModel> ConvertToMatchupEntries(this List <string> lines) { List <MatchupEntryModel> output = new List <MatchupEntryModel>(); foreach (string line in lines) { MatchupEntryModel matchup = new MatchupEntryModel(); string[] cols = line.Split('|'); matchup.Id = int.Parse(cols[0]); if (cols[1].Length > 0) { matchup.TeamCompeting = LookUpTeamById(int.Parse(cols[1])); } else { matchup.TeamCompeting = null; } matchup.Score = double.Parse(cols[2]); if (cols[3].Length > 0) { matchup.ParentMatchup = ConvertStringToMatchupModels(cols[3]).First(); } else { matchup.ParentMatchup = null; } output.Add(matchup); } return(output); }
public static void SaveEntryToFile(this MatchupEntryModel model) { List <MatchupEntryModel> entries = GlobalConfig.MatchUpEntryFile.FullFileName().LoadFile().ConvertToMatchUpEntryModels(); int currentId = entries.Count > 0 ? entries.OrderByDescending(x => x.Id).First().Id + 1 : 1; model.Id = currentId; entries.Add(model); // save to file List <string> lines = new List <string>(); foreach (var entry in entries) { string parent = entry.ParentMatchUp != null?entry.ParentMatchUp.Id.ToString() : ""; string competing = entry.TeamCompeting != null?entry.TeamCompeting.Id.ToString() : ""; lines.Add($"{entry.Id},{competing},{entry.Score},{parent}"); } File.WriteAllLines(GlobalConfig.MatchUpEntryFile.FullFileName(), lines); }
public void UpdateMatchupEntry(MatchupEntryModel model) { model.UpdateMatchupEntryToFile(); }
public static void SaveEntryToFile(this MatchupEntryModel entry, string matchupEntryFile) { }
private void matchupNameComboBox_SelectedIndexChanged(object sender, EventArgs e) { if (matchupNameComboBox.SelectedItem != null) { selectedMatchup = selectableMatchups[(int)matchupNameComboBox.SelectedItem - 1]; selectableMatchupEntries = selectedMatchup.Entries; int j = 1; bye = false; foreach (MatchupEntryModel matchupEntry in selectableMatchupEntries) { if (j == 1) { if (matchupEntry.TeamCompeting == null && selectedRound == 1) { team1NameLabel.Text = "-"; team1ScoreTextBox.Text = "-"; team2ScoreTextBox.Text = "-"; bye = true; } else if (matchupEntry.TeamCompeting == null && selectedRound > 1) { team1NameLabel.Text = "TBA"; } else { team1NameLabel.Text = matchupEntry.TeamCompeting.TeamName; team1ScoreTextBox.Text = matchupEntry.Score.ToString(); } } else { if (matchupEntry.TeamCompeting == null && selectedRound == 1) { team2NameLabel.Text = "-"; team2ScoreTextBox.Text = "-"; team1ScoreTextBox.Text = "-"; bye = true; } else if (matchupEntry.TeamCompeting == null && selectedRound > 1) { team2NameLabel.Text = "TBA"; } else { team2NameLabel.Text = matchupEntry.TeamCompeting.TeamName; team2ScoreTextBox.Text = matchupEntry.Score.ToString(); } } j += 1; } // If displaying a bye Matchup, determine the winner and update DB if (selectedMatchup.Winner == null && selectedRound < selectedTournament.Rounds.Count() && bye) { winningMatchupEntry = TournamentLogic.DetermineWinner(selectableMatchupEntries[0], selectableMatchupEntries[1]); winningTeamNameLabel.Text = winningMatchupEntry.TeamCompeting.TeamName; selectedMatchup.Winner = winningMatchupEntry.TeamCompeting; selectedMatchup.WinnerId = winningMatchupEntry.TeamCompeting.Id; GlobalConfig.Connection.UpdateMatchup(selectedMatchup); // Add winning TeamModel to next round's Matchupup corresponding to the winning team's MatchupId foreach (MatchupModel matchupModel in selectedTournament.Rounds[selectedRound]) { foreach (MatchupEntryModel matchupEntryModel in matchupModel.Entries) { if (matchupEntryModel.ParentMatchupId == selectedMatchup.Id) { matchupEntryModel.TeamCompeting = winningMatchupEntry.TeamCompeting; matchupEntryModel.TeamCompetingId = winningMatchupEntry.TeamCompeting.Id; GlobalConfig.Connection.UpdateMatchupEntry(matchupEntryModel); } } } ConnectFormToList(); roundNumberComboBox.SelectedIndex = 0; } else if (selectedMatchup.Winner == null && !bye) { winningTeamNameLabel.Text = "TBD"; } else { winningTeamNameLabel.Text = selectedMatchup.Winner.TeamName; } } else { team1NameLabel.Text = "-"; team1ScoreTextBox.Text = "-"; team2NameLabel.Text = "-"; team2ScoreTextBox.Text = "-"; winningTeamNameLabel.Text = "-"; } }
public MatchupEntryModel CreateMatchupEntry(MatchupEntryModel model) { throw new NotImplementedException(); }