Files
tbf/TBF/Rig/RegisterReaders/FrequencyMeterFromUniCB/RRCfgCtrl.cs
T
2025-09-09 12:51:26 +02:00

107 lines
2.5 KiB
C#

///
/// Copyright (c) 2021 Sensus Slovensko a.s.
///
using System;
using System.Windows.Forms;
using Common;
using TBF.Rig.Generic;
using TBF.UI.Bench.Components;
namespace TBF.Rig.RegisterReaders.FrequencyMeterFromUniCB
{
public partial class RRCfgCtrl : UserControl, IComponentCfgCtrl
{
ComponentParametersDlg parent;
bool IComponentCfgCtrl.ShowMore { get { return false; } }
RRCfg config;
IComponentCfg IComponentCfgCtrl.Config
{
get { return config as IComponentCfg; }
set
{
config = value as RRCfg;
Redraw();
}
}
public RRCfgCtrl()
{
InitializeComponent();
}
private void RegisterReaderCfgCtrl_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 ControlBoard.Uni.Factory)
{
parentNameComboBox.Items.Add(cmpnt.Name);
}
}
}
Redraw();
}
void IComponentCfgCtrl.Closing()
{
}
void Redraw()
{
if (config == null) return; /// Control was not loaded, settings were not changed
componentNameLabel.Text = config.Factory.ClassName;
nameTextBox.Text = config.Name;
parentNameComboBox.Text = string.IsNullOrEmpty(config.ParentName) ? "---" : config.ParentName;
positionTextBox.Text = config.Position.ToString();
}
void IComponentCfgCtrl.Unlock()
{
nameTextBox.Enabled = true;
parentNameComboBox.Enabled = true;
positionTextBox.Enabled = true;
}
CfgUpdateFlags IComponentCfgCtrl.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 < 1))
{
flags |= CfgUpdateFlags.Error;
message += Environment.NewLine + "'Position' should be >= 1";
}
return flags;
}
CfgUpdateFlags IComponentCfgCtrl.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.Position = int.Parse(positionTextBox.Text);
return flags;
}
}
}