// mymfc15View.cpp : implementation of the CMymfc15View class
//

#include "stdafx.h"
#include "mymfc15.h"

#include "mymfc15Doc.h"
#include "mymfc15View.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CMymfc15View

IMPLEMENT_DYNCREATE(CMymfc15View, CFormView)

BEGIN_MESSAGE_MAP(CMymfc15View, CFormView)
	//{{AFX_MSG_MAP(CMymfc15View)
	ON_BN_CLICKED(IDC_ENTER, OnEnter)
	ON_COMMAND(ID_EDIT_CLEAR_ALL, OnEditClearAll)
	ON_UPDATE_COMMAND_UI(ID_EDIT_CLEAR_ALL, OnUpdateEditClearAll)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CMymfc15View construction/destruction

CMymfc15View::CMymfc15View()
	: CFormView(CMymfc15View::IDD)
{
	//{{AFX_DATA_INIT(CMymfc15View)
	m_nGrade = 0;
	m_strName = _T("");
	//}}AFX_DATA_INIT
	// TODO: add construction code here

}

CMymfc15View::~CMymfc15View()
{
}

void CMymfc15View::DoDataExchange(CDataExchange* pDX)
{
	CFormView::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CMymfc15View)
	DDX_Text(pDX, IDC_GRADE, m_nGrade);
	DDV_MinMaxInt(pDX, m_nGrade, 0, 100);
	DDX_Text(pDX, IDC_NAME, m_strName);
	//}}AFX_DATA_MAP
}

BOOL CMymfc15View::PreCreateWindow(CREATESTRUCT& cs)
{
	// TODO: Modify the Window class or styles here by modifying
	//  the CREATESTRUCT cs

	return CFormView::PreCreateWindow(cs);
}

void CMymfc15View::OnInitialUpdate()
{
	// called on startup
    UpdateControlsFromDoc();
}

/////////////////////////////////////////////////////////////////////////////
// CMymfc15View diagnostics

#ifdef _DEBUG
void CMymfc15View::AssertValid() const
{
	CFormView::AssertValid();
}

void CMymfc15View::Dump(CDumpContext& dc) const
{
	CFormView::Dump(dc);
}

CMymfc15Doc* CMymfc15View::GetDocument() // non-debug version is inline
{
	ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CMymfc15Doc)));
	return (CMymfc15Doc*)m_pDocument;
}
#endif //_DEBUG

/////////////////////////////////////////////////////////////////////////////
// CMymfc15View message handlers

void CMymfc15View::OnEnter() 
{
	// TODO: Add your control notification handler code here
	CMymfc15Doc* pDoc = GetDocument();
    UpdateData(TRUE);
    pDoc->m_student.m_nGrade = m_nGrade;
    pDoc->m_student.m_strName = m_strName;
}

void CMymfc15View::OnEditClearAll() 
{
	// TODO: Add your command handler code here
	// "blank" student object
	GetDocument()->m_student = CStudent();
    UpdateControlsFromDoc();
}

void CMymfc15View::OnUpdateEditClearAll(CCmdUI* pCmdUI) 
{
	// TODO: Add your command update UI handler code here
	// blank?
	pCmdUI->Enable(GetDocument()->m_student != CStudent());	
}

void CMymfc15View::UpdateControlsFromDoc()
{
	// called from OnInitialUpdate and OnEditClearAll
    CMymfc15Doc* pDoc = GetDocument();
    m_nGrade = pDoc->m_student.m_nGrade;
    m_strName = pDoc->m_student.m_strName;

    UpdateData(FALSE); // calls DDX
}

