1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
|
using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;
using System.Drawing;
namespace Aktywator
{
abstract public class Tournament
{
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; }
}
protected int _type = Tournament.TYPE_UNKNOWN; // 0-unknown, 1-Pary, 2-Teamy, 3-RRB
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();
virtual internal Dictionary<int, List<string>> getNameList()
{
return new Dictionary<int, List<string>>();
}
virtual public void displayNameList(DataGridView grid)
{
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);
}
}
virtual internal bool updateNameListRow(DataGridView grid, int pairNumber, List<string> names)
{
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;
}
virtual internal void addNameListRow(DataGridView grid, int pairNumber, List<string> names)
{
DataGridViewRow row = new DataGridViewRow();
row.Cells.Add(new DataGridViewTextBoxCell());
row.Cells[0].Value = pairNumber.ToString();
foreach (string name in names)
{
DataGridViewTextBoxCell cell = new DataGridViewTextBoxCell();
cell.Value = name;
cell.Tag = false;
row.Cells.Add(cell);
}
grid.Rows.Add(row);
}
virtual internal void clearCellLocks(DataGridView grid)
{
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;
}
}
}
virtual internal string shortenNameToBWS(string name)
{
name = Common.bezOgonkow(name);
if (name.Length > 18)
{
name = name.Substring(0, 18);
}
if ("pauza".Equals(name.Trim()))
{
return " ";
}
else
{
if (this._type != Tournament.TYPE_TEAMY)
{
string[] nameParts = name.Trim().Split(' ');
if (nameParts.Length > 0)
{
nameParts[0] = (nameParts[0].Length > 0) ? nameParts[0][0].ToString() : " ";
}
return String.Join(" ", nameParts);
}
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;
}
}
}
|