2015-04-15 18:32:56 +00:00
|
|
|
|
///
|
|
|
|
|
|
/// Copyright (c) 2013-2015 Sensus Metering Systems
|
|
|
|
|
|
///
|
|
|
|
|
|
using System.Collections.Generic;
|
2014-07-28 07:54:35 +00:00
|
|
|
|
using System.Globalization;
|
|
|
|
|
|
using System.Windows.Forms;
|
|
|
|
|
|
using log4net;
|
|
|
|
|
|
using TBF.BenchControl;
|
|
|
|
|
|
using TBF.BenchControl.GenericDevices;
|
|
|
|
|
|
using TBF.Resources;
|
|
|
|
|
|
|
|
|
|
|
|
namespace TBF.UiControls
|
|
|
|
|
|
{
|
2015-12-04 16:17:20 +00:00
|
|
|
|
public class PathsBenchCtrl : BaseWithListViewEx<Config.Entities.BenchPath>, ITabWithListViewEx
|
2014-07-28 07:54:35 +00:00
|
|
|
|
{
|
|
|
|
|
|
static readonly ILog log = LogManager.GetLogger(typeof(PathsBenchCtrl));
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Fixed ListViewEx columns
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
enum Column
|
|
|
|
|
|
{
|
|
|
|
|
|
Name,
|
|
|
|
|
|
Qfrom,
|
|
|
|
|
|
Qto,
|
|
|
|
|
|
Tin,
|
|
|
|
|
|
Tout,
|
|
|
|
|
|
Pin,
|
|
|
|
|
|
Pout,
|
2016-03-18 02:36:33 +00:00
|
|
|
|
StopBFValve,
|
2014-07-28 07:54:35 +00:00
|
|
|
|
FixedColumnsCount,
|
|
|
|
|
|
}
|
|
|
|
|
|
readonly int fixedColumnsCount = (int)Column.FixedColumnsCount;
|
|
|
|
|
|
|
|
|
|
|
|
PathsDlg parent;
|
|
|
|
|
|
Control parentControl;
|
|
|
|
|
|
Control[] editors;
|
|
|
|
|
|
|
|
|
|
|
|
public PathsBenchCtrl()
|
|
|
|
|
|
: base()
|
|
|
|
|
|
{
|
|
|
|
|
|
FixedRowsCount = 1;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void Initialize(PathsDlg parent, Control parentControl)
|
|
|
|
|
|
{
|
|
|
|
|
|
this.parent = parent;
|
|
|
|
|
|
this.parentControl = parentControl;
|
|
|
|
|
|
|
|
|
|
|
|
/// Load the paths
|
|
|
|
|
|
MyItems = parent.Session
|
|
|
|
|
|
.CreateQuery("FROM BenchPath ORDER BY ItemNr")
|
2015-12-04 16:17:20 +00:00
|
|
|
|
.List<Config.Entities.BenchPath>();
|
2014-07-28 07:54:35 +00:00
|
|
|
|
|
|
|
|
|
|
SubItemClicked += new SubItemEventHandler(listViewEx_SubItemClicked);
|
|
|
|
|
|
SubItemEndEditing += new SubItemEndEditingEventHandler(listViewEx_SubItemEndEditing);
|
|
|
|
|
|
|
|
|
|
|
|
/// ListViewEx columns
|
2014-09-03 11:42:46 +00:00
|
|
|
|
TBF.LocalSettings ls = Program.LocalSettings;
|
2016-03-18 02:36:33 +00:00
|
|
|
|
Columns.Add(Strings.Name, (ls.BenchColumnCount > 0) ? ls.BenchColumnWidths[0] : 60 * parent.Dpi / PathsDlg.Dpi100pct);
|
|
|
|
|
|
Columns.Add(Strings.Q_from_m3h, (ls.BenchColumnCount > 1) ? ls.BenchColumnWidths[1] : 50 * parent.Dpi / PathsDlg.Dpi100pct);
|
|
|
|
|
|
Columns.Add(Strings.Q_to_m3h, (ls.BenchColumnCount > 2) ? ls.BenchColumnWidths[2] : 50 * parent.Dpi / PathsDlg.Dpi100pct);
|
|
|
|
|
|
Columns.Add(Strings.T_in, (ls.BenchColumnCount > 3) ? ls.BenchColumnWidths[3] : 50 * parent.Dpi / PathsDlg.Dpi100pct);
|
|
|
|
|
|
Columns.Add(Strings.T_out, (ls.BenchColumnCount > 4) ? ls.BenchColumnWidths[4] : 50 * parent.Dpi / PathsDlg.Dpi100pct);
|
|
|
|
|
|
Columns.Add(Strings.P_in, (ls.BenchColumnCount > 5) ? ls.BenchColumnWidths[5] : 50 * parent.Dpi / PathsDlg.Dpi100pct);
|
|
|
|
|
|
Columns.Add(Strings.P_out, (ls.BenchColumnCount > 6) ? ls.BenchColumnWidths[6] : 50 * parent.Dpi / PathsDlg.Dpi100pct);
|
|
|
|
|
|
Columns.Add(Strings.StopBFValve_chdr, (ls.BenchColumnCount > 7) ? ls.BenchColumnWidths[7] : 70 * parent.Dpi / PathsDlg.Dpi100pct);
|
|
|
|
|
|
int clmn = (int)Column.FixedColumnsCount;
|
2014-09-02 16:10:16 +00:00
|
|
|
|
foreach (var vlv in parent.Valves)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (vlv.Category == ValveCategory.All || vlv.Category == ValveCategory.Bench)
|
|
|
|
|
|
{
|
2014-09-03 11:42:46 +00:00
|
|
|
|
Columns.Add(vlv.Cfg.Name, (ls.BenchColumnCount > clmn) ? ls.BenchColumnWidths[clmn] : 50 * parent.Dpi / PathsDlg.Dpi100pct);
|
|
|
|
|
|
clmn++;
|
2014-09-02 16:10:16 +00:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2014-07-28 07:54:35 +00:00
|
|
|
|
|
|
|
|
|
|
/// Temperatures, pressures
|
|
|
|
|
|
ComboBox tInCBox = new ComboBox();
|
|
|
|
|
|
ComboBox tOutCBox = new ComboBox();
|
|
|
|
|
|
ComboBox prInCBox = new ComboBox();
|
|
|
|
|
|
ComboBox prOutCBox = new ComboBox();
|
2016-03-18 02:36:33 +00:00
|
|
|
|
ComboBox stopBFValveComboBox = new ComboBox();
|
|
|
|
|
|
stopBFValveComboBox.Items.Add("---");
|
2014-07-28 07:54:35 +00:00
|
|
|
|
foreach (var cmpnt in parent.TbfComponents)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (cmpnt is BenchControl.GenericDevices.ITempMeter)
|
|
|
|
|
|
{
|
|
|
|
|
|
tInCBox.Items.Add(cmpnt.Cfg.Name);
|
|
|
|
|
|
tOutCBox.Items.Add(cmpnt.Cfg.Name);
|
|
|
|
|
|
}
|
|
|
|
|
|
if (cmpnt is BenchControl.GenericDevices.IPressureMeter)
|
|
|
|
|
|
{
|
|
|
|
|
|
prInCBox.Items.Add(cmpnt.Cfg.Name);
|
|
|
|
|
|
prOutCBox.Items.Add(cmpnt.Cfg.Name);
|
|
|
|
|
|
}
|
2016-03-18 02:36:33 +00:00
|
|
|
|
if (cmpnt is IValve && (cmpnt as IValve).CoupledTo == null)
|
|
|
|
|
|
{
|
|
|
|
|
|
stopBFValveComboBox.Items.Add(cmpnt.Cfg.Name);
|
|
|
|
|
|
}
|
2014-07-28 07:54:35 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
editors = new Control[fixedColumnsCount + 64];
|
|
|
|
|
|
///
|
|
|
|
|
|
editors[(int)Column.Name] = new TextBox(); /// Name
|
|
|
|
|
|
editors[(int)Column.Qfrom] = new TextBox(); /// Q_from
|
|
|
|
|
|
editors[(int)Column.Qto] = new TextBox(); /// Q_to
|
|
|
|
|
|
editors[(int)Column.Tin] = tInCBox;
|
|
|
|
|
|
editors[(int)Column.Tout] = tOutCBox;
|
|
|
|
|
|
editors[(int)Column.Pin] = prInCBox;
|
|
|
|
|
|
editors[(int)Column.Pout] = prOutCBox;
|
2016-03-18 02:36:33 +00:00
|
|
|
|
editors[(int)Column.StopBFValve] = stopBFValveComboBox;
|
2014-07-28 07:54:35 +00:00
|
|
|
|
/// Prepare valve combo-boxes (max. 64 valves)
|
|
|
|
|
|
for (int i = 0; i < 64; i++)
|
|
|
|
|
|
{
|
|
|
|
|
|
ComboBox cb = new ComboBox();
|
|
|
|
|
|
cb.Items.Add("---");
|
|
|
|
|
|
cb.Items.Add(Strings.open);
|
|
|
|
|
|
cb.Items.Add(Strings.close);
|
|
|
|
|
|
editors[fixedColumnsCount + i] = cb;
|
|
|
|
|
|
}
|
|
|
|
|
|
///
|
2016-05-26 12:02:12 +00:00
|
|
|
|
for (int i = 0; i < editors.Length; i++)
|
|
|
|
|
|
{
|
|
|
|
|
|
editors[i].Visible = false;
|
|
|
|
|
|
parent.Controls.Add(editors[i]);
|
|
|
|
|
|
}
|
2014-07-28 07:54:35 +00:00
|
|
|
|
|
|
|
|
|
|
base.RedrawAll();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void listViewEx_SubItemClicked(object sender, SubItemEventArgs e)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (!Unlocked || e.SubItem >= editors.Length) return;
|
2015-12-04 16:17:20 +00:00
|
|
|
|
if ((e.Item.Tag is Config.Entities.IHasItemNr) &&
|
|
|
|
|
|
((e.Item.Tag as Config.Entities.IHasItemNr).ItemNr < FixedRowsCount) &&
|
2014-07-28 07:54:35 +00:00
|
|
|
|
(e.SubItem < fixedColumnsCount))
|
|
|
|
|
|
{
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
StartEditing(editors[e.SubItem], e.Item, e.SubItem);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void listViewEx_SubItemEndEditing(object sender, SubItemEndEditingEventArgs e)
|
|
|
|
|
|
{
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public override void DrawOne(object myItem)
|
|
|
|
|
|
{
|
2015-12-04 16:17:20 +00:00
|
|
|
|
Config.Entities.BenchPath entity =(Config.Entities.BenchPath)myItem;
|
2014-07-28 07:54:35 +00:00
|
|
|
|
BenchControl.BenchPath path = new BenchControl.BenchPath(entity, parent.TbfComponents);
|
|
|
|
|
|
|
|
|
|
|
|
ListViewItem lvi = new ListViewItem(entity.Name);
|
|
|
|
|
|
lvi.SubItems.Add(path.Qfrom.ToString());
|
|
|
|
|
|
lvi.SubItems.Add(path.Qto.ToString());
|
|
|
|
|
|
lvi.SubItems.Add(path.TempIn != null ? path.TempIn.Cfg.Name : "---");
|
|
|
|
|
|
lvi.SubItems.Add(path.TempOut != null ? path.TempOut.Cfg.Name : "---");
|
|
|
|
|
|
lvi.SubItems.Add(path.PressIn != null ? path.PressIn.Cfg.Name : "---");
|
|
|
|
|
|
lvi.SubItems.Add(path.PressOut != null ? path.PressOut.Cfg.Name : "---");
|
2016-03-18 02:36:33 +00:00
|
|
|
|
lvi.SubItems.Add((path.StopBFValve != null) ? path.StopBFValve.Cfg.Name : "---");
|
2014-07-28 07:54:35 +00:00
|
|
|
|
|
|
|
|
|
|
foreach (var valve in parent.Valves)
|
|
|
|
|
|
{
|
2014-09-02 16:10:16 +00:00
|
|
|
|
if (valve.Category == ValveCategory.All || valve.Category == ValveCategory.Bench)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (path.ValvesOpen != null && path.ValvesOpen.Contains(valve))
|
|
|
|
|
|
{
|
|
|
|
|
|
lvi.SubItems.Add(Strings.open);
|
|
|
|
|
|
}
|
|
|
|
|
|
else if (path.ValvesClose != null && path.ValvesClose.Contains(valve))
|
|
|
|
|
|
{
|
|
|
|
|
|
lvi.SubItems.Add(Strings.close);
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
lvi.SubItems.Add("---");
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2014-07-28 07:54:35 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
lvi.Tag = entity;
|
|
|
|
|
|
|
|
|
|
|
|
Items.Add(lvi);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public override void UpdateOne(ListViewItem lvi, object myItem)
|
|
|
|
|
|
{
|
2015-12-04 16:17:20 +00:00
|
|
|
|
Config.Entities.BenchPath entity = (Config.Entities.BenchPath)myItem;
|
2014-07-28 07:54:35 +00:00
|
|
|
|
|
|
|
|
|
|
entity.Name = lvi.Text;
|
|
|
|
|
|
|
|
|
|
|
|
float Qfrom;
|
|
|
|
|
|
bool allOk = Utils.TryParseUFloat(lvi.SubItems[(int)Column.Qfrom].Text, out Qfrom);
|
|
|
|
|
|
entity.Qfrom = Qfrom;
|
|
|
|
|
|
|
|
|
|
|
|
float Qto;
|
|
|
|
|
|
allOk &= Utils.TryParseUFloat(lvi.SubItems[(int)Column.Qto].Text, out Qto);
|
|
|
|
|
|
entity.Qto = Qto;
|
|
|
|
|
|
|
|
|
|
|
|
entity.TempIn = lvi.SubItems[(int)Column.Tin].Text;
|
|
|
|
|
|
entity.TempOut = lvi.SubItems[(int)Column.Tout].Text;
|
|
|
|
|
|
entity.PressIn = lvi.SubItems[(int)Column.Pin].Text;
|
|
|
|
|
|
entity.PressOut = lvi.SubItems[(int)Column.Pout].Text;
|
2016-03-18 02:36:33 +00:00
|
|
|
|
entity.StopBFValve = lvi.SubItems[(int)Column.StopBFValve].Text.Equals("---") ? null : lvi.SubItems[(int)Column.StopBFValve].Text;
|
2014-07-28 07:54:35 +00:00
|
|
|
|
|
|
|
|
|
|
string valvesOpen = string.Empty;
|
|
|
|
|
|
string valvesClose = string.Empty;
|
2014-09-02 16:10:16 +00:00
|
|
|
|
int k = 0;
|
2014-07-28 07:54:35 +00:00
|
|
|
|
for (int j = 0; j < parent.Valves.Count; j++)
|
|
|
|
|
|
{
|
2014-09-02 16:10:16 +00:00
|
|
|
|
if (parent.Valves[j].Category == ValveCategory.All || parent.Valves[j].Category == ValveCategory.Bench)
|
|
|
|
|
|
{
|
|
|
|
|
|
string text = lvi.SubItems[fixedColumnsCount + k].Text;
|
|
|
|
|
|
if (text.Equals(Strings.open))
|
|
|
|
|
|
{
|
|
|
|
|
|
if (valvesOpen != string.Empty) valvesOpen += ";";
|
|
|
|
|
|
valvesOpen += parent.Valves[j].Cfg.Name;
|
|
|
|
|
|
}
|
|
|
|
|
|
if (text.Equals(Strings.close))
|
|
|
|
|
|
{
|
|
|
|
|
|
if (valvesClose != string.Empty) valvesClose += ";";
|
|
|
|
|
|
valvesClose += parent.Valves[j].Cfg.Name;
|
|
|
|
|
|
}
|
|
|
|
|
|
k++;
|
|
|
|
|
|
}
|
2014-07-28 07:54:35 +00:00
|
|
|
|
}
|
|
|
|
|
|
entity.ValvesOpen = valvesOpen;
|
|
|
|
|
|
entity.ValvesClose = valvesClose;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Update the entities and save them to the database
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public new void OkBtnClicked()
|
|
|
|
|
|
{
|
|
|
|
|
|
base.OkBtnClicked();
|
|
|
|
|
|
|
2014-09-03 11:42:46 +00:00
|
|
|
|
/// Update the database
|
2014-07-28 07:54:35 +00:00
|
|
|
|
foreach (var entity in ToBeRemovedItems)
|
|
|
|
|
|
{
|
2015-12-04 16:17:20 +00:00
|
|
|
|
Config.FluentCommon.DeleteFromDb(parent.Session, entity);
|
2014-07-28 07:54:35 +00:00
|
|
|
|
}
|
|
|
|
|
|
foreach (var entity in MyItems)
|
|
|
|
|
|
{
|
2015-12-04 16:17:20 +00:00
|
|
|
|
Config.FluentCommon.SaveToDb(parent.Session, entity);
|
2014-07-28 07:54:35 +00:00
|
|
|
|
}
|
2014-09-03 11:42:46 +00:00
|
|
|
|
|
|
|
|
|
|
/// Update the column widths
|
|
|
|
|
|
Program.LocalSettings.BenchColumnWidths = new int[Columns.Count];
|
|
|
|
|
|
for (int i = 0; i < Columns.Count; i++)
|
|
|
|
|
|
{
|
|
|
|
|
|
Program.LocalSettings.BenchColumnWidths[i] = Columns[i].Width;
|
|
|
|
|
|
}
|
|
|
|
|
|
Program.LocalSettings.Save();
|
2014-07-28 07:54:35 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void AddOne()
|
|
|
|
|
|
{
|
2015-12-04 16:17:20 +00:00
|
|
|
|
Config.Entities.BenchPath entity;
|
2014-07-28 07:54:35 +00:00
|
|
|
|
|
|
|
|
|
|
if (MyItems.Count < FixedRowsCount)
|
|
|
|
|
|
{
|
2015-12-04 16:17:20 +00:00
|
|
|
|
entity = new Config.Entities.BenchPath(Strings._none_, MyItems.Count);
|
2014-07-28 07:54:35 +00:00
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
/// Find an unused test name
|
|
|
|
|
|
string newName;
|
|
|
|
|
|
for (int nameId = 1; true; nameId++)
|
|
|
|
|
|
{
|
|
|
|
|
|
newName = Strings.New_bench_path_name + nameId.ToString();
|
|
|
|
|
|
bool notUsed = true;
|
|
|
|
|
|
foreach (var t in MyItems) if (t.Name.Equals(newName)) notUsed = false;
|
|
|
|
|
|
if (notUsed) break;
|
|
|
|
|
|
}
|
2015-12-04 16:17:20 +00:00
|
|
|
|
entity = new Config.Entities.BenchPath(newName, MyItems.Count);
|
2014-07-28 07:54:35 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
base.AddOne(entity);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public new void RemoveSelected()
|
|
|
|
|
|
{
|
|
|
|
|
|
bool lastOneRemoved = base.RemoveSelected();
|
|
|
|
|
|
if (lastOneRemoved && parent != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
parent.UpdateButtonStates(SharedButtons.SelectedItemPos.None);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|