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/ChooseTournament.cs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'Aktywator/ChooseTournament.cs') 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()); -- cgit v1.2.3 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/ChooseTournament.cs') 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 From f12d2b996b165d66f4c32eef4a3bdfb89309670d Mon Sep 17 00:00:00 2001 From: emkael Date: Mon, 20 Nov 2017 21:36:09 +0100 Subject: Further improvement to DB listing performace. Fixes #25 (hopefully properly this time). --- Aktywator/ChooseTournament.cs | 23 +++++++++++++++-------- Aktywator/MySQLTournament.cs | 17 +++++++++++++---- Aktywator/Resources/BuildDate.txt | 2 +- 3 files changed, 29 insertions(+), 13 deletions(-) (limited to 'Aktywator/ChooseTournament.cs') diff --git a/Aktywator/ChooseTournament.cs b/Aktywator/ChooseTournament.cs index 734b191..2a7316f 100644 --- a/Aktywator/ChooseTournament.cs +++ b/Aktywator/ChooseTournament.cs @@ -8,9 +8,16 @@ using System.Windows.Forms; namespace Aktywator { + public struct TournamentListItem + { + public int Type; + public string Name; + public string Label; + } + public partial class ChooseTournament : Form { - private MySQLTournament[] turns; + private TournamentListItem[] turns; public MySQLTournament chosenTournament; public ChooseTournament() @@ -20,13 +27,13 @@ namespace Aktywator private void ChooseTournament_Load(object sender, EventArgs e) { - List list = MySQLTournament.getTournaments(); - turns = new MySQLTournament[list.Count]; + List list = MySQLTournament.getTournaments(); + turns = new TournamentListItem[list.Count]; int c = 0; - foreach (MySQLTournament t in list) + foreach (TournamentListItem t in list) { turns[c++] = t; - listBox.Items.Add(t.ToString()); + listBox.Items.Add(t.Label); } } @@ -34,13 +41,13 @@ namespace Aktywator { if (listBox.SelectedIndex >= 0) { - switch (turns[listBox.SelectedIndex].type) + switch (turns[listBox.SelectedIndex].Type) { case Tournament.TYPE_PARY: - chosenTournament = new ParyTournament(turns[listBox.SelectedIndex].name); + chosenTournament = new ParyTournament(turns[listBox.SelectedIndex].Name); break; case Tournament.TYPE_TEAMY: - chosenTournament = new TeamyTournament(turns[listBox.SelectedIndex].name); + chosenTournament = new TeamyTournament(turns[listBox.SelectedIndex].Name); break; } Close(); diff --git a/Aktywator/MySQLTournament.cs b/Aktywator/MySQLTournament.cs index f745a91..3bc9acc 100644 --- a/Aktywator/MySQLTournament.cs +++ b/Aktywator/MySQLTournament.cs @@ -21,19 +21,28 @@ namespace Aktywator mysql = new MySQL(name); } + public static string getLabel(string name, int type) + { + return name + " [" + (type == Tournament.TYPE_PARY ? 'P' : 'T') + "]"; + } + public override string ToString() { - return this.name + " [" + (this.type == Tournament.TYPE_PARY ? 'P' : 'T') + "]"; + return MySQLTournament.getLabel(this.name, this.type); } - public static List getTournaments() + public static List getTournaments() { - List list = new List(); + List list = new List(); MySQL c = new MySQL(""); data dbs = c.select("SELECT TABLE_SCHEMA, COLUMN_NAME FROM information_schema.COLUMNS WHERE TABLE_NAME = 'admin' AND COLUMN_NAME IN ('dnazwa', 'teamcnt') ORDER BY TABLE_SCHEMA;"); while (dbs.Read()) { - list.Add(new MySQLTournament(dbs.GetString(0), "dnazwa".Equals(dbs.GetString(1)) ? Tournament.TYPE_PARY : Tournament.TYPE_TEAMY)); + TournamentListItem item = new TournamentListItem(); + item.Name = dbs.GetString(0); + item.Type = "dnazwa".Equals(dbs.GetString(1)) ? Tournament.TYPE_PARY : Tournament.TYPE_TEAMY; + item.Label = MySQLTournament.getLabel(item.Name, item.Type); + list.Add(item); } dbs.Close(); return list; diff --git a/Aktywator/Resources/BuildDate.txt b/Aktywator/Resources/BuildDate.txt index 4accc51..6b9b605 100644 --- a/Aktywator/Resources/BuildDate.txt +++ b/Aktywator/Resources/BuildDate.txt @@ -1 +1 @@ -2017-11-18 +2017-11-20 -- cgit v1.2.3