/// /// Copyright (c) 2018 Sensus Slovensko a.s. /// using System; using System.Windows.Forms; using Config.Entities; using TBF.BenchControl.Generic; using TBF.Resources; namespace TBF.BenchControl.Various.TankWithLevelMsrmnt { public partial class TankCfgCtrl : UserControl, IComponentCfgCtrl { ComponentParametersDlg parent; public bool ShowMore { get { return false; } } TankCfg config; public IComponentCfg Config { get { return config as IComponentCfg; } set { config = value as TankCfg; Redraw(); } } public TankCfgCtrl() { InitializeComponent(); } private void BalanceCfgCtrl_Load(object sender, EventArgs e) { parent = ParentForm as ComponentParametersDlg; if (parent == null) return; if (parent.TbfComponents != null) { drainValveComboBox.Items.Add("---"); drainValve2ComboBox.Items.Add("---"); levelMeasurementComboBox.Items.Add("---"); foreach (var cmpnt in parent.TbfComponents) { IComponentFactory cmpntFact = TbfComponents.CmpntFactoryFromClassName(cmpnt.ClassName); if (cmpntFact is Elde.Valve.ValveFactory) { drainValveComboBox.Items.Add(cmpnt.Name); drainValve2ComboBox.Items.Add(cmpnt.Name); } //if (cmpnt is TBF.BenchControl.GenericDevices.ILevelMeter) /// TODO: Preco nefunguje? if (cmpntFact is Modbus.UltrasoundLevelMeter.Factory || cmpntFact is Hart.Nivotrack.Factory) { levelMeasurementComboBox.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; capacityTextBox.Text = config.Capacity.ToString(); emptyTextBox.Text = config.Empty.ToString(); drainValveComboBox.Text = string.IsNullOrEmpty(config.DrainValve) ? "---" : config.DrainValve; drainValve2ComboBox.Text = string.IsNullOrEmpty(config.DrainValve2) ? "---" : config.DrainValve2; drainTimeTextBox.Text = config.DrainTimeSec.ToString(); levelMeasurementComboBox.Text = string.IsNullOrEmpty(config.LevelMeasurement) ? "---" : config.LevelMeasurement; thresholdLevel1TextBox.Text = config.ThldLevel1.ToString(); thresholdLevel2TextBox.Text = config.ThldLevel2.ToString(); thresholdLevel3TextBox.Text = config.ThldLevel3.ToString(); thresholdLevel4TextBox.Text = config.ThldLevel4.ToString(); calibrationTableTextBox.Text = config.CalibrationTable; } public void Unlock() { nameTextBox.Enabled = true; capacityTextBox.Enabled = true; emptyTextBox.Enabled = true; drainValveComboBox.Enabled = true; drainValve2ComboBox.Enabled = true; drainTimeTextBox.Enabled = true; levelMeasurementComboBox.Enabled = true; thresholdLevel1TextBox.Enabled = true; thresholdLevel2TextBox.Enabled = true; thresholdLevel3TextBox.Enabled = true; thresholdLevel4TextBox.Enabled = true; calibrationTableTextBox.Enabled = true; } public CfgUpdateFlags VerifyCfg(ref string message) { CfgUpdateFlags flags = CfgUpdateFlags.None; int dummy; float ftmp; if (!Utils.TryParseUFloat(capacityTextBox.Text, out ftmp) || ftmp <= 0) { flags |= CfgUpdateFlags.Error; message += Environment.NewLine + "'Tank Capacity' is not valid"; } if (!Utils.TryParseUFloat(emptyTextBox.Text, out ftmp) || ftmp <= 0) { flags |= CfgUpdateFlags.Error; message += Environment.NewLine + "'Tank Empty' is not valid"; } if (!drainValveComboBox.Items.Contains(drainValveComboBox.Text)) { flags |= CfgUpdateFlags.Error; message += Environment.NewLine + string.Format(Strings.Invalid_0, drainValveLabel.Text); } if (!drainValve2ComboBox.Items.Contains(drainValve2ComboBox.Text)) { flags |= CfgUpdateFlags.Error; message += Environment.NewLine + string.Format(Strings.Invalid_0, drainValve2Label.Text); } if (!int.TryParse(drainTimeTextBox.Text, out dummy) || dummy < 1 || dummy > 999) { flags |= CfgUpdateFlags.Error; message += Environment.NewLine + "'Tank drain time' should be between 1 and 999 sec"; } if (!levelMeasurementComboBox.Items.Contains(levelMeasurementComboBox.Text)) { flags |= CfgUpdateFlags.Error; message += Environment.NewLine + string.Format(Strings.Invalid_0, levelMeasurementLabel.Text); } if (!Utils.TryParseUFloat(thresholdLevel1TextBox.Text, out ftmp) || ftmp <= 0) { flags |= CfgUpdateFlags.Error; message += Environment.NewLine + "'Threshold level 1' is not valid"; } if (!Utils.TryParseUFloat(thresholdLevel2TextBox.Text, out ftmp) || ftmp <= 0) { flags |= CfgUpdateFlags.Error; message += Environment.NewLine + "'Threshold level 2' is not valid"; } if (!Utils.TryParseUFloat(thresholdLevel3TextBox.Text, out ftmp) || ftmp <= 0) { flags |= CfgUpdateFlags.Error; message += Environment.NewLine + "'Threshold level 3' is not valid"; } if (!Utils.TryParseUFloat(thresholdLevel4TextBox.Text, out ftmp) || ftmp <= 0) { flags |= CfgUpdateFlags.Error; message += Environment.NewLine + "'Threshold level 4' 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.Capacity = Utils.ParseUFloat(capacityTextBox.Text); config.Empty = Utils.ParseUFloat(emptyTextBox.Text); config.DrainTimeSec = int.Parse(drainTimeTextBox.Text); config.DrainValve = drainValveComboBox.Text.Equals("---") ? string.Empty : drainValveComboBox.Text; config.DrainValve2 = drainValve2ComboBox.Text.Equals("---") ? string.Empty : drainValve2ComboBox.Text; config.LevelMeasurement = levelMeasurementComboBox.Text.Equals("---") ? string.Empty : levelMeasurementComboBox.Text; config.ThldLevel1 = Utils.ParseUFloat(thresholdLevel1TextBox.Text); config.ThldLevel2 = Utils.ParseUFloat(thresholdLevel2TextBox.Text); config.ThldLevel3 = Utils.ParseUFloat(thresholdLevel3TextBox.Text); config.ThldLevel4 = Utils.ParseUFloat(thresholdLevel4TextBox.Text); config.CalibrationTable = calibrationTableTextBox.Text; return flags; } } }