// DialogAdmin.cpp : implementation file
//

#include "stdafx.h"
#include "POSystems.h"
#include "DialogAdmin.h"
#include "DialogConfirm.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// DialogAdmin dialog


DialogAdmin::DialogAdmin(CWnd* pParent /*=NULL*/)
	: CDialog(DialogAdmin::IDD, pParent)
{
	//{{AFX_DATA_INIT(DialogAdmin)
	m_EmpID = _T("");
	m_AddStaff = -1;
	m_Passwd = _T("");
	m_Password = _T("");
	m_newEmpID = _T("");
	m_newCost = 0.0f;
	m_Item = _T("");
	m_oldCost = 0.0f;
	//}}AFX_DATA_INIT
}


void DialogAdmin::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(DialogAdmin)
	DDX_Text(pDX, IDC_EDIT_EmpID, m_EmpID);
	DDX_Radio(pDX, IDC_RADIO_MANAGER, m_AddStaff);
	DDX_Text(pDX, IDC_EDIT_PASSWD, m_Passwd);
	DDV_MaxChars(pDX, m_Passwd, 8);
	DDX_Text(pDX, IDC_EDIT_PASSWORD, m_Password);
	DDV_MaxChars(pDX, m_Password, 8);
	DDX_Text(pDX, IDC_EDIT_NEWEMPID, m_newEmpID);
	DDV_MaxChars(pDX, m_newEmpID, 8);
	DDX_Text(pDX, IDC_EDIT_NEWCOST, m_newCost);
	DDV_MinMaxFloat(pDX, m_newCost, 0.f, 1000.f);
	DDX_CBString(pDX, IDC_COMBO_ITEM, m_Item);
	DDX_Text(pDX, IDC_EDIT_OLDCOST, m_oldCost);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(DialogAdmin, CDialog)
	//{{AFX_MSG_MAP(DialogAdmin)
	ON_BN_CLICKED(IDC_BUTTON_ADD, OnButtonAdd)
	ON_BN_CLICKED(IDC_CANCEL, OnClickedCancel)
	ON_CBN_SELCHANGE(IDC_COMBO_ITEM, OnSelchangeComboItem)
	ON_BN_CLICKED(IDC_BUTTON_RESET2, OnButtonReset2)
	ON_BN_CLICKED(IDC_BUTTON_RESET, OnButtonReset)
	ON_BN_CLICKED(IDC_BUTTON_UPDATE, OnButtonUpdate)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// DialogAdmin message handlers
void DialogAdmin::OnOK() 
{

}

void DialogAdmin::OnButtonAdd() 
{
	UpdateData(TRUE);
	if ((m_AddStaff == -1)
		|| (m_newEmpID == "")
		|| (m_Password == "")
		|| (m_Passwd == ""))
	{
		AfxMessageBox("Please fill up all fields.");
	}

	if (m_Password != m_Passwd)
	{
		AfxMessageBox("Please re-enter password.");
		m_Password = "";
		m_Passwd = "";
		UpdateData(FALSE);
	}
	else
	{ if ((m_AddStaff != -1)
		&& (m_newEmpID != "")
		&& (m_Password != "")
		&& (m_Passwd != ""))
	{
		CDialogConfirm CMsgDlg;
		CMsgDlg.m_Msg = "Staff added.";
		if (CMsgDlg.DoModal() == IDOK)
		{
			m_Password = "";
			m_Passwd = "";
			m_AddStaff = -1;
			m_newEmpID = "";
			UpdateData(FALSE);
		}
	}
	}
}

void DialogAdmin::OnButtonReset2() 
{
	m_Password = "";
	m_Passwd = "";
	m_AddStaff = -1;
	m_newEmpID = "";
	UpdateData(FALSE);
}

void DialogAdmin::OnClickedCancel() 
{
	CDialog::OnOK();
	
}

void DialogAdmin::OnSelchangeComboItem() 
{
	UpdateData(TRUE);
	if (m_Item == "McChicken")
		m_oldCost = 2.50;
	if (m_Item == "Ham Burger")
		m_oldCost = 1.30;
	if (m_Item == "Cheese Burger")
		m_oldCost = 1.50;
	if (m_Item == "Chicken Meal")
		m_oldCost = 5.60;
	if (m_Item == "Ham Meal")
		m_oldCost = 5.30;
	if (m_Item == "Cheese Meal")
		m_oldCost = 5.00;
	if (m_Item == "Soft Drinks - R")
		m_oldCost = 1.60;
	if (m_Item == "Soft Drinks - M")
		m_oldCost = 1.80;
	if (m_Item == "Soft Drinks - L")
		m_oldCost = 2.10;
	if (m_Item == "French Fries - R")
		m_oldCost = 1.80;
	if (m_Item == "French Fries - M")
		m_oldCost = 2.00;
	if (m_Item == "French Fries - L")
		m_oldCost = 2.20;
	if (m_Item == "Dessert - R")
		m_oldCost = 1.50;
	if (m_Item == "Dessert - M")
		m_oldCost = 1.80;
	if (m_Item == "Dessert - L")
		m_oldCost = 1.20;
	if (m_Item == "Chicken Meal (Coupons)")
		m_oldCost = 5.00;
	if (m_Item == "Ham Meal (Coupons)")
		m_oldCost = 4.80;
	if (m_Item == "Cheese Meal (Coupons)")
		m_oldCost = 4.40;
	UpdateData(FALSE);
	
}

void DialogAdmin::OnButtonReset() 
{
	m_Item = "";
	m_oldCost = 0;
	m_newCost = 0;
	UpdateData(FALSE);
}

void DialogAdmin::OnButtonUpdate()
{
	UpdateData(TRUE);
	if ((m_Item == "")
		|| (m_newCost == 0)
		|| (m_oldCost == 0))
	{
		AfxMessageBox("Please fill up all fields.");
	}

	{ if (m_newCost < 1000)
		{
			if ((m_Item != "")
			&& (m_newCost != 0)
			&& (m_oldCost != 0))
			{
				CDialogConfirm CMsgDlg;
				CMsgDlg.m_Msg = "Product Information Changed.";
				if (CMsgDlg.DoModal() == IDOK)
				{
					m_Item = "";
					m_oldCost = 0;
					m_newCost = 0;
					UpdateData(FALSE);
				}
			}
		}
	}
}
