www.gusucode.com > 基于VC编程界面编程高级应用技术源码程序 > VC界面编程高级应用技术/code/2/TaxExpert/TaxExpertDoc.cpp
// TaxExpertDoc.cpp : implementation of the CTaxExpertDoc class // #include "stdafx.h" #include "TaxExpert.h" #include "TaxExpertDoc.h" #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif ///////////////////////////////////////////////////////////////////////////// // CTaxExpertDoc IMPLEMENT_DYNCREATE(CTaxExpertDoc, CDocument) BEGIN_MESSAGE_MAP(CTaxExpertDoc, CDocument) //{{AFX_MSG_MAP(CTaxExpertDoc) // 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() ///////////////////////////////////////////////////////////////////////////// // CTaxExpertDoc construction/destruction CTaxExpertDoc::CTaxExpertDoc() { } CTaxExpertDoc::~CTaxExpertDoc() { //关闭数据集 this->m_pSet->Close(); //关闭数据库 this->m_pDB->Close(); } //在新建文档时同时打开数据库 BOOL CTaxExpertDoc::OnNewDocument() { if (!CDocument::OnNewDocument()) return FALSE; m_pDB = new CDaoDatabase; m_pSet = new CDaoSF(m_pDB); ASSERT(m_pDB != NULL); ASSERT(m_pSet != NULL); //打开法规库,并进行错误捕获 try { m_pDB->Open("taxexpert.dat"); } catch (CDaoException* e) { CString error; error.Format("税务法规库定位失败!\r\n\r\n"); error+="导致该错误的原因可能是以下几方面:\r\n\r\n"; error+="1、未安装DAO数据组件,请安装\"安装MS-Jet 数据引擎\"!\r\n"; error+="2、税务法规库文件被删除,或者是税务法规库已经被破坏,\ 请重新安装\"税务师\"!\r\n\r\n"; error+="如果不能解决此问题,你也可以和zhoumingyang@163.net联系\ 以解决此问题。"; delete m_pDB; e ->Delete(); MessageBox(NULL,error,"打开数据库错",MB_ICONSTOP|MB_OK ); return 0; } //进行数据表打开的测试 try { m_pSet->Open(); } catch (CDaoException* e) { delete m_pSet; e ->Delete(); MessageBox(NULL,"税务法规库记录集访问失败\n请重新安装本程序", "访问失败",MB_ICONSTOP|MB_OK ); return 0; } return TRUE; } ///////////////////////////////////////////////////////////////////////////// // CTaxExpertDoc serialization void CTaxExpertDoc::Serialize(CArchive& ar) { if (ar.IsStoring()) { // TODO: add storing code here } else { // TODO: add loading code here } } ///////////////////////////////////////////////////////////////////////////// // CTaxExpertDoc diagnostics #ifdef _DEBUG void CTaxExpertDoc::AssertValid() const { CDocument::AssertValid(); } void CTaxExpertDoc::Dump(CDumpContext& dc) const { CDocument::Dump(dc); } #endif //_DEBUG ///////////////////////////////////////////////////////////////////////////// // CTaxExpertDoc commands