// Dlg_LightsAndAppliances.cpp : implementation file
//

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


// CDlg_LightsAndAppliances dialog

IMPLEMENT_DYNAMIC(CDlg_LightsAndAppliances, CDialog)
CDlg_LightsAndAppliances::CDlg_LightsAndAppliances(CWnd* pParent /*=NULL*/)
	: CDialog(CDlg_LightsAndAppliances::IDD, pParent)
	, str_editIntLightStdFittings(_T(""))
	, str_editIntLightDedicatedLowE(_T(""))
	, str_editIntLightNonDedicatedLowE(_T(""))
	, str_editIntLightTotal(_T(""))
	, str_comboAssessExtLight(_T(""))
	, str_comoExtLightsFittings(_T(""))
	, str_comboExtLigtsLamps(_T(""))
	, str_editLEL(_T(""))
{
}

CDlg_LightsAndAppliances::~CDlg_LightsAndAppliances()
{
}

void CDlg_LightsAndAppliances::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	DDX_Control(pDX, IDC_STATIC_1, m_labelIntLighting);
	DDX_Control(pDX, IDC_STATIC_2, m_labelExtLighting);
	DDX_Control(pDX, IDC_STATIC_3, m_labelAppliances);
	DDX_Control(pDX, IDC_EDIT_stdFittings, m_editIntLightStdFittings);
	DDX_Control(pDX, IDC_EDIT_lowEnergyDed, m_editIntLightDedicatedLowE);
	DDX_Control(pDX, IDC_EDIT_lowEnergyNonded, m_editIntLightNonDedicatedLowE);
	DDX_Control(pDX, IDC_EDIT_total, m_editIntLightTotal);
	DDX_Control(pDX, IDC_COMBO_AssessExtLighting, m_comboAssessExtLight);
	DDX_Control(pDX, IDC_COMBO_fittings, m_comoExtLightsFittings);
	DDX_Control(pDX, IDC_COMBO_lamps, m_comboExtLigtsLamps);
	DDX_Text(pDX, IDC_EDIT_stdFittings, str_editIntLightStdFittings);
	DDX_Text(pDX, IDC_EDIT_lowEnergyDed, str_editIntLightDedicatedLowE);
	DDX_Text(pDX, IDC_EDIT_lowEnergyNonded, str_editIntLightNonDedicatedLowE);
	DDX_Text(pDX, IDC_EDIT_total, str_editIntLightTotal);
	DDX_CBString(pDX, IDC_COMBO_AssessExtLighting, str_comboAssessExtLight);
	DDX_CBString(pDX, IDC_COMBO_fittings, str_comoExtLightsFittings);
	DDX_CBString(pDX, IDC_COMBO_lamps, str_comboExtLigtsLamps);
	DDX_Control(pDX, IDC_STATIC_4, m_labelLEL);
	DDX_Control(pDX, IDC_EDIT_LEL, m_editLEL);
	DDX_Text(pDX, IDC_EDIT_LEL, str_editLEL);
}


BEGIN_MESSAGE_MAP(CDlg_LightsAndAppliances, CDialog)
	ON_EN_CHANGE(IDC_EDIT_stdFittings, OnEnChangeEditstdfittings)
	ON_EN_CHANGE(IDC_EDIT_lowEnergyDed, OnEnChangeEditlowenergyded)
	ON_EN_CHANGE(IDC_EDIT_lowEnergyNonded, OnEnChangeEditlowenergynonded)
	ON_EN_CHANGE(IDC_EDIT_total, OnEnChangeEdittotal)
	ON_CBN_SELCHANGE(IDC_COMBO_AssessExtLighting, OnCbnSelchangeComboAssessextlighting)
	ON_CBN_SELCHANGE(IDC_COMBO_fittings, OnCbnSelchangeCombofittings)
	ON_CBN_SELCHANGE(IDC_COMBO_lamps, OnCbnSelchangeCombolamps)
	ON_EN_CHANGE(IDC_EDIT_LEL, OnEnChangeEditLel)
END_MESSAGE_MAP()


// CDlg_LightsAndAppliances message handlers




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

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

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

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

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

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

	AddStringsToComboBoxesForLightsAndAppliancesDlg();

	if(file_new_selected ==true)
	{
		//fractionLEL = 0;
		//IntLightsStdFittings           = 0;
		//IntLightsDedicatedLowEnergy    = 0;
		//IntLightsNonDedicatedLowEnergy = 0;
	
	
		//ExtLightsAssess = " ";    
		//ExtLightsFittingGT40Lumens = " ";
		//ExtLightsLampsNGT150W = " ";

		//IntLightsTotal = 0;
	}

	ReadPreviousInputsFromLightsAndAppliancesDlg();

	return TRUE;  // return TRUE  unless you set the focus to a control
}

void CDlg_LightsAndAppliances::AddStringsToComboBoxesForLightsAndAppliancesDlg()
{
	//m_comboAssessExtLight.InsertString(0,"No");
	//m_comboAssessExtLight.InsertString(1,"Yes");

	//m_comoExtLightsFittings.InsertString(0,"No");
	//m_comoExtLightsFittings.InsertString(1,"Yes");

	//m_comboExtLigtsLamps.InsertString(0,"No");
	//m_comboExtLigtsLamps.InsertString(1,"Yes");
}

void CDlg_LightsAndAppliances::ReadPreviousInputsFromLightsAndAppliancesDlg()
{

	//str_editLEL.Format("%.2f",fractionLEL);
	//str_editIntLightStdFittings.Format("%d",IntLightsStdFittings);
	//str_editIntLightDedicatedLowE.Format("%d",IntLightsDedicatedLowEnergy);
	//str_editIntLightNonDedicatedLowE.Format("%d",IntLightsNonDedicatedLowEnergy);
	//str_editIntLightTotal.Format("%d",IntLightsTotal);
	
	//str_comboAssessExtLight.Format("%s",ExtLightsAssess);
	//str_comoExtLightsFittings.Format("%s",ExtLightsFittingGT40Lumens);
	//str_comboExtLigtsLamps.Format("%s",ExtLightsLampsNGT150W);

	UpdateData(FALSE);
}

void CDlg_LightsAndAppliances::ReadInputsFromLightsAndAppliancesDlg()
{
//	UpdateData(TRUE);

	//fractionLEL = atof(str_editLEL);
//	IntLightsStdFittings = atoi(str_editIntLightStdFittings);
//	IntLightsDedicatedLowEnergy = atoi(str_editIntLightDedicatedLowE);
//	IntLightsNonDedicatedLowEnergy = atoi(str_editIntLightNonDedicatedLowE);
	
//	ExtLightsAssess = str_comboAssessExtLight;
//	ExtLightsFittingGT40Lumens = str_comoExtLightsFittings;
//	ExtLightsLampsNGT150W = str_comboExtLigtsLamps;

//	IntLightsTotal = IntLightsStdFittings + IntLightsDedicatedLowEnergy 
//		           + IntLightsNonDedicatedLowEnergy;

//   str_editIntLightTotal.Format("%d",IntLightsTotal);		
//	UpdateData(FALSE);
}
void CDlg_LightsAndAppliances::OnEnChangeEditstdfittings()
{
	//------------------------------------------------------------------------------
	// 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_editIntLightStdFittings, lpszValidChars) != 0) 
	{
		str_editIntLightStdFittings = " ";
		UpdateData(FALSE);
		return;
	}
	ReadInputsFromLightsAndAppliancesDlg();	
}

void CDlg_LightsAndAppliances::OnEnChangeEditlowenergyded()
{
	//------------------------------------------------------------------------------
	// 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_editIntLightDedicatedLowE, lpszValidChars) != 0) 
	{
		str_editIntLightDedicatedLowE = " ";
		UpdateData(FALSE);
		return;
	}
	ReadInputsFromLightsAndAppliancesDlg();
}

void CDlg_LightsAndAppliances::OnEnChangeEditlowenergynonded()
{
	//------------------------------------------------------------------------------
	// 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_editIntLightNonDedicatedLowE, lpszValidChars) != 0) 
	{
		str_editIntLightNonDedicatedLowE = " ";
		UpdateData(FALSE);
		return;
	}
	ReadInputsFromLightsAndAppliancesDlg();
}

void CDlg_LightsAndAppliances::OnEnChangeEdittotal()
{
	ReadInputsFromLightsAndAppliancesDlg();
}

void CDlg_LightsAndAppliances::OnCbnSelchangeComboAssessextlighting()
{
	ReadInputsFromLightsAndAppliancesDlg();
}

void CDlg_LightsAndAppliances::OnCbnSelchangeCombofittings()
{
	ReadInputsFromLightsAndAppliancesDlg();
}

void CDlg_LightsAndAppliances::OnCbnSelchangeCombolamps()
{
	ReadInputsFromLightsAndAppliancesDlg();
}


BOOL CDlg_LightsAndAppliances::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);
}
void CDlg_LightsAndAppliances::OnEnChangeEditLel()
{
	//------------------------------------------------------------------------------
	// 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_editLEL, lpszValidChars) != 0) 
	{
		str_editLEL = " ";
		UpdateData(FALSE);
		return;
	}
	ReadInputsFromLightsAndAppliancesDlg();	
}
