2016-12-07 16:19:01 +00:00
|
|
|
|
///
|
|
|
|
|
|
/// Copyright (c) 2016 Sensus Metering Systems
|
|
|
|
|
|
///
|
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
using System.Drawing;
|
|
|
|
|
|
using System.Windows.Forms;
|
|
|
|
|
|
using log4net;
|
|
|
|
|
|
using TBF.BenchControl.GenericDevices;
|
|
|
|
|
|
using TBF.Resources;
|
|
|
|
|
|
|
|
|
|
|
|
namespace TBF.BenchControl.TestMethods.Endurance
|
|
|
|
|
|
{
|
|
|
|
|
|
public partial class CycleStepsCtrl : TBF.UiControls.BaseWithListViewEx<CycleStep>, TBF.UiControls.ITabWithListViewEx
|
|
|
|
|
|
{
|
|
|
|
|
|
static readonly ILog log = LogManager.GetLogger(typeof(CycleStepsCtrl));
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Fixed ListViewEx columns
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
enum Column
|
|
|
|
|
|
{
|
|
|
|
|
|
Duration,
|
2016-12-08 08:27:47 +00:00
|
|
|
|
//Message,
|
2016-12-07 16:19:01 +00:00
|
|
|
|
FixedColumnsCount,
|
|
|
|
|
|
}
|
|
|
|
|
|
readonly int fixedCount = (int)Column.FixedColumnsCount;
|
|
|
|
|
|
|
|
|
|
|
|
IList<CycleStep> sequence;
|
|
|
|
|
|
|
|
|
|
|
|
CycleDlg parent;
|
|
|
|
|
|
Control parentControl;
|
|
|
|
|
|
Control[] editors;
|
|
|
|
|
|
|
|
|
|
|
|
int vCount; /// Number of valves
|
|
|
|
|
|
|
|
|
|
|
|
public CycleStepsCtrl()
|
|
|
|
|
|
: base()
|
|
|
|
|
|
{
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void Initialize(IList<CycleStep> sequence, CycleDlg parent, Control parentControl)
|
|
|
|
|
|
{
|
|
|
|
|
|
this.sequence = sequence;
|
|
|
|
|
|
this.parent = parent;
|
|
|
|
|
|
this.parentControl = parentControl;
|
|
|
|
|
|
Name = "Dummy";
|
|
|
|
|
|
MyItems = sequence;
|
|
|
|
|
|
|
|
|
|
|
|
SubItemClicked += new Results.Forms.SubItemEventHandler(listViewEx_SubItemClicked);
|
|
|
|
|
|
SubItemRightClicked += new Results.Forms.SubItemEventHandler(listViewEx_SubItemRightClicked);
|
|
|
|
|
|
SubItemEndEditing += new Results.Forms.SubItemEndEditingEventHandler(listViewEx_SubItemEndEditing);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
///
|
|
|
|
|
|
/// ListViewEx columns
|
|
|
|
|
|
///
|
2016-12-08 08:27:47 +00:00
|
|
|
|
Columns.Add(Strings.Duration_ms, 100 * parent.Dpi / PathsDlg.Dpi100pct);
|
|
|
|
|
|
//Columns.Add(Strings.Message, 100 * parent.Dpi / PathsDlg.Dpi100pct);
|
2016-12-07 16:19:01 +00:00
|
|
|
|
///
|
|
|
|
|
|
vCount = 0;
|
|
|
|
|
|
foreach (var vlv in parent.Valves)
|
|
|
|
|
|
{
|
|
|
|
|
|
Columns.Add(vlv.Cfg.Name, 50 * parent.Dpi / PathsDlg.Dpi100pct);
|
|
|
|
|
|
vCount++;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
///
|
|
|
|
|
|
/// Prepare valve combo-boxes
|
|
|
|
|
|
///
|
|
|
|
|
|
TextBox tb;
|
|
|
|
|
|
ComboBox cb;
|
|
|
|
|
|
editors = new Control[fixedCount + vCount];
|
|
|
|
|
|
|
|
|
|
|
|
/// Duration
|
|
|
|
|
|
editors[(int)Column.Duration] = tb = new TextBox();
|
|
|
|
|
|
tb.Visible = false;
|
|
|
|
|
|
parent.Controls.Add(tb);
|
|
|
|
|
|
|
|
|
|
|
|
/// Message
|
2016-12-08 08:27:47 +00:00
|
|
|
|
//editors[(int)Column.Message] = tb = new TextBox();
|
|
|
|
|
|
//tb.Visible = false;
|
|
|
|
|
|
//parent.Controls.Add(tb);
|
2016-12-07 16:19:01 +00:00
|
|
|
|
|
|
|
|
|
|
/// Valves
|
|
|
|
|
|
for (int i = fixedCount; i < fixedCount + vCount; i++)
|
|
|
|
|
|
{
|
|
|
|
|
|
editors[i] = cb = new ComboBox();
|
|
|
|
|
|
cb.Visible = false;
|
|
|
|
|
|
cb.Items.Add("---");
|
|
|
|
|
|
cb.Items.Add(Strings.open);
|
|
|
|
|
|
cb.Items.Add(Strings.close);
|
|
|
|
|
|
parent.Controls.Add(cb);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
base.RedrawAll();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2016-12-08 08:27:47 +00:00
|
|
|
|
|
2016-12-07 16:19:01 +00:00
|
|
|
|
void listViewEx_SubItemClicked(object sender, Results.Forms.SubItemEventArgs e)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (!Unlocked || e.SubItem >= editors.Length) return;
|
|
|
|
|
|
StartEditing(editors[e.SubItem], e.Item, e.SubItem);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2016-12-08 08:27:47 +00:00
|
|
|
|
|
2016-12-07 16:19:01 +00:00
|
|
|
|
void listViewEx_SubItemRightClicked(object sender, Results.Forms.SubItemEventArgs e)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (!Unlocked || e.SubItem >= editors.Length) 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))
|
|
|
|
|
|
{
|
|
|
|
|
|
int columnNr = e.SubItem;
|
|
|
|
|
|
string value = null;
|
|
|
|
|
|
System.Drawing.Color backColor = System.Drawing.Color.White;
|
|
|
|
|
|
foreach (ListViewItem item in Items)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (value != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
item.SubItems[columnNr].Text = value;
|
|
|
|
|
|
item.SubItems[columnNr].BackColor = backColor;
|
|
|
|
|
|
}
|
|
|
|
|
|
else if (item == e.Item)
|
|
|
|
|
|
{
|
|
|
|
|
|
value = item.SubItems[columnNr].Text;
|
|
|
|
|
|
backColor = item.SubItems[columnNr].BackColor;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2016-12-08 08:27:47 +00:00
|
|
|
|
|
2016-12-07 16:19:01 +00:00
|
|
|
|
void listViewEx_SubItemEndEditing(object sender, Results.Forms.SubItemEndEditingEventArgs e)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (e.SubItem == (int)Column.Duration)
|
|
|
|
|
|
{
|
2016-12-08 08:27:47 +00:00
|
|
|
|
uint duration;
|
2016-12-09 17:06:14 +00:00
|
|
|
|
if (!uint.TryParse(e.DisplayText, out duration) || (duration % 10) != 0 || duration == 0)
|
2016-12-07 16:19:01 +00:00
|
|
|
|
{
|
|
|
|
|
|
e.DisplayText = e.Item.Text;
|
|
|
|
|
|
e.Cancel = true;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2016-12-08 08:27:47 +00:00
|
|
|
|
//else if (e.SubItem == (int)Column.Message)
|
|
|
|
|
|
//{
|
|
|
|
|
|
// if (e.DisplayText.Length >= 255)
|
|
|
|
|
|
// {
|
|
|
|
|
|
// // Message too long
|
|
|
|
|
|
// e.DisplayText = e.Item.SubItems[e.SubItem].Text;
|
|
|
|
|
|
// e.Cancel = true;
|
|
|
|
|
|
// }
|
|
|
|
|
|
//}
|
2016-12-07 16:19:01 +00:00
|
|
|
|
else if ((e.SubItem >= fixedCount) && (e.SubItem < fixedCount + vCount))
|
|
|
|
|
|
{
|
|
|
|
|
|
if ((e.DisplayText != Strings.open) && (e.DisplayText != Strings.close) && (e.DisplayText != "---"))
|
|
|
|
|
|
{
|
|
|
|
|
|
e.DisplayText = e.Item.SubItems[e.SubItem].Text;
|
|
|
|
|
|
e.Cancel = true;
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
e.Item.SubItems[e.SubItem].BackColor = e.DisplayText == Strings.open ? Color.LightGray : Color.White;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2016-12-08 08:27:47 +00:00
|
|
|
|
|
2016-12-07 16:19:01 +00:00
|
|
|
|
public override void DrawOne(object myItem)
|
|
|
|
|
|
{
|
|
|
|
|
|
CycleStep step = (CycleStep)myItem;
|
|
|
|
|
|
|
|
|
|
|
|
ListViewItem lvi = new ListViewItem(step.Duration.ToString());
|
|
|
|
|
|
lvi.UseItemStyleForSubItems = false;
|
|
|
|
|
|
|
2016-12-08 08:27:47 +00:00
|
|
|
|
//lvi.SubItems.Add(string.IsNullOrEmpty(step.Message) ? string.Empty : step.Message);
|
2016-12-07 16:19:01 +00:00
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < parent.Valves.Count; i++)
|
|
|
|
|
|
{
|
|
|
|
|
|
if ((step.ValvesOpen & (1 << i)) != 0)
|
|
|
|
|
|
{
|
|
|
|
|
|
lvi.SubItems.Add(Strings.open);
|
|
|
|
|
|
lvi.SubItems[lvi.SubItems.Count - 1].BackColor = Color.LightGray;
|
|
|
|
|
|
}
|
|
|
|
|
|
else if ((step.ValvesClose & (1 << i)) != 0)
|
|
|
|
|
|
{
|
|
|
|
|
|
lvi.SubItems.Add(Strings.close);
|
|
|
|
|
|
lvi.SubItems[lvi.SubItems.Count - 1].BackColor = Color.White;
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
lvi.SubItems.Add("---");
|
|
|
|
|
|
lvi.SubItems[lvi.SubItems.Count - 1].BackColor = Color.White;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
lvi.Tag = step;
|
|
|
|
|
|
|
|
|
|
|
|
Items.Add(lvi);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2016-12-08 08:27:47 +00:00
|
|
|
|
|
2016-12-07 16:19:01 +00:00
|
|
|
|
public override void UpdateOne(ListViewItem lvi, object myItem)
|
|
|
|
|
|
{
|
|
|
|
|
|
CycleStep step = (CycleStep)myItem;
|
|
|
|
|
|
|
|
|
|
|
|
///
|
|
|
|
|
|
/// Duration
|
|
|
|
|
|
///
|
2016-12-08 08:27:47 +00:00
|
|
|
|
uint duration;
|
2016-12-09 17:06:14 +00:00
|
|
|
|
if (uint.TryParse(lvi.Text, out duration) && (duration % 10) == 0 && duration != 0)
|
2016-12-07 16:19:01 +00:00
|
|
|
|
step.Duration = duration;
|
|
|
|
|
|
else
|
|
|
|
|
|
lvi.Text = step.Duration.ToString();
|
|
|
|
|
|
|
|
|
|
|
|
///
|
|
|
|
|
|
/// Message
|
|
|
|
|
|
///
|
2016-12-08 08:27:47 +00:00
|
|
|
|
//if (lvi.SubItems[(int)Column.Message].Text.Length == 0)
|
|
|
|
|
|
// step.Message = string.Empty;
|
|
|
|
|
|
//else
|
|
|
|
|
|
// step.Message = lvi.SubItems[(int)Column.Message].Text;
|
2016-12-07 16:19:01 +00:00
|
|
|
|
|
|
|
|
|
|
///
|
|
|
|
|
|
/// Valves
|
|
|
|
|
|
///
|
|
|
|
|
|
int k = 0;
|
2016-12-08 08:27:47 +00:00
|
|
|
|
uint valvesOpen = 0;
|
|
|
|
|
|
uint valvesClose = 0;
|
2016-12-07 16:19:01 +00:00
|
|
|
|
///
|
|
|
|
|
|
for (int i = 0; i < parent.Valves.Count; i++)
|
|
|
|
|
|
{
|
|
|
|
|
|
IValve valve = parent.Valves[i];
|
|
|
|
|
|
string lviSubitText = lvi.SubItems[fixedCount + k++].Text;
|
|
|
|
|
|
if (lviSubitText.Equals(Strings.open))
|
|
|
|
|
|
{
|
2016-12-08 08:27:47 +00:00
|
|
|
|
valvesOpen += ((uint)1 << i);
|
2016-12-07 16:19:01 +00:00
|
|
|
|
}
|
|
|
|
|
|
if (lviSubitText.Equals(Strings.close))
|
|
|
|
|
|
{
|
2016-12-08 08:27:47 +00:00
|
|
|
|
valvesClose += ((uint)1 << i);
|
2016-12-07 16:19:01 +00:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
step.ValvesOpen = valvesOpen;
|
|
|
|
|
|
step.ValvesClose = valvesClose;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2016-12-08 08:27:47 +00:00
|
|
|
|
|
2016-12-07 16:19:01 +00:00
|
|
|
|
public void AddOne()
|
|
|
|
|
|
{
|
|
|
|
|
|
base.AddOne(new CycleStep());
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2016-12-08 08:27:47 +00:00
|
|
|
|
|
2016-12-07 16:19:01 +00:00
|
|
|
|
public new void RemoveSelected()
|
|
|
|
|
|
{
|
|
|
|
|
|
bool lastItemRemoved = base.RemoveSelected();
|
|
|
|
|
|
if (lastItemRemoved && parent != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
parent.UpdateButtonStates(TBF.UiControls.SharedButtons.SelectedItemPos.None);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2017-05-25 08:39:15 +00:00
|
|
|
|
|
|
|
|
|
|
public string GetWarningsBeforeSaving()
|
|
|
|
|
|
{
|
|
|
|
|
|
return string.Empty;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void UpdateRelatedItems()
|
|
|
|
|
|
{
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2016-12-07 16:19:01 +00:00
|
|
|
|
}
|