// Dlg_WaterHeating.cpp : implementation file
//

#include "stdafx.h"
#include "SAPP1.h"
#include "SAPP1Dlg.h"
#include "Dlg_WaterHeating.h"

// CDlg_WaterHeating dialog

IMPLEMENT_DYNAMIC(CDlg_WaterHeating, CDialog)
CDlg_WaterHeating::CDlg_WaterHeating(CWnd* pParent /*=NULL*/)
	: CDialog(CDlg_WaterHeating::IDD, pParent)
	, str_comboWHtype(_T(""))
	, str_comboCylinderWithingDwelling(_T(""))
	, str_comboDHWfuel(_T(""))
	, str_comboWaterSepTimed(_T(""))
	, str_comboManufactLossFactor(_T(""))
	, str_editCylinderDecFactor(_T(""))
	, str_editCylinderVolume(_T(""))
	, str_comboInsulationType(_T(""))
	, str_editCylInsulationThickness(_T(""))
	, str_comboCylThermostat(_T(""))
	, str_comboCylInHtdSpace(_T(""))
	, str_comboCylPrimaryPipeworkIns(_T(""))
	, str_comboCylPumpedPrimarySys(_T(""))
	, str_comboTSinSingleUnit(_T(""))
	, str_comboTSPrimaryPipework(_T(""))
	, str_comboTSInAiringCpbd(_T(""))
	, str_comboCombiHotUsesElec(_T(""))
	, str_editTSpowerRating(_T(""))
	, str_comboDHWprovidedFrom(_T(""))
	, str_editCHPheatToPowerRatio(_T(""))
	, str_comboDHWsystem(_T(""))
	, str_editDHWefficiency(_T(""))
	, str_comboHPusesImmer(_T(""))
	, str_comboSummerImmer(_T(""))
	, str_comboCombiHotYN(_T(""))
	, str_comboDHWCom(_T(""))
	, str_comboFGHRsys(_T(""))
	, str_editWTEff(_T(""))
{
}

CDlg_WaterHeating::~CDlg_WaterHeating()
{
}

void CDlg_WaterHeating::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	DDX_Control(pDX, IDC_STATIC_1, m_labelGeneral);
	DDX_Control(pDX, IDC_STATIC_2, m_labelCylinderDetails);
	DDX_Control(pDX, IDC_STATIC_3, m_labelThermalStore);
	DDX_Control(pDX, IDC_STATIC_4, m_labelCombiHot);
	DDX_Control(pDX, IDC_STATIC_6, m_labelDHW);
	DDX_Control(pDX, IDC_STATIC_5, m_labelHeatPump);
	DDX_Control(pDX, IDC_STATIC_7, m_labelSummerImmer);
	DDX_Control(pDX, IDC_COMBO_WHtype, m_comboWHtype);
	DDX_Control(pDX, IDC_COMBO_cylinder, m_comboCylinderWithingDwelling);
	DDX_Control(pDX, IDC_COMBO_WHfuel, m_comboDHWfuel);
	DDX_Control(pDX, IDC_COMBO_waterSepTimed, m_comboWaterSepTimed);
	DDX_Control(pDX, IDC_COMBO_ManufactLossFact, m_comboManufactLossFactor);
	DDX_Control(pDX, IDC_COMBO_insType, m_comboInsulationType);
	DDX_Control(pDX, IDC_COMBO_thermostat, m_comboCylThermostat);
	DDX_Control(pDX, IDC_COMBO_inHeatedSpace, m_comboCylInHtdSpace);
	DDX_Control(pDX, IDC_COMBO_primPipeworkIns, m_comboCylPrimaryPipeworkIns);
	DDX_Control(pDX, IDC_COMBO_pumpedPrimSystem, m_comboCylPumpedPrimarySys);
	DDX_Control(pDX, IDC_COMBO_inSingleUnit, m_comboTSinSingleUnit);
	DDX_Control(pDX, IDC_COMBO_primPipeLT1_5m, m_comboTSPrimaryPipework);
	DDX_Control(pDX, IDC_COMBO_storeInAiringCpbd, m_comboTSInAiringCpbd);
	DDX_Control(pDX, IDC_COMB_keepHotUsesElec, m_comboCombiHotUsesElec);
	DDX_Control(pDX, IDC_COMBO_DHWprovidedFrom, m_comboDHWprovidedFrom);
	DDX_Control(pDX, IDC_COMBO28, m_comboDHWsystem);
	DDX_Control(pDX, IDC_COMBO_DHWusesImmer, m_comboHPusesImmer);
	DDX_Control(pDX, IDC_COMBO_summerImmer, m_comboSummerImmer);
	DDX_Control(pDX, IDC_EDIT_cylDeclaredFactor, m_editCylinderDecFactor);
	DDX_Control(pDX, IDC_EDIT_cylVolume, m_editCylinderVolume);
	DDX_Control(pDX, IDC_EDIT_InsThickness, m_editCylInsulationThickness);
	DDX_Control(pDX, IDC_EDIT_keepHotWaterRating, m_editTSpowerRating);
	DDX_Control(pDX, IDC_EDIT_CHPheatToPowerRatio, m_editCHPheatToPowerRatio);
	DDX_Control(pDX, IDC_EDIT_efficiency, m_editDHWefficiency);
	DDX_CBString(pDX, IDC_COMBO_WHtype, str_comboWHtype);
	DDX_CBString(pDX, IDC_COMBO_cylinder, str_comboCylinderWithingDwelling);
	DDX_CBString(pDX, IDC_COMBO_WHfuel, str_comboDHWfuel);
	DDX_CBString(pDX, IDC_COMBO_waterSepTimed, str_comboWaterSepTimed);
	DDX_CBString(pDX, IDC_COMBO_ManufactLossFact, str_comboManufactLossFactor);
	DDX_Text(pDX, IDC_EDIT_cylDeclaredFactor, str_editCylinderDecFactor);
	DDX_Text(pDX, IDC_EDIT_cylVolume, str_editCylinderVolume);
	DDX_CBString(pDX, IDC_COMBO_insType, str_comboInsulationType);
	DDX_Text(pDX, IDC_EDIT_InsThickness, str_editCylInsulationThickness);
	DDX_CBString(pDX, IDC_COMBO_thermostat, str_comboCylThermostat);
	DDX_CBString(pDX, IDC_COMBO_inHeatedSpace, str_comboCylInHtdSpace);
	DDX_CBString(pDX, IDC_COMBO_primPipeworkIns, str_comboCylPrimaryPipeworkIns);
	DDX_CBString(pDX, IDC_COMBO_pumpedPrimSystem, str_comboCylPumpedPrimarySys);
	DDX_CBString(pDX, IDC_COMBO_inSingleUnit, str_comboTSinSingleUnit);
	DDX_CBString(pDX, IDC_COMBO_primPipeLT1_5m, str_comboTSPrimaryPipework);
	DDX_CBString(pDX, IDC_COMBO_storeInAiringCpbd, str_comboTSInAiringCpbd);
	DDX_CBString(pDX, IDC_COMB_keepHotUsesElec, str_comboCombiHotUsesElec);
	DDX_Text(pDX, IDC_EDIT_keepHotWaterRating, str_editTSpowerRating);
	DDX_CBString(pDX, IDC_COMBO_DHWprovidedFrom, str_comboDHWprovidedFrom);
	DDX_Text(pDX, IDC_EDIT_CHPheatToPowerRatio, str_editCHPheatToPowerRatio);
	DDX_CBString(pDX, IDC_COMBO28, str_comboDHWsystem);
	DDX_Text(pDX, IDC_EDIT_efficiency, str_editDHWefficiency);
	DDX_CBString(pDX, IDC_COMBO_DHWusesImmer, str_comboHPusesImmer);
	DDX_CBString(pDX, IDC_COMBO_summerImmer, str_comboSummerImmer);
	DDX_Control(pDX, IDC_COMBO1, m_comboCombiHotYN);
	DDX_CBString(pDX, IDC_COMBO1, str_comboCombiHotYN);
	DDX_Control(pDX, IDC_COMBO4, m_comboDHWCom);
	DDX_CBString(pDX, IDC_COMBO4, str_comboDHWCom);
	DDX_Control(pDX, IDC_STATIC_9, m_labelFGHRS);
	DDX_Control(pDX, IDC_COMBO5, m_comboFGHRsys);
	DDX_CBString(pDX, IDC_COMBO5, str_comboFGHRsys);
	DDX_Control(pDX, IDC_CHECK1, m_btnWaterHtFromMain);
	DDX_Control(pDX, IDC_EDIT_cylVolume2, m_editWTEff);
	DDX_Text(pDX, IDC_EDIT_cylVolume2, str_editWTEff);
}

BEGIN_MESSAGE_MAP(CDlg_WaterHeating, CDialog)
	ON_CBN_SELCHANGE(IDC_COMBO_WHtype, OnCbnSelchangeComboWhtype)
	ON_CBN_SELCHANGE(IDC_COMBO_cylinder, OnCbnSelchangeCombocylinder)
	ON_CBN_SELCHANGE(IDC_COMBO_WHfuel, OnCbnSelchangeComboWhfuel)
	ON_CBN_SELCHANGE(IDC_COMBO_waterSepTimed, OnCbnSelchangeCombowaterseptimed)
	ON_CBN_SELCHANGE(IDC_COMBO_rangeCookerType, OnCbnSelchangeComborangecookertype)
	ON_CBN_SELCHANGE(IDC_COMBO_ManufactLossFact, OnCbnSelchangeComboManufactlossfact)
	ON_EN_CHANGE(IDC_EDIT_cylDeclaredFactor, OnEnChangeEditcyldeclaredfactor)
	ON_EN_CHANGE(IDC_EDIT_cylVolume, OnEnChangeEditcylvolume)
	ON_CBN_SELCHANGE(IDC_COMBO_insType, OnCbnSelchangeComboinstype)
	ON_EN_CHANGE(IDC_EDIT_InsThickness, OnEnChangeEditInsthickness)
	ON_CBN_SELCHANGE(IDC_COMBO_thermostat, OnCbnSelchangeCombothermostat)
	ON_CBN_SELCHANGE(IDC_COMBO_inHeatedSpace, OnCbnSelchangeComboinheatedspace)
	ON_CBN_SELCHANGE(IDC_COMBO_primPipeworkIns, OnCbnSelchangeComboprimpipeworkins)
	ON_CBN_SELCHANGE(IDC_COMBO_pumpedPrimSystem, OnCbnSelchangeCombopumpedprimsystem)
	ON_CBN_SELCHANGE(IDC_COMBO_inSingleUnit, OnCbnSelchangeComboinsingleunit)
	ON_CBN_SELCHANGE(IDC_COMBO_primPipeLT1_5m, OnCbnSelchangeComboprimpipelt15m)
	ON_CBN_SELCHANGE(IDC_COMBO_storeInAiringCpbd, OnCbnSelchangeCombostoreinairingcpbd)
	ON_CBN_SELCHANGE(IDC_COMB_keepHotUsesElec, OnCbnSelchangeCombkeephotuseselec)
	ON_EN_CHANGE(IDC_EDIT_keepHotWaterRating, OnEnChangeEditkeephotwaterrating)
	ON_CBN_SELCHANGE(IDC_COMBO_DHWprovidedFrom, OnCbnSelchangeComboDhwprovidedfrom)
	ON_EN_CHANGE(IDC_EDIT_CHPheatToPowerRatio, OnEnChangeEditChpheattopowerratio)
	ON_CBN_SELCHANGE(IDC_COMBO28, OnCbnSelchangeCombo28)
	ON_EN_CHANGE(IDC_EDIT_efficiency, OnEnChangeEditefficiency)
	ON_CBN_SELCHANGE(IDC_COMBO_DHWusesImmer, OnCbnSelchangeComboDhwusesimmer)
	ON_CBN_SELCHANGE(IDC_COMBO_summerImmer, OnCbnSelchangeCombosummerimmer)
	ON_CBN_SELCHANGE(IDC_COMBO1, OnCbnSelchangeCombo1)
	ON_CBN_SELCHANGE(IDC_COMBO4, OnCbnSelchangeCombo4)
	ON_CBN_SELCHANGE(IDC_COMBO5, OnCbnSelchangeCombo5)
	ON_BN_CLICKED(IDC_CHECK1, OnBnClickedCheck1)
	ON_EN_CHANGE(IDC_EDIT_cylVolume2, OnEnChangeEditcylvolume2)
END_MESSAGE_MAP()

// CDlg_WaterHeating message handlers

BOOL CDlg_WaterHeating::OnInitDialog()
{
	CDialog::OnInitDialog();

	display_msg_only_once = true;

	//---------------------------------------------------
	// LABELS
	//---------------------------------------------------
	CFont *m_Font1 = new CFont;
	m_Font1->CreatePointFont(90, "Arial Bold");

	m_labelGeneral.SetFont(m_Font1); 
	m_labelGeneral.SetTextColor(BLUE); 

	m_labelCylinderDetails.SetFont(m_Font1); 
	m_labelCylinderDetails.SetTextColor(BLUE); 

	m_labelThermalStore.SetFont(m_Font1); 
	m_labelThermalStore.SetTextColor(BLUE); 

	m_labelCombiHot.SetFont(m_Font1); 
	m_labelCombiHot.SetTextColor(BLUE); 

	m_labelDHW.SetFont(m_Font1); 
	m_labelDHW.SetTextColor(BLUE); 

	m_labelHeatPump.SetFont(m_Font1); 
	m_labelHeatPump.SetTextColor(BLUE); 

	m_labelSummerImmer.SetFont(m_Font1); 
	m_labelSummerImmer.SetTextColor(BLUE); 

	m_labelFGHRS.SetFont(m_Font1); 
	m_labelFGHRS.SetTextColor(BLUE); 
	
	//---------------------------------------------------
	// DROP DOWN MENUS
	//---------------------------------------------------
	AddStringsToComboBoxesForWaterHeatingDlg();

	if(file_new_selected ==true)
	{
		SetAllValuesToDefault();		
	}

	DisplayValuesForWaterHeatingDlg();

	//----------------------------------------------------------------------
	// If heating from main is selected from overview tab proceed as follows
	//----------------------------------------------------------------------
	if(btnWaterHtFromMainState ==1) 
	{	 
		m_btnWaterHtFromMain.SetCheck(1);

		m_editWTEff.SetReadOnly(TRUE);

		//str_editWTEff.Format("%.0f",mainHtEffNominal);
		//WHtEff = mainHtEff;
		str_editWTEff.Format("%.0f",mainHtEffNominal); //@min
		WHtEff = mainHtEffNominal;

		m_comboDHWfuel.EnableWindow(FALSE);
		str_comboDHWfuel.Format("%s",mainFuel); 
		WHtFuel = mainFuel;

		// Disable check box and slider
		chkDHWEff = 0;		
	}
	else 
	{	 
		m_btnWaterHtFromMain.SetCheck(0);

		m_editWTEff.SetReadOnly(FALSE);
		m_comboDHWfuel.EnableWindow(TRUE);

		// Disable check box and slider
		chkDHWEff = 1;
	}

	// Manufacturer loss factor
	if(strcmp(WHtCylManufactLossFactor,"Known")==0)
	{
		m_editCylinderDecFactor.EnableWindow(TRUE);
	}
	else
	{
		m_editCylinderDecFactor.EnableWindow(FALSE);
	}

	if((strcmp(WHtype,"Storage combi boiler - primary store")==0) ||
		(strcmp(WHtype,"Storage combi boiler - secondary store")==0))
	{
		m_comboCombiHotYN.EnableWindow(TRUE);
	}
	else
	{
		m_comboCombiHotYN.EnableWindow(FALSE);
	}
		
	UpdateData(FALSE);
	
	return TRUE;
}

void CDlg_WaterHeating::AddStringsToComboBoxesForWaterHeatingDlg()
{
	m_comboWHtype.InsertString(0,"Cylinder - electric immersion");
	m_comboWHtype.InsertString(1,"Cylinder - indirect");
	m_comboWHtype.InsertString(2,"Storage combi boiler - primary store");
	m_comboWHtype.InsertString(3,"Storage combi boiler - secondary store");
	m_comboWHtype.InsertString(4,"Instantaneous combi with closecoupled external store");
	m_comboWHtype.InsertString(5,"Instantaneous at point of use");
	m_comboWHtype.InsertString(6,"Hot water only thermal store");
	m_comboWHtype.InsertString(7,"Integrated thermal store and gas-fired CPSU");
	m_comboWHtype.InsertString(8,"Electric CPSU: for winter operating temperature");
	m_comboWHtype.InsertString(9,"Plate heat exchanger in a community system");

	m_comboDHWCom.InsertString(0,"No");
	m_comboDHWCom.InsertString(1,"Yes");

	m_comboCylinderWithingDwelling.InsertString(0,"No");
	m_comboCylinderWithingDwelling.InsertString(1,"Yes");

	int nIndex = 0;
	unsigned int i = 0;
	m_comboDHWfuel.ResetContent();
	for(i = 0; i < SAPcostTable_New.size(); i++)
	{
		if ((nIndex=m_comboDHWfuel.FindStringExact(nIndex, SAPcostTable_New[i].fuelType)) != CB_ERR)
		{
			; // Do nothing
		}
		else
		{
			// Fill fuel drop down menu
			m_comboDHWfuel.AddString(SAPcostTable_New[i].fuelType);
		}
	}

	m_comboWaterSepTimed.InsertString(0,"No");
	m_comboWaterSepTimed.InsertString(1,"Yes");

	m_comboManufactLossFactor.InsertString(0,"Known");
	m_comboManufactLossFactor.InsertString(0,"Unknown");

	m_comboInsulationType.InsertString(0,"None");
	m_comboInsulationType.InsertString(1,"Loose jacket");
	m_comboInsulationType.InsertString(2,"Factory insulated");
	m_comboInsulationType.InsertString(3,"Spray foam");

	m_comboCylThermostat.InsertString(0,"No");
	m_comboCylThermostat.InsertString(1,"Yes");
	m_comboCylInHtdSpace.InsertString(0,"No");
	m_comboCylInHtdSpace.InsertString(1,"Yes");

	m_comboCylPrimaryPipeworkIns.InsertString(0,"No");
	m_comboCylPrimaryPipeworkIns.InsertString(1,"Yes");

	m_comboCylPumpedPrimarySys.InsertString(0,"No");
	m_comboCylPumpedPrimarySys.InsertString(1,"Yes");	

	m_comboTSinSingleUnit.InsertString(0,"No");
	m_comboTSinSingleUnit.InsertString(1,"Yes");	

	m_comboTSPrimaryPipework.InsertString(0,"No");
	m_comboTSPrimaryPipework.InsertString(1,"Yes");	

	m_comboTSInAiringCpbd.InsertString(0,"No");
	m_comboTSInAiringCpbd.InsertString(1,"Yes");	

	m_comboCombiHotUsesElec.InsertString(0,"No");
	m_comboCombiHotUsesElec.InsertString(1,"Yes");	

	m_comboCombiHotYN.InsertString(0,"No");
	m_comboCombiHotYN.InsertString(1,"Yes");	

	m_comboHPusesImmer.InsertString(0,"No");
	m_comboHPusesImmer.InsertString(1,"Yes");

	m_comboSummerImmer.InsertString(0,"No");
	m_comboSummerImmer.InsertString(1,"Yes");	
	m_comboFGHRsys.InsertString(0,"No");
	m_comboFGHRsys.InsertString(1,"Yes");
}

void CDlg_WaterHeating::DisplayValuesForWaterHeatingDlg()
{
    str_comboWHtype.Format("%s",WHtype);
	str_comboCylinderWithingDwelling.Format("%s",WHtCylinderWithinDwelling);
	str_comboDHWfuel.Format("%s",WHtFuel);
	str_comboWaterSepTimed.Format("%s",WHtWaterSepTimed);

	str_comboManufactLossFactor.Format("%s",WHtCylManufactLossFactor);
	str_editCylinderDecFactor.Format("%.0f",WHtCylDeclaredFactor);
	str_editCylinderVolume.Format("%.0f",WHtCylVolume);

	str_comboInsulationType.Format("%s",WHtCylInsType);
	str_editCylInsulationThickness.Format("%.0f",WHtCylInsThickness);

	str_comboCylThermostat.Format("%s",WHtCylThermostat);
	str_comboCylInHtdSpace.Format("%s",WHtCylInHeatedSpace);
	str_comboCylPrimaryPipeworkIns.Format("%s",WHtCylPrimaryPipeworkInsulated);
	str_comboCylPumpedPrimarySys.Format("%s",WHtCylPumpedPrimarySystem);

	str_editWTEff.Format("%.0f",WHtEff);

	str_comboTSinSingleUnit.Format("%s",WHtTSnCPSUinSingleUnit);
	str_comboTSPrimaryPipework.Format("%s",WHtTSnCPSUPrimaryPipeworkLT1_5m);
	str_comboTSInAiringCpbd.Format("%s",WHtTSnCPSUstoreInAirCupbrd);
	str_comboCombiHotYN.Format("%s",WHtCombiKeepHotYN);
	str_comboDHWCom.Format("%s",DHWfromCommunityScheme);
	str_comboHPusesImmer.Format("%s",WHtHeatPumpUsesImmer);
	str_comboSummerImmer.Format("%s",WHtUsesSummerImmer);

	UpdateData(FALSE);
}

void CDlg_WaterHeating::ReadInputsFromWaterHeatingDlg()
{
	UpdateData(TRUE);

	WHtype = str_comboWHtype;
	WHtCylinderWithinDwelling = str_comboCylinderWithingDwelling;
	WHtFuel = str_comboDHWfuel;
	WHtWaterSepTimed   = str_comboWaterSepTimed;

	WHtCylManufactLossFactor = str_comboManufactLossFactor;
	WHtCylDeclaredFactor     = atof(str_editCylinderDecFactor);
	WHtCylVolume             = atof(str_editCylinderVolume);

	WHtCylInsType = str_comboInsulationType;
	WHtCylInsThickness =  atof(str_editCylInsulationThickness);
	WHtCylThermostat    = str_comboCylThermostat;
	WHtCylInHeatedSpace = str_comboCylInHtdSpace;
	WHtCylPrimaryPipeworkInsulated = str_comboCylPrimaryPipeworkIns;
	WHtCylPumpedPrimarySystem      = str_comboCylPumpedPrimarySys;

	WHtEff = atof(str_editWTEff);

	WHtTSnCPSUinSingleUnit          = str_comboTSinSingleUnit;
	WHtTSnCPSUPrimaryPipeworkLT1_5m = str_comboTSPrimaryPipework;
	WHtTSnCPSUstoreInAirCupbrd      = str_comboTSInAiringCpbd; 

	if((strcmp(WHtype,"Storage combi boiler - primary store")==0) ||
		(strcmp(WHtype,"Storage combi boiler - secondary store")==0))
	{
		m_comboCombiHotYN.EnableWindow(TRUE);
	}
	else
	{
		m_comboCombiHotYN.EnableWindow(FALSE);
	}

	WHtCombiKeepHotYN = str_comboCombiHotYN;

	DHWfromCommunityScheme = str_comboDHWCom;

	WHtHeatPumpUsesImmer = str_comboHPusesImmer;
	WHtUsesSummerImmer   = str_comboSummerImmer;
}

void CDlg_WaterHeating::OnCbnSelchangeComboWhtype()
{
	ReadInputsFromWaterHeatingDlg();
}

void CDlg_WaterHeating::OnCbnSelchangeCombocylinder()
{
	ReadInputsFromWaterHeatingDlg();
}

void CDlg_WaterHeating::OnCbnSelchangeComboWhfuel()
{
	ReadInputsFromWaterHeatingDlg();
}

void CDlg_WaterHeating::OnCbnSelchangeCombowaterseptimed()
{
	ReadInputsFromWaterHeatingDlg();
}

void CDlg_WaterHeating::OnCbnSelchangeComborangecookertype()
{
	ReadInputsFromWaterHeatingDlg();
}

void CDlg_WaterHeating::OnCbnSelchangeComboManufactlossfact()
{
	ReadInputsFromWaterHeatingDlg();

	// Manufacturer loss factor
	if(strcmp(WHtCylManufactLossFactor, "Known")==0)
	{
		m_editCylinderDecFactor.EnableWindow(TRUE);
	}
	else
	{
		m_editCylinderDecFactor.EnableWindow(FALSE);
	}
}

void CDlg_WaterHeating::OnEnChangeEditcyldeclaredfactor()
{
	//------------------------------------------------------------------------------
	// Empty edit box if user types any character other than numeric characters or '.'
	UpdateData(TRUE);
	static TCHAR * lpszValidChars = _T(".-0123456789");
	// szText is the string we want to check for invalid chracters
	if (_tcsspnp(str_editCylinderDecFactor, lpszValidChars) != 0) 
	{
		str_editCylinderDecFactor = " ";
		UpdateData(FALSE);
		return;
	}
	ReadInputsFromWaterHeatingDlg();
					
	// Check limit
	isCheckRange_WHtCylDeclaredFactor= true;
}

void CDlg_WaterHeating::OnEnChangeEditcylvolume()
{
	//------------------------------------------------------------------------------
	// Empty edit box if user types any character other than numeric characters or '.'
	UpdateData(TRUE);
	static TCHAR * lpszValidChars = _T(".-0123456789");
	// szText is the string we want to check for invalid chracters
	if (_tcsspnp(str_editCylinderVolume, lpszValidChars) != 0) 
	{
		str_editCylinderVolume = " ";
		UpdateData(FALSE);
		return;
	}
	ReadInputsFromWaterHeatingDlg();
					
	// Check limit
	isCheckRange_WHtCylVolume= true;
}

void CDlg_WaterHeating::OnCbnSelchangeComboinstype()
{
	ReadInputsFromWaterHeatingDlg();
}

void CDlg_WaterHeating::OnEnChangeEditInsthickness()
{
	//------------------------------------------------------------------------------
	// Empty edit box if user types any character other than numeric characters or '.'
	UpdateData(TRUE);
	static TCHAR * lpszValidChars = _T(".-0123456789");
	// szText is the string we want to check for invalid chracters
	if (_tcsspnp(str_editCylInsulationThickness, lpszValidChars) != 0) 
	{
		str_editCylInsulationThickness = " ";
		UpdateData(FALSE);
		return;
	}
	ReadInputsFromWaterHeatingDlg();
					
	// Check limit
	isCheckRange_WHtCylInsThickness= true;
}

void CDlg_WaterHeating::OnCbnSelchangeCombothermostat()
{
	ReadInputsFromWaterHeatingDlg();
}

void CDlg_WaterHeating::OnCbnSelchangeComboinheatedspace()
{
	ReadInputsFromWaterHeatingDlg();
}

void CDlg_WaterHeating::OnCbnSelchangeComboprimpipeworkins()
{
	ReadInputsFromWaterHeatingDlg();
}

void CDlg_WaterHeating::OnCbnSelchangeCombopumpedprimsystem()
{
	ReadInputsFromWaterHeatingDlg();
}

void CDlg_WaterHeating::OnCbnSelchangeComboinsingleunit()
{
	ReadInputsFromWaterHeatingDlg();
}

void CDlg_WaterHeating::OnCbnSelchangeComboprimpipelt15m()
{
	ReadInputsFromWaterHeatingDlg();
}

void CDlg_WaterHeating::OnCbnSelchangeCombostoreinairingcpbd()
{
	ReadInputsFromWaterHeatingDlg();
}

void CDlg_WaterHeating::OnCbnSelchangeCombkeephotuseselec()
{
	ReadInputsFromWaterHeatingDlg();
}

void CDlg_WaterHeating::OnEnChangeEditkeephotwaterrating()
{
	//------------------------------------------------------------------------------
	// Empty edit box if user types any character other than numeric characters or '.'
	UpdateData(TRUE);
	static TCHAR * lpszValidChars = _T(".-0123456789");
	// szText is the string we want to check for invalid chracters
	if (_tcsspnp(str_editTSpowerRating, lpszValidChars) != 0) 
	{
		str_editTSpowerRating = " ";
		UpdateData(FALSE);
		return;
	}
	ReadInputsFromWaterHeatingDlg();
}

void CDlg_WaterHeating::OnCbnSelchangeComboDhwprovidedfrom()
{
	ReadInputsFromWaterHeatingDlg();
}

void CDlg_WaterHeating::OnEnChangeEditChpheattopowerratio()
{
	//------------------------------------------------------------------------------
	// Empty edit box if user types any character other than numeric characters or '.'
	UpdateData(TRUE);
	static TCHAR * lpszValidChars = _T(".-0123456789");
	// szText is the string we want to check for invalid chracters
	if (_tcsspnp(str_editCHPheatToPowerRatio, lpszValidChars) != 0) 
	{
		str_editCHPheatToPowerRatio = " ";
		UpdateData(FALSE);
		return;
	}
	ReadInputsFromWaterHeatingDlg();
}

void CDlg_WaterHeating::OnCbnSelchangeCombo28()
{
	ReadInputsFromWaterHeatingDlg();
}

void CDlg_WaterHeating::OnEnChangeEditefficiency()
{
	//------------------------------------------------------------------------------
	// Empty edit box if user types any character other than numeric characters or '.'
	UpdateData(TRUE);
	static TCHAR * lpszValidChars = _T(".-0123456789");
	// szText is the string we want to check for invalid chracters
	if (_tcsspnp(str_editDHWefficiency, lpszValidChars) != 0) 
	{
		str_editDHWefficiency = " ";
		UpdateData(FALSE);
		return;
	}
	ReadInputsFromWaterHeatingDlg();
}

void CDlg_WaterHeating::OnCbnSelchangeComboDhwusesimmer()
{
	ReadInputsFromWaterHeatingDlg();
}

void CDlg_WaterHeating::OnCbnSelchangeCombosummerimmer()
{
	ReadInputsFromWaterHeatingDlg();
}

void CDlg_WaterHeating::OnCbnSelchangeCombo1()
{
	ReadInputsFromWaterHeatingDlg();
}

void CDlg_WaterHeating::OnCbnSelchangeCombo4()
{
	ReadInputsFromWaterHeatingDlg();
}

void CDlg_WaterHeating::OnCbnSelchangeCombo5()
{
	ReadInputsFromWaterHeatingDlg();
}

void CDlg_WaterHeating::OnBnClickedCheck1()
{
	//----------------------------------------------------------------------------
	// If mian heating type is combi and boiler type is combi or condensing combi, 
	// water heating will always be selected from main
	if((mainHtType == "Boiler") &&
	((boilerType == "Combi") || (boilerType == "Condensing combi")))
	{	
		btnWaterHtFromMainState = 1;
		m_btnWaterHtFromMain.SetCheck(1);
		MessageBox("Action not allowed. Main heating type is Boiler and boiler type is Combi or Condensing boiler.\nChange this in order to uncheck this box", "Help", MB_OK);
	}

	if(m_btnWaterHtFromMain.GetCheck() == 1) 
	{	 
		btnWaterHtFromMainState = 1;

		m_editWTEff.SetReadOnly(TRUE);
		
		//str_editWTEff.Format("%.0f", mainHtEff);
		//WHtEff = mainHtEff;

		str_editWTEff.Format("%.0f",mainHtEffNominal); //@min
		WHtEff = mainHtEffNominal;

		m_comboDHWfuel.EnableWindow(FALSE);
		str_comboDHWfuel.Format("%s",mainFuel); 
		WHtFuel = mainFuel;
	}
	else 
	{	 
		btnWaterHtFromMainState = 0;
		m_editWTEff.SetReadOnly(FALSE);
		m_comboDHWfuel.EnableWindow(TRUE);
	}	
	UpdateData(FALSE);
}

void CDlg_WaterHeating::OnEnChangeEditcylvolume2()
{
	if(display_msg_only_once == true)
	{
		display_msg_only_once = false;
		MessageBox("Input value as per database record, table 4a or equation 8 in section 9.2.1\nThis should be adjusted where appropriate by the amount shoun in DHW1 adjustment column of Table 4c\nFor gas and oil boilers use summer effeciency, see Section 9.2.1", "Help", MB_OK);
	}
	ReadInputsFromWaterHeatingDlg();
					
	// Check limit
	isCheckRange_WHtEff= true;
}

BOOL CDlg_WaterHeating::PreTranslateMessage(MSG* pMsg) 
{
	// TODO: Add your specialized code here and/or call the base class
	if(pMsg->message==WM_KEYDOWN)
	{
		if(pMsg->wParam==VK_RETURN || pMsg->wParam==VK_ESCAPE)
			pMsg->wParam=NULL ;
	} 

	return CDialog::PreTranslateMessage(pMsg);
}