summaryrefslogtreecommitdiff
path: root/Aktywator
diff options
context:
space:
mode:
authoremkael <emkael@tlen.pl>2018-10-24 14:55:33 +0200
committeremkael <emkael@tlen.pl>2018-10-24 14:55:33 +0200
commitfe71701968627f6ee3e1066dbb1ee6d2ab08afcc (patch)
tree8daa40c814437b89fa56adc25858234f61c9a4bf /Aktywator
parent6aedfb8b024edba840c792050403c05209896703 (diff)
Grouping tables in sections extended to support teams IMP results
Diffstat (limited to 'Aktywator')
-rw-r--r--Aktywator/Bws.cs9
-rw-r--r--Aktywator/Setting.cs41
2 files changed, 43 insertions, 7 deletions
diff --git a/Aktywator/Bws.cs b/Aktywator/Bws.cs
index 4c4586e..e89996f 100644
--- a/Aktywator/Bws.cs
+++ b/Aktywator/Bws.cs
@@ -126,7 +126,7 @@ namespace Aktywator
MessageBox.Show(MainForm.differentRecordsInSections, "Ustawienia grupowania zapisów w sektorach", MessageBoxButtons.OK, MessageBoxIcon.Warning);
main.xGroupSections.Checked = false;
}
- Setting.saveSectionGroups(this.sql, main.xGroupSections.Checked);
+ Setting.saveSectionGroups(this.sql, main.xGroupSections.Checked, (this.getMySQLDatabaseForSection() != null) ? Convert.ToInt32(main.numTeamsTableOffset.Value) : 0);
}
main.checkRecordsForSectionGroups();
}
@@ -583,7 +583,7 @@ namespace Aktywator
Setting.save("BM2NameSource", "2", this, errors, section);
Setting.save("BM2PINcode", "'" + main.xPINcode.Text + "'", this, errors, section);
Setting.save("BM2ResultsOverview", main.xResultsOverview.SelectedIndex.ToString(), this, errors, section);
- Setting.saveSectionGroups(this.sql, main.xGroupSections.Checked);
+ Setting.saveSectionGroups(this.sql, main.xGroupSections.Checked, (this.getMySQLDatabaseForSection() != null) ? Convert.ToInt32(main.numTeamsTableOffset.Value) : 0);
this.loadSettings();
}
@@ -614,6 +614,11 @@ namespace Aktywator
private int getBWSNumber(OleDbDataReader reader, int index)
{
+ return Bws.bwsNumber(reader, index);
+ }
+
+ public static int bwsNumber(OleDbDataReader reader, int index)
+ {
switch (Type.GetTypeCode(reader.GetFieldType(index)))
{
case TypeCode.Int16:
diff --git a/Aktywator/Setting.cs b/Aktywator/Setting.cs
index bde6fd1..802e92a 100644
--- a/Aktywator/Setting.cs
+++ b/Aktywator/Setting.cs
@@ -171,12 +171,43 @@ namespace Aktywator
}
}
- public static void saveSectionGroups(Sql sql, bool value)
+ public static void saveSectionGroups(Sql sql, bool value, int teamTableOffset = 0)
{
- StringBuilder sb = new StringBuilder("UPDATE Tables SET `Group` = ");
- sb.Append(value ? "1" : "`Section`");
- sb.Append(";");
- sql.query(sb.ToString());
+ if (teamTableOffset == 0)
+ {
+ StringBuilder sb = new StringBuilder("UPDATE Tables SET `Group` = ");
+ sb.Append(value ? "1" : "`Section`");
+ sb.Append(";");
+ sql.query(sb.ToString());
+ }
+ else
+ {
+ int group = 1;
+ StringBuilder tablesQuery = new StringBuilder("SELECT `Section`, (`Table` MOD ");
+ tablesQuery.Append(teamTableOffset);
+ tablesQuery.Append(") FROM `Tables` GROUP BY `Section`, (`Table` MOD ");
+ tablesQuery.Append(teamTableOffset);
+ tablesQuery.Append(");");
+ OleDbDataReader tables = sql.select(tablesQuery.ToString());
+ List<string> queries = new List<string>();
+ while (tables.Read())
+ {
+ StringBuilder sb = new StringBuilder("UPDATE `Tables` SET `Group` = ");
+ sb.Append(group++);
+ sb.Append(" WHERE `Section` = ");
+ sb.Append(Bws.bwsNumber(tables, 0));
+ sb.Append(" AND (`Table` MOD ");
+ sb.Append(teamTableOffset);
+ sb.Append(") = ");
+ sb.Append(Bws.bwsNumber(tables, 1));
+ sb.Append(";");
+ queries.Add(sb.ToString());
+ }
+ foreach (string query in queries)
+ {
+ sql.query(query);
+ }
+ }
}
}
}