2015-04-15 18:32:56 +00:00
|
|
|
///
|
|
|
|
|
/// Copyright (c) 2013-2015 Sensus Metering Systems
|
|
|
|
|
///
|
2014-07-28 07:54:35 +00:00
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.ComponentModel;
|
|
|
|
|
using System.Data;
|
|
|
|
|
using System.Drawing;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Windows.Forms;
|
|
|
|
|
using TBF.Resources;
|
|
|
|
|
|
|
|
|
|
namespace TBF
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Dialog to process test bench name and database settings (BenchSettings)
|
|
|
|
|
/// </summary>
|
|
|
|
|
public partial class DatabaseSettingsDlg : Form
|
|
|
|
|
{
|
|
|
|
|
// Reference to bench DB settins (not a local copy)
|
|
|
|
|
DatabaseSettings bench;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Constructor
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="bench">Test bench database settings</param>
|
|
|
|
|
public DatabaseSettingsDlg(DatabaseSettings bench)
|
|
|
|
|
{
|
|
|
|
|
this.bench = bench;
|
|
|
|
|
|
|
|
|
|
InitializeComponent();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Localize()
|
|
|
|
|
{
|
|
|
|
|
Text = Strings.Test_Bench_Databases_Specification;
|
|
|
|
|
label1.Text = Strings.Test_bench_name;
|
|
|
|
|
realBenchCheckBox.Text = Strings.Test_bench_is_controlled_by_this_computer;
|
|
|
|
|
dbTypeLabel.Text = Strings.Database_type;
|
|
|
|
|
connectionStringLabel.Text = Strings.Connection_string;
|
|
|
|
|
label2.Text = Strings.Users_and_groups;
|
|
|
|
|
label3.Text = Strings.Bench_parameters;
|
|
|
|
|
label4.Text = Strings.Procedures;
|
|
|
|
|
label5.Text = Strings.Water_meter_types;
|
|
|
|
|
label6.Text = Strings.Water_meter_data;
|
|
|
|
|
okButton.Text = Strings.OkBtnText;
|
|
|
|
|
cancelButton.Text = Strings.CancelBtnText;
|
|
|
|
|
|
|
|
|
|
testConnBenchBtn.Text = Strings.Test_connection;
|
|
|
|
|
testConnProceduresBtn.Text = Strings.Test_connection;
|
|
|
|
|
testConnUsersBtn.Text = Strings.Test_connection;
|
|
|
|
|
testConnWaterMetersBtn.Text = Strings.Test_connection;
|
|
|
|
|
testConnWMTypesBtn.Text = Strings.Test_connection;
|
|
|
|
|
|
|
|
|
|
createBenchDbBtn.Text = Strings.Create_DB;
|
|
|
|
|
createProceduresDbBtn.Text = Strings.Create_DB;
|
|
|
|
|
createUsersDbBtn.Text = Strings.Create_DB;
|
|
|
|
|
createWaterMetersDbBtn.Text = Strings.Create_DB;
|
|
|
|
|
createWMTypesDbBtn.Text = Strings.Create_DB;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void BenchSettingsDlg_Load(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
Localize();
|
|
|
|
|
|
|
|
|
|
benchNameTextBox.Text = bench.BenchName;
|
|
|
|
|
realBenchCheckBox.Checked = bench.IsRealBench;
|
|
|
|
|
|
|
|
|
|
/// Initialize 'Database type' combo-boxes
|
|
|
|
|
for (int i = 0; i < (int)DBType.DbTypesCount; i++)
|
|
|
|
|
{
|
|
|
|
|
DBType dbType = (DBType)i;
|
|
|
|
|
usersDbTypeComboBox.Items.Add(dbType);
|
|
|
|
|
benchDbTypeComboBox.Items.Add(dbType);
|
|
|
|
|
proceduresDbTypeComboBox.Items.Add(dbType);
|
|
|
|
|
wmTypesDbTypeComboBox.Items.Add(dbType);
|
|
|
|
|
watermetersDbTypeComboBox.Items.Add(dbType);
|
|
|
|
|
}
|
|
|
|
|
usersDbTypeComboBox.SelectedIndex = (int)bench.UsersDBSettings.DbType;
|
|
|
|
|
benchDbTypeComboBox.SelectedIndex = (int)bench.BenchDBSettings.DbType;
|
|
|
|
|
proceduresDbTypeComboBox.SelectedIndex = (int)bench.ProceduresDBSettings.DbType;
|
|
|
|
|
wmTypesDbTypeComboBox.SelectedIndex = (int)bench.WMTypesDBSettings.DbType;
|
|
|
|
|
watermetersDbTypeComboBox.SelectedIndex = (int)bench.WaterMetersDBSettings.DbType;
|
|
|
|
|
|
|
|
|
|
/// Initialize connection strings
|
|
|
|
|
usersConnectionStringTextBox.Text = bench.UsersDBSettings.ConnectionString;
|
|
|
|
|
benchConnectionStringTextBox.Text = bench.BenchDBSettings.ConnectionString;
|
|
|
|
|
proceduresConnectionStringTextBox.Text = bench.ProceduresDBSettings.ConnectionString;
|
|
|
|
|
wmTypesConnectionStringTextBox.Text = bench.WMTypesDBSettings.ConnectionString;
|
|
|
|
|
watermetersConnectionStringTextBox.Text = bench.WaterMetersDBSettings.ConnectionString;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool UpdateBenchFromUIControls()
|
|
|
|
|
{
|
2015-03-09 14:26:44 +00:00
|
|
|
/// TODO: The following code doesnot work as expected - error message shown!
|
|
|
|
|
//for (int i = 0; i < Program.LocalSettings.BenchesCount; i++)
|
|
|
|
|
//{
|
|
|
|
|
// if (bench != Program.LocalSettings.TestBenches[i] &&
|
|
|
|
|
// benchNameTextBox.Text == Program.LocalSettings.TestBenches[i].BenchName)
|
|
|
|
|
// {
|
|
|
|
|
// MessageBox.Show(Strings.Bench_name_conflict_Use_another_name_pls, Strings.Error, MessageBoxButtons.OK);
|
|
|
|
|
// return false;
|
|
|
|
|
// }
|
|
|
|
|
//}
|
2014-07-28 07:54:35 +00:00
|
|
|
|
|
|
|
|
bench.BenchName = benchNameTextBox.Text;
|
|
|
|
|
bench.IsRealBench = realBenchCheckBox.Checked;
|
|
|
|
|
|
|
|
|
|
bench.UsersDBSettings.ConnectionString = usersConnectionStringTextBox.Text;
|
|
|
|
|
bench.BenchDBSettings.ConnectionString = benchConnectionStringTextBox.Text;
|
|
|
|
|
bench.ProceduresDBSettings.ConnectionString = proceduresConnectionStringTextBox.Text;
|
|
|
|
|
bench.WMTypesDBSettings.ConnectionString = wmTypesConnectionStringTextBox.Text;
|
|
|
|
|
bench.WaterMetersDBSettings.ConnectionString = watermetersConnectionStringTextBox.Text;
|
|
|
|
|
|
|
|
|
|
bench.UsersDBSettings.DbType = (DBType)usersDbTypeComboBox.SelectedIndex;
|
|
|
|
|
bench.BenchDBSettings.DbType = (DBType)benchDbTypeComboBox.SelectedIndex;
|
|
|
|
|
bench.ProceduresDBSettings.DbType = (DBType)proceduresDbTypeComboBox.SelectedIndex;
|
|
|
|
|
bench.WMTypesDBSettings.DbType = (DBType)wmTypesDbTypeComboBox.SelectedIndex;
|
|
|
|
|
bench.WaterMetersDBSettings.DbType = (DBType)watermetersDbTypeComboBox.SelectedIndex;
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Update bench DB setting, return 'OK'
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="sender">Not used</param>
|
|
|
|
|
/// <param name="e">Not used</param>
|
|
|
|
|
private void okButton_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (UpdateBenchFromUIControls())
|
|
|
|
|
{
|
|
|
|
|
DialogResult = DialogResult.OK;
|
|
|
|
|
Close();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
DialogResult = DialogResult.None;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Throw away changes, return 'Cancel'
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="sender">Not used</param>
|
|
|
|
|
/// <param name="e">Not used</param>
|
|
|
|
|
private void cancelButton_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
DialogResult = DialogResult.Cancel;
|
|
|
|
|
Close();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void createDatabasesButton_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (!UpdateBenchFromUIControls()) return;
|
|
|
|
|
|
|
|
|
|
if (DialogResult.OK == MessageBox.Show(Strings.DB_will_be_overwritten + Environment.NewLine +
|
|
|
|
|
Strings.Do_you_want_to_proceed, Strings.Warning,
|
|
|
|
|
MessageBoxButtons.OKCancel, MessageBoxIcon.Exclamation))
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
Cursor.Current = Cursors.WaitCursor;
|
|
|
|
|
FluentCommon.CreateEmptyUsersDB(bench.UsersDBSettings);
|
|
|
|
|
MessageBox.Show(Strings.DB_was_successfully_created, Strings.Notification);
|
|
|
|
|
Cursor.Current = Cursors.Default;
|
|
|
|
|
DialogResult = DialogResult.None;
|
|
|
|
|
}
|
2015-03-09 14:26:44 +00:00
|
|
|
catch (NHibernate.HibernateException exception)
|
2014-07-28 07:54:35 +00:00
|
|
|
{
|
|
|
|
|
Cursor.Current = Cursors.Default;
|
|
|
|
|
MessageBox.Show(Strings.Error_while_creating_DB_Reason + exception.Message, Strings.Error);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void createbenchDbBtn_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (!UpdateBenchFromUIControls()) return;
|
|
|
|
|
|
|
|
|
|
if (DialogResult.OK == MessageBox.Show(Strings.DB_will_be_overwritten + Environment.NewLine +
|
|
|
|
|
Strings.Do_you_want_to_proceed, Strings.Warning,
|
|
|
|
|
MessageBoxButtons.OKCancel, MessageBoxIcon.Exclamation))
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
Cursor.Current = Cursors.WaitCursor;
|
|
|
|
|
FluentCommon.CreateEmptyBenchDB(bench.BenchDBSettings);
|
|
|
|
|
MessageBox.Show(Strings.DB_was_successfully_created, Strings.Notification);
|
|
|
|
|
Cursor.Current = Cursors.Default;
|
|
|
|
|
DialogResult = DialogResult.None;
|
|
|
|
|
}
|
|
|
|
|
catch (Exception exception)
|
|
|
|
|
{
|
|
|
|
|
Cursor.Current = Cursors.Default;
|
|
|
|
|
MessageBox.Show(Strings.Error_while_creating_DB_Reason + exception.Message, Strings.Error);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void createProecduresDbBtn_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (!UpdateBenchFromUIControls()) return;
|
|
|
|
|
|
|
|
|
|
if (DialogResult.OK == MessageBox.Show(Strings.DB_will_be_overwritten + Environment.NewLine +
|
|
|
|
|
Strings.Do_you_want_to_proceed, Strings.Warning,
|
|
|
|
|
MessageBoxButtons.OKCancel, MessageBoxIcon.Exclamation))
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
Cursor.Current = Cursors.WaitCursor;
|
|
|
|
|
FluentCommon.CreateEmptyProceduresDB(bench.ProceduresDBSettings);
|
|
|
|
|
MessageBox.Show(Strings.DB_was_successfully_created, Strings.Notification);
|
|
|
|
|
Cursor.Current = Cursors.Default;
|
|
|
|
|
DialogResult = DialogResult.None;
|
|
|
|
|
}
|
|
|
|
|
catch (Exception exception)
|
|
|
|
|
{
|
|
|
|
|
Cursor.Current = Cursors.Default;
|
|
|
|
|
MessageBox.Show(Strings.Error_while_creating_DB_Reason + exception.Message, Strings.Error);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void createWMTypesDbBtn_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void createWaterMetersDbBtn_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (!UpdateBenchFromUIControls()) return;
|
|
|
|
|
|
|
|
|
|
if (DialogResult.OK == MessageBox.Show(Strings.DB_will_be_overwritten + Environment.NewLine +
|
|
|
|
|
Strings.Do_you_want_to_proceed, Strings.Warning,
|
|
|
|
|
MessageBoxButtons.OKCancel, MessageBoxIcon.Exclamation))
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
Cursor.Current = Cursors.WaitCursor;
|
|
|
|
|
FluentCommon.CreateEmptyWaterMetersDB(bench.WaterMetersDBSettings);
|
|
|
|
|
MessageBox.Show(Strings.DB_was_successfully_created, Strings.Notification);
|
|
|
|
|
Cursor.Current = Cursors.Default;
|
|
|
|
|
DialogResult = DialogResult.None;
|
|
|
|
|
}
|
|
|
|
|
catch (Exception exception)
|
|
|
|
|
{
|
|
|
|
|
Cursor.Current = Cursors.Default;
|
|
|
|
|
MessageBox.Show(Strings.Error_while_creating_DB_Reason + exception.Message, Strings.Error);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void testConnUsersBtn_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void testConnBenchBtn_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void testConnProceduresBtn_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void testConnWMTypesBtn_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void testConnWaterMetersBtn_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|