【VC开源代码栏目提醒】:文章导读:在新的一年中,各位网友都进入紧张的学习或是工作阶段。网学会员整理了VC开源代码-AddressBookDoc.cpp的相关内容供大家参考,祝大家在新的一年里工作和学习顺利!
// AddressBookDoc.cpp : implementation of the CAddressBookDoc class
//
#include "stdafx.h"
#include "AddressBook.h"
#include "AddressBookDoc.h"
#include "Hints.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CAddressBookDoc
IMPLEMENT_DYNCREATE(CAddressBookDoc, CDocument)
BEGIN_MESSAGE_MAP(CAddressBookDoc, CDocument)
//{{AFX_MSG_MAP(CAddressBookDoc)
// NOTE - the ClassWizard will add and remove mapping macros here.
// DO NOT EDIT what you see in these blocks of generated code!
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CAddressBookDoc construction/destruction
CAddressBookDoc* CAddressBookDoc::g_Doc=NULL;
CAddressBookDoc::CAddressBookDoc()
{
// TODO: add one-time construction code here
ASSERT(!g_Doc);
g_Doc =this;
m_pDB = NULL;
m_pSet = NULL;
m_RecordCount = 0 ;
}
CAddressBookDoc::~CAddressBookDoc()
{
if(m_pSet!=NULL)
{
delete m_pSet; m_pSet = NULL;
}
}
BOOL CAddressBookDoc::OnNewDocument()
{
if (!CDocument::OnNewDocument())
return FALSE;
if(m_pSet!=NULL)
{
m_pSet->Close(); delete m_pSet; m_pSet = NULL;
}
if(m_pDB!=NULL)
{
m_pDB->Close(); delete m_pDB; m_pDB=NULL;
}
m_bFileOpen = FALSE;
return TRUE;
}
/////////////////////////////////////////////////////////////////////////////
// CAddressBookDoc serialization
void CAddressBookDoc::Serialize(CArchive& ar)
{
if (ar.IsStoring())
{
// TODO: add storing code here
}
else
{
// TODO: add loading code here
}
}
/////////////////////////////////////////////////////////////////////////////
// CAddressBookDoc diagnostics
#ifdef _DEBUG
void CAddressBookDoc::AssertValid() const
{
CDocument::AssertValid();
}
void CAddressBookDoc::Dump(CDumpContext& dc) const
{
CDocument::Dump(dc);
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CAddressBookDoc commands
BOOL CAddressBookDoc::OnOpenDocument(LPCTSTR lpszPathName)
{
if (!CDocument::OnOpenDocument(lpszPathName))
{
AfxMessageBox("可以通过程序菜单“文件”中“打开数据库”\n重新定位数据库的位置!");
return FALSE;
}
m_pDB = new CDaoDatabase;
ASSERT(m_pDB!=NULL);
try
{
m_pDB->Open(lpszPathName);
}
catch(CDaoException* e)
{
delete m_pDB;
m_pDB = NULL;
TCHAR szCause[255];
CString strFormatted = _T("The data file could not be opened because of this error: \n");
e->GetErrorMessage(szCause, 255);
strFormatted += szCause;
AfxMessageBox(strFormatted, MB_OK | MB_ICONEXCLAMATION);
e->Delete();
m_bFileOpen = FALSE;
return FALSE;
}
m_pSet = new CDaoRecordsetAccess(m_pDB) ;
try
{
m_pSet->Open();
m_RecordCount=m_pSet->GetRecordCount();
}
catch(CDaoException* e)
{
delete m_pSet; m_pSet = NULL;
TCHAR szCause[255];
CString strFormatted = _T("The data file could not be opened because of this error: \n");
e->GetErrorMessage(szCause, 255);
strFormatted += szCause;
AfxMessageBox(strFormatted, MB_OK | MB_ICONEXCLAMATION);
e->Delete();
m_bFileOpen = FALSE;
return FALSE;
}
m_bFileOpen = TRUE;
UpdateAllViews(NULL,HINT_DB_OPENED);
return TRUE;
}
上一篇:
AddressBook.cpp
下一篇:
配电自动化系统计算机网络及其支持软件的体系结构