// Dlg_MainHeating.cpp : implementation file
//

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

// CDlg_MainHeating dialog

IMPLEMENT_DYNAMIC(CDlg_MainHeating, CDialog)
CDlg_MainHeating::CDlg_MainHeating(CWnd* pParent /*=NULL*/)
	: CDialog(CDlg_MainHeating::IDD, pParent)
	, str_comboElecTariff(_T(""))
	, str_comboMHType(_T(""))
	, str_comboEffFrom(_T(""))
	, str_comboBoilerType(_T(""))
	, str_comboFuel(_T(""))
	, str_comboSecBiolerFuel(_T(""))
	, str_comboFanFlue(_T(""))
	, str_comboSystem(_T(""))
	, str_comboControls(_T(""))
	, str_comboEmitter(_T(""))
	, str_comboInterlock(_T(""))
	, str_comboCompensator(_T(""))
	, str_comboPump(_T(""))
	, str_editManufactDesc(_T(""))
	, str_comboTestMethod(_T(""))
	, str_editEff(_T(""))
	, str_editlBoilerRef(_T(""))
	, str_editlBoilerModel(_T(""))
	, str_editFractionSupplied(_T(""))
{
}

CDlg_MainHeating::~CDlg_MainHeating()
{
}

void CDlg_MainHeating::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	DDX_Control(pDX, IDC_STATIC_MH, m_labelMainHeating);
	DDX_Control(pDX, IDC_COMBO_ElecTariff, m_comboElecTariff);
	DDX_Control(pDX, IDC_COMBO_MHtype, m_comboMHType);
	DDX_Control(pDX, IDC_COMBO_MHeffFrom, m_comboEffFrom);
	DDX_Control(pDX, IDC_COMBO_MHboilerType, m_comboBoilerType);
	DDX_Control(pDX, IDC_COMBO_MHfuel, m_comboFuel);
	DDX_Control(pDX, IDC_COMBO_SecBoilerFuel, m_comboSecBiolerFuel);
	DDX_Control(pDX, IDC_COMBO_FanFlue, m_comboFanFlue);
	DDX_Control(pDX, IDC_COMBO_system, m_comboSystem);
	DDX_Control(pDX, IDC_COMBO_controls, m_comboControls);
	DDX_Control(pDX, IDC_COMBO_emitter, m_comboEmitter);
	DDX_Control(pDX, IDC_COMBO_interlock, m_comboInterlock);
	DDX_Control(pDX, IDC_COMBO_compensator, m_comboCompensator);
	DDX_Control(pDX, IDC_COMBO_pump, m_comboPump);
	DDX_Control(pDX, IDC_COMBO_testMethod, m_comboTestMethod);
	DDX_Control(pDX, IDC_EDIT_manufactDescription, m_editManufactDesc);
	DDX_Control(pDX, IDC_EDIT_eff, m_editEff);
	DDX_CBString(pDX, IDC_COMBO_ElecTariff, str_comboElecTariff);
	DDX_CBString(pDX, IDC_COMBO_MHtype, str_comboMHType);
	DDX_CBString(pDX, IDC_COMBO_MHeffFrom, str_comboEffFrom);
	DDX_CBString(pDX, IDC_COMBO_MHboilerType, str_comboBoilerType);
	DDX_CBString(pDX, IDC_COMBO_MHfuel, str_comboFuel);
	DDX_CBString(pDX, IDC_COMBO_SecBoilerFuel, str_comboSecBiolerFuel);
	DDX_CBString(pDX, IDC_COMBO_FanFlue, str_comboFanFlue);
	DDX_CBString(pDX, IDC_COMBO_system, str_comboSystem);
	DDX_CBString(pDX, IDC_COMBO_controls, str_comboControls);
	DDX_CBString(pDX, IDC_COMBO_emitter, str_comboEmitter);
	DDX_CBString(pDX, IDC_COMBO_interlock, str_comboInterlock);
	DDX_CBString(pDX, IDC_COMBO_compensator, str_comboCompensator);
	DDX_CBString(pDX, IDC_COMBO_pump, str_comboPump);
	DDX_Text(pDX, IDC_EDIT_manufactDescription, str_editManufactDesc);
	DDX_CBString(pDX, IDC_COMBO_testMethod, str_comboTestMethod);
	DDX_Text(pDX, IDC_EDIT_eff, str_editEff);
	DDX_Control(pDX, IDC_STATIC_boilerRef, m_labelBoilerRef);
	DDX_Control(pDX, IDC_STATIC_boilerModel, m_labelBoilerModel);
	DDX_Control(pDX, IDC_EDIT_boilerRef, m_editlBoilerRef);
	DDX_Control(pDX, IDC_EDIT_boilerModel, m_editlBoilerModel);
	DDX_Text(pDX, IDC_EDIT_boilerRef, str_editlBoilerRef);
	DDX_Text(pDX, IDC_EDIT_boilerModel, str_editlBoilerModel);
	DDX_Control(pDX, IDC_STATIC_1, m_labelBoiler);
	DDX_Control(pDX, IDC_STATIC_2, m_labelEmitter);
	DDX_Control(pDX, IDC_STATIC_3, m_labelPump);
	DDX_Control(pDX, IDC_STATIC_4, m_labelSystem);
	DDX_Control(pDX, IDC_EDIT_eff2, m_editFractionSupplied);
	DDX_Text(pDX, IDC_EDIT_eff2, str_editFractionSupplied);
	DDX_Control(pDX, IDC_STATIC_interlock, m_labelInterlock);
	DDX_Control(pDX, IDC_STATIC_compensator, m_labelCompensator);
	DDX_Control(pDX, IDC_STATIC_MH2, m_labelNote);
	DDX_Control(pDX, IDC_STATIC_tariff, m_labelTariff);
}

BEGIN_MESSAGE_MAP(CDlg_MainHeating, CDialog)
	ON_CBN_SELCHANGE(IDC_COMBO_controls, OnCbnSelchangeCombocontrols)
	ON_CBN_SELCHANGE(IDC_COMBO_MHtype, OnCbnSelchangeComboMhtype)
	ON_CBN_SELCHANGE(IDC_COMBO_ElecTariff, OnCbnSelchangeComboElectariff)
	ON_CBN_SELCHANGE(IDC_COMBO_MHeffFrom, OnCbnSelchangeComboMhefffrom)
	ON_CBN_SELCHANGE(IDC_COMBO_MHboilerType, OnCbnSelchangeComboMhboilertype)
	ON_CBN_SELCHANGE(IDC_COMBO_MHfuel, OnCbnSelchangeComboMhfuel)
	ON_CBN_SELCHANGE(IDC_COMBO_SecBoilerFuel, OnCbnSelchangeComboSecboilerfuel)
	ON_CBN_SELCHANGE(IDC_COMBO_FanFlue, OnCbnSelchangeComboFanflue)
	ON_CBN_SELCHANGE(IDC_COMBO_system, OnCbnSelchangeCombosystem)
	ON_CBN_SELCHANGE(IDC_COMBO_emitter, OnCbnSelchangeComboemitter)
	ON_CBN_SELCHANGE(IDC_COMBO_interlock, OnCbnSelchangeCombointerlock)
	ON_CBN_SELCHANGE(IDC_COMBO_compensator, OnCbnSelchangeCombocompensator)
	ON_CBN_SELCHANGE(IDC_COMBO_pump, OnCbnSelchangeCombopump)
	ON_EN_CHANGE(IDC_EDIT_manufactDescription, OnEnChangeEditmanufactdescription)
	ON_CBN_SELCHANGE(IDC_COMBO_testMethod, OnCbnSelchangeCombotestmethod)
	ON_EN_CHANGE(IDC_EDIT_eff, OnEnChangeEditeff)
	ON_EN_CHANGE(IDC_EDIT_boilerRef, OnEnChangeEditboilerref)
	ON_EN_CHANGE(IDC_EDIT_boilerModel, OnEnChangeEditboilermodel)
	ON_EN_CHANGE(IDC_EDIT_eff2, OnEnChangeEditeff2)
END_MESSAGE_MAP()

// CDlg_MainHeating message handlers 

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

	//---------------------------------------------------
	// LABELS
	//---------------------------------------------------
	CFont *m_Font1 = new CFont;
	m_Font1->CreatePointFont(90, "Arial Bold");	
	m_labelMainHeating.SetFont(m_Font1); 
	m_labelMainHeating.SetTextColor(BLUE); 
	m_labelNote.SetTextColor(RED); 
	
	//---------------------------------------------------
	// DROP DOWN MENUS
	//---------------------------------------------------
	AddStringsToComboBoxes();

	//---------------------------------------------------
	// If user selects File > New display default values
	//---------------------------------------------------
	if(file_new_selected ==true)
	{
		SetAllValuesToDefault();		
	}

	DisplayValuesForMainHeatinDlg();

	//---------------------------------------
	// Show boiler type only if
	//---------------------------------------
	if(mainHtType == "Boiler") 
	{
		m_labelBoiler.ShowWindow(TRUE);
        m_comboBoilerType.ShowWindow(TRUE);
	}
	else
	{
		m_labelBoiler.ShowWindow(FALSE);
        m_comboBoilerType.ShowWindow(FALSE);
	}

	//---------------------------------------
	// Show compensator only if
	//---------------------------------------
	if (((mainHtType == "Boiler")  && ( boilerType == "Condensing")) || 
	  (mainHtType == "Heat pump - wet system" ) || (mainHtType == "Heat pump - warm air" ))
	{
		m_labelCompensator.EnableWindow(TRUE);
        m_comboCompensator.EnableWindow(TRUE);
	}
	else
	{
		m_labelCompensator.EnableWindow(FALSE);
        m_comboCompensator.EnableWindow(FALSE);
	}
	
	//---------------------------------------
	// Show interlock only if
	//---------------------------------------
	if(mainHtType == "Boiler") 
	{
		m_labelInterlock.EnableWindow(TRUE);
        m_comboInterlock.EnableWindow(TRUE);
	}
	else
	{
		m_labelInterlock.EnableWindow(FALSE);
        m_comboInterlock.EnableWindow(FALSE);
	}

	//---------------------------------------
	// Show emitter type only if
	//---------------------------------------
	if((mainHtType == "Boiler") ||
		(mainHtType  == "Community heating")||
		(mainHtType  == "Heat pump - wet system"))
	{
		m_labelEmitter.EnableWindow(TRUE);
        m_comboEmitter.EnableWindow(TRUE);
	}
	else
	{
		m_labelEmitter.EnableWindow(FALSE);
        m_comboEmitter.EnableWindow(FALSE);
	}

	//---------------------------------------
	// Show pump in heated space only if
	//---------------------------------------
	if((mainHtType == "Boiler") ||
		(mainHtType  == "Heat pump - wet system"))
	{
		m_labelPump.EnableWindow(TRUE);
        m_comboPump.EnableWindow(TRUE);
	}
	else
	{
		m_labelPump.EnableWindow(FALSE);
        m_comboPump.EnableWindow(FALSE);
	}

	//---------------------------------------
	if(mainFuel == "Electricity")
	{
		m_comboSystem.EnableWindow(TRUE);
		m_labelSystem.EnableWindow(TRUE);
	}
	else
	{
		m_comboSystem.EnableWindow(FALSE);
		m_labelSystem.EnableWindow(FALSE);
	}

	//---------------------------------------
	// Select tariff type based on fuel
	// Fuel is standard for all tariffs except electricity
	if(mainFuel == "Electricity")
	{
		m_comboElecTariff.ResetContent();
		m_comboElecTariff.InsertString(0,"Standard");
		m_comboElecTariff.InsertString(1,"7 hour");
		m_comboElecTariff.InsertString(2,"10 hour");
		m_comboElecTariff.InsertString(3,"24 hour");
		m_comboElecTariff.SelectString(0,electricityTarrif);

		m_labelTariff.ShowWindow(TRUE);
		m_comboElecTariff.ShowWindow(TRUE);
	}
	else
	{
		m_comboElecTariff.ResetContent();
		m_comboElecTariff.InsertString(0,"Standard");
		m_comboElecTariff.SelectString(0,"Standard");

		m_labelTariff.ShowWindow(FALSE);
		m_comboElecTariff.ShowWindow(FALSE);
	}
	
	return TRUE;
}

void CDlg_MainHeating::ApplyEffeciencyAdjustmentsToMainHeatingDlg()
{
	//-----------------------------------------------------------------------
	// 1.Gas or oil boiler systems with radiators or underfloor heating
	// SAP2009 Table 4c
	//-----------------------------------------------------------------------

	// (1) Efficiency adjustment due to lower temperature of distribution system
	if(strcmp(mainFuel,"Mains gas")==0)
	{
		if((strcmp(boilerType,"Condensing")==0) && (strcmp(mainHtCompensator,"Load compensator")==0))
		{
			spaceHeatingEffAdj = 0;
		}
		else if((strcmp(boilerType,"Condensing")==0) && (strcmp(mainHtCompensator,"Enhanced load compensator")==0))
		{
			spaceHeatingEffAdj = 3;
		}
		else if((strcmp(boilerType,"Condensing")==0) && (strcmp(mainHtCompensator,"Weather compensator")==0))
		{
			spaceHeatingEffAdj = 3;
		}
		else if((strcmp(boilerType,"Condensing")==0) && ((strcmp(mainHtEmitter,"Underfloor (timber)")==0) || (strcmp(mainHtEmitter,"Underfloor (concrete)")==0) || (strcmp(mainHtEmitter,"Underfloor (screed)")==0)))
		{
			spaceHeatingEffAdj = 3;
		}
		else
		{
			spaceHeatingEffAdj = 0;
		}      
	}

	if((strcmp(mainFuel,"Oil")==0) ||(strcmp(mainFuel, "LPG")==0) )
	{
		;
	}
}
void CDlg_MainHeating::DisplayValuesForMainHeatinDlg()
{	
	str_comboElecTariff.Format("%s", electricityTarrif);
	str_comboMHType.Format("%s", mainHtType);
	str_comboEffFrom.Format("%s", mainHtEffFrom);
	str_comboBoilerType.Format("%s", boilerType);
	str_editlBoilerRef.Format("%s", boilerRef);
	str_editlBoilerModel.Format("%s", boilerModel);
	str_comboFuel.Format("%s", mainFuel);
	str_comboSecBiolerFuel.Format("%s", isSecBoilerFuelPresent);
	str_comboFanFlue.Format("%s", isFanFluePresent);
	str_comboSystem.Format("%s", mainHtSystem);
	str_comboControls.Format("%s", mainHtControls);
	str_comboEmitter.Format("%s", mainHtEmitter);
	str_comboInterlock.Format("%s", isIterlockPresent);
	str_comboCompensator.Format("%s", mainHtCompensator);
	str_comboPump.Format("%s", isPumpInHeatedSpace);
	str_editManufactDesc.Format("%s", mainHtManufacturerDesc);
	str_comboTestMethod.Format("%s", mainHtTestMethod);
	//str_editEff.Format("%.2f", mainHtEff);
	str_editEff.Format("%.2f", mainHtEffNominal); //@min

	str_editFractionSupplied.Format("%.2f",mainHtFractionSupplied);

	//----------------------------------------------------------------------------
	// 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;
	}
	UpdateData(FALSE);
}

void CDlg_MainHeating::ReadBoilerEffFromVectors()
{
	unsigned int i  = 0;

	for( i=0; i < SAPboilers_db.size(); i++)
	{
		if ( (strcmp(boilerRef, SAPboilers_db[i].boilerRef) ==  0) && (strcmp(boilerModel, SAPboilers_db[i].boilerModel) ==  0))
		{
			// Fill Model name drop down menu
			//mainHtEff = SAPboilers_db[i].effeciency;
			mainHtEffNominal = SAPboilers_db[i].effeciency;  //@min
		} 
	}	

	str_editEff.Format("%.2f", mainHtEffNominal); //@min
	UpdateData(FALSE);
}

void CDlg_MainHeating::ReadInputsFromMainHeatingDlg()
{
	UpdateData(TRUE);

	electricityTarrif = str_comboElecTariff;
	mainHtType    = str_comboMHType;
	mainHtEffFrom = str_comboEffFrom;
	boilerRef     = str_editlBoilerRef;
	boilerModel   = str_editlBoilerModel;
	boilerType    = str_comboBoilerType;
	mainFuel      = str_comboFuel;

	isSecBoilerFuelPresent = str_comboSecBiolerFuel;
	isFanFluePresent  = str_comboFanFlue;
	mainHtSystem      = str_comboSystem;
	mainHtControls    = str_comboControls;
	mainHtEmitter     = str_comboEmitter;
	isIterlockPresent = str_comboInterlock;
	mainHtCompensator = str_comboCompensator; 

	isPumpInHeatedSpace = str_comboPump;

	mainHtManufacturerDesc = str_editManufactDesc;
	mainHtTestMethod       = str_comboTestMethod;
	//mainHtEff              = atof(str_editEff);
	mainHtEffNominal              = atof(str_editEff);  //@min
	
	
	mainHtFractionSupplied = atof(str_editFractionSupplied);

	if(mainHtType == "Boiler") 
	{
		m_labelBoiler.ShowWindow(TRUE);
        m_comboBoilerType.ShowWindow(TRUE);
	}
	else
	{
		m_labelBoiler.ShowWindow(FALSE);
        m_comboBoilerType.ShowWindow(FALSE);
	}

	//---------------------------------------
	// Show compensator only if
	//---------------------------------------
	if (((mainHtType == "Boiler")  && ( boilerType == "Condensing")) || 
	  (mainHtType == "Heat pump - wet system" ) || (mainHtType == "Heat pump - warm air" ))
	{
		m_labelCompensator.EnableWindow(TRUE);
        m_comboCompensator.EnableWindow(TRUE);
	}
	else
	{
		m_labelCompensator.EnableWindow(FALSE);
        m_comboCompensator.EnableWindow(FALSE);
	}
	//---------------------------------------
	// Show interlock only if
	//---------------------------------------
	if(mainHtType == "Boiler") 
	{
		m_labelInterlock.EnableWindow(TRUE);
        m_comboInterlock.EnableWindow(TRUE);
	}
	else
	{
		m_labelInterlock.EnableWindow(FALSE);
        m_comboInterlock.EnableWindow(FALSE);
	}

	//---------------------------------------
	// Show emitter type only if
	//---------------------------------------
	if((mainHtType == "Boiler") ||
		(mainHtType  == "Community heating")||
		(mainHtType  == "Heat pump - wet system"))
	{
		m_labelEmitter.EnableWindow(TRUE);
        m_comboEmitter.EnableWindow(TRUE);
	}
	else
	{
		m_labelEmitter.EnableWindow(FALSE);
        m_comboEmitter.EnableWindow(FALSE);
	}

	//---------------------------------------
	// Show pump in heated space only if
	//---------------------------------------
	if((mainHtType == "Boiler") ||
		(mainHtType  == "Heat pump - wet system"))
	{
		m_labelPump.EnableWindow(TRUE);
        m_comboPump.EnableWindow(TRUE);
	}
	else
	{
		m_labelPump.EnableWindow(FALSE);
        m_comboPump.EnableWindow(FALSE);
	}
	
	ReadBoilerEffFromVectors();

	//----------------------------------------------------------------------------
	// 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;
	}
}

void CDlg_MainHeating::AddStringsToComboBoxes()
{
	unsigned int i = 0;

	m_comboElecTariff.InsertString(0,"Standard");
	m_comboElecTariff.InsertString(1,"7 hour");
	m_comboElecTariff.InsertString(2,"10 hour");
	m_comboElecTariff.InsertString(3,"24 hour");

	m_comboMHType.InsertString(0,"Boiler");
	m_comboMHType.InsertString(1,"Community heating");
	m_comboMHType.InsertString(2,"Storage heaters");	
	m_comboMHType.InsertString(3,"Warm air");
	m_comboMHType.InsertString(4,"Heat pump - wet system");
	m_comboMHType.InsertString(5,"Heat pump - warm air");
	m_comboMHType.InsertString(6,"Room heaters");	
	m_comboMHType.InsertString(7,"Other systems");	

	m_comboEffFrom.InsertString(0,"Manufacturer declaration");

	m_comboBoilerType.InsertString(0,"Standard");
	m_comboBoilerType.InsertString(1,"Combi");
	m_comboBoilerType.InsertString(2,"Condensing");
	m_comboBoilerType.InsertString(3,"Condensing combi");
	m_comboBoilerType.InsertString(4,"Back boiler");
	m_comboBoilerType.InsertString(5,"CPSU");
	m_comboBoilerType.InsertString(6,"Range cooker");

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

	// data ????
	m_comboSecBiolerFuel.InsertString(0,"Yes");
	m_comboSecBiolerFuel.InsertString(1,"No");

	// data ????
	m_comboFanFlue.InsertString(0,"Yes");
	m_comboFanFlue.InsertString(1,"No");

	// SYSTEM
	// Boiler system
	m_comboSystem.InsertString(0,"Direct acting");
	m_comboSystem.InsertString(1,"Dry core storage boiler in heated space");
	m_comboSystem.InsertString(2,"Dry core storage boiler in unheated space");
	m_comboSystem.InsertString(3,"Water storage boiler in heated space");
	m_comboSystem.InsertString(4,"Water storage boiler in unheated space");
	m_comboSystem.InsertString(5,"No");

	// Boiler controls
	m_comboControls.InsertString(0,"No time or thermostatic control of room temperature");
	m_comboControls.InsertString(1,"Programmer - no thermostat");
	m_comboControls.InsertString(2,"Room thermostat only");
	m_comboControls.InsertString(3,"Programmer and room thermostat");
	m_comboControls.InsertString(4,"Programmer and atleast two room thermostats");
	m_comboControls.InsertString(5,"Programmer - room thermostat and TRVs");
	m_comboControls.InsertString(6,"Programmer - TRVs and bypass");
	m_comboControls.InsertString(7,"Programmer - TRVs and flow switch");
	m_comboControls.InsertString(8,"Programmer - TRVs and boiler energy manager");
	m_comboControls.InsertString(9,"Time and temperature zone control");
	m_comboControls.InsertString(10,"Delayed start thermostat");
	m_comboControls.InsertString(11,"Programmer and delayed start thermostat");
	m_comboControls.InsertString(12,"Programmer and atleast 2 room thermostat including a delayed start thermostat");
	m_comboControls.InsertString(13,"Programmer - delayed start thermostat and TRVs");
	
	m_comboEmitter.InsertString(0,"Radiators");
	m_comboEmitter.InsertString(1,"Underfloor (timber)");
	m_comboEmitter.InsertString(2,"Underfloor (concrete)");
	m_comboEmitter.InsertString(3,"Underfloor (timber)+radiators");
	m_comboEmitter.InsertString(4,"Underfloor (concrete)+radiators");	
	m_comboEmitter.InsertString(5,"Underfloor (screed)");
	m_comboEmitter.InsertString(6,"Underfloor (screed)+radiators");

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

	m_comboCompensator.InsertString(0,"None");
	m_comboCompensator.InsertString(1,"Enhanced load compensator");
	m_comboCompensator.InsertString(2,"Weather compensator");

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

	// data ????
	m_comboTestMethod.InsertString(0,"method 1");
	m_comboTestMethod.InsertString(1,"method 2");

}

void CDlg_MainHeating::OnCbnSelchangeCombocontrols()
{
	ReadInputsFromMainHeatingDlg();
}

void CDlg_MainHeating::OnCbnSelchangeComboMhtype()
{
	ReadInputsFromMainHeatingDlg();

	m_comboControls.ResetContent();

	// Default value
	m_comboControls.InsertString(0,"Uknown");

	if(str_comboMHType == "Boiler")
	{
		// Boiler controls		
		m_comboControls.InsertString(0,"No time or thermostatic control of room temperature");
		m_comboControls.InsertString(1,"Programmer - no thermostat");
		m_comboControls.InsertString(2,"Room thermostat only");
		m_comboControls.InsertString(3,"Programmer and room thermostat");
		m_comboControls.InsertString(4,"Programmer and atleast two room thermostats");
		m_comboControls.InsertString(5,"Programmer - room thermostat and TRVs");
		m_comboControls.InsertString(6,"Programmer - TRVs and bypass");
		m_comboControls.InsertString(7,"Programmer - TRVs and flow switch");
		m_comboControls.InsertString(8,"Programmer - TRVs and boiler energy manager");
		m_comboControls.InsertString(9,"Time and temperature zone control");
		m_comboControls.InsertString(10,"Delayed start thermostat");
		m_comboControls.InsertString(11,"Programmer and delayed start thermostat");
		m_comboControls.InsertString(12,"Programmer and atleast 2 room thermostat including a delayed start thermostat");
		m_comboControls.InsertString(13,"Programmer - delayed start thermostat and TRVs");	
		m_comboControls.InsertString(14,"Uknown");
	}
	if(str_comboMHType == "Community heating")
	{
		// Community heating controls
		m_comboControls.InsertString(0,"Flat rate charging - no thermostatic control of room temperature");
		m_comboControls.InsertString(1,"Flat rate charging - programmer and no room thermostat");
		m_comboControls.InsertString(2,"Flat rate charging - room thermostat only");
		m_comboControls.InsertString(3,"Flat rate charging - programmer and room thermostat");
		m_comboControls.InsertString(4,"Flat rate charging - programmer and TRVs");
		m_comboControls.InsertString(5,"Charging system linked to us of community heating, programmer and TRVs");
		m_comboControls.InsertString(6,"Uknown");
	}

	if(str_comboMHType == "Storage heaters")
	{
		// Storage heater controls
		m_comboControls.InsertString(0,"Manual charge control");
		m_comboControls.InsertString(1,"Automatic charge control");
		m_comboControls.InsertString(2,"Celect-type controls");
		m_comboControls.InsertString(3,"Uknown");
	}

	if(str_comboMHType == "Warm air")
	{
		// Warm air controls
		m_comboControls.InsertString(0,"No thermostatic control of room temperature");
		m_comboControls.InsertString(1,"Programmer - no thermostat");
		m_comboControls.InsertString(2,"Room thermostat only");
		m_comboControls.InsertString(3,"Programmer and room thermostat");
		m_comboControls.InsertString(4,"Programmer and atleast two room thermostats");
		m_comboControls.InsertString(5,"Time and temperature zone control");	
		m_comboControls.InsertString(6,"Uknown");
	}
	
	if(str_comboMHType == "Heat pump - wet system")
	{
		// Heat pump - wet system controls
		m_comboControls.InsertString(0,"No time or thermostatic control of room temperature");
		m_comboControls.InsertString(1,"Programmer - no thermostat");
		m_comboControls.InsertString(2,"Room thermostat only");
		m_comboControls.InsertString(3,"Programmer and room thermostat");
		m_comboControls.InsertString(4,"Programmer and atleast two room thermostats");	
		m_comboControls.InsertString(5,"Programmer - TRVs and bypass");
		m_comboControls.InsertString(6,"Time and temperature zone control");
		m_comboControls.InsertString(7,"Uknown");
	}
	
	if(str_comboMHType == "Heat pump - warm air")
	{
		// Heat pump - warm air
		m_comboControls.InsertString(0,"No thermostatic control of room temperature");
		m_comboControls.InsertString(1,"Programmer - no thermostat");
		m_comboControls.InsertString(2,"Room thermostat only");
		m_comboControls.InsertString(3,"Programmer and room thermostat");
		m_comboControls.InsertString(4,"Programmer and atleast two room thermostats");
		m_comboControls.InsertString(5,"Time and temperature zone control");
		m_comboControls.InsertString(6,"Uknown");
	}
	
	if(str_comboMHType == "Room heaters")
	{
		// Room heaters controls
		m_comboControls.InsertString(0,"No thermostat control of room temperature");	
		m_comboControls.InsertString(1,"Appliance thermostats");	
		m_comboControls.InsertString(2,"Programmer and appliance thermostats");	
		m_comboControls.InsertString(3,"Programmer and room thermostats");
		m_comboControls.InsertString(4,"Room thermostats");
		m_comboControls.InsertString(5,"Uknown");
	}
	
	if(str_comboMHType == "Electric ceiling heating")
	{
		// Electric ceiling heating
		m_comboControls.InsertString(0,"No thermostatic control of room temperature");
		m_comboControls.InsertString(1,"Programmer, no room thermostat");
		m_comboControls.InsertString(2,"Room thermostat only");
		m_comboControls.InsertString(3,"Programmer and room thermostat");
		m_comboControls.InsertString(3,"Temperature zone control");
		m_comboControls.InsertString(4,"Time and temperature zone control");
		m_comboControls.InsertString(5,"Uknown");
	}
	
	if(str_comboMHType == "Electric underfloor heating")
	{
		// Electric underfloor heating heating
		m_comboControls.InsertString(0,"No thermostatic control of room temperature");
		m_comboControls.InsertString(1,"Programmer, no room thermostat");
		m_comboControls.InsertString(2,"Room thermostat only");
		m_comboControls.InsertString(3,"Programmer and room thermostat");
		m_comboControls.InsertString(3,"Temperature zone control");
		m_comboControls.InsertString(4,"Time and temperature zone control");
		m_comboControls.InsertString(5,"Uknown");
	}

	//---------------------------------------
	// Show interlock only if
	//---------------------------------------
	if(mainHtType == "Boiler") 
	{
		m_labelInterlock.EnableWindow(TRUE);
        m_comboInterlock.EnableWindow(TRUE);
	}
	else
	{
		m_labelInterlock.EnableWindow(FALSE);
        m_comboInterlock.EnableWindow(FALSE);
	}

	//---------------------------------------
	// Show boiler type only if
	//---------------------------------------
	if(str_comboMHType == "Boiler") 
	{
		m_labelBoiler.ShowWindow(TRUE);
        m_comboBoilerType.ShowWindow(TRUE);
	}
	else
	{
		m_labelBoiler.ShowWindow(FALSE);
        m_comboBoilerType.ShowWindow(FALSE);
	}

	//---------------------------------------
	// Show compensator only if
	//---------------------------------------
	if (((mainHtType == "Boiler")  && ( boilerType == "Condensing")) || 
	  (mainHtType == "Heat pump - wet system" ) || (mainHtType == "Heat pump - warm air" ))
	{
		m_labelCompensator.EnableWindow(TRUE);
        m_comboCompensator.EnableWindow(TRUE);
	}
	else
	{
		m_labelCompensator.EnableWindow(FALSE);
        m_comboCompensator.EnableWindow(FALSE);
	}

	//---------------------------------------
	// Show emitter type only if
	//---------------------------------------
	if((str_comboMHType == "Boiler") ||
		(str_comboMHType  == "Community heating")||
		(str_comboMHType  == "Heat pump - wet system"))

	{
		m_labelEmitter.EnableWindow(TRUE);
        m_comboEmitter.EnableWindow(TRUE);
	}
	else
	{
		m_labelEmitter.EnableWindow(FALSE);
        m_comboEmitter.EnableWindow(FALSE);
	}

	//---------------------------------------
	// Show pump in heated space only if
	//---------------------------------------
	if((str_comboMHType == "Boiler") ||
		(str_comboMHType  == "Heat pump - wet system"))
	{
		m_labelPump.EnableWindow(TRUE);
        m_comboPump.EnableWindow(TRUE);
	}
	else
	{
		m_labelPump.EnableWindow(FALSE);
        m_comboPump.EnableWindow(FALSE);
	}

	ReadInputsFromMainHeatingDlg();
	DetermineSecHeatFraction();
}

void CDlg_MainHeating::OnCbnSelchangeComboElectariff()
{
	ReadInputsFromMainHeatingDlg();
}

void CDlg_MainHeating::OnCbnSelchangeComboMhefffrom()
{
	ReadInputsFromMainHeatingDlg();
}

void CDlg_MainHeating::OnCbnSelchangeComboMhboilertype()
{
	ReadInputsFromMainHeatingDlg();

    if((strcmp(boilerType,"Range cooker")==0) && ((heatEmmFromCase == 0) || (heatTransferredToWater==0)))
	{
		MessageBox("Please enter valid values for Range cooker in Main Heating detailed tab ", "Help", MB_OK);
	}
}
void CDlg_MainHeating::DetermineSecHeatFraction()
{
	// Change values based on fuel
	if( (strcmp(mainFuel,"Mains gas")==0) ||
		(strcmp(mainFuel,"LPG")==0)||
		(strcmp(mainFuel,"Bottled gas")==0) ||
		(strcmp(mainFuel,"Oil")==0) ||
		(strcmp(mainFuel,"House coal")==0) ||
		(strcmp(mainFuel,"Smokeless")==0) || 
		(strcmp(mainFuel,"Anthracite")==0) ||
		(strcmp(mainFuel,"Wood logs")==0) ||
		(strcmp(mainFuel,"Bulk wood pellets")==0) ||
		(strcmp(mainFuel,"Wood chips")==0) ||
		(strcmp(mainFuel,"Dual fuel (mineral and wood)")==0) ||
		(strcmp(mainFuel,"Electricity")==0))
	{
		secHtFraction  = 0.10;
		mainHtFractionSupplied = 0.90;
	}

	if((strcmp(mainFuel,"Electricity")==0) &&
		    (strcmp(mainHtType,"Storage heaters")==0) &&
			(strcmp(isFanFluePresent,"Yes")==0))		 
	{
		secHtFraction  = 0.15;
		mainHtFractionSupplied = 0.85;
	}

	if((strcmp(mainFuel,"Electricity")==0) &&
		    (strcmp(mainHtType,"Storage heaters")==0) &&
			(strcmp(isFanFluePresent,"No")==0))		 
	{
		secHtFraction  = 0.10;
		mainHtFractionSupplied = 0.90;
	}

	if((strcmp(mainFuel,"Electricity")==0) &&
		    (strcmp(mainHtType,"Room heaters")==0))
	{
		secHtFraction  = 0.20;
		mainHtFractionSupplied = 0.80;
	}
	
	if( (strcmp(mainHtType,"Heat pump - wet system")==0) ||
		(strcmp(mainHtType,"Heat pump - warm air")==0))
	{
		secHtFraction  = 0.10;
		mainHtFractionSupplied = 0.90;
	}

	str_editFractionSupplied.Format("%.2f",mainHtFractionSupplied);
	UpdateData(FALSE);
}

void CDlg_MainHeating::OnCbnSelchangeComboMhfuel()
{
	UpdateData(TRUE);

	ReadInputsFromMainHeatingDlg();

	if(mainFuel == "Electricity")
	{
		m_comboSystem.EnableWindow(TRUE);
		m_labelSystem.EnableWindow(TRUE);
	}
	else
	{
		m_comboSystem.EnableWindow(FALSE);
		m_labelSystem.EnableWindow(FALSE);
	}

	// Fuel is standard for all tariffs except electricity
	if(mainFuel == "Electricity")
	{
		m_comboElecTariff.ResetContent();
		m_comboElecTariff.InsertString(0,"Standard");
		m_comboElecTariff.InsertString(1,"7 hour");
		m_comboElecTariff.InsertString(2,"10 hour");
		m_comboElecTariff.InsertString(3,"24 hour");

		m_labelTariff.ShowWindow(TRUE);
		m_comboElecTariff.ShowWindow(TRUE);
	}
	else
	{
		m_comboElecTariff.ResetContent();
		m_comboElecTariff.InsertString(0,"Standard");

		m_labelTariff.ShowWindow(FALSE);
		m_comboElecTariff.ShowWindow(FALSE);
	}
	m_comboElecTariff.SelectString(0,"Standard");

	ReadInputsFromMainHeatingDlg();
	DetermineSecHeatFraction();
}

void CDlg_MainHeating::OnCbnSelchangeComboSecboilerfuel()
{
	ReadInputsFromMainHeatingDlg();
}

void CDlg_MainHeating::OnCbnSelchangeComboFanflue()
{
	ReadInputsFromMainHeatingDlg();
	DetermineSecHeatFraction();
}

void CDlg_MainHeating::OnCbnSelchangeCombosystem()
{
	ReadInputsFromMainHeatingDlg();	
}

void CDlg_MainHeating::OnCbnSelchangeComboemitter()
{
	ReadInputsFromMainHeatingDlg();
}

void CDlg_MainHeating::OnCbnSelchangeCombointerlock()
{
	ReadInputsFromMainHeatingDlg();
}

void CDlg_MainHeating::OnCbnSelchangeCombocompensator()
{
	ReadInputsFromMainHeatingDlg();
}

void CDlg_MainHeating::OnCbnSelchangeCombopump()
{
	ReadInputsFromMainHeatingDlg();
}

void CDlg_MainHeating::OnEnChangeEditmanufactdescription()
{
	//------------------------------------------------------------------------------
	// Empty edit box if user types any character other than numeric characters or '.'
	UpdateData(TRUE);
	static TCHAR * lpszValidChars = _T("0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz-*&%!'@#_:;.0123456789 ");
	// szText is the string we want to check for invalid chracters
	if (_tcsspnp(str_editManufactDesc, lpszValidChars) != 0) 
	{
		str_editManufactDesc = " ";
		UpdateData(FALSE);
		return;
	}
	ReadInputsFromMainHeatingDlg();
}

void CDlg_MainHeating::OnCbnSelchangeCombotestmethod()
{
	ReadInputsFromMainHeatingDlg();
}

void CDlg_MainHeating::OnEnChangeEditeff()
{
	//------------------------------------------------------------------------------
	// 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_editEff, lpszValidChars) != 0) 
	{
		str_editEff = " ";
		UpdateData(FALSE);
		return;
	}
	ReadInputsFromMainHeatingDlg();
					
	// Check limit
	isCheckRange_mainHtEff= true;
}

void CDlg_MainHeating::OnEnChangeEditboilerref()
{
	//------------------------------------------------------------------------------
	// Empty edit box if user types any character other than numeric characters or '.'
	UpdateData(TRUE);
	static TCHAR * lpszValidChars = _T("0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz-*&%!'@#_:;.()0123456789 ");
	// szText is the string we want to check for invalid chracters
	if (_tcsspnp(str_editlBoilerRef, lpszValidChars) != 0) 
	{
		str_editlBoilerRef = " ";
		UpdateData(FALSE);
		return;
	}
	ReadInputsFromMainHeatingDlg();
}

void CDlg_MainHeating::OnEnChangeEditboilermodel()
{
	//------------------------------------------------------------------------------
	// Empty edit box if user types any character other than numeric characters or '.'
	UpdateData(TRUE);
	static TCHAR * lpszValidChars = _T("0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz-*&%!'@#_:;.()0123456789 ");
	// szText is the string we want to check for invalid chracters
	if (_tcsspnp(str_editlBoilerModel, lpszValidChars) != 0) 
	{
		str_editlBoilerModel = " ";
		UpdateData(FALSE);
		return;
	}
	ReadInputsFromMainHeatingDlg();
}

void CDlg_MainHeating::OnEnChangeEditeff2()
{
	ReadInputsFromMainHeatingDlg();
					
	// Check limit
	isCheckRange_mainHtFractionSupplied= true;

	// To make sure the sum of secHtFraction and mainHtFractionSupplied is 1
	secHtFraction  = 1 - mainHtFractionSupplied;
}

BOOL CDlg_MainHeating::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);
}