204 lines
7.3 KiB
C#
204 lines
7.3 KiB
C#
///
|
|
/// Copyright (c) 2013-2015 Sensus Metering Systems
|
|
///
|
|
using System;
|
|
using System.Windows.Forms;
|
|
|
|
namespace ResultsBrowser
|
|
{
|
|
/// <summary>
|
|
/// Dialog to edit local settings that specify database parameters (S1.2)
|
|
/// </summary>
|
|
public partial class BenchesDlg : Form
|
|
{
|
|
// Local copy of 'local settings' initialized to Program.localSettings.
|
|
// Dialog modifies this copy and updates Program.localSettings just
|
|
// when 'OK' is pressed.
|
|
LocalSettings localSettings;
|
|
|
|
/// <summary>
|
|
/// Constructor, initializes the dialog
|
|
/// </summary>
|
|
public BenchesDlg()
|
|
{
|
|
Program.LocalSettings.Save();
|
|
localSettings = LocalSettings.Load(Program.LocalSettingsFileName);
|
|
if (localSettings == null) throw new Exception("Cannot load local settings");
|
|
|
|
InitializeComponent();
|
|
RedrawTestBenchesListBox();
|
|
}
|
|
|
|
void RedrawTestBenchesListBox()
|
|
{
|
|
testBenchesListBox.Items.Clear();
|
|
if (localSettings.TestBenches != null)
|
|
{
|
|
int nrBenches = localSettings.TestBenches.GetLength(0);
|
|
for (int i = 0; i < nrBenches; i++)
|
|
{
|
|
testBenchesListBox.Items.Add(localSettings.TestBenches[i].BenchName);
|
|
}
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Create a new test bench DB specification and append it to the list
|
|
/// </summary>
|
|
/// <param name="sender">Not used</param>
|
|
/// <param name="e">Not used</param>
|
|
private void addButton_Click(object sender, EventArgs e)
|
|
{
|
|
Config.DatabaseSettings bench = new Config.DatabaseSettings();
|
|
Config.DatabaseSettingsDlg dlg = new Config.DatabaseSettingsDlg(bench);
|
|
DialogResult dr = dlg.ShowDialog();
|
|
if (dr == DialogResult.OK)
|
|
{
|
|
int nrBenches =
|
|
(localSettings.TestBenches == null) ? 0 : localSettings.TestBenches.GetLength(0);
|
|
|
|
if (nrBenches == 0)
|
|
{
|
|
localSettings.TestBenches = new Config.DatabaseSettings[1];
|
|
localSettings.TestBenches[0] = bench;
|
|
}
|
|
else
|
|
{
|
|
Config.DatabaseSettings[] newTestBenches = new Config.DatabaseSettings[nrBenches + 1];
|
|
for (int i = 0; i < nrBenches; i++)
|
|
{
|
|
newTestBenches[i] = localSettings.TestBenches[i];
|
|
}
|
|
newTestBenches[nrBenches] = bench;
|
|
localSettings.TestBenches = newTestBenches;
|
|
}
|
|
|
|
testBenchesListBox.Items.Add(bench.BenchName);
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Create a new test bench DB specification,which is a copy of the
|
|
/// selected bench, and append it to the list
|
|
/// </summary>
|
|
/// <param name="sender">Not used</param>
|
|
/// <param name="e">Not used</param>
|
|
private void copyButton_Click(object sender, EventArgs e)
|
|
{
|
|
if (testBenchesListBox.SelectedIndex >= 0)
|
|
{
|
|
Config.DatabaseSettings ori = localSettings.TestBenches[testBenchesListBox.SelectedIndex];
|
|
Config.DatabaseSettings bench = (Config.DatabaseSettings)ori.Clone();
|
|
|
|
Config.DatabaseSettingsDlg dlg = new Config.DatabaseSettingsDlg(bench);
|
|
DialogResult dr = dlg.ShowDialog();
|
|
if (dr == DialogResult.OK)
|
|
{
|
|
int nrBenches =
|
|
(localSettings.TestBenches == null) ? 0 : localSettings.TestBenches.GetLength(0);
|
|
|
|
Config.DatabaseSettings[] newTestBenches = new Config.DatabaseSettings[nrBenches + 1];
|
|
for (int i = 0; i < nrBenches; i++)
|
|
{
|
|
newTestBenches[i] = localSettings.TestBenches[i];
|
|
}
|
|
newTestBenches[nrBenches] = bench;
|
|
localSettings.TestBenches = newTestBenches;
|
|
|
|
testBenchesListBox.Items.Add(bench.BenchName);
|
|
}
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Edit selected test bench DB specification
|
|
/// </summary>
|
|
/// <param name="sender">Not used</param>
|
|
/// <param name="e">Not used</param>
|
|
private void editButton_Click(object sender, EventArgs e)
|
|
{
|
|
if (testBenchesListBox.SelectedIndex >= 0)
|
|
{
|
|
Config.DatabaseSettingsDlg dlg = new Config.DatabaseSettingsDlg(localSettings.TestBenches[testBenchesListBox.SelectedIndex]);
|
|
DialogResult dr = dlg.ShowDialog();
|
|
if (dr == DialogResult.OK)
|
|
{
|
|
// Update the item name
|
|
testBenchesListBox.Items[testBenchesListBox.SelectedIndex] =
|
|
localSettings.TestBenches[testBenchesListBox.SelectedIndex].BenchName;
|
|
}
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Remove selected test bench DB specification from the list
|
|
/// </summary>
|
|
/// <param name="sender">Not used</param>
|
|
/// <param name="e">Not used</param>
|
|
private void removeButton_Click(object sender, EventArgs e)
|
|
{
|
|
int selectedIx = testBenchesListBox.SelectedIndex;
|
|
if (selectedIx >= 0)
|
|
{
|
|
int nrBenches =
|
|
(localSettings.TestBenches == null) ? 0 : localSettings.TestBenches.GetLength(0);
|
|
|
|
if (nrBenches == 1)
|
|
{
|
|
localSettings.TestBenches = null;
|
|
}
|
|
else
|
|
{
|
|
Config.DatabaseSettings[] newTestBenches = new Config.DatabaseSettings[nrBenches - 1];
|
|
for (int i = 0; i < selectedIx; i++)
|
|
{
|
|
newTestBenches[i] = localSettings.TestBenches[i];
|
|
}
|
|
for (int i = selectedIx + 1; i < nrBenches; i++)
|
|
{
|
|
newTestBenches[i - 1] = localSettings.TestBenches[i];
|
|
}
|
|
localSettings.TestBenches = newTestBenches;
|
|
}
|
|
|
|
RedrawTestBenchesListBox();
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Update setting, return 'OK'
|
|
/// </summary>
|
|
/// <param name="sender">Not used</param>
|
|
/// <param name="e">Not used</param>
|
|
private void okButton_Click(object sender, EventArgs e)
|
|
{
|
|
localSettings.Save();
|
|
Program.LocalSettings = LocalSettings.Load(Program.LocalSettingsFileName);
|
|
DialogResult = DialogResult.OK;
|
|
Close();
|
|
return;
|
|
}
|
|
|
|
/// <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();
|
|
return;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Double click on an item = edit item
|
|
/// </summary>
|
|
/// <param name="sender">Not used</param>
|
|
/// <param name="e">Not used</param>
|
|
private void testBenchesListBox_DoubleClick(object sender, EventArgs e)
|
|
{
|
|
editButton_Click(sender, e);
|
|
}
|
|
}
|
|
} |