113 lines
3.0 KiB
C#
113 lines
3.0 KiB
C#
///
|
|
/// Copyright (c) 2018 Sensus Slovensko a.s.
|
|
///
|
|
using System;
|
|
using System.Net;
|
|
using System.Windows.Forms;
|
|
using Common;
|
|
using Config.Entities;
|
|
using TBF.Rig.Generic;
|
|
using TBF.Resources;
|
|
|
|
namespace TBF.Rig.Network.Comet.Ambient
|
|
{
|
|
public partial class AmbientCfgCtrl : UserControl, IComponentCfgCtrl
|
|
{
|
|
public bool ShowMore { get { return false; } }
|
|
|
|
AmbientCfg config;
|
|
public IComponentCfg Config
|
|
{
|
|
get { return config as IComponentCfg; }
|
|
set
|
|
{
|
|
config = value as AmbientCfg;
|
|
Redraw();
|
|
}
|
|
}
|
|
|
|
public AmbientCfgCtrl()
|
|
{
|
|
InitializeComponent();
|
|
}
|
|
|
|
private void AbbientCfgCtrl_Load(object sender, EventArgs e)
|
|
{
|
|
Localize();
|
|
Redraw();
|
|
}
|
|
|
|
void Localize()
|
|
{
|
|
nameLabel.Text = Strings.Name;
|
|
serialNrLabel.Text = Strings.Serial_number;
|
|
}
|
|
|
|
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;
|
|
ipAddressTextBox.Text = config.IPAddress != null ? config.IPAddress.ToString() : "192.168.0.123";
|
|
tcpPortTextBox.Text = config.TcpPort.ToString();
|
|
serialNrTextBox.Text = config.SerialNr.ToString();
|
|
}
|
|
|
|
public void Unlock()
|
|
{
|
|
nameTextBox.Enabled = true;
|
|
ipAddressTextBox.Enabled = true;
|
|
tcpPortTextBox.Enabled = true;
|
|
serialNrTextBox.Enabled = true;
|
|
}
|
|
|
|
public CfgUpdateFlags VerifyCfg(ref string message)
|
|
{
|
|
CfgUpdateFlags flags = CfgUpdateFlags.None;
|
|
|
|
IPAddress ip;
|
|
if (!IPAddress.TryParse(ipAddressTextBox.Text, out ip))
|
|
{
|
|
flags |= CfgUpdateFlags.Error;
|
|
message += Environment.NewLine + string.Format(Strings.Invalid_0, ipAddressLabel.Text);
|
|
}
|
|
|
|
int port;
|
|
if (!int.TryParse(tcpPortTextBox.Text, out port) || port < 0 || port > 65535)
|
|
{
|
|
flags |= CfgUpdateFlags.Error;
|
|
message += Environment.NewLine + string.Format(Strings.Invalid_0, tcpPortLabel.Text);
|
|
}
|
|
|
|
return flags;
|
|
}
|
|
|
|
public CfgUpdateFlags UpdateCfg()
|
|
{
|
|
CfgUpdateFlags flags = CfgUpdateFlags.None;
|
|
|
|
if (config == null) return CfgUpdateFlags.Error; /// Control was not loaded, settings were not changed
|
|
|
|
if (config.Name != nameTextBox.Text ||
|
|
config.IPAddress != ipAddressTextBox.Text ||
|
|
config.TcpPort.ToString() != tcpPortTextBox.Text ||
|
|
config.SerialNr != serialNrTextBox.Text)
|
|
{
|
|
config.Name = nameTextBox.Text;
|
|
config.IPAddress = ipAddressTextBox.Text;
|
|
config.TcpPort = int.Parse(tcpPortTextBox.Text);
|
|
config.SerialNr = serialNrTextBox.Text;
|
|
|
|
flags |= (CfgUpdateFlags.RestartRqrd | CfgUpdateFlags.AnyChange);
|
|
}
|
|
|
|
return flags;
|
|
}
|
|
}
|
|
}
|