From 66631855bbb81143bbe70c00a2a5a4ba916afeb2 Mon Sep 17 00:00:00 2001 From: Milan Hanajik Date: Mon, 6 Apr 2020 22:46:42 +0200 Subject: [PATCH] UpgradeSelectionDlg : 2.25 --> 2.26 --- .../Settings/UpgradeSelectionDlg.Designer.cs | 25 ++++-- TBF/UI/Settings/UpgradeSelectionDlg.cs | 89 +++++++++++++++++-- 2 files changed, 101 insertions(+), 13 deletions(-) diff --git a/TBF/UI/Settings/UpgradeSelectionDlg.Designer.cs b/TBF/UI/Settings/UpgradeSelectionDlg.Designer.cs index b6ede9c6d..266c53c19 100644 --- a/TBF/UI/Settings/UpgradeSelectionDlg.Designer.cs +++ b/TBF/UI/Settings/UpgradeSelectionDlg.Designer.cs @@ -47,6 +47,7 @@ this.upgradeDb_224_225_Button = new System.Windows.Forms.Button(); this.errorFlagsComponentsTextBox = new System.Windows.Forms.TextBox(); this.label3 = new System.Windows.Forms.Label(); + this.upgradeDb_225_226_Button = new System.Windows.Forms.Button(); this.SuspendLayout(); // // upgradeDb_215_216_Button @@ -123,7 +124,7 @@ // this.textBox1.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); this.textBox1.Enabled = false; - this.textBox1.Location = new System.Drawing.Point(94, 493); + this.textBox1.Location = new System.Drawing.Point(94, 535); this.textBox1.Name = "textBox1"; this.textBox1.Size = new System.Drawing.Size(100, 20); this.textBox1.TabIndex = 11; @@ -132,7 +133,7 @@ // this.textBox2.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); this.textBox2.Enabled = false; - this.textBox2.Location = new System.Drawing.Point(94, 519); + this.textBox2.Location = new System.Drawing.Point(94, 561); this.textBox2.Name = "textBox2"; this.textBox2.Size = new System.Drawing.Size(100, 20); this.textBox2.TabIndex = 13; @@ -142,7 +143,7 @@ this.label1.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); this.label1.AutoSize = true; this.label1.Enabled = false; - this.label1.Location = new System.Drawing.Point(12, 496); + this.label1.Location = new System.Drawing.Point(12, 538); this.label1.Name = "label1"; this.label1.Size = new System.Drawing.Size(70, 13); this.label1.TabIndex = 10; @@ -153,7 +154,7 @@ this.label2.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); this.label2.AutoSize = true; this.label2.Enabled = false; - this.label2.Location = new System.Drawing.Point(12, 522); + this.label2.Location = new System.Drawing.Point(12, 564); this.label2.Name = "label2"; this.label2.Size = new System.Drawing.Size(60, 13); this.label2.TabIndex = 12; @@ -163,7 +164,7 @@ // this.pressureRepresentationButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); this.pressureRepresentationButton.Enabled = false; - this.pressureRepresentationButton.Location = new System.Drawing.Point(207, 493); + this.pressureRepresentationButton.Location = new System.Drawing.Point(207, 535); this.pressureRepresentationButton.Name = "pressureRepresentationButton"; this.pressureRepresentationButton.Size = new System.Drawing.Size(65, 42); this.pressureRepresentationButton.TabIndex = 14; @@ -237,11 +238,22 @@ this.label3.TabIndex = 18; this.label3.Text = "ErrFlags1~E.."; // + // upgradeDb_225_226_Button + // + this.upgradeDb_225_226_Button.Location = new System.Drawing.Point(13, 484); + this.upgradeDb_225_226_Button.Name = "upgradeDb_225_226_Button"; + this.upgradeDb_225_226_Button.Size = new System.Drawing.Size(260, 34); + this.upgradeDb_225_226_Button.TabIndex = 19; + this.upgradeDb_225_226_Button.Text = "Upgrade DB from v.2.25 to v.2.26 (calendar)"; + this.upgradeDb_225_226_Button.UseVisualStyleBackColor = true; + this.upgradeDb_225_226_Button.Click += new System.EventHandler(this.upgradeDb_225_226_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, 555); + this.ClientSize = new System.Drawing.Size(284, 597); + this.Controls.Add(this.upgradeDb_225_226_Button); this.Controls.Add(this.label3); this.Controls.Add(this.errorFlagsComponentsTextBox); this.Controls.Add(this.upgradeDb_224_225_Button); @@ -289,6 +301,7 @@ private System.Windows.Forms.Button upgradeDb_224_225_Button; private System.Windows.Forms.TextBox errorFlagsComponentsTextBox; private System.Windows.Forms.Label label3; + private System.Windows.Forms.Button upgradeDb_225_226_Button; } } \ No newline at end of file diff --git a/TBF/UI/Settings/UpgradeSelectionDlg.cs b/TBF/UI/Settings/UpgradeSelectionDlg.cs index 01d0efd78..2335db716 100644 --- a/TBF/UI/Settings/UpgradeSelectionDlg.cs +++ b/TBF/UI/Settings/UpgradeSelectionDlg.cs @@ -71,8 +71,9 @@ namespace TBF.UI.Settings /// true = successful bool ExecuteCommands(MySqlConnection dbConn, string[] commands) { - bool success = false; + if (commands.Length == 0) return true; + bool success = false; try { dbConn.Open(); @@ -84,7 +85,6 @@ namespace TBF.UI.Settings cmd.ExecuteNonQuery(); cmd.Dispose(); } - success = true; } catch (Exception exc) @@ -557,7 +557,8 @@ namespace TBF.UI.Settings 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`;", + "ALTER TABLE `testrslt` ADD `ErrorFlagsMd` TINYINT( 4 ) NOT NULL DEFAULT '0' AFTER `ErrorMaster`," + + " ADD `ErrorFlags` INT NOT NULL DEFAULT '0' AFTER `ErrorFlagsMd`;", }; ActivityStart(); @@ -581,7 +582,8 @@ namespace TBF.UI.Settings 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 `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`;", }; @@ -631,9 +633,22 @@ namespace TBF.UI.Settings string[] resultsDbCommands = 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 `TimeBtwnMassMsrmnts` INT NOT NULL DEFAULT '0' AFTER `FlowSetTime`, ADD `TestTimeCorrection` DOUBLE NOT NULL DEFAULT '0' AFTER `TestTime`, ADD `ConstMasterRaw` DOUBLE NOT NULL DEFAULT '1' AFTER `PulsesMaster`, ADD `ConstMasterCorr` DOUBLE NOT NULL DEFAULT '1' AFTER `ConstMasterRaw`;", + "ALTER TABLE `testrslt` ADD `MethodClass` VARCHAR(255) NULL DEFAULT NULL AFTER `RepetitionNr`," + + " ADD `TimeBtwnMassMsrmnts` INT NOT NULL DEFAULT '0' AFTER `FlowSetTime`," + + " ADD `TestTimeCorrection` DOUBLE NOT NULL DEFAULT '0' AFTER `TestTime`," + + " 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`;", - "ALTER TABLE `batch` ADD `Counter1` INT NOT NULL DEFAULT '0' AFTER `Custom3`, ADD `Counter2` INT NOT NULL DEFAULT '0' AFTER `Counter1`, ADD `Counter3` INT NOT NULL DEFAULT '0' AFTER `Counter2`, ADD `Counter4` INT NOT NULL DEFAULT '0' AFTER `Counter3`, ADD `Counter5` INT NOT NULL DEFAULT '0' AFTER `Counter4`, ADD `Counter6` INT NOT NULL DEFAULT '0' AFTER `Counter5`, ADD `Counter7` INT NOT NULL DEFAULT '0' AFTER `Counter6`, ADD `Counter8` INT NOT NULL DEFAULT '0' AFTER `Counter7`, ADD `Counter9` INT NOT NULL DEFAULT '0' AFTER `Counter8`, ADD `Counter10` INT NOT NULL DEFAULT '0' AFTER `Counter9`;", + "ALTER TABLE `batch` ADD `Counter1` INT NOT NULL DEFAULT '0' AFTER `Custom3`," + + " ADD `Counter2` INT NOT NULL DEFAULT '0' AFTER `Counter1`," + + " ADD `Counter3` INT NOT NULL DEFAULT '0' AFTER `Counter2`," + + " ADD `Counter4` INT NOT NULL DEFAULT '0' AFTER `Counter3`," + + " ADD `Counter5` INT NOT NULL DEFAULT '0' AFTER `Counter4`," + + " ADD `Counter6` INT NOT NULL DEFAULT '0' AFTER `Counter5`," + + " ADD `Counter7` INT NOT NULL DEFAULT '0' AFTER `Counter6`," + + " ADD `Counter8` INT NOT NULL DEFAULT '0' AFTER `Counter7`," + + " ADD `Counter9` INT NOT NULL DEFAULT '0' AFTER `Counter8`," + + " ADD `Counter10` INT NOT NULL DEFAULT '0' AFTER `Counter9`;", }; ActivityStart(); @@ -751,7 +766,11 @@ namespace TBF.UI.Settings { "ALTER TABLE `testdata` ADD `Qtg` DOUBLE NULL DEFAULT NULL AFTER `Name`;", - "ALTER TABLE `testrslt` ADD `Uncertnt` FLOAT NOT NULL DEFAULT '0' AFTER `FlowMax`, ADD `UncertntScale` FLOAT NOT NULL DEFAULT '0' AFTER `Uncertnt`, ADD `UncertntDensity` FLOAT NOT NULL DEFAULT '0' AFTER `UncertntScale`, ADD `UncertntTemp` FLOAT NOT NULL DEFAULT '0' AFTER `UncertntDensity`, ADD `UncertntPressure` FLOAT NOT NULL DEFAULT '0' AFTER `UncertntTemp`;", + "ALTER TABLE `testrslt` ADD `Uncertnt` FLOAT NOT NULL DEFAULT '0' AFTER `FlowMax`," + + " ADD `UncertntScale` FLOAT NOT NULL DEFAULT '0' AFTER `Uncertnt`," + + " ADD `UncertntDensity` FLOAT NOT NULL DEFAULT '0' AFTER `UncertntScale`," + + " ADD `UncertntTemp` FLOAT NOT NULL DEFAULT '0' AFTER `UncertntDensity`," + + " ADD `UncertntPressure` FLOAT NOT NULL DEFAULT '0' AFTER `UncertntTemp`;", "ALTER TABLE `testrslt` CHANGE `ErrorFlags` `ErrorFlags` BIGINT(20) NOT NULL DEFAULT '0', CHANGE `ErrorFlagsMd` `InfoFlags` BIGINT(20) NOT NULL DEFAULT '0';", "ALTER TABLE `watermeter` CHANGE `ErrorFlags` `ErrorFlags` BIGINT(20) NOT NULL DEFAULT '0', ADD `InfoFlags` BIGINT NOT NULL DEFAULT '0' AFTER `ErrorFlags`;", @@ -898,6 +917,62 @@ namespace TBF.UI.Settings } } + private void upgradeDb_225_226_Button_Click(object sender, EventArgs e) + { + if (!upgradeConfigDBCheckBox.Checked && !upgradeResultsDBCheckBox.Checked) + { + MessageBox.Show("No database selected"); + return; + } + + string[] configDbCommands = new string[] + { + "ALTER TABLE `procedure` ADD `EventTriggers` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL AFTER `ResultsWriter`;", + + "CREATE TABLE IF NOT EXISTS `customevent` (" + + "`Id` int(11) NOT NULL," + + " `Date` datetime DEFAULT NULL," + + " `Frequency` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL," + + " `AllDay` tinyint(1) DEFAULT NULL," + + " `TriggerOnExactDayOnly` tinyint(1) DEFAULT NULL," + + " `Source` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL," + + " `Title` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL," + + " `AutoAction` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL," + + " `Parameters` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL," + + " `Rank` int(11) DEFAULT NULL," + + " `Hidden` tinyint(1) DEFAULT NULL," + + " `ReadOnly` tinyint(1) DEFAULT NULL," + + " `BackColor` int(11) DEFAULT NULL," + + " `TextColor` int(11) DEFAULT NULL," + + " `TooltipEnabled` tinyint(1) DEFAULT NULL) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=1;", + + "ALTER TABLE `customevent` ADD PRIMARY KEY (`Id`);", + + "ALTER TABLE `customevent` MODIFY `Id` int(11) NOT NULL AUTO_INCREMENT;", + }; + + string[] resultsDbCommands = new string[] + { +#if TURA_IPERL || TURA_IPERL_NEW || TURA_SPECIAL + "ALTER TABLE `testrslt` ADD `ConductMean` FLOAT NULL DEFAULT NULL AFTER `FlowMax`," + + " ADD `ConductStart` FLOAT NULL DEFAULT NULL AFTER `ConductMean`," + + " ADD `ConductEnd` FLOAT NULL DEFAULT NULL AFTER `ConductStart`," + + " ADD `ConductMin` FLOAT NULL DEFAULT NULL AFTER `ConductEnd`," + + " ADD `ConductMax` FLOAT NULL DEFAULT NULL AFTER `ConductMin`;", +#endif + }; + + 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_225_226_Button.Enabled = false; + } + } + private void pressureRepresentationButton_Click(object sender, EventArgs e) { try