UpgradeSelectionDlg support for 2.12-->2.17, ver. 2.17.722

This commit is contained in:
Milan Hanajik
2017-11-07 11:07:11 +01:00
parent 441cf91ff6
commit 59c2afe0e8
7 changed files with 356 additions and 157 deletions
+17 -4
View File
@@ -37,6 +37,7 @@ namespace TBF.Forms
this.configureButton = new System.Windows.Forms.Button(); this.configureButton = new System.Windows.Forms.Button();
this.pictureBox1 = new System.Windows.Forms.PictureBox(); this.pictureBox1 = new System.Windows.Forms.PictureBox();
this.errorMessageLabel = new System.Windows.Forms.Label(); this.errorMessageLabel = new System.Windows.Forms.Label();
this.upgradeButton = new System.Windows.Forms.Button();
((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).BeginInit();
this.SuspendLayout(); this.SuspendLayout();
// //
@@ -45,7 +46,7 @@ namespace TBF.Forms
this.exitButton.DialogResult = System.Windows.Forms.DialogResult.Cancel; this.exitButton.DialogResult = System.Windows.Forms.DialogResult.Cancel;
this.exitButton.Location = new System.Drawing.Point(42, 68); this.exitButton.Location = new System.Drawing.Point(42, 68);
this.exitButton.Name = "exitButton"; this.exitButton.Name = "exitButton";
this.exitButton.Size = new System.Drawing.Size(246, 33); this.exitButton.Size = new System.Drawing.Size(388, 33);
this.exitButton.TabIndex = 0; this.exitButton.TabIndex = 0;
this.exitButton.Text = "Exit"; this.exitButton.Text = "Exit";
this.exitButton.UseVisualStyleBackColor = true; this.exitButton.UseVisualStyleBackColor = true;
@@ -55,7 +56,7 @@ namespace TBF.Forms
// //
this.retryButton.Location = new System.Drawing.Point(42, 146); this.retryButton.Location = new System.Drawing.Point(42, 146);
this.retryButton.Name = "retryButton"; this.retryButton.Name = "retryButton";
this.retryButton.Size = new System.Drawing.Size(246, 33); this.retryButton.Size = new System.Drawing.Size(388, 33);
this.retryButton.TabIndex = 1; this.retryButton.TabIndex = 1;
this.retryButton.Text = "Retry database connection"; this.retryButton.Text = "Retry database connection";
this.retryButton.UseVisualStyleBackColor = true; this.retryButton.UseVisualStyleBackColor = true;
@@ -65,7 +66,7 @@ namespace TBF.Forms
// //
this.configureButton.Location = new System.Drawing.Point(42, 107); this.configureButton.Location = new System.Drawing.Point(42, 107);
this.configureButton.Name = "configureButton"; this.configureButton.Name = "configureButton";
this.configureButton.Size = new System.Drawing.Size(246, 33); this.configureButton.Size = new System.Drawing.Size(388, 33);
this.configureButton.TabIndex = 2; this.configureButton.TabIndex = 2;
this.configureButton.Text = "Configure test benches (password required)"; this.configureButton.Text = "Configure test benches (password required)";
this.configureButton.UseVisualStyleBackColor = true; this.configureButton.UseVisualStyleBackColor = true;
@@ -91,12 +92,23 @@ namespace TBF.Forms
this.errorMessageLabel.TabIndex = 4; this.errorMessageLabel.TabIndex = 4;
this.errorMessageLabel.Text = "Cannot connect to the database"; this.errorMessageLabel.Text = "Cannot connect to the database";
// //
// upgradeButton
//
this.upgradeButton.Location = new System.Drawing.Point(42, 185);
this.upgradeButton.Name = "upgradeButton";
this.upgradeButton.Size = new System.Drawing.Size(388, 33);
this.upgradeButton.TabIndex = 5;
this.upgradeButton.Text = "Upgrade the database";
this.upgradeButton.UseVisualStyleBackColor = true;
this.upgradeButton.Click += new System.EventHandler(this.upgradeButton_Click);
//
// NoBenchOrDatabaseDlg // NoBenchOrDatabaseDlg
// //
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.CancelButton = this.exitButton; this.CancelButton = this.exitButton;
this.ClientSize = new System.Drawing.Size(328, 194); this.ClientSize = new System.Drawing.Size(466, 240);
this.Controls.Add(this.upgradeButton);
this.Controls.Add(this.errorMessageLabel); this.Controls.Add(this.errorMessageLabel);
this.Controls.Add(this.pictureBox1); this.Controls.Add(this.pictureBox1);
this.Controls.Add(this.configureButton); this.Controls.Add(this.configureButton);
@@ -119,5 +131,6 @@ namespace TBF.Forms
private System.Windows.Forms.Button configureButton; private System.Windows.Forms.Button configureButton;
private System.Windows.Forms.PictureBox pictureBox1; private System.Windows.Forms.PictureBox pictureBox1;
private System.Windows.Forms.Label errorMessageLabel; private System.Windows.Forms.Label errorMessageLabel;
private System.Windows.Forms.Button upgradeButton;
} }
} }
@@ -33,19 +33,9 @@ namespace TBF.Forms
if (!ShowRetry) retryButton.Enabled = false; if (!ShowRetry) retryButton.Enabled = false;
} }
private void exitButton_Click(object sender, EventArgs e) private void exitButton_Click(object sender, EventArgs e) { DialogResult = DialogResult.Abort; } /// Exit
{ private void configureButton_Click(object sender, EventArgs e) { DialogResult = DialogResult.OK; } /// Configure test benches
DialogResult = DialogResult.Abort; private void retryButton_Click(object sender, EventArgs e) { DialogResult = DialogResult.Retry; } /// Retry connection to the database
} private void upgradeButton_Click(object sender, EventArgs e) { DialogResult = DialogResult.Yes; } /// Upgrade the database
private void retryButton_Click(object sender, EventArgs e)
{
DialogResult = DialogResult.Retry;
}
private void configureButton_Click(object sender, EventArgs e)
{
DialogResult = DialogResult.OK;
}
} }
} }
@@ -229,8 +229,8 @@
<data name="pictureBox1.Image" type="System.Drawing.Bitmap, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64"> <data name="pictureBox1.Image" type="System.Drawing.Bitmap, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value> <value>
iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAIAAAD8GO2jAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8 iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAIAAAD8GO2jAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8
YQUAAAAgY0hSTQAAeiYAAICEAAD6AAAAgOgAAHUwAADqYAAAOpgAABdwnLpRPAAAAAlwSFlzAAAOvwAA YQUAAAAgY0hSTQAAeiYAAICEAAD6AAAAgOgAAHUwAADqYAAAOpgAABdwnLpRPAAAAAlwSFlzAAAOvgAA
Dr8BOAVTJAAACG1JREFUSEu1lmlQW9cVx/mG0GIZZCczGcZjvCQEiLHNYpABAQKEwBjTeqmXCfkQ3Mx4 Dr4B6kKxwAAACG1JREFUSEu1lmlQW9cVx/mG0GIZZCczGcZjvCQEiLHNYpABAQKEwBjTeqmXCfkQ3Mx4
xp58SlMnY/dLmxl3TJIZu3UhBAQBsYNsisBoByS0C21oMUhCYIQkbFzqxo4n9C89TElqt/3SM1dv3tM7 xp58SlMnY/dLmxl3TJIZu3UhBAQBsYNsisBoByS0C21oMUhCYIQkbFzqxo4n9C89TElqt/3SM1dv3tM7
93fOPfecc1/M+n+UQCCgnJzs5PPrb9787OrVK5cvY+AGj/gTr6Cwofoaea0Bh8PR1dl5/do1Ho8nlUqd 93fOPfecc1/M+n+UQCCgnJzs5PPrb9787OrVK5cvY+AGj/gTr6Cwofoaea0Bh8PR1dl5/do1Ho8nlUqd
TudKOPxDVHCDR/yJV1CAGpQ3pv2bvMJAMBgcGBior6+XSCQhPDhm/CKRu4Nvv3Xb8vsv9J9fm77xRwev TudKOPxDVHCDR/yJV1CAGpQ3pv2bvMJAMBgcGBior6+XSCQhPDhm/CKRu4Nvv3Xb8vsv9J9fm77xRwev
+26 -13
View File
@@ -28,37 +28,49 @@
/// </summary> /// </summary>
private void InitializeComponent() private void InitializeComponent()
{ {
this.upgradeDbButton = new System.Windows.Forms.Button(); this.upgradeDb_215_217_Button = new System.Windows.Forms.Button();
this.upgradeDb_216_217_Button = new System.Windows.Forms.Button(); this.upgradeDb_216_217_Button = new System.Windows.Forms.Button();
this.upgradeDb_212_217_Button = new System.Windows.Forms.Button();
this.SuspendLayout(); this.SuspendLayout();
// //
// upgradeDbButton // upgradeDb_215_217_Button
// //
this.upgradeDbButton.Location = new System.Drawing.Point(12, 12); this.upgradeDb_215_217_Button.Location = new System.Drawing.Point(12, 52);
this.upgradeDbButton.Name = "upgradeDbButton"; this.upgradeDb_215_217_Button.Name = "upgradeDb_215_217_Button";
this.upgradeDbButton.Size = new System.Drawing.Size(260, 34); this.upgradeDb_215_217_Button.Size = new System.Drawing.Size(260, 34);
this.upgradeDbButton.TabIndex = 0; this.upgradeDb_215_217_Button.TabIndex = 1;
this.upgradeDbButton.Text = "Upgrade database from ver. 2.15 to ver. 2.17"; this.upgradeDb_215_217_Button.Text = "Upgrade database from ver. 2.15 to ver. 2.17";
this.upgradeDbButton.UseVisualStyleBackColor = true; this.upgradeDb_215_217_Button.UseVisualStyleBackColor = true;
this.upgradeDbButton.Click += new System.EventHandler(this.upgradeDbButton_Click); this.upgradeDb_215_217_Button.Click += new System.EventHandler(this.upgradeDb_215_217_Button_Click);
// //
// upgradeDb_216_217_Button // upgradeDb_216_217_Button
// //
this.upgradeDb_216_217_Button.Location = new System.Drawing.Point(12, 52); this.upgradeDb_216_217_Button.Location = new System.Drawing.Point(12, 92);
this.upgradeDb_216_217_Button.Name = "upgradeDb_216_217_Button"; this.upgradeDb_216_217_Button.Name = "upgradeDb_216_217_Button";
this.upgradeDb_216_217_Button.Size = new System.Drawing.Size(260, 34); this.upgradeDb_216_217_Button.Size = new System.Drawing.Size(260, 34);
this.upgradeDb_216_217_Button.TabIndex = 1; this.upgradeDb_216_217_Button.TabIndex = 2;
this.upgradeDb_216_217_Button.Text = "Upgrade database from ver. 2.16 to ver. 2.17"; this.upgradeDb_216_217_Button.Text = "Upgrade database from ver. 2.16 to ver. 2.17";
this.upgradeDb_216_217_Button.UseVisualStyleBackColor = true; this.upgradeDb_216_217_Button.UseVisualStyleBackColor = true;
this.upgradeDb_216_217_Button.Click += new System.EventHandler(this.upgradeDb_216_217_Button_Click); this.upgradeDb_216_217_Button.Click += new System.EventHandler(this.upgradeDb_216_217_Button_Click);
// //
// upgradeDb_212_217_Button
//
this.upgradeDb_212_217_Button.Location = new System.Drawing.Point(12, 12);
this.upgradeDb_212_217_Button.Name = "upgradeDb_212_217_Button";
this.upgradeDb_212_217_Button.Size = new System.Drawing.Size(260, 34);
this.upgradeDb_212_217_Button.TabIndex = 0;
this.upgradeDb_212_217_Button.Text = "Upgrade database from ver. 2.12 to ver. 2.17";
this.upgradeDb_212_217_Button.UseVisualStyleBackColor = true;
this.upgradeDb_212_217_Button.Click += new System.EventHandler(this.upgradeDb_212_217_Button_Click);
//
// UpgradeSelectionDlg // UpgradeSelectionDlg
// //
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(284, 262); this.ClientSize = new System.Drawing.Size(284, 262);
this.Controls.Add(this.upgradeDb_212_217_Button);
this.Controls.Add(this.upgradeDb_216_217_Button); this.Controls.Add(this.upgradeDb_216_217_Button);
this.Controls.Add(this.upgradeDbButton); this.Controls.Add(this.upgradeDb_215_217_Button);
this.Name = "UpgradeSelectionDlg"; this.Name = "UpgradeSelectionDlg";
this.Text = "Upgrade selection"; this.Text = "Upgrade selection";
this.ResumeLayout(false); this.ResumeLayout(false);
@@ -67,8 +79,9 @@
#endregion #endregion
private System.Windows.Forms.Button upgradeDbButton; private System.Windows.Forms.Button upgradeDb_215_217_Button;
private System.Windows.Forms.Button upgradeDb_216_217_Button; private System.Windows.Forms.Button upgradeDb_216_217_Button;
private System.Windows.Forms.Button upgradeDb_212_217_Button;
} }
} }
+208 -35
View File
@@ -1,51 +1,27 @@
using System; using System;
using System.Windows.Forms; using System.Windows.Forms;
using System.Collections.Generic;
using log4net;
using MySql.Data.MySqlClient; using MySql.Data.MySqlClient;
using Results;
namespace TBF.Forms namespace TBF.Forms
{ {
public partial class UpgradeSelectionDlg : Form public partial class UpgradeSelectionDlg : Form
{ {
int batchFrom; private static readonly ILog log = LogManager.GetLogger(typeof(UpgradeSelectionDlg));
int batchTo;
public UpgradeSelectionDlg() public UpgradeSelectionDlg()
{ {
InitializeComponent(); InitializeComponent();
batchFrom = 1;
batchTo = Program.LocalSettings.BatchNr - 1;
} }
private void upgradeDbButton_Click(object sender, EventArgs e) /// <summary>
{ /// Common part of database upgrade code
string[] commands = new string[] /// </summary>
{ /// <param name="dbConn">Database connection</param>
"ALTER TABLE `testrslt` ADD `ErrorFlagsMd` TINYINT( 4 ) NOT NULL DEFAULT '0' AFTER `ErrorMaster`, ADD `ErrorFlags` INT NOT NULL DEFAULT '0' AFTER `ErrorFlagsMd`, ADD `DiverterStart` FLOAT NOT NULL DEFAULT '0.001' AFTER `ErrorMaster`, ADD `DiverterEnd` FLOAT NOT NULL DEFAULT '0.001' AFTER `DiverterStart`;", /// <param name="commands">Array of SQL commands to be executed</param>
"ALTER TABLE `watermeter` ADD `ErrorFlags` INT NOT NULL DEFAULT '0' AFTER `QFall`;", /// <returns>true = successful</returns>
}; bool UpgradeCommon(MySqlConnection dbConn, string[] commands)
if (Common(new MySqlConnection(Results.DB.ConnectionString), commands))
{
upgradeDbButton.Enabled = false;
}
}
private void upgradeDb_216_217_Button_Click(object sender, EventArgs e)
{
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`;",
};
if (Common(new MySqlConnection(Results.DB.ConnectionString), commands))
{
upgradeDb_216_217_Button.Enabled = false;
}
}
bool Common(MySqlConnection dbConn, string[] commands)
{ {
bool success = false; bool success = false;
@@ -58,13 +34,15 @@ namespace TBF.Forms
MySqlCommand cmd = dbConn.CreateCommand(); MySqlCommand cmd = dbConn.CreateCommand();
cmd.CommandText = cmdText; cmd.CommandText = cmdText;
cmd.ExecuteNonQuery(); cmd.ExecuteNonQuery();
cmd.Dispose();
} }
MessageBox.Show("DB succesfully upgraded", "Confirmation", MessageBoxButtons.OK, MessageBoxIcon.Information);
success = true; success = true;
} }
catch (Exception exc) 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));
MessageBox.Show(string.Format("Exception {0}", exc.Message), "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); MessageBox.Show(string.Format("Exception {0}", exc.Message), "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
} }
finally finally
@@ -74,5 +52,200 @@ namespace TBF.Forms
return success; return success;
} }
///---------------------------------------------------------------------
private void upgradeDb_212_217_Button_Click(object sender, EventArgs e)
{
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`;",
/// 2.15 -> 2.17
"ALTER TABLE `testrslt` ADD `ErrorFlagsMd` TINYINT( 4 ) NOT NULL DEFAULT '0' AFTER `ErrorMaster`, ADD `ErrorFlags` INT NOT NULL DEFAULT '0' AFTER `ErrorFlagsMd`, 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`;",
};
if (UpgradeCommon(new MySqlConnection(Config.Data.CurrentBench.ProceduresDBSettings.ConnectionString), configDbCommands) &&
UpgradeCommon(new MySqlConnection(Results.DB.ConnectionString), resultsDbCommands))
{
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");
MessageBox.Show("DB succesfully upgraded", "Confirmation", MessageBoxButtons.OK, MessageBoxIcon.Information);
upgradeDb_212_217_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));
MessageBox.Show(string.Format("Exception {0}", exc.Message), "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
}
finally
{
dbConn.Close();
}
}
}
///---------------------------------------------------------------------
private void upgradeDb_215_217_Button_Click(object sender, EventArgs e)
{
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`, 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`;",
};
if (UpgradeCommon(new MySqlConnection(Results.DB.ConnectionString), commands))
{
MessageBox.Show("DB succesfully upgraded", "Confirmation", MessageBoxButtons.OK, MessageBoxIcon.Information);
upgradeDb_215_217_Button.Enabled = false;
}
}
///---------------------------------------------------------------------
private void upgradeDb_216_217_Button_Click(object sender, EventArgs e)
{
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`;",
};
if (UpgradeCommon(new MySqlConnection(Results.DB.ConnectionString), commands))
{
MessageBox.Show("DB succesfully upgraded", "Confirmation", MessageBoxButtons.OK, MessageBoxIcon.Information);
upgradeDb_216_217_Button.Enabled = false;
}
}
} }
} }
+14 -4
View File
@@ -343,8 +343,16 @@ namespace TBF
/// Ask what to do /// Ask what to do
switch ((new Forms.NoBenchOrDatabaseDlg { Message = Strings.NoDatabaseMsg, ShowRetry = true }).ShowDialog()) switch ((new Forms.NoBenchOrDatabaseDlg { Message = Strings.NoDatabaseMsg, ShowRetry = true }).ShowDialog())
{ {
case DialogResult.Abort: return; /// Exit program case DialogResult.Abort:
case DialogResult.Retry: break; /// Retry the loop return; /// Exit program
case DialogResult.Retry:
break; /// Retry connection to the database, stay inside the loop
case DialogResult.Yes:
new UpgradeSelectionDlg().ShowDialog();
break; /// Stay inside the loop
default: default:
/// Open 'DatabaseSetingsDlg' and retry DB connect on OK /// Open 'DatabaseSetingsDlg' and retry DB connect on OK
if (new Users.Forms.LoginDlg(true).ShowDialog() == DialogResult.Cancel || if (new Users.Forms.LoginDlg(true).ShowDialog() == DialogResult.Cancel ||
@@ -353,8 +361,10 @@ namespace TBF
return; /// Exit program return; /// Exit program
} }
Program.LocalSettings = LocalSettings.Load(Program.LocalSettingsFileName); Program.LocalSettings = LocalSettings.Load(Program.LocalSettingsFileName);
if (Program.LocalSettings == null) return; /// Fatal error if (Program.LocalSettings == null)
break; /// Retry the loop return; /// Fatal error -> Exit program
else
break; /// Stay inside the loop
} }
} }
} // if benchname is OK } // if benchname is OK
@@ -29,5 +29,5 @@ using System.Runtime.InteropServices;
// Build Number // Build Number
// Revision // Revision
// //
[assembly: AssemblyVersion("2.17.721.1")] [assembly: AssemblyVersion("2.17.722.1")]
[assembly: AssemblyFileVersion("2.17.721.1")] [assembly: AssemblyFileVersion("2.17.722.1")]