summaryrefslogtreecommitdiff
path: root/Aktywator/Tournament.cs
diff options
context:
space:
mode:
authorMichał Zimniewicz <michzimny@users.noreply.github.com>2017-12-06 23:57:31 +0100
committerGitHub <noreply@github.com>2017-12-06 23:57:31 +0100
commit80cd31c1c8e7cef2cfbf6148df3d9ec2d2a23279 (patch)
tree4071e574a3e611cf4d8a19e231ff7ecc659949fa /Aktywator/Tournament.cs
parent83e064ccb67f0b68b1f947026301cd3905d06a3c (diff)
parentf12d2b996b165d66f4c32eef4a3bdfb89309670d (diff)
Merge pull request #29 from michzimny/1.1-beta
Scalenie gałęzi beta do master
Diffstat (limited to 'Aktywator/Tournament.cs')
-rw-r--r--Aktywator/Tournament.cs160
1 files changed, 119 insertions, 41 deletions
diff --git a/Aktywator/Tournament.cs b/Aktywator/Tournament.cs
index b46740b..117b1da 100644
--- a/Aktywator/Tournament.cs
+++ b/Aktywator/Tournament.cs
@@ -1,82 +1,160 @@
using System;
using System.Collections.Generic;
using System.Text;
-using MySql.Data.MySqlClient;
-using data = MySql.Data.MySqlClient.MySqlDataReader;
+using System.Windows.Forms;
+using System.Drawing;
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;
+ abstract internal void setup();
+
+ abstract internal string getName();
+
+ abstract public string getSectionsNum();
- public Tournament(string name)
+ abstract public string getTablesNum();
+
+ abstract internal string getTypeLabel();
+
+ virtual internal Dictionary<int, List<string>> getNameList()
{
- this._name = name;
- mysql = new MySQL(name);
- recognizeType();
+ return new Dictionary<int, List<string>>();
}
- private void recognizeType()
+ virtual public void displayNameList(DataGridView grid)
{
- 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;
+ Dictionary<int, List<string>> names = this.getNameList();
+ foreach (KeyValuePair<int, List<string>> item in names) {
+ if (!this.updateNameListRow(grid, item.Key, item.Value))
+ {
+ this.addNameListRow(grid, item.Key, item.Value);
+ }
+ }
+ List<DataGridViewRow> toDelete = new List<DataGridViewRow>();
+ foreach (DataGridViewRow row in grid.Rows)
+ {
+ if (!names.ContainsKey(Int32.Parse(row.Cells[0].Value.ToString())))
+ {
+ toDelete.Add(row);
+ }
+ }
+ foreach (DataGridViewRow r in toDelete)
+ {
+ grid.Rows.Remove(r);
+ }
+ grid.Update();
+ grid.Refresh();
}
- public override string ToString()
+ virtual internal bool updateNameListRow(DataGridView grid, int pairNumber, List<string> names)
{
- return this.name + " [" + (this.type == 1 ? 'P' : 'T') + "]";
+ foreach (DataGridViewRow row in grid.Rows)
+ {
+ if (Int32.Parse(row.Cells[0].Value.ToString()) == pairNumber)
+ {
+ for (int i = 1; i < 3; i++)
+ {
+ if (!(bool)row.Cells[i].Tag)
+ {
+ row.Cells[i].Value = names[i - 1];
+ row.Cells[i].Tag = false;
+ row.Cells[i].Style.BackColor = Color.White;
+ }
+ }
+ return true;
+ }
+ }
+ return false;
}
- public static List<Tournament> getTournaments()
+ virtual internal void addNameListRow(DataGridView grid, int pairNumber, List<string> names)
{
- List<Tournament> list = new List<Tournament>();
- MySQL c = new MySQL("");
- data dbs = c.select("SHOW DATABASES;");
- while (dbs.Read())
+ DataGridViewRow row = new DataGridViewRow();
+ row.Cells.Add(new DataGridViewTextBoxCell());
+ row.Cells[0].Value = pairNumber.ToString();
+ foreach (string name in names)
{
- Tournament t = new Tournament(dbs.GetString(0));
- if (t.type > 0)
- list.Add(t);
- t.mysql.close();
+ DataGridViewTextBoxCell cell = new DataGridViewTextBoxCell();
+ cell.Value = name;
+ cell.Tag = false;
+ row.Cells.Add(cell);
}
- return list;
+ grid.Rows.Add(row);
+ grid.FirstDisplayedScrollingRowIndex = grid.RowCount - 1;
}
- public string getSectionsNum()
+ virtual internal void clearCellLocks(DataGridView grid)
{
- if (type == 1)
- return mysql.selectOne("SELECT COUNT(DISTINCT seknum) FROM sektory;");
- else
- return "1";
+ foreach (DataGridViewRow row in grid.Rows)
+ {
+ for (int i = 1; i < 3; i++)
+ {
+ row.Cells[i].Tag = false;
+ row.Cells[i].Style.BackColor = Color.White;
+ }
+ }
}
- public string getTablesNum()
+ virtual internal string shortenNameToBWS(string name)
{
- if (type == 1)
- return mysql.selectOne("SELECT COUNT(*) FROM sektory;");
+ name = Common.bezOgonkow(name);
+ if ("pauza".Equals(name.Trim()))
+ {
+ return " ";
+ }
else
- return mysql.selectOne("SELECT teamcnt FROM admin;");
+ {
+ if (this._type != Tournament.TYPE_TEAMY || MainForm.teamNames.arePlayerNamesDisplayed())
+ {
+ string[] nameParts = name.Trim().Split(' ');
+ if (nameParts.Length > 0)
+ {
+ nameParts[0] = (nameParts[0].Length > 0) ? nameParts[0][0].ToString() : " ";
+ }
+ name = String.Join(" ", nameParts);
+ }
+ if (name.Length > 18)
+ {
+ name = name.Substring(0, 18);
+ }
+ return name;
+ }
}
+ virtual public Dictionary<int, List<string>> getBWSNames(DataGridView grid)
+ {
+ Dictionary<int, List<string>> dict = new Dictionary<int, List<string>>();
+ foreach (DataGridViewRow row in grid.Rows)
+ {
+ List<string> names = new List<string>();
+ for (int i = 1; i < 3; i++)
+ {
+ names.Add(this.shortenNameToBWS(row.Cells[i].Value.ToString()));
+ }
+ dict.Add(Int32.Parse(row.Cells[0].Value.ToString()), names);
+ }
+ return dict;
+ }
+
+
}
}