www.gusucode.com > VC++编写的SQL服务端和客户端源码程序 > VC++编写的SQL服务端和客户端源码程序\code\Server\UserDoc.cpp

    //Download by http://www.NewXing.com
// UserDoc.cpp : implementation file
//

#include "stdafx.h"
#include "miniSQL.h"
#include "UserDoc.h"
#include "Error.h"

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

/////////////////////////////////////////////////////////////////////////////
// CUserDoc

IMPLEMENT_DYNCREATE(CUserDoc, CDocument)

CUserDoc::CUserDoc()
{
}

BOOL CUserDoc::OnNewDocument()
{
	if (!CDocument::OnNewDocument())
		return FALSE;

	m_UserList.RemoveAll();
	return TRUE;
}

CUserDoc::~CUserDoc()
{
}


BEGIN_MESSAGE_MAP(CUserDoc, CDocument)
	//{{AFX_MSG_MAP(CUserDoc)
		// NOTE - the ClassWizard will add and remove mapping macros here.
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CUserDoc diagnostics

#ifdef _DEBUG
void CUserDoc::AssertValid() const
{
	CDocument::AssertValid();
}

void CUserDoc::Dump(CDumpContext& dc) const
{
	CDocument::Dump(dc);
}
#endif //_DEBUG

/////////////////////////////////////////////////////////////////////////////
// CUserDoc serialization

void CUserDoc::Serialize(CArchive& ar)
{
	CUser user;
	int count = m_UserList.GetCount();
	
	if (ar.IsStoring())
	{
		ar<<count;
		for( int i = 0; i < count; i++ )
		{
			user = m_UserList.GetAt( m_UserList.FindIndex( i ) );
			user.Serialize( ar );
		}
		ar<<'\0';
	}
	else
	{
		ar>>count;
		m_UserList.RemoveAll();
		for( int i = 0; i < count; i++ )
		{
			user.Serialize( ar );
			m_UserList.AddTail( user );
		}
		char c;
		ar>>c;
		if( c != '\0' )
			throw Error( ERROR_FILE_CORRUPTED, 0, _T("") );
	}
}

/////////////////////////////////////////////////////////////////////////////
// CUserDoc commands