185 lines
5.8 KiB
C#
185 lines
5.8 KiB
C#
///
|
|
/// Copyright (c) 2015 Sensus Metering Systems
|
|
///
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Windows.Forms;
|
|
using Config.Entities;
|
|
using TBF.BenchControl.Generic;
|
|
|
|
namespace TBF.BenchControl.Elde.ValveEx
|
|
{
|
|
public partial class ValveCfgCtrl : UserControl, IComponentCfgCtrl
|
|
{
|
|
ComponentParametersDlg parent;
|
|
|
|
public bool ShowMore { get { return false; } }
|
|
|
|
ValveCfg config;
|
|
public IComponentCfg Config
|
|
{
|
|
get { return config as IComponentCfg; }
|
|
set
|
|
{
|
|
config = value as ValveCfg;
|
|
Redraw();
|
|
}
|
|
}
|
|
|
|
public ValveCfgCtrl()
|
|
{
|
|
InitializeComponent();
|
|
}
|
|
|
|
private void ValveCfgCtrl_Load(object sender, EventArgs e)
|
|
{
|
|
parent = ParentForm as ComponentParametersDlg;
|
|
if (parent == null) return;
|
|
|
|
logicalOpComboBox.Items.Add("AND");
|
|
logicalOpComboBox.Items.Add("OR");
|
|
|
|
if (parent.TbfComponents != null)
|
|
{
|
|
AddValvePumpItemsToCombo(input1ComboBox, parent.TbfComponents);
|
|
AddValvePumpItemsToCombo(input2ComboBox, parent.TbfComponents);
|
|
AddValvePumpItemsToCombo(input3ComboBox, parent.TbfComponents);
|
|
AddValvePumpItemsToCombo(input4ComboBox, parent.TbfComponents);
|
|
AddValvePumpItemsToCombo(input5ComboBox, parent.TbfComponents);
|
|
}
|
|
|
|
Redraw();
|
|
}
|
|
|
|
void AddValvePumpItemsToCombo(ComboBox combo, IList<Config.Entities.Component> components)
|
|
{
|
|
foreach (var cmpntEntity in components)
|
|
{
|
|
IComponent comp = TbfComponents.CmpntFactoryFromClassName(cmpntEntity.ClassName).DummyComponent();
|
|
if (comp is GenericDevices.IValve )
|
|
{
|
|
combo.Items.Add(cmpntEntity.Name);
|
|
}
|
|
}
|
|
}
|
|
|
|
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;
|
|
bitPositionTextBox.Text = config.BitPosition.ToString();
|
|
invertedOutpCheckBox.Checked = config.InvertOutput;
|
|
logicalOpComboBox.Text = (config.LogicalOp == ValveExOperation.And) ? "AND" : ((config.LogicalOp == ValveExOperation.Or) ? "OR" : "---");
|
|
inputsCountTextBox.Text = config.InputValvesCount.ToString();
|
|
input1ComboBox.Text = config.Input1;
|
|
input2ComboBox.Text = config.Input2;
|
|
input3ComboBox.Text = config.Input3;
|
|
input4ComboBox.Text = config.Input4;
|
|
input5ComboBox.Text = config.Input5;
|
|
}
|
|
|
|
public void Unlock()
|
|
{
|
|
nameTextBox.Enabled = true;
|
|
bitPositionTextBox.Enabled = true;
|
|
invertedOutpCheckBox.Enabled = true;
|
|
logicalOpComboBox.Enabled = true;
|
|
inputsCountTextBox.Enabled = true;
|
|
input1ComboBox.Enabled = true;
|
|
input2ComboBox.Enabled = true;
|
|
input3ComboBox.Enabled = true;
|
|
input4ComboBox.Enabled = true;
|
|
input5ComboBox.Enabled = true;
|
|
}
|
|
|
|
public CfgUpdateFlags UpdateCfg()
|
|
{
|
|
CfgUpdateFlags flags = CfgUpdateFlags.RestartRqrd;
|
|
|
|
if (config == null) return CfgUpdateFlags.Error; /// Control was not loaded, settings were not changed
|
|
|
|
config.Name = nameTextBox.Text;
|
|
config.BitPosition = int.Parse(bitPositionTextBox.Text);
|
|
config.InvertOutput = invertedOutpCheckBox.Checked;
|
|
config.LogicalOp = (logicalOpComboBox.Text == "AND") ? ValveExOperation.And : ValveExOperation.Or;
|
|
config.InputValvesCount = int.Parse(inputsCountTextBox.Text);
|
|
config.Input1 = input1ComboBox.Text.Equals("---") ? string.Empty : input1ComboBox.Text;
|
|
config.Input2 = input2ComboBox.Text.Equals("---") ? string.Empty : input2ComboBox.Text;
|
|
if (config.InputValvesCount >= 3) config.Input3 = input3ComboBox.Text.Equals("---") ? string.Empty : input3ComboBox.Text;
|
|
if (config.InputValvesCount >= 4) config.Input4 = input4ComboBox.Text.Equals("---") ? string.Empty : input4ComboBox.Text;
|
|
if (config.InputValvesCount >= 5) config.Input5 = input5ComboBox.Text.Equals("---") ? string.Empty : input5ComboBox.Text;
|
|
|
|
return flags;
|
|
}
|
|
|
|
public CfgUpdateFlags VerifyCfg(ref string message)
|
|
{
|
|
CfgUpdateFlags flags = CfgUpdateFlags.None;
|
|
|
|
int dummy;
|
|
if (!int.TryParse(bitPositionTextBox.Text, out dummy) || dummy < 0 || dummy >= 128)
|
|
{
|
|
flags |= CfgUpdateFlags.Error;
|
|
message += Environment.NewLine + "'Bit Position' should be between 0 and 127";
|
|
}
|
|
if (!logicalOpComboBox.Items.Contains(logicalOpComboBox.Text))
|
|
{
|
|
flags |= CfgUpdateFlags.Error;
|
|
message += Environment.NewLine + "Invalid 'Category'";
|
|
}
|
|
int nrInputs;
|
|
if (!int.TryParse(inputsCountTextBox.Text, out nrInputs) || nrInputs < 2 || nrInputs > 5)
|
|
{
|
|
flags |= CfgUpdateFlags.Error;
|
|
message += Environment.NewLine + "'Inputs count' out of range (2..5)";
|
|
}
|
|
if (!input1ComboBox.Items.Contains(input1ComboBox.Text))
|
|
{
|
|
flags |= CfgUpdateFlags.Error;
|
|
message += Environment.NewLine + "Invalid 'Input 1'";
|
|
}
|
|
if (!input2ComboBox.Items.Contains(input2ComboBox.Text))
|
|
{
|
|
flags |= CfgUpdateFlags.Error;
|
|
message += Environment.NewLine + "Invalid 'Input 2'";
|
|
}
|
|
if (nrInputs >= 3 && !input3ComboBox.Items.Contains(input3ComboBox.Text))
|
|
{
|
|
flags |= CfgUpdateFlags.Error;
|
|
message += Environment.NewLine + "Invalid 'Input 3'";
|
|
}
|
|
if (nrInputs >= 4 && !input4ComboBox.Items.Contains(input4ComboBox.Text))
|
|
{
|
|
flags |= CfgUpdateFlags.Error;
|
|
message += Environment.NewLine + "Invalid 'Input 4'";
|
|
}
|
|
if (nrInputs >= 5 && !input5ComboBox.Items.Contains(input5ComboBox.Text))
|
|
{
|
|
flags |= CfgUpdateFlags.Error;
|
|
message += Environment.NewLine + "Invalid 'Input 5'";
|
|
}
|
|
return flags;
|
|
}
|
|
|
|
private void inputsCountTextBox_TextChanged(object sender, EventArgs e)
|
|
{
|
|
int count;
|
|
if (int.TryParse(inputsCountTextBox.Text, out count) && count >= 2 || count <= 5)
|
|
{
|
|
input3Label.Visible = (count >= 3);
|
|
input4Label.Visible = (count >= 4);
|
|
input5Label.Visible = (count >= 5);
|
|
input3ComboBox.Visible = (count >= 3);
|
|
input4ComboBox.Visible = (count >= 4);
|
|
input5ComboBox.Visible = (count >= 5);
|
|
}
|
|
}
|
|
}
|
|
}
|