From f14238e95bf1a10789585bf7632c5506daecc630 Mon Sep 17 00:00:00 2001 From: emkael Date: Sun, 30 Jul 2017 00:55:33 +0200 Subject: Refactoring Tournament as MySQLTournament --- Aktywator/Aktywator.csproj | 2 +- Aktywator/Bws.cs | 2 +- Aktywator/ChooseTournament.cs | 10 ++-- Aktywator/MainForm.cs | 6 +-- Aktywator/MySQLTournament.cs | 105 ++++++++++++++++++++++++++++++++++++++++++ Aktywator/Tournament.cs | 105 ------------------------------------------ 6 files changed, 115 insertions(+), 115 deletions(-) create mode 100644 Aktywator/MySQLTournament.cs delete mode 100644 Aktywator/Tournament.cs (limited to 'Aktywator') diff --git a/Aktywator/Aktywator.csproj b/Aktywator/Aktywator.csproj index edee3c0..97fa090 100644 --- a/Aktywator/Aktywator.csproj +++ b/Aktywator/Aktywator.csproj @@ -107,7 +107,7 @@ - + ChooseTournament.cs diff --git a/Aktywator/Bws.cs b/Aktywator/Bws.cs index 6a3b394..24e707c 100644 --- a/Aktywator/Bws.cs +++ b/Aktywator/Bws.cs @@ -344,7 +344,7 @@ namespace Aktywator else return 0; } - public void syncNames(Tournament tournament, bool interactive, string startRounds) + public void syncNames(MySQLTournament tournament, bool interactive, string startRounds) { int count = 0, countNew = 0, SKOK_STOLOW = 100; data d; diff --git a/Aktywator/ChooseTournament.cs b/Aktywator/ChooseTournament.cs index 2bc2ded..155624b 100644 --- a/Aktywator/ChooseTournament.cs +++ b/Aktywator/ChooseTournament.cs @@ -10,8 +10,8 @@ namespace Aktywator { public partial class ChooseTournament : Form { - private Tournament[] turns; - public Tournament chosenTournament; + private MySQLTournament[] turns; + public MySQLTournament chosenTournament; public ChooseTournament() { @@ -20,10 +20,10 @@ namespace Aktywator private void ChooseTournament_Load(object sender, EventArgs e) { - List list = Tournament.getTournaments(); - turns = new Tournament[list.Count]; + List list = MySQLTournament.getTournaments(); + turns = new MySQLTournament[list.Count]; int c = 0; - foreach (Tournament t in list) + foreach (MySQLTournament t in list) { turns[c++] = t; listBox.Items.Add(t.ToString()); diff --git a/Aktywator/MainForm.cs b/Aktywator/MainForm.cs index 55e2f53..96d965b 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 Tournament tournament; + private MySQLTournament tournament; public MainForm() { @@ -181,7 +181,7 @@ namespace Aktywator } } - private void updateTournamentInfo(Tournament tournament) + private void updateTournamentInfo(MySQLTournament tournament) { if (tournament != null) { @@ -194,7 +194,7 @@ namespace Aktywator bSync.Enabled = true; bAutoSync.Enabled = true; eInterval.Enabled = true; - if (tournament.type == Tournament.TYPE_TEAMY) + if (tournament.type == MySQLTournament.TYPE_TEAMY) { lSkok.Visible = true; lNazwyTeamow.Visible = true; diff --git a/Aktywator/MySQLTournament.cs b/Aktywator/MySQLTournament.cs new file mode 100644 index 0000000..54f3f7b --- /dev/null +++ b/Aktywator/MySQLTournament.cs @@ -0,0 +1,105 @@ +using System; +using System.Collections.Generic; +using System.Text; +using MySql.Data.MySqlClient; +using data = MySql.Data.MySqlClient.MySqlDataReader; + +namespace Aktywator +{ + public class MySQLTournament + { + 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) + { + this._name = name; + mysql = new MySQL(name); + recognizeType(); + } + + private void recognizeType() + { + 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; + 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; + } + + public override string ToString() + { + return this.name + " [" + (this.type == MySQLTournament.TYPE_PARY ? 'P' : 'T') + "]"; + } + + public static List getTournaments() + { + List list = new List(); + MySQL c = new MySQL(""); + data dbs = c.select("SHOW DATABASES;"); + while (dbs.Read()) + { + MySQLTournament t = new MySQLTournament(dbs.GetString(0)); + if (t.type > MySQLTournament.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() + { + if (this.mysql != null) + { + this.mysql.close(); + this.mysql.connect(); + } + } + + internal string getName() + { + return this.name; + } + + internal string getTypeLabel() + { + return this._type == MySQLTournament.TYPE_PARY ? "Pary" : "Teamy"; + } + } +} diff --git a/Aktywator/Tournament.cs b/Aktywator/Tournament.cs deleted file mode 100644 index ec45c15..0000000 --- a/Aktywator/Tournament.cs +++ /dev/null @@ -1,105 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Text; -using MySql.Data.MySqlClient; -using data = MySql.Data.MySqlClient.MySqlDataReader; - -namespace Aktywator -{ - public class 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 Tournament(string name) - { - this._name = name; - mysql = new MySQL(name); - recognizeType(); - } - - private void recognizeType() - { - 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 = 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 = Tournament.TYPE_TEAMY; - else _type = Tournament.TYPE_UNKNOWN; - } - - public override string ToString() - { - return this.name + " [" + (this.type == Tournament.TYPE_PARY ? 'P' : 'T') + "]"; - } - - public static List getTournaments() - { - List list = new List(); - MySQL c = new MySQL(""); - data dbs = c.select("SHOW DATABASES;"); - while (dbs.Read()) - { - Tournament t = new Tournament(dbs.GetString(0)); - if (t.type > Tournament.TYPE_UNKNOWN) - list.Add(t); - t.mysql.close(); - } - return list; - } - - public string getSectionsNum() - { - if (type == Tournament.TYPE_PARY) - return mysql.selectOne("SELECT COUNT(DISTINCT seknum) FROM sektory;"); - else - return "1"; - } - - public string getTablesNum() - { - if (type == Tournament.TYPE_PARY) - return mysql.selectOne("SELECT COUNT(*) FROM sektory;"); - else - return mysql.selectOne("SELECT teamcnt FROM admin;"); - } - - - internal void setup() - { - if (this.mysql != null) - { - this.mysql.close(); - this.mysql.connect(); - } - } - - internal string getName() - { - return this.name; - } - - internal string getTypeLabel() - { - return this._type == Tournament.TYPE_PARY ? "Pary" : "Teamy"; - } - } -} -- cgit v1.2.3