137 lines
3.6 KiB
C#
137 lines
3.6 KiB
C#
///
|
|
/// Copyright (c) 2017 Sensus Metering Systems
|
|
///
|
|
using System;
|
|
using System.Windows.Forms;
|
|
using log4net;
|
|
using TBF.BenchControl.Generic;
|
|
using TBF.Resources;
|
|
|
|
namespace TBF.BenchControl.Network.Camera.CLP1611
|
|
{
|
|
public partial class CameraCfgCtrl : UserControl, IComponentCfgCtrl
|
|
{
|
|
static readonly ILog log = LogManager.GetLogger(typeof(CameraCfgCtrl));
|
|
|
|
ComponentParametersDlg parent;
|
|
|
|
public bool ShowMore { get { return false; } }
|
|
|
|
CameraCfg config;
|
|
public IComponentCfg Config
|
|
{
|
|
get { return config as IComponentCfg; }
|
|
set
|
|
{
|
|
config = value as CameraCfg;
|
|
Redraw();
|
|
}
|
|
}
|
|
|
|
public CameraCfgCtrl()
|
|
{
|
|
InitializeComponent();
|
|
}
|
|
|
|
private void PumpCfgCtrl_Load(object sender, EventArgs e)
|
|
{
|
|
Localize();
|
|
|
|
parent = ParentForm as ComponentParametersDlg;
|
|
if (parent == null) return;
|
|
|
|
if (parent.TbfComponents != null)
|
|
{
|
|
foreach (var cmpnt in parent.TbfComponents)
|
|
{
|
|
if (TbfComponents.CmpntFactoryFromClassName(cmpnt.ClassName) is TBF.BenchControl.Network.Adapter.Factory)
|
|
{
|
|
parentNameComboBox.Items.Add(cmpnt.Name);
|
|
}
|
|
}
|
|
}
|
|
|
|
Redraw();
|
|
}
|
|
|
|
void Localize()
|
|
{
|
|
nameLabel.Text = Strings.Name;
|
|
hwAddressLabel.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;
|
|
parentNameComboBox.Text = string.IsNullOrEmpty(config.ParentName) ? "---" : config.ParentName;
|
|
hwAddressTextBox.Text = config.HardwareAddress.ToString();
|
|
useTestImagesCheckBox.Checked = config.UseTestImages;
|
|
testImagesCountTextBox.Text = config.TestImagesCount.ToString();
|
|
displayTerminalCheckBox.Checked = config.DisplayTerminal;
|
|
}
|
|
|
|
public void Unlock()
|
|
{
|
|
nameTextBox.Enabled = true;
|
|
parentNameComboBox.Enabled = true;
|
|
hwAddressTextBox.Enabled = true;
|
|
useTestImagesCheckBox.Enabled = true;
|
|
testImagesCountTextBox.Enabled = true;
|
|
displayTerminalCheckBox.Enabled = true;
|
|
}
|
|
|
|
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.ParentName = parentNameComboBox.Text.Equals("---") ? string.Empty : parentNameComboBox.Text;
|
|
config.HardwareAddress = int.Parse(hwAddressTextBox.Text);
|
|
config.DisplayTerminal = displayTerminalCheckBox.Checked;
|
|
config.UseTestImages = useTestImagesCheckBox.Checked;
|
|
if (config.UseTestImages)
|
|
{
|
|
config.TestImagesCount = int.Parse(testImagesCountTextBox.Text);
|
|
}
|
|
|
|
return flags;
|
|
}
|
|
|
|
public CfgUpdateFlags VerifyCfg(ref string message)
|
|
{
|
|
CfgUpdateFlags flags = CfgUpdateFlags.None;
|
|
|
|
int dummy;
|
|
if (!parentNameComboBox.Items.Contains(parentNameComboBox.Text))
|
|
{
|
|
flags |= CfgUpdateFlags.Error;
|
|
message += Environment.NewLine + string.Format("Invalid '{0}'", Strings.Parent_name);
|
|
}
|
|
|
|
if (!int.TryParse(hwAddressTextBox.Text, out dummy) || dummy % 100 > 63)
|
|
{
|
|
flags |= CfgUpdateFlags.Error;
|
|
message += Environment.NewLine + string.Format("'{0}' is not correct", hwAddressLabel.Text);
|
|
}
|
|
|
|
if (useTestImagesCheckBox.Checked &&
|
|
(!int.TryParse(testImagesCountTextBox.Text, out dummy) || dummy < 1 || dummy > 50))
|
|
{
|
|
flags |= CfgUpdateFlags.Error;
|
|
message += Environment.NewLine + string.Format("'{0}' should be between 1 and 50", testImagesCountLabel.Text);
|
|
}
|
|
|
|
return flags;
|
|
}
|
|
}
|
|
}
|