diff options
| author | MichaĆ Zimniewicz <michzimny@users.noreply.github.com> | 2019-02-20 18:41:06 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2019-02-20 18:41:06 +0100 |
| commit | c87e5eebb4d54a1b63439e7cf150486d9230274e (patch) | |
| tree | 257c28f02c4acfd8f02b082953604aaf326d127f /Aktywator/Setting.cs | |
| parent | cbf1e8ff15377e0bf4b9ddee0a868e4ab85a6cc0 (diff) | |
| parent | e010784a72017a46239504308c88a7199c65ff72 (diff) | |
Merge pull request #53 from emkael/master
v1.1.5
Diffstat (limited to 'Aktywator/Setting.cs')
| -rw-r--r-- | Aktywator/Setting.cs | 59 |
1 files changed, 53 insertions, 6 deletions
diff --git a/Aktywator/Setting.cs b/Aktywator/Setting.cs index bde6fd1..657c822 100644 --- a/Aktywator/Setting.cs +++ b/Aktywator/Setting.cs @@ -42,15 +42,18 @@ namespace Aktywator field.Checked = a.ToUpper() == "TRUE" ? true : false; } - public static string load(string name, Bws bws, StringBuilder errors, string section = null) + public static string load(string name, Bws bws, StringBuilder errors, string section = null, string table = "Settings", string sectionField = "`Section`") { StringBuilder str = new StringBuilder(); str.Append("SELECT "); str.Append(name); - str.Append(" FROM Settings"); + str.Append(" FROM "); + str.Append(table); if (section != null) { - str.Append(" WHERE `Section` = "); + str.Append(" WHERE "); + str.Append(sectionField); + str.Append(" = "); str.Append(section); } try @@ -171,12 +174,56 @@ namespace Aktywator } } - public static void saveSectionGroups(Sql sql, bool value) + public static void saveScoringType(Sql sql, int value, string section) { - StringBuilder sb = new StringBuilder("UPDATE Tables SET `Group` = "); - sb.Append(value ? "1" : "`Section`"); + StringBuilder sb = new StringBuilder("UPDATE `Section` SET `ScoringType` = "); + sb.Append(value); + if (section != null) + { + sb.Append(" WHERE `ID` = "); + sb.Append(section); + } sb.Append(";"); sql.query(sb.ToString()); } + + public static void saveSectionGroups(Sql sql, bool value, int teamTableOffset = 0) + { + 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); + } + } + } } } |
