From 8d54da0f80b27dfc94d813bd37b2bf922cffe24e Mon Sep 17 00:00:00 2001 From: Alejoho <142363177+Alejoho@users.noreply.github.com> Date: Sun, 30 Nov 2025 11:31:52 -0500 Subject: [PATCH] Refresh The Tournamet List Now the tournament list refreshes every time a tournament is created or completed --- TournamentsDB/TournamentsDB.sqlproj | 1 + TrackerLibrary/DataAccess/SqlConnector.cs | 2 +- TrackerLibrary/DataAccess/TextConnector.cs | 3 --- TrackerLibrary/EmailLogic.cs | 1 - TrackerLibrary/GlobalConfig.cs | 2 -- TrackerLibrary/Models/TournamentModel.cs | 4 ++-- TrackerUI/App.config | 2 +- TrackerUI/CreateTournamentForm.cs | 7 +++++-- TrackerUI/TournamentDashboardForm.cs | 12 ++++++++++++ TrackerUI/TournamentViewerForm.cs | 2 +- 10 files changed, 23 insertions(+), 13 deletions(-) diff --git a/TournamentsDB/TournamentsDB.sqlproj b/TournamentsDB/TournamentsDB.sqlproj index f40b88c..37286cc 100644 --- a/TournamentsDB/TournamentsDB.sqlproj +++ b/TournamentsDB/TournamentsDB.sqlproj @@ -94,5 +94,6 @@ + \ No newline at end of file diff --git a/TrackerLibrary/DataAccess/SqlConnector.cs b/TrackerLibrary/DataAccess/SqlConnector.cs index 4aaeae7..2b9b033 100644 --- a/TrackerLibrary/DataAccess/SqlConnector.cs +++ b/TrackerLibrary/DataAccess/SqlConnector.cs @@ -10,7 +10,7 @@ namespace TrackerLibrary.DataAccess public class SqlConnector : IDataConnection { private const string db = "Tournaments"; - //TODO - Make the CreatePrize method actually save to the database + /// /// Gives and ID to the new prize and save it to the database. /// diff --git a/TrackerLibrary/DataAccess/TextConnector.cs b/TrackerLibrary/DataAccess/TextConnector.cs index 7faf166..b2eeeb5 100644 --- a/TrackerLibrary/DataAccess/TextConnector.cs +++ b/TrackerLibrary/DataAccess/TextConnector.cs @@ -23,9 +23,6 @@ public void CreatePrize(PrizeModel model) if (prizes.Count > 0) currentId = prizes.OrderByDescending(x => x.Id).First().Id + 1; - //TODO - This is an alternative to the code of the line 34 through 37 - //int currentId = prizes.OrderByDescending(x => x.ID).Select(x => x.ID).FirstOrDefault() + 1; - model.Id = currentId; //Add the new record with the new ID (max + 1) diff --git a/TrackerLibrary/EmailLogic.cs b/TrackerLibrary/EmailLogic.cs index d19b2d2..a958a31 100644 --- a/TrackerLibrary/EmailLogic.cs +++ b/TrackerLibrary/EmailLogic.cs @@ -27,7 +27,6 @@ public static void SendEmail(List to, List bcc, string subject, { mail.Bcc.Add(email); } - // TODO: Continue here 39:42 mail.From = fromMailAddress; mail.Subject = subject; diff --git a/TrackerLibrary/GlobalConfig.cs b/TrackerLibrary/GlobalConfig.cs index 896efb9..44f0015 100644 --- a/TrackerLibrary/GlobalConfig.cs +++ b/TrackerLibrary/GlobalConfig.cs @@ -44,14 +44,12 @@ public static void InitializeConnections(DatabaseType db) { if (db == DatabaseType.Sql) { - //TODO - Set up the SQL Connector properly SqlConnector sql = new SqlConnector(); Connection = sql; } if (db == DatabaseType.TextFile) { - //TODO - Create the Text Connection TextConnector text = new TextConnector(); Connection = text; } diff --git a/TrackerLibrary/Models/TournamentModel.cs b/TrackerLibrary/Models/TournamentModel.cs index 0d195b8..a5c6cf9 100644 --- a/TrackerLibrary/Models/TournamentModel.cs +++ b/TrackerLibrary/Models/TournamentModel.cs @@ -8,7 +8,7 @@ namespace TrackerLibrary.Models /// public class TournamentModel { - public event EventHandler OnTournamentComplete; + public event EventHandler OnTournamentComplete; /// /// The unique identifier for the tournament. /// @@ -36,7 +36,7 @@ public class TournamentModel public void CompleteTournament() { - OnTournamentComplete?.Invoke(this, DateTime.Now); + OnTournamentComplete?.Invoke(this, EventArgs.Empty); } } } diff --git a/TrackerUI/App.config b/TrackerUI/App.config index 2ee1275..4ca0abc 100644 --- a/TrackerUI/App.config +++ b/TrackerUI/App.config @@ -8,7 +8,7 @@ diff --git a/TrackerUI/CreateTournamentForm.cs b/TrackerUI/CreateTournamentForm.cs index ed4ea79..85764b4 100644 --- a/TrackerUI/CreateTournamentForm.cs +++ b/TrackerUI/CreateTournamentForm.cs @@ -1,4 +1,5 @@ -using System.Collections.Generic; +using System; +using System.Collections.Generic; using System.Windows.Forms; using TrackerLibrary; using TrackerLibrary.Models; @@ -10,6 +11,7 @@ public partial class CreateTournamentForm : Form, IPrizeRequester, ITeamRequeste List availableTeams = GlobalConfig.Connection.GetTeam_All(); List selectedTeams = new List(); List selectedPrizes = new List(); + public event EventHandler OnTournamentCreated; public CreateTournamentForm() { @@ -122,7 +124,6 @@ private void createTournamentButton_Click(object sender, System.EventArgs e) tm.Prizes = selectedPrizes; tm.EnteredTeams = selectedTeams; - //TODO - Wire up our matchups TournamentLogic.CreateRounds(tm); //Create Tournament entry @@ -132,6 +133,8 @@ private void createTournamentButton_Click(object sender, System.EventArgs e) tm.AlertUsersToNewRound(); + OnTournamentCreated?.Invoke(this, EventArgs.Empty); + TournamentViewerForm frm = new TournamentViewerForm(tm); frm.Show(); this.Close(); diff --git a/TrackerUI/TournamentDashboardForm.cs b/TrackerUI/TournamentDashboardForm.cs index e6c036c..2c4a4f0 100644 --- a/TrackerUI/TournamentDashboardForm.cs +++ b/TrackerUI/TournamentDashboardForm.cs @@ -22,16 +22,28 @@ public void WireUpLists() loadExistingTournamentDropDown.DisplayMember = "TournamentName"; } + public void RefreshLists(object sender, EventArgs e) + { + tournaments = GlobalConfig.Connection.GetTournament_All(); + + loadExistingTournamentDropDown.DataSource = null; + loadExistingTournamentDropDown.DataSource = tournaments; + loadExistingTournamentDropDown.DisplayMember = "TournamentName"; + } + private void createTournamentButton_Click(object sender, EventArgs e) { CreateTournamentForm frm = new CreateTournamentForm(); + frm.OnTournamentCreated += RefreshLists; frm.Show(); } private void loadTournamentButton_Click(object sender, EventArgs e) { TournamentModel tm = (TournamentModel)loadExistingTournamentDropDown.SelectedItem; + tm.OnTournamentComplete += RefreshLists; TournamentViewerForm frm = new TournamentViewerForm(tm); + // create a subcriber method for the event im going to create in tournamentviewerform frm.Show(); } } diff --git a/TrackerUI/TournamentViewerForm.cs b/TrackerUI/TournamentViewerForm.cs index 67f91ad..dc8fb11 100644 --- a/TrackerUI/TournamentViewerForm.cs +++ b/TrackerUI/TournamentViewerForm.cs @@ -29,7 +29,7 @@ public TournamentViewerForm(TournamentModel tournamentModel) LoadRounds(); } - private void Tournament_OnTournamentComplete(object sender, DateTime e) + private void Tournament_OnTournamentComplete(object sender, EventArgs e) { this.Close(); }