2020-01-09 09:00:14 +00:00
///
/// Copyright (c) 2016-2020 Sensus slovensko a.s.
///
using System ;
2018-03-12 05:37:08 +00:00
using System.Drawing ;
2016-08-03 07:59:55 +00:00
using System.Windows.Forms ;
2017-10-31 08:45:29 +00:00
using System.Collections.Generic ;
using log4net ;
2017-10-03 01:04:06 +00:00
using MySql.Data.MySqlClient ;
2018-03-13 06:44:33 +00:00
using NHibernate ;
2019-09-16 08:51:25 +00:00
using Results ;
2018-03-13 06:44:33 +00:00
using Results.Entities ;
2018-03-12 05:37:08 +00:00
using TBF.Resources ;
2020-12-08 07:51:07 +00:00
using System.Text ;
2016-08-03 07:59:55 +00:00
2019-09-16 08:51:25 +00:00
namespace TBF.UI.Settings
2016-08-03 07:59:55 +00:00
{
public partial class UpgradeSelectionDlg : Form
{
2017-10-31 08:45:29 +00:00
private static readonly ILog log = LogManager . GetLogger ( typeof ( UpgradeSelectionDlg ) ) ;
2016-08-15 14:54:12 +00:00
2018-03-13 06:44:33 +00:00
int batchFrom ;
int batchTo ;
2019-09-16 08:51:25 +00:00
Shared . ModelessActivityForm form ;
2018-03-12 05:37:08 +00:00
System . Threading . Thread formThread ;
2016-08-03 07:59:55 +00:00
public UpgradeSelectionDlg ( )
{
InitializeComponent ( ) ;
2018-03-13 06:44:33 +00:00
2018-03-15 02:42:19 +00:00
upgradeConfigDBCheckBox . Checked = true ;
upgradeResultsDBCheckBox . Checked = true ;
2018-03-13 06:44:33 +00:00
batchFrom = 1 ;
batchTo = Program . LocalSettings . BatchNr - 1 ;
textBox1 . Text = batchFrom . ToString ( ) ;
textBox2 . Text = batchTo . ToString ( ) ;
2016-08-03 07:59:55 +00:00
}
2018-03-12 05:37:08 +00:00
void ActivityStart ( )
{
2019-09-16 08:51:25 +00:00
form = new Shared . ModelessActivityForm ( )
2020-01-09 09:00:14 +00:00
{
Message = "Upgrading database" ,
FontFamily = "Arial" ,
FontSize = 24 ,
FontStyle = FontStyle . Regular ,
BackgroundColor = Color . Green ,
} ;
2018-03-12 05:37:08 +00:00
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 ;
}
2017-10-31 08:45:29 +00:00
/// <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>
2018-03-12 05:37:08 +00:00
bool ExecuteCommands ( MySqlConnection dbConn , string [ ] commands )
2017-10-24 13:18:31 +00:00
{
2020-04-06 20:46:42 +00:00
if ( commands . Length = = 0 ) return true ;
2017-10-31 08:45:29 +00:00
2020-04-06 20:46:42 +00:00
bool success = false ;
2016-08-15 14:54:12 +00:00
try
{
2017-10-03 01:04:06 +00:00
dbConn . Open ( ) ;
2016-08-15 14:54:12 +00:00
2017-10-03 01:04:06 +00:00
foreach ( var cmdText in commands )
2016-08-15 14:54:12 +00:00
{
2017-10-03 01:04:06 +00:00
MySqlCommand cmd = dbConn . CreateCommand ( ) ;
cmd . CommandText = cmdText ;
cmd . ExecuteNonQuery ( ) ;
2017-10-31 08:45:29 +00:00
cmd . Dispose ( ) ;
2016-08-15 14:54:12 +00:00
}
2017-10-24 13:18:31 +00:00
success = true ;
2016-08-15 14:54:12 +00:00
}
catch ( Exception exc )
{
2017-10-31 08:45:29 +00:00
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 ) ) ;
2018-03-12 05:37:08 +00:00
ActivityEnd ( ) ;
2017-10-03 01:04:06 +00:00
MessageBox . Show ( string . Format ( "Exception {0}" , exc . Message ) , "Error" , MessageBoxButtons . OK , MessageBoxIcon . Exclamation ) ;
}
finally
{
dbConn . Close ( ) ;
2016-08-15 14:54:12 +00:00
}
2017-10-24 13:18:31 +00:00
return success ;
2016-08-03 07:59:55 +00:00
}
2017-10-31 08:45:29 +00:00
2020-01-09 09:00:14 +00:00
/// <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 ChangeErrorFlags ( string errorFlagsCmpntName )
{
bool success = false ;
ISession session = null ;
try
{
session = Config . FluentCommon . CreateSession ( Users . Entities . DBKind . Config ) ;
var testParams = session . QueryOver < Config . Entities . ComponentTest > ( )
. Where ( x = > ( x . CmpntName = = errorFlagsCmpntName ) )
. List ( ) ;
foreach ( var tp in testParams )
{
string temp ;
if ( tp . Parameters . Contains ( "<Mode>Info</Mode>" ) )
{
temp = tp . Parameters . Replace ( "true" , "1" ) ;
}
else if ( tp . Parameters . Contains ( "<Mode>On</Mode>" ) )
{
temp = tp . Parameters . Replace ( "true" , "2" ) ;
}
else
{
temp = tp . Parameters . Replace ( "true" , "0" ) ;
}
tp . Parameters = temp . Replace ( "false" , "0" ) ;
session . SaveOrUpdate ( tp ) ;
}
session . Flush ( ) ;
success = true ;
}
catch ( Exception exc )
{
ActivityEnd ( ) ;
MessageBox . Show ( string . Format ( "Upgrade failed:\r\n{0}" , exc . Message ) ,
"Error" , MessageBoxButtons . OK , MessageBoxIcon . Information ) ;
}
finally
{
if ( session ! = null ) session . Close ( ) ;
}
return success ;
}
2018-05-17 15:22:50 +00:00
///---------------------------------------------------------------------
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 ;
}
}
2018-03-14 03:01:46 +00:00
///---------------------------------------------------------------------
private void upgradeDb_24_29_Button_Click ( object sender , EventArgs e )
{
2018-03-15 02:42:19 +00:00
if ( ! upgradeConfigDBCheckBox . Checked & & ! upgradeResultsDBCheckBox . Checked )
{
MessageBox . Show ( "No database selected" ) ;
return ;
}
2020-01-09 09:00:14 +00:00
2018-03-14 03:01:46 +00:00
string [ ] configDbCommands = new string [ ]
{
/// 2.4 -> 2.5
2018-03-15 02:42:19 +00:00
"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`" ,
2018-03-14 03:01:46 +00:00
/// 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 ---
} ;
2018-03-15 02:42:19 +00:00
ActivityStart ( ) ;
2018-03-14 03:01:46 +00:00
if ( ( ! upgradeConfigDBCheckBox . Checked | | ExecuteCommands ( new MySqlConnection ( Config . Data . CurrentBench . ProceduresDBSettings . ConnectionString ) , configDbCommands ) ) & &
2019-09-16 08:51:25 +00:00
( ! upgradeResultsDBCheckBox . Checked | | ExecuteCommands ( new MySqlConnection ( DB . ConnectionString ) , resultsDbCommands ) ) )
2018-03-14 03:01:46 +00:00
{
ActivityEnd ( ) ;
MessageBox . Show ( "DB succesfully upgraded" , "Confirmation" , MessageBoxButtons . OK , MessageBoxIcon . Information ) ;
upgradeDb_24_29_Button . Enabled = false ;
}
}
2017-10-31 08:45:29 +00:00
2018-03-12 05:37:08 +00:00
///---------------------------------------------------------------------
private void upgradeDb_29_212_Button_Click ( object sender , EventArgs e )
{
2018-03-15 02:42:19 +00:00
if ( ! upgradeConfigDBCheckBox . Checked & & ! upgradeResultsDBCheckBox . Checked )
{
MessageBox . Show ( "No database selected" ) ;
return ;
}
2020-01-09 09:00:14 +00:00
2018-03-12 05:37:08 +00:00
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`" ,
} ;
2018-03-15 02:42:19 +00:00
ActivityStart ( ) ;
2018-03-12 05:37:08 +00:00
if ( ( ! upgradeConfigDBCheckBox . Checked | | ExecuteCommands ( new MySqlConnection ( Config . Data . CurrentBench . ProceduresDBSettings . ConnectionString ) , configDbCommands ) ) & &
2019-09-16 08:51:25 +00:00
( ! upgradeResultsDBCheckBox . Checked | | ExecuteCommands ( new MySqlConnection ( DB . ConnectionString ) , resultsDbCommands ) ) )
2018-03-12 05:37:08 +00:00
{
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 ( ) ;
2019-01-14 15:12:55 +00:00
cmd = dbConn . CreateCommand ( ) ;
cmd . CommandText = "UPDATE component SET ClassName = 'TestMethods.FixedStartMassCollection.Compound' WHERE ClassName = 'FixedStartCombinedMeters'" ;
cmd . ExecuteNonQuery ( ) ;
cmd . Dispose ( ) ;
2018-03-12 05:37:08 +00:00
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 ( ) ;
}
}
2018-03-14 03:01:46 +00:00
else
{
ActivityEnd ( ) ;
MessageBox . Show ( "DB succesfully upgraded" , "Confirmation" , MessageBoxButtons . OK , MessageBoxIcon . Information ) ;
upgradeDb_29_212_Button . Enabled = false ;
}
2018-03-12 05:37:08 +00:00
}
}
2020-01-09 09:00:14 +00:00
2018-03-12 05:37:08 +00:00
///---------------------------------------------------------------------
private void upgradeDb_212_215_Button_Click ( object sender , EventArgs e )
2017-10-31 08:45:29 +00:00
{
2018-03-15 02:42:19 +00:00
if ( ! upgradeConfigDBCheckBox . Checked & & ! upgradeResultsDBCheckBox . Checked )
{
MessageBox . Show ( "No database selected" ) ;
return ;
}
2018-03-12 05:37:08 +00:00
2017-10-31 08:45:29 +00:00
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`;" ,
} ;
2018-03-15 02:42:19 +00:00
ActivityStart ( ) ;
2018-03-12 05:37:08 +00:00
if ( ( ! upgradeConfigDBCheckBox . Checked | | ExecuteCommands ( new MySqlConnection ( Config . Data . CurrentBench . ProceduresDBSettings . ConnectionString ) , configDbCommands ) ) & &
2019-09-16 08:51:25 +00:00
( ! upgradeResultsDBCheckBox . Checked | | ExecuteCommands ( new MySqlConnection ( DB . ConnectionString ) , resultsDbCommands ) ) )
2017-10-31 08:45:29 +00:00
{
2018-03-12 05:37:08 +00:00
if ( upgradeConfigDBCheckBox . Checked )
2017-10-31 08:45:29 +00:00
{
2018-03-12 05:37:08 +00:00
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 ( ) ;
2017-10-31 08:45:29 +00:00
2018-03-12 05:37:08 +00:00
cmd = dbConn . CreateCommand ( ) ;
cmd . CommandText = "UPDATE component SET ClassName = 'RegisterReader for standing start/stop' WHERE ClassName = 'Fixed-Start-Register-Reader'" ;
cmd . ExecuteNonQuery ( ) ;
cmd . Dispose ( ) ;
2017-10-31 08:45:29 +00:00
2018-03-12 05:37:08 +00:00
cmd = dbConn . CreateCommand ( ) ;
cmd . CommandText = "UPDATE component SET ClassName = 'TestMethods.iPerlCommunication' WHERE ClassName = 'iPerlCommunication'" ;
cmd . ExecuteNonQuery ( ) ;
cmd . Dispose ( ) ;
2017-10-31 08:45:29 +00:00
2018-03-12 05:37:08 +00:00
cmd = dbConn . CreateCommand ( ) ;
cmd . CommandText = "UPDATE component SET ClassName = 'WaterMeter' WHERE ClassName = 'iPerl'" ;
cmd . ExecuteNonQuery ( ) ;
2017-10-31 08:45:29 +00:00
cmd . Dispose ( ) ;
2018-03-12 05:37:08 +00:00
for ( int i = 1 ; i < = 40 ; i + + )
{
Text = string . Format ( "Upgrade selection: {0}/40" , i ) ;
2017-10-31 08:45:29 +00:00
2018-03-12 05:37:08 +00:00
/// Read original iPerl water meter parameters
int id = 0 ;
string parameters = string . Empty ;
2017-10-31 08:45:29 +00:00
cmd = dbConn . CreateCommand ( ) ;
2018-03-12 05:37:08 +00:00
cmd . CommandText = string . Format ( "SELECT Id, Parameters FROM Component WHERE Name = 'iPerl{0}' AND ClassName = 'WaterMeter'" , i ) ;
2017-10-31 08:45:29 +00:00
dr = cmd . ExecuteReader ( ) ;
2018-03-12 05:37:08 +00:00
if ( dr . Read ( ) )
2017-10-31 08:45:29 +00:00
{
2018-03-12 05:37:08 +00:00
id = dr . GetInt32 ( 0 ) ;
parameters = dr . GetString ( 1 ) ;
2017-10-31 08:45:29 +00:00
}
dr . Close ( ) ;
cmd . Dispose ( ) ;
2018-03-12 05:37:08 +00:00
if ( id ! = 0 )
2017-10-31 08:45:29 +00:00
{
2018-03-12 05:37:08 +00:00
/// 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 ( ) )
2017-10-31 08:45:29 +00:00
{
2018-03-12 05:37:08 +00:00
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 ( ) ;
}
2017-10-31 08:45:29 +00:00
}
}
}
2018-03-12 05:37:08 +00:00
/// 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 ( ) ;
2017-10-31 08:45:29 +00:00
2018-03-12 05:37:08 +00:00
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 ( ) ;
}
2017-10-31 08:45:29 +00:00
}
2018-03-15 02:42:19 +00:00
else
{
ActivityEnd ( ) ;
MessageBox . Show ( "DB succesfully upgraded" , "Confirmation" , MessageBoxButtons . OK , MessageBoxIcon . Information ) ;
upgradeDb_212_215_Button . Enabled = false ;
}
2017-10-31 08:45:29 +00:00
}
}
2020-01-09 09:00:14 +00:00
///---------------------------------------------------------------------
private void upgradeDb_215_216_Button_Click ( object sender , EventArgs e )
2017-10-31 08:45:29 +00:00
{
2018-03-15 02:42:19 +00:00
if ( ! upgradeConfigDBCheckBox . Checked & & ! upgradeResultsDBCheckBox . Checked )
{
MessageBox . Show ( "No database selected" ) ;
return ;
}
2018-03-12 05:37:08 +00:00
2017-10-31 08:45:29 +00:00
string [ ] commands = new string [ ]
{
2020-04-06 20:46:42 +00:00
"ALTER TABLE `testrslt` ADD `ErrorFlagsMd` TINYINT( 4 ) NOT NULL DEFAULT '0' AFTER `ErrorMaster`," +
" ADD `ErrorFlags` INT NOT NULL DEFAULT '0' AFTER `ErrorFlagsMd`;" ,
2017-10-31 08:45:29 +00:00
} ;
2018-03-15 02:42:19 +00:00
ActivityStart ( ) ;
2019-09-16 08:51:25 +00:00
if ( ! upgradeResultsDBCheckBox . Checked | | ExecuteCommands ( new MySqlConnection ( DB . ConnectionString ) , commands ) )
2017-10-31 08:45:29 +00:00
{
2018-03-12 05:37:08 +00:00
ActivityEnd ( ) ;
2017-10-31 08:45:29 +00:00
MessageBox . Show ( "DB succesfully upgraded" , "Confirmation" , MessageBoxButtons . OK , MessageBoxIcon . Information ) ;
2018-03-12 05:37:08 +00:00
upgradeDb_215_216_Button . Enabled = false ;
2017-10-31 08:45:29 +00:00
}
2018-03-12 05:37:08 +00:00
}
2017-10-31 08:45:29 +00:00
2020-01-09 09:00:14 +00:00
///---------------------------------------------------------------------
private void upgradeDb_216_217_Button_Click ( object sender , EventArgs e )
2017-10-31 08:45:29 +00:00
{
2018-03-15 02:42:19 +00:00
if ( ! upgradeConfigDBCheckBox . Checked & & ! upgradeResultsDBCheckBox . Checked )
{
MessageBox . Show ( "No database selected" ) ;
return ;
}
2018-03-12 05:37:08 +00:00
2017-10-31 08:45:29 +00:00
string [ ] commands = new string [ ]
{
2020-04-06 20:46:42 +00:00
"ALTER TABLE `testrslt` ADD `DiverterStart` FLOAT NOT NULL DEFAULT '0.001' AFTER `ErrorMaster`," +
" ADD `DiverterEnd` FLOAT NOT NULL DEFAULT '0.001' AFTER `DiverterStart`;" ,
2017-10-31 08:45:29 +00:00
"ALTER TABLE `watermeter` ADD `ErrorFlags` INT NOT NULL DEFAULT '0' AFTER `QFall`;" ,
} ;
2018-03-15 02:42:19 +00:00
ActivityStart ( ) ;
2019-09-16 08:51:25 +00:00
if ( ! upgradeResultsDBCheckBox . Checked | | ExecuteCommands ( new MySqlConnection ( DB . ConnectionString ) , commands ) )
2017-10-31 08:45:29 +00:00
{
2018-03-12 05:37:08 +00:00
ActivityEnd ( ) ;
2017-10-31 08:45:29 +00:00
MessageBox . Show ( "DB succesfully upgraded" , "Confirmation" , MessageBoxButtons . OK , MessageBoxIcon . Information ) ;
upgradeDb_216_217_Button . Enabled = false ;
}
}
2018-01-24 13:16:38 +00:00
2018-03-12 05:37:08 +00:00
///---------------------------------------------------------------------
2018-01-24 13:16:38 +00:00
private void upgradeDb_217_218_Button_Click ( object sender , EventArgs e )
{
2018-03-15 02:42:19 +00:00
if ( ! upgradeConfigDBCheckBox . Checked & & ! upgradeResultsDBCheckBox . Checked )
{
MessageBox . Show ( "No database selected" ) ;
return ;
}
2018-03-12 05:37:08 +00:00
2018-01-24 13:16:38 +00:00
string [ ] commands = new string [ ]
{
"ALTER TABLE `measurementcorrection` ADD `RangeIx` INT NOT NULL DEFAULT '0' AFTER `Id`;" ,
} ;
2018-03-15 02:42:19 +00:00
ActivityStart ( ) ;
2018-03-12 05:37:08 +00:00
if ( ! upgradeConfigDBCheckBox . Checked | | ExecuteCommands ( new MySqlConnection ( Config . Data . CurrentBench . ProceduresDBSettings . ConnectionString ) , commands ) )
2018-01-24 13:16:38 +00:00
{
2018-03-12 05:37:08 +00:00
ActivityEnd ( ) ;
2018-01-24 13:16:38 +00:00
MessageBox . Show ( "DB succesfully upgraded" , "Confirmation" , MessageBoxButtons . OK , MessageBoxIcon . Information ) ;
upgradeDb_217_218_Button . Enabled = false ;
}
}
2018-03-13 06:44:33 +00:00
2018-04-10 21:15:55 +00:00
///---------------------------------------------------------------------
2019-09-19 11:48:33 +00:00
private void upgradeDb_218_222_Button_Click ( object sender , EventArgs e )
2018-04-10 21:15:55 +00:00
{
if ( ! upgradeConfigDBCheckBox . Checked & & ! upgradeResultsDBCheckBox . Checked )
{
MessageBox . Show ( "No database selected" ) ;
return ;
}
2019-09-19 11:48:33 +00:00
string [ ] resultsDbCommands = new string [ ]
2018-04-10 21:15:55 +00:00
{
"ALTER TABLE `metertestrslt` ADD `RegReaderType` INT NOT NULL DEFAULT '0' AFTER `CompoundMeterId`;" ,
2020-04-06 20:46:42 +00:00
"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`;" ,
2018-05-17 15:22:50 +00:00
"ALTER TABLE `watermeterdata` ADD `Medium` VARCHAR(255) NULL DEFAULT NULL AFTER `ApprovalInfoAux`;" ,
2020-04-06 20:46:42 +00:00
"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`;" ,
2018-04-10 21:15:55 +00:00
} ;
ActivityStart ( ) ;
2019-09-19 11:48:33 +00:00
if ( ! upgradeResultsDBCheckBox . Checked | | ExecuteCommands ( new MySqlConnection ( DB . ConnectionString ) , resultsDbCommands ) )
2018-04-10 21:15:55 +00:00
{
ActivityEnd ( ) ;
MessageBox . Show ( "DB succesfully upgraded" , "Confirmation" , MessageBoxButtons . OK , MessageBoxIcon . Information ) ;
2019-09-19 11:48:33 +00:00
upgradeDb_218_222_Button . Enabled = false ;
}
}
private void upgradeDb_222_224_Button_Click ( object sender , EventArgs e )
{
if ( ! upgradeConfigDBCheckBox . Checked & & ! upgradeResultsDBCheckBox . Checked )
{
MessageBox . Show ( "No database selected" ) ;
return ;
}
string [ ] configDbCommands = new string [ ]
{
2020-01-09 09:00:14 +00:00
/// Table profile
"CREATE TABLE IF NOT EXISTS `profile` (" +
2020-02-13 20:10:41 +00:00
"`Id` int(11) NOT NULL AUTO_INCREMENT," +
" `ItemNr` int(11) NOT NULL DEFAULT '0'," +
2020-01-09 09:00:14 +00:00
" `Name` varchar(255) CHARACTER SET utf8 COLLATE utf8_unicode_ci DEFAULT NULL," +
" `Description` varchar(255) CHARACTER SET utf8 COLLATE utf8_unicode_ci DEFAULT NULL," +
" `CreationUser` varchar(255) CHARACTER SET utf8 COLLATE utf8_unicode_ci DEFAULT NULL," +
" `CreationTime` datetime DEFAULT NULL," +
" `LastChgUser` varchar(255) CHARACTER SET utf8 COLLATE utf8_unicode_ci DEFAULT NULL," +
" `LastChgTime` datetime DEFAULT NULL," +
" `ProfileType` varchar(255) CHARACTER SET utf8 COLLATE utf8_unicode_ci DEFAULT NULL," +
" `ErrorLimitType` varchar(255) CHARACTER SET utf8 COLLATE utf8_unicode_ci DEFAULT NULL," +
" PRIMARY KEY (`Id`));" ,
/// Table ptest
"CREATE TABLE IF NOT EXISTS `ptest` (" +
2020-02-13 20:10:41 +00:00
"`Id` int(11) NOT NULL AUTO_INCREMENT," +
" `ItemNr` int(11) NOT NULL DEFAULT '0'," +
2020-01-09 09:00:14 +00:00
" `Name` varchar(255) DEFAULT NULL," +
" `Part` int(11) NOT NULL DEFAULT '0'," +
" `CoefQfrom` double NOT NULL DEFAULT '0'," +
" `CoefQto` double NOT NULL DEFAULT '0'," +
" `ErrLimLo` double NOT NULL DEFAULT '0'," +
" `ErrLimHi` double NOT NULL DEFAULT '0'," +
" `TempLimLo` double NOT NULL DEFAULT '0'," +
" `TempLimHi` double NOT NULL DEFAULT '0'," +
" `PressLimLo` double NOT NULL DEFAULT '0'," +
" `PressLimHi` double NOT NULL DEFAULT '0'," +
" `Publish` tinyint(4) NOT NULL DEFAULT '1'," +
" `Evaluate` boolean NOT NULL DEFAULT TRUE," +
" `E1` tinyint(4) NOT NULL DEFAULT '0'," +
" `E2` tinyint(4) NOT NULL DEFAULT '0'," +
" `E3` tinyint(4) NOT NULL DEFAULT '0'," +
" `E4` tinyint(4) NOT NULL DEFAULT '0'," +
" `E5` tinyint(4) NOT NULL DEFAULT '0'," +
" `E6` tinyint(4) NOT NULL DEFAULT '0'," +
" `E7` tinyint(4) NOT NULL DEFAULT '0'," +
" `E8` tinyint(4) NOT NULL DEFAULT '0'," +
" `E9` tinyint(4) NOT NULL DEFAULT '0'," +
" `E10` tinyint(4) NOT NULL DEFAULT '0'," +
" `E11` tinyint(4) NOT NULL DEFAULT '0'," +
" `E12` tinyint(4) NOT NULL DEFAULT '0'," +
" `E13` tinyint(4) NOT NULL DEFAULT '0'," +
" `E14` tinyint(4) NOT NULL DEFAULT '0'," +
" `E15` tinyint(4) NOT NULL DEFAULT '0'," +
" `E16` tinyint(4) NOT NULL DEFAULT '0'," +
" `E21` tinyint(4) NOT NULL DEFAULT '0'," +
" `Delta_Q_pct` double NOT NULL DEFAULT '0'," +
" `Delta_T` double NOT NULL DEFAULT '0'," +
" `Delta_Tup_Tdn` double NOT NULL DEFAULT '0'," +
" `TestTime_min` double NOT NULL DEFAULT '0'," +
" `TestTime_max` double NOT NULL DEFAULT '0'," +
" `AmbTemp_min` double NOT NULL DEFAULT '0'," +
" `AmbTemp_max` double NOT NULL DEFAULT '0'," +
" `Coef_E9` double NOT NULL DEFAULT '0'," +
" `Coef_E10` double NOT NULL DEFAULT '0'," +
" `Coef_E11` double NOT NULL DEFAULT '0'," +
" `Coef_E12` double NOT NULL DEFAULT '0'," +
" `Offset_E9` double NOT NULL DEFAULT '0'," +
" `Offset_E12` double NOT NULL DEFAULT '0'," +
2020-02-13 20:10:41 +00:00
" `Profile_id` int(11) DEFAULT NULL," +
2020-01-09 09:00:14 +00:00
" PRIMARY KEY (`Id`));" ,
/// Table test
"ALTER TABLE `test` ADD `Qtg` FLOAT NULL DEFAULT NULL AFTER `Evaluate`;" ,
"ALTER TABLE `test` CHANGE `RelTransAfter` `Profile` VARCHAR(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL;" ,
"UPDATE `test` SET Profile = 'UserDefined';" ,
/// Table uncertainty
2019-09-19 11:48:33 +00:00
"CREATE TABLE IF NOT EXISTS `uncertainty` (" +
" `Id` int(11) NOT NULL AUTO_INCREMENT," +
" `Measurement` float NOT NULL DEFAULT '0'," +
" `MainUncertainty` float NOT NULL DEFAULT '0'," +
" `Resolution` float NOT NULL DEFAULT '0'," +
" `DriftPerYr` float NOT NULL DEFAULT '0'," +
" `Conditions` float NOT NULL DEFAULT '0'," +
" `UncertaintyOfCorrection` float NOT NULL DEFAULT '0'," +
" `Component_id` int(11) DEFAULT NULL," +
" PRIMARY KEY (`Id`)," +
2020-02-13 20:10:41 +00:00
" KEY `Component_id` (`Component_id`));" ,
2020-01-09 09:00:14 +00:00
/// Table user
"ALTER TABLE `user` ADD `Password2` VARCHAR(255) NULL DEFAULT NULL AFTER `Password`, ADD `Password3` VARCHAR(255) NULL DEFAULT NULL AFTER `Password2`, ADD `Password4` VARCHAR(255) NULL DEFAULT NULL AFTER `Password3`;" ,
/// Tables watermeter and wmtype
"DROP TABLE `watermeter`" ,
"DROP TABLE `wmtype`" ,
//"ALTER TABLE `procedure` DROP `ProtocolTitle`",
2019-09-19 11:48:33 +00:00
} ;
2019-09-21 16:03:25 +00:00
string [ ] resultsDbCommands = new string [ ]
{
2020-01-09 09:00:14 +00:00
"ALTER TABLE `testdata` ADD `Qtg` DOUBLE NULL DEFAULT NULL AFTER `Name`;" ,
2020-04-06 20:46:42 +00:00
"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`;" ,
2020-01-09 09:00:14 +00:00
"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`;" ,
#if IPERL
"ALTER TABLE `watermeter` DROP `Q2CorrectionDone`, DROP `Q2Correction`;" ,
#endif
2019-09-21 16:03:25 +00:00
} ;
2019-09-19 11:48:33 +00:00
ActivityStart ( ) ;
2020-01-09 09:00:14 +00:00
bool success = true ;
2019-09-19 11:48:33 +00:00
2020-01-09 09:00:14 +00:00
if ( upgradeConfigDBCheckBox . Checked )
{
success = success & & ExecuteCommands ( new MySqlConnection ( Config . Data . CurrentBench . ProceduresDBSettings . ConnectionString ) , configDbCommands ) ;
if ( ! string . IsNullOrEmpty ( errorFlagsComponentsTextBox . Text ) )
{
string [ ] errorFlagsCmpnts = errorFlagsComponentsTextBox . Text . Split ( new char [ ] { '~' } ) ;
foreach ( var errFCmpnt in errorFlagsCmpnts )
{
success = success & & ChangeErrorFlags ( errFCmpnt ) ;
}
}
}
if ( upgradeResultsDBCheckBox . Checked )
{
success = success & & ExecuteCommands ( new MySqlConnection ( DB . ConnectionString ) , resultsDbCommands ) ;
}
if ( success )
2019-09-19 11:48:33 +00:00
{
ActivityEnd ( ) ;
MessageBox . Show ( "DB succesfully upgraded." + Environment . NewLine +
"Please, create Density and Buoyancy components." ,
"Confirmation" ,
MessageBoxButtons . OK ,
MessageBoxIcon . Information ) ;
upgradeDb_222_224_Button . Enabled = false ;
2018-04-10 21:15:55 +00:00
}
}
2020-01-09 09:00:14 +00:00
private void upgradeDb_224_225_Button_Click ( object sender , EventArgs e )
{
MySqlConnection dbConn = null ;
MySqlCommand cmd ;
ActivityStart ( ) ;
bool success = false ;
try
{
dbConn = new MySqlConnection ( Config . Data . CurrentBench . ProceduresDBSettings . ConnectionString ) ;
dbConn . Open ( ) ;
cmd = dbConn . CreateCommand ( ) ;
cmd . CommandText = "CREATE TABLE IF NOT EXISTS `usersgroups` ( `Group_id` int(11) NOT NULL, `User_id` int(11) NOT NULL );" ;
cmd . ExecuteNonQuery ( ) ;
cmd . Dispose ( ) ;
cmd = dbConn . CreateCommand ( ) ;
cmd . CommandText = "ALTER TABLE `usersgroups` ADD KEY `User_id` (`User_id`), ADD KEY `Group_id` (`Group_id`)," +
" ADD CONSTRAINT `FKEC3AF23393C4061C` FOREIGN KEY (`Group_id`) REFERENCES `group` (`Id`)," +
" ADD CONSTRAINT `FKEC3AF23373767C99` FOREIGN KEY (`User_id`) REFERENCES `user` (`Id`);" ;
cmd . ExecuteNonQuery ( ) ;
cmd . Dispose ( ) ;
int [ ] groupIdsToKeep = new int [ ( int ) Users . Entities . GID . NrOfGroups ] ;
IList < GroupTableRow > groupTable = new List < GroupTableRow > ( ) ;
cmd = dbConn . CreateCommand ( ) ;
cmd . CommandText = "SELECT `Id`, `Gid`, `User_id` FROM `group`;" ;
MySqlDataReader dr = cmd . ExecuteReader ( ) ;
while ( dr . Read ( ) )
{
int groupId = dr . GetInt32 ( 0 ) ;
Users . Entities . GID gid = ( Users . Entities . GID ) dr . GetInt32 ( 1 ) ;
int userId = dr . GetInt32 ( 2 ) ;
groupTable . Add ( new GroupTableRow ( groupId , gid , userId ) ) ;
if ( ( gid > = 0 ) & & ( gid < Users . Entities . GID . NrOfGroups ) & & ( groupIdsToKeep [ ( int ) gid ] = = 0 ) )
{
groupIdsToKeep [ ( int ) gid ] = groupId ;
}
}
dr . Close ( ) ;
foreach ( var groupTableRow in groupTable )
{
cmd = dbConn . CreateCommand ( ) ;
cmd . CommandText = string . Format ( "INSERT INTO `usersgroups` (`Group_id`, `User_id`) VALUES ({0}, {1});" ,
groupIdsToKeep [ ( int ) groupTableRow . Gid ] ,
groupTableRow . UserId ) ;
cmd . ExecuteNonQuery ( ) ;
cmd . Dispose ( ) ;
}
//foreach (var groupTableRow in groupTable)
//{
// bool deleteThisRow = true;
// for (int i = 0; i < groupIdsToKeep.Length; i++)
// {
// if (groupTableRow.GroupId == groupIdsToKeep[i])
// {
// deleteThisRow = false;
// break;
// }
// }
// if (deleteThisRow)
// {
// cmd = dbConn.CreateCommand();
// cmd.CommandText = string.Format("DELETE FROM `group` WHERE `Id` = {0}", groupTableRow.GroupId);
// cmd.ExecuteNonQuery();
// cmd.Dispose();
// }
//}
cmd = dbConn . CreateCommand ( ) ;
cmd . CommandText = string . Format ( "ALTER TABLE `group` ADD `AccessFlags` BIGINT NOT NULL DEFAULT '0' AFTER `Name`;" ) ;
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
{
if ( dbConn ! = null ) dbConn . Close ( ) ;
}
if ( success )
{
ActivityEnd ( ) ;
MessageBox . Show ( "DB succesfully upgraded" , "Confirmation" , MessageBoxButtons . OK , MessageBoxIcon . Information ) ;
upgradeDb_224_225_Button . Enabled = false ;
}
}
2020-04-06 20:46:42 +00:00
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 ;
}
}
2018-03-13 06:44:33 +00:00
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
{
2019-09-16 08:51:25 +00:00
ISession session = DB . CreateSession ( ) ;
2018-03-13 06:44:33 +00:00
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 ) ;
}
}
2020-12-08 07:51:07 +00:00
private void customButton_Click ( object sender , EventArgs e )
{
ActivityStart ( ) ;
try
{
//ISession session = Config.FluentCommon.CreateSession(Users.Entities.DBKind.Config);
//var proceduresToModify = session.QueryOver<Config.Entities.Procedure>()
// .Where(x => (x.ProcedureState == Config.Entities.ProcedureState.Active))
// .OrderBy(x => x.ItemNr).Asc
// .List<Config.Entities.Procedure>();
//foreach (var proc in proceduresToModify)
//{
// if (!string.IsNullOrEmpty(proc.ResultsWriter) && proc.ResultsWriter.Contains("IperlLogger"))
// {
// Console.WriteLine("{0} ... {1}", proc.Name, proc.ResultsWriter);
// string[] writers = proc.ResultsWriter.Split(new char[] { '~' });
// StringBuilder sb = new StringBuilder();
// for (int i = 0; i < writers.Length; i++)
// {
// if (writers[i].Contains("IperlLogger"))
// {
// sb.Append("IperlLogger");
// }
// else
// {
// sb.Append(writers[i]);
// }
// if (i != writers.Length - 1) sb.Append("~");
// }
// proc.ResultsWriter = sb.ToString();
// session.SaveOrUpdate(proc);
// }
//}
//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 ) ;
}
}
2016-08-03 07:59:55 +00:00
}
}