// Dlg_ListOpenings.cpp : implementation file
//

#include "stdafx.h"
#include "SAPP1.h"
#include "SAPP1Dlg.h"
#include "Dlg_ListOpenings.h"
#include <vector>


using namespace std;
// CDlg_ListOpenings dialog

IMPLEMENT_DYNAMIC(CDlg_ListOpenings, CDialog)
CDlg_ListOpenings::CDlg_ListOpenings(CWnd* pParent /*=NULL*/)
	: CDialog(CDlg_ListOpenings::IDD, pParent)
{
}

CDlg_ListOpenings::~CDlg_ListOpenings()
{
}

void CDlg_ListOpenings::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	DDX_Control(pDX, IDC_LIST_OPENINGS, m_listOpenings);
}


BEGIN_MESSAGE_MAP(CDlg_ListOpenings, CDialog)
	ON_BN_CLICKED(IDC_BUTTON1, OnBnClickedButton1)
	ON_BN_CLICKED(IDOK, OnBnClickedOk)
END_MESSAGE_MAP()


// CDlg_ListOpenings message handlers


//vector <openingsList> openingsList1;

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

	unsigned int i = 0;
	unsigned int i_test = 0;
	int nItem = 0;
	int lineNum=0;
	CString tempString;
	tempString = "checK";	
	
	//----------------------------------------------------
	// Add headings to list
	//----------------------------------------------------
	m_listOpenings.InsertColumn(0, "Name", LVCFMT_CENTER, 100);
	m_listOpenings.InsertColumn(1, "Reference", LVCFMT_CENTER, 100);
	m_listOpenings.InsertColumn(2, "Type", LVCFMT_CENTER, 100);
	m_listOpenings.InsertColumn(3, "Frame", LVCFMT_CENTER, 70);
	m_listOpenings.InsertColumn(4, "Glazing", LVCFMT_CENTER, 50);
	m_listOpenings.InsertColumn(5, "Width", LVCFMT_CENTER, 50);
	m_listOpenings.InsertColumn(6, "Height", LVCFMT_CENTER, 50);
	m_listOpenings.InsertColumn(7, "Orientation", LVCFMT_CENTER, 80);
	m_listOpenings.InsertColumn(8, "U-value", LVCFMT_CENTER, 65);
	m_listOpenings.InsertColumn(9, "Location", LVCFMT_CENTER, 105);

	i_test = openingListData_New.size();
	//----------------------------------------------------
	// Write data to list
	//----------------------------------------------------
	for( i=0; i < openingListData_New.size(); i++)
	{
		nItem = m_listOpenings.InsertItem( LVIF_TEXT|LVIF_STATE, i, openingListData_New[i].openingName, 
			0, LVIS_SELECTED,
			0, 0);
		m_listOpenings.SetItemText(nItem, 1,  openingListData_New[i].openingRef);
		tempString = openingListData_New[i].openingRef;

		m_listOpenings.SetItemText(nItem, 2,  openingListData_New[i].openingGlzType);
		tempString = openingListData_New[i].openingGlzType;

		m_listOpenings.SetItemText(nItem, 3,  openingListData_New[i].openingFrame);
		tempString = openingListData_New[i].openingFrame;

		m_listOpenings.SetItemText(nItem, 4,  openingListData_New[i].openingGlzType);
		tempString = openingListData_New[i].openingFrame;

		tempString.Format("%.2f",openingListData_New[i].openingWidth);
		m_listOpenings.SetItemText(nItem, 5,  tempString);

		tempString.Format("%.2f",openingListData_New[i].openingHeight);
		m_listOpenings.SetItemText(nItem, 6,  tempString);

		m_listOpenings.SetItemText(nItem, 7,  openingListData_New[i].openingOrientation);
		tempString = openingListData_New[i].openingOrientation;

		tempString.Format("%.2f",openingListData_New[i].openingUvalue);
		m_listOpenings.SetItemText(nItem, 8,  tempString);	

		m_listOpenings.SetItemText(nItem, 9,  openingListData_New[i].openingLocationName);	
	}

	//UpdateData(FALSE);

	return TRUE;
}


void CDlg_ListOpenings::OnBnClickedButton1()
{
	POSITION itemIndex = 0;
	int vectorIndex;
	unsigned int i = 0;

	//-----------------------------------------------------------------------------
	// Get the item index of the item selected
	itemIndex = m_listOpenings.GetFirstSelectedItemPosition();

	// Check if user has selected any item to delete, if no item is selected
	// prompt the user to select an item
	if (itemIndex == 0)
	{
		MessageBox("Select an item to delete..", "Warning", MB_OK);
	}

	// If an item has been selected by the user to delete, confirm deletion
	else
	{
		//-----------------------------------------------------------------------------
		// Confirm item deletion
		int msgboxID = MessageBox("Are you sure you want to delete this opening?", "Warning", MB_OKCANCEL);

		//-----------------------------------------------------------------------------
		// If OK, delete the item, else do nothing
		switch (msgboxID)
		{
		case IDOK:
			//------------------------------------------
			// delete item from list
			m_listOpenings.DeleteItem(int(itemIndex)-1);
			vectorIndex = int(itemIndex)-1;

			//------------------------------------------
			// delete data from vector
			openingListData_New.erase(openingListData_New.begin()+vectorIndex); 

		case IDCANCEL:
			break;
		default:
			break;			
		}	
	}
}

void CDlg_ListOpenings::AddDataToOpenings()
{
}

void CDlg_ListOpenings::OnBnClickedOk()
{
	OnOK();
}


