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

📄 databaseviewerdoc.cpp

📁 数据库浏览器
💻 CPP
字号:
// DataBaseViewerDoc.cpp : implementation of the CDataBaseViewerDoc class
//

#include "stdafx.h"
#include "DataBaseViewer.h"
#include "DaoListView.h"
#include "DaoTreeView.h"
#include "DataBaseViewerDoc.h"

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

/////////////////////////////////////////////////////////////////////////////
// CDataBaseViewerDoc

IMPLEMENT_DYNCREATE(CDataBaseViewerDoc, CDocument)

BEGIN_MESSAGE_MAP(CDataBaseViewerDoc, CDocument)
	//{{AFX_MSG_MAP(CDataBaseViewerDoc)
		// 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()

/////////////////////////////////////////////////////////////////////////////
// CDataBaseViewerDoc construction/destruction

CDataBaseViewerDoc::CDataBaseViewerDoc()
{
	//初始化指针
	m_pDB = NULL;
	m_pTreeView = NULL;
	m_pListView = NULL;
}

CDataBaseViewerDoc::~CDataBaseViewerDoc()
{
}

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

	// TODO: add reinitialization code here
	// (SDI documents will reuse this document)

	return TRUE;
}



/////////////////////////////////////////////////////////////////////////////
// CDataBaseViewerDoc serialization

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

/////////////////////////////////////////////////////////////////////////////
// CDataBaseViewerDoc diagnostics

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

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

/////////////////////////////////////////////////////////////////////////////
// CDataBaseViewerDoc commands

BOOL CDataBaseViewerDoc::OnOpenDocument(LPCTSTR lpszPathName) 
{
	if (!CDocument::OnOpenDocument(lpszPathName))
		return FALSE;
	
	CDaoDatabase* tmpDB = new CDaoDatabase;

	//在给m_pDB赋值之前,先试着打开数据库;
	//若成功,则给其赋值
	try
	{
		tmpDB->Open(lpszPathName);
	}
	catch (CDaoException* e)
	{
		DisplayDaoException(e);
		delete tmpDB;
		e->Delete();
		return FALSE;
	}

	//删除指向上次所打开数据库的指针
	if (m_pDB)
	{
		if (m_pDB->IsOpen())
			m_pDB->Close();
		delete m_pDB;
	}

	//给指针赋新值
	m_pDB = tmpDB;
	m_pTreeView->m_pDB = m_pDB;
	m_pListView->m_pDB = m_pDB;

	//刷新视图
	RefreshViews();	
	return TRUE;
}

void CDataBaseViewerDoc::RefreshViews()
{
	if (m_pDB)
	{
		//刷新列表视图
		if (m_pListView)
			m_pListView->EraseList();

		//刷新树视图
		if (m_pTreeView)
			m_pTreeView->PopulateTree();
	}
}

⌨️ 快捷键说明

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