2017-02-09 13:25:41 +00:00
///
/// Copyright (c) 2017 Sensus Metering Systems
///
using System ;
using System.Windows.Forms ;
using log4net ;
using TBF.BenchControl.Generic ;
2017-02-10 12:43:41 +00:00
namespace TBF.BenchControl.Modbus.TankSelector
2017-02-09 13:25:41 +00:00
{
public partial class TankSelectorCfgCtrl : UserControl , IComponentCfgCtrl
{
static readonly ILog log = LogManager . GetLogger ( typeof ( TankSelectorCfgCtrl ) ) ;
ComponentParametersDlg parent ;
public bool ShowMore { get { return false ; } }
TankSelectorCfg config ;
public IComponentCfg Config
{
get { return config as IComponentCfg ; }
set
{
config = value as TankSelectorCfg ;
Redraw ( ) ;
}
}
public TankSelectorCfgCtrl ( )
{
InitializeComponent ( ) ;
}
private void TankSelectorCfgCtrl_Load ( object sender , EventArgs e )
{
parent = ParentForm as ComponentParametersDlg ;
if ( parent = = null ) return ;
2017-03-09 12:28:06 +00:00
hotHeatingComboBox . Items . Add ( "---" ) ;
hotCoolingComboBox . Items . Add ( "---" ) ;
warmHeatingComboBox . Items . Add ( "---" ) ;
warmCoolingComboBox . Items . Add ( "---" ) ;
coldCoolingComboBox . Items . Add ( "---" ) ;
if ( parent . TbfComponents ! = null )
2017-02-09 13:25:41 +00:00
{
foreach ( var cmpnt in parent . TbfComponents )
{
if ( TbfComponents . CmpntFactoryFromClassName ( cmpnt . ClassName ) is Modbus . QuidoRS . Factory )
{
parentNameComboBox . Items . Add ( cmpnt . Name ) ;
}
2017-03-09 12:28:06 +00:00
if ( TbfComponents . CmpntFactoryFromClassName ( cmpnt . ClassName ) is Modbus . Easytherm . Factory )
2017-02-09 13:25:41 +00:00
{
2017-03-09 12:28:06 +00:00
hotHeatingComboBox . Items . Add ( cmpnt . Name ) ;
hotCoolingComboBox . Items . Add ( cmpnt . Name ) ;
warmHeatingComboBox . Items . Add ( cmpnt . Name ) ;
warmCoolingComboBox . Items . Add ( cmpnt . Name ) ;
coldCoolingComboBox . Items . Add ( cmpnt . Name ) ;
}
2017-02-09 13:25:41 +00:00
}
}
Redraw ( ) ;
}
public void Closing ( )
{
}
void Redraw ( )
{
if ( config = = null ) return ; /// Control was not loaded, settings were not changed
componentNameLabel . Text = config . Factory . ClassName ;
nameTextBox . Text = config . Name ;
parentNameComboBox . Text = string . IsNullOrEmpty ( config . ParentName ) ? "---" : config . ParentName ;
2017-03-09 12:28:06 +00:00
hotHeatingComboBox . Text = string . IsNullOrEmpty ( config . HotWaterHeating ) ? "---" : config . HotWaterHeating ;
hotCoolingComboBox . Text = string . IsNullOrEmpty ( config . HotWaterCooling ) ? "---" : config . HotWaterCooling ;
warmHeatingComboBox . Text = string . IsNullOrEmpty ( config . WarmWaterHeating ) ? "---" : config . WarmWaterHeating ;
warmCoolingComboBox . Text = string . IsNullOrEmpty ( config . WarmWaterCooling ) ? "---" : config . WarmWaterCooling ;
coldCoolingComboBox . Text = string . IsNullOrEmpty ( config . ColdWaterCooling ) ? "---" : config . ColdWaterCooling ;
}
2017-02-09 13:25:41 +00:00
public void Unlock ( )
{
nameTextBox . Enabled = true ;
parentNameComboBox . Enabled = true ;
2017-03-09 12:28:06 +00:00
hotHeatingComboBox . Enabled = true ;
hotCoolingComboBox . Enabled = true ;
warmHeatingComboBox . Enabled = true ;
warmCoolingComboBox . Enabled = true ;
coldCoolingComboBox . Enabled = true ;
}
2017-02-09 13:25:41 +00:00
public CfgUpdateFlags VerifyCfg ( ref string message )
{
CfgUpdateFlags flags = CfgUpdateFlags . None ;
2017-03-09 12:28:06 +00:00
if ( ! parentNameComboBox . Items . Contains ( parentNameComboBox . Text ) ) { flags | = CfgUpdateFlags . Error ; message + = Environment . NewLine + "Invalid 'Parent name'" ; }
if ( ! hotHeatingComboBox . Items . Contains ( hotHeatingComboBox . Text ) ) { flags | = CfgUpdateFlags . Error ; message + = Environment . NewLine + "Invalid 'Hot water heating'" ; }
if ( ! hotCoolingComboBox . Items . Contains ( hotCoolingComboBox . Text ) ) { flags | = CfgUpdateFlags . Error ; message + = Environment . NewLine + "Invalid 'Hot water cooling'" ; }
if ( ! warmHeatingComboBox . Items . Contains ( warmHeatingComboBox . Text ) ) { flags | = CfgUpdateFlags . Error ; message + = Environment . NewLine + "Invalid 'Warm water heating'" ; }
if ( ! warmCoolingComboBox . Items . Contains ( warmCoolingComboBox . Text ) ) { flags | = CfgUpdateFlags . Error ; message + = Environment . NewLine + "Invalid 'Warm water cooling'" ; }
if ( ! coldCoolingComboBox . Items . Contains ( coldCoolingComboBox . Text ) ) { flags | = CfgUpdateFlags . Error ; message + = Environment . NewLine + "Invalid 'Cold water cooling'" ; }
return flags ;
2017-02-09 13:25:41 +00:00
}
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 ;
2017-03-09 12:28:06 +00:00
config . HotWaterHeating = hotHeatingComboBox . Text . Equals ( "---" ) ? string . Empty : hotHeatingComboBox . Text ;
config . HotWaterCooling = hotCoolingComboBox . Text . Equals ( "---" ) ? string . Empty : hotCoolingComboBox . Text ;
config . WarmWaterHeating = warmHeatingComboBox . Text . Equals ( "---" ) ? string . Empty : warmHeatingComboBox . Text ;
config . WarmWaterCooling = warmCoolingComboBox . Text . Equals ( "---" ) ? string . Empty : warmCoolingComboBox . Text ;
config . ColdWaterCooling = coldCoolingComboBox . Text . Equals ( "---" ) ? string . Empty : coldCoolingComboBox . Text ;
2017-02-09 13:25:41 +00:00
return flags ;
}
}
}