home *** CD-ROM | disk | FTP | other *** search
- // MDBDoc.cpp : implementation of the CMDBDoc class
- //
-
- #include "stdafx.h"
- #include "MDB.h"
-
- #include "MDBDoc.h"
- #include "MDBView.h"
-
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
-
- /////////////////////////////////////////////////////////////////////////////
- // CMDBDoc
-
- IMPLEMENT_DYNCREATE(CMDBDoc, CDocument)
-
- BEGIN_MESSAGE_MAP(CMDBDoc, CDocument)
- //{{AFX_MSG_MAP(CMDBDoc)
- ON_COMMAND(ID_FILE_SAVE_AS, OnFileSaveAs)
- //}}AFX_MSG_MAP
- END_MESSAGE_MAP()
-
- /////////////////////////////////////////////////////////////////////////////
- // CMDBDoc construction/destruction
-
- CMDBDoc::CMDBDoc()
- {
- // TODO: add one-time construction code here
-
- }
-
- CMDBDoc::~CMDBDoc()
- {
- }
-
- BOOL CMDBDoc::OnNewDocument()
- {
- if (!CDocument::OnNewDocument())
- return FALSE;
-
- // TODO: add reinitialization code here
- // (SDI documents will reuse this document)
-
- POSITION pos = GetFirstViewPosition( );
- CTreeView * pView = ( CTreeView * ) GetNextView( pos );
- CTreeCtrl & tree = pView->GetTreeCtrl( );
- tree.DeleteAllItems( );
- SetModifiedFlag( FALSE );
-
- return TRUE;
- }
-
- /////////////////////////////////////////////////////////////////////////////
- // CMDBDoc serialization
-
- void CMDBDoc::Serialize(CArchive& ar)
- {
- if (ar.IsStoring())
- {
- // TODO: add storing code here
- }
- else
- {
- // TODO: add loading code here
- }
- }
-
- /////////////////////////////////////////////////////////////////////////////
- // CMDBDoc diagnostics
-
- #ifdef _DEBUG
- void CMDBDoc::AssertValid() const
- {
- CDocument::AssertValid();
- }
-
- void CMDBDoc::Dump(CDumpContext& dc) const
- {
- CDocument::Dump(dc);
- }
- #endif //_DEBUG
-
- /////////////////////////////////////////////////////////////////////////////
- // CMDBDoc commands
-
-
- BOOL CMDBDoc::SaveModified()
- {
- // TODO: Add your specialized code here and/or call the base class
- if ( ! IsModified( ) )
- return TRUE;
- int answer = AfxMessageBox( "Create database before closing?",
- MB_YESNOCANCEL | MB_ICONQUESTION );
- if ( IDCANCEL == answer )
- return FALSE;
- if ( IDYES == answer )
- {
- OnFileSaveAs( ); //This handler knows what to do
- return ! IsModified( ); //In case of exception
- }
- return TRUE; //No, don't save it
- }
-
- void CMDBDoc::OnFileSaveAs()
- {
- // TODO: Add your command handler code here
-
- POSITION pos = GetFirstViewPosition( );
- CMDBView * pView = ( CMDBView * ) GetNextView( pos );
- if ( 0 == pView->GetTreeCtrl( ).GetCount( ) ) //No tables in the tree
- if ( IDNO ==
- AfxMessageBox("Create empty database?",
- MB_YESNO | MB_ICONQUESTION ) )
- {
- SetModifiedFlag( FALSE );
- return;
- }
-
- CString strDatabaseName;
- CFileDialog dlg( FALSE, "mdb", NULL, OFN_HIDEREADONLY,
- "Access database|*.mdb||" );
-
- if ( IDOK != dlg.DoModal( ) ) //User cancelled, nothing to do
- return;
-
- CString strTableName, strFieldName;
- int nFieldType, nTextFieldLength;
-
- HTREEITEM hTableItem;
-
- try
- {
- //Exercise 1: Create database
-
- while ( NULL != //While there is a table
- ( hTableItem = pView->TableNameIterator( strTableName ) ) )
- {
- //Exercise 1: Define tabledef object
- //Exercise 1: Create tabledef
-
- while ( NULL != //While there is a field
- pView->FieldInfoIterator( strFieldName, nFieldType, nTextFieldLength, hTableItem ) )
- {
-
- //Exercise 1: Determine data type constant to use
- //Exercise 1: Create a field in the table
-
- } //End while there is a field
-
- //Exercise 1: Append the table definition
- //Exercise 1: Close the table definition
- }//End while there is a table
-
- //Exercise 1: Close the database
- //Exercise 1: Reset the modified flag
- }
- catch ( CDaoException * ex )
- {
- ex->ReportError( );
- try
- {
- //Exercise 1: Close the database
- //Exercise 1: Remove database file if not error 3204
- }
- catch ( CException * exInner )
- {
- exInner->ReportError( );
- exInner->Delete( );
- }
- ex->Delete( );
- }
- }
-
-
-