// Dlg_AddToEstate.cpp : implementation file
//

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


// CDlg_AddToEstate dialog

IMPLEMENT_DYNAMIC(CDlg_AddToEstate, CDialog)
CDlg_AddToEstate::CDlg_AddToEstate(CWnd* pParent /*=NULL*/)
	: CDialog(CDlg_AddToEstate::IDD, pParent)
	, str_editNumOfSimilarDwellings(_T(""))
	, str_comboSelectCase(_T(""))
	, str_selectProject(_T(""))
{
}

CDlg_AddToEstate::~CDlg_AddToEstate()
{
}

void CDlg_AddToEstate::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	DDX_Control(pDX, IDC_COMBO1, m_comboSelectCase);
	DDX_Control(pDX, IDC_EDIT1, m_editNumOfSimilarDwellings);
	DDX_Text(pDX, IDC_EDIT1, str_editNumOfSimilarDwellings);
	DDX_CBString(pDX, IDC_COMBO1, str_comboSelectCase);
	DDX_Control(pDX, IDC_COMBO2, m_selectProject);
	DDX_CBString(pDX, IDC_COMBO2, str_selectProject);
}


BEGIN_MESSAGE_MAP(CDlg_AddToEstate, CDialog)
	ON_BN_CLICKED(IDOK, OnBnClickedOk)
	ON_CBN_SELCHANGE(IDC_COMBO1, OnCbnSelchangeCombo1)
	ON_EN_CHANGE(IDC_EDIT1, OnEnChangeEdit1)
	ON_CBN_SELCHANGE(IDC_COMBO2, OnCbnSelchangeCombo2)
END_MESSAGE_MAP()


// CDlg_AddToEstate message handlers
BOOL CDlg_AddToEstate::OnInitDialog()
{
	CDialog::OnInitDialog();

	// Display value for number of dwellings
	str_editNumOfSimilarDwellings.Format("%d",numOfDwellings);
	m_comboSelectCase.ResetContent();

	// Populate case box depending on how many cases the user
	// has established
	if((is_base_selected == false) &&
		(is_imp1_selected == false) &&
		(is_imp2_selected == false) &&
		(is_imp3_selected == false) &&
		(is_imp4_selected == false) &&
		(is_imp5_selected == false))
	{
		m_comboSelectCase.InsertString(0,"Base");
	}

	if(is_base_selected == true)
	{
		m_comboSelectCase.InsertString(0,"Base");
	}
	if(is_imp1_selected == true)
	{
		m_comboSelectCase.InsertString(1,"Improvement 1");
	}
	if(is_imp2_selected == true)
	{
		m_comboSelectCase.InsertString(2,"Improvement 2");
	}
	if(is_imp3_selected == true)
	{
		m_comboSelectCase.InsertString(3,"Improvement 3");
	}
	if(is_imp4_selected == true)
	{
		m_comboSelectCase.InsertString(4,"Improvement 4");
	}
	if(is_imp5_selected == true)
	{
		m_comboSelectCase.InsertString(5,"Improvement 5");
	}
	

	//-------------------------------------------------------------------------
	// Save name of project files in array, to be disppalyed in Add to Estate doalog
	m_selectProject.ResetContent();
	CString projectFielName;
	unsigned int i = 0;
	int index = 0;

	for(i = 0; i < projectFileNamesInTabs_1.size(); i++)
	{
		AfxExtractSubString(projectFielName, projectFileNamesInTabs_1[i].nameNoPath, 0, '.');
		m_selectProject.InsertString(index,projectFielName);
		index++;
	}
	
	str_selectProject = projectFileNameNoExt;
	m_selectProject.SelectString(0,str_selectProject);

	str_comboSelectCase = "Base";
	m_comboSelectCase.SetCurSel(0);
	UpdateData(FALSE);

	return TRUE;
}

void CDlg_AddToEstate::OnBnClickedOk()
{
	add_dwelling_to_estate = true;

	caseOfDwellings = str_comboSelectCase;
	numOfDwellings  = atoi(str_editNumOfSimilarDwellings);	

	OnOK();
}

void CDlg_AddToEstate::OnCbnSelchangeCombo1()
{
	UpdateData(TRUE);
}

void CDlg_AddToEstate::OnEnChangeEdit1()
{
	UpdateData(TRUE);
}

void CDlg_AddToEstate::OnCbnSelchangeCombo2()
{
	UpdateData(TRUE);
}
