54 lines
1.8 KiB
C#
54 lines
1.8 KiB
C#
using System;
|
|
using System.Windows.Forms;
|
|
using MySql.Data.MySqlClient;
|
|
using Results;
|
|
|
|
namespace TBF.Forms
|
|
{
|
|
public partial class UpgradeSelectionDlg : Form
|
|
{
|
|
int batchFrom;
|
|
int batchTo;
|
|
|
|
public UpgradeSelectionDlg()
|
|
{
|
|
InitializeComponent();
|
|
batchFrom = 1;
|
|
batchTo = Program.LocalSettings.BatchNr - 1;
|
|
}
|
|
|
|
private void upgradeDbButton_Click(object sender, EventArgs e)
|
|
{
|
|
MySqlConnection dbConn = new MySqlConnection(Results.DB.ConnectionString);
|
|
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`;",
|
|
};
|
|
|
|
try
|
|
{
|
|
dbConn.Open();
|
|
|
|
foreach (var cmdText in commands)
|
|
{
|
|
MySqlCommand cmd = dbConn.CreateCommand();
|
|
cmd.CommandText = cmdText;
|
|
cmd.ExecuteNonQuery();
|
|
}
|
|
|
|
MessageBox.Show("DB succesfully upgraded", "Confirmation", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
|
upgradeDbButton.Enabled = false;
|
|
}
|
|
catch (Exception exc)
|
|
{
|
|
MessageBox.Show(string.Format("Exception {0}", exc.Message), "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
|
|
}
|
|
finally
|
|
{
|
|
dbConn.Close();
|
|
}
|
|
}
|
|
}
|
|
}
|