From cfe97d223573c4792e5d42a4443c139fd8c87381 Mon Sep 17 00:00:00 2001 From: emkael Date: Sun, 30 Jul 2017 01:44:48 +0200 Subject: Refactoring MySQL tournament names: generalization --- Aktywator/Aktywator.csproj | 3 ++ Aktywator/Bws.cs | 4 +-- Aktywator/ChooseTournament.cs | 10 ++++++- Aktywator/MainForm.cs | 7 +++-- Aktywator/MySQLTournament.cs | 65 +++++++++++++++---------------------------- Aktywator/ParyTournament.cs | 30 ++++++++++++++++++++ Aktywator/TeamyTournament.cs | 30 ++++++++++++++++++++ Aktywator/Tournament.cs | 36 ++++++++++++++++++++++++ 8 files changed, 136 insertions(+), 49 deletions(-) create mode 100644 Aktywator/ParyTournament.cs create mode 100644 Aktywator/TeamyTournament.cs create mode 100644 Aktywator/Tournament.cs (limited to 'Aktywator') diff --git a/Aktywator/Aktywator.csproj b/Aktywator/Aktywator.csproj index 97fa090..e1b78f1 100644 --- a/Aktywator/Aktywator.csproj +++ b/Aktywator/Aktywator.csproj @@ -99,6 +99,7 @@ MysqlSettings.cs + @@ -108,6 +109,8 @@ + + ChooseTournament.cs diff --git a/Aktywator/Bws.cs b/Aktywator/Bws.cs index 24e707c..41717b2 100644 --- a/Aktywator/Bws.cs +++ b/Aktywator/Bws.cs @@ -344,7 +344,7 @@ namespace Aktywator else return 0; } - public void syncNames(MySQLTournament tournament, bool interactive, string startRounds) + public void syncNames(Tournament tournament, bool interactive, string startRounds) { int count = 0, countNew = 0, SKOK_STOLOW = 100; data d; @@ -394,7 +394,7 @@ namespace Aktywator query.Append(ew); query.Append(" UNION ALL SELECT ' '; "); } - mydata n = tournament.mysql.select(query.ToString()); + mydata n = ((MySQLTournament)tournament).mysql.select(query.ToString()); DialogResult dr = DialogResult.None; diff --git a/Aktywator/ChooseTournament.cs b/Aktywator/ChooseTournament.cs index 155624b..734b191 100644 --- a/Aktywator/ChooseTournament.cs +++ b/Aktywator/ChooseTournament.cs @@ -34,7 +34,15 @@ namespace Aktywator { if (listBox.SelectedIndex >= 0) { - chosenTournament = turns[listBox.SelectedIndex]; + switch (turns[listBox.SelectedIndex].type) + { + case Tournament.TYPE_PARY: + chosenTournament = new ParyTournament(turns[listBox.SelectedIndex].name); + break; + case Tournament.TYPE_TEAMY: + chosenTournament = new TeamyTournament(turns[listBox.SelectedIndex].name); + break; + } Close(); } } diff --git a/Aktywator/MainForm.cs b/Aktywator/MainForm.cs index 96d965b..e2e87db 100644 --- a/Aktywator/MainForm.cs +++ b/Aktywator/MainForm.cs @@ -15,7 +15,7 @@ namespace Aktywator public string date = "28.06.2017"; private Bws bws; - private MySQLTournament tournament; + private Tournament tournament; public MainForm() { @@ -181,7 +181,7 @@ namespace Aktywator } } - private void updateTournamentInfo(MySQLTournament tournament) + private void updateTournamentInfo(Tournament tournament) { if (tournament != null) { @@ -194,7 +194,7 @@ namespace Aktywator bSync.Enabled = true; bAutoSync.Enabled = true; eInterval.Enabled = true; - if (tournament.type == MySQLTournament.TYPE_TEAMY) + if (tournament.GetType().Equals(typeof(TeamyTournament))) { lSkok.Visible = true; lNazwyTeamow.Visible = true; @@ -209,6 +209,7 @@ namespace Aktywator { lSkok.Visible = false; lNazwyTeamow.Visible = false; + } } diff --git a/Aktywator/MySQLTournament.cs b/Aktywator/MySQLTournament.cs index 54f3f7b..ff3258a 100644 --- a/Aktywator/MySQLTournament.cs +++ b/Aktywator/MySQLTournament.cs @@ -6,24 +6,8 @@ using data = MySql.Data.MySqlClient.MySqlDataReader; namespace Aktywator { - public class MySQLTournament + public class MySQLTournament : Tournament { - public const int TYPE_PARY = 1; - public const int TYPE_TEAMY = 2; - public const int TYPE_UNKNOWN = 0; - - private string _name; - public string name - { - get { return _name; } - } - - private int _type; // 0-unknown, 1-Pary, 2-Teamy - public int type - { - get { return _type; } - } - public MySQL mysql; public MySQLTournament(string name) @@ -38,17 +22,17 @@ namespace Aktywator if ((mysql.selectOne("SHOW TABLES LIKE 'admin'") == "admin") && (mysql.selectOne("SHOW FIELDS IN admin LIKE 'dnazwa'") == "dnazwa") && (mysql.selectOne("SHOW TABLES LIKE 'zawodnicy'") == "zawodnicy")) - _type = MySQLTournament.TYPE_PARY; + _type = Tournament.TYPE_PARY; else if ((mysql.selectOne("SHOW TABLES LIKE 'admin'") == "admin") && (mysql.selectOne("SHOW FIELDS IN admin LIKE 'teamcnt'") == "teamcnt") && (mysql.selectOne("SHOW TABLES LIKE 'players'") == "players")) - _type = MySQLTournament.TYPE_TEAMY; - else _type = MySQLTournament.TYPE_UNKNOWN; + _type = Tournament.TYPE_TEAMY; + else _type = Tournament.TYPE_UNKNOWN; } public override string ToString() { - return this.name + " [" + (this.type == MySQLTournament.TYPE_PARY ? 'P' : 'T') + "]"; + return this.name + " [" + (this.type == Tournament.TYPE_PARY ? 'P' : 'T') + "]"; } public static List getTournaments() @@ -59,31 +43,14 @@ namespace Aktywator while (dbs.Read()) { MySQLTournament t = new MySQLTournament(dbs.GetString(0)); - if (t.type > MySQLTournament.TYPE_UNKNOWN) + if (t.type > Tournament.TYPE_UNKNOWN) list.Add(t); t.mysql.close(); } return list; } - public string getSectionsNum() - { - if (type == MySQLTournament.TYPE_PARY) - return mysql.selectOne("SELECT COUNT(DISTINCT seknum) FROM sektory;"); - else - return "1"; - } - - public string getTablesNum() - { - if (type == MySQLTournament.TYPE_PARY) - return mysql.selectOne("SELECT COUNT(*) FROM sektory;"); - else - return mysql.selectOne("SELECT teamcnt FROM admin;"); - } - - - internal void setup() + override internal void setup() { if (this.mysql != null) { @@ -92,14 +59,26 @@ namespace Aktywator } } - internal string getName() + override internal string getName() { return this.name; } - internal string getTypeLabel() + override public string getSectionsNum() + { + throw new NotImplementedException("Don't call this method on generic class instance"); + } + + override public string getTablesNum() { - return this._type == MySQLTournament.TYPE_PARY ? "Pary" : "Teamy"; + throw new NotImplementedException("Don't call this method on generic class instance"); } + + override internal string getTypeLabel() + { + throw new NotImplementedException("Don't call this method on generic class instance"); + } + } } + diff --git a/Aktywator/ParyTournament.cs b/Aktywator/ParyTournament.cs new file mode 100644 index 0000000..8d80d9f --- /dev/null +++ b/Aktywator/ParyTournament.cs @@ -0,0 +1,30 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace Aktywator +{ + class ParyTournament: MySQLTournament + { + public ParyTournament(string name) + : base(name) + { + } + + override internal string getTypeLabel() + { + return "Pary"; + } + + override public string getSectionsNum() + { + return this.mysql.selectOne("SELECT COUNT(DISTINCT seknum) FROM sektory;"); + } + + override public string getTablesNum() + { + return this.mysql.selectOne("SELECT COUNT(*) FROM sektory;"); + } + + } +} diff --git a/Aktywator/TeamyTournament.cs b/Aktywator/TeamyTournament.cs new file mode 100644 index 0000000..34908be --- /dev/null +++ b/Aktywator/TeamyTournament.cs @@ -0,0 +1,30 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace Aktywator +{ + class TeamyTournament : MySQLTournament + { + public TeamyTournament(string name) + : base(name) + { + } + + override internal string getTypeLabel() + { + return "Teamy"; + } + + override public string getSectionsNum() + { + return "1"; + } + + override public string getTablesNum() + { + return this.mysql.selectOne("SELECT teamcnt FROM admin;"); + } + + } +} diff --git a/Aktywator/Tournament.cs b/Aktywator/Tournament.cs new file mode 100644 index 0000000..fdeb323 --- /dev/null +++ b/Aktywator/Tournament.cs @@ -0,0 +1,36 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace Aktywator +{ + abstract public class Tournament + { + public const int TYPE_PARY = 1; + public const int TYPE_TEAMY = 2; + public const int TYPE_UNKNOWN = 0; + + protected string _name; + public string name + { + get { return _name; } + } + + protected int _type; // 0-unknown, 1-Pary, 2-Teamy + public int type + { + get { return _type; } + } + + abstract internal void setup(); + + abstract internal string getName(); + + abstract public string getSectionsNum(); + + abstract public string getTablesNum(); + + abstract internal string getTypeLabel(); + + } +} -- cgit v1.2.3