tbf/TBF/BenchControl/Elde/PumpTandem/PumpCfgCtrl.cs

109 lines
3.1 KiB
C#

///
/// Copyright (c) 2013-2015 Sensus Metering Systems
///
using System;
using System.Windows.Forms;
using Config.Entities;
using TBF.BenchControl.Generic;
using TBF.UI.Bench.Components;
namespace TBF.BenchControl.Elde.PumpTandem
{
public partial class PumpCfgCtrl : UserControl, IComponentCfgCtrl
{
ComponentParametersDlg parentDlg;
public bool ShowMore { get { return false; } }
PumpCfg config;
public IComponentCfg Config
{
get { return config as IComponentCfg; }
set
{
config = value as PumpCfg;
Redraw();
}
}
public PumpCfgCtrl()
{
InitializeComponent();
}
private void PumpCfgCtrl_Load(object sender, EventArgs e)
{
parentDlg = ParentForm as ComponentParametersDlg;
if (parentDlg == null) return;
if (parentDlg.CmpntEntities != null)
{
foreach (var cmpnt in parentDlg.CmpntEntities)
{
if (TbfComponents.CmpntFactoryFromClassName(cmpnt.ClassName) is Elde.Pump.PumpFactory ||
TbfComponents.CmpntFactoryFromClassName(cmpnt.ClassName) is Elde.PumpWithFM.PumpFactory ||
TbfComponents.CmpntFactoryFromClassName(cmpnt.ClassName) is Danfoss.VLT2800.PumpFactory ||
TbfComponents.CmpntFactoryFromClassName(cmpnt.ClassName) is Elde.PumpTandem.PumpFactory)
{
pump1ComboBox.Items.Add(cmpnt.Name);
pump2ComboBox.Items.Add(cmpnt.Name);
}
}
}
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;
pump1ComboBox.Text = string.IsNullOrEmpty(config.Pump1) ? "---" : config.Pump1;
pump2ComboBox.Text = string.IsNullOrEmpty(config.Pump2) ? "---" : config.Pump2;
}
public void Unlock()
{
nameTextBox.Enabled = true;
pump1ComboBox.Enabled = true;
pump2ComboBox.Enabled = true;
}
public CfgUpdateFlags VerifyCfg(ref string message)
{
CfgUpdateFlags flags = CfgUpdateFlags.None;
if (!pump1ComboBox.Items.Contains(pump1ComboBox.Text))
{
flags |= CfgUpdateFlags.Error;
message += Environment.NewLine + "Invalid 'Pump 1'";
}
if (!pump2ComboBox.Items.Contains(pump2ComboBox.Text))
{
flags |= CfgUpdateFlags.Error;
message += Environment.NewLine + "Invalid 'Pump 2'";
}
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.Pump1 = pump1ComboBox.Text.Equals("---") ? string.Empty : pump1ComboBox.Text;
config.Pump2 = pump2ComboBox.Text.Equals("---") ? string.Empty : pump2ComboBox.Text;
return flags;
}
}
}