263 lines
8.5 KiB
C#
263 lines
8.5 KiB
C#
///
|
|
/// Copyright (c) 2013-2015 Sensus Metering Systems
|
|
///
|
|
using System.Collections.Generic;
|
|
using System.Drawing;
|
|
using System.Windows.Forms;
|
|
using log4net;
|
|
using Config.Entities;
|
|
using TBF.BenchControl;
|
|
using TBF.BenchControl.GenericDevices;
|
|
using TBF.Resources;
|
|
|
|
namespace TBF.UiControls
|
|
{
|
|
public partial class VirtualBenchStepsCtrl : BaseWithListViewEx<VirtualBenchStep>, ITabWithListViewEx
|
|
{
|
|
static readonly ILog log = LogManager.GetLogger(typeof(VirtualBenchStepsCtrl));
|
|
|
|
/// <summary>
|
|
/// Fixed ListViewEx columns
|
|
/// </summary>
|
|
enum Column
|
|
{
|
|
Duration,
|
|
FixedColumnsCount,
|
|
}
|
|
readonly int fixedCount = (int)Column.FixedColumnsCount;
|
|
|
|
VirtualBenchSequence sequence;
|
|
|
|
TransitionsDlg parent;
|
|
Control parentControl;
|
|
Control[] editors;
|
|
|
|
int fmPumpCount; /// Number of pumps with FM control
|
|
int regvCount; /// Number of regulating valves
|
|
int vCount; /// Number of valves
|
|
|
|
public VirtualBenchStepsCtrl()
|
|
: base()
|
|
{
|
|
}
|
|
|
|
public void Initialize(VirtualBenchSequence sequence, TransitionsDlg parent, Control parentControl)
|
|
{
|
|
this.sequence = sequence;
|
|
this.parent = parent;
|
|
this.parentControl = parentControl;
|
|
Name = sequence.Name;
|
|
MyItems = sequence.VirtualBenchSteps;
|
|
|
|
SubItemClicked += new Results.Forms.SubItemEventHandler(listViewEx_SubItemClicked);
|
|
SubItemRightClicked += new Results.Forms.SubItemEventHandler(listViewEx_SubItemRightClicked);
|
|
SubItemEndEditing += new Results.Forms.SubItemEndEditingEventHandler(listViewEx_SubItemEndEditing);
|
|
|
|
vCount = 0;
|
|
fmPumpCount = 0;
|
|
regvCount = 0;
|
|
|
|
///
|
|
/// ListViewEx columns
|
|
///
|
|
Columns.Add(Strings.Duration_s, 70 * parent.Dpi / PathsDlg.Dpi100pct);
|
|
//foreach (var vlv in parent.Valves)
|
|
//{
|
|
// if (vlv is BenchControl.GenericDevices.IPumpFM)
|
|
// {
|
|
// Columns.Add(vlv.Cfg.Name + " [%]", 45 * parent.Dpi / PathsDlg.Dpi100pct);
|
|
// fmPumpCount++;
|
|
// }
|
|
//}
|
|
//foreach (var rvlv in parent.RegulValves)
|
|
//{
|
|
// Columns.Add(rvlv.Cfg.Name + " [%]", 55 * parent.Dpi / PathsDlg.Dpi100pct);
|
|
//}
|
|
//foreach (var vlv in parent.Valves)
|
|
//{
|
|
// if (!(vlv is BenchControl.GenericDevices.IPumpFM))
|
|
// {
|
|
// Columns.Add(vlv.Cfg.Name, 40 * parent.Dpi / PathsDlg.Dpi100pct);
|
|
// vCount++;
|
|
// }
|
|
//}
|
|
|
|
///
|
|
/// Prepare valve combo-boxes
|
|
///
|
|
editors = new Control[fixedCount + vCount + fmPumpCount + regvCount];
|
|
|
|
editors[0] = new TextBox(); /// Duration
|
|
editors[0].Visible = false;
|
|
parent.Controls.Add(editors[0]);
|
|
|
|
//for (int i = fixedCount; i < fixedCount + fmPumpCount; i++)
|
|
//{
|
|
// ComboBox cb = new ComboBox();
|
|
// cb.Items.Add("---");
|
|
// cb.Items.Add(Strings.dflt);
|
|
// cb.Items.Add("0");
|
|
// cb.Items.Add("25");
|
|
// cb.Items.Add("50");
|
|
// cb.Items.Add("75");
|
|
// cb.Items.Add("100");
|
|
// editors[i] = cb;
|
|
// parent.Controls.Add(editors[i]);
|
|
//}
|
|
|
|
//for (int i = fixedCount + fmPumpCount; i < fixedCount + fmPumpCount + regvCount; i++)
|
|
//{
|
|
// ComboBox cb = new ComboBox();
|
|
// cb.Items.Add("---");
|
|
// cb.Items.Add("0");
|
|
// cb.Items.Add("25");
|
|
// cb.Items.Add("50");
|
|
// cb.Items.Add("75");
|
|
// cb.Items.Add("100");
|
|
// editors[i] = cb;
|
|
// parent.Controls.Add(editors[i]);
|
|
//}
|
|
|
|
//for (int i = fixedCount + fmPumpCount + regvCount; i < fixedCount + fmPumpCount + regvCount + vCount; i++)
|
|
//{
|
|
// ComboBox cb = new ComboBox();
|
|
// cb.Items.Add("---");
|
|
// cb.Items.Add(Strings.open);
|
|
// cb.Items.Add(Strings.close);
|
|
// editors[i] = cb;
|
|
// parent.Controls.Add(cb);
|
|
//}
|
|
|
|
base.RedrawAll();
|
|
}
|
|
|
|
void listViewEx_SubItemClicked(object sender, Results.Forms.SubItemEventArgs e)
|
|
{
|
|
if (!Unlocked || e.SubItem >= editors.Length) return;
|
|
StartEditing(editors[e.SubItem], e.Item, e.SubItem);
|
|
}
|
|
|
|
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.Count > columnNr)
|
|
{
|
|
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;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
void listViewEx_SubItemEndEditing(object sender, Results.Forms.SubItemEndEditingEventArgs e)
|
|
{
|
|
if (e.SubItem == (int)Column.Duration)
|
|
{
|
|
int duration;
|
|
if (!int.TryParse(e.DisplayText, out duration) || duration <= 0)
|
|
{
|
|
e.DisplayText = e.Item.Text;
|
|
e.Cancel = true;
|
|
}
|
|
}
|
|
//else if ((e.SubItem >= fixedCount) && (e.SubItem < fixedCount + fmPumpCount))
|
|
//{
|
|
// float pct;
|
|
// if (!e.DisplayText.Equals("---") &&
|
|
// !e.DisplayText.Equals(Strings.dflt) &&
|
|
// !(Utils.TryParseUFloat(e.DisplayText, out pct) && (pct >= 0) && (pct <= 100.0f)))
|
|
// {
|
|
// e.DisplayText = e.Item.SubItems[e.SubItem].Text;
|
|
// e.Cancel = true;
|
|
// }
|
|
//}
|
|
//else if ((e.SubItem >= fixedCount + fmPumpCount) && (e.SubItem < fixedCount + fmPumpCount + regvCount))
|
|
//{
|
|
// float pct;
|
|
// if (!e.DisplayText.Equals("---") &&
|
|
// !(Utils.TryParseUFloat(e.DisplayText, out pct) && (pct >= 0) && (pct <= 100.0f)))
|
|
// {
|
|
// e.DisplayText = e.Item.SubItems[e.SubItem].Text;
|
|
// e.Cancel = true;
|
|
// }
|
|
//}
|
|
//else if ((e.SubItem >= fixedCount + fmPumpCount + regvCount) && (e.SubItem < fixedCount + fmPumpCount + regvCount + vCount))
|
|
//{
|
|
// if ((e.DisplayText != Strings.open) && (e.DisplayText != Strings.close) && (e.DisplayText != "---"))
|
|
// {
|
|
// e.DisplayText = e.Item.SubItems[e.SubItem].Text;
|
|
// e.Cancel = true;
|
|
// }
|
|
//}
|
|
|
|
if (e.SubItem >= fixedCount)
|
|
{
|
|
e.Item.SubItems[e.SubItem].BackColor = e.DisplayText == Strings.open ? Color.LightGray : Color.White;
|
|
}
|
|
}
|
|
|
|
public override void DrawOne(object myItem)
|
|
{
|
|
VirtualBenchStep step = (VirtualBenchStep)myItem;
|
|
|
|
ListViewItem lvi = new ListViewItem(step.Duration.ToString());
|
|
|
|
/// TODO: All the rest
|
|
|
|
lvi.Tag = step;
|
|
|
|
Items.Add(lvi);
|
|
}
|
|
|
|
public override void UpdateOne(ListViewItem lvi, object myItem)
|
|
{
|
|
VirtualBenchStep step = (VirtualBenchStep)myItem;
|
|
|
|
/// Duration
|
|
int duration;
|
|
if (int.TryParse(lvi.Text, out duration) && duration > 0)
|
|
{
|
|
step.Duration = duration;
|
|
}
|
|
else
|
|
{
|
|
lvi.Text = step.Duration.ToString();
|
|
}
|
|
|
|
// TODO: Replace the following:
|
|
//step.PumpWithFMPcts = fmPumpsPcts;
|
|
//step.RegulValvesPct = regulValvesPct;
|
|
//step.ValvesOpen = valvesOpen;
|
|
//step.ValvesClose = valvesClose;
|
|
}
|
|
|
|
public void AddOne()
|
|
{
|
|
base.AddOne(new VirtualBenchStep(MyItems.Count, sequence));
|
|
}
|
|
|
|
public new void RemoveSelected()
|
|
{
|
|
bool lastItemRemoved = base.RemoveSelected();
|
|
if (lastItemRemoved && parent != null)
|
|
{
|
|
parent.UpdateButtonStates(SharedButtons.SelectedItemPos.None);
|
|
}
|
|
}
|
|
}
|
|
}
|