/// /// Copyright (c) 2015-2018 Sensus Slovensko a.s. /// using System; using System.Windows.Forms; using Config.Entities; using TBF.BenchControl.Generic; using TBF.UI.Bench.Components; namespace TBF.BenchControl.Elde.PressureMeterInternal { public partial class PressureMeterCfgCtrl : UserControl, IComponentCfgCtrl { ComponentParametersDlg parent; public bool ShowMore { get { return false; } } PressureMeterCfg config; public IComponentCfg Config { get { return config as IComponentCfg; } set { config = value as PressureMeterCfg; Redraw(); } } public PressureMeterCfgCtrl() { InitializeComponent(); } private void TempMeterCfgCtrl_Load(object sender, EventArgs e) { parent = ParentForm as ComponentParametersDlg; if (parent == null) return; if (parent.CmpntEntities != null) { foreach (var cmpnt in parent.CmpntEntities) { if (TbfComponents.CmpntFactoryFromClassName(cmpnt.ClassName) is Elde.ControlBoardFactory) { parentNameComboBox.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; parentNameComboBox.Text = string.IsNullOrEmpty(config.ParentName) ? "---" : config.ParentName; positionTextBox.Text = config.Idx0.ToString(); coefsIdxTextBox.Text = config.CoefsIdx0.ToString(); a1TextBox.Text = config.A1.ToString(); a2TextBox.Text = config.A2.ToString(); a3TextBox.Text = config.A3.ToString(); a4TextBox.Text = config.A4.ToString(); a5TextBox.Text = config.A5.ToString(); } public void Unlock() { nameTextBox.Enabled = true; parentNameComboBox.Enabled = true; positionTextBox.Enabled = true; coefsIdxTextBox.Enabled = true; a1TextBox.Enabled = true; a2TextBox.Enabled = true; a3TextBox.Enabled = true; a4TextBox.Enabled = true; a5TextBox.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 (!int.TryParse(positionTextBox.Text, out dummy) || dummy < 0 || dummy > 7) { flags |= CfgUpdateFlags.Error; message += Environment.NewLine + "'Position' should be between 0 and 7"; } if (!int.TryParse(coefsIdxTextBox.Text, out dummy) || dummy < 0 || dummy > 7) { flags |= CfgUpdateFlags.Error; message += Environment.NewLine + "'Coeficients idx.' should be between 0 and 7"; } float fdummy; if (!Utils.TryParseEFloat(a1TextBox.Text, out fdummy)) { flags |= CfgUpdateFlags.Error; message += Environment.NewLine + "'A1' is not valid"; } if (!Utils.TryParseEFloat(a2TextBox.Text, out fdummy)) { flags |= CfgUpdateFlags.Error; message += Environment.NewLine + "'A2' is not valid"; } if (!Utils.TryParseEFloat(a3TextBox.Text, out fdummy)) { flags |= CfgUpdateFlags.Error; message += Environment.NewLine + "'A3' is not valid"; } if (!Utils.TryParseEFloat(a4TextBox.Text, out fdummy)) { flags |= CfgUpdateFlags.Error; message += Environment.NewLine + "'A4' is not valid"; } if (!Utils.TryParseEFloat(a5TextBox.Text, out fdummy)) { flags |= CfgUpdateFlags.Error; message += Environment.NewLine + "'A5' is not valid"; } return flags; } 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.ParentName = parentNameComboBox.Text.Equals("---") ? string.Empty : parentNameComboBox.Text; config.Idx0 = int.Parse(positionTextBox.Text); config.CoefsIdx0 = int.Parse(coefsIdxTextBox.Text); bool updateOk = Utils.TryParseEFloat(a1TextBox.Text, out config.A1) && Utils.TryParseEFloat(a2TextBox.Text, out config.A2) && Utils.TryParseEFloat(a3TextBox.Text, out config.A3) && Utils.TryParseEFloat(a4TextBox.Text, out config.A4) && Utils.TryParseEFloat(a5TextBox.Text, out config.A5); return flags; } } }