226 lines
8.9 KiB
C#
226 lines
8.9 KiB
C#
///
|
|
/// Copyright (c) 2013-2016 Sensus Metering Systems
|
|
///
|
|
using System;
|
|
using System.Windows.Forms;
|
|
using TBF.Resources;
|
|
|
|
namespace TBF.Forms
|
|
{
|
|
/// <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)
|
|
Config.DatabaseSettings bench;
|
|
|
|
/// <summary>
|
|
/// Constructor
|
|
/// </summary>
|
|
/// <param name="bench">Test bench database settings</param>
|
|
public DatabaseSettingsDlg(Config.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;
|
|
|
|
configLabel.Text = Strings.Configuration;
|
|
resultsLabel.Text = Strings.Results;
|
|
usersLabel.Text = Strings.Users;
|
|
|
|
testConnConfigDbBtn.Text = Strings.Test_connection;
|
|
testConnResultsDbBtn.Text = Strings.Test_connection;
|
|
testConnUsersDbBtn.Text = Strings.Test_connection;
|
|
|
|
createConfigDbBtn.Text = Strings.Create_DB;
|
|
createResultsDbBtn.Text = Strings.Create_DB;
|
|
createUsersDbBtn.Text = Strings.Create_DB;
|
|
|
|
okButton.Text = Strings.OkBtnText;
|
|
cancelButton.Text = Strings.CancelBtnText;
|
|
}
|
|
|
|
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)Users.Entities.DBType.DbTypesCount; i++)
|
|
{
|
|
Users.Entities.DBType dbType = (Users.Entities.DBType)i;
|
|
configDbTypeComboBox.Items.Add(dbType);
|
|
resultsDbTypeComboBox.Items.Add(dbType);
|
|
usersDbTypeComboBox.Items.Add(dbType);
|
|
}
|
|
configDbTypeComboBox.SelectedIndex = (int)bench.ProceduresDBSettings.DbType;
|
|
resultsDbTypeComboBox.SelectedIndex = (int)bench.WaterMetersDBSettings.DbType;
|
|
usersDbTypeComboBox.SelectedIndex = (int)bench.UsersDBSettings.DbType;
|
|
|
|
/// Initialize connection strings
|
|
configDbConnectionStringTextBox.Text = bench.ProceduresDBSettings.ConnectionString;
|
|
resultsDbConnectionStringTextBox.Text = bench.WaterMetersDBSettings.ConnectionString;
|
|
usersDbConnectionStringTextBox.Text = bench.UsersDBSettings.ConnectionString;
|
|
}
|
|
|
|
bool UpdateBenchFromUIControls()
|
|
{
|
|
/// 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;
|
|
// }
|
|
//}
|
|
|
|
bench.BenchName = benchNameTextBox.Text;
|
|
bench.IsRealBench = realBenchCheckBox.Checked;
|
|
|
|
bench.ProceduresDBSettings.ConnectionString = configDbConnectionStringTextBox.Text;
|
|
bench.WaterMetersDBSettings.ConnectionString = resultsDbConnectionStringTextBox.Text;
|
|
bench.UsersDBSettings.ConnectionString = usersDbConnectionStringTextBox.Text;
|
|
|
|
bench.ProceduresDBSettings.DbType = (Users.Entities.DBType)configDbTypeComboBox.SelectedIndex;
|
|
bench.WaterMetersDBSettings.DbType = (Users.Entities.DBType)resultsDbTypeComboBox.SelectedIndex;
|
|
bench.UsersDBSettings.DbType = (Users.Entities.DBType)usersDbTypeComboBox.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 createConfigDbBtn_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;
|
|
Config.FluentCommon.CreateEmptyConfigDB(bench.ProceduresDBSettings.DbType, bench.ProceduresDBSettings.ConnectionString);
|
|
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 createResultsDbBtn_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;
|
|
Results.DB.DbType = bench.WaterMetersDBSettings.DbType;
|
|
Results.DB.ConnectionString = bench.WaterMetersDBSettings.ConnectionString;
|
|
Results.DB.CreateEmptyDB();
|
|
MessageBox.Show(Strings.DB_was_successfully_created, Strings.Notification);
|
|
Cursor.Current = Cursors.Default;
|
|
DialogResult = DialogResult.None;
|
|
}
|
|
catch (Exception exception)
|
|
{
|
|
Cursor.Current = Cursors.Default;
|
|
string msg = Strings.Error_while_creating_DB_Reason + Environment.NewLine + exception.Message;
|
|
if (exception.InnerException != null)
|
|
{
|
|
msg += Environment.NewLine + exception.InnerException.Message;
|
|
}
|
|
MessageBox.Show(msg, Strings.Error, MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|
}
|
|
}
|
|
|
|
private void createUsersDbBtn_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;
|
|
Users.DB.DbType = bench.UsersDBSettings.DbType;
|
|
Users.DB.ConnectionString = bench.UsersDBSettings.ConnectionString;
|
|
Users.DB.CreateEmptyDB();
|
|
MessageBox.Show(Strings.DB_was_successfully_created, Strings.Notification);
|
|
Cursor.Current = Cursors.Default;
|
|
DialogResult = DialogResult.None;
|
|
}
|
|
catch (Exception exception)
|
|
{
|
|
Cursor.Current = Cursors.Default;
|
|
string msg = Strings.Error_while_creating_DB_Reason + Environment.NewLine + exception.Message;
|
|
if (exception.InnerException != null)
|
|
{
|
|
msg += Environment.NewLine + exception.InnerException.Message;
|
|
}
|
|
MessageBox.Show(msg, Strings.Error, MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|
}
|
|
}
|
|
|
|
private void testConnConfigDbBtn_Click(object sender, EventArgs e)
|
|
{
|
|
}
|
|
|
|
private void testConnResultsDbBtn_Click(object sender, EventArgs e)
|
|
{
|
|
}
|
|
|
|
private void testConnUsersDbBtn_Click(object sender, EventArgs e)
|
|
{
|
|
|
|
}
|
|
}
|
|
} |