183 lines
5.4 KiB
C#
183 lines
5.4 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);
|
|
}
|
|
}
|
|
}
|
|
|
|
for (TestImagesMode mode = 0; mode < TestImagesMode.Count; mode++)
|
|
{
|
|
testImagesModeComboBox.Items.Add(mode.ToString());
|
|
}
|
|
|
|
Redraw();
|
|
}
|
|
|
|
void Localize()
|
|
{
|
|
nameLabel.Text = Strings.Name;
|
|
parentNameLabel.Text = Strings.Parent_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();
|
|
displayTerminalCheckBox.Checked = config.DisplayTerminal;
|
|
testImagesModeComboBox.Text = config.TestImagesMode.ToString();
|
|
testImagesCountTextBox.Text = config.TestImagesCount.ToString();
|
|
}
|
|
|
|
public void Unlock()
|
|
{
|
|
nameTextBox.Enabled = true;
|
|
parentNameComboBox.Enabled = true;
|
|
hwAddressTextBox.Enabled = true;
|
|
displayTerminalCheckBox.Enabled = true;
|
|
testImagesModeComboBox.Enabled = true;
|
|
testImagesCountTextBox.Enabled = true;
|
|
}
|
|
|
|
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(Strings.Invalid_0, parentNameLabel.Text);
|
|
}
|
|
|
|
if (!int.TryParse(hwAddressTextBox.Text, out dummy) || dummy % 100 > 63)
|
|
{
|
|
flags |= CfgUpdateFlags.Error;
|
|
message += Environment.NewLine + string.Format(Strings.Invalid_0, hwAddressLabel.Text);
|
|
}
|
|
|
|
TestImagesMode newTestImagesMode = TestImagesMode.Invalid;
|
|
for (TestImagesMode mode = 0; mode < TestImagesMode.Count; mode++)
|
|
{
|
|
if (testImagesModeComboBox.Text == mode.ToString()) newTestImagesMode = mode;
|
|
}
|
|
if (newTestImagesMode == TestImagesMode.Invalid)
|
|
{
|
|
flags |= CfgUpdateFlags.Error;
|
|
message += Environment.NewLine + string.Format(Strings.Invalid_0, testImagesModeLabel.Text);
|
|
}
|
|
|
|
if (!int.TryParse(testImagesCountTextBox.Text, out dummy) || dummy < 0 || dummy > 3000
|
|
|| ((dummy == 0) && (newTestImagesMode != TestImagesMode.None)))
|
|
{
|
|
flags |= CfgUpdateFlags.Error;
|
|
message += Environment.NewLine + string.Format(Strings.Invalid_0, testImagesCountLabel.Text);
|
|
}
|
|
|
|
|
|
return flags;
|
|
}
|
|
|
|
public CfgUpdateFlags UpdateCfg()
|
|
{
|
|
CfgUpdateFlags flags = CfgUpdateFlags.None;
|
|
|
|
if (config == null) return CfgUpdateFlags.Error; /// Control was not loaded, settings were not changed
|
|
|
|
string newParentName = parentNameComboBox.Text.Equals("---") ? string.Empty : parentNameComboBox.Text;
|
|
int newHWAddress = int.Parse(hwAddressTextBox.Text);
|
|
TestImagesMode newTestImagesMode = 0;
|
|
for (TestImagesMode mode = 0; mode < TestImagesMode.Count; mode++)
|
|
{
|
|
if (testImagesModeComboBox.Text == mode.ToString()) newTestImagesMode = mode;
|
|
}
|
|
int newTestImagesCount = int.Parse(testImagesCountTextBox.Text);
|
|
|
|
|
|
if (config.Name != nameTextBox.Text ||
|
|
config.ParentName != newParentName ||
|
|
config.HardwareAddress != newHWAddress ||
|
|
config.DisplayTerminal != displayTerminalCheckBox.Checked)
|
|
{
|
|
config.Name = nameTextBox.Text;
|
|
config.ParentName = newParentName;
|
|
config.HardwareAddress = newHWAddress;
|
|
config.DisplayTerminal = displayTerminalCheckBox.Checked;
|
|
|
|
flags |= (CfgUpdateFlags.RestartRqrd | CfgUpdateFlags.AnyChange);
|
|
}
|
|
|
|
|
|
if (config.TestImagesMode != newTestImagesMode ||
|
|
config.TestImagesCount != newTestImagesCount)
|
|
{
|
|
config.TestImagesMode = newTestImagesMode;
|
|
config.TestImagesCount = newTestImagesCount;
|
|
|
|
flags |= (CfgUpdateFlags.InvokeCfgChange | CfgUpdateFlags.VolatileChange);
|
|
}
|
|
|
|
if ((flags & CfgUpdateFlags.InvokeCfgChange) != 0)
|
|
{
|
|
Camera.OnCfgChange(this, new CfgChangeArgs(CfgChangeCmd.CfgChange, config));
|
|
}
|
|
|
|
return flags;
|
|
}
|
|
}
|
|
}
|