UpgradeSelectionDlg support for 2.12-->2.17, ver. 2.17.722
This commit is contained in:
parent
441cf91ff6
commit
59c2afe0e8
@ -31,84 +31,96 @@ namespace TBF.Forms
|
||||
/// </summary>
|
||||
private void InitializeComponent()
|
||||
{
|
||||
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(NoBenchOrDatabaseDlg));
|
||||
this.exitButton = new System.Windows.Forms.Button();
|
||||
this.retryButton = new System.Windows.Forms.Button();
|
||||
this.configureButton = new System.Windows.Forms.Button();
|
||||
this.pictureBox1 = new System.Windows.Forms.PictureBox();
|
||||
this.errorMessageLabel = new System.Windows.Forms.Label();
|
||||
((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).BeginInit();
|
||||
this.SuspendLayout();
|
||||
//
|
||||
// exitButton
|
||||
//
|
||||
this.exitButton.DialogResult = System.Windows.Forms.DialogResult.Cancel;
|
||||
this.exitButton.Location = new System.Drawing.Point(42, 68);
|
||||
this.exitButton.Name = "exitButton";
|
||||
this.exitButton.Size = new System.Drawing.Size(246, 33);
|
||||
this.exitButton.TabIndex = 0;
|
||||
this.exitButton.Text = "Exit";
|
||||
this.exitButton.UseVisualStyleBackColor = true;
|
||||
this.exitButton.Click += new System.EventHandler(this.exitButton_Click);
|
||||
//
|
||||
// retryButton
|
||||
//
|
||||
this.retryButton.Location = new System.Drawing.Point(42, 146);
|
||||
this.retryButton.Name = "retryButton";
|
||||
this.retryButton.Size = new System.Drawing.Size(246, 33);
|
||||
this.retryButton.TabIndex = 1;
|
||||
this.retryButton.Text = "Retry database connection";
|
||||
this.retryButton.UseVisualStyleBackColor = true;
|
||||
this.retryButton.Click += new System.EventHandler(this.retryButton_Click);
|
||||
//
|
||||
// configureButton
|
||||
//
|
||||
this.configureButton.Location = new System.Drawing.Point(42, 107);
|
||||
this.configureButton.Name = "configureButton";
|
||||
this.configureButton.Size = new System.Drawing.Size(246, 33);
|
||||
this.configureButton.TabIndex = 2;
|
||||
this.configureButton.Text = "Configure test benches (password required)";
|
||||
this.configureButton.UseVisualStyleBackColor = true;
|
||||
this.configureButton.Click += new System.EventHandler(this.configureButton_Click);
|
||||
//
|
||||
// pictureBox1
|
||||
//
|
||||
this.pictureBox1.ErrorImage = ((System.Drawing.Image)(resources.GetObject("pictureBox1.ErrorImage")));
|
||||
this.pictureBox1.Image = ((System.Drawing.Image)(resources.GetObject("pictureBox1.Image")));
|
||||
this.pictureBox1.InitialImage = null;
|
||||
this.pictureBox1.Location = new System.Drawing.Point(42, 21);
|
||||
this.pictureBox1.Name = "pictureBox1";
|
||||
this.pictureBox1.Size = new System.Drawing.Size(32, 32);
|
||||
this.pictureBox1.TabIndex = 3;
|
||||
this.pictureBox1.TabStop = false;
|
||||
//
|
||||
// errorMessageLabel
|
||||
//
|
||||
this.errorMessageLabel.AutoSize = true;
|
||||
this.errorMessageLabel.Location = new System.Drawing.Point(80, 31);
|
||||
this.errorMessageLabel.Name = "errorMessageLabel";
|
||||
this.errorMessageLabel.Size = new System.Drawing.Size(160, 13);
|
||||
this.errorMessageLabel.TabIndex = 4;
|
||||
this.errorMessageLabel.Text = "Cannot connect to the database";
|
||||
//
|
||||
// NoBenchOrDatabaseDlg
|
||||
//
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||
this.CancelButton = this.exitButton;
|
||||
this.ClientSize = new System.Drawing.Size(328, 194);
|
||||
this.Controls.Add(this.errorMessageLabel);
|
||||
this.Controls.Add(this.pictureBox1);
|
||||
this.Controls.Add(this.configureButton);
|
||||
this.Controls.Add(this.retryButton);
|
||||
this.Controls.Add(this.exitButton);
|
||||
this.Name = "NoBenchOrDatabaseDlg";
|
||||
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
|
||||
this.Text = "Error";
|
||||
this.Load += new System.EventHandler(this.NoDatabaseMsgDlg_Load);
|
||||
((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).EndInit();
|
||||
this.ResumeLayout(false);
|
||||
this.PerformLayout();
|
||||
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(NoBenchOrDatabaseDlg));
|
||||
this.exitButton = new System.Windows.Forms.Button();
|
||||
this.retryButton = new System.Windows.Forms.Button();
|
||||
this.configureButton = new System.Windows.Forms.Button();
|
||||
this.pictureBox1 = new System.Windows.Forms.PictureBox();
|
||||
this.errorMessageLabel = new System.Windows.Forms.Label();
|
||||
this.upgradeButton = new System.Windows.Forms.Button();
|
||||
((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).BeginInit();
|
||||
this.SuspendLayout();
|
||||
//
|
||||
// exitButton
|
||||
//
|
||||
this.exitButton.DialogResult = System.Windows.Forms.DialogResult.Cancel;
|
||||
this.exitButton.Location = new System.Drawing.Point(42, 68);
|
||||
this.exitButton.Name = "exitButton";
|
||||
this.exitButton.Size = new System.Drawing.Size(388, 33);
|
||||
this.exitButton.TabIndex = 0;
|
||||
this.exitButton.Text = "Exit";
|
||||
this.exitButton.UseVisualStyleBackColor = true;
|
||||
this.exitButton.Click += new System.EventHandler(this.exitButton_Click);
|
||||
//
|
||||
// retryButton
|
||||
//
|
||||
this.retryButton.Location = new System.Drawing.Point(42, 146);
|
||||
this.retryButton.Name = "retryButton";
|
||||
this.retryButton.Size = new System.Drawing.Size(388, 33);
|
||||
this.retryButton.TabIndex = 1;
|
||||
this.retryButton.Text = "Retry database connection";
|
||||
this.retryButton.UseVisualStyleBackColor = true;
|
||||
this.retryButton.Click += new System.EventHandler(this.retryButton_Click);
|
||||
//
|
||||
// configureButton
|
||||
//
|
||||
this.configureButton.Location = new System.Drawing.Point(42, 107);
|
||||
this.configureButton.Name = "configureButton";
|
||||
this.configureButton.Size = new System.Drawing.Size(388, 33);
|
||||
this.configureButton.TabIndex = 2;
|
||||
this.configureButton.Text = "Configure test benches (password required)";
|
||||
this.configureButton.UseVisualStyleBackColor = true;
|
||||
this.configureButton.Click += new System.EventHandler(this.configureButton_Click);
|
||||
//
|
||||
// pictureBox1
|
||||
//
|
||||
this.pictureBox1.ErrorImage = ((System.Drawing.Image)(resources.GetObject("pictureBox1.ErrorImage")));
|
||||
this.pictureBox1.Image = ((System.Drawing.Image)(resources.GetObject("pictureBox1.Image")));
|
||||
this.pictureBox1.InitialImage = null;
|
||||
this.pictureBox1.Location = new System.Drawing.Point(42, 21);
|
||||
this.pictureBox1.Name = "pictureBox1";
|
||||
this.pictureBox1.Size = new System.Drawing.Size(32, 32);
|
||||
this.pictureBox1.TabIndex = 3;
|
||||
this.pictureBox1.TabStop = false;
|
||||
//
|
||||
// errorMessageLabel
|
||||
//
|
||||
this.errorMessageLabel.AutoSize = true;
|
||||
this.errorMessageLabel.Location = new System.Drawing.Point(80, 31);
|
||||
this.errorMessageLabel.Name = "errorMessageLabel";
|
||||
this.errorMessageLabel.Size = new System.Drawing.Size(160, 13);
|
||||
this.errorMessageLabel.TabIndex = 4;
|
||||
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
|
||||
//
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||
this.CancelButton = this.exitButton;
|
||||
this.ClientSize = new System.Drawing.Size(466, 240);
|
||||
this.Controls.Add(this.upgradeButton);
|
||||
this.Controls.Add(this.errorMessageLabel);
|
||||
this.Controls.Add(this.pictureBox1);
|
||||
this.Controls.Add(this.configureButton);
|
||||
this.Controls.Add(this.retryButton);
|
||||
this.Controls.Add(this.exitButton);
|
||||
this.Name = "NoBenchOrDatabaseDlg";
|
||||
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
|
||||
this.Text = "Error";
|
||||
this.Load += new System.EventHandler(this.NoDatabaseMsgDlg_Load);
|
||||
((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).EndInit();
|
||||
this.ResumeLayout(false);
|
||||
this.PerformLayout();
|
||||
|
||||
}
|
||||
|
||||
@ -119,5 +131,6 @@ namespace TBF.Forms
|
||||
private System.Windows.Forms.Button configureButton;
|
||||
private System.Windows.Forms.PictureBox pictureBox1;
|
||||
private System.Windows.Forms.Label errorMessageLabel;
|
||||
private System.Windows.Forms.Button upgradeButton;
|
||||
}
|
||||
}
|
||||
@ -33,19 +33,9 @@ namespace TBF.Forms
|
||||
if (!ShowRetry) retryButton.Enabled = false;
|
||||
}
|
||||
|
||||
private void exitButton_Click(object sender, EventArgs e)
|
||||
{
|
||||
DialogResult = DialogResult.Abort;
|
||||
}
|
||||
|
||||
private void retryButton_Click(object sender, EventArgs e)
|
||||
{
|
||||
DialogResult = DialogResult.Retry;
|
||||
}
|
||||
|
||||
private void configureButton_Click(object sender, EventArgs e)
|
||||
{
|
||||
DialogResult = DialogResult.OK;
|
||||
}
|
||||
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
|
||||
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
|
||||
}
|
||||
}
|
||||
|
||||
@ -229,8 +229,8 @@
|
||||
<data name="pictureBox1.Image" type="System.Drawing.Bitmap, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
|
||||
<value>
|
||||
iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAIAAAD8GO2jAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8
|
||||
YQUAAAAgY0hSTQAAeiYAAICEAAD6AAAAgOgAAHUwAADqYAAAOpgAABdwnLpRPAAAAAlwSFlzAAAOvwAA
|
||||
Dr8BOAVTJAAACG1JREFUSEu1lmlQW9cVx/mG0GIZZCczGcZjvCQEiLHNYpABAQKEwBjTeqmXCfkQ3Mx4
|
||||
YQUAAAAgY0hSTQAAeiYAAICEAAD6AAAAgOgAAHUwAADqYAAAOpgAABdwnLpRPAAAAAlwSFlzAAAOvgAA
|
||||
Dr4B6kKxwAAACG1JREFUSEu1lmlQW9cVx/mG0GIZZCczGcZjvCQEiLHNYpABAQKEwBjTeqmXCfkQ3Mx4
|
||||
xp58SlMnY/dLmxl3TJIZu3UhBAQBsYNsisBoByS0C21oMUhCYIQkbFzqxo4n9C89TElqt/3SM1dv3tM7
|
||||
93fOPfecc1/M+n+UQCCgnJzs5PPrb9787OrVK5cvY+AGj/gTr6Cwofoaea0Bh8PR1dl5/do1Ho8nlUqd
|
||||
TudKOPxDVHCDR/yJV1CAGpQ3pv2bvMJAMBgcGBior6+XSCQhPDhm/CKRu4Nvv3Xb8vsv9J9fm77xRwev
|
||||
|
||||
@ -28,37 +28,49 @@
|
||||
/// </summary>
|
||||
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_212_217_Button = new System.Windows.Forms.Button();
|
||||
this.SuspendLayout();
|
||||
//
|
||||
// upgradeDbButton
|
||||
// upgradeDb_215_217_Button
|
||||
//
|
||||
this.upgradeDbButton.Location = new System.Drawing.Point(12, 12);
|
||||
this.upgradeDbButton.Name = "upgradeDbButton";
|
||||
this.upgradeDbButton.Size = new System.Drawing.Size(260, 34);
|
||||
this.upgradeDbButton.TabIndex = 0;
|
||||
this.upgradeDbButton.Text = "Upgrade database from ver. 2.15 to ver. 2.17";
|
||||
this.upgradeDbButton.UseVisualStyleBackColor = true;
|
||||
this.upgradeDbButton.Click += new System.EventHandler(this.upgradeDbButton_Click);
|
||||
this.upgradeDb_215_217_Button.Location = new System.Drawing.Point(12, 52);
|
||||
this.upgradeDb_215_217_Button.Name = "upgradeDb_215_217_Button";
|
||||
this.upgradeDb_215_217_Button.Size = new System.Drawing.Size(260, 34);
|
||||
this.upgradeDb_215_217_Button.TabIndex = 1;
|
||||
this.upgradeDb_215_217_Button.Text = "Upgrade database from ver. 2.15 to ver. 2.17";
|
||||
this.upgradeDb_215_217_Button.UseVisualStyleBackColor = true;
|
||||
this.upgradeDb_215_217_Button.Click += new System.EventHandler(this.upgradeDb_215_217_Button_Click);
|
||||
//
|
||||
// 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.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.UseVisualStyleBackColor = true;
|
||||
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
|
||||
//
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||
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.upgradeDbButton);
|
||||
this.Controls.Add(this.upgradeDb_215_217_Button);
|
||||
this.Name = "UpgradeSelectionDlg";
|
||||
this.Text = "Upgrade selection";
|
||||
this.ResumeLayout(false);
|
||||
@ -67,8 +79,9 @@
|
||||
|
||||
#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_212_217_Button;
|
||||
|
||||
}
|
||||
}
|
||||
@ -1,54 +1,30 @@
|
||||
using System;
|
||||
using System.Windows.Forms;
|
||||
using System.Collections.Generic;
|
||||
using log4net;
|
||||
using MySql.Data.MySqlClient;
|
||||
using Results;
|
||||
|
||||
namespace TBF.Forms
|
||||
{
|
||||
public partial class UpgradeSelectionDlg : Form
|
||||
{
|
||||
int batchFrom;
|
||||
int batchTo;
|
||||
private static readonly ILog log = LogManager.GetLogger(typeof(UpgradeSelectionDlg));
|
||||
|
||||
public UpgradeSelectionDlg()
|
||||
{
|
||||
InitializeComponent();
|
||||
batchFrom = 1;
|
||||
batchTo = Program.LocalSettings.BatchNr - 1;
|
||||
}
|
||||
|
||||
private void upgradeDbButton_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 (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)
|
||||
/// <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 UpgradeCommon(MySqlConnection dbConn, string[] commands)
|
||||
{
|
||||
bool success = false;
|
||||
|
||||
|
||||
try
|
||||
{
|
||||
dbConn.Open();
|
||||
@ -58,13 +34,15 @@ namespace TBF.Forms
|
||||
MySqlCommand cmd = dbConn.CreateCommand();
|
||||
cmd.CommandText = cmdText;
|
||||
cmd.ExecuteNonQuery();
|
||||
cmd.Dispose();
|
||||
}
|
||||
|
||||
MessageBox.Show("DB succesfully upgraded", "Confirmation", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
||||
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));
|
||||
MessageBox.Show(string.Format("Exception {0}", exc.Message), "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
|
||||
}
|
||||
finally
|
||||
@ -74,5 +52,200 @@ namespace TBF.Forms
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -305,14 +305,14 @@ namespace TBF
|
||||
Results.DB.DbType = Config.Data.CurrentBench.WaterMetersDBSettings.DbType;
|
||||
Results.DB.ConnectionString = Config.Data.CurrentBench.WaterMetersDBSettings.ConnectionString;
|
||||
Results.DB.LoadSharedData();
|
||||
int maxBatchNr = Results.DB.GetMaxSavedBatchNr();
|
||||
int maxBatchNr = Results.DB.GetMaxSavedBatchNr();
|
||||
if (!Config.Data.CurrentBench.IsRealBench || Program.LocalSettings.BatchNr <= maxBatchNr)
|
||||
{
|
||||
log.FatalFormat("Max. BatchNr in DB = {0}, LocalSettings.BatchNr = {1}", maxBatchNr, Program.LocalSettings.BatchNr);
|
||||
Program.LocalSettings.BatchNr = maxBatchNr + 1;
|
||||
Program.LocalSettings.Save();
|
||||
log.FatalFormat("LocalSettings.BatchNr updated to {0}", Program.LocalSettings.BatchNr);
|
||||
}
|
||||
{
|
||||
log.FatalFormat("Max. BatchNr in DB = {0}, LocalSettings.BatchNr = {1}", maxBatchNr, Program.LocalSettings.BatchNr);
|
||||
Program.LocalSettings.BatchNr = maxBatchNr + 1;
|
||||
Program.LocalSettings.Save();
|
||||
log.FatalFormat("LocalSettings.BatchNr updated to {0}", Program.LocalSettings.BatchNr);
|
||||
}
|
||||
|
||||
/// This is to trigger an exception in case of a power user and no Config database
|
||||
IList<Procedure> listOfProcedures = Config.FluentCommon.CreateSession(Users.Entities.DBKind.Config)
|
||||
@ -343,18 +343,28 @@ namespace TBF
|
||||
/// Ask what to do
|
||||
switch ((new Forms.NoBenchOrDatabaseDlg { Message = Strings.NoDatabaseMsg, ShowRetry = true }).ShowDialog())
|
||||
{
|
||||
case DialogResult.Abort: return; /// Exit program
|
||||
case DialogResult.Retry: break; /// Retry the loop
|
||||
case DialogResult.Abort:
|
||||
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:
|
||||
/// Open 'DatabaseSetingsDlg' and retry DB connect on OK
|
||||
if (new Users.Forms.LoginDlg(true).ShowDialog() == DialogResult.Cancel ||
|
||||
new BenchesDlg().ShowDialog() == DialogResult.Cancel)
|
||||
{
|
||||
return; /// Exit program
|
||||
return; /// Exit program
|
||||
}
|
||||
Program.LocalSettings = LocalSettings.Load(Program.LocalSettingsFileName);
|
||||
if (Program.LocalSettings == null) return; /// Fatal error
|
||||
break; /// Retry the loop
|
||||
if (Program.LocalSettings == null)
|
||||
return; /// Fatal error -> Exit program
|
||||
else
|
||||
break; /// Stay inside the loop
|
||||
}
|
||||
}
|
||||
} // if benchname is OK
|
||||
|
||||
@ -29,5 +29,5 @@ using System.Runtime.InteropServices;
|
||||
// Build Number
|
||||
// Revision
|
||||
//
|
||||
[assembly: AssemblyVersion("2.17.721.1")]
|
||||
[assembly: AssemblyFileVersion("2.17.721.1")]
|
||||
[assembly: AssemblyVersion("2.17.722.1")]
|
||||
[assembly: AssemblyFileVersion("2.17.722.1")]
|
||||
|
||||
Loading…
Reference in New Issue
Block a user