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
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
|
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.OleDb;
namespace Aktywator
{
public partial class MainForm : Form
{
public string version = "1.0.4";
public string date = "12.04.2013";
private Bws bws;
private Tournament tournament;
public MainForm()
{
InitializeComponent();
}
private void MainForm_Load(object sender, EventArgs e)
{
if (MySQL.getPass() == "") (new MysqlSettings()).ShowDialog();
}
private void MainForm_Shown(object sender, EventArgs e)
{
status2.Text = "Wersja " + this.version;
status3.Text = "Data: " + this.date;
string filename;
string[] args = Environment.GetCommandLineArgs();
if (args.Length > 1)
filename = args[1];
else if (open.ShowDialog() == DialogResult.OK)
filename = open.FileName;
else
{
Close();
return;
}
bws = new Bws(filename, this);
if (!bws.isBm2())
if (MessageBox.Show("Ten BWS nie jest przygotowany dla BM2. Przekonwertować?", "Konwersja do BM2",
MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
bws.convert();
labelFilename.Text = filename;
bws.initSettings();
bws.loadSettings();
this.WindowState = FormWindowState.Normal;
}
private void bLaunch_Click(object sender, EventArgs e)
{
if (trySave())
{
int max = 0;
int.TryParse(bws.sql.selectOne("SELECT max(ID) FROM Clients;"), out max);
try
{
bws.sql.query("INSERT INTO Clients (ID,Computer) VALUES (" + (max + 1) + ",'" + Environment.MachineName + "');");
}
catch (OleDbException)
{
}
string id = bws.sql.selectOne("SELECT ID FROM Clients WHERE Computer='" + Environment.MachineName + "';");
if (id.Length == 0) id = "0";
bws.sql.query("UPDATE Tables SET ComputerID=" + id);
try
{
bws.runBCS();
}
catch (Exception)
{
MessageBox.Show("Nie znalazłem BCS (BMPro) :(", "Nie znaleziono BCS", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
private void MainForm_FormClosed(object sender, FormClosedEventArgs e)
{
if (bws != null)
bws.sql.close();
}
private void konwertujuzupelnijBrakiToolStripMenuItem_Click(object sender, EventArgs e)
{
bws.convert();
MessageBox.Show("Zrobione! Ew. brakujące tabele i pola zostały dodane.", "Konwersja do BM2");
}
private void updateUstawieńWSerwerkuWTrakcieSesjiToolStripMenuItem_Click(object sender, EventArgs e)
{
if (trySave())
{
bws.updateSettings();
MessageBox.Show("Wykonano!", "Settings update", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}
private bool trySave()
{
bool blad = false;
if (xPINcode.Text.Length != 4) blad = true;
else
for (int i = 0; i < xPINcode.Text.Length; i++)
if ((xPINcode.Text[i] < '0') || (xPINcode.Text[i] > '9')) blad = true;
if (blad)
{
MessageBox.Show("PIN musi składać się z 4 cyfr.", "Błędny PIN", MessageBoxButtons.OK, MessageBoxIcon.Stop);
xPINcode.Focus();
return false;
}
else
{
bws.saveSettings();
return true;
}
}
private void bSave_Click(object sender, EventArgs e)
{
trySave();
}
private void bLoad_Click(object sender, EventArgs e)
{
bws.loadSettings();
}
private void xShowResults_CheckedChanged(object sender, EventArgs e)
{
if (xShowResults.Checked)
{
xRepeatResults.Enabled = true;
xShowPercentage.Enabled = true;
xResultsOverview.Enabled = true;
}
else
{
xRepeatResults.Enabled = false;
xShowPercentage.Enabled = false;
xResultsOverview.Enabled = false;
}
}
private void xMemberNumbers_CheckedChanged(object sender, EventArgs e)
{
if (xMemberNumbers.Checked)
{
xMemberNumbersNoBlankEntry.Enabled = true;
}
else
{
xMemberNumbersNoBlankEntry.Enabled = false;
}
}
private void bTournament_Click(object sender, EventArgs e)
{
try
{
ChooseTournament choose = new ChooseTournament();
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;
}
}
}
catch (Exception ee)
{
MessageBox.Show(ee.Message, "Błąd", MessageBoxButtons.OK, MessageBoxIcon.Stop);
}
}
private void bSync_Click(object sender, EventArgs e)
{
try
{
bws.syncNames(tournament, true, eOomRounds.Text);
}
catch (Exception ee)
{
MessageBox.Show(ee.Message, "Błąd", MessageBoxButtons.OK, MessageBoxIcon.Stop);
}
}
private void bMysqlSettings_Click(object sender, EventArgs e)
{
(new MysqlSettings()).ShowDialog();
}
private void bTruncate_Click(object sender, EventArgs e)
{
try
{
bws.sql.query("UPDATE PlayerNumbers SET Name='XXX' AND Updated=True WHERE 1=1");
MessageBox.Show("Wykonano!", "Usuń nazwiska", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
catch (Exception ee)
{
MessageBox.Show(ee.Message, "Błąd", MessageBoxButtons.OK, MessageBoxIcon.Stop);
}
}
private void bAutoSync_Click(object sender, EventArgs e)
{
if (!timer.Enabled)
{
int interval;
if ((!int.TryParse(eInterval.Text, out interval)) || (interval < 15))
{
eInterval.Focus();
return;
}
timer.Interval = interval * 1000;
eInterval.Enabled = false;
bAutoSync.Text = "pracuje się...";
bTournament.Enabled = false;
bMysqlSettings.Enabled = false;
timer.Enabled = true;
}
else
{
timer.Enabled = false;
bAutoSync.Text = "Synchronizuj cyklicznie";
eInterval.Enabled = true;
bTournament.Enabled = true;
bMysqlSettings.Enabled = true;
}
}
private void timer_Tick(object sender, EventArgs e)
{
bws.syncNames(tournament, false, eOomRounds.Text);
}
private void bForceSync_Click(object sender, EventArgs e)
{
bws.sql.query("UPDATE PlayerNumbers SET Updated=True");
MessageBox.Show("Wykonano!", "Force sync", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
private void bLoadHands_Click(object sender, EventArgs e)
{
if (openPBN.ShowDialog() != System.Windows.Forms.DialogResult.Cancel)
{
try
{
PBN pbn = new PBN(openPBN.FileName, bws.lowBoard(), bws.highBoard());
bws.loadHandRecords(pbn);
MessageBox.Show("Wczytanych rozkładów: " + pbn.count, "Rozkłady wczytane!", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Błąd wczytywania rozkładów", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
private void bClearHands_Click(object sender, EventArgs e)
{
try
{
bws.clearHandRecords();
MessageBox.Show("Wyczyszczono rozkłady", "Rozkłady wyczyszczone!", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Błąd czyszczenia rozkładów", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
}
|