106 lines
2.7 KiB
C#
106 lines
2.7 KiB
C#
///
|
|
/// Copyright (c) 2020 Sensus Slovensko a.s.
|
|
///
|
|
using System;
|
|
using System.Windows.Forms;
|
|
using Config.Entities;
|
|
using TBF.BenchControl.Generic;
|
|
|
|
namespace TBF.BenchControl.ControlBoard.New
|
|
{
|
|
public partial class CBoardCfgCtrl : UserControl, IComponentCfgCtrl
|
|
{
|
|
public bool ShowMore { get { return false; } }
|
|
|
|
CBoardCfg config;
|
|
public IComponentCfg Config
|
|
{
|
|
get { return config as IComponentCfg; }
|
|
set
|
|
{
|
|
config = value as CBoardCfg;
|
|
Redraw();
|
|
}
|
|
}
|
|
|
|
public CBoardCfgCtrl()
|
|
{
|
|
InitializeComponent();
|
|
}
|
|
|
|
private void ControlBoardCfgCtrl_Load(object sender, EventArgs e)
|
|
{
|
|
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;
|
|
comPortNrTextBox.Text = config.ComPortNr.ToString();
|
|
vValveRangeLoTextBox.Text = config.VirtualValvesRangeLo.ToString();
|
|
vValveRangeHiTextBox.Text = config.VirtualValvesRangeHi.ToString();
|
|
}
|
|
|
|
public void Unlock()
|
|
{
|
|
nameTextBox.Enabled = true;
|
|
comPortNrTextBox.Enabled = true;
|
|
vValveRangeLoTextBox.Enabled = true;
|
|
vValveRangeHiTextBox.Enabled = true;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Verify current user controls for validity.
|
|
/// Called when user wants to close/save the configuration.
|
|
/// </summary>
|
|
/// <returns>See VerifyFlags</returns>
|
|
public CfgUpdateFlags VerifyCfg(ref string message)
|
|
{
|
|
CfgUpdateFlags flags = CfgUpdateFlags.None;
|
|
|
|
int dummy;
|
|
if (!int.TryParse(comPortNrTextBox.Text, out dummy) || dummy <= 0 || dummy > 999)
|
|
{
|
|
message += "Control board serial port number is invalid";
|
|
flags |= CfgUpdateFlags.Error;
|
|
}
|
|
if (!int.TryParse(vValveRangeLoTextBox.Text, out dummy) || dummy < 0 || dummy > 63)
|
|
{
|
|
message += "Virtual valves range Lo is invalid";
|
|
flags |= CfgUpdateFlags.Error;
|
|
}
|
|
if (!int.TryParse(vValveRangeHiTextBox.Text, out dummy) || dummy < 0 || dummy > 63)
|
|
{
|
|
message += "Virtual valves range Hi is invalid";
|
|
flags |= CfgUpdateFlags.Error;
|
|
}
|
|
|
|
return flags;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Save settings to the configuration class.
|
|
/// </summary>
|
|
public CfgUpdateFlags UpdateCfg()
|
|
{
|
|
CfgUpdateFlags flags = CfgUpdateFlags.RestartRqrd;
|
|
|
|
if (config == null) return CfgUpdateFlags.Error; /// Control was not loaded, settings were not changed
|
|
|
|
this.Name = nameTextBox.Text;
|
|
this.config.ComPortNr = int.Parse(comPortNrTextBox.Text);
|
|
this.config.VirtualValvesRangeLo = int.Parse(vValveRangeLoTextBox.Text);
|
|
this.config.VirtualValvesRangeHi = int.Parse(vValveRangeHiTextBox.Text);
|
|
|
|
return flags;
|
|
}
|
|
}
|
|
}
|