From fba8c52dfb4f66a9fd88f254d55bf0adf5d90b9d Mon Sep 17 00:00:00 2001 From: Milan Hanajik Date: Sun, 2 Apr 2023 12:04:23 +0200 Subject: [PATCH] 1. TestWizard.FlowSelection fixed: float avoided, 2. Rounding of test flows after conversion, ver. 2.33.2034 --- TBF/Properties/AssemblyInfo.cs | 4 +-- TBF/UI/Procedures/TestWizard/FlowSelection.cs | 28 +++++++-------- TBF/UI/Settings/UpgradeSelectionDlg.cs | 36 +++++++++++++++++++ 3 files changed, 52 insertions(+), 16 deletions(-) diff --git a/TBF/Properties/AssemblyInfo.cs b/TBF/Properties/AssemblyInfo.cs index 89e221d24..e30cbc24a 100644 --- a/TBF/Properties/AssemblyInfo.cs +++ b/TBF/Properties/AssemblyInfo.cs @@ -29,5 +29,5 @@ using System.Runtime.InteropServices; // Build Number // Revision // -[assembly: AssemblyVersion("2.33.2033.0")] -[assembly: AssemblyFileVersion("2.33.2033.0")] +[assembly: AssemblyVersion("2.33.2034.0")] +[assembly: AssemblyFileVersion("2.33.2034.0")] diff --git a/TBF/UI/Procedures/TestWizard/FlowSelection.cs b/TBF/UI/Procedures/TestWizard/FlowSelection.cs index dab000ab7..694659bd9 100644 --- a/TBF/UI/Procedures/TestWizard/FlowSelection.cs +++ b/TBF/UI/Procedures/TestWizard/FlowSelection.cs @@ -101,20 +101,20 @@ namespace TBF.UI.Procedures.TestWizard case QSpec.Q_dQ: var Q = Units.ConvertFrom(flowUnit, Utils.ParseUDouble(q2TextBox.Text)); var dQ = Units.ConvertFrom(flowUnit, Utils.ParseUDouble(dQTextBox.Text)); - qFrom = (Q - dQ); - qTo = (Q + dQ); + qFrom = Q - dQ; + qTo = Q + dQ; break; case QSpec.Q_dPct: var Q2 = Units.ConvertFrom(flowUnit, Utils.ParseUDouble(q3TextBox.Text)); var dQpct = Utils.ParseUDouble(dQpctTextBox.Text); - qFrom = (float)(Q2 * (1 - dQpct / 100.0)); - qTo = (float)(Q2 * (1 + dQpct / 100.0)); + qFrom = Q2 * (1 - dQpct / 100.0); + qTo = Q2 * (1 + dQpct / 100.0); break; } - test.Qfrom = (float)qFrom; - test.Qto = (float)qTo; + test.Qfrom = qFrom; + test.Qto = qTo; test.FlowUnit = flowUnit; if (sensorsComboBox.Items.Contains(sensorsComboBox.Text)) @@ -125,25 +125,25 @@ namespace TBF.UI.Procedures.TestWizard bool IsFormValid() { - float dummy; + double dummy; switch (qSpec) { default: case QSpec.Qfrom_Qto: - return Utils.TryParseUFloat(qFromTextBox.Text, out dummy) && - Utils.TryParseUFloat(qToTextBox.Text, out dummy) && + return Utils.TryParseUDouble(qFromTextBox.Text, out dummy) && + Utils.TryParseUDouble(qToTextBox.Text, out dummy) && selectorComboBox.Items.Contains(selectorComboBox.Text) && sensorsComboBox.Items.Contains(sensorsComboBox.Text); case QSpec.Q_dQ: - return Utils.TryParseUFloat(q2TextBox.Text, out dummy) && - Utils.TryParseUFloat(dQTextBox.Text, out dummy) && + return Utils.TryParseUDouble(q2TextBox.Text, out dummy) && + Utils.TryParseUDouble(dQTextBox.Text, out dummy) && selectorComboBox.Items.Contains(selectorComboBox.Text) && sensorsComboBox.Items.Contains(sensorsComboBox.Text); case QSpec.Q_dPct: - return Utils.TryParseUFloat(q3TextBox.Text, out dummy) && - Utils.TryParseUFloat(dQpctTextBox.Text, out dummy) && + return Utils.TryParseUDouble(q3TextBox.Text, out dummy) && + Utils.TryParseUDouble(dQpctTextBox.Text, out dummy) && selectorComboBox.Items.Contains(selectorComboBox.Text) && sensorsComboBox.Items.Contains(sensorsComboBox.Text); } @@ -182,7 +182,7 @@ namespace TBF.UI.Procedures.TestWizard private void tabControl1_SelectedIndexChanged(object sender, EventArgs e) { - double Q1,Q2; + double Q1, Q2; switch ((QSpec)tabControl1.SelectedIndex) { diff --git a/TBF/UI/Settings/UpgradeSelectionDlg.cs b/TBF/UI/Settings/UpgradeSelectionDlg.cs index 714f66db6..8d82512a1 100644 --- a/TBF/UI/Settings/UpgradeSelectionDlg.cs +++ b/TBF/UI/Settings/UpgradeSelectionDlg.cs @@ -1293,6 +1293,42 @@ namespace TBF.UI.Settings (!upgradeResultsDBCheckBox.Checked || resultsDbCommands.Length == 0 || ExecuteCommands(new MySqlConnection(Results.DB.ConnectionString), resultsDbCommands))) { + if (upgradeConfigDBCheckBox.Checked) + { + ISession session = null; + try + { + session = TBF.DB.CreateSession(Common.DBKind.Config); + var tests = session.QueryOver().List(); + + foreach (var t in tests) + { + string singlePrecStr = Convert.ToSingle(t.Qtg).ToString(); + if (t.Qtg.ToString().Length > 2 * singlePrecStr.Length) t.Qtg = double.Parse(singlePrecStr); + + singlePrecStr = Convert.ToSingle(t.Qfrom).ToString(); + if (t.Qfrom.ToString().Length > 2 * singlePrecStr.Length) t.Qfrom = double.Parse(singlePrecStr); + + singlePrecStr = Convert.ToSingle(t.Qto).ToString(); + if (t.Qto.ToString().Length > 2 * singlePrecStr.Length) t.Qto = double.Parse(singlePrecStr); + + session.SaveOrUpdate(t); + } + + session.Flush(); + } + catch (Exception exc) + { + ActivityEnd(); + MessageBox.Show(string.Format("Test flow rounding after a conversion to double failed:\r\n{0}", exc.Message), + "Error", MessageBoxButtons.OK, MessageBoxIcon.Information); + } + finally + { + if (session != null && session.IsOpen) session.Close(); + } + } + ActivityEnd(); MessageBox.Show("DB succesfully upgraded", "Confirmation", MessageBoxButtons.OK, MessageBoxIcon.Information); upgradeDb_232_233_Button.Enabled = false;