home *** CD-ROM | disk | FTP | other *** search
/ QBasic & Borland Pascal & C / Delphi5.iso / Basic / Visual Basic.60 / COMMON / TOOLS / VCM / VCM.MDB / VcmComponentContainer / 14_Cabinet / DBDOC.CPP < prev    next >
Encoding:
C/C++ Source or Header  |  1998-05-18  |  3.3 KB  |  163 lines

  1. // DBDoc.cpp : implementation of the CDBViewDoc class
  2. //
  3. // This is a part of the Microsoft Foundation Classes and
  4. // Templates (MFC&T).
  5. // Copyright (C) 1998 Microsoft Corporation
  6. // All rights reserved.
  7. //
  8. // This source code is only intended as a supplement to the
  9. // MFC&T Reference and related electronic documentation provided
  10. // with the library.  See these sources for detailed information
  11. // regarding the MFC&T product.
  12. //
  13.  
  14. #include "stdafx.h"
  15. #include "DBViewer.h"
  16.  
  17. #include "DBDoc.h"
  18.  
  19. #ifdef _DEBUG
  20. #define new DEBUG_NEW
  21. #undef THIS_FILE
  22. static char THIS_FILE[] = __FILE__;
  23. #endif
  24.  
  25. /////////////////////////////////////////////////////////////////////////////
  26. // CDBViewDoc
  27.  
  28. IMPLEMENT_DYNCREATE(CDBViewDoc, CDocument)
  29.  
  30. BEGIN_MESSAGE_MAP(CDBViewDoc, CDocument)
  31.     //{{AFX_MSG_MAP(CDBViewDoc)
  32.     ON_COMMAND(ID_FILE_OPEN, OnFileOpen)
  33.     //}}AFX_MSG_MAP
  34. END_MESSAGE_MAP()
  35.  
  36. /////////////////////////////////////////////////////////////////////////////
  37. // CDBViewDoc construction/destruction
  38.  
  39. CDBViewDoc::CDBViewDoc()
  40. {
  41.     m_pListView = NULL;
  42.     m_pTreeView = NULL;
  43. }
  44.  
  45. CDBViewDoc::~CDBViewDoc()
  46. {
  47.     m_pListView = NULL;
  48.     m_pTreeView = NULL;
  49. }
  50.  
  51. BOOL CDBViewDoc::OnNewDocument()
  52. {
  53.     if (!CDocument::OnNewDocument())
  54.         return FALSE;
  55.  
  56.     // TODO: add reinitialization code here
  57.     // (SDI documents will reuse this document)
  58.  
  59.     return TRUE;
  60. }
  61.  
  62. /////////////////////////////////////////////////////////////////////////////
  63. // CDBViewDoc serialization
  64.  
  65. void CDBViewDoc::Serialize(CArchive& ar)
  66. {
  67.     if (ar.IsStoring())
  68.     {
  69.         // TODO: add storing code here
  70.     }
  71.     else
  72.     {
  73.         // TODO: add loading code here
  74.     }
  75. }
  76.  
  77. /////////////////////////////////////////////////////////////////////////////
  78. // CDBViewDoc diagnostics
  79.  
  80. #ifdef _DEBUG
  81. void CDBViewDoc::AssertValid() const
  82. {
  83.     CDocument::AssertValid();
  84. }
  85.  
  86. void CDBViewDoc::Dump(CDumpContext& dc) const
  87. {
  88.     CDocument::Dump(dc);
  89. }
  90. #endif //_DEBUG
  91.  
  92. /////////////////////////////////////////////////////////////////////////////
  93. // CDBViewDoc commands
  94.  
  95. void CDBViewDoc::RefreshViews()
  96. {
  97.     if (m_pListView)
  98.         m_pListView->EraseList();
  99.  
  100.     if (m_pTreeView)
  101.         m_pTreeView->PopulateTree();
  102. }
  103.  
  104. BOOL CDBViewDoc::OnOpenDocument(LPCTSTR lpszPathName)
  105. {
  106.     if (m_Session.m_spOpenRowset != NULL)
  107.         m_Session.m_spOpenRowset.Release();
  108.  
  109.     m_strConnect = _T("");
  110.  
  111.     if (m_Connect.Open(AfxGetMainWnd()->GetSafeHwnd()) != S_OK)
  112.     {
  113.         AfxMessageBox(_T("Unable to connect to data source"));
  114.         return FALSE;
  115.     }
  116.     else
  117.     {
  118.         USES_CONVERSION;
  119.  
  120.         if (m_Session.Open(m_Connect) != S_OK)
  121.         {
  122.             AfxMessageBox(_T("Couldn't create session on data source"));
  123.             return FALSE;
  124.         }
  125.  
  126.         CComVariant var;
  127.         m_Connect.GetProperty(DBPROPSET_DATASOURCEINFO, DBPROP_DATASOURCENAME, &var);
  128.         m_strConnect = OLE2T(var.bstrVal);
  129.  
  130.         m_pTreeView->m_pSession = &m_Session;
  131.         m_pListView->m_pSession = &m_Session;
  132.         RefreshViews();
  133.         return TRUE;
  134.     }
  135.  
  136.     return FALSE;
  137. }
  138.  
  139. CString CDBViewDoc::GetDSN()
  140. {
  141.     // pull DSN from database connect string
  142.     CString string = m_strConnect;
  143. //  string = string.Right(string.GetLength() - (string.Find(_T("DSN=")) + 4));
  144. //  string = string.Left(string.Find(_T(";")));
  145.     return string;
  146. }
  147.  
  148. CString CDBViewDoc::GetConnect()
  149. {
  150.     return m_strConnect;
  151. }
  152.  
  153. void CDBViewDoc::OnFileOpen()
  154. {
  155.     OnOpenDocument(NULL);
  156. }
  157.  
  158. CDataSource* CDBViewDoc::GetDataSource()
  159. {
  160.     return &m_Connect;
  161.  
  162. }
  163.