Files
tbf/TBF/UI/Settings/UpgradeSelectionDlg.cs
T

658 lines
32 KiB
C#

using System;
using System.Drawing;
using System.Windows.Forms;
using System.Collections.Generic;
using log4net;
using MySql.Data.MySqlClient;
using NHibernate;
using Results;
using Results.Entities;
using TBF.Resources;
namespace TBF.UI.Settings
{
public partial class UpgradeSelectionDlg : Form
{
private static readonly ILog log = LogManager.GetLogger(typeof(UpgradeSelectionDlg));
int batchFrom;
int batchTo;
Shared.ModelessActivityForm form;
System.Threading.Thread formThread;
public UpgradeSelectionDlg()
{
InitializeComponent();
upgradeConfigDBCheckBox.Checked = true;
upgradeResultsDBCheckBox.Checked = true;
batchFrom = 1;
batchTo = Program.LocalSettings.BatchNr - 1;
textBox1.Text = batchFrom.ToString();
textBox2.Text = batchTo.ToString();
}
void ActivityStart()
{
form = new Shared.ModelessActivityForm()
{
Message = "Upgrading database",
FontFamily = "Arial",
FontSize = 24,
FontStyle = FontStyle.Regular,
BackgroundColor = Color.Green,
};
formThread = new System.Threading.Thread(() => form.ShowDialog());
formThread.Start();
}
void ActivityEnd()
{
if (form != null && formThread != null)
{
form.CloseForm(null, new EventArgs());
formThread.Join();
}
form = null;
formThread = null;
}
/// <summary>
/// Common part of database upgrade code
/// </summary>
/// <param name="dbConn">Database connection</param>
/// <param name="commands">Array of SQL commands to be executed</param>
/// <returns>true = successful</returns>
bool ExecuteCommands(MySqlConnection dbConn, string[] commands)
{
bool success = false;
try
{
dbConn.Open();
foreach (var cmdText in commands)
{
MySqlCommand cmd = dbConn.CreateCommand();
cmd.CommandText = cmdText;
cmd.ExecuteNonQuery();
cmd.Dispose();
}
success = true;
}
catch (Exception exc)
{
log.ErrorFormat(string.Format("Exception when upgrading DB: {0}", exc.Message));
if (exc.InnerException != null) log.ErrorFormat(string.Format("Inner exception: {0}", exc.InnerException.Message));
ActivityEnd();
MessageBox.Show(string.Format("Exception {0}", exc.Message), "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
}
finally
{
dbConn.Close();
}
return success;
}
///---------------------------------------------------------------------
private void upgradeDb_NFC_button_Click(object sender, EventArgs e)
{
if (!upgradeConfigDBCheckBox.Checked && !upgradeResultsDBCheckBox.Checked)
{
MessageBox.Show("No database selected");
return;
}
string[] commands = new string[]
{
"ALTER TABLE `user` ADD `Tag` VARCHAR(255) NULL DEFAULT NULL AFTER `Number`;",
};
ActivityStart();
if (!upgradeConfigDBCheckBox.Checked || ExecuteCommands(new MySqlConnection(Config.Data.CurrentBench.ProceduresDBSettings.ConnectionString), commands))
{
ActivityEnd();
MessageBox.Show("DB succesfully upgraded", "Confirmation", MessageBoxButtons.OK, MessageBoxIcon.Information);
upgradeDb_NFC_button.Enabled = false;
}
}
///---------------------------------------------------------------------
private void upgradeDb_24_29_Button_Click(object sender, EventArgs e)
{
if (!upgradeConfigDBCheckBox.Checked && !upgradeResultsDBCheckBox.Checked)
{
MessageBox.Show("No database selected");
return;
}
string[] configDbCommands = new string[]
{
/// 2.4 -> 2.5
"ALTER TABLE `test` ADD `MassRepeats` INT NOT NULL DEFAULT '5' AFTER `PumpPower`, ADD `MassSpread` FLOAT NOT NULL DEFAULT '0' AFTER `MassRepeats`, ADD `MassMethod` TINYINT(3) UNSIGNED NOT NULL DEFAULT '0' AFTER `MassSpread`",
/// 2.5 -> 2.6 ---
/// 2.6 -> 2.7 ---
/// 2.7 -> 2.8 ---
/// 2.8 -> 2.9
"ALTER TABLE `meterspath` DROP `Qfrom`, DROP `Qto`;",
};
string[] resultsDbCommands = new string[]
{
/// 2.4 -> 2.5 ---
/// 2.5 -> 2.6
"ALTER TABLE `watermeterdata` DROP `Q3`, CHANGE `Qn` `Q3_Qn` DOUBLE NULL DEFAULT NULL ",
"ALTER TABLE `watermeterdata` ADD `DN` DOUBLE NOT NULL DEFAULT '0' AFTER `Producer`, ADD `L` DOUBLE NOT NULL DEFAULT '0' AFTER `DN`, ADD `Mounting` VARCHAR(255) NULL DEFAULT NULL AFTER `L`, ADD `TemperatureClass` VARCHAR(255) NULL DEFAULT NULL AFTER `Q1_Qmin`, ADD `PressureLossClass` VARCHAR(255) NULL DEFAULT NULL AFTER `TemperatureClass`",
"ALTER TABLE `watermeterdata` ADD `MaxAdmissiblePressure` VARCHAR(255) NULL DEFAULT NULL AFTER `PressureLossClass`, ADD `FlowProfileSensitivityClass` VARCHAR(255) NULL DEFAULT NULL AFTER `MaxAdmissiblePressure`, ADD `Certificate` VARCHAR(255) NULL DEFAULT NULL AFTER `FlowProfileSensitivityClass`, ADD `PulsesPerLtr` DOUBLE NOT NULL DEFAULT '1' AFTER `Certificate`",
"ALTER TABLE `watermeterdata` ADD `Text1` VARCHAR(255) NULL DEFAULT NULL AFTER `PulsesPerLtr`, ADD `Text2` VARCHAR(255) NULL DEFAULT NULL AFTER `Text1`, ADD `Text3` VARCHAR(255) NULL DEFAULT NULL AFTER `Text2`, ADD `Text4` VARCHAR(255) NULL DEFAULT NULL AFTER `Text3`, ADD `Text5` VARCHAR(255) NULL DEFAULT NULL AFTER `Text4`",
/// 2.6 -> 2.7
"ALTER TABLE `watermeterdata` ADD `ProducerAux` VARCHAR(255) NULL DEFAULT NULL AFTER `PulsesPerLtr`, ADD `Q3_Qn_Aux` DOUBLE NOT NULL DEFAULT '0' AFTER `ProducerAux`, ADD `MetrologicalClassAux` VARCHAR(255) NULL DEFAULT NULL AFTER `Q3_Qn_Aux`, ADD `ApprovalInfoAux` VARCHAR(255) NULL DEFAULT NULL AFTER `MetrologicalClassAux`",
/// 2.7 -> 2.8
"ALTER TABLE `watermeter` ADD `ResultCode` INT NOT NULL DEFAULT '0' AFTER `Passed`",
"ALTER TABLE `batch` ADD `Remark` VARCHAR( 2000 ) NULL DEFAULT NULL AFTER `ProtocolTitle`",
/// 2.8 -> 2.9 ---
};
ActivityStart();
if ((!upgradeConfigDBCheckBox.Checked || ExecuteCommands(new MySqlConnection(Config.Data.CurrentBench.ProceduresDBSettings.ConnectionString), configDbCommands)) &&
(!upgradeResultsDBCheckBox.Checked || ExecuteCommands(new MySqlConnection(DB.ConnectionString), resultsDbCommands)))
{
ActivityEnd();
MessageBox.Show("DB succesfully upgraded", "Confirmation", MessageBoxButtons.OK, MessageBoxIcon.Information);
upgradeDb_24_29_Button.Enabled = false;
}
}
///---------------------------------------------------------------------
private void upgradeDb_29_212_Button_Click(object sender, EventArgs e)
{
if (!upgradeConfigDBCheckBox.Checked && !upgradeResultsDBCheckBox.Checked)
{
MessageBox.Show("No database selected");
return;
}
string[] configDbCommands = new string[]
{
/// 2.9 -> 2.10
/// 2.10 -> 2.11
"ALTER TABLE `feedingpath` ADD `RegulValvesPct` VARCHAR(255) NULL DEFAULT NULL AFTER `Pump;",
/// 2.11 -> 2.12
"ALTER TABLE `benchpath` ADD `PressMtrDelta` VARCHAR(255) NULL DEFAULT NULL AFTER `PressOut;",
};
string[] resultsDbCommands = new string[]
{
/// 2.9 -> 2.10
"ALTER TABLE `testrslt` ADD `AmbTempStart` FLOAT NOT NULL DEFAULT '0' AFTER `AmbientTempAve`",
"ALTER TABLE `testrslt` ADD `AmbTempEnd` FLOAT NOT NULL DEFAULT '0' AFTER `AmbTempStart`",
"ALTER TABLE `testrslt` ADD `AmbTempMin` FLOAT NOT NULL DEFAULT '0' AFTER `AmbTempEnd`",
"ALTER TABLE `testrslt` ADD `AmbTempMax` FLOAT NOT NULL DEFAULT '0' AFTER `AmbTempMin`",
"ALTER TABLE `testrslt` ADD `AmbPressStart` FLOAT NOT NULL DEFAULT '0' AFTER `AmbientPressAve`",
"ALTER TABLE `testrslt` ADD `AmbPressEnd` FLOAT NOT NULL DEFAULT '0' AFTER `AmbPressStart`",
"ALTER TABLE `testrslt` ADD `AmbPressMin` FLOAT NOT NULL DEFAULT '0' AFTER `AmbPressEnd`",
"ALTER TABLE `testrslt` ADD `AmbPressMax` FLOAT NOT NULL DEFAULT '0' AFTER `AmbPressMin`",
"ALTER TABLE `testrslt` ADD `AmbHumiStart` FLOAT NOT NULL DEFAULT '0' AFTER `AmbientHumiAve`",
"ALTER TABLE `testrslt` ADD `AmbHumiEnd` FLOAT NOT NULL DEFAULT '0' AFTER `AmbHumiStart`",
"ALTER TABLE `testrslt` ADD `AmbHumiMin` FLOAT NOT NULL DEFAULT '0' AFTER `AmbHumiEnd`",
"ALTER TABLE `testrslt` ADD `AmbHumiMax` FLOAT NOT NULL DEFAULT '0' AFTER `AmbHumiMin`",
/// 2.10 -> 2.11
/// 2.11 -> 2.12
"ALTER TABLE `testrslt` ADD `PressDeltaMean` FLOAT NOT NULL DEFAULT '0' AFTER `PressDownMax`",
"ALTER TABLE `testrslt` ADD `PressDeltaStart` FLOAT NOT NULL DEFAULT '0' AFTER `PressDeltaMean`",
"ALTER TABLE `testrslt` ADD `PressDeltaEnd` FLOAT NOT NULL DEFAULT '0' AFTER `PressDeltaStart`",
"ALTER TABLE `testrslt` ADD `PressDeltaMin` FLOAT NOT NULL DEFAULT '0' AFTER `PressDeltaEnd`",
"ALTER TABLE `testrslt` ADD `PressDeltaMax` FLOAT NOT NULL DEFAULT '0' AFTER `PressDeltaMin`",
"ALTER TABLE `testrslt` ADD `FlowStart` FLOAT NOT NULL DEFAULT '0' AFTER `TempDivMax`",
"ALTER TABLE `testrslt` ADD `FlowEnd` FLOAT NOT NULL DEFAULT '0' AFTER `FlowStart`",
};
ActivityStart();
if ((!upgradeConfigDBCheckBox.Checked || ExecuteCommands(new MySqlConnection(Config.Data.CurrentBench.ProceduresDBSettings.ConnectionString), configDbCommands)) &&
(!upgradeResultsDBCheckBox.Checked || ExecuteCommands(new MySqlConnection(DB.ConnectionString), resultsDbCommands)))
{
if (upgradeConfigDBCheckBox.Checked)
{
MySqlConnection dbConn = new MySqlConnection(Config.Data.CurrentBench.ProceduresDBSettings.ConnectionString);
try
{
dbConn.Open();
MySqlCommand cmd;
cmd = dbConn.CreateCommand();
cmd.CommandText = "UPDATE component SET ClassName = 'TestMethods.Adjustment.Single' WHERE ClassName = 'Adjustment'";
cmd.ExecuteNonQuery();
cmd.Dispose();
cmd = dbConn.CreateCommand();
cmd.CommandText = "UPDATE component SET ClassName = 'TestMethods.FlyingStartMassCollection.Compound' WHERE ClassName = 'CombinedMeters'";
cmd.ExecuteNonQuery();
cmd.Dispose();
cmd = dbConn.CreateCommand();
cmd.CommandText = "UPDATE component SET ClassName = 'TestMethods.CombinedWithDetection.Compound' WHERE ClassName = 'CombinedWithDetection'";
cmd.ExecuteNonQuery();
cmd.Dispose();
cmd = dbConn.CreateCommand();
cmd.CommandText = "UPDATE component SET ClassName = 'TestMethods.FixedStartMassCollection.Single' WHERE ClassName = 'FixedStartMassCollection'";
cmd.ExecuteNonQuery();
cmd.Dispose();
cmd = dbConn.CreateCommand();
cmd.CommandText = "UPDATE component SET ClassName = 'TestMethods.FixedStartMassCollection.Compound' WHERE ClassName = 'FixedStartCombinedMeters'";
cmd.ExecuteNonQuery();
cmd.Dispose();
cmd = dbConn.CreateCommand();
cmd.CommandText = "UPDATE component SET ClassName = 'TestMethods.FlyingStart.Single' WHERE ClassName = 'FlyingStart'";
cmd.ExecuteNonQuery();
cmd.Dispose();
cmd = dbConn.CreateCommand();
cmd.CommandText = "UPDATE component SET ClassName = 'TestMethods.FlyingStartMassCollection.Single' WHERE ClassName = 'Flying-Start-Collection'";
cmd.ExecuteNonQuery();
cmd.Dispose();
cmd = dbConn.CreateCommand();
cmd.CommandText = "UPDATE component SET ClassName = 'TestMethods.LeakTest' WHERE ClassName = 'Leak-Test'";
cmd.ExecuteNonQuery();
cmd.Dispose();
cmd = dbConn.CreateCommand();
cmd.CommandText = "UPDATE component SET ClassName = 'TestMethods.PMaxTest' WHERE ClassName = 'PMax-Test'";
cmd.ExecuteNonQuery();
cmd.Dispose();
cmd = dbConn.CreateCommand();
cmd.CommandText = "UPDATE component SET ClassName = 'Output.Printers.Enhanced.Single' WHERE ClassName = 'BasicResultsPrinter'";
cmd.ExecuteNonQuery();
cmd.Dispose();
ActivityEnd();
MessageBox.Show("DB succesfully upgraded", "Confirmation", MessageBoxButtons.OK, MessageBoxIcon.Information);
upgradeDb_29_212_Button.Enabled = false;
}
catch (Exception exc)
{
log.ErrorFormat(string.Format("Exception when upgrading DB: {0}", exc.Message));
if (exc.InnerException != null) log.ErrorFormat(string.Format("Inner exception: {0}", exc.InnerException.Message));
ActivityEnd();
MessageBox.Show(string.Format("Exception {0}", exc.Message), "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
}
finally
{
dbConn.Close();
}
}
else
{
ActivityEnd();
MessageBox.Show("DB succesfully upgraded", "Confirmation", MessageBoxButtons.OK, MessageBoxIcon.Information);
upgradeDb_29_212_Button.Enabled = false;
}
}
}
///---------------------------------------------------------------------
private void upgradeDb_212_215_Button_Click(object sender, EventArgs e)
{
if (!upgradeConfigDBCheckBox.Checked && !upgradeResultsDBCheckBox.Checked)
{
MessageBox.Show("No database selected");
return;
}
string[] configDbCommands = new string[]
{
/// 2.12 -> 2.13
"ALTER TABLE `procedure` ADD `Protected` BOOLEAN NOT NULL DEFAULT '0' AFTER `ProtocolTitle`, ADD `MustBeComplete` BOOLEAN NOT NULL DEFAULT '0' AFTER `Protected`, ADD `ManualCtrlDisabled` BOOLEAN NOT NULL DEFAULT '0' AFTER `MustBeComplete`",
/// 2.13 -> 2.14
"ALTER TABLE `test` ADD `DoControlWaterTemp` BOOLEAN NOT NULL DEFAULT '0' AFTER `Zeroing`, ADD `TempLimLo` FLOAT NOT NULL DEFAULT '15' AFTER `DoControlWaterTemp`, ADD `TempLimHi` FLOAT NOT NULL DEFAULT '25' AFTER `TempLimLo`",
/// 2.14 -> 2.15
"ALTER TABLE `procedure` ADD `AltProcName` VARCHAR(255) NULL DEFAULT NULL , ADD `AltProcPeriod` INT NOT NULL DEFAULT '0';",
//"ALTER TABLE `procedure` DROP `ProtocolTitle`;", /// Commented out to maintain compatibility with an old ResultsBrowser
};
string[] resultsDbCommands = new string[]
{
/// 2.12 -> 2.13
"ALTER TABLE `watermeter` ADD `Remark` VARCHAR( 2000 ) NULL DEFAULT NULL AFTER `ResultCode`",
"ALTER TABLE `batch` ADD `Dirty` BOOLEAN NOT NULL DEFAULT '0' AFTER `EndTime`",
/// 2.13 -> 2.14
#if !IPERL
"ALTER TABLE `testrslt` ADD `FlowMean` FLOAT NOT NULL DEFAULT '0' AFTER `TempDivMax`",
#endif
"ALTER TABLE `testrslt` ADD `TestDone` BOOLEAN NOT NULL DEFAULT '1' AFTER `RepetitionNr`, ADD `Remark` VARCHAR( 2000 ) NULL DEFAULT NULL AFTER `TestDone`",
"ALTER TABLE `testdata` ADD `DoControlWaterTemp` BOOLEAN NOT NULL DEFAULT '0' AFTER `Uncertainty`, ADD `TempLimLo` FLOAT NOT NULL DEFAULT '15' AFTER `DoControlWaterTemp`, ADD `TempLimHi` FLOAT NOT NULL DEFAULT '25' AFTER `TempLimLo`",
/// 2.14 -> 2.15
"ALTER TABLE `watermeter` ADD `ArchivePath` VARCHAR(255) NULL DEFAULT NULL AFTER `ResultCode`;",
};
ActivityStart();
if ((!upgradeConfigDBCheckBox.Checked || ExecuteCommands(new MySqlConnection(Config.Data.CurrentBench.ProceduresDBSettings.ConnectionString), configDbCommands)) &&
(!upgradeResultsDBCheckBox.Checked || ExecuteCommands(new MySqlConnection(DB.ConnectionString), resultsDbCommands)))
{
if (upgradeConfigDBCheckBox.Checked)
{
MySqlConnection dbConn = new MySqlConnection(Config.Data.CurrentBench.ProceduresDBSettings.ConnectionString);
try
{
dbConn.Open();
int maxItemNr = 0;
MySqlCommand cmd = dbConn.CreateCommand();
cmd.CommandText = "SELECT ItemNr FROM component";
MySqlDataReader dr = cmd.ExecuteReader();
while (dr.Read())
{
int itemNr = dr.GetInt32(0);
if (itemNr > maxItemNr) maxItemNr = itemNr;
}
dr.Close();
cmd = dbConn.CreateCommand();
cmd.CommandText = "UPDATE component SET ClassName = 'RegisterReader for standing start/stop' WHERE ClassName = 'Fixed-Start-Register-Reader'";
cmd.ExecuteNonQuery();
cmd.Dispose();
cmd = dbConn.CreateCommand();
cmd.CommandText = "UPDATE component SET ClassName = 'TestMethods.iPerlCommunication' WHERE ClassName = 'iPerlCommunication'";
cmd.ExecuteNonQuery();
cmd.Dispose();
cmd = dbConn.CreateCommand();
cmd.CommandText = "UPDATE component SET ClassName = 'WaterMeter' WHERE ClassName = 'iPerl'";
cmd.ExecuteNonQuery();
cmd.Dispose();
for (int i = 1; i <= 40; i++)
{
Text = string.Format("Upgrade selection: {0}/40", i);
/// Read original iPerl water meter parameters
int id = 0;
string parameters = string.Empty;
cmd = dbConn.CreateCommand();
cmd.CommandText = string.Format("SELECT Id, Parameters FROM Component WHERE Name = 'iPerl{0}' AND ClassName = 'WaterMeter'", i);
dr = cmd.ExecuteReader();
if (dr.Read())
{
id = dr.GetInt32(0);
parameters = dr.GetString(1);
}
dr.Close();
cmd.Dispose();
if (id != 0)
{
/// Rename iPerl water meter
cmd = dbConn.CreateCommand();
cmd.CommandText = string.Format("UPDATE component SET Name = 'WM{0}' WHERE Name = 'iPerl{0}'", i);
cmd.ExecuteNonQuery();
cmd.Dispose();
/// Create iPerl Head
cmd = dbConn.CreateCommand();
cmd.CommandText = string.Format("INSERT INTO component(ItemNr, Name, ClassName, Parentname, Mode, Logging, Parameters) VALUES ({0}, 'iPerl{1}', 'RegisterReader for iPerl', '', 'Normal', 'Off', @params)",
maxItemNr + 1, i);
cmd.Parameters.AddWithValue("@params", parameters.Replace("WaterMeterCfg", "IperlHeadCfg"));
cmd.ExecuteNonQuery();
cmd.Dispose();
/// Clone procedure parameters
IList<int> idList = new List<int>();
IList<string> parList = new List<string>();
IList<int> procIdList = new List<int>();
cmd = dbConn.CreateCommand();
cmd.CommandText = string.Format("SELECT Id, Parameters, Procedure_id FROM componentprocedure WHERE CmpntName = 'iPerl{0}'", i);
dr = cmd.ExecuteReader();
while (dr.Read())
{
idList.Add(dr.GetInt32(0));
parList.Add(dr.GetString(1));
procIdList.Add(dr.GetInt32(2));
}
dr.Close();
cmd.Dispose();
if ((idList.Count == parList.Count) && (parList.Count == procIdList.Count))
{
for (int j = 0; j < parList.Count; j++)
{
cmd = dbConn.CreateCommand();
cmd.CommandText = string.Format("INSERT INTO componentprocedure(CmpntName, Parameters, Procedure_id) VALUES ('WM{0}', @params, {1})",
i, procIdList[j]);
cmd.Parameters.AddWithValue("@params", parList[j].Replace("Q4", "Qmax")
.Replace("Q3", "Qn")
.Replace("Q2", "Qt")
.Replace("Q1", "Qmin")
.Replace("<Qmax>", "<NewQnames>true</NewQnames>\r\n <Qmax>"));
cmd.ExecuteNonQuery();
cmd.Dispose();
}
}
}
}
/// Delete 'Parmeters' of iPerl water meters
cmd = dbConn.CreateCommand();
cmd.CommandText = "UPDATE component SET Parameters = '<?xml version=\"1.0\" encoding=\"utf-16\"?>\r\n<WaterMeterCfg xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\">\r\n</WaterMeterCfg>' WHERE ClassName = 'WaterMeter'";
cmd.ExecuteNonQuery();
cmd.Dispose();
Text = string.Format("Upgrade selection");
ActivityEnd();
MessageBox.Show("DB succesfully upgraded", "Confirmation", MessageBoxButtons.OK, MessageBoxIcon.Information);
upgradeDb_212_215_Button.Enabled = false;
}
catch (Exception exc)
{
log.ErrorFormat(string.Format("Exception when upgrading DB: {0}", exc.Message));
if (exc.InnerException != null) log.ErrorFormat(string.Format("Inner exception: {0}", exc.InnerException.Message));
ActivityEnd();
MessageBox.Show(string.Format("Exception {0}", exc.Message), "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
}
finally
{
dbConn.Close();
}
}
else
{
ActivityEnd();
MessageBox.Show("DB succesfully upgraded", "Confirmation", MessageBoxButtons.OK, MessageBoxIcon.Information);
upgradeDb_212_215_Button.Enabled = false;
}
}
}
///---------------------------------------------------------------------
private void upgradeDb_215_216_Button_Click(object sender, EventArgs e)
{
if (!upgradeConfigDBCheckBox.Checked && !upgradeResultsDBCheckBox.Checked)
{
MessageBox.Show("No database selected");
return;
}
string[] commands = new string[]
{
"ALTER TABLE `testrslt` ADD `ErrorFlagsMd` TINYINT( 4 ) NOT NULL DEFAULT '0' AFTER `ErrorMaster`, ADD `ErrorFlags` INT NOT NULL DEFAULT '0' AFTER `ErrorFlagsMd`;",
};
ActivityStart();
if (!upgradeResultsDBCheckBox.Checked || ExecuteCommands(new MySqlConnection(DB.ConnectionString), commands))
{
ActivityEnd();
MessageBox.Show("DB succesfully upgraded", "Confirmation", MessageBoxButtons.OK, MessageBoxIcon.Information);
upgradeDb_215_216_Button.Enabled = false;
}
}
///---------------------------------------------------------------------
private void upgradeDb_216_217_Button_Click(object sender, EventArgs e)
{
if (!upgradeConfigDBCheckBox.Checked && !upgradeResultsDBCheckBox.Checked)
{
MessageBox.Show("No database selected");
return;
}
string[] commands = new string[]
{
"ALTER TABLE `testrslt` ADD `DiverterStart` FLOAT NOT NULL DEFAULT '0.001' AFTER `ErrorMaster`, ADD `DiverterEnd` FLOAT NOT NULL DEFAULT '0.001' AFTER `DiverterStart`;",
"ALTER TABLE `watermeter` ADD `ErrorFlags` INT NOT NULL DEFAULT '0' AFTER `QFall`;",
};
ActivityStart();
if (!upgradeResultsDBCheckBox.Checked || ExecuteCommands(new MySqlConnection(DB.ConnectionString), commands))
{
ActivityEnd();
MessageBox.Show("DB succesfully upgraded", "Confirmation", MessageBoxButtons.OK, MessageBoxIcon.Information);
upgradeDb_216_217_Button.Enabled = false;
}
}
///---------------------------------------------------------------------
private void upgradeDb_217_218_Button_Click(object sender, EventArgs e)
{
if (!upgradeConfigDBCheckBox.Checked && !upgradeResultsDBCheckBox.Checked)
{
MessageBox.Show("No database selected");
return;
}
string[] commands = new string[]
{
"ALTER TABLE `measurementcorrection` ADD `RangeIx` INT NOT NULL DEFAULT '0' AFTER `Id`;",
};
ActivityStart();
if (!upgradeConfigDBCheckBox.Checked || ExecuteCommands(new MySqlConnection(Config.Data.CurrentBench.ProceduresDBSettings.ConnectionString), commands))
{
ActivityEnd();
MessageBox.Show("DB succesfully upgraded", "Confirmation", MessageBoxButtons.OK, MessageBoxIcon.Information);
upgradeDb_217_218_Button.Enabled = false;
}
}
///---------------------------------------------------------------------
private void upgradeDb_218_220_Button_Click(object sender, EventArgs e)
{
if (!upgradeConfigDBCheckBox.Checked && !upgradeResultsDBCheckBox.Checked)
{
MessageBox.Show("No database selected");
return;
}
string[] commands = new string[]
{
"ALTER TABLE `metertestrslt` ADD `RegReaderType` INT NOT NULL DEFAULT '0' AFTER `CompoundMeterId`;",
"ALTER TABLE `testrslt` ADD `MethodClass` VARCHAR(255) NULL DEFAULT NULL AFTER `RepetitionNr`, ADD `ConstMasterRaw` DOUBLE NOT NULL DEFAULT '1' AFTER `PulsesMaster`, ADD `ConstMasterCorr` DOUBLE NOT NULL DEFAULT '1' AFTER `ConstMasterRaw`;",
"ALTER TABLE `watermeterdata` ADD `Medium` VARCHAR(255) NULL DEFAULT NULL AFTER `ApprovalInfoAux`;",
};
ActivityStart();
if (!upgradeResultsDBCheckBox.Checked || ExecuteCommands(new MySqlConnection(DB.ConnectionString), commands))
{
ActivityEnd();
MessageBox.Show("DB succesfully upgraded", "Confirmation", MessageBoxButtons.OK, MessageBoxIcon.Information);
upgradeDb_218_220_Button.Enabled = false;
}
}
private void pressureRepresentationButton_Click(object sender, EventArgs e)
{
try
{
batchFrom = int.Parse(textBox1.Text);
batchTo = int.Parse(textBox2.Text);
if (batchFrom < 1 || batchFrom > batchTo) throw new Exception();
}
catch
{
MessageBox.Show("Wrong 'From batch #' or 'To batch #'", "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
return;
}
if (MessageBox.Show("Are you sure ?", "", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No) return;
ActivityStart();
try
{
ISession session = DB.CreateSession();
IList<Batch> bFrom = session.QueryOver<Batch>().Where(x => (x.BatchNr == batchFrom)).List<Batch>();
IList<Batch> bTo = session.QueryOver<Batch>().Where(x => (x.BatchNr == batchTo)).List<Batch>();
if (bFrom.Count != 1) throw new Exception("No start batch");
if (bTo.Count != 1) throw new Exception("No end batch");
IList<TestRslt> testResults = session.QueryOver<TestRslt>()
.WhereRestrictionOn(x => x.StartTime)
.IsBetween(bFrom[0].StartTime)
.And(bTo[0].EndTime)
.List<TestRslt>();
foreach (var tr in testResults)
{
Text = string.Format("Batch # = {0}", tr.Batch.BatchNr);
float factor1 = 0.01f;
tr.PressUpMean *= factor1;
tr.PressUpStart *= factor1;
tr.PressUpEnd *= factor1;
tr.PressUpMin *= factor1;
tr.PressUpMax *= factor1;
tr.PressDownMean *= factor1;
tr.PressDownStart *= factor1;
tr.PressDownEnd *= factor1;
tr.PressDownMin *= factor1;
tr.PressDownMax *= factor1;
tr.AmbPressMean *= 0.001f;
session.SaveOrUpdate(tr);
}
session.Flush();
ActivityEnd();
MessageBox.Show("Upgrade completed", "", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
catch (Exception exc)
{
ActivityEnd();
MessageBox.Show(string.Format("Upgrade failed:\r\n{0}", exc.Message),
"Error", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}
}
}