UpgradeSelectionDlg fixed : Rounding flows after converting them to double must be done at the very end, after all other upgrades.

This commit is contained in:
Milan Hanajik 2023-11-24 11:58:52 +01:00
parent d772a3d531
commit 09c542e1e6

View File

@ -236,60 +236,6 @@ 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(DBKind.Config);
var tests = session.QueryOver<Config.Entities.Test>().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);
singlePrecStr = Convert.ToSingle(t.Volume).ToString();
if (t.Volume.ToString().Length > 2 * singlePrecStr.Length) t.Volume = double.Parse(singlePrecStr);
singlePrecStr = Convert.ToSingle(t.TestTime).ToString();
if (t.TestTime.ToString().Length > 2 * singlePrecStr.Length) t.TestTime = double.Parse(singlePrecStr);
session.SaveOrUpdate(t);
}
var mcorrections = session.QueryOver<Config.Entities.MeasurementCorrection>().List();
foreach (var mc in mcorrections)
{
string singlePrecStr = Convert.ToSingle(mc.Measurement).ToString();
if (mc.Measurement.ToString().Length > 2 * singlePrecStr.Length) mc.Measurement = double.Parse(singlePrecStr);
singlePrecStr = Convert.ToSingle(mc.Correction).ToString();
if (mc.Correction.ToString().Length > 2 * singlePrecStr.Length) mc.Correction = double.Parse(singlePrecStr);
session.SaveOrUpdate(mc);
}
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_302_303_Button.Enabled = false;
@ -469,10 +415,69 @@ namespace TBF.UI.Settings
(!upgradeResultsDBCheckBox.Checked || resultsDbCommands.Length == 0 ||
ExecuteCommands(new MySqlConnection(Results.DB.ConnectionString), resultsDbCommands)))
{
if (upgradeConfigDBCheckBox.Checked)
{
RoundFlowsAfterConversionToDbl();
}
ActivityEnd();
MessageBox.Show("DB succesfully upgraded", "Confirmation", MessageBoxButtons.OK, MessageBoxIcon.Information);
upgradeDb_308_309_Button.Enabled = false;
}
}
private void RoundFlowsAfterConversionToDbl()
{
ISession session = null;
try
{
session = TBF.DB.CreateSession(DBKind.Config);
var tests = session.QueryOver<Config.Entities.Test>().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);
singlePrecStr = Convert.ToSingle(t.Volume).ToString();
if (t.Volume.ToString().Length > 2 * singlePrecStr.Length) t.Volume = double.Parse(singlePrecStr);
singlePrecStr = Convert.ToSingle(t.TestTime).ToString();
if (t.TestTime.ToString().Length > 2 * singlePrecStr.Length) t.TestTime = double.Parse(singlePrecStr);
session.SaveOrUpdate(t);
}
var mcorrections = session.QueryOver<Config.Entities.MeasurementCorrection>().List();
foreach (var mc in mcorrections)
{
string singlePrecStr = Convert.ToSingle(mc.Measurement).ToString();
if (mc.Measurement.ToString().Length > 2 * singlePrecStr.Length) mc.Measurement = double.Parse(singlePrecStr);
singlePrecStr = Convert.ToSingle(mc.Correction).ToString();
if (mc.Correction.ToString().Length > 2 * singlePrecStr.Length) mc.Correction = double.Parse(singlePrecStr);
session.SaveOrUpdate(mc);
}
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();
}
}
}
}