// Dlg_SummerOverHeating.cpp : implementation file
//

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


// CDlg_SummerOverHeating dialog



IMPLEMENT_DYNAMIC(CDlg_SummerOverHeating, CDialog)
CDlg_SummerOverHeating::CDlg_SummerOverHeating(CWnd* pParent /*=NULL*/)
	: CDialog(CDlg_SummerOverHeating::IDD, pParent)
	, str_comboTMP(_T(""))
	, str_editTMP(_T(""))
	, str_comboTMPIntPartConstruction(_T(""))
	, str_comboPartyWallConstruction(_T(""))
	, str_comboIsVentUserDefined(_T(""))
	, str_editAirChangeRate(_T(""))
	, str_comboIsCrossVentOnMostFloors(_T(""))
	, str_comboWindowVentilation(_T(""))
	, str_comboCurtainsClosed(_T(""))
	, str_editFractCurtainsClosed(_T(""))
	, str_comboBlindCurtainType(_T(""))
	, str_editSourceUserDefValues(_T(""))
{
}

CDlg_SummerOverHeating::~CDlg_SummerOverHeating()
{
}

void CDlg_SummerOverHeating::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	DDX_Control(pDX, IDC_STATIC_1, m_label1);
	DDX_Control(pDX, IDC_STATIC_2, m_label2);
	DDX_Control(pDX, IDC_STATIC_3, m_label3);
	DDX_Control(pDX, IDC_COMBO1_UserDef, m_comboTMP);
	DDX_Control(pDX, IDC_COMBO_IntPartConst, m_comboTMPIntPartConstruction);
	DDX_Control(pDX, IDC_COMBO_PartyWallConst, m_comboPartyWallConstruction);
	DDX_Control(pDX, IDC_COMBO_ventUserDef, m_comboIsVentUserDefined);
	DDX_Control(pDX, IDC_COMBO_CrossVent, m_comboIsCrossVentOnMostFloors);
	DDX_Control(pDX, IDC_COMBO_WindowVentilation, m_comboWindowVentilation);
	DDX_Control(pDX, IDC_COMBO_CurtainsClosed, m_comboCurtainsClosed);
	DDX_Control(pDX, IDC_COMBO_BlindCurtainType, m_comboBlindCurtainType);
	DDX_Control(pDX, IDC_EDIT_TMP, m_editTMP);
	DDX_Control(pDX, IDC_EDIT_acr, m_editAirChangeRate);
	DDX_Control(pDX, IDC_EDIT_fractCurtainsClosed, m_editFractCurtainsClosed);
	DDX_Control(pDX, IDC_EDIT_SourcerUserDefinedValues, m_editSourceUserDefValues);
	DDX_CBString(pDX, IDC_COMBO1_UserDef, str_comboTMP);
	DDX_Text(pDX, IDC_EDIT_TMP, str_editTMP);
	DDX_CBString(pDX, IDC_COMBO_IntPartConst, str_comboTMPIntPartConstruction);
	DDX_CBString(pDX, IDC_COMBO_PartyWallConst, str_comboPartyWallConstruction);
	DDX_CBString(pDX, IDC_COMBO_ventUserDef, str_comboIsVentUserDefined);
	DDX_Text(pDX, IDC_EDIT_acr, str_editAirChangeRate);
	DDX_CBString(pDX, IDC_COMBO_CrossVent, str_comboIsCrossVentOnMostFloors);
	DDX_CBString(pDX, IDC_COMBO_WindowVentilation, str_comboWindowVentilation);
	DDX_CBString(pDX, IDC_COMBO_CurtainsClosed, str_comboCurtainsClosed);
	DDX_Text(pDX, IDC_EDIT_fractCurtainsClosed, str_editFractCurtainsClosed);
	DDX_CBString(pDX, IDC_COMBO_BlindCurtainType, str_comboBlindCurtainType);
	DDX_Text(pDX, IDC_EDIT_SourcerUserDefinedValues, str_editSourceUserDefValues);
}


BEGIN_MESSAGE_MAP(CDlg_SummerOverHeating, CDialog)
	ON_CBN_SELCHANGE(IDC_COMBO1_UserDef, OnCbnSelchangeCombo1Userdef)
	ON_CBN_SELCHANGE(IDC_COMBO_CurtainsClosed, OnCbnSelchangeComboCurtainsclosed)
	ON_EN_CHANGE(IDC_EDIT_TMP, OnEnChangeEditTmp)
	ON_CBN_SELCHANGE(IDC_COMBO_IntPartConst, OnCbnSelchangeComboIntpartconst)
	ON_CBN_SELCHANGE(IDC_COMBO_PartyWallConst, OnCbnSelchangeComboPartywallconst)
	ON_CBN_SELCHANGE(IDC_COMBO_ventUserDef, OnCbnSelchangeComboventuserdef)
	ON_EN_CHANGE(IDC_EDIT_acr, OnEnChangeEditacr)
	ON_CBN_SELCHANGE(IDC_COMBO_CrossVent, OnCbnSelchangeComboCrossvent)
	ON_CBN_SELCHANGE(IDC_COMBO_WindowVentilation, OnCbnSelchangeComboWindowventilation)
	ON_EN_CHANGE(IDC_EDIT_fractCurtainsClosed, OnEnChangeEditfractcurtainsclosed)
	ON_CBN_SELCHANGE(IDC_COMBO_BlindCurtainType, OnCbnSelchangeComboBlindcurtaintype)
	ON_EN_CHANGE(IDC_EDIT_SourcerUserDefinedValues, OnEnChangeEditSourceruserdefinedvalues)
END_MESSAGE_MAP()


// CDlg_SummerOverHeating message handlers
BOOL CDlg_SummerOverHeating::OnInitDialog()
{
	CDialog::OnInitDialog();
	
	CFont *m_Font1 = new CFont;
	m_Font1->CreatePointFont(90, "Arial Bold");

	//---------------------------------------------------
	// LABELS
	//---------------------------------------------------
	m_label1.SetFont(m_Font1); 
	m_label1.SetTextColor(BLUE);  

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

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

	AddStringsForSummerOverHeatingDlg();	

	if(file_new_selected ==true)
	{
		isTMPUserDef = " ";
		TMPvalue     = 0;
		TMPIntPartConstruction = " ";
		TMPPartyWallConstruction = " ";
		isVentUserDefined = " ";
		airChangeRate     = 0;
		isCrossVentOnMostFloors = " ";
		windowVentilation = " ";
		areCurtainsClosedDuringDay = " ";
		fractCurtainsClosed = 0;
		blindCurtainType = " ";
		sourceUserDefValues = " ";
	}

	ReadPreviousInputsFromSummerOverHeatingDlg();

	return TRUE;
}


void CDlg_SummerOverHeating::AddStringsForSummerOverHeatingDlg()
{
	m_comboTMP.InsertString(0,"No");
	m_comboTMP.InsertString(1,"Yes");

	m_comboTMPIntPartConstruction.InsertString(0,"Plasterboard-timber/steel frame");
	m_comboTMPIntPartConstruction.InsertString(1,"Plasterboard on dabs-masonry");
	m_comboTMPIntPartConstruction.InsertString(2,"Dense plaster-masonry");

	m_comboPartyWallConstruction.InsertString(0,"Plasterboard-timber/steel frame");
	m_comboPartyWallConstruction.InsertString(1,"Plasterboard on dabs-masonry");
	m_comboPartyWallConstruction.InsertString(2,"Dense plaster-masonry");

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

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

	m_comboWindowVentilation.InsertString(0,"Trickle vents only");
	
	m_comboCurtainsClosed.InsertString(0,"No");
	m_comboCurtainsClosed.InsertString(1,"Yes");

	m_comboBlindCurtainType.InsertString(0,"Net curtain (covering whole window)");
	m_comboBlindCurtainType.InsertString(1,"Net curtain (covering half window)");
	m_comboBlindCurtainType.InsertString(2,"Dark-coloured curtain or roller blind");
	m_comboBlindCurtainType.InsertString(3,"Light-coloured curtain or roller blind");
	m_comboBlindCurtainType.InsertString(4,"Dark-coloured venetian blind");
	m_comboBlindCurtainType.InsertString(5,"Light-coloured venetian blind");
	m_comboBlindCurtainType.InsertString(6,"Dark-coloured external shutter - window closed");
	m_comboBlindCurtainType.InsertString(7,"White external shutter - window closed");
	m_comboBlindCurtainType.InsertString(8,"Dark-coloured external shutter - window fully open");
	m_comboBlindCurtainType.InsertString(9,"White external shutter - window fully open");
}



void CDlg_SummerOverHeating::ReadPreviousInputsFromSummerOverHeatingDlg()
{
	netAreaWindows = winNArea+   
					  winNEArea+ 
				      winEArea+   
				      winSEArea+ 
				      winSArea+   
			          winSWArea+ 
				      winWArea+   
				      winNWArea;
				    
	netAreaRoofLights = rooflightsArea;

	TMPvalue = ((netAreaDoors) + (netAreaWindows)+ (netAreaRoofLights)+ (netAreaGF * kValueGF)+
		(netAreaExFloor * kValueExpFloor) + (netAreaWallType1 * kValueWallType1) +
		(netAreaWallType2 * kValueWallType2)+ (netAreaRoofType1 * kValueRoofType1)+
		(netAreaRoofType2 * kValueRoofType2) + (netAreaPartyWall * kValuePartyWall)+
		(netAreaPartyFloor*kValuePartyFloor) + (netAreaPartyCeiling * kValuePartyCeiling)+
		(netAreaInternalWall * kValueIntWall)+(netAreaInternalFloor * kValueIntFloor)+
		(netAreaInternalCeiling *kValueIntCeiling ))/TFA;

	str_comboTMP.Format("%s",isTMPUserDef);
	str_editTMP.Format("%.1f",TMPvalue);
	str_comboTMPIntPartConstruction.Format("%s",TMPIntPartConstruction);
	str_comboPartyWallConstruction.Format("%s",TMPPartyWallConstruction);
	str_comboIsVentUserDefined.Format("%s",isVentUserDefined);
	str_editAirChangeRate.Format("%.1f",airChangeRate);
	str_comboIsCrossVentOnMostFloors.Format("%s",isCrossVentOnMostFloors);
	str_comboWindowVentilation.Format("%s",windowVentilation);
	str_comboCurtainsClosed.Format("%s",areCurtainsClosedDuringDay);
	str_editFractCurtainsClosed.Format("%.1f",fractCurtainsClosed);
	str_comboBlindCurtainType.Format("%s",blindCurtainType);
	str_editSourceUserDefValues.Format("%s",sourceUserDefValues);

	UpdateData(FALSE);
}

void CDlg_SummerOverHeating::ReadInputsFromSummerOverHeatingDlg()
{
	UpdateData(TRUE);

	isTMPUserDef = str_comboTMP;

	TMPIntPartConstruction = str_comboTMPIntPartConstruction;
	TMPPartyWallConstruction = str_comboPartyWallConstruction;
	isVentUserDefined = str_comboIsVentUserDefined;
	airChangeRate = atof(str_editAirChangeRate);
	isCrossVentOnMostFloors = str_comboIsCrossVentOnMostFloors;
	windowVentilation = str_comboWindowVentilation;
	areCurtainsClosedDuringDay = str_comboCurtainsClosed;
	fractCurtainsClosed = atof(str_editFractCurtainsClosed);
	blindCurtainType = str_comboBlindCurtainType;
	sourceUserDefValues = str_editSourceUserDefValues;

	netAreaWindows = winNArea+   
		winNEArea+ 
		winEArea+   
		winSEArea+ 
		winSArea+   
		winSWArea+ 
		winWArea+   
		winNWArea;

	netAreaRoofLights = rooflightsArea;

	TMPvalue = ((netAreaDoors) + (netAreaWindows)+ (netAreaRoofLights)+ (netAreaGF * kValueGF)+
		(netAreaExFloor * kValueExpFloor) + (netAreaWallType1 * kValueWallType1) +
		(netAreaWallType2 * kValueWallType2)+ (netAreaRoofType1 * kValueRoofType1)+
		(netAreaRoofType2 * kValueRoofType2) + (netAreaPartyWall * kValuePartyWall)+
		(netAreaPartyFloor*kValuePartyFloor) + (netAreaPartyCeiling * kValuePartyCeiling)+
		(netAreaInternalWall * kValueIntWall)+(netAreaInternalFloor * kValueIntFloor)+
		(netAreaInternalCeiling *kValueIntCeiling ))/TFA;

	str_editTMP.Format("%.1f",TMPvalue);
	UpdateData(FALSE);
}

void CDlg_SummerOverHeating::OnCbnSelchangeCombo1Userdef()
{
	UpdateData(TRUE);

	if (str_comboTMP == "No")
	{
		m_editTMP.EnableWindow(TRUE);
		m_comboTMPIntPartConstruction.EnableWindow(FALSE);
		m_comboPartyWallConstruction.EnableWindow(FALSE);

		TMPIntPartConstruction = " ";
		TMPPartyWallConstruction = " ";

		str_comboTMPIntPartConstruction.Format("%s",TMPIntPartConstruction);
		str_comboPartyWallConstruction.Format("%s",TMPPartyWallConstruction);
	}
	else
	{
		m_editTMP.EnableWindow(FALSE);
		m_comboTMPIntPartConstruction.EnableWindow(TRUE);
		m_comboPartyWallConstruction.EnableWindow(TRUE);

		TMPvalue = 0;
		str_editTMP.Format("%.1f",isTMPUserDef);
	}

	UpdateData(FALSE);
	ReadInputsFromSummerOverHeatingDlg();
}

void CDlg_SummerOverHeating::OnCbnSelchangeComboCurtainsclosed()
{
	UpdateData(TRUE);
	if(str_comboCurtainsClosed == "Yes")
	{
		m_editFractCurtainsClosed.EnableWindow(TRUE);
		m_comboBlindCurtainType.EnableWindow(TRUE);
	}
	else
	{
		m_editFractCurtainsClosed.EnableWindow(FALSE);
		m_comboBlindCurtainType.EnableWindow(FALSE);
	}
	ReadInputsFromSummerOverHeatingDlg();

}

void CDlg_SummerOverHeating::OnEnChangeEditTmp()
{
	//------------------------------------------------------------------------------
	// 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_editTMP, lpszValidChars) != 0) 
	{
		str_editTMP = " ";
		UpdateData(FALSE);
		return;
	}
	ReadInputsFromSummerOverHeatingDlg();
}

void CDlg_SummerOverHeating::OnCbnSelchangeComboIntpartconst()
{
	ReadInputsFromSummerOverHeatingDlg();
}

void CDlg_SummerOverHeating::OnCbnSelchangeComboPartywallconst()
{
	ReadInputsFromSummerOverHeatingDlg();
}

void CDlg_SummerOverHeating::OnCbnSelchangeComboventuserdef()
{
	ReadInputsFromSummerOverHeatingDlg();
}

void CDlg_SummerOverHeating::OnEnChangeEditacr()
{
	//------------------------------------------------------------------------------
	// 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_editAirChangeRate, lpszValidChars) != 0) 
	{
		str_editAirChangeRate = " ";
		UpdateData(FALSE);
		return;
	}
	ReadInputsFromSummerOverHeatingDlg();
}

void CDlg_SummerOverHeating::OnCbnSelchangeComboCrossvent()
{
	ReadInputsFromSummerOverHeatingDlg();
}

void CDlg_SummerOverHeating::OnCbnSelchangeComboWindowventilation()
{
	ReadInputsFromSummerOverHeatingDlg();
}

void CDlg_SummerOverHeating::OnEnChangeEditfractcurtainsclosed()
{
	//------------------------------------------------------------------------------
	// 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_editFractCurtainsClosed, lpszValidChars) != 0) 
	{
		str_editFractCurtainsClosed = " ";
		UpdateData(FALSE);
		return;
	}
	ReadInputsFromSummerOverHeatingDlg();
}

void CDlg_SummerOverHeating::OnCbnSelchangeComboBlindcurtaintype()
{
	ReadInputsFromSummerOverHeatingDlg();
}

void CDlg_SummerOverHeating::OnEnChangeEditSourceruserdefinedvalues()
{
	//------------------------------------------------------------------------------
	// 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_editSourceUserDefValues, lpszValidChars) != 0) 
	{
		str_editSourceUserDefValues = " ";
		UpdateData(FALSE);
		return;
	}
	ReadInputsFromSummerOverHeatingDlg();
}

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