Some refactorings

This commit is contained in:
2020-03-23 00:55:54 +01:00
parent bf67841d48
commit 70c6a28e54
5 changed files with 35 additions and 18 deletions

14
TrackerLibrary/Enums.cs Normal file
View File

@ -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
}
}

View File

@ -8,22 +8,26 @@ namespace TrackerLibrary
{ {
public static class GlobalConfig public static class GlobalConfig
{ {
public static List<IDataConnection> Connections { get; private set; } = new List<IDataConnection>(); public static IDataConnection Connection { get; private set; }
public static void InitializeConnections(bool database, bool textFiles) public static void InitializeConnections(DatabaseType db)
{ {
if (database)
switch (db)
{ {
// TODO - Set up the sql connector properly ! case DatabaseType.Sql:
SqlConnector sql = new SqlConnector(); // TODO - Set up the sql connector properly !
Connections.Add(sql); SqlConnector sql = new SqlConnector();
Connection = sql;
break;
case DatabaseType.TextFile:
// TODO - Create the text Connection
TextConnector text = new TextConnector();
Connection = text;
break;
default:
break;
} }
if (textFiles)
{
// TODO - Create the text Connection
TextConnector text = new TextConnector();
Connections.Add(text);
}
} }

View File

@ -48,6 +48,7 @@
<Compile Include="DataAccess\IDataConnection.cs" /> <Compile Include="DataAccess\IDataConnection.cs" />
<Compile Include="DataAccess\SqlConnector.cs" /> <Compile Include="DataAccess\SqlConnector.cs" />
<Compile Include="DataAccess\TextConnector.cs" /> <Compile Include="DataAccess\TextConnector.cs" />
<Compile Include="Enums.cs" />
<Compile Include="GlobalConfig.cs" /> <Compile Include="GlobalConfig.cs" />
<Compile Include="Models\MatchupEntryModel.cs" /> <Compile Include="Models\MatchupEntryModel.cs" />
<Compile Include="Models\MatchupModel.cs" /> <Compile Include="Models\MatchupModel.cs" />

View File

@ -29,10 +29,7 @@ namespace TrackerUI
prizeAmountValue.Text, prizeAmountValue.Text,
prizePercentageValue.Text); prizePercentageValue.Text);
foreach (var db in GlobalConfig.Connections) GlobalConfig.Connection.CreatePrize(model);
{
db.CreatePrize(model);
}
placeNameValue.Text = ""; placeNameValue.Text = "";
placeNumberValue.Text = ""; placeNumberValue.Text = "";

View File

@ -3,6 +3,7 @@ using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Threading.Tasks; using System.Threading.Tasks;
using System.Windows.Forms; using System.Windows.Forms;
using TrackerLibrary;
namespace TrackerUI namespace TrackerUI
{ {
@ -18,7 +19,7 @@ namespace TrackerUI
Application.SetCompatibleTextRenderingDefault(false); Application.SetCompatibleTextRenderingDefault(false);
// Initialize the database connections // Initialize the database connections
TrackerLibrary.GlobalConfig.InitializeConnections(true, true); GlobalConfig.InitializeConnections(DatabaseType.Sql);
Application.Run(new CreatePrizeForm()); Application.Run(new CreatePrizeForm());
//Application.Run(new TournamentDashboardForm()); //Application.Run(new TournamentDashboardForm());