// CardDlg.cpp : implementation file
//

#include "stdafx.h"
#include "CgDemoBy5000asi.h"
#include "CardDlg.h"

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

/////////////////////////////////////////////////////////////////////////////
// CCardDlg dialog


CCardDlg::CCardDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CCardDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CCardDlg)
	m_iCardNum = -1;
	m_strEventName = _T("");
	//}}AFX_DATA_INIT
}


void CCardDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CCardDlg)
	DDX_CBIndex(pDX, IDC_CARD_NUM, m_iCardNum);
	DDX_Text(pDX, IDC_EVENT_NAME, m_strEventName);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CCardDlg, CDialog)
	//{{AFX_MSG_MAP(CCardDlg)
	ON_CBN_SELCHANGE(IDC_CARD_NUM, OnSelchangeCardNum)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CCardDlg message handlers

void CCardDlg::OnOK() 
{
	UpdateData();
	if(m_iCardNum < 0)
	{	AfxMessageBox(_T("A card must be selected!"), MB_OK | MB_ICONINFORMATION);
		return;
	}
	m_strEventName.TrimLeft();
	m_strEventName.TrimRight();
	if(m_strEventName.IsEmpty())
	{	AfxMessageBox(_T("The event name can not be empty!"), MB_OK | MB_ICONINFORMATION);
		return;
	}
	
	CDialog::OnOK();
}

BOOL CCardDlg::OnInitDialog() 
{
	CDialog::OnInitDialog();
	
	SetCtrl();
	
	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}

void CCardDlg::SetCtrl()
{
	UINT i;
	CString strItem;
	CComboBox * pBox;

	pBox = (CComboBox *)GetDlgItem(IDC_CARD_NUM);
	for(i = 0; i < giCardSum; i ++)
	{	strItem.Format(_T("Card %d"), i);
		pBox->AddString(strItem);
	}
	if (giCardSum != 0)
	{
		pBox->SetCurSel(0);
		OnSelchangeCardNum();
	}
}

void CCardDlg::OnSelchangeCardNum() 
{
	UpdateData();
	m_strEventName.Format(_T("Global Event %d"), m_iCardNum);
	UpdateData(false);
}
