// Dlg_Estate.cpp : implementation file
//

#include "stdafx.h"
#include "SAPP1.h"
#include "SAPP1Dlg.h"
#include "Dlg_Estate.h"
#include "SAPPImpData.h"




// CDlg_Estate dialog

IMPLEMENT_DYNAMIC(CDlg_Estate, CDialog)
CDlg_Estate::CDlg_Estate(CWnd* pParent /*=NULL*/)
	: CDialog(CDlg_Estate::IDD, pParent)
	, str_editNumOfDwellings(_T(""))
	, str_comboCase(_T(""))
	, str_editNameOfDwelling(_T(""))
{
}

CDlg_Estate::~CDlg_Estate()
{
}

void CDlg_Estate::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	DDX_Control(pDX, IDC_LIST1, m_listEstate);
	DDX_Control(pDX, IDC_CHECK1, m_chkAbsolute);
	DDX_Control(pDX, IDC_CHECK2, m_chkperm2);
	DDX_Control(pDX, IDC_CHECK3, m_chkEnergy);
	DDX_Control(pDX, IDC_CHECK4, m_chkCost);
	DDX_Control(pDX, IDC_CHECK5, m_chkEmissions);
	DDX_Control(pDX, IDC_STATIC_co2, m_lableCO2small);
	DDX_Control(pDX, IDC_EDIT_NUM, m_editNumOfDwellings);
	DDX_Control(pDX, IDC_COMBO_CASE, m_comboCase);
	DDX_Text(pDX, IDC_EDIT_NUM, str_editNumOfDwellings);
	DDX_CBString(pDX, IDC_COMBO_CASE, str_comboCase);
	DDX_Control(pDX, IDC_STATIC_1, m_lableNumDwellingds);
	DDX_Control(pDX, IDC_STATIC_2, m_labelCase);
	DDX_Control(pDX, IDC_STATIC_3, m_labelDwellingName);
	DDX_Control(pDX, IDC_EDIT_NAME, m_editNameOfDwelling);
	DDX_Text(pDX, IDC_EDIT_NAME, str_editNameOfDwelling);
}


BEGIN_MESSAGE_MAP(CDlg_Estate, CDialog)
	ON_BN_CLICKED(IDC_CHECK1, OnBnClickedCheck1)
	ON_BN_CLICKED(IDC_CHECK3, OnBnClickedCheck3)
	ON_BN_CLICKED(IDC_CHECK4, OnBnClickedCheck4)
	ON_BN_CLICKED(IDC_CHECK5, OnBnClickedCheck5)
	ON_BN_CLICKED(IDC_CHECK2, OnBnClickedCheck2)
	//ON_NOTIFY(LVN_ITEMCHANGED, IDC_LIST1, &CDlg_Estate::OnLvnItemchangedList1)
	ON_BN_CLICKED(IDC_BUTTON_export, &CDlg_Estate::OnBnClickedButtonexport)
	ON_BN_CLICKED(IDC_BUTTON_SAVE_ESTATE, &CDlg_Estate::OnBnClickedButtonSaveEstate)
	ON_EN_CHANGE(IDC_EDIT_NUM, &CDlg_Estate::OnEnChangeEditNum)
	ON_CBN_SELCHANGE(IDC_COMBO_CASE, &CDlg_Estate::OnCbnSelchangeComboCase)
	ON_BN_CLICKED(IDC_BUTTON_DELETE, &CDlg_Estate::OnBnClickedButtonDelete)
	ON_EN_CHANGE(IDC_EDIT_NAME, &CDlg_Estate::OnEnChangeEditName)
	ON_BN_CLICKED(IDC_BUTTON_UPDATE, &CDlg_Estate::OnBnClickedButtonUpdate)
	ON_NOTIFY(LVN_ITEMACTIVATE, IDC_LIST1, &CDlg_Estate::OnLvnItemActivateList1)
END_MESSAGE_MAP()


CString displayForList;

//void PrettyPrintNumbers(CString srcValue, CString destStr )
static void PrettyPrintNumbers(CString srcValue)
{
	// Convert the number into a string
	// Copy this string char by char into another buffer starting from the last
	// digit - BUT - after every third character, insert a comma
	int i = 0; 
	int size = 0;

	CString str;
	CString number;
	str = "100000000";
	
	// Now we will use the 'insert' method of str     
	//size = str.GetLength();
	size = srcValue.GetLength();

	if(size>=4 && size<=6)
	{
		for ( i=size-3; i>0; i = i-3 )
		{
			//str.Insert(i,',');
			srcValue.Insert(i,',');
		}
	}
	else if(size>=7 && size<=9)
	{
		for ( i=size-3; i>0; i = i-3 )
		{
			srcValue.Insert(i, ',');
		}
	}
	else if(size>=10)
	{
		for ( i=size-3; i>0; i = i-3 )
		{
			srcValue.Insert(i, ',');
		}
	}
	displayForList = srcValue;
}

// CDlg_Estate message handlers
BOOL CDlg_Estate::OnInitDialog()
{
	CDialog::OnInitDialog();
	
	//-----------------------------------------------------
	// LABLES
	//-----------------------------------------------------
	CFont *m_FontSmall = new CFont;
	m_FontSmall->CreatePointFont(51, "Arial");

	m_lableCO2small.SetFont(m_FontSmall); 

	m_chkEnergy.SetCheck(1);
	m_chkAbsolute.SetCheck(1);

	m_editNumOfDwellings.SetReadOnly(TRUE);	
	m_comboCase.EnableWindow(FALSE);
	m_lableNumDwellingds.EnableWindow(FALSE);
	m_labelCase.EnableWindow(FALSE);
	m_labelDwellingName.EnableWindow(FALSE);
	m_editNameOfDwelling.EnableWindow(FALSE);

	//-----------------------------------------------------
	// Add titles for list
	//-----------------------------------------------------
	/*m_listEstate.InsertColumn(0, "Name", LVCFMT_LEFT, 130);
	m_listEstate.InsertColumn(1, "Number of dwellings", LVCFMT_LEFT, 50);
	m_listEstate.InsertColumn(2, "Case", LVCFMT_LEFT, 101);
	m_listEstate.InsertColumn(3, "Space Heating Supply ", LVCFMT_LEFT, 75);
	m_listEstate.InsertColumn(4, "Space Coolong Supply" , LVCFMT_LEFT, 72);
	m_listEstate.InsertColumn(5, "Domestic Hot Water", LVCFMT_LEFT, 72);
	m_listEstate.InsertColumn(6, "Lighting", LVCFMT_LEFT, 72);
	m_listEstate.InsertColumn(7, "Auxilary Electricity", LVCFMT_LEFT, 72);
	m_listEstate.InsertColumn(8, "Total Electricity Supply", LVCFMT_LEFT, 72);	
	m_listEstate.InsertColumn(9, "Primary Fuel", LVCFMT_LEFT, 75);	
	m_listEstate.InsertColumn(10, "Secondary Fuel", LVCFMT_LEFT, 72);	
	m_listEstate.InsertColumn(11, "LZCT Electricity Sold", LVCFMT_LEFT, 72);
	m_listEstate.InsertColumn(12, "LZCT Electricity Displaced", LVCFMT_LEFT, 66);*/

	m_listEstate.InsertColumn(0, " ", LVCFMT_LEFT, 129);
	m_listEstate.InsertColumn(1, " ", LVCFMT_LEFT, 52);
	m_listEstate.InsertColumn(2, " ", LVCFMT_LEFT, 101);
	m_listEstate.InsertColumn(3, " ", LVCFMT_LEFT, 76);
	m_listEstate.InsertColumn(4, " " , LVCFMT_LEFT, 73);
	m_listEstate.InsertColumn(5, " ", LVCFMT_LEFT, 73);
	m_listEstate.InsertColumn(6, " ", LVCFMT_LEFT, 73);
	m_listEstate.InsertColumn(7, " ", LVCFMT_LEFT, 73);
	m_listEstate.InsertColumn(8, " ", LVCFMT_LEFT, 73);	
	m_listEstate.InsertColumn(9, " ", LVCFMT_LEFT, 76);	
	m_listEstate.InsertColumn(10, " ", LVCFMT_LEFT, 73);	
	m_listEstate.InsertColumn(11, " ", LVCFMT_LEFT, 73);
	m_listEstate.InsertColumn(12, " ", LVCFMT_LEFT, 67);

	DisplayEstateList();

	return TRUE;
}

void CDlg_Estate::DisplayEstateList()
{
	//-----------------------
	// ESTATE DATA LIST
	//-----------------------
	int nItem = 0;
	int indexLastItem = 0;
	CString tempStr;
	double tempDouble;

	CString unitToDisplay;
	CString unitToDisplay2;
	CString str_totalSpaceHtSupply;
	CString str_totalSpaceCoolingSupply;
	CString str_domesticHotWaterSupply;
	CString str_lightElectricity;
	CString str_auxillaryElectricity ;
	CString str_totalElectricalSupply;
	CString str_mainSpaceHtSupply;
	CString str_secSpaceHtSupply;
	CString str_LZCT_elecSold ;
	CString str_LZCT_elecDisplaced;

	int numOfDwellingsEstate = 0;
	double totalSpaceHtSupplyEstate = 0;
	double totalSpaceCoolingSupplyEstate = 0;
	double domesticHotWaterSupplyEstate = 0;
	double lightElectricityEstate = 0;
	double auxillaryElectricityEstate = 0;
	double totalElectricalSupplyEstate = 0;
	double mainSpaceHtSupplyEstate = 0;
	double secSpaceHtSupplyEstate = 0;
	double LZCT_elecSoldEstate = 0;
	double LZCT_elecDisplacedEstate = 0;

	CString totalSpaceHtSupply_disp;
	CString totalSpaceCoolingSupply_disp;
	CString domesticHotWaterSupply_disp;
	CString lightElectricity_disp;
	CString auxillaryElectricity_disp;
	CString totalElectricalSupply_disp;
	CString mainSpaceHtSupply_disp;
	CString secSpaceHtSupply_disp;
	CString LZCT_elecSold_disp;
	CString LZCT_elecDisplaced_disp;

	//-------------------------------------------------------------------
	// Establish from check boxes which units to display
	//-------------------------------------------------------------------	
	if(m_chkEnergy.GetCheck() == 1)
	{
		unitToDisplay = "kWh";
	}
	else if(m_chkCost.GetCheck() == 1)
	{
		unitToDisplay = "£";
	}
	else if(m_chkEmissions.GetCheck() == 1)
	{
		unitToDisplay = "kgCO2";
	}

	//-------------------------------------------------------------------
	// Display either absoulte or normalized (by floor area values)
	//-------------------------------------------------------------------	
	if(m_chkperm2.GetCheck() == 1)
	{
		unitToDisplay2 = "/m²";
	}
	else
	{
		unitToDisplay2.Empty();
	}
	
	// Delete list 
	m_listEstate.DeleteAllItems();

	unsigned int i = 0;
	i = EstateDataValues.size();

	for( i=0; i < EstateDataValues.size(); i++)
	{
		nItem = m_listEstate.InsertItem( LVIF_TEXT|LVIF_STATE, i, EstateDataValues[i].projectFileNameNoExt, 
			0, LVIS_SELECTED,
			0, 0);

		tempStr.Format("%d",EstateDataValues[i].numOfDwellings);
		m_listEstate.SetItemText(nItem, 1,  tempStr);
		m_listEstate.SetItemText(nItem, 2,  EstateDataValues[i].caseOfDwellings);

		if(unitToDisplay == "kWh")
		{
			str_totalSpaceHtSupply.Format("%.0f",(EstateDataValues[i].numOfDwellings * EstateDataValues[i].totalSpaceHtSupply));
			str_totalSpaceCoolingSupply.Format("%.0f",(EstateDataValues[i].numOfDwellings *EstateDataValues[i].totalSpaceCoolingSupply));
			str_domesticHotWaterSupply.Format("%.0f",(EstateDataValues[i].numOfDwellings *EstateDataValues[i].domesticHotWaterSupply));
			str_lightElectricity.Format("%.0f",(EstateDataValues[i].numOfDwellings *EstateDataValues[i].lightElectricity));
			str_auxillaryElectricity.Format("%.0f",(EstateDataValues[i].numOfDwellings *EstateDataValues[i].auxillaryElectricity));
			str_totalElectricalSupply.Format("%.0f",(EstateDataValues[i].numOfDwellings *EstateDataValues[i].totalElectricalSupply));
			str_mainSpaceHtSupply.Format("%.0f",(EstateDataValues[i].numOfDwellings *EstateDataValues[i].primaryFuelUsed));
			str_secSpaceHtSupply.Format("%.0f",(EstateDataValues[i].numOfDwellings *EstateDataValues[i].secFuelUsed));
			str_LZCT_elecSold.Format("%.0f",(EstateDataValues[i].numOfDwellings *EstateDataValues[i].LZCT_elecSold));
			str_LZCT_elecDisplaced.Format("%.0f",(EstateDataValues[i].numOfDwellings *EstateDataValues[i].LZCT_elecDisplaced));
		}
		else if(unitToDisplay == "kgCO2")
		{
			str_totalSpaceHtSupply.Format("%.0f",(EstateDataValues[i].numOfDwellings) *(EstateDataValues[i].mainSpaceHtSupply_Emm+ EstateDataValues[i].secSpaceHtSupply_Emm));
			str_totalSpaceCoolingSupply.Format("%.0f",(EstateDataValues[i].numOfDwellings *EstateDataValues[i].totalSpaceCoolingSupply_Emm));
			str_domesticHotWaterSupply.Format("%.0f",(EstateDataValues[i].numOfDwellings *EstateDataValues[i].domesticHotWaterSupply_Emm));
			str_lightElectricity.Format("%.0f",(EstateDataValues[i].numOfDwellings *EstateDataValues[i].lightElectricity_Emm));
			str_auxillaryElectricity.Format("%.0f",(EstateDataValues[i].numOfDwellings *EstateDataValues[i].auxillaryElectricity_Emm));
			str_totalElectricalSupply.Format("%.0f",(EstateDataValues[i].numOfDwellings )*(EstateDataValues[i].lightElectricity_Emm + EstateDataValues[i].auxillaryElectricity_Emm));
			str_mainSpaceHtSupply.Format("%.0f",(EstateDataValues[i].numOfDwellings *EstateDataValues[i].primaryFuelUsed_Emm));
			str_secSpaceHtSupply.Format("%.0f",(EstateDataValues[i].numOfDwellings *EstateDataValues[i].secFuelUsed_Emm));
			str_LZCT_elecSold.Format("%.0f",(EstateDataValues[i].numOfDwellings *EstateDataValues[i].LZCTelecSold_Emm));
			str_LZCT_elecDisplaced.Format("%.0f",(EstateDataValues[i].numOfDwellings * EstateDataValues[i].LZCTelecDisp_Emm));
		}
		else if(unitToDisplay == "£")
		{
			str_totalSpaceHtSupply.Format("%.0f",(EstateDataValues[i].numOfDwellings) * (EstateDataValues[i].mainSpaceHtSupply_fuelCost+ EstateDataValues[i].secSpaceHtSupply_fuelCost));
			str_totalSpaceCoolingSupply.Format("%.0f",(EstateDataValues[i].numOfDwellings * EstateDataValues[i].totalSpaceCoolingSupply_fuelCost));
			str_domesticHotWaterSupply.Format("%.0f",(EstateDataValues[i].numOfDwellings * EstateDataValues[i].domesticHotWaterSupply_fuelCost));
			str_lightElectricity.Format("%.0f",(EstateDataValues[i].numOfDwellings * EstateDataValues[i].lightElectricity_fuelCost));
			str_auxillaryElectricity.Format("%.0f",(EstateDataValues[i].numOfDwellings * EstateDataValues[i].auxillaryElectricity_fuelCost));
			str_totalElectricalSupply.Format("%.0f",(EstateDataValues[i].numOfDwellings )* (EstateDataValues[i].lightElectricity_fuelCost + EstateDataValues[i].auxillaryElectricity_fuelCost));
			str_mainSpaceHtSupply.Format("%.0f",(EstateDataValues[i].numOfDwellings * EstateDataValues[i].primaryFuelUsed_fuelCost));
			str_secSpaceHtSupply.Format("%.0f",(EstateDataValues[i].numOfDwellings * EstateDataValues[i].secFuelUsed_fuelCost));
			str_LZCT_elecSold.Format("%.0f",(EstateDataValues[i].numOfDwellings * EstateDataValues[i].LZCTelecSold_fuelCost));
			str_LZCT_elecDisplaced.Format("%.0f",(EstateDataValues[i].numOfDwellings * EstateDataValues[i].LZCTelecDisp_fuelCost));
		}

		if(unitToDisplay2  == "/m²") 
		{
			tempDouble = ((atof(str_totalSpaceHtSupply))/EstateDataValues[i].TFA)/EstateDataValues[i].numOfDwellings;
			str_totalSpaceHtSupply.Format("%.0f",tempDouble);

			tempDouble = ((atof(str_totalSpaceCoolingSupply))/EstateDataValues[i].TFA)/EstateDataValues[i].numOfDwellings;
			str_totalSpaceCoolingSupply.Format("%.0f",tempDouble);

			tempDouble = ((atof(str_domesticHotWaterSupply))/EstateDataValues[i].TFA)/EstateDataValues[i].numOfDwellings;
			str_domesticHotWaterSupply.Format("%.0f",tempDouble);

			tempDouble = ((atof(str_lightElectricity))/EstateDataValues[i].TFA)/EstateDataValues[i].numOfDwellings;
			str_lightElectricity.Format("%.0f",tempDouble);

			tempDouble = ((atof(str_auxillaryElectricity))/EstateDataValues[i].TFA)/EstateDataValues[i].numOfDwellings;
			str_auxillaryElectricity.Format("%.0f",tempDouble);

			tempDouble = ((atof(str_totalElectricalSupply))/EstateDataValues[i].TFA)/EstateDataValues[i].numOfDwellings;
			str_totalElectricalSupply.Format("%.0f",tempDouble);

			tempDouble = ((atof(str_mainSpaceHtSupply))/EstateDataValues[i].TFA)/EstateDataValues[i].numOfDwellings;
			str_mainSpaceHtSupply.Format("%.0f",tempDouble);

			tempDouble = ((atof(str_secSpaceHtSupply))/EstateDataValues[i].TFA)/EstateDataValues[i].numOfDwellings;
			str_secSpaceHtSupply.Format("%.0f",tempDouble);

			tempDouble = ((atof(str_LZCT_elecSold))/EstateDataValues[i].TFA)/EstateDataValues[i].numOfDwellings;
			str_LZCT_elecSold.Format("%.0f",tempDouble);

			tempDouble = ((atof(str_LZCT_elecDisplaced))/EstateDataValues[i].TFA)/EstateDataValues[i].numOfDwellings;
			str_LZCT_elecDisplaced.Format("%.0f",tempDouble);
		}

		PrettyPrintNumbers(str_totalSpaceHtSupply);
		m_listEstate.SetItemText(nItem, 3,  displayForList);
		
		PrettyPrintNumbers(str_totalSpaceCoolingSupply);
		m_listEstate.SetItemText(nItem, 4,  displayForList);

		PrettyPrintNumbers(str_domesticHotWaterSupply);
		m_listEstate.SetItemText(nItem, 5,  displayForList);

		PrettyPrintNumbers(str_lightElectricity);
		m_listEstate.SetItemText(nItem, 6,  displayForList);

		PrettyPrintNumbers(str_auxillaryElectricity);
		m_listEstate.SetItemText(nItem, 7,  displayForList);

		PrettyPrintNumbers(str_totalElectricalSupply);
		m_listEstate.SetItemText(nItem, 8,  displayForList);

		PrettyPrintNumbers(str_mainSpaceHtSupply);
		m_listEstate.SetItemText(nItem, 9,  displayForList);

		PrettyPrintNumbers(str_secSpaceHtSupply);
		m_listEstate.SetItemText(nItem, 10,  displayForList);

		PrettyPrintNumbers(str_LZCT_elecSold);
		m_listEstate.SetItemText(nItem, 11,  displayForList);

		PrettyPrintNumbers(str_LZCT_elecDisplaced);
		m_listEstate.SetItemText(nItem, 12,  displayForList);

		//m_listEstate.SetItemText(nItem, 3,  str_totalSpaceHtSupply);
		//m_listEstate.SetItemText(nItem, 4,  str_totalSpaceCoolingSupply);
		//m_listEstate.SetItemText(nItem, 5,  str_domesticHotWaterSupply);
		//m_listEstate.SetItemText(nItem, 6,  str_lightElectricity);
		//m_listEstate.SetItemText(nItem, 7,  str_auxillaryElectricity);
		//m_listEstate.SetItemText(nItem, 8,  str_totalElectricalSupply);
		//m_listEstate.SetItemText(nItem, 9, str_mainSpaceHtSupply);
		//m_listEstate.SetItemText(nItem, 10, str_secSpaceHtSupply);
		//m_listEstate.SetItemText(nItem, 11, str_LZCT_elecSold);	
		//m_listEstate.SetItemText(nItem, 12, str_LZCT_elecDisplaced);	

		numOfDwellingsEstate          = numOfDwellingsEstate         + EstateDataValues[i].numOfDwellings;
		totalSpaceHtSupplyEstate	  = totalSpaceHtSupplyEstate     + atof(str_totalSpaceHtSupply);
		totalSpaceCoolingSupplyEstate = totalSpaceCoolingSupplyEstate+ atof(str_totalSpaceCoolingSupply);
		domesticHotWaterSupplyEstate  = domesticHotWaterSupplyEstate + atof(str_domesticHotWaterSupply);
		lightElectricityEstate		  = lightElectricityEstate       + atof(str_lightElectricity);
		auxillaryElectricityEstate    = auxillaryElectricityEstate   + atof(str_auxillaryElectricity);
		totalElectricalSupplyEstate   = totalElectricalSupplyEstate  + atof(str_totalElectricalSupply);
		mainSpaceHtSupplyEstate       = mainSpaceHtSupplyEstate      + atof(str_mainSpaceHtSupply);
		secSpaceHtSupplyEstate        = secSpaceHtSupplyEstate       + atof(str_secSpaceHtSupply);
		LZCT_elecSoldEstate           = LZCT_elecSoldEstate          + atof(str_LZCT_elecSold);
		LZCT_elecDisplacedEstate      = LZCT_elecDisplacedEstate     + atof(str_LZCT_elecDisplaced);		
	}

	//-----------------------------------------------------------
	// DISPLAY TOTAL FOR ESTATE
	//-----------------------------------------------------------
	if(nItem >= 0)
	{
		indexLastItem = nItem+1;

		m_listEstate.InsertItem( LVIF_TEXT|LVIF_STATE, indexLastItem, "Total for estate", 
			0, LVIS_SELECTED,
			0, 0);

		tempStr.Format("%d",numOfDwellingsEstate);
		m_listEstate.SetItemText(indexLastItem, 1,  tempStr);

		m_listEstate.SetItemText(indexLastItem, 2,  " ");

		tempStr.Format("%.0f",totalSpaceHtSupplyEstate);
		PrettyPrintNumbers(tempStr);
		m_listEstate.SetItemText(indexLastItem, 3,  displayForList);

		tempStr.Format("%.0f",totalSpaceCoolingSupplyEstate);
		PrettyPrintNumbers(tempStr);
		m_listEstate.SetItemText(indexLastItem, 4,  displayForList);
	
		tempStr.Format("%.0f",domesticHotWaterSupplyEstate);
		PrettyPrintNumbers(tempStr);
		m_listEstate.SetItemText(indexLastItem, 5,  displayForList);

		tempStr.Format("%.0f",lightElectricityEstate);
		PrettyPrintNumbers(tempStr);
		m_listEstate.SetItemText(indexLastItem, 6,  displayForList);

		tempStr.Format("%.0f",auxillaryElectricityEstate);
		PrettyPrintNumbers(tempStr);
		m_listEstate.SetItemText(indexLastItem, 7,  displayForList);

		tempStr.Format("%.0f",totalElectricalSupplyEstate);
		PrettyPrintNumbers(tempStr);
		m_listEstate.SetItemText(indexLastItem, 8,  displayForList);

		tempStr.Format("%.0f",mainSpaceHtSupplyEstate);
		PrettyPrintNumbers(tempStr);
		m_listEstate.SetItemText(indexLastItem, 9,  displayForList);

		tempStr.Format("%.0f",secSpaceHtSupplyEstate);
		PrettyPrintNumbers(tempStr);
		m_listEstate.SetItemText(indexLastItem, 10,  displayForList);

		tempStr.Format("%.0f",LZCT_elecSoldEstate);
		PrettyPrintNumbers(tempStr);
		m_listEstate.SetItemText(indexLastItem, 11,  displayForList);	

		tempStr.Format("%.0f",LZCT_elecDisplacedEstate);
		PrettyPrintNumbers(tempStr);
		m_listEstate.SetItemText(indexLastItem, 12,  displayForList);;	


		/*tempStr.Format("%.0f",totalSpaceHtSupplyEstate);
		m_listEstate.SetItemText(indexLastItem, 3,  tempStr);

		tempStr.Format("%.0f",totalSpaceCoolingSupplyEstate);
		m_listEstate.SetItemText(indexLastItem, 4,  tempStr);
	
		tempStr.Format("%.0f",domesticHotWaterSupplyEstate);
		m_listEstate.SetItemText(indexLastItem, 5,  tempStr);

		tempStr.Format("%.0f",lightElectricityEstate);
		m_listEstate.SetItemText(indexLastItem, 6,  tempStr);

		tempStr.Format("%.0f",auxillaryElectricityEstate);
		m_listEstate.SetItemText(indexLastItem, 7,  tempStr);

		tempStr.Format("%.0f",totalElectricalSupplyEstate);
		m_listEstate.SetItemText(indexLastItem, 8,  tempStr);

		tempStr.Format("%.0f",mainSpaceHtSupplyEstate);
		m_listEstate.SetItemText(indexLastItem, 9, tempStr);

		tempStr.Format("%.0f",secSpaceHtSupplyEstate);
		m_listEstate.SetItemText(indexLastItem, 10, tempStr);

		tempStr.Format("%.0f",LZCT_elecSoldEstate);
		m_listEstate.SetItemText(indexLastItem, 11, tempStr);	

		tempStr.Format("%.0f",LZCT_elecDisplacedEstate);
		m_listEstate.SetItemText(indexLastItem, 12, tempStr);	*/
	}
}

void CDlg_Estate::OnBnClickedCheck1()
{
	if(m_chkAbsolute.GetCheck() == 1)
	{
		m_chkperm2.SetCheck(0);
	}
	
	DisplayEstateList();
}

void CDlg_Estate::OnBnClickedCheck3()
{
	if(m_chkEnergy.GetCheck() == 1)
	{
		m_chkCost.SetCheck(0);
		m_chkEmissions.SetCheck(0);
	}

	if((m_chkEnergy.GetCheck() == 0) &&
	   (m_chkEmissions.GetCheck() == 0) &&
	   (m_chkCost.GetCheck() == 0))
	{
		m_chkEnergy.SetCheck(1);		
	}

	DisplayEstateList();
}

void CDlg_Estate::OnBnClickedCheck4()
{
	if(m_chkCost.GetCheck() == 1)
	{
		m_chkEnergy.SetCheck(0);
		m_chkEmissions.SetCheck(0);
	}

	if((m_chkEnergy.GetCheck() == 0) &&
	   (m_chkEmissions.GetCheck() == 0) &&
	   (m_chkCost.GetCheck() == 0))
	{
		m_chkEnergy.SetCheck(1);		
	}
	DisplayEstateList();
}

void CDlg_Estate::OnBnClickedCheck5()
{
	if(m_chkEmissions.GetCheck() == 1)
	{
		m_chkEnergy.SetCheck(0);
		m_chkCost.SetCheck(0);
	}

	if((m_chkEnergy.GetCheck() == 0) &&
	   (m_chkEmissions.GetCheck() == 0) &&
	   (m_chkCost.GetCheck() == 0))
	{
		m_chkEnergy.SetCheck(1);		
	}

	DisplayEstateList();
}

void CDlg_Estate::OnBnClickedCheck2()
{
	if(m_chkperm2.GetCheck() == 1)
	{
		m_chkAbsolute.SetCheck(0);
	}
	DisplayEstateList();
}













void CDlg_Estate::OnEnChangeEditName()
{
	// TODO:  If this is a RICHEDIT control, the control will not
	// send this notification unless you override the CDialog::OnInitDialog()
	// function and call CRichEditCtrl().SetEventMask()
	// with the ENM_CHANGE flag ORed into the mask.

	// TODO:  Add your control notification handler code here
}














