Bug fix - Refactor flow meter handling and add validation checks.
Simplified flow meter logic by introducing a reusable variable for `LtrPerPulse` and handling potential null values. Added batch components correlation validation to ensure water meter counts align with configuration, preventing mismatches. Additionally, improved code formatting for consistency and readability.
This commit is contained in:
@@ -1,9 +1,11 @@
|
||||
///
|
||||
/// Copyright (c) 2013-2021 Sensus Slovensko a.s.
|
||||
///
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Web.UI;
|
||||
using System.Windows.Forms;
|
||||
using log4net;
|
||||
using NHibernate;
|
||||
@@ -13,27 +15,31 @@ using Config.Entities;
|
||||
using TBF.Rig;
|
||||
using TBF.Rig.Generic;
|
||||
using TBF.Resources;
|
||||
using TBF.Rig.GenericDevices;
|
||||
using TBF.Rig.WaterMeters.WaterMeter;
|
||||
using TBF.UI.Shared;
|
||||
|
||||
namespace TBF.UI.Bench.Components
|
||||
{
|
||||
public partial class ComponentsManagerDlg : Form, IParentOfListViewEx
|
||||
{
|
||||
static readonly ILog log = LogManager.GetLogger(typeof(ComponentsManagerDlg));
|
||||
public partial class ComponentsManagerDlg : Form, IParentOfListViewEx
|
||||
{
|
||||
static readonly ILog log = LogManager.GetLogger(typeof(ComponentsManagerDlg));
|
||||
|
||||
/// <summary>
|
||||
/// List of components (=component configuration instances)
|
||||
/// </summary>
|
||||
IList<Component> cmpntEntities;
|
||||
/// <summary>
|
||||
/// List of components (=component configuration instances)
|
||||
/// </summary>
|
||||
IList<Component> cmpntEntities;
|
||||
|
||||
IList<Component> toBeDeletedEntities;
|
||||
IList<Component> toBeDeletedEntities;
|
||||
|
||||
ISession session;
|
||||
ISession session;
|
||||
|
||||
SelectComponentClassDlg selectComponentTypeDlg; /// Constructed once, the selection is kept between dialog usages
|
||||
SelectComponentClassDlg selectComponentTypeDlg;
|
||||
|
||||
CfgUpdateFlags flags; /// Or-ed from particular Flags from ComponentParametersDlg
|
||||
|
||||
/// Constructed once, the selection is kept between dialog usages
|
||||
CfgUpdateFlags flags;
|
||||
|
||||
/// Or-ed from particular Flags from ComponentParametersDlg
|
||||
/// <summary>
|
||||
/// ListViewEx columns
|
||||
/// </summary>
|
||||
@@ -50,27 +56,29 @@ namespace TBF.UI.Bench.Components
|
||||
}
|
||||
|
||||
MySortOrder sortOrder = MySortOrder.Ascending;
|
||||
int sortColumn = -1; /// 0-based index of column to be used for sorting
|
||||
int sortColumn = -1;
|
||||
|
||||
/// Editors used by listViewEx
|
||||
/// 0-based index of column to be used for sorting
|
||||
/// Editors used by listViewEx
|
||||
ComboBox debugCB;
|
||||
|
||||
ComboBox logCB;
|
||||
|
||||
bool unlocked;
|
||||
bool unlocked;
|
||||
|
||||
public ComponentsManagerDlg()
|
||||
{
|
||||
toBeDeletedEntities = new List<Component>();
|
||||
public ComponentsManagerDlg()
|
||||
{
|
||||
toBeDeletedEntities = new List<Component>();
|
||||
|
||||
InitializeComponent();
|
||||
InitializeComponent();
|
||||
|
||||
flags = CfgUpdateFlags.None;
|
||||
flags = CfgUpdateFlags.None;
|
||||
|
||||
selectComponentTypeDlg = new SelectComponentClassDlg();
|
||||
selectComponentTypeDlg = new SelectComponentClassDlg();
|
||||
|
||||
/// SharedDlgButtons configuration
|
||||
/// SharedDlgButtons configuration
|
||||
sharedButtons.ParentForm = this;
|
||||
sharedButtons.RequiredGroupMembership = new GID[] { GID.Metrologists };
|
||||
sharedButtons.RequiredGroupMembership = new GID[] { GID.Metrologists };
|
||||
|
||||
sharedButtons.OptionalButtons = SharedButtons.Buttons.Add |
|
||||
SharedButtons.Buttons.Remove |
|
||||
@@ -81,34 +89,35 @@ namespace TBF.UI.Bench.Components
|
||||
SharedButtons.Buttons.Export |
|
||||
SharedButtons.Buttons.Import;
|
||||
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;
|
||||
sharedButtons.EditClicked += editButton_Click;
|
||||
sharedButtons.OKClicked += okButton_Click;
|
||||
sharedButtons.CancelClicked += cancelButton_Click;
|
||||
sharedButtons.AddClicked += addButton_Click;
|
||||
sharedButtons.RemoveClicked += removeButton_Click;
|
||||
sharedButtons.UpClicked += upButton_Click;
|
||||
sharedButtons.DownClicked += downButton_Click;
|
||||
sharedButtons.EditClicked += editButton_Click;
|
||||
sharedButtons.CopyClicked += copyButton_Click;
|
||||
sharedButtons.ExportClicked += exportButton_Click;
|
||||
sharedButtons.ImportClicked += importButton_Click;
|
||||
}
|
||||
|
||||
private void ComponentsManagerDlg_Load(object sender, EventArgs e)
|
||||
{
|
||||
private void ComponentsManagerDlg_Load(object sender, EventArgs e)
|
||||
{
|
||||
LoadFormPosition();
|
||||
|
||||
Text = Strings.Test_Bench_Components_Configuration;
|
||||
LocalSettings ls = Program.LocalSettings;
|
||||
listViewEx.Columns.Add(Strings.Nr, (ls.ComponentsColumnCount > 0) ? ls.ComponentsColumnWidths[0] : 40);
|
||||
listViewEx.Columns.Add(Strings.Name, (ls.ComponentsColumnCount > 1) ? ls.ComponentsColumnWidths[1] : 80);
|
||||
listViewEx.Columns.Add(Strings.Type, (ls.ComponentsColumnCount > 2) ? ls.ComponentsColumnWidths[2] : 120);
|
||||
listViewEx.Columns.Add(Strings.Parent, (ls.ComponentsColumnCount > 3) ? ls.ComponentsColumnWidths[3] : 55);
|
||||
listViewEx.Columns.Add(Strings.Mode, (ls.ComponentsColumnCount > 4) ? ls.ComponentsColumnWidths[4] : 55);
|
||||
listViewEx.Columns.Add(Strings.Logging, (ls.ComponentsColumnCount > 5) ? ls.ComponentsColumnWidths[5] : 55);
|
||||
listViewEx.Columns.Add(Strings.Parameters, (ls.ComponentsColumnCount > 6) ? ls.ComponentsColumnWidths[6] : 600);
|
||||
listViewEx.Columns.Add(Strings.Nr, (ls.ComponentsColumnCount > 0) ? ls.ComponentsColumnWidths[0] : 40);
|
||||
listViewEx.Columns.Add(Strings.Name, (ls.ComponentsColumnCount > 1) ? ls.ComponentsColumnWidths[1] : 80);
|
||||
listViewEx.Columns.Add(Strings.Type, (ls.ComponentsColumnCount > 2) ? ls.ComponentsColumnWidths[2] : 120);
|
||||
listViewEx.Columns.Add(Strings.Parent, (ls.ComponentsColumnCount > 3) ? ls.ComponentsColumnWidths[3] : 55);
|
||||
listViewEx.Columns.Add(Strings.Mode, (ls.ComponentsColumnCount > 4) ? ls.ComponentsColumnWidths[4] : 55);
|
||||
listViewEx.Columns.Add(Strings.Logging, (ls.ComponentsColumnCount > 5) ? ls.ComponentsColumnWidths[5] : 55);
|
||||
listViewEx.Columns.Add(Strings.Parameters,
|
||||
(ls.ComponentsColumnCount > 6) ? ls.ComponentsColumnWidths[6] : 600);
|
||||
listViewEx.HeaderStyle = ColumnHeaderStyle.Clickable;
|
||||
|
||||
debugCB = new ComboBox();
|
||||
debugCB = new ComboBox();
|
||||
for (DebugMode level = 0; level < DebugMode.Count; level++) debugCB.Items.Add(level.ToDescription());
|
||||
splitContainer.Panel1.Controls.Add(debugCB);
|
||||
|
||||
@@ -119,23 +128,23 @@ namespace TBF.UI.Bench.Components
|
||||
listViewEx.SubItemClicked += new SubItemEventHandler(listViewEx_SubItemClicked);
|
||||
listViewEx.SubItemEndEditing += new SubItemEndEditingEventHandler(listViewEx_SubItemEndEditing);
|
||||
|
||||
sharedButtons.DisableButtons(SharedButtons.Buttons.Remove | SharedButtons.Buttons.Edit);
|
||||
sharedButtons.DisableButtons(SharedButtons.Buttons.Remove | SharedButtons.Buttons.Edit);
|
||||
|
||||
session = TBF.DB.CreateSession(DBKind.Config);
|
||||
cmpntEntities = session.QueryOver<Component>()
|
||||
.OrderBy(x => x.ItemNr).Asc
|
||||
.List<Component>();
|
||||
session = TBF.DB.CreateSession(DBKind.Config);
|
||||
cmpntEntities = session.QueryOver<Component>()
|
||||
.OrderBy(x => x.ItemNr).Asc
|
||||
.List<Component>();
|
||||
|
||||
RedrawAll();
|
||||
}
|
||||
RedrawAll();
|
||||
}
|
||||
|
||||
void listViewEx_SubItemClicked(object sender, SubItemEventArgs e)
|
||||
{
|
||||
if (unlocked && e.SubItem == (int)Column.DebugMode)
|
||||
if (unlocked && e.SubItem == (int)Column.DebugMode)
|
||||
{
|
||||
listViewEx.StartEditing(debugCB, e.Item, e.SubItem);
|
||||
}
|
||||
else if (unlocked && e.SubItem == (int)Column.Logging)
|
||||
else if (unlocked && e.SubItem == (int)Column.Logging)
|
||||
{
|
||||
listViewEx.StartEditing(logCB, e.Item, e.SubItem);
|
||||
}
|
||||
@@ -146,7 +155,7 @@ namespace TBF.UI.Bench.Components
|
||||
if (!unlocked || ((e.SubItem != (int)Column.DebugMode) && (e.SubItem != (int)Column.Logging))) return;
|
||||
|
||||
if (DialogResult.Yes == MessageBox.Show(Strings.Do_you_want_to_copy_this_value_to_all_cells_below_this_cell,
|
||||
Strings.Confirmation, MessageBoxButtons.YesNo, MessageBoxIcon.Question))
|
||||
Strings.Confirmation, MessageBoxButtons.YesNo, MessageBoxIcon.Question))
|
||||
{
|
||||
int columnNr = e.SubItem;
|
||||
string value = null;
|
||||
@@ -204,10 +213,11 @@ namespace TBF.UI.Bench.Components
|
||||
if (debugCB.Text.Equals(level.ToDescription()))
|
||||
{
|
||||
cmpnt.DebugMode = level;
|
||||
flags |= CfgUpdateFlags.RestartRqrd;
|
||||
flags |= CfgUpdateFlags.RestartRqrd;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
e.DisplayText = cmpnt.DebugMode.ToString();
|
||||
}
|
||||
else if (e.SubItem == (int)Column.Logging)
|
||||
@@ -217,35 +227,36 @@ namespace TBF.UI.Bench.Components
|
||||
if (logCB.Text.Equals(level.ToDescription()))
|
||||
{
|
||||
cmpnt.LogLevel = level;
|
||||
flags |= CfgUpdateFlags.RestartRqrd;
|
||||
return;
|
||||
flags |= CfgUpdateFlags.RestartRqrd;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
e.DisplayText = cmpnt.LogLevel.ToString();
|
||||
}
|
||||
}
|
||||
|
||||
private void Unlocked(object sender, EventArgs e)
|
||||
{
|
||||
unlocked = true;
|
||||
private void Unlocked(object sender, EventArgs e)
|
||||
{
|
||||
unlocked = true;
|
||||
|
||||
if (listViewEx.SelectedItems.Count == 1)
|
||||
{
|
||||
int ix = listViewEx.SelectedIndices[0];
|
||||
Focus();
|
||||
listViewEx.Items[ix].Selected = true;
|
||||
listViewEx.Items[ix].EnsureVisible();
|
||||
}
|
||||
}
|
||||
if (listViewEx.SelectedItems.Count == 1)
|
||||
{
|
||||
int ix = listViewEx.SelectedIndices[0];
|
||||
Focus();
|
||||
listViewEx.Items[ix].Selected = true;
|
||||
listViewEx.Items[ix].EnsureVisible();
|
||||
}
|
||||
}
|
||||
|
||||
void RedrawAll()
|
||||
{
|
||||
listViewEx.Items.Clear();
|
||||
foreach (var cmpnt in cmpntEntities) DrawOne(cmpnt);
|
||||
}
|
||||
void RedrawAll()
|
||||
{
|
||||
listViewEx.Items.Clear();
|
||||
foreach (var cmpnt in cmpntEntities) DrawOne(cmpnt);
|
||||
}
|
||||
|
||||
void DrawOne(Component cmpnt)
|
||||
{
|
||||
void DrawOne(Component cmpnt)
|
||||
{
|
||||
ListViewItem lvi = new ListViewItem(cmpnt.ItemNr.ToString());
|
||||
lvi.Tag = cmpnt;
|
||||
lvi.SubItems.Add(cmpnt.Name);
|
||||
@@ -254,18 +265,17 @@ namespace TBF.UI.Bench.Components
|
||||
|
||||
IComponentCfg cmpCfg = TbfComponents.CmpntCfgFromCmpntEntity(cmpnt);
|
||||
if (cmpCfg != null)
|
||||
{
|
||||
{
|
||||
lvi.SubItems.Add(cmpCfg.DebugLevel.ToDescription());
|
||||
lvi.SubItems.Add(cmpCfg.LogLevel.ToDescription());
|
||||
lvi.SubItems.Add(cmpCfg.ToString(-1));
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
lvi.SubItems.Add("---");
|
||||
lvi.SubItems.Add("---");
|
||||
lvi.SubItems.Add("Not a component");
|
||||
}
|
||||
lvi.SubItems.Add(cmpCfg.LogLevel.ToDescription());
|
||||
lvi.SubItems.Add(cmpCfg.ToString(-1));
|
||||
}
|
||||
else
|
||||
{
|
||||
lvi.SubItems.Add("---");
|
||||
lvi.SubItems.Add("---");
|
||||
lvi.SubItems.Add("Not a component");
|
||||
}
|
||||
|
||||
listViewEx.Items.Add(lvi);
|
||||
}
|
||||
@@ -304,10 +314,10 @@ namespace TBF.UI.Bench.Components
|
||||
private void LoadFormPosition()
|
||||
{
|
||||
LocalSettings ls = Program.LocalSettings;
|
||||
Width = (ls.ComponentsDlgWidth > 0) ? ls.ComponentsDlgWidth : 850;
|
||||
Width = (ls.ComponentsDlgWidth > 0) ? ls.ComponentsDlgWidth : 850;
|
||||
Height = (ls.ComponentsDlgHeight > 0) ? ls.ComponentsDlgHeight : 500;
|
||||
Left = (ls.ComponentsDlgLeft != 0) ? ls.ComponentsDlgLeft : 200;
|
||||
Top = (ls.ComponentsDlgTop != 0) ? ls.ComponentsDlgTop : 100;
|
||||
Left = (ls.ComponentsDlgLeft != 0) ? ls.ComponentsDlgLeft : 200;
|
||||
Top = (ls.ComponentsDlgTop != 0) ? ls.ComponentsDlgTop : 100;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -334,7 +344,11 @@ namespace TBF.UI.Bench.Components
|
||||
{
|
||||
for (int i = 0; i < (int)Column.ColumnsCount; i++)
|
||||
{
|
||||
if (listViewEx.Columns[i].Width != ls.ComponentsColumnWidths[i]) { anyColumnDiffers = true; break; }
|
||||
if (listViewEx.Columns[i].Width != ls.ComponentsColumnWidths[i])
|
||||
{
|
||||
anyColumnDiffers = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -366,84 +380,149 @@ namespace TBF.UI.Bench.Components
|
||||
}
|
||||
|
||||
///
|
||||
/// OK
|
||||
/// OK
|
||||
///
|
||||
private void okButton_Click(object sender, EventArgs e)
|
||||
{
|
||||
if ((flags & CfgUpdateFlags.AnyChange) != 0 || (flags & CfgUpdateFlags.RestartRqrd) != 0)
|
||||
{
|
||||
{
|
||||
ValidateComponents();
|
||||
if ((flags & CfgUpdateFlags.AnyChange) != 0 || (flags & CfgUpdateFlags.RestartRqrd) != 0)
|
||||
{
|
||||
SaveDBChanges(session);
|
||||
flags = CfgUpdateFlags.None; /// Changes saved
|
||||
flags = CfgUpdateFlags.None; /// Changes saved
|
||||
}
|
||||
|
||||
SaveUISettings();
|
||||
|
||||
DialogResult = DialogResult.OK;
|
||||
Close();
|
||||
return;
|
||||
}
|
||||
Close();
|
||||
return;
|
||||
}
|
||||
|
||||
/// Cancel
|
||||
private void cancelButton_Click(object sender, EventArgs e)
|
||||
{
|
||||
private void ValidateComponents()
|
||||
{
|
||||
Boolean invalid = false;
|
||||
string validationMessage = "";
|
||||
//validation cycle
|
||||
invalid = !ValidateMetersBatchCount(out validationMessage);
|
||||
|
||||
if (invalid)
|
||||
{
|
||||
MessageBox.Show(validationMessage, Strings.Warning, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
|
||||
}
|
||||
}
|
||||
|
||||
private Boolean ValidateMetersBatchCount(out string message)
|
||||
{
|
||||
bool invalid = false;
|
||||
|
||||
TBF.Rig.DataContainer.BenchInfo.ComponentCfg benchInfo = null;
|
||||
int waterMetersCount = 0;
|
||||
int iWaterMeterComponentCount = 0;
|
||||
foreach (Component component in cmpntEntities)
|
||||
{
|
||||
if (component == null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
string className = (string.IsNullOrEmpty(component.ClassName) ? string.Empty : component.ClassName);
|
||||
if (className == "DataContainer.BenchInfo")
|
||||
{
|
||||
try
|
||||
{
|
||||
var cfg = new TBF.Rig.DataContainer.BenchInfo.Factory().CmpntCfgFromCmpntEntity(component)
|
||||
as TBF.Rig.DataContainer.BenchInfo.ComponentCfg;
|
||||
|
||||
waterMetersCount = cfg.WaterMetersCount;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
log.Error("Finding of DataContainer.BenchInfo data unsuccessfully!");
|
||||
}
|
||||
}
|
||||
|
||||
if (className == "WaterMeter")
|
||||
{
|
||||
iWaterMeterComponentCount++;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
invalid = (waterMetersCount != iWaterMeterComponentCount);
|
||||
|
||||
|
||||
if (invalid)
|
||||
{
|
||||
message = "The count of water meters on the bench does not match the count of their components!";
|
||||
return false;
|
||||
}
|
||||
|
||||
message = "";
|
||||
return true;
|
||||
}
|
||||
|
||||
/// Cancel
|
||||
private void cancelButton_Click(object sender, EventArgs e)
|
||||
{
|
||||
SaveUISettings();
|
||||
|
||||
if ((flags & CfgUpdateFlags.AnyChange) != 0 || (flags & CfgUpdateFlags.RestartRqrd) != 0)
|
||||
{
|
||||
DialogResult dr = MessageBox.Show(Strings.Changes_will_be_lost_Do_you_want_to_proceed,
|
||||
Strings.Warning,
|
||||
MessageBoxButtons.YesNo,
|
||||
MessageBoxIcon.Question);
|
||||
if (dr != DialogResult.Yes) return;
|
||||
}
|
||||
if ((flags & CfgUpdateFlags.AnyChange) != 0 || (flags & CfgUpdateFlags.RestartRqrd) != 0)
|
||||
{
|
||||
DialogResult dr = MessageBox.Show(Strings.Changes_will_be_lost_Do_you_want_to_proceed,
|
||||
Strings.Warning,
|
||||
MessageBoxButtons.YesNo,
|
||||
MessageBoxIcon.Question);
|
||||
if (dr != DialogResult.Yes) return;
|
||||
}
|
||||
|
||||
flags = CfgUpdateFlags.None; /// Abandoning changes confirmed
|
||||
flags = CfgUpdateFlags.None; /// Abandoning changes confirmed
|
||||
|
||||
DialogResult = DialogResult.Cancel;
|
||||
Close();
|
||||
return;
|
||||
}
|
||||
Close();
|
||||
return;
|
||||
}
|
||||
|
||||
/// Add a new component
|
||||
private void addButton_Click(object sender, EventArgs e)
|
||||
{
|
||||
selectComponentTypeDlg.SelectedScriptName = null;
|
||||
DialogResult dialogRslt = selectComponentTypeDlg.ShowDialog();
|
||||
if (dialogRslt != DialogResult.OK) return;
|
||||
/// Add a new component
|
||||
private void addButton_Click(object sender, EventArgs e)
|
||||
{
|
||||
selectComponentTypeDlg.SelectedScriptName = null;
|
||||
DialogResult dialogRslt = selectComponentTypeDlg.ShowDialog();
|
||||
if (dialogRslt != DialogResult.OK) return;
|
||||
|
||||
IComponentFactory factory = selectComponentTypeDlg.SlctdCmpntFactory;
|
||||
IComponentFactory factory = selectComponentTypeDlg.SlctdCmpntFactory;
|
||||
IComponentCfg cfg = factory.DefaultConfig();
|
||||
if (selectComponentTypeDlg.SelectedScriptName == null)
|
||||
{
|
||||
{
|
||||
///
|
||||
/// Create a single component of the selected type
|
||||
///
|
||||
IComponentCfgCtrl cfgControl = cfg.GetControl(cmpntEntities);
|
||||
cfgControl.Config = cfg;
|
||||
cfgControl.Config.ItemNr = (cmpntEntities.Count > 0) ? (cmpntEntities[cmpntEntities.Count - 1].ItemNr + 1) : 1;
|
||||
cfgControl.Config = cfg;
|
||||
cfgControl.Config.ItemNr =
|
||||
(cmpntEntities.Count > 0) ? (cmpntEntities[cmpntEntities.Count - 1].ItemNr + 1) : 1;
|
||||
|
||||
ComponentParametersDlg cfgForm = new ComponentParametersDlg(this);
|
||||
cfgForm.CmpntEntities = cmpntEntities;
|
||||
cfgForm.ComponentCfgCtrl = cfgControl;
|
||||
cfgForm.UnlockAfterStart = true;
|
||||
dialogRslt = cfgForm.ShowDialog();
|
||||
if (dialogRslt != DialogResult.OK) return;
|
||||
ComponentParametersDlg cfgForm = new ComponentParametersDlg(this);
|
||||
cfgForm.CmpntEntities = cmpntEntities;
|
||||
cfgForm.ComponentCfgCtrl = cfgControl;
|
||||
cfgForm.UnlockAfterStart = true;
|
||||
dialogRslt = cfgForm.ShowDialog();
|
||||
if (dialogRslt != DialogResult.OK) return;
|
||||
|
||||
flags |= CfgUpdateFlags.RestartRqrd;
|
||||
AddOne(cfgForm.Config.CreateDbEntity());
|
||||
}
|
||||
else
|
||||
{
|
||||
flags |= CfgUpdateFlags.RestartRqrd;
|
||||
AddOne(cfgForm.Config.CreateDbEntity());
|
||||
}
|
||||
else
|
||||
{
|
||||
///
|
||||
/// Create more components, read their names and other properties from a file
|
||||
///
|
||||
using (TextReader reader = new StreamReader(selectComponentTypeDlg.SelectedScriptName))
|
||||
{
|
||||
int zeroBasedIdx = 0;
|
||||
string line = reader.ReadLine();
|
||||
while (line != null)
|
||||
{
|
||||
line.Trim();
|
||||
{
|
||||
int zeroBasedIdx = 0;
|
||||
string line = reader.ReadLine();
|
||||
while (line != null)
|
||||
{
|
||||
line.Trim();
|
||||
if (line.Length > 0)
|
||||
{
|
||||
string[] words = line.Split(new char[] { ' ', '\t' });
|
||||
@@ -451,83 +530,85 @@ namespace TBF.UI.Bench.Components
|
||||
if (UpdateCfg(ref cfg, words, ref zeroBasedIdx))
|
||||
{
|
||||
flags |= CfgUpdateFlags.RestartRqrd;
|
||||
cfg.ItemNr = (cmpntEntities.Count > 0) ? (cmpntEntities[cmpntEntities.Count - 1].ItemNr + 1) : 1;
|
||||
cfg.ItemNr = (cmpntEntities.Count > 0)
|
||||
? (cmpntEntities[cmpntEntities.Count - 1].ItemNr + 1)
|
||||
: 1;
|
||||
AddOne(cfg.CreateDbEntity());
|
||||
}
|
||||
|
||||
|
||||
zeroBasedIdx++;
|
||||
}
|
||||
|
||||
line = reader.ReadLine();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
line = reader.ReadLine();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void AddOne(Component cmpnt)
|
||||
{
|
||||
cmpntEntities.Add(cmpnt);
|
||||
DrawOne(cmpnt);
|
||||
}
|
||||
void AddOne(Component cmpnt)
|
||||
{
|
||||
cmpntEntities.Add(cmpnt);
|
||||
DrawOne(cmpnt);
|
||||
}
|
||||
|
||||
/// Delete the component
|
||||
private void removeButton_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (listViewEx.SelectedIndices.Count != 1) return;
|
||||
int ix = listViewEx.SelectedIndices[0];
|
||||
if (ix < 0) return;
|
||||
|
||||
Component selectedCmpnt = (Component)listViewEx.Items[ix].Tag;
|
||||
/// Delete the component
|
||||
private void removeButton_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (listViewEx.SelectedIndices.Count != 1) return;
|
||||
int ix = listViewEx.SelectedIndices[0];
|
||||
if (ix < 0) return;
|
||||
|
||||
Component selectedCmpnt = (Component)listViewEx.Items[ix].Tag;
|
||||
if (selectedCmpnt.Id != 0) toBeDeletedEntities.Add(selectedCmpnt);
|
||||
cmpntEntities.Remove(selectedCmpnt);
|
||||
|
||||
flags |= CfgUpdateFlags.AnyChange;
|
||||
|
||||
RedrawAll();
|
||||
}
|
||||
RedrawAll();
|
||||
}
|
||||
|
||||
/// DoubleClick -> Edit the component
|
||||
private void listViewEx_MouseDoubleClick(object sender, MouseEventArgs e)
|
||||
{
|
||||
editButton_Click(sender, e);
|
||||
}
|
||||
/// DoubleClick -> Edit the component
|
||||
private void listViewEx_MouseDoubleClick(object sender, MouseEventArgs e)
|
||||
{
|
||||
editButton_Click(sender, e);
|
||||
}
|
||||
|
||||
/// Edit a component
|
||||
private void editButton_Click(object sender, EventArgs e)
|
||||
{
|
||||
/// Edit a component
|
||||
private void editButton_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (listViewEx.SelectedIndices.Count != 1) return;
|
||||
ListViewItem lvi = listViewEx.SelectedItems[0];
|
||||
Component component = lvi.Tag as Component;
|
||||
if (component == null) return;
|
||||
|
||||
IComponentCfg cfg = TbfComponents.CmpntCfgFromCmpntEntity(component);
|
||||
if (cfg != null)
|
||||
{
|
||||
IComponentCfg cfg = TbfComponents.CmpntCfgFromCmpntEntity(component);
|
||||
if (cfg != null)
|
||||
{
|
||||
ComponentParametersDlg cfgForm = new ComponentParametersDlg(this, component.Id);
|
||||
cfgForm.CmpntEntities = cmpntEntities;
|
||||
cfgForm.CmpntEntities = cmpntEntities;
|
||||
cfgForm.ComponentCfgCtrl = cfg.GetControl(cmpntEntities);
|
||||
cfgForm.ComponentCfgCtrl.Config = cfg;
|
||||
DialogResult dr = cfgForm.ShowDialog();
|
||||
if (dr != DialogResult.OK) return;
|
||||
cfgForm.ComponentCfgCtrl.Config = cfg;
|
||||
DialogResult dr = cfgForm.ShowDialog();
|
||||
if (dr != DialogResult.OK) return;
|
||||
|
||||
flags |= cfgForm.Flags;
|
||||
flags |= cfgForm.Flags;
|
||||
|
||||
sharedButtons.UnlockButtons(); /// Unlock this dialog buttons as changes were enabled
|
||||
unlocked = true; /// in the ComponentParametersDlg.
|
||||
sharedButtons.UnlockButtons(); /// Unlock this dialog buttons as changes were enabled
|
||||
unlocked = true; /// in the ComponentParametersDlg.
|
||||
|
||||
Component modified = cfgForm.Config.CreateDbEntity();
|
||||
Component original = (Component)lvi.Tag;
|
||||
Component modified = cfgForm.Config.CreateDbEntity();
|
||||
Component original = (Component)lvi.Tag;
|
||||
|
||||
original.Name = modified.Name;
|
||||
original.ClassName = modified.ClassName;
|
||||
original.Parent = modified.Parent;
|
||||
original.DebugMode = modified.DebugMode;
|
||||
original.LogLevel = modified.LogLevel;
|
||||
original.Parameters = modified.Parameters;
|
||||
original.Name = modified.Name;
|
||||
original.ClassName = modified.ClassName;
|
||||
original.Parent = modified.Parent;
|
||||
original.DebugMode = modified.DebugMode;
|
||||
original.LogLevel = modified.LogLevel;
|
||||
original.Parameters = modified.Parameters;
|
||||
|
||||
RedrawAll();
|
||||
}
|
||||
}
|
||||
RedrawAll();
|
||||
}
|
||||
}
|
||||
|
||||
/// Copy a component
|
||||
private void copyButton_Click(object sender, EventArgs e)
|
||||
@@ -535,7 +616,7 @@ namespace TBF.UI.Bench.Components
|
||||
if (listViewEx.SelectedIndices.Count != 1) return;
|
||||
ListViewItem lvi = listViewEx.SelectedItems[0];
|
||||
|
||||
IComponentCfg cfg = TbfComponents.CmpntCfgFromCmpntEntity((Component)lvi.Tag);
|
||||
IComponentCfg cfg = TbfComponents.CmpntCfgFromCmpntEntity((Component)lvi.Tag);
|
||||
if (cfg != null)
|
||||
{
|
||||
cfg.Name += Strings.New_name_copy;
|
||||
@@ -543,7 +624,9 @@ namespace TBF.UI.Bench.Components
|
||||
{
|
||||
IComponentCfgCtrl cfgControl = cfg.GetControl(cmpntEntities);
|
||||
cfgControl.Config = cfg;
|
||||
cfgControl.Config.ItemNr = (cmpntEntities.Count > 0) ? (cmpntEntities[cmpntEntities.Count - 1].ItemNr + 1) : 1;
|
||||
cfgControl.Config.ItemNr = (cmpntEntities.Count > 0)
|
||||
? (cmpntEntities[cmpntEntities.Count - 1].ItemNr + 1)
|
||||
: 1;
|
||||
|
||||
ComponentParametersDlg cfgForm = new ComponentParametersDlg(this);
|
||||
cfgForm.CmpntEntities = cmpntEntities;
|
||||
@@ -588,7 +671,8 @@ namespace TBF.UI.Bench.Components
|
||||
IComponentCfgCtrl cfgControl = cfg.GetControl(cmpntEntities);
|
||||
cfgControl.Config = cfg;
|
||||
cfgControl.Config.Name = cfgControl.Config.Name + " imported";
|
||||
cfgControl.Config.ItemNr = (cmpntEntities.Count > 0) ? (cmpntEntities[cmpntEntities.Count - 1].ItemNr + 1) : 1;
|
||||
cfgControl.Config.ItemNr =
|
||||
(cmpntEntities.Count > 0) ? (cmpntEntities[cmpntEntities.Count - 1].ItemNr + 1) : 1;
|
||||
|
||||
ComponentParametersDlg cfgForm = new ComponentParametersDlg(this);
|
||||
cfgForm.CmpntEntities = cmpntEntities;
|
||||
@@ -601,88 +685,90 @@ namespace TBF.UI.Bench.Components
|
||||
}
|
||||
}
|
||||
|
||||
private void upButton_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (listViewEx.SelectedIndices.Count != 1) return;
|
||||
int ix = listViewEx.SelectedIndices[0];
|
||||
if (ix < 1) return;
|
||||
private void upButton_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (listViewEx.SelectedIndices.Count != 1) return;
|
||||
int ix = listViewEx.SelectedIndices[0];
|
||||
if (ix < 1) return;
|
||||
|
||||
Component item1 = (Component)(listViewEx.Items[ix - 1].Tag);
|
||||
Component item2 = (Component)(listViewEx.Items[ix].Tag);
|
||||
(item1 as IHasItemNr).ItemNr++;
|
||||
(item2 as IHasItemNr).ItemNr--;
|
||||
cmpntEntities.RemoveAt(ix);
|
||||
cmpntEntities.Insert(ix - 1, item2);
|
||||
Component item1 = (Component)(listViewEx.Items[ix - 1].Tag);
|
||||
Component item2 = (Component)(listViewEx.Items[ix].Tag);
|
||||
(item1 as IHasItemNr).ItemNr++;
|
||||
(item2 as IHasItemNr).ItemNr--;
|
||||
cmpntEntities.RemoveAt(ix);
|
||||
cmpntEntities.Insert(ix - 1, item2);
|
||||
|
||||
flags |= CfgUpdateFlags.AnyChange;
|
||||
flags |= CfgUpdateFlags.AnyChange;
|
||||
|
||||
RedrawAll();
|
||||
RedrawAll();
|
||||
|
||||
Focus();
|
||||
listViewEx.Items[ix - 1].Selected = true;
|
||||
listViewEx.Items[ix - 1].EnsureVisible();
|
||||
}
|
||||
Focus();
|
||||
listViewEx.Items[ix - 1].Selected = true;
|
||||
listViewEx.Items[ix - 1].EnsureVisible();
|
||||
}
|
||||
|
||||
private void downButton_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (listViewEx.SelectedIndices.Count != 1) return;
|
||||
int ix = listViewEx.SelectedIndices[0];
|
||||
if (ix >= listViewEx.Items.Count - 1) return;
|
||||
private void downButton_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (listViewEx.SelectedIndices.Count != 1) return;
|
||||
int ix = listViewEx.SelectedIndices[0];
|
||||
if (ix >= listViewEx.Items.Count - 1) return;
|
||||
|
||||
Component item1 = (Component)(listViewEx.Items[ix].Tag);
|
||||
Component item2 = (Component)(listViewEx.Items[ix + 1].Tag);
|
||||
(item1 as IHasItemNr).ItemNr++;
|
||||
(item2 as IHasItemNr).ItemNr--;
|
||||
cmpntEntities.RemoveAt(ix + 1);
|
||||
cmpntEntities.Insert(ix, item2);
|
||||
Component item1 = (Component)(listViewEx.Items[ix].Tag);
|
||||
Component item2 = (Component)(listViewEx.Items[ix + 1].Tag);
|
||||
(item1 as IHasItemNr).ItemNr++;
|
||||
(item2 as IHasItemNr).ItemNr--;
|
||||
cmpntEntities.RemoveAt(ix + 1);
|
||||
cmpntEntities.Insert(ix, item2);
|
||||
|
||||
flags |= CfgUpdateFlags.AnyChange;
|
||||
flags |= CfgUpdateFlags.AnyChange;
|
||||
|
||||
RedrawAll();
|
||||
RedrawAll();
|
||||
|
||||
Focus();
|
||||
listViewEx.Items[ix + 1].Selected = true;
|
||||
listViewEx.Items[ix + 1].EnsureVisible();
|
||||
}
|
||||
Focus();
|
||||
listViewEx.Items[ix + 1].Selected = true;
|
||||
listViewEx.Items[ix + 1].EnsureVisible();
|
||||
}
|
||||
|
||||
private void componentsListView_SelectedIndexChanged(object sender, EventArgs e)
|
||||
{
|
||||
if (listViewEx.SelectedIndices.Count == 1)
|
||||
{
|
||||
sharedButtons.EnableButtons(SharedButtons.Buttons.Remove | SharedButtons.Buttons.Edit);
|
||||
}
|
||||
else
|
||||
{
|
||||
sharedButtons.DisableButtons(SharedButtons.Buttons.Remove | SharedButtons.Buttons.Edit);
|
||||
}
|
||||
}
|
||||
private void componentsListView_SelectedIndexChanged(object sender, EventArgs e)
|
||||
{
|
||||
if (listViewEx.SelectedIndices.Count == 1)
|
||||
{
|
||||
sharedButtons.EnableButtons(SharedButtons.Buttons.Remove | SharedButtons.Buttons.Edit);
|
||||
}
|
||||
else
|
||||
{
|
||||
sharedButtons.DisableButtons(SharedButtons.Buttons.Remove | SharedButtons.Buttons.Edit);
|
||||
}
|
||||
}
|
||||
|
||||
public void UpdateButtonStates(SharedButtons.SelectedItemPos selectedItemPos)
|
||||
{
|
||||
if (selectedItemPos == SharedButtons.SelectedItemPos.None)
|
||||
{
|
||||
sharedButtons.DisableButtons(SharedButtons.Buttons.Remove | SharedButtons.Buttons.Up | SharedButtons.Buttons.Down);
|
||||
}
|
||||
else if (selectedItemPos == SharedButtons.SelectedItemPos.First)
|
||||
{
|
||||
sharedButtons.EnableButtons(SharedButtons.Buttons.Remove | SharedButtons.Buttons.Down);
|
||||
sharedButtons.DisableButtons(SharedButtons.Buttons.Up);
|
||||
}
|
||||
else if (selectedItemPos == SharedButtons.SelectedItemPos.Last)
|
||||
{
|
||||
sharedButtons.EnableButtons(SharedButtons.Buttons.Remove | SharedButtons.Buttons.Up);
|
||||
sharedButtons.DisableButtons(SharedButtons.Buttons.Down);
|
||||
}
|
||||
else if (selectedItemPos == SharedButtons.SelectedItemPos.FirstAndLast)
|
||||
{
|
||||
sharedButtons.EnableButtons(SharedButtons.Buttons.Remove);
|
||||
sharedButtons.DisableButtons(SharedButtons.Buttons.Up | SharedButtons.Buttons.Down);
|
||||
}
|
||||
else
|
||||
{
|
||||
sharedButtons.EnableButtons(SharedButtons.Buttons.Remove | SharedButtons.Buttons.Up | SharedButtons.Buttons.Down);
|
||||
}
|
||||
}
|
||||
public void UpdateButtonStates(SharedButtons.SelectedItemPos selectedItemPos)
|
||||
{
|
||||
if (selectedItemPos == SharedButtons.SelectedItemPos.None)
|
||||
{
|
||||
sharedButtons.DisableButtons(SharedButtons.Buttons.Remove | SharedButtons.Buttons.Up |
|
||||
SharedButtons.Buttons.Down);
|
||||
}
|
||||
else if (selectedItemPos == SharedButtons.SelectedItemPos.First)
|
||||
{
|
||||
sharedButtons.EnableButtons(SharedButtons.Buttons.Remove | SharedButtons.Buttons.Down);
|
||||
sharedButtons.DisableButtons(SharedButtons.Buttons.Up);
|
||||
}
|
||||
else if (selectedItemPos == SharedButtons.SelectedItemPos.Last)
|
||||
{
|
||||
sharedButtons.EnableButtons(SharedButtons.Buttons.Remove | SharedButtons.Buttons.Up);
|
||||
sharedButtons.DisableButtons(SharedButtons.Buttons.Down);
|
||||
}
|
||||
else if (selectedItemPos == SharedButtons.SelectedItemPos.FirstAndLast)
|
||||
{
|
||||
sharedButtons.EnableButtons(SharedButtons.Buttons.Remove);
|
||||
sharedButtons.DisableButtons(SharedButtons.Buttons.Up | SharedButtons.Buttons.Down);
|
||||
}
|
||||
else
|
||||
{
|
||||
sharedButtons.EnableButtons(SharedButtons.Buttons.Remove | SharedButtons.Buttons.Up |
|
||||
SharedButtons.Buttons.Down);
|
||||
}
|
||||
}
|
||||
|
||||
private void ComponentsManagerDlg_FormClosing(object sender, FormClosingEventArgs e)
|
||||
{
|
||||
@@ -691,9 +777,9 @@ namespace TBF.UI.Bench.Components
|
||||
if ((flags & CfgUpdateFlags.AnyChange) != 0 || (flags & CfgUpdateFlags.RestartRqrd) != 0)
|
||||
{
|
||||
DialogResult dr = MessageBox.Show(Strings.Do_you_want_to_save_changes,
|
||||
Strings.Warning,
|
||||
MessageBoxButtons.YesNo,
|
||||
MessageBoxIcon.Question);
|
||||
Strings.Warning,
|
||||
MessageBoxButtons.YesNo,
|
||||
MessageBoxIcon.Question);
|
||||
if (dr == DialogResult.Yes)
|
||||
{
|
||||
SaveDBChanges(session);
|
||||
@@ -702,7 +788,7 @@ namespace TBF.UI.Bench.Components
|
||||
|
||||
if (CurrentUser.Restore(this)) Program.MainWnd.UpdateUser();
|
||||
}
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Updates component configuration from a script file
|
||||
@@ -713,7 +799,7 @@ namespace TBF.UI.Bench.Components
|
||||
/// <returns>true = udated component configuration should be saved, new component should be created</returns>
|
||||
bool UpdateCfg(ref IComponentCfg cfg, string[] words, ref int zeroBasedIdx)
|
||||
{
|
||||
string name = words[words.Length - 1]; /// The last word is the component name
|
||||
string name = words[words.Length - 1]; /// The last word is the component name
|
||||
cfg.Name = name.Replace("#", (zeroBasedIdx + 1).ToString());
|
||||
|
||||
if (cfg is Rig.BuiltIn.Valve.ValveCfg)
|
||||
@@ -760,9 +846,9 @@ namespace TBF.UI.Bench.Components
|
||||
}
|
||||
else if (cfg is Rig.Modbus.Meret.AdjustableScale.AdjustableMeterCfg)
|
||||
{
|
||||
(cfg as IChildComponentCfg).ParentName = "CB";
|
||||
(cfg as Rig.Modbus.Meret.AdjustableScale.AdjustableMeterCfg).ModbusAddress = (byte)(zeroBasedIdx + 1);
|
||||
return true;
|
||||
(cfg as IChildComponentCfg).ParentName = "CB";
|
||||
(cfg as Rig.Modbus.Meret.AdjustableScale.AdjustableMeterCfg).ModbusAddress = (byte)(zeroBasedIdx + 1);
|
||||
return true;
|
||||
}
|
||||
else if (cfg is Rig.RegisterReaders.PulsesFromUniCB.RRCfg)
|
||||
{
|
||||
@@ -818,4 +904,4 @@ namespace TBF.UI.Bench.Components
|
||||
listViewEx.Sort();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user