// Mymfc17Doc.cpp : implementation of the CMymfc17Doc class
//

#include "stdafx.h"
#include "mymfc17.h"

#include "Mymfc17Doc.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

//////////////////////////////////////////////////////////////////////
// CMymfc17Doc

IMPLEMENT_DYNCREATE(CMymfc17Doc, CDocument)

BEGIN_MESSAGE_MAP(CMymfc17Doc, CDocument)
    //{{AFX_MSG_MAP(CMymfc17Doc)
    ON_COMMAND(ID_EDIT_CLEAR_ALL, OnEditClearAll)
    ON_UPDATE_COMMAND_UI(ID_EDIT_CLEAR_ALL, OnUpdateEditClearAll)
	ON_UPDATE_COMMAND_UI(ID_FILE_SAVE, OnUpdateFileSave)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

//////////////////////////////////////////////////////////////////////
// CMymfc17Doc construction/destruction

CMymfc17Doc::CMymfc17Doc()
{
    TRACE("Entering CMymfc17Doc constructor\n");
#ifdef _DEBUG
    afxDump.SetDepth(1); // Ensure dump of list elements
#endif // _DEBUG
}

CMymfc17Doc::~CMymfc17Doc()
{
}

BOOL CMymfc17Doc::OnNewDocument()
{
    TRACE("Entering CMymfc17Doc::OnNewDocument\n");
    if (!CDocument::OnNewDocument())
        return FALSE;

    // TODO: add re-initialization code here
    // (SDI documents will reuse this document)

    return TRUE;
}
//////////////////////////////////////////////////////////////////////
// CMymfc17Doc serialization

void CMymfc17Doc::Serialize(CArchive& ar)
{
    TRACE("Entering CMymfc17Doc::Serialize\n");
    if (ar.IsStoring())
    {
        // TODO: add storing code here
		ar << m_strName << m_nGrade;
    }
    else
    {
        // TODO: add loading code here
		ar >> m_strName >> m_nGrade;
    }
    m_studentList.Serialize(ar);
}

//////////////////////////////////////////////////////////////////////
// CMymfc17Doc diagnostics

#ifdef _DEBUG
void CMymfc17Doc::AssertValid() const
{
    CDocument::AssertValid();
}

void CMymfc17Doc::Dump(CDumpContext& dc) const
{
    CDocument::Dump(dc);
    dc << "\n" << m_studentList << "\n";
}
#endif //_DEBUG

//////////////////////////////////////////////////////////////////////
// CMymfc17Doc commands

void CMymfc17Doc::DeleteContents() 
{
    TRACE("Entering CMymfc17Doc::DeleteContents\n");
    while (m_studentList.GetHeadPosition())
	{
        delete m_studentList.RemoveHead();
    }
}

void CMymfc17Doc::OnEditClearAll() 
{
    DeleteContents();
    UpdateAllViews(NULL);
}

void CMymfc17Doc::OnUpdateEditClearAll(CCmdUI* pCmdUI) 
{
    pCmdUI->Enable(!m_studentList.IsEmpty());
}

BOOL CMymfc17Doc::OnOpenDocument(LPCTSTR lpszPathName)
{
    TRACE("Entering CMymfc17Doc::OnOpenDocument\n");
     if (!CDocument::OnOpenDocument(lpszPathName))
        return FALSE;
     
    // TODO: Add your specialized creation code here
     
    return TRUE;
}

void CMymfc17Doc::OnUpdateFileSave(CCmdUI* pCmdUI) 
{
	// TODO: Add your command update UI handler code here
	pCmdUI->Enable(IsModified());
	
}
