209 lines
6.3 KiB
C#
209 lines
6.3 KiB
C#
///
|
|
/// Copyright (c) 2017 Sensus Metering Systems
|
|
///
|
|
using System;
|
|
using System.Windows.Forms;
|
|
using log4net;
|
|
using TBF.BenchControl.Generic;
|
|
|
|
namespace TBF.BenchControl.Elde.RegulValveCoax
|
|
{
|
|
public partial class RegulValveCfgCtrl : UserControl, IComponentCfgCtrl
|
|
{
|
|
static readonly ILog log = LogManager.GetLogger(typeof(RegulValveCfgCtrl));
|
|
|
|
ComponentParametersDlg parent;
|
|
|
|
public bool ShowMore { get { return true; } }
|
|
|
|
RegulValveCfg config;
|
|
public IComponentCfg Config
|
|
{
|
|
get { return config as IComponentCfg; }
|
|
set
|
|
{
|
|
config = value as RegulValveCfg;
|
|
Redraw();
|
|
}
|
|
}
|
|
|
|
public RegulValveCfgCtrl()
|
|
{
|
|
InitializeComponent();
|
|
}
|
|
|
|
private void RegulationValveCfgCtrl_Load(object sender, EventArgs e)
|
|
{
|
|
parent = ParentForm as ComponentParametersDlg;
|
|
if (parent == null) return;
|
|
|
|
if (parent.TbfComponents != null)
|
|
{
|
|
foreach (var cmpnt in parent.TbfComponents)
|
|
{
|
|
if (TbfComponents.CmpntFactoryFromClassName(cmpnt.ClassName) is Elde.ControlBoardFactory)
|
|
{
|
|
parentNameComboBox.Items.Add(cmpnt.Name);
|
|
}
|
|
}
|
|
}
|
|
|
|
categoryComboBox.Items.Add(ValveCategory.All.ToString());
|
|
categoryComboBox.Items.Add(ValveCategory.Feeding.ToString());
|
|
categoryComboBox.Items.Add(ValveCategory.Output.ToString());
|
|
|
|
Redraw();
|
|
}
|
|
|
|
public void Closing()
|
|
{
|
|
}
|
|
|
|
void Redraw()
|
|
{
|
|
if (config == null) return; /// Control was not loaded, settings were not changed
|
|
|
|
classNameLabel.Text = config.Factory.ClassName;
|
|
nameTextBox.Text = config.Name;
|
|
parentNameComboBox.Text = string.IsNullOrEmpty(config.ParentName) ? "---" : config.ParentName;
|
|
categoryComboBox.Text = config.Category.ToString();
|
|
positionTextBox.Text = config.Idx1.ToString();
|
|
stableTimeTextBox.Text = config.StableTimeMs.ToString();
|
|
flowStableSecTextBox.Text = config.FlowStableSec.ToString();
|
|
storedPosReuseCheckBox.Checked = config.StoredPositionReuse;
|
|
reTryCommandsCheckBox.Checked = config.ReTryCommands;
|
|
}
|
|
|
|
public void Unlock()
|
|
{
|
|
nameTextBox.Enabled = true;
|
|
parentNameComboBox.Enabled = true;
|
|
categoryComboBox.Enabled = true;
|
|
positionTextBox.Enabled = true;
|
|
stableTimeTextBox.Enabled = true;
|
|
flowStableSecTextBox.Enabled = true;
|
|
storedPosReuseCheckBox.Enabled = true;
|
|
reTryCommandsCheckBox.Enabled = true;
|
|
}
|
|
|
|
public CfgUpdateFlags VerifyCfg(ref string message)
|
|
{
|
|
CfgUpdateFlags flags = CfgUpdateFlags.None;
|
|
|
|
int dummy;
|
|
if (!parentNameComboBox.Items.Contains(parentNameComboBox.Text))
|
|
{
|
|
flags |= CfgUpdateFlags.Error;
|
|
message += Environment.NewLine + "Invalid 'Parent Name'";
|
|
}
|
|
|
|
if (!categoryComboBox.Text.Equals(ValveCategory.All.ToString()) &&
|
|
!categoryComboBox.Text.Equals(ValveCategory.Feeding.ToString()) &&
|
|
!categoryComboBox.Text.Equals(ValveCategory.Output.ToString()))
|
|
{
|
|
flags |= CfgUpdateFlags.Error;
|
|
message += Environment.NewLine + "Invalid 'Category'";
|
|
}
|
|
|
|
if (!int.TryParse(positionTextBox.Text, out dummy) || dummy < 1 || dummy > 8)
|
|
{
|
|
flags |= CfgUpdateFlags.Error;
|
|
message += Environment.NewLine + "'Position' should be between 1 and 8";
|
|
}
|
|
|
|
if (!int.TryParse(stableTimeTextBox.Text, out dummy) || dummy < 200 || dummy > 1500 || (dummy % 50) != 0)
|
|
{
|
|
flags |= CfgUpdateFlags.Error;
|
|
message += Environment.NewLine + "'Stable time' should be between 200 and 1500 ms in 50 ms steps";
|
|
}
|
|
|
|
if (!int.TryParse(flowStableSecTextBox.Text, out dummy) || dummy < 0 || dummy > 60)
|
|
{
|
|
flags |= CfgUpdateFlags.Error;
|
|
message += Environment.NewLine + "'Flow stable' should be between 0 and 60 sec";
|
|
}
|
|
|
|
return flags;
|
|
}
|
|
|
|
public CfgUpdateFlags UpdateCfg()
|
|
{
|
|
CfgUpdateFlags flags = CfgUpdateFlags.None;
|
|
|
|
if (config == null) return CfgUpdateFlags.Error; /// Control was not loaded, settings were not changed
|
|
///
|
|
if (!config.Name.Equals(nameTextBox.Text))
|
|
{
|
|
config.Name = nameTextBox.Text;
|
|
flags |= CfgUpdateFlags.RestartRqrd;
|
|
}
|
|
|
|
string parentname = parentNameComboBox.Text.Equals("---") ? string.Empty : parentNameComboBox.Text;
|
|
if (!config.ParentName.Equals(parentname))
|
|
{
|
|
config.ParentName = parentname;
|
|
flags |= CfgUpdateFlags.RestartRqrd;
|
|
}
|
|
|
|
ValveCategory newCategory;
|
|
if (categoryComboBox.Text.Equals(ValveCategory.All.ToString())) newCategory = ValveCategory.All;
|
|
else if (categoryComboBox.Text.Equals(ValveCategory.Feeding.ToString())) newCategory = ValveCategory.Feeding;
|
|
else if (categoryComboBox.Text.Equals(ValveCategory.Bench.ToString())) newCategory = ValveCategory.Bench;
|
|
else if (categoryComboBox.Text.Equals(ValveCategory.Output.ToString())) newCategory = ValveCategory.Output;
|
|
else newCategory = ValveCategory.None;
|
|
if (newCategory != config.Category)
|
|
{
|
|
config.Category = newCategory;
|
|
flags |= CfgUpdateFlags.RestartRqrd;
|
|
}
|
|
|
|
int tmp = int.Parse(positionTextBox.Text);
|
|
if (config.Idx1 != tmp)
|
|
{
|
|
config.Idx1 = tmp;
|
|
flags |= CfgUpdateFlags.RestartRqrd;
|
|
}
|
|
|
|
tmp = int.Parse(stableTimeTextBox.Text);
|
|
if (config.StableTimeMs != tmp)
|
|
{
|
|
config.StableTimeMs = tmp;
|
|
flags |= CfgUpdateFlags.RestartRqrd;
|
|
}
|
|
|
|
tmp = int.Parse(flowStableSecTextBox.Text);
|
|
if (config.FlowStableSec != tmp)
|
|
{
|
|
config.FlowStableSec = tmp;
|
|
flags |= CfgUpdateFlags.RestartRqrd;
|
|
}
|
|
|
|
bool btmp = storedPosReuseCheckBox.Checked;
|
|
if (config.StoredPositionReuse != btmp)
|
|
{
|
|
config.StoredPositionReuse = btmp;
|
|
flags |= CfgUpdateFlags.RestartRqrd;
|
|
}
|
|
|
|
btmp = reTryCommandsCheckBox.Checked;
|
|
if (config.ReTryCommands != btmp)
|
|
{
|
|
config.ReTryCommands = btmp;
|
|
flags |= CfgUpdateFlags.RestartRqrd;
|
|
}
|
|
|
|
return flags;
|
|
}
|
|
|
|
private void openButton_Click(object sender, EventArgs e)
|
|
{
|
|
/// TODO
|
|
}
|
|
|
|
private void closeButton_Click(object sender, EventArgs e)
|
|
{
|
|
/// TODO
|
|
}
|
|
}
|
|
}
|