diff --git a/TrackerLibrary/Enums.cs b/TrackerLibrary/Enums.cs new file mode 100644 index 0000000..9f91181 --- /dev/null +++ b/TrackerLibrary/Enums.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace TrackerLibrary +{ + public enum DatabaseType + { + Sql, + TextFile + } +} diff --git a/TrackerLibrary/GlobalConfig.cs b/TrackerLibrary/GlobalConfig.cs index fc874a2..9abd4fe 100644 --- a/TrackerLibrary/GlobalConfig.cs +++ b/TrackerLibrary/GlobalConfig.cs @@ -8,23 +8,27 @@ namespace TrackerLibrary { public static class GlobalConfig { - public static List Connections { get; private set; } = new List(); - public static void InitializeConnections(bool database, bool textFiles) + public static IDataConnection Connection { get; private set; } + public static void InitializeConnections(DatabaseType db) { - if (database) + + switch (db) { - // TODO - Set up the sql connector properly ! - SqlConnector sql = new SqlConnector(); - Connections.Add(sql); - } - - if (textFiles) - { - // TODO - Create the text Connection - TextConnector text = new TextConnector(); - Connections.Add(text); + case DatabaseType.Sql: + // TODO - Set up the sql connector properly ! + SqlConnector sql = new SqlConnector(); + Connection = sql; + break; + case DatabaseType.TextFile: + // TODO - Create the text Connection + TextConnector text = new TextConnector(); + Connection = text; + break; + default: + break; } + } public static string CnnString(string name) diff --git a/TrackerLibrary/TrackerLibrary.csproj b/TrackerLibrary/TrackerLibrary.csproj index fe0dfd3..7027b92 100644 --- a/TrackerLibrary/TrackerLibrary.csproj +++ b/TrackerLibrary/TrackerLibrary.csproj @@ -48,6 +48,7 @@ + diff --git a/TrackerUI/CreatePrizeForm.cs b/TrackerUI/CreatePrizeForm.cs index e5b7312..1df5eb5 100644 --- a/TrackerUI/CreatePrizeForm.cs +++ b/TrackerUI/CreatePrizeForm.cs @@ -29,10 +29,7 @@ namespace TrackerUI prizeAmountValue.Text, prizePercentageValue.Text); - foreach (var db in GlobalConfig.Connections) - { - db.CreatePrize(model); - } + GlobalConfig.Connection.CreatePrize(model); placeNameValue.Text = ""; placeNumberValue.Text = ""; diff --git a/TrackerUI/Program.cs b/TrackerUI/Program.cs index 5e517fa..4668d4c 100644 --- a/TrackerUI/Program.cs +++ b/TrackerUI/Program.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; using System.Windows.Forms; +using TrackerLibrary; namespace TrackerUI { @@ -18,7 +19,7 @@ namespace TrackerUI Application.SetCompatibleTextRenderingDefault(false); // Initialize the database connections - TrackerLibrary.GlobalConfig.InitializeConnections(true, true); + GlobalConfig.InitializeConnections(DatabaseType.Sql); Application.Run(new CreatePrizeForm()); //Application.Run(new TournamentDashboardForm());