From c826889695c08a76c0e4c4f5d8ae126a3eb09ab6 Mon Sep 17 00:00:00 2001 From: emkael Date: Sun, 30 Jul 2017 00:51:34 +0200 Subject: Tournament info code refactored for incoming generalization --- Aktywator/Tournament.cs | 37 ++++++++++++++++++++++++++++++------- 1 file changed, 30 insertions(+), 7 deletions(-) (limited to 'Aktywator/Tournament.cs') diff --git a/Aktywator/Tournament.cs b/Aktywator/Tournament.cs index b46740b..ec45c15 100644 --- a/Aktywator/Tournament.cs +++ b/Aktywator/Tournament.cs @@ -8,6 +8,10 @@ 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 { @@ -34,17 +38,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 = 1; + _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 = 2; - else _type = 0; + _type = Tournament.TYPE_TEAMY; + else _type = Tournament.TYPE_UNKNOWN; } public override string ToString() { - return this.name + " [" + (this.type == 1 ? 'P' : 'T') + "]"; + return this.name + " [" + (this.type == Tournament.TYPE_PARY ? 'P' : 'T') + "]"; } public static List getTournaments() @@ -55,7 +59,7 @@ namespace Aktywator while (dbs.Read()) { Tournament t = new Tournament(dbs.GetString(0)); - if (t.type > 0) + if (t.type > Tournament.TYPE_UNKNOWN) list.Add(t); t.mysql.close(); } @@ -64,7 +68,7 @@ namespace Aktywator public string getSectionsNum() { - if (type == 1) + if (type == Tournament.TYPE_PARY) return mysql.selectOne("SELECT COUNT(DISTINCT seknum) FROM sektory;"); else return "1"; @@ -72,11 +76,30 @@ namespace Aktywator public string getTablesNum() { - if (type == 1) + 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