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
|
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace Aktywator
{
public partial class TeamNamesSettings : Form
{
public TeamNamesSettings()
{
InitializeComponent();
}
private MainForm form;
private TeamyTournament tournament;
public const int OpenClosedDiff = 1000;
internal void initTournament(TeamyTournament tournament, MainForm form)
{
this.form = form;
this.tournament = tournament;
lTournamentName.Text = this.tournament.getName();
int rounds = this.tournament.getRoundsNum();
int segments = this.tournament.getSegmentsNum();
cbRounds.Items.Clear();
for (int i = 1; i <= rounds; i++)
{
cbRounds.Items.Add(i.ToString());
}
cbSegments.Items.Clear();
for (int i = 1; i <= segments; i++)
{
cbSegments.Items.Add(i.ToString());
}
List<int> currentSegment = this.tournament.getCurrentSegment();
cbRounds.SelectedIndex = currentSegment[0] - 1;
cbSegments.SelectedIndex = currentSegment[1] - 1;
cbSecondRow.SelectedIndex = 0;
}
public string getLabel()
{
StringBuilder ret = new StringBuilder();
ret.Append(cbRounds.SelectedItem);
ret.Append('-');
ret.Append(cbSegments.SelectedItem);
ret.Append(", ");
if (rbShowTeamNames.Checked)
{
ret.Append("teamy");
if (cbSecondRow.SelectedIndex == 1)
{
ret.Append(" + IMP");
}
if (cbSecondRow.SelectedIndex == 2)
{
ret.Append(" + VP/IMP");
}
}
else
{
ret.Append("lineup");
}
return ret.ToString();
}
public bool arePlayerNamesDisplayed()
{
return rbShowPlayerNames.Checked;
}
public string getQuery()
{
StringBuilder ret = new StringBuilder();
ret.Append("SELECT teams.id, ");
if (rbShowTeamNames.Checked)
{
ret.Append("shortname, ");
switch (cbSecondRow.SelectedIndex) {
case 0:
ret.Append("' ' FROM teams ORDER BY teams.id");
break;
case 1:
ret.Append("CONCAT(");
ret.Append("SUM(IF(segments.homet = teams.id, segments.impH+segments.corrH, segments.impV+segments.corrV))");
ret.Append(" + IF(matches.homet = teams.id AND matches.carry > 0, matches.carry, 0)");
ret.Append("+ IF(matches.visit = teams.id AND matches.carry < 0, -matches.carry, 0),");
ret.Append("' IMP')");
ret.Append("FROM teams LEFT JOIN segments ON (teams.id = segments.homet OR teams.id = segments.visit) AND segments.rnd = ");
ret.Append(cbRounds.SelectedItem);
ret.Append(" AND segments.segment < ");
ret.Append(cbSegments.SelectedItem);
ret.Append(" LEFT JOIN matches ON (teams.id = matches.homet OR teams.id = matches.visit) AND matches.rnd = ");
ret.Append(cbRounds.SelectedItem);
ret.Append(" GROUP BY teams.id ORDER BY teams.id");
break;
case 2:
ret.Append("CONCAT(SUM(IF(matches.homet = teams.id, vph+corrh, vpv+corrv)) + teams.score, ' ");
ret.Append(this.tournament.getPointsUnit());
ret.Append("') FROM teams LEFT JOIN matches ON (teams.id = matches.homet OR teams.id = matches.visit) AND matches.rnd < ");
ret.Append(cbRounds.SelectedItem);
ret.Append(" GROUP BY teams.id ORDER BY teams.id");
break;
}
}
else
{
ret.Append("CONCAT(p1.gname, ' ', p1.sname), CONCAT(p2.gname, ' ', p2.sname) FROM teams JOIN segments ON segments.rnd = ");
ret.Append(cbRounds.SelectedItem);
ret.Append(" AND segments.segment = ");
ret.Append(cbSegments.SelectedItem);
ret.Append(" AND teams.id = segments.homet LEFT JOIN players p1 ON p1.id = segments.openN LEFT JOIN players p2 ON p2.id = segments.openS");
ret.Append(" UNION SELECT teams.id, CONCAT(p1.gname, ' ', p1.sname), CONCAT(p2.gname, ' ', p2.sname) FROM teams JOIN segments ON segments.rnd = ");
ret.Append(cbRounds.SelectedItem);
ret.Append(" AND segments.segment = ");
ret.Append(cbSegments.SelectedItem);
ret.Append(" AND teams.id = segments.visit LEFT JOIN players p1 ON p1.id = segments.openE LEFT JOIN players p2 ON p2.id = segments.openW");
ret.Append(" UNION SELECT teams.id + ");
ret.Append(TeamNamesSettings.OpenClosedDiff);
ret.Append(", CONCAT(p1.gname, ' ', p1.sname), CONCAT(p2.gname, ' ', p2.sname) FROM teams JOIN segments ON segments.rnd = ");
ret.Append(cbRounds.SelectedItem);
ret.Append(" AND segments.segment = ");
ret.Append(cbSegments.SelectedItem);
ret.Append(" AND teams.id = segments.homet LEFT JOIN players p1 ON p1.id = segments.closeE LEFT JOIN players p2 ON p2.id = segments.closeW");
ret.Append(" UNION SELECT teams.id + ");
ret.Append(TeamNamesSettings.OpenClosedDiff);
ret.Append(", CONCAT(p1.gname, ' ', p1.sname), CONCAT(p2.gname, ' ', p2.sname) FROM teams JOIN segments ON segments.rnd = ");
ret.Append(cbRounds.SelectedItem);
ret.Append(" AND segments.segment = ");
ret.Append(cbSegments.SelectedItem);
ret.Append(" AND teams.id = segments.visit LEFT JOIN players p1 ON p1.id = segments.closeN LEFT JOIN players p2 ON p2.id = segments.closeS");
ret.Append(" ORDER BY id");
}
return ret.ToString();
}
private void rbShowPlayerNames_CheckedChanged(object sender, EventArgs e)
{
cbSecondRow.Enabled = !rbShowPlayerNames.Checked;
}
private void bClose_Click(object sender, EventArgs e)
{
this.Close();
}
private void TeamNamesSettings_FormClosed(object sender, FormClosedEventArgs e)
{
this.form.bTeamsNamesSettings.Text = this.getLabel();
this.form.namesTimer_Tick(null, null);
this.form.namesTimer.Enabled = true;
}
private void TeamNamesSettings_Shown(object sender, EventArgs e)
{
this.form.namesTimer.Enabled = false;
}
}
}
|