From 77d5507bb68d431d59a78741839be999959efab4 Mon Sep 17 00:00:00 2001 From: emkael Date: Sun, 20 Nov 2016 01:16:39 +0100 Subject: * lowSection just like highSection, for now --- Aktywator/Bws.cs | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'Aktywator/Bws.cs') diff --git a/Aktywator/Bws.cs b/Aktywator/Bws.cs index 9533c7e..9c2df11 100644 --- a/Aktywator/Bws.cs +++ b/Aktywator/Bws.cs @@ -417,13 +417,21 @@ namespace Aktywator else return 0; } + public int lowSection() + { + string s = sql.selectOne("SELECT min(`Section`) FROM `Tables`"); + int i; + if (int.TryParse(s, out i)) return i; + else return 0; + } + public void loadHandRecords(PBN pbn) { sql.query("DELETE FROM HandRecord"); sql.query("DELETE FROM HandEvaluation"); for (int i = 0; i < pbn.handRecords.Length; i++) if (pbn.handRecords[i] != null) - for (int section = 1; section <= highSection(); section++) + for (int section = lowSection(); section <= highSection(); section++) { HandRecord b = pbn.handRecords[i]; StringBuilder str = new StringBuilder(50); -- cgit v1.2.3 From 425192e081de10a7efaee8d508f7dd336d97987a Mon Sep 17 00:00:00 2001 From: emkael Date: Sat, 26 Nov 2016 16:22:52 +0100 Subject: * refactoring various section list retrieving --- Aktywator/Bws.cs | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) (limited to 'Aktywator/Bws.cs') diff --git a/Aktywator/Bws.cs b/Aktywator/Bws.cs index 9c2df11..4822f43 100644 --- a/Aktywator/Bws.cs +++ b/Aktywator/Bws.cs @@ -59,12 +59,12 @@ namespace Aktywator settings.Add(new Setting("BM2ValidateLeadCard", main.xCheckLeadCard, this)); } - public string sectionsForHandRecords() + private string getSectionList(string table) { try { string s; - data d = sql.select("SELECT DISTINCT `Section` FROM HandRecord ORDER BY 1"); + data d = sql.select("SELECT DISTINCT `Section` FROM " + table + " ORDER BY 1"); d.Read(); s = d[0].ToString(); while (d.Read()) @@ -79,6 +79,17 @@ namespace Aktywator } } + public string getSections() + { + return this.getSectionList("RoundData"); + } + + + public string sectionsForHandRecords() + { + return this.getSectionList("HandRecord"); + } + public void runBCS() { string app = Common.ProgramFilesx86() + "\\Bridgemate Pro\\BMPro.exe"; -- cgit v1.2.3 From 665e91d1a86047d726aebc7cf14c2441a36b484e Mon Sep 17 00:00:00 2001 From: emkael Date: Sat, 26 Nov 2016 16:24:19 +0100 Subject: * refactoring lowBoard/highBoard methods, also allowing to specify section(s) --- Aktywator/Bws.cs | 27 ++++++++++++++++++++------- 1 file changed, 20 insertions(+), 7 deletions(-) (limited to 'Aktywator/Bws.cs') diff --git a/Aktywator/Bws.cs b/Aktywator/Bws.cs index 4822f43..ba11b72 100644 --- a/Aktywator/Bws.cs +++ b/Aktywator/Bws.cs @@ -404,20 +404,33 @@ namespace Aktywator } } - public int lowBoard() + private int getBoard(string function, string sector) { - string s = sql.selectOne("SELECT min(lowBoard) FROM RoundData WHERE lowBoard > 0"); + sector = sector.Trim(); + StringBuilder query = new StringBuilder(); + query.Append("SELECT "); + query.Append(function); + query.Append(" FROM RoundData WHERE lowBoard > 0"); + if (sector.Length > 0) + { + query.Append(" AND `Section` IN("); + query.Append(sector); + query.Append(")"); + } + string s = sql.selectOne(query.ToString()); int i; if (int.TryParse(s, out i)) return i; else return 0; } - public int highBoard() + public int lowBoard(string sector = "") { - string s = sql.selectOne("SELECT max(highBoard) FROM RoundData WHERE highBoard > 0"); - int i; - if (int.TryParse(s, out i)) return i; - else return 0; + return this.getBoard("MIN(lowBoard)", sector); + } + + public int highBoard(string sector = "") + { + return this.getBoard("MAX(highBoard)", sector); } public int highSection() -- cgit v1.2.3 From 2f47067c7b0db33b6b5e9fe1c846c054b75256e2 Mon Sep 17 00:00:00 2001 From: emkael Date: Sat, 26 Nov 2016 16:26:16 +0100 Subject: * load only boards necessary for existing sections --- Aktywator/Bws.cs | 38 ++++++++++++++++++++++++++++++++++---- Aktywator/MainForm.Designer.cs | 2 +- 2 files changed, 35 insertions(+), 5 deletions(-) (limited to 'Aktywator/Bws.cs') diff --git a/Aktywator/Bws.cs b/Aktywator/Bws.cs index ba11b72..381e10f 100644 --- a/Aktywator/Bws.cs +++ b/Aktywator/Bws.cs @@ -27,7 +27,35 @@ namespace Aktywator this._filename = filename; sql = new Sql(filename); this.main = main; - main.lWczytywane.Text += this.lowBoard() + "-" + this.highBoard(); + main.lWczytywane.Text = this.getBoardRangeText(this.getSections().Split(',')); + } + + private int sectorLetterToNumber(string sector) + { + return sector[0] - 'A' + 1; + } + + private string sectorNumberToLetter(int sector) + { + char character = (char)('A' - 1 + sector); + return character.ToString(); + } + + private string getBoardRangeText(string[] sectors) + { + StringBuilder sb = new StringBuilder(); + sb.Append("Wczytywane rozkłady:"); + foreach (string sector in sectors) + { + sb.Append("\n "); + sb.Append(this.lowBoard(sector)); + sb.Append("-"); + sb.Append(this.highBoard(sector)); + sb.Append(" (sektor "); + sb.Append(this.sectorNumberToLetter(Int16.Parse(sector))); + sb.Append(")"); + } + return sb.ToString(); } public void initSettings() @@ -453,9 +481,10 @@ namespace Aktywator { sql.query("DELETE FROM HandRecord"); sql.query("DELETE FROM HandEvaluation"); - for (int i = 0; i < pbn.handRecords.Length; i++) - if (pbn.handRecords[i] != null) - for (int section = lowSection(); section <= highSection(); section++) + foreach (string section in this.getSections().Split(',')) + { + for (int i = this.lowBoard(section.Trim()); i <= this.highBoard(section.Trim()); i++) + if (pbn.handRecords[i] != null) { HandRecord b = pbn.handRecords[i]; StringBuilder str = new StringBuilder(50); @@ -506,6 +535,7 @@ namespace Aktywator sql.query(ddStr.ToString()); } } + } } } } diff --git a/Aktywator/MainForm.Designer.cs b/Aktywator/MainForm.Designer.cs index c28159e..2d31fe7 100644 --- a/Aktywator/MainForm.Designer.cs +++ b/Aktywator/MainForm.Designer.cs @@ -868,7 +868,7 @@ // this.lWczytywane.AutoSize = true; this.lWczytywane.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(238))); - this.lWczytywane.Location = new System.Drawing.Point(192, 99); + this.lWczytywane.Location = new System.Drawing.Point(218, 84); this.lWczytywane.Name = "lWczytywane"; this.lWczytywane.Size = new System.Drawing.Size(139, 13); this.lWczytywane.TabIndex = 3; -- cgit v1.2.3 From 9651a1a48d6343787e608b2c9daa70eb541fffdb Mon Sep 17 00:00:00 2001 From: emkael Date: Sat, 26 Nov 2016 17:33:24 +0100 Subject: * selected sections list initialization and value getter --- Aktywator/Bws.cs | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) (limited to 'Aktywator/Bws.cs') diff --git a/Aktywator/Bws.cs b/Aktywator/Bws.cs index 381e10f..3331ae0 100644 --- a/Aktywator/Bws.cs +++ b/Aktywator/Bws.cs @@ -27,7 +27,16 @@ namespace Aktywator this._filename = filename; sql = new Sql(filename); this.main = main; - main.lWczytywane.Text = this.getBoardRangeText(this.getSections().Split(',')); + string[] sections = this.getSections().Split(','); + main.lWczytywane.Text = this.getBoardRangeText(sections); + foreach (string section in sections) + { + main.cblSections.Items.Add(this.sectorNumberToLetter(Int16.Parse(section))); + } + for (int i = 0; i < main.cblSections.Items.Count; i++) + { + main.cblSections.SetItemChecked(i, true); + } } private int sectorLetterToNumber(string sector) @@ -58,6 +67,16 @@ namespace Aktywator return sb.ToString(); } + public string[] getSelectedSections() + { + List sections = new List(); + foreach (string section in main.cblSections.CheckedItems) + { + sections.Add(this.sectorLetterToNumber(section).ToString()); + } + return sections.ToArray(); + } + public void initSettings() { settings = new List(); -- cgit v1.2.3 From 8b1f024231571b16940aab83c1a131bf9a1eb5d5 Mon Sep 17 00:00:00 2001 From: emkael Date: Sat, 26 Nov 2016 17:39:59 +0100 Subject: * hand record clearing, per section --- Aktywator/Bws.cs | 21 +++++++++++++++++++-- Aktywator/MainForm.cs | 13 +++++++++++++ 2 files changed, 32 insertions(+), 2 deletions(-) (limited to 'Aktywator/Bws.cs') diff --git a/Aktywator/Bws.cs b/Aktywator/Bws.cs index 3331ae0..dee1112 100644 --- a/Aktywator/Bws.cs +++ b/Aktywator/Bws.cs @@ -496,12 +496,29 @@ namespace Aktywator else return 0; } + private void clearRecords(string section) + { + sql.query("DELETE FROM HandRecord WHERE `Section` = " + section); + sql.query("DELETE FROM HandEvaluation WHERE `Section` = " + section); + } + + public void clearHandRecords() + { + string sections = this.sectionsForHandRecords(); + if (sections != null) + { + foreach (string section in this.sectionsForHandRecords().Split(',')) + { + this.clearRecords(section.Trim()); + } + } + } + public void loadHandRecords(PBN pbn) { - sql.query("DELETE FROM HandRecord"); - sql.query("DELETE FROM HandEvaluation"); foreach (string section in this.getSections().Split(',')) { + this.clearRecords(section); for (int i = this.lowBoard(section.Trim()); i <= this.highBoard(section.Trim()); i++) if (pbn.handRecords[i] != null) { diff --git a/Aktywator/MainForm.cs b/Aktywator/MainForm.cs index f684e34..aa3a447 100644 --- a/Aktywator/MainForm.cs +++ b/Aktywator/MainForm.cs @@ -287,5 +287,18 @@ namespace Aktywator } } + 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); + } + } + } } -- cgit v1.2.3 From 792069c65af52df86286d9596c2e7eab340d18ff Mon Sep 17 00:00:00 2001 From: emkael Date: Sat, 26 Nov 2016 17:40:45 +0100 Subject: * updating label for boards to read on section selection --- Aktywator/Bws.cs | 2 +- Aktywator/MainForm.cs | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) (limited to 'Aktywator/Bws.cs') diff --git a/Aktywator/Bws.cs b/Aktywator/Bws.cs index dee1112..606de96 100644 --- a/Aktywator/Bws.cs +++ b/Aktywator/Bws.cs @@ -50,7 +50,7 @@ namespace Aktywator return character.ToString(); } - private string getBoardRangeText(string[] sectors) + public string getBoardRangeText(string[] sectors) { StringBuilder sb = new StringBuilder(); sb.Append("Wczytywane rozkłady:"); diff --git a/Aktywator/MainForm.cs b/Aktywator/MainForm.cs index aa3a447..1326777 100644 --- a/Aktywator/MainForm.cs +++ b/Aktywator/MainForm.cs @@ -287,6 +287,11 @@ namespace Aktywator } } + private void cblSections_SelectedIndexChanged(object sender, EventArgs e) + { + this.lWczytywane.Text = bws.getBoardRangeText(bws.getSelectedSections()); + } + private void bClearHands_Click(object sender, EventArgs e) { try -- cgit v1.2.3 From 5738d7e27fa1da52cbe50a2e26a0bd3a7749335e Mon Sep 17 00:00:00 2001 From: emkael Date: Sat, 26 Nov 2016 17:41:19 +0100 Subject: * reading boards only for selected sections (and accummulating count) --- Aktywator/Bws.cs | 7 +++++-- Aktywator/MainForm.cs | 4 ++-- 2 files changed, 7 insertions(+), 4 deletions(-) (limited to 'Aktywator/Bws.cs') diff --git a/Aktywator/Bws.cs b/Aktywator/Bws.cs index 606de96..335bc11 100644 --- a/Aktywator/Bws.cs +++ b/Aktywator/Bws.cs @@ -514,9 +514,10 @@ namespace Aktywator } } - public void loadHandRecords(PBN pbn) + public int loadHandRecords(PBN pbn) { - foreach (string section in this.getSections().Split(',')) + int count = 0; + foreach (string section in this.getSelectedSections()) { this.clearRecords(section); for (int i = this.lowBoard(section.Trim()); i <= this.highBoard(section.Trim()); i++) @@ -570,8 +571,10 @@ namespace Aktywator ddStr.Append(")"); sql.query(ddStr.ToString()); } + count++; } } + return count; } } } diff --git a/Aktywator/MainForm.cs b/Aktywator/MainForm.cs index 1326777..8979d6b 100644 --- a/Aktywator/MainForm.cs +++ b/Aktywator/MainForm.cs @@ -277,8 +277,8 @@ namespace Aktywator 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); + int count = bws.loadHandRecords(pbn); + MessageBox.Show("Wczytanych rozkładów: " + count, "Rozkłady wczytane!", MessageBoxButtons.OK, MessageBoxIcon.Information); } catch (Exception ex) { -- cgit v1.2.3