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

  1. // denrldoc.cpp : implementation of the CDaoEnrolDoc 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 "DaoEnrol.h"
  15.  
  16. #include "sectset.h"
  17. #include "coursese.h"
  18. #include "denrldoc.h"
  19.  
  20. #ifdef _DEBUG
  21. #define new DEBUG_NEW
  22. #undef THIS_FILE
  23. static char THIS_FILE[] = __FILE__;
  24. #endif
  25.  
  26. /////////////////////////////////////////////////////////////////////////////
  27. // CUpdateHint
  28.  
  29. IMPLEMENT_DYNAMIC(CUpdateHint, CObject)
  30.  
  31. CUpdateHint::CUpdateHint()
  32. {
  33. }
  34.  
  35. /////////////////////////////////////////////////////////////////////////////
  36. // CDaoEnrolDoc
  37.  
  38. IMPLEMENT_DYNCREATE(CDaoEnrolDoc, CDocument)
  39.  
  40. BEGIN_MESSAGE_MAP(CDaoEnrolDoc, CDocument)
  41.     //{{AFX_MSG_MAP(CDaoEnrolDoc)
  42.         // NOTE - the ClassWizard will add and remove mapping macros here.
  43.         //    DO NOT EDIT what you see in these blocks of generated code!
  44.     //}}AFX_MSG_MAP
  45. END_MESSAGE_MAP()
  46.  
  47. /////////////////////////////////////////////////////////////////////////////
  48. // CDaoEnrolDoc construction/destruction
  49.  
  50. CDaoEnrolDoc::CDaoEnrolDoc()
  51. {
  52.     // TODO: add one-time construction code here
  53.  
  54. }
  55.  
  56. CDaoEnrolDoc::~CDaoEnrolDoc()
  57. {
  58. }
  59.  
  60.  
  61. BOOL CDaoEnrolDoc::OnNewDocument()
  62. {
  63.     if (!m_database.IsOpen())
  64.     {
  65.         // First assume stdreg32.mdb file is in current directory
  66.         try
  67.         {
  68.             m_database.Open(_T("stdreg32.mdb"));
  69.         }
  70.         catch (CDaoException* e)
  71.         {
  72.             // Assume failure is becauase we couldn't find the file
  73.             e->Delete();
  74.         }
  75.     }
  76.     if (!m_database.IsOpen())
  77.     {
  78.         // Now pop-up file-open dlg to ask for location
  79.         CFileDialog dlgFile(
  80.             TRUE,
  81.             _T(".mdb"),
  82.             NULL,
  83.             OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,
  84.             _T("Access Files (*.mdb)|*.mdb|All Files (*.*)|*.*||"));
  85.         if (dlgFile.DoModal() == IDCANCEL)
  86.             return FALSE;
  87.         try
  88.         {
  89.             m_database.Open(dlgFile.GetFileName());
  90.         }
  91.         catch (CDaoException* e)
  92.         {
  93.             // Tell them the reason it failed to open
  94.             AfxMessageBox(e->m_pErrorInfo->m_strDescription);
  95.             e->Delete();
  96.             return FALSE;
  97.         }
  98.     }
  99.     if (!m_database.IsOpen())
  100.         return FALSE;
  101.     if (!CDocument::OnNewDocument())
  102.         return FALSE;
  103.     return TRUE;
  104. }
  105.  
  106. /////////////////////////////////////////////////////////////////////////////
  107. // CDaoEnrolDoc diagnostics
  108.  
  109. #ifdef _DEBUG
  110. void CDaoEnrolDoc::AssertValid() const
  111. {
  112.     CDocument::AssertValid();
  113. }
  114.  
  115. void CDaoEnrolDoc::Dump(CDumpContext& dc) const
  116. {
  117.     CDocument::Dump(dc);
  118. }
  119. #endif //_DEBUG
  120.  
  121. /////////////////////////////////////////////////////////////////////////////
  122. // CDaoEnrolDoc commands
  123.