home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Windows Gam…ming Gurus (2nd Edition) / Disc2.iso / msdn_vcb / samples / vc98 / mfc / database / daoview / daovwdoc.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1998-03-27  |  2.8 KB  |  145 lines

  1. // DaoViewDoc.cpp : implementation of the CDaoViewDoc class
  2. //
  3. // This is a part of the Microsoft Foundation Classes C++ library.
  4. // Copyright (C) 1992-1998 Microsoft Corporation
  5. // All rights reserved.
  6. //
  7. // This source code is only intended as a supplement to the
  8. // Microsoft Foundation Classes Reference and related
  9. // electronic documentation provided with the library.
  10. // See these sources for detailed information regarding the
  11. // Microsoft Foundation Classes product.
  12.  
  13. #include "stdafx.h"
  14. #include "DaoView.h"
  15. #include "OptionsD.h"
  16.  
  17. #ifdef _DEBUG
  18. #undef THIS_FILE
  19. static char THIS_FILE[] = __FILE__;
  20. #endif
  21.  
  22. /////////////////////////////////////////////////////////////////////////////
  23. // CDaoViewDoc
  24.  
  25. IMPLEMENT_DYNCREATE(CDaoViewDoc, CDocument)
  26.  
  27. BEGIN_MESSAGE_MAP(CDaoViewDoc, CDocument)
  28.     //{{AFX_MSG_MAP(CDaoViewDoc)
  29.     //}}AFX_MSG_MAP
  30. END_MESSAGE_MAP()
  31.  
  32. /////////////////////////////////////////////////////////////////////////////
  33. // CDaoViewDoc construction/destruction
  34.  
  35. CDaoViewDoc::CDaoViewDoc()
  36. {
  37.     m_pDB = NULL;
  38.     m_pTreeView = NULL;
  39.     m_pListView = NULL;
  40. }
  41.  
  42. CDaoViewDoc::~CDaoViewDoc()
  43. {
  44.     if(m_pDB)
  45.     {
  46.         if(m_pDB->IsOpen())
  47.             m_pDB->Close();
  48.         delete m_pDB;
  49.     }
  50. }
  51.  
  52. BOOL CDaoViewDoc::OnNewDocument()
  53. {
  54.     if (!CDocument::OnNewDocument())
  55.         return FALSE;
  56.  
  57.     // TODO: add reinitialization code here
  58.     // (SDI documents will reuse this document)
  59.  
  60.     return TRUE;
  61. }
  62.  
  63. /////////////////////////////////////////////////////////////////////////////
  64. // CDaoViewDoc serialization
  65.  
  66. void CDaoViewDoc::Serialize(CArchive& ar)
  67. {
  68.     if (ar.IsStoring())
  69.     {
  70.         // TODO: add storing code here
  71.     }
  72.     else
  73.     {
  74.         // TODO: add loading code here
  75.     }
  76. }
  77.  
  78. /////////////////////////////////////////////////////////////////////////////
  79. // CDaoViewDoc diagnostics
  80.  
  81. #ifdef _DEBUG
  82. void CDaoViewDoc::AssertValid() const
  83. {
  84.     CDocument::AssertValid();
  85. }
  86.  
  87. void CDaoViewDoc::Dump(CDumpContext& dc) const
  88. {
  89.     CDocument::Dump(dc);
  90. }
  91. #endif //_DEBUG
  92.  
  93. /////////////////////////////////////////////////////////////////////////////
  94. // CDaoViewDoc commands
  95.  
  96. BOOL CDaoViewDoc::OnOpenDocument(LPCTSTR lpszPathName)
  97. {
  98.     if (!CDocument::OnOpenDocument(lpszPathName))
  99.         return FALSE;
  100.  
  101.     CDaoDatabase* tmpDB = new CDaoDatabase;
  102.  
  103.     // Attempt to open the new database before replacing our ptr
  104.     try
  105.     {
  106.         tmpDB->Open(lpszPathName);
  107.     }
  108.     catch (CDaoException* e)
  109.     {
  110.         DisplayDaoException(e);
  111.         delete tmpDB;
  112.         e->Delete();
  113.         return FALSE;
  114.     }
  115.  
  116.  
  117.     if (m_pDB)
  118.     {
  119.         if (m_pDB->IsOpen())
  120.             m_pDB->Close();
  121.         delete m_pDB;
  122.     }
  123.  
  124.     m_pDB = tmpDB;
  125.     m_pTreeView->m_pDB = m_pDB;
  126.     m_pListView->m_pDB = m_pDB;
  127.  
  128.     RefreshViews();
  129.  
  130.     return TRUE;
  131. }
  132.  
  133.  
  134. void CDaoViewDoc::RefreshViews()
  135. {
  136.     if (m_pDB)
  137.     {
  138.         if (m_pListView)
  139.             m_pListView->EraseList();
  140.  
  141.         if (m_pTreeView)
  142.             m_pTreeView->PopulateTree();
  143.     }
  144. }
  145.