tbf/TBF/Rig/TestMethods/GenesisCommunication/GenesisHead/GenesisHeadCfgCtrl.cs

112 lines
2.9 KiB
C#

///
/// Copyright (c) 2015-2017 Sensus Metering Systems
///
using System;
using System.Net;
using System.Net.Sockets;
using System.Windows.Forms;
using log4net;
using TBF.Rig.Generic;
using TBF.Resources;
using Config.Entities;
using Common;
namespace TBF.Rig.TestMethods.GenesisCommunication.GenesisHead
{
public partial class GenesisHeadCfgCtrl : UserControl, IComponentCfgCtrl
{
static readonly ILog log = LogManager.GetLogger(typeof(GenesisHeadCfgCtrl));
public bool ShowMore { get { return false; } }
GenesisHeadCfg config;
public IComponentCfg Config
{
get { return config as IComponentCfg; }
set
{
config = value as GenesisHeadCfg;
Redraw();
}
}
public GenesisHeadCfgCtrl()
{
InitializeComponent();
}
private void WaterMeterCfgCtrl_Load(object sender, EventArgs e)
{
nameLabel.Text = Strings.Name;
classNameLabel.Text = config.Factory.ClassName;
slotNrTextBox.Text = config.SlotNr.ToString();
optoSerialPortTextBox.Text = config.OptoComPortNr.ToString();
headPortNrTextBox.Text = config.HeadComPortNr.ToString();
Redraw();
}
public void Closing()
{
}
void Redraw()
{
if (config == null) return; /// Control was not loaded, settings were not changed
nameTextBox.Text = config.Name;
optoSerialPortTextBox.Text = config.OptoComPortNr.ToString();
headPortNrTextBox.Text = config.HeadComPortNr.ToString();
}
public void Unlock()
{
nameTextBox.Enabled = true;
slotNrTextBox.Enabled = true;
optoSerialPortTextBox.Enabled = true;
headPortNrTextBox.Enabled = true;
}
public CfgUpdateFlags VerifyCfg(ref string message)
{
CfgUpdateFlags flags = CfgUpdateFlags.None;
int dummy;
if (!int.TryParse(slotNrTextBox.Text, out dummy) || dummy < 1 || dummy > 10)
{
flags |= CfgUpdateFlags.Error;
message += Environment.NewLine + string.Format(Strings.Invalid_0, muxBoardNrLabel.Text);
}
if (!int.TryParse(optoSerialPortTextBox.Text, out dummy) || dummy < 1 || dummy > 999)
{
flags |= CfgUpdateFlags.Error;
message += Environment.NewLine + "'Opto serial port nr.' is not valid";
}
if (!int.TryParse(headPortNrTextBox.Text, out dummy) || dummy < 0 || dummy > 999)
{
flags |= CfgUpdateFlags.Error;
message += Environment.NewLine + "'Head communication serial port nr.' 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.SlotNr = int.Parse(slotNrTextBox.Text);
config.OptoComPortNr = int.Parse(optoSerialPortTextBox.Text);
config.HeadComPortNr = int.Parse(headPortNrTextBox.Text);
return flags;
}
}
}