diff --git a/TrackerUI/TournamentViewerForm.Designer.cs b/TrackerUI/TournamentViewerForm.Designer.cs index 2233b54..141a935 100644 --- a/TrackerUI/TournamentViewerForm.Designer.cs +++ b/TrackerUI/TournamentViewerForm.Designer.cs @@ -109,6 +109,7 @@ this.MatchUpListBox.Name = "MatchUpListBox"; this.MatchUpListBox.Size = new System.Drawing.Size(338, 272); this.MatchUpListBox.TabIndex = 5; + this.MatchUpListBox.SelectedIndexChanged += new System.EventHandler(this.MatchUpListBox_SelectedIndexChanged); // // teamOneName // diff --git a/TrackerUI/TournamentViewerForm.cs b/TrackerUI/TournamentViewerForm.cs index 7ac2a65..cede55a 100644 --- a/TrackerUI/TournamentViewerForm.cs +++ b/TrackerUI/TournamentViewerForm.cs @@ -14,12 +14,16 @@ namespace TrackerUI public partial class TournamentViewerForm : Form { private readonly TournamentModel tournament; - List rounds = new List(); - List selectedMatchups = new List(); + BindingList rounds = new BindingList(); + BindingList selectedMatchups = new BindingList(); + bool loading = false; + + public TournamentViewerForm(TournamentModel tournamentModel) { InitializeComponent(); tournament = tournamentModel; + WireUpLists(); LoadFormData(); LoadRounds(); } @@ -29,21 +33,16 @@ namespace TrackerUI tournamentName.Text = tournament.TournamentName; } - private void WireUpRoundsLists() + private void WireUpLists() { - roundDropDown.DataSource = null; roundDropDown.DataSource = rounds; - - } - private void WireUpMatchupsLists() - { - MatchUpListBox.DataSource = null; MatchUpListBox.DataSource = selectedMatchups; MatchUpListBox.DisplayMember = "DisplayName"; } + private void LoadRounds() { - rounds = new List(); + rounds.Clear(); rounds.Add(1); int currRound = 1; @@ -55,26 +54,77 @@ namespace TrackerUI rounds.Add(currRound); } } - WireUpRoundsLists(); + LoadMatchups(1); } private void roundDropDown_SelectedIndexChanged(object sender, EventArgs e) { - LoadMatchups(); + LoadMatchups( (int)roundDropDown.SelectedItem); } - private void LoadMatchups() + private void LoadMatchups(int round) { - int round = (int)roundDropDown.SelectedItem; foreach (List matchups in tournament.Rounds) { if (matchups.First().MatchupRound == round) { - selectedMatchups = matchups; + loading = true; + selectedMatchups.Clear(); + foreach (MatchupModel mm in matchups) + { + selectedMatchups.Add(mm); + } + loading = false; } } - WireUpMatchupsLists(); + + LoadMatchup(selectedMatchups.First()); + } + + private void LoadMatchup(MatchupModel m) + { + if (!loading) + { + for (int i = 0; i < m.Entries.Count; i++) + { + if (i == 0) + { + if (m.Entries[0].TeamCompeting != null) + { + teamOneName.Text = m.Entries[0].TeamCompeting.TeamName; + teamOneScoeValue.Text = m.Entries[0].Score.ToString(); + + teamTwoName.Text = ""; + teamTwoScoeValue.Text = "0"; + } + else + { + teamOneName.Text = "Not Yet Set"; + teamOneScoeValue.Text = ""; + } + } + + if (i == 1) + { + if (m.Entries[1].TeamCompeting != null) + { + teamTwoName.Text = m.Entries[1].TeamCompeting.TeamName; + teamTwoScoeValue.Text = m.Entries[1].Score.ToString(); + } + else + { + teamTwoName.Text = "Not Yet Set"; + teamTwoScoeValue.Text = ""; + } + } + } + } + } + + private void MatchUpListBox_SelectedIndexChanged(object sender, EventArgs e) + { + LoadMatchup((MatchupModel)MatchUpListBox.SelectedItem); } } }