⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 myaddrdoc.cpp

📁 MFC ACCESS 数据库
💻 CPP
字号:
// MyAddrDoc.cpp : implementation of the CMyAddrDoc class
//

#include "stdafx.h"
#include "MyAddr.h"

#include "MyAddrDoc.h"
#include "Hints.h"

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

/////////////////////////////////////////////////////////////////////////////
// CMyAddrDoc

IMPLEMENT_DYNCREATE(CMyAddrDoc, CDocument)

BEGIN_MESSAGE_MAP(CMyAddrDoc, CDocument)
	//{{AFX_MSG_MAP(CMyAddrDoc)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CMyAddrDoc construction/destruction
CMyAddrDoc* CMyAddrDoc::g_Doc=NULL;

CMyAddrDoc::CMyAddrDoc()
{
	// TODO: add one-time construction code here
    ASSERT(!g_Doc);
	g_Doc =this;
	m_pDB  = NULL;
	m_pSet = NULL;
	m_RecordCount = 0 ;
}

CMyAddrDoc::~CMyAddrDoc()
{
}

BOOL CMyAddrDoc::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;
}



/////////////////////////////////////////////////////////////////////////////
// CMyAddrDoc serialization

void CMyAddrDoc::Serialize(CArchive& ar)
{
	if (ar.IsStoring())
	{
		// TODO: add storing code here
	}
	else
	{
		// TODO: add loading code here
	}
}

/////////////////////////////////////////////////////////////////////////////
// CMyAddrDoc diagnostics

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

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

/////////////////////////////////////////////////////////////////////////////
// CMyAddrDoc commands



BOOL CMyAddrDoc::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 CMyRecordSet(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;

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -