using System; using System.Globalization; using System.Windows.Forms; using log4net; using TBF.BenchControl.Generic; namespace TBF.BenchControl.Elde.FlowMeter { public partial class FlowMeterCfgCtrl : UserControl, IComponentCfgCtrl { static readonly ILog log = LogManager.GetLogger(typeof(FlowMeterCfgCtrl)); ComponentParametersDlg parent; FlowMeterCfg config; public IComponentCfg Config { get { return config as IComponentCfg; } set { config = value as FlowMeterCfg; Redraw(); } } public FlowMeterCfgCtrl() { InitializeComponent(); } private void FlowMeterCfgCtrl_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); } } } Redraw(); } 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; positionTextBox.Text = config.Idx1.ToString(); nominalFlowTextBox.Text = config.NominalFlow.ToString(); } public void Unlock() { nameTextBox.Enabled = true; parentNameComboBox.Enabled = true; positionTextBox.Enabled = true; nominalFlowTextBox.Enabled = true; } public CfgVerifyFlags VerifyCfg(ref string message) { CfgVerifyFlags flags = CfgVerifyFlags.None; int dummy; if (!parentNameComboBox.Items.Contains(parentNameComboBox.Text)) { flags |= CfgVerifyFlags.Error; message += Environment.NewLine + "Invalid 'Parent Name'"; } if (!int.TryParse(positionTextBox.Text, out dummy) || dummy < 1 || dummy > 7) { flags |= CfgVerifyFlags.Error; message += Environment.NewLine + "'Idx1' should be between 1 and 7"; } float fdummy; if (!Utils.TryParseUFloat(nominalFlowTextBox.Text, out fdummy) || fdummy < 0.2 || fdummy > 1600) { flags |= CfgVerifyFlags.Error; message += Environment.NewLine + "'Nominal flow' should be between 0.2 and 1600"; } return flags; } public void UpdateCfg() { if (config == null) return; /// Control was not loaded, settings were not changed config.Name = nameTextBox.Text; config.ParentName = parentNameComboBox.Text.Equals("---") ? string.Empty : parentNameComboBox.Text; config.Idx1 = int.Parse(positionTextBox.Text); Utils.TryParseUFloat(nominalFlowTextBox.Text, out config.NominalFlow); } } }