summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoremkael <emkael@tlen.pl>2017-07-30 00:51:34 +0200
committeremkael <emkael@tlen.pl>2017-07-30 00:51:34 +0200
commitc826889695c08a76c0e4c4f5d8ae126a3eb09ab6 (patch)
tree0ecfbda705a6be5f4d29470aca2c594029cc8f69
parent04f325bbb2f9cfcfdf699b28057651f4a6a50541 (diff)
Tournament info code refactored for incoming generalization
-rw-r--r--Aktywator/MainForm.cs54
-rw-r--r--Aktywator/Tournament.cs37
2 files changed, 62 insertions, 29 deletions
diff --git a/Aktywator/MainForm.cs b/Aktywator/MainForm.cs
index 24f300c..55e2f53 100644
--- a/Aktywator/MainForm.cs
+++ b/Aktywator/MainForm.cs
@@ -171,29 +171,8 @@ namespace Aktywator
choose.ShowDialog();
if (choose.chosenTournament != null)
{
- if ((tournament != null) && (tournament.mysql != null))
- tournament.mysql.close();
-
tournament = choose.chosenTournament;
- tournament.mysql.connect();
-
- lTournament.Text = tournament.name;
- lType.Text = tournament.type == 1 ? "Pary" : "Teamy";
- lSections.Text = tournament.getSectionsNum();
- lTables.Text = tournament.getTablesNum();
- bSync.Enabled = true;
- bAutoSync.Enabled = true;
- eInterval.Enabled = true;
- if (tournament.type == 2)
- {
- lSkok.Visible = true;
- lNazwyTeamow.Visible = true;
- }
- else
- {
- lSkok.Visible = false;
- lNazwyTeamow.Visible = false;
- }
+ updateTournamentInfo(tournament);
}
}
catch (Exception ee)
@@ -202,6 +181,37 @@ namespace Aktywator
}
}
+ private void updateTournamentInfo(Tournament tournament)
+ {
+ if (tournament != null)
+ {
+ tournament.setup();
+
+ lTournament.Text = tournament.getName();
+ lType.Text = tournament.getTypeLabel();
+ lSections.Text = tournament.getSectionsNum();
+ lTables.Text = tournament.getTablesNum();
+ bSync.Enabled = true;
+ bAutoSync.Enabled = true;
+ eInterval.Enabled = true;
+ if (tournament.type == Tournament.TYPE_TEAMY)
+ {
+ lSkok.Visible = true;
+ lNazwyTeamow.Visible = true;
+ }
+ else
+ {
+ lSkok.Visible = false;
+ lNazwyTeamow.Visible = false;
+ }
+ }
+ else
+ {
+ lSkok.Visible = false;
+ lNazwyTeamow.Visible = false;
+ }
+ }
+
private void bSync_Click(object sender, EventArgs e)
{
try
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<Tournament> 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";
+ }
}
}