home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Windows Gam…ming Gurus (2nd Edition) / Disc2.iso / msdn_vcb / samples / vc98 / mfc / database / daotable / adddbdlg.cpp next >
C/C++ Source or Header  |  1998-03-26  |  4KB  |  125 lines

  1. // AddDbDlg.cpp : implementation file
  2. // Contains functions to support the user interface for setting
  3. // the properties of the database to be created.
  4. //
  5. // This is a part of the Microsoft Foundation Classes C++ library.
  6. // Copyright (C) 1992-1998 Microsoft Corporation
  7. // All rights reserved.
  8. //
  9. // This source code is only intended as a supplement to the
  10. // Microsoft Foundation Classes Reference and related
  11. // electronic documentation provided with the library.
  12. // See these sources for detailed information regarding the
  13. // Microsoft Foundation Classes product.
  14.  
  15. #include "stdafx.h"
  16. #include "DAOTable.h"
  17. #include "database.h"
  18. #include "AddDbDlg.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. // CAddDatabaseDlg dialog
  28.  
  29. // default constructor
  30. CAddDatabaseDlg::CAddDatabaseDlg(CWnd* pParent /*=NULL*/)
  31.     : CDialog(CAddDatabaseDlg::IDD, pParent)
  32. {
  33.     // call centralized intialization
  34.     initializer();
  35. }
  36.  
  37. // constructor that will generally be called
  38. // for constructing this dialog since the arguments are needed
  39. // to do any useful database operations
  40. //
  41. // IN/OUT: ppDatabase--ptr to ptr to the datbase that is created via this
  42. //         dialog
  43. // IN: strDatabase--the name of the database file (full path or relative)
  44. // IN: pParent--ptr to parent of this dialog
  45. //
  46. CAddDatabaseDlg::CAddDatabaseDlg(CDaoDatabase **ppDatabase,
  47.                                  CString strDatabaseName,
  48.                                  CWnd *pParent /*=NULL*/)
  49.     : CDialog(CAddDatabaseDlg::IDD, pParent)
  50. {
  51.     // call centralized initialization
  52.     initializer();
  53.  
  54.     // transfer incoming parameters to member variables
  55.     m_strDatabaseName = strDatabaseName;
  56.     m_ppDatabase = ppDatabase;
  57. }
  58.  
  59. // initialize members that are not set to incoming arguments
  60. void CAddDatabaseDlg::initializer()
  61. {
  62.     //{{AFX_DATA_INIT(CAddDatabaseDlg)
  63.     m_strDatabaseName = _T("");
  64.     m_bEncrypt = FALSE;
  65.     m_nVersion = 3;
  66.     //}}AFX_DATA_INIT
  67. }
  68.  
  69. void CAddDatabaseDlg::DoDataExchange(CDataExchange* pDX)
  70. {
  71.     CDialog::DoDataExchange(pDX);
  72.     //{{AFX_DATA_MAP(CAddDatabaseDlg)
  73.     DDX_Text(pDX, IDC_EDIT_DATABASE_NAME, m_strDatabaseName);
  74.     DDX_Check(pDX, IDC_CHECK_ENCRYPT, m_bEncrypt);
  75.     DDX_Radio(pDX, IDC_RADIO_V10, m_nVersion);
  76.     //}}AFX_DATA_MAP
  77. }
  78.  
  79. BEGIN_MESSAGE_MAP(CAddDatabaseDlg, CDialog)
  80.     //{{AFX_MSG_MAP(CAddDatabaseDlg)
  81.     //}}AFX_MSG_MAP
  82. END_MESSAGE_MAP()
  83.  
  84. /////////////////////////////////////////////////////////////////////////////
  85. // CAddDatabaseDlg message handlers
  86.  
  87. // user has selected the "Done" button--this means it's time to create
  88. // the database file
  89. void CAddDatabaseDlg::OnOK()
  90. {
  91.     // transfer information from dialog controls to member variables
  92.     UpdateData(TRUE);
  93.  
  94.     // initialize the database open options
  95.     int dwOptions = 0;
  96.  
  97.     // user can specify encrypted or non-encrypted format
  98.     if (m_bEncrypt)
  99.         dwOptions |= dbEncrypt;
  100.     else
  101.         dwOptions |= dbDecrypt;
  102.  
  103.     // user can specify what version of access format to use
  104.     // in creating .mdb file.  Map from radio button group
  105.     // index to actual value to pass to database create call
  106.     switch(m_nVersion)
  107.     {
  108.         case 0: dwOptions |= dbVersion10;
  109.                break;
  110.         case 1: dwOptions |= dbVersion11;
  111.                break;
  112.         case 2: dwOptions |= dbVersion20;
  113.                break;
  114.         case 3: dwOptions |= dbVersion30;
  115.                break;
  116.     }
  117.  
  118.     // try to create the database -- if failure, reinitialize pointer
  119.     if (!createDatabase(m_ppDatabase, m_strDatabaseName, dwOptions))
  120.         (*m_ppDatabase) = NULL;
  121.  
  122.     // call the base class
  123.     CDialog::OnOK();
  124. }
  125.