summaryrefslogtreecommitdiff
path: root/Aktywator
diff options
context:
space:
mode:
Diffstat (limited to 'Aktywator')
-rw-r--r--Aktywator/Aktywator.csproj4
-rw-r--r--Aktywator/Bws.cs179
-rw-r--r--Aktywator/ChooseTournament.cs20
-rw-r--r--Aktywator/Common.cs22
-rw-r--r--Aktywator/MainForm.Designer.cs51
-rw-r--r--Aktywator/MainForm.cs84
-rw-r--r--Aktywator/MySQLTournament.cs84
-rw-r--r--Aktywator/ParyTournament.cs56
-rw-r--r--Aktywator/Properties/AssemblyInfo.cs6
-rw-r--r--Aktywator/RRBTournament.cs90
-rw-r--r--Aktywator/Sql.cs17
-rw-r--r--Aktywator/TeamyTournament.cs47
-rw-r--r--Aktywator/Tournament.cs70
13 files changed, 517 insertions, 213 deletions
diff --git a/Aktywator/Aktywator.csproj b/Aktywator/Aktywator.csproj
index edee3c0..a4dc515 100644
--- a/Aktywator/Aktywator.csproj
+++ b/Aktywator/Aktywator.csproj
@@ -99,14 +99,18 @@
<Compile Include="MysqlSettings.Designer.cs">
<DependentUpon>MysqlSettings.cs</DependentUpon>
</Compile>
+ <Compile Include="ParyTournament.cs" />
<Compile Include="PBN.cs" />
<Compile Include="PBNBoard.cs" />
<Compile Include="PBNFile.cs" />
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
+ <Compile Include="RRBTournament.cs" />
<Compile Include="Setting.cs" />
<Compile Include="Settings.cs" />
<Compile Include="Sql.cs" />
+ <Compile Include="MySQLTournament.cs" />
+ <Compile Include="TeamyTournament.cs" />
<Compile Include="Tournament.cs" />
<EmbeddedResource Include="ChooseTournament.resx">
<DependentUpon>ChooseTournament.cs</DependentUpon>
diff --git a/Aktywator/Bws.cs b/Aktywator/Bws.cs
index 1cc5e07..4bc107f 100644
--- a/Aktywator/Bws.cs
+++ b/Aktywator/Bws.cs
@@ -3,9 +3,7 @@ using System.Collections.Generic;
using System.Text;
using System.Data.OleDb;
using System.Windows.Forms;
-using MySql.Data.MySqlClient;
-using mydata = MySql.Data.MySqlClient.MySqlDataReader;
-using data = System.Data.OleDb.OleDbDataReader;
+using System.Data.OleDb;
namespace Aktywator
{
@@ -113,7 +111,7 @@ namespace Aktywator
try
{
string s;
- data d = sql.select("SELECT DISTINCT `Section` FROM " + table + " ORDER BY 1");
+ OleDbDataReader d = sql.select("SELECT DISTINCT `Section` FROM " + table + " ORDER BY 1");
d.Read();
s = d[0].ToString();
while (d.Read())
@@ -341,26 +339,47 @@ namespace Aktywator
name = Common.bezOgonkow(name);
if (name.Length > 18)
name = name.Substring(0, 18);
- string actual = sql.selectOne("SELECT Name FROM PlayerNumbers WHERE `Section`=" + section + " AND `Table`=" + table
- + " AND `Direction`='" + direction + "'");
- if (actual != name)
+ try
+ {
+ string actual = sql.selectOne("SELECT Name FROM PlayerNumbers WHERE `Section`=" + section + " AND `Table`=" + table
+ + " AND `Direction`='" + direction + "'", true);
+ if (actual != name)
+ {
+ sql.query("UPDATE PlayerNumbers SET Name='" + name + "', Updated=TRUE WHERE `Section`=" + section + " AND `Table`=" + table
+ + " AND `Direction`='" + direction + "'");
+ return 1;
+ }
+ else return 0;
+ }
+ catch (OleDbRowMissingException)
{
- sql.query("UPDATE PlayerNumbers SET Name='" + name + "', Updated=TRUE WHERE `Section`=" + section + " AND `Table`=" + table
- + " AND `Direction`='" + direction + "'");
+ sql.query("INSERT INTO PlayerNumbers(`Section`, `Table`, Direction, Name, Updated) VALUES("
+ + section + ", " + table + ", '" + direction + "', '" + name + "', TRUE)");
return 1;
}
- else return 0;
+ }
+
+ private int getBWSNumber(OleDbDataReader reader, int index)
+ {
+ switch (Type.GetTypeCode(reader.GetFieldType(index)))
+ {
+ case TypeCode.Int16:
+ return reader.GetInt16(index);
+ case TypeCode.Int32:
+ return reader.GetInt32(index);
+ }
+ throw new InvalidCastException("Unable to read numeric value from BWS field");
}
public void syncNames(Tournament tournament, bool interactive, string startRounds)
{
int count = 0, countNew = 0, SKOK_STOLOW = 100;
- data d;
+ OleDbDataReader d;
startRounds = startRounds.Trim();
- if (tournament.type == 1)
+ if (tournament.type != Tournament.TYPE_TEAMY)
{
- if (startRounds.Length > 0)
+ if (tournament.type == Tournament.TYPE_PARY && startRounds.Length > 0)
{
d = sql.select("SELECT `Section`, `Table`, NSPair, EWPair FROM RoundData WHERE NSPair>0 AND `Round` in (" + startRounds + ")");
}
@@ -372,90 +391,90 @@ namespace Aktywator
}
else
{
- d = sql.select("SELECT `Section`, `Table`, NSPair, EWPair FROM RoundData WHERE `Table`<=100");
+ d = sql.select("SELECT `Section`, `Table`, NSPair, EWPair FROM RoundData WHERE `Table`<=" + SKOK_STOLOW);
}
- while (d.Read())
+ try
{
- string section = d.GetInt32(0).ToString();
- string table = d.GetInt32(1).ToString();
- string ns = d.GetInt32(2).ToString();
- string ew = d.GetInt32(3).ToString();
+ Dictionary<int, List<String>> names = tournament.getNameList();
- StringBuilder query = new StringBuilder();
- if (tournament.type == 1)
- {
- query.Append("SELECT CONCAT(SUBSTR(imie,1,1),'.',nazw) name FROM zawodnicy WHERE idp=");
- query.Append(ns);
- query.Append(" OR idp=");
- query.Append(ew);
- query.Append(" ORDER BY idp ");
- if (int.Parse(ew) < int.Parse(ns))
- query.Append("DESC");
- }
- else
+ while (d.Read())
{
- query.Append("SELECT fullname NAME FROM teams WHERE id=");
- query.Append(ns);
- query.Append(" UNION ALL SELECT ' ' UNION ALL");
- query.Append(" SELECT fullname NAME FROM teams WHERE id=");
- query.Append(ew);
- query.Append(" UNION ALL SELECT ' '; ");
- }
- mydata n = tournament.mysql.select(query.ToString());
+ string section = this.getBWSNumber(d, 0).ToString();
+ string table = this.getBWSNumber(d, 1).ToString();
+ int ns = this.getBWSNumber(d, 2);
+ int ew = this.getBWSNumber(d, 3);
- try
- {
- n.Read();
- countNew += updateName(section, table, "N", n.IsDBNull(0) ? "" : n.GetString(0));
- if (tournament.type == 2)
- countNew += updateName(section, (int.Parse(table) + SKOK_STOLOW).ToString(), "E", n.IsDBNull(0) ? "" : n.GetString(0));
- n.Read();
- countNew += updateName(section, table, "S", n.IsDBNull(0) ? "" : n.GetString(0));
- if (tournament.type == 2)
- countNew += updateName(section, (int.Parse(table) + SKOK_STOLOW).ToString(), "W", n.IsDBNull(0) ? "" : n.GetString(0));
- n.Read();
- countNew += updateName(section, table, "E", n.IsDBNull(0) ? "" : n.GetString(0));
- if (tournament.type == 2)
- countNew += updateName(section, (int.Parse(table) + SKOK_STOLOW).ToString(), "N", n.IsDBNull(0) ? "" : n.GetString(0));
- n.Read();
- countNew += updateName(section, table, "W", n.IsDBNull(0) ? "" : n.GetString(0));
- if (tournament.type == 2)
- countNew += updateName(section, (int.Parse(table) + SKOK_STOLOW).ToString(), "S", n.IsDBNull(0) ? "" : n.GetString(0));
-
- if (tournament.type == 1) count += 4;
- else count += 8;
- }
- catch (MySqlException ee)
- {
- if (interactive)
+ try
{
- if (ee.ErrorCode == -2147467259)
+ if (!names.ContainsKey(ns))
{
- DialogResult dr = MessageBox.Show("W bws-ie jest para/team (" + ns + " albo " + ew
- + "), który nie istnieje w wybranym turnieju. Może to nie ten turniej?",
- "Zły turniej", MessageBoxButtons.AbortRetryIgnore, MessageBoxIcon.Warning);
- if (dr == DialogResult.Abort) return;
+ throw new KeyNotFoundException(ns.ToString());
}
- else
+ countNew += updateName(section, table, "N", names[ns][0]);
+ countNew += updateName(section, table, "S", names[ns][1]);
+ count += 2;
+ if (tournament.type == Tournament.TYPE_TEAMY)
+ {
+ countNew += updateName(section, (int.Parse(table) + SKOK_STOLOW).ToString(), "E", names[ns][0]);
+ countNew += updateName(section, (int.Parse(table) + SKOK_STOLOW).ToString(), "W", names[ns][1]);
+ count += 2;
+ }
+ }
+ catch (KeyNotFoundException keyE)
+ {
+ if (interactive)
{
- MessageBox.Show(ee.Message, "Błąd MySQL", MessageBoxButtons.AbortRetryIgnore, MessageBoxIcon.Warning);
+ DialogResult dr = MessageBox.Show("W bws-ie jest para/team (" + keyE.Message + ")"
+ + ", który nie istnieje w wybranym turnieju."
+ + "Może to nie ten turniej?" + "\n\n" + "Kontynuować wczytywanie?",
+ "Zły turniej", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);
+ if (dr == DialogResult.No) break;
+ }
+ }
+ try
+ {
+ if (!names.ContainsKey(ew))
+ {
+ throw new KeyNotFoundException(ew.ToString());
+ }
+ countNew += updateName(section, table, "E", names[ew][0]);
+ countNew += updateName(section, table, "W", names[ew][1]);
+ count += 2;
+ if (tournament.type == Tournament.TYPE_TEAMY)
+ {
+ countNew += updateName(section, (int.Parse(table) + SKOK_STOLOW).ToString(), "N", names[ew][0]);
+ countNew += updateName(section, (int.Parse(table) + SKOK_STOLOW).ToString(), "S", names[ew][1]);
+ count += 2;
+ }
+ }
+ catch (KeyNotFoundException keyE)
+ {
+ if (interactive)
+ {
+ DialogResult dr = MessageBox.Show("W bws-ie jest para/team (" + keyE.Message + ")"
+ + ", który nie istnieje w wybranym turnieju."
+ + "Może to nie ten turniej?" + "\n\n" + "Kontynuować wczytywanie?",
+ "Zły turniej", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);
+ if (dr == DialogResult.No) break;
}
}
}
- try
+ if (interactive)
{
- n.Close();
+ MessageBox.Show("Synchronizacja zakończona!\nPrzejrzanych nazwisk: " + count + "\nZmienionych: " + countNew,
+ "Synchronizacja nazwisk", MessageBoxButtons.OK, MessageBoxIcon.Information);
+ if (sql.selectOne("SELECT BM2ShowPlayerNames FROM Settings") != "1")
+ MessageBox.Show("Pamiętaj żeby włączyć opcję \"pokazuj nazwiska\"!", "Brakujące ustawienie",
+ MessageBoxButtons.OK, MessageBoxIcon.Information);
}
- catch (Exception) { }
}
- if (interactive)
+ catch (Exception ee)
{
- MessageBox.Show("Synchronizacja zakończona!\nPrzejrzanych nazwisk: " + count + "\nZmienionych: " + countNew,
- "Synchronizacja nazwisk", MessageBoxButtons.OK, MessageBoxIcon.Information);
- if (sql.selectOne("SELECT BM2ShowPlayerNames FROM Settings") != "1")
- MessageBox.Show("Pamiętaj żeby włączyć opcję \"pokazuj nazwiska\"!", "Brakujące ustawienie",
- MessageBoxButtons.OK, MessageBoxIcon.Information);
+ if (interactive)
+ {
+ MessageBox.Show(ee.Message, "Błąd wczytywania nazwisk", MessageBoxButtons.OK, MessageBoxIcon.Error);
+ }
}
}
diff --git a/Aktywator/ChooseTournament.cs b/Aktywator/ChooseTournament.cs
index 2bc2ded..734b191 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<Tournament> list = Tournament.getTournaments();
- turns = new Tournament[list.Count];
+ List<MySQLTournament> 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());
@@ -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/Common.cs b/Aktywator/Common.cs
index d00649d..b00157c 100644
--- a/Aktywator/Common.cs
+++ b/Aktywator/Common.cs
@@ -17,27 +17,9 @@ namespace Aktywator
return Environment.GetEnvironmentVariable("ProgramFiles");
}
- public static string bezOgonkow(string str)
+ public static string bezOgonkow(string text)
{
- str = str.Replace('ą', 'a');
- str = str.Replace('ć', 'c');
- str = str.Replace('ę', 'e');
- str = str.Replace('ł', 'l');
- str = str.Replace('ń', 'n');
- str = str.Replace('ó', 'o');
- str = str.Replace('ś', 's');
- str = str.Replace('ź', 'z');
- str = str.Replace('ż', 'z');
- str = str.Replace('Ą', 'A');
- str = str.Replace('Ć', 'C');
- str = str.Replace('Ę', 'E');
- str = str.Replace('Ł', 'L');
- str = str.Replace('Ń', 'N');
- str = str.Replace('Ó', 'O');
- str = str.Replace('Ś', 'S');
- str = str.Replace('Ź', 'Z');
- str = str.Replace('Ż', 'Z');
- return str;
+ return Encoding.ASCII.GetString(Encoding.GetEncoding(1251).GetBytes(text));
}
}
}
diff --git a/Aktywator/MainForm.Designer.cs b/Aktywator/MainForm.Designer.cs
index a921d82..20066e0 100644
--- a/Aktywator/MainForm.Designer.cs
+++ b/Aktywator/MainForm.Designer.cs
@@ -77,6 +77,7 @@
this.xShowResults = new System.Windows.Forms.CheckBox();
this.label1 = new System.Windows.Forms.Label();
this.tabPage2 = new System.Windows.Forms.TabPage();
+ this.bRRBTournament = new System.Windows.Forms.Button();
this.label9 = new System.Windows.Forms.Label();
this.eOomRounds = new System.Windows.Forms.TextBox();
this.bForceSync = new System.Windows.Forms.Button();
@@ -97,7 +98,7 @@
this.label5 = new System.Windows.Forms.Label();
this.label4 = new System.Windows.Forms.Label();
this.lTournament = new System.Windows.Forms.Label();
- this.bTournament = new System.Windows.Forms.Button();
+ this.bMySQLTournament = new System.Windows.Forms.Button();
this.label3 = new System.Windows.Forms.Label();
this.tabPage3 = new System.Windows.Forms.TabPage();
this.bClearHands = new System.Windows.Forms.Button();
@@ -626,6 +627,7 @@
//
// tabPage2
//
+ this.tabPage2.Controls.Add(this.bRRBTournament);
this.tabPage2.Controls.Add(this.label9);
this.tabPage2.Controls.Add(this.eOomRounds);
this.tabPage2.Controls.Add(this.bForceSync);
@@ -646,7 +648,7 @@
this.tabPage2.Controls.Add(this.label5);
this.tabPage2.Controls.Add(this.label4);
this.tabPage2.Controls.Add(this.lTournament);
- this.tabPage2.Controls.Add(this.bTournament);
+ this.tabPage2.Controls.Add(this.bMySQLTournament);
this.tabPage2.Controls.Add(this.label3);
this.tabPage2.Location = new System.Drawing.Point(4, 22);
this.tabPage2.Name = "tabPage2";
@@ -656,6 +658,16 @@
this.tabPage2.Text = "Nazwiska";
this.tabPage2.UseVisualStyleBackColor = true;
//
+ // bRRBTournament
+ //
+ this.bRRBTournament.Location = new System.Drawing.Point(54, 51);
+ this.bRRBTournament.Name = "bRRBTournament";
+ this.bRRBTournament.Size = new System.Drawing.Size(89, 23);
+ this.bRRBTournament.TabIndex = 25;
+ this.bRRBTournament.Text = "wybierz (RRB)";
+ this.bRRBTournament.UseVisualStyleBackColor = true;
+ this.bRRBTournament.Click += new System.EventHandler(this.bRRBTournament_Click);
+ //
// label9
//
this.label9.AutoSize = true;
@@ -697,7 +709,7 @@
// lSkok
//
this.lSkok.AutoSize = true;
- this.lSkok.Location = new System.Drawing.Point(77, 150);
+ this.lSkok.Location = new System.Drawing.Point(77, 164);
this.lSkok.Name = "lSkok";
this.lSkok.Size = new System.Drawing.Size(188, 13);
this.lSkok.TabIndex = 19;
@@ -788,7 +800,7 @@
// lTables
//
this.lTables.AutoSize = true;
- this.lTables.Location = new System.Drawing.Point(77, 127);
+ this.lTables.Location = new System.Drawing.Point(77, 138);
this.lTables.Name = "lTables";
this.lTables.Size = new System.Drawing.Size(0, 13);
this.lTables.TabIndex = 8;
@@ -796,7 +808,7 @@
// lSections
//
this.lSections.AutoSize = true;
- this.lSections.Location = new System.Drawing.Point(77, 102);
+ this.lSections.Location = new System.Drawing.Point(77, 113);
this.lSections.Name = "lSections";
this.lSections.Size = new System.Drawing.Size(0, 13);
this.lSections.TabIndex = 7;
@@ -804,7 +816,7 @@
// lType
//
this.lType.AutoSize = true;
- this.lType.Location = new System.Drawing.Point(77, 77);
+ this.lType.Location = new System.Drawing.Point(77, 88);
this.lType.Name = "lType";
this.lType.Size = new System.Drawing.Size(0, 13);
this.lType.TabIndex = 6;
@@ -812,7 +824,7 @@
// label6
//
this.label6.AutoSize = true;
- this.label6.Location = new System.Drawing.Point(9, 127);
+ this.label6.Location = new System.Drawing.Point(9, 138);
this.label6.Name = "label6";
this.label6.Size = new System.Drawing.Size(44, 13);
this.label6.TabIndex = 5;
@@ -821,7 +833,7 @@
// label5
//
this.label5.AutoSize = true;
- this.label5.Location = new System.Drawing.Point(9, 102);
+ this.label5.Location = new System.Drawing.Point(9, 113);
this.label5.Name = "label5";
this.label5.Size = new System.Drawing.Size(55, 13);
this.label5.TabIndex = 4;
@@ -830,7 +842,7 @@
// label4
//
this.label4.AutoSize = true;
- this.label4.Location = new System.Drawing.Point(9, 77);
+ this.label4.Location = new System.Drawing.Point(9, 88);
this.label4.Name = "label4";
this.label4.Size = new System.Drawing.Size(28, 13);
this.label4.TabIndex = 3;
@@ -840,20 +852,20 @@
//
this.lTournament.AutoSize = true;
this.lTournament.Font = new System.Drawing.Font("Microsoft Sans Serif", 9.75F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(238)));
- this.lTournament.Location = new System.Drawing.Point(135, 30);
+ this.lTournament.Location = new System.Drawing.Point(149, 48);
this.lTournament.Name = "lTournament";
this.lTournament.Size = new System.Drawing.Size(0, 16);
this.lTournament.TabIndex = 2;
//
- // bTournament
+ // bMySQLTournament
//
- this.bTournament.Location = new System.Drawing.Point(54, 27);
- this.bTournament.Name = "bTournament";
- this.bTournament.Size = new System.Drawing.Size(75, 23);
- this.bTournament.TabIndex = 1;
- this.bTournament.Text = "wybierz";
- this.bTournament.UseVisualStyleBackColor = true;
- this.bTournament.Click += new System.EventHandler(this.bTournament_Click);
+ this.bMySQLTournament.Location = new System.Drawing.Point(54, 27);
+ this.bMySQLTournament.Name = "bMySQLTournament";
+ this.bMySQLTournament.Size = new System.Drawing.Size(89, 23);
+ this.bMySQLTournament.TabIndex = 1;
+ this.bMySQLTournament.Text = "wybierz (JFR)";
+ this.bMySQLTournament.UseVisualStyleBackColor = true;
+ this.bMySQLTournament.Click += new System.EventHandler(this.bMySQLTournament_Click);
//
// label3
//
@@ -1115,7 +1127,7 @@
private System.Windows.Forms.Button bSave;
private System.Windows.Forms.Button bLoad;
private System.Windows.Forms.Label lTournament;
- private System.Windows.Forms.Button bTournament;
+ private System.Windows.Forms.Button bMySQLTournament;
private System.Windows.Forms.Label label3;
private System.Windows.Forms.Label label4;
private System.Windows.Forms.Label lTables;
@@ -1153,6 +1165,7 @@
public System.Windows.Forms.CheckedListBox cblSections;
private System.Windows.Forms.Label lRecordSections;
private System.Windows.Forms.Button bClearHands;
+ private System.Windows.Forms.Button bRRBTournament;
private System.Windows.Forms.Label label17;
private System.Windows.Forms.Label label16;
private System.Windows.Forms.Label label15;
diff --git a/Aktywator/MainForm.cs b/Aktywator/MainForm.cs
index b1efe50..01c7e19 100644
--- a/Aktywator/MainForm.cs
+++ b/Aktywator/MainForm.cs
@@ -12,8 +12,8 @@ namespace Aktywator
{
public partial class MainForm : Form
{
- public string version = "1.0.8";
- public string date = "27.07.2017";
+ public string version = "1.1.0-beta";
+ public string date = "30.07.2017";
private Bws bws;
private List<Setting> bwsSettings;
@@ -292,7 +292,7 @@ namespace Aktywator
}
}
- private void bTournament_Click(object sender, EventArgs e)
+ private void bMySQLTournament_Click(object sender, EventArgs e)
{
try
{
@@ -300,29 +300,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)
@@ -331,6 +310,57 @@ namespace Aktywator
}
}
+ private void bRRBTournament_Click(object sender, EventArgs e)
+ {
+ try
+ {
+ OpenFileDialog fDialog = new OpenFileDialog();
+ fDialog.Filter = "RRBrigde tournament files (*.rrt)|*.rrt";
+ fDialog.RestoreDirectory = true;
+ if (fDialog.ShowDialog() == DialogResult.OK)
+ {
+ tournament = new RRBTournament(fDialog.FileName);
+ updateTournamentInfo(tournament);
+ }
+ }
+ catch (Exception ee)
+ {
+ MessageBox.Show(ee.Message, "Błąd", MessageBoxButtons.OK, MessageBoxIcon.Stop);
+ }
+ }
+
+ 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.GetType().Equals(typeof(TeamyTournament)))
+ {
+ 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
@@ -374,7 +404,7 @@ namespace Aktywator
timer.Interval = interval * 1000;
eInterval.Enabled = false;
bAutoSync.Text = "pracuje się...";
- bTournament.Enabled = false;
+ bMySQLTournament.Enabled = false;
bMysqlSettings.Enabled = false;
timer.Enabled = true;
}
@@ -383,7 +413,7 @@ namespace Aktywator
timer.Enabled = false;
bAutoSync.Text = "Synchronizuj cyklicznie";
eInterval.Enabled = true;
- bTournament.Enabled = true;
+ bMySQLTournament.Enabled = true;
bMysqlSettings.Enabled = true;
}
}
diff --git a/Aktywator/MySQLTournament.cs b/Aktywator/MySQLTournament.cs
new file mode 100644
index 0000000..ff3258a
--- /dev/null
+++ b/Aktywator/MySQLTournament.cs
@@ -0,0 +1,84 @@
+using System;
+using System.Collections.Generic;
+using System.Text;
+using MySql.Data.MySqlClient;
+using data = MySql.Data.MySqlClient.MySqlDataReader;
+
+namespace Aktywator
+{
+ public class MySQLTournament : Tournament
+ {
+ 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 = 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<MySQLTournament> getTournaments()
+ {
+ List<MySQLTournament> list = new List<MySQLTournament>();
+ MySQL c = new MySQL("");
+ data dbs = c.select("SHOW DATABASES;");
+ while (dbs.Read())
+ {
+ MySQLTournament t = new MySQLTournament(dbs.GetString(0));
+ if (t.type > Tournament.TYPE_UNKNOWN)
+ list.Add(t);
+ t.mysql.close();
+ }
+ return list;
+ }
+
+ override internal void setup()
+ {
+ if (this.mysql != null)
+ {
+ this.mysql.close();
+ this.mysql.connect();
+ }
+ }
+
+ override internal string getName()
+ {
+ return this.name;
+ }
+
+ override public string getSectionsNum()
+ {
+ throw new NotImplementedException("Don't call this method on generic class instance");
+ }
+
+ override public string getTablesNum()
+ {
+ 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..9a592d7
--- /dev/null
+++ b/Aktywator/ParyTournament.cs
@@ -0,0 +1,56 @@
+using System;
+using System.Collections.Generic;
+using System.Text;
+using MySql.Data.MySqlClient;
+
+namespace Aktywator
+{
+ class ParyTournament: MySQLTournament
+ {
+ public ParyTournament(string name)
+ : base(name)
+ {
+ this._type = Tournament.TYPE_PARY;
+ }
+
+ 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;");
+ }
+
+ override internal Dictionary<int, List<string>> getNameList()
+ {
+ Dictionary<int, List<String>> pairs = new Dictionary<int, List<string>>();
+ MySqlDataReader dbData = this.mysql.select("SELECT idp, CONCAT(SUBSTR(imie,1,1),'.',nazw) name FROM zawodnicy");
+ while (dbData.Read())
+ {
+ int pairNo = dbData.GetInt32(0);
+ if (!pairs.ContainsKey(pairNo))
+ {
+ pairs.Add(pairNo, new List<string>());
+ }
+ pairs[pairNo].Add(dbData.IsDBNull(1) ? "" : dbData.GetString(1));
+ }
+ foreach (KeyValuePair<int, List<string>> pair in pairs)
+ {
+ while (pair.Value.Count < 2)
+ {
+ pair.Value.Add("");
+ }
+ }
+ dbData.Close();
+ return pairs;
+ }
+
+ }
+}
diff --git a/Aktywator/Properties/AssemblyInfo.cs b/Aktywator/Properties/AssemblyInfo.cs
index df9c1fc..b3ba87f 100644
--- a/Aktywator/Properties/AssemblyInfo.cs
+++ b/Aktywator/Properties/AssemblyInfo.cs
@@ -10,7 +10,7 @@ using System.Runtime.InteropServices;
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("Michał Zimniewicz")]
[assembly: AssemblyProduct("Aktywator")]
-[assembly: AssemblyCopyright("Copyright © 2011-2016 Michał Zimniewicz")]
+[assembly: AssemblyCopyright("Copyright © 2011-2017 Michał Zimniewicz")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
@@ -32,5 +32,5 @@ using System.Runtime.InteropServices;
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
-[assembly: AssemblyVersion("1.0.6.0")]
-[assembly: AssemblyFileVersion("1.0.6.0")]
+[assembly: AssemblyVersion("1.1.0.0")]
+[assembly: AssemblyFileVersion("1.1.0.0")]
diff --git a/Aktywator/RRBTournament.cs b/Aktywator/RRBTournament.cs
new file mode 100644
index 0000000..20a3c21
--- /dev/null
+++ b/Aktywator/RRBTournament.cs
@@ -0,0 +1,90 @@
+using System;
+using System.Collections.Generic;
+using System.Text;
+using System.Xml;
+using System.IO;
+
+namespace Aktywator
+{
+ class RRBTournament : Tournament
+ {
+ private XmlDocument _xml;
+ private string p;
+
+ public RRBTournament(string name)
+ {
+ this._name = name;
+ this._type = Tournament.TYPE_RRB;
+ }
+
+ override internal void setup()
+ {
+ this._xml = new XmlDocument();
+ this._xml.Load(this._name);
+ }
+
+ override internal string getName()
+ {
+ return this._xml.SelectSingleNode("//ustawienia/nazwa").InnerText;
+ }
+
+ override public string getSectionsNum()
+ {
+ List<string> sections = new List<string>();
+ foreach (XmlNode table in this._xml.SelectNodes("//monitor/stoly/stol"))
+ {
+ string section = table.SelectSingleNode("sektor").InnerText;
+ if (!sections.Contains(section))
+ {
+ sections.Add(section);
+ }
+ }
+ return sections.Count.ToString();
+ }
+
+ override public string getTablesNum()
+ {
+ return this._xml.SelectNodes("//monitor/stoly/stol").Count.ToString();
+ }
+
+ override internal string getTypeLabel()
+ {
+ return "RRBridge";
+ }
+
+ override internal Dictionary<int, List<string>> getNameList()
+ {
+ Dictionary<int, List<string>> names = new Dictionary<int, List<string>>();
+ foreach (XmlNode pair in this._xml.SelectNodes("//lista/para"))
+ {
+ int pairNo = Int32.Parse(pair.SelectSingleNode("numer").InnerText);
+ names.Add(pairNo, new List<string>());
+ foreach (XmlNode player in pair.SelectNodes("gracz/nazwisko"))
+ {
+ if ("pauza".Equals(player.InnerText.Trim()))
+ {
+ names[pairNo].Add("");
+ }
+ else
+ {
+ string[] name = player.InnerText.Trim().Split(' ');
+ if (name.Length > 0)
+ {
+ name[0] = (name[0].Length > 0) ? name[0][0].ToString() : "";
+ }
+ names[pairNo].Add(String.Join(" ", name));
+ }
+ }
+ }
+
+ foreach (KeyValuePair<int, List<string>> pair in names)
+ {
+ while (pair.Value.Count < 2)
+ {
+ pair.Value.Add("");
+ }
+ }
+ return names;
+ }
+ }
+}
diff --git a/Aktywator/Sql.cs b/Aktywator/Sql.cs
index c35b0dd..cf0eb38 100644
--- a/Aktywator/Sql.cs
+++ b/Aktywator/Sql.cs
@@ -7,6 +7,10 @@ using data = System.Data.OleDb.OleDbDataReader;
namespace Aktywator
{
+ class OleDbRowMissingException : Exception
+ {
+ }
+
class Sql
{
private OleDbConnection connection;
@@ -34,12 +38,19 @@ namespace Aktywator
OleDbCommand cmd = new OleDbCommand(q, connection);
return cmd.ExecuteNonQuery();
}
- public string selectOne(string q)
+ public string selectOne(string q, bool checkForRow = false)
{
OleDbCommand cmd = new OleDbCommand(q, connection);
object o = cmd.ExecuteScalar();
- if (o == null) return "";
- else return o.ToString();
+ if (o == null) // it's null if the row does not exist, it'd be DBNull.Value if NULL was the value in existing row
+ {
+ if (!checkForRow)
+ {
+ return "";
+ }
+ throw new OleDbRowMissingException();
+ }
+ return o.ToString();
}
public data select(string q)
{
diff --git a/Aktywator/TeamyTournament.cs b/Aktywator/TeamyTournament.cs
new file mode 100644
index 0000000..7bc3496
--- /dev/null
+++ b/Aktywator/TeamyTournament.cs
@@ -0,0 +1,47 @@
+using System;
+using System.Collections.Generic;
+using System.Text;
+using MySql.Data.MySqlClient;
+
+namespace Aktywator
+{
+ class TeamyTournament : MySQLTournament
+ {
+ public TeamyTournament(string name)
+ : base(name)
+ {
+ this._type = Tournament.TYPE_TEAMY;
+ }
+
+ override internal string getTypeLabel()
+ {
+ return "Teamy";
+ }
+
+ override public string getSectionsNum()
+ {
+ return "1";
+ }
+
+ override public string getTablesNum()
+ {
+ return this.mysql.selectOne("SELECT teamcnt FROM admin;");
+ }
+
+ override internal Dictionary<int, List<string>> getNameList()
+ {
+ Dictionary<int, List<String>> teams = new Dictionary<int, List<string>>();
+ MySqlDataReader dbData = this.mysql.select("SELECT id, fullname NAME FROM teams");
+ while (dbData.Read())
+ {
+ List<string> names = new List<string>();
+ names.Add(dbData.IsDBNull(1) ? "" : dbData.GetString(1));
+ names.Add("");
+ teams.Add(dbData.GetInt32(0), names);
+ }
+ dbData.Close();
+ return teams;
+ }
+
+ }
+}
diff --git a/Aktywator/Tournament.cs b/Aktywator/Tournament.cs
index b46740b..85a2666 100644
--- a/Aktywator/Tournament.cs
+++ b/Aktywator/Tournament.cs
@@ -1,81 +1,41 @@
using System;
using System.Collections.Generic;
using System.Text;
-using MySql.Data.MySqlClient;
-using data = MySql.Data.MySqlClient.MySqlDataReader;
namespace Aktywator
{
- public class Tournament
+ abstract public class Tournament
{
- private string _name;
+ public const int TYPE_PARY = 1;
+ public const int TYPE_TEAMY = 2;
+ public const int TYPE_RRB = 3;
+ public const int TYPE_UNKNOWN = 0;
+
+ protected string _name;
public string name
{
get { return _name; }
}
- private int _type; // 0-unknown, 1-Pary, 2-Teamy
+ protected int _type = Tournament.TYPE_UNKNOWN; // 0-unknown, 1-Pary, 2-Teamy, 3-RRB
public int type
{
get { return _type; }
}
- public MySQL mysql;
-
- public Tournament(string name)
- {
- this._name = name;
- mysql = new MySQL(name);
- recognizeType();
- }
+ abstract internal void setup();
- 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 = 1;
- 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;
- }
+ abstract internal string getName();
- public override string ToString()
- {
- return this.name + " [" + (this.type == 1 ? 'P' : 'T') + "]";
- }
+ abstract public string getSectionsNum();
- public static List<Tournament> getTournaments()
- {
- List<Tournament> list = new List<Tournament>();
- MySQL c = new MySQL("");
- data dbs = c.select("SHOW DATABASES;");
- while (dbs.Read())
- {
- Tournament t = new Tournament(dbs.GetString(0));
- if (t.type > 0)
- list.Add(t);
- t.mysql.close();
- }
- return list;
- }
+ abstract public string getTablesNum();
- public string getSectionsNum()
- {
- if (type == 1)
- return mysql.selectOne("SELECT COUNT(DISTINCT seknum) FROM sektory;");
- else
- return "1";
- }
+ abstract internal string getTypeLabel();
- public string getTablesNum()
+ virtual internal Dictionary<int, List<string>> getNameList()
{
- if (type == 1)
- return mysql.selectOne("SELECT COUNT(*) FROM sektory;");
- else
- return mysql.selectOne("SELECT teamcnt FROM admin;");
+ return new Dictionary<int, List<string>>();
}
}