162 lines
4.4 KiB
C#
162 lines
4.4 KiB
C#
using System;
|
|
using System.Windows.Forms;
|
|
using log4net;
|
|
using TBF.BenchControl.Generic;
|
|
|
|
namespace TBF.BenchControl.Elde.RegulValveTandem
|
|
{
|
|
public partial class RegulValveTandemCfgCtrl : UserControl, IComponentCfgCtrl
|
|
{
|
|
static readonly ILog log = LogManager.GetLogger(typeof(RegulValveTandemCfgCtrl));
|
|
|
|
ComponentParametersDlg parent;
|
|
|
|
public bool ShowMore { get { return true; } }
|
|
|
|
RegulValveTandemCfg config;
|
|
public IComponentCfg Config
|
|
{
|
|
get { return config as IComponentCfg; }
|
|
set
|
|
{
|
|
config = value as RegulValveTandemCfg;
|
|
Redraw();
|
|
}
|
|
}
|
|
|
|
public RegulValveTandemCfgCtrl()
|
|
{
|
|
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.RegulValve.RegulValveFactory)
|
|
{
|
|
regulValveNameComboBox.Items.Add(cmpnt.Name);
|
|
fixedRVNameComboBox.Items.Add(cmpnt.Name);
|
|
}
|
|
}
|
|
}
|
|
|
|
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;
|
|
regulValveNameComboBox.Text = string.IsNullOrEmpty(config.RegulValveName) ? "---" : config.RegulValveName;
|
|
fixedRVNameComboBox.Text = string.IsNullOrEmpty(config.FixedRVName) ? "---" : config.FixedRVName;
|
|
stableTimeTextBox.Text = config.StableTimeMs.ToString();
|
|
storedPosReuseCheckBox.Checked = config.StoredPositionReuse;
|
|
flowStableSecTextBox.Text = config.FlowStableSec.ToString();
|
|
}
|
|
|
|
public void Unlock()
|
|
{
|
|
nameTextBox.Enabled = true;
|
|
regulValveNameComboBox.Enabled = true;
|
|
fixedRVNameComboBox.Enabled = true;
|
|
stableTimeTextBox.Enabled = true;
|
|
storedPosReuseCheckBox.Enabled = true;
|
|
flowStableSecTextBox.Enabled = true;
|
|
}
|
|
|
|
public CfgUpdateFlags VerifyCfg(ref string message)
|
|
{
|
|
CfgUpdateFlags flags = CfgUpdateFlags.None;
|
|
|
|
if (!regulValveNameComboBox.Items.Contains(regulValveNameComboBox.Text))
|
|
{
|
|
flags |= CfgUpdateFlags.Error;
|
|
message += Environment.NewLine + "Invalid 'Regulation valve'";
|
|
}
|
|
|
|
if (!fixedRVNameComboBox.Items.Contains(fixedRVNameComboBox.Text))
|
|
{
|
|
flags |= CfgUpdateFlags.Error;
|
|
message += Environment.NewLine + "Invalid 'Fixed reg. valve'";
|
|
}
|
|
|
|
int dummy;
|
|
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 str = regulValveNameComboBox.Text.Equals("---") ? string.Empty : regulValveNameComboBox.Text;
|
|
if (!config.RegulValveName.Equals(str))
|
|
{
|
|
config.RegulValveName = str;
|
|
flags |= CfgUpdateFlags.RestartRqrd;
|
|
}
|
|
|
|
str = fixedRVNameComboBox.Text.Equals("---") ? string.Empty : fixedRVNameComboBox.Text;
|
|
if (!config.FixedRVName.Equals(str))
|
|
{
|
|
config.FixedRVName = str;
|
|
flags |= CfgUpdateFlags.RestartRqrd;
|
|
}
|
|
|
|
int tmp = int.Parse(stableTimeTextBox.Text);
|
|
if (config.StableTimeMs != tmp)
|
|
{
|
|
config.StableTimeMs = tmp;
|
|
flags |= CfgUpdateFlags.RestartRqrd;
|
|
}
|
|
|
|
bool btmp = storedPosReuseCheckBox.Checked;
|
|
if (config.StoredPositionReuse != btmp)
|
|
{
|
|
config.StoredPositionReuse = btmp;
|
|
flags |= CfgUpdateFlags.RestartRqrd;
|
|
}
|
|
|
|
tmp = int.Parse(flowStableSecTextBox.Text);
|
|
if (config.FlowStableSec != tmp)
|
|
{
|
|
config.FlowStableSec = tmp;
|
|
flags |= CfgUpdateFlags.RestartRqrd;
|
|
}
|
|
|
|
return flags;
|
|
}
|
|
}
|
|
}
|