2015-04-15 18:32:56 +00:00
|
|
|
|
///
|
|
|
|
|
|
/// Copyright (c) 2013-2015 Sensus Metering Systems
|
|
|
|
|
|
///
|
|
|
|
|
|
using System;
|
2014-07-28 07:54:35 +00:00
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
using System.Globalization;
|
|
|
|
|
|
using System.Windows.Forms;
|
|
|
|
|
|
using NHibernate;
|
|
|
|
|
|
using log4net;
|
|
|
|
|
|
using TBF.UiControls;
|
|
|
|
|
|
using TBF.BenchControl.GenericDevices;
|
|
|
|
|
|
using TBF.Resources;
|
|
|
|
|
|
|
|
|
|
|
|
namespace TBF
|
|
|
|
|
|
{
|
|
|
|
|
|
public partial class PathsDlg : Form, IParentOfListViewEx
|
|
|
|
|
|
{
|
|
|
|
|
|
static readonly ILog log = LogManager.GetLogger(typeof(PathsDlg));
|
|
|
|
|
|
|
|
|
|
|
|
enum PathsDlgTabs
|
|
|
|
|
|
{
|
|
|
|
|
|
Feeding,
|
|
|
|
|
|
Bench,
|
|
|
|
|
|
Output,
|
|
|
|
|
|
Meters,
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// Used when re-scaling the dialog: 100% = 96dpi, 125% = 120dpi, 150% = 144dpi
|
|
|
|
|
|
public readonly int Dpi;
|
|
|
|
|
|
public const int Dpi100pct = 96;
|
|
|
|
|
|
|
|
|
|
|
|
public IList<BenchControl.Generic.IComponent> TbfComponents;
|
|
|
|
|
|
public IList<IValve> Valves;
|
|
|
|
|
|
public ISession Session; /// One common DB session passed also to the controls inside tab pages
|
|
|
|
|
|
|
|
|
|
|
|
public PathsDlg()
|
|
|
|
|
|
{
|
|
|
|
|
|
/// Detect display setting: 100% = 96dpi, 125% = 120dpi, 150% = 144dpi.
|
|
|
|
|
|
Dpi = (int)this.CreateGraphics().DpiX;
|
|
|
|
|
|
|
|
|
|
|
|
InitializeComponent();
|
|
|
|
|
|
|
|
|
|
|
|
/// SharedDlgButtons configuration
|
2015-12-04 16:17:20 +00:00
|
|
|
|
sharedButtons.RequiredGroupMembership = Config.Grp.GID.Metrologists;
|
2014-07-28 07:54:35 +00:00
|
|
|
|
sharedButtons.OptionalButtons = SharedButtons.Buttons.Add | SharedButtons.Buttons.Remove |
|
|
|
|
|
|
SharedButtons.Buttons.Up | SharedButtons.Buttons.Down;
|
|
|
|
|
|
sharedButtons.Unlocked += Unlocked;
|
|
|
|
|
|
sharedButtons.OKClicked += okButton_Click;
|
|
|
|
|
|
sharedButtons.CancelClicked += cancelButton_Click;
|
|
|
|
|
|
sharedButtons.AddClicked += addButton_Click;
|
|
|
|
|
|
sharedButtons.RemoveClicked += removeButton_Click;
|
|
|
|
|
|
sharedButtons.UpClicked += upButton_Click;
|
|
|
|
|
|
sharedButtons.DownClicked += downButton_Click;
|
|
|
|
|
|
|
|
|
|
|
|
/// Load the list of components from the database
|
2015-12-31 21:48:22 +00:00
|
|
|
|
TbfComponents = BenchControl.TbfComponents.LoadComponentsFromDB(Config.FluentCommon.CreateSession(Config.Entities.DBKind.Config));
|
2014-07-28 07:54:35 +00:00
|
|
|
|
|
|
|
|
|
|
/// Find all master valves
|
|
|
|
|
|
Valves = BenchControl.GenericDevices.ValveBase.MasterValves(TbfComponents);
|
|
|
|
|
|
|
|
|
|
|
|
/// Create the database session for paths
|
2015-12-31 21:48:22 +00:00
|
|
|
|
Session = Config.FluentCommon.CreateSession(Config.Entities.DBKind.Config);
|
2014-07-28 07:54:35 +00:00
|
|
|
|
|
|
|
|
|
|
pathsTabControl.TabPages[(int)PathsDlgTabs.Feeding].Tag = pathsFeedingCtrl;
|
|
|
|
|
|
pathsTabControl.TabPages[(int)PathsDlgTabs.Bench].Tag = pathsBenchCtrl;
|
|
|
|
|
|
pathsTabControl.TabPages[(int)PathsDlgTabs.Output].Tag = pathsOutputCtrl;
|
|
|
|
|
|
pathsTabControl.TabPages[(int)PathsDlgTabs.Meters].Tag = pathsMetersCtrl;
|
|
|
|
|
|
|
|
|
|
|
|
// Requires 'Session' to be created
|
|
|
|
|
|
pathsFeedingCtrl.Initialize(this, pathsTabControl.TabPages[(int)PathsDlgTabs.Feeding]);
|
|
|
|
|
|
pathsBenchCtrl.Initialize(this, pathsTabControl.TabPages[(int)PathsDlgTabs.Bench]);
|
|
|
|
|
|
pathsOutputCtrl.Initialize(this, pathsTabControl.TabPages[(int)PathsDlgTabs.Output]);
|
|
|
|
|
|
pathsMetersCtrl.Initialize(this, pathsTabControl.TabPages[(int)PathsDlgTabs.Meters]);
|
2014-09-07 07:34:28 +00:00
|
|
|
|
}
|
2014-07-28 07:54:35 +00:00
|
|
|
|
|
|
|
|
|
|
private void PathsDlg_Load(object sender, EventArgs e)
|
|
|
|
|
|
{
|
2016-03-16 08:43:05 +00:00
|
|
|
|
Localize();
|
2014-09-07 07:34:28 +00:00
|
|
|
|
TBF.LocalSettings ls = Program.LocalSettings;
|
|
|
|
|
|
Width = (ls.PathsDlgWidth > 0) ? ls.PathsDlgWidth : 1050;
|
|
|
|
|
|
Height = (ls.PathsDlgHeight > 0) ? ls.PathsDlgHeight : 360;
|
|
|
|
|
|
Left = (ls.PathsDlgLeft != 0) ? ls.PathsDlgLeft : 150;
|
|
|
|
|
|
Top = (ls.PathsDlgTop != 0) ? ls.PathsDlgTop : 150;
|
|
|
|
|
|
}
|
2014-07-28 07:54:35 +00:00
|
|
|
|
|
2016-03-16 08:43:05 +00:00
|
|
|
|
private void Localize()
|
|
|
|
|
|
{
|
|
|
|
|
|
Text = Strings.PathsDlgTitle;
|
|
|
|
|
|
pathsTabControl.TabPages[(int)PathsDlgTabs.Feeding].Text = Strings.FeedingTabPageTitle;
|
|
|
|
|
|
pathsTabControl.TabPages[(int)PathsDlgTabs.Bench].Text = Strings.BenchTabPageTitle;
|
|
|
|
|
|
pathsTabControl.TabPages[(int)PathsDlgTabs.Output].Text = Strings.OutputTabPageTitle;
|
|
|
|
|
|
pathsTabControl.TabPages[(int)PathsDlgTabs.Meters].Text = Strings.MetersTabPageTitle;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2014-07-28 07:54:35 +00:00
|
|
|
|
private void Unlocked(object sender, EventArgs e)
|
|
|
|
|
|
{
|
|
|
|
|
|
foreach (TabPage tab in pathsTabControl.TabPages)
|
|
|
|
|
|
{
|
|
|
|
|
|
(tab.Tag as ITabWithListViewEx).Unlock();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void okButton_Click(object sender, EventArgs e)
|
|
|
|
|
|
{
|
|
|
|
|
|
foreach (TabPage tab in pathsTabControl.TabPages)
|
|
|
|
|
|
{
|
|
|
|
|
|
(tab.Tag as ITabWithListViewEx).OkBtnClicked();
|
|
|
|
|
|
}
|
2014-09-07 07:34:28 +00:00
|
|
|
|
|
|
|
|
|
|
Program.LocalSettings.PathsDlgLeft = Location.X;
|
|
|
|
|
|
Program.LocalSettings.PathsDlgTop = Location.Y;
|
|
|
|
|
|
Program.LocalSettings.PathsDlgWidth = Size.Width;
|
|
|
|
|
|
Program.LocalSettings.PathsDlgHeight = Size.Height;
|
|
|
|
|
|
Program.LocalSettings.Save();
|
|
|
|
|
|
|
|
|
|
|
|
DialogResult = DialogResult.OK;
|
2014-07-28 07:54:35 +00:00
|
|
|
|
Close();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void cancelButton_Click(object sender, EventArgs e)
|
|
|
|
|
|
{
|
2014-09-07 07:34:28 +00:00
|
|
|
|
Program.LocalSettings.PathsDlgLeft = Location.X;
|
|
|
|
|
|
Program.LocalSettings.PathsDlgTop = Location.Y;
|
|
|
|
|
|
Program.LocalSettings.PathsDlgWidth = Size.Width;
|
|
|
|
|
|
Program.LocalSettings.PathsDlgHeight = Size.Height;
|
|
|
|
|
|
Program.LocalSettings.Save();
|
|
|
|
|
|
|
|
|
|
|
|
foreach (TabPage tab in pathsTabControl.TabPages)
|
2014-07-28 07:54:35 +00:00
|
|
|
|
{
|
|
|
|
|
|
(tab.Tag as ITabWithListViewEx).CancelBtnClicked();
|
|
|
|
|
|
}
|
|
|
|
|
|
DialogResult = DialogResult.Cancel;
|
|
|
|
|
|
Close();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void addButton_Click(object sender, EventArgs e)
|
|
|
|
|
|
{
|
|
|
|
|
|
(pathsTabControl.SelectedTab.Tag as ITabWithListViewEx).AddOne();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void removeButton_Click(object sender, EventArgs e)
|
|
|
|
|
|
{
|
|
|
|
|
|
(pathsTabControl.SelectedTab.Tag as ITabWithListViewEx).RemoveSelected();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void upButton_Click(object sender, EventArgs e)
|
|
|
|
|
|
{
|
|
|
|
|
|
(pathsTabControl.SelectedTab.Tag as ITabWithListViewEx).MoveUpSelected();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void downButton_Click(object sender, EventArgs e)
|
|
|
|
|
|
{
|
|
|
|
|
|
(pathsTabControl.SelectedTab.Tag as ITabWithListViewEx).MoveDownSelected();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Common part for three xxxListViewEx_SelectedIndexChanged event handlers
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="listViewEx"></param>
|
|
|
|
|
|
void SelectedIndexChanged(object sender, EventArgs e)
|
|
|
|
|
|
{
|
|
|
|
|
|
ListViewEx listViewEx = sender as ListViewEx;
|
|
|
|
|
|
if (listViewEx.SelectedItems.Count != 1)
|
|
|
|
|
|
{
|
|
|
|
|
|
/// No item selected
|
|
|
|
|
|
sharedButtons.DisableButtons(SharedButtons.Buttons.Remove | SharedButtons.Buttons.Up | SharedButtons.Buttons.Down);
|
|
|
|
|
|
}
|
|
|
|
|
|
else if (listViewEx.Items.Count == 1)
|
|
|
|
|
|
{
|
|
|
|
|
|
/// One (the first and the last) item selected
|
|
|
|
|
|
sharedButtons.EnableButtons(SharedButtons.Buttons.Remove);
|
|
|
|
|
|
sharedButtons.DisableButtons(SharedButtons.Buttons.Up | SharedButtons.Buttons.Down);
|
|
|
|
|
|
}
|
|
|
|
|
|
else if (listViewEx.SelectedIndices[0] == 0)
|
|
|
|
|
|
{
|
|
|
|
|
|
/// The first of many items selected
|
|
|
|
|
|
sharedButtons.EnableButtons(SharedButtons.Buttons.Remove | SharedButtons.Buttons.Down);
|
|
|
|
|
|
sharedButtons.DisableButtons(SharedButtons.Buttons.Up);
|
|
|
|
|
|
}
|
|
|
|
|
|
else if (listViewEx.SelectedIndices[0] == (listViewEx.Items.Count - 1))
|
|
|
|
|
|
{
|
|
|
|
|
|
/// The last of many items selected
|
|
|
|
|
|
sharedButtons.EnableButtons(SharedButtons.Buttons.Remove | SharedButtons.Buttons.Up);
|
|
|
|
|
|
sharedButtons.DisableButtons(SharedButtons.Buttons.Down);
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
/// One of middle items selected
|
|
|
|
|
|
sharedButtons.EnableButtons(SharedButtons.Buttons.Remove | SharedButtons.Buttons.Up | SharedButtons.Buttons.Down);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Tab page changed - item is unselected
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
private void pathsTabControl_SelectedIndexChanged(object sender, EventArgs e)
|
|
|
|
|
|
{
|
|
|
|
|
|
UpdateButtonStates(SharedButtons.SelectedItemPos.None);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void UpdateButtonStates(SharedButtons.SelectedItemPos selectedItemPos)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (selectedItemPos == SharedButtons.SelectedItemPos.None)
|
|
|
|
|
|
{
|
|
|
|
|
|
sharedButtons.DisableButtons(SharedButtons.Buttons.Remove | SharedButtons.Buttons.Up | SharedButtons.Buttons.Down);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|