Initialize the database
Return to Main


Resume :

To initialize the KJV database:
  • To construct a CDaoDatabase and CDaoRecordset objects.
  • To connect the CDaoDatabase object to the KJV database, at the current directory.
  • To create a new recordset for the table - BibleTable.
  • To display the 2nd KJV database record into the Record data boxes, at the first time.
  • To enable or disable the navigation controls.

The changes to ...

  1. TestVC0Dlg.h file - the new Text Code is red.

    // TestVC0Dlg.h : header file
    //

    #if !defined(AFX_TESTVC0DLG_H__073CEC4B_1920_11D7_BFCA_87C57485DA49__INCLUDED_)
    #define AFX_TESTVC0DLG_H__073CEC4B_1920_11D7_BFCA_87C57485DA49__INCLUDED_

    #if _MSC_VER > 1000
    #pragma once
    #endif // _MSC_VER > 1000

    /////////////////////////////////////////////////////////////////////////////
    // CTestVC0Dlg dialog

    class CTestVC0Dlg : public CDialog
    {
    // Construction
    public:
    CTestVC0Dlg(CWnd* pParent = NULL); // standard constructor

    // Dialog Data
    //{{AFX_DATA(CTestVC0Dlg)
    enum { IDD = IDD_TESTVC0_DIALOG };
    CString m_book;
    CString m_chapter;
    CString m_title;
    CString m_verse;
    CString m_textdata;
    //}}AFX_DATA

    // ClassWizard generated virtual function overrides
    //{{AFX_VIRTUAL(CTestVC0Dlg)
    protected:
    virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
    //}}AFX_VIRTUAL

    // Implementation
    protected:
    HICON m_hIcon;
    CDaoDatabase
    * m_pDB;
    CDaoRecordset* m_pRS;


    // Generated message map functions
    //{{AFX_MSG(CTestVC0Dlg)
    virtual BOOL OnInitDialog();
    afx_msg void OnSysCommand(UINT nID, LPARAM lParam);
    afx_msg void OnPaint();
    afx_msg HCURSOR OnQueryDragIcon();
    //}}AFX_MSG
    DECLARE_MESSAGE_MAP()
    void CalculValue();
    void SetButtons(BOOL bVal);

    };

    //{{AFX_INSERT_LOCATION}}
    // Microsoft Visual C++ will insert additional declarations immediately before the previous line.

    #endif // !defined(AFX_TESTVC0DLG_H__073CEC4B_1920_11D7_BFCA_87C57485DA49__INCLUDED_)


  2. TestVC0Dlg.cpp file - the new Text Code is red.


    // TestVC0Dlg.cpp : implementation file
    //

    #include "stdafx.h"
    #include "TestVC0.h"
    #include "TestVC0Dlg.h"

    #ifdef _DEBUG
    #define new DEBUG_NEW
    #undef THIS_FILE
    static char THIS_FILE[] = __FILE__;
    #endif

    /////////////////////////////////////////////////////////////////////////////
    // CAboutDlg dialog used for App About

    class CAboutDlg : public CDialog
    {
    (.......................)
    };

    CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
    {
    (.......................)
    }

    void CAboutDlg::DoDataExchange(CDataExchange* pDX)
    {
    (.......................)
    }

    BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
    //{{AFX_MSG_MAP(CAboutDlg)
    // No message handlers
    //}}AFX_MSG_MAP
    END_MESSAGE_MAP()

    /////////////////////////////////////////////////////////////////////////////
    // CTestVC0Dlg dialog

    CTestVC0Dlg::CTestVC0Dlg(CWnd* pParent /*=NULL*/)
    : CDialog(CTestVC0Dlg::IDD, pParent)
    {
    //{{AFX_DATA_INIT(CTestVC0Dlg)
    m_book = _T("");
    m_chapter = _T("");
    m_title = _T("");
    m_verse = _T("");
    m_textdata = _T("");
    //}}AFX_DATA_INIT
    // Note that LoadIcon does not require a subsequent DestroyIcon in Win32
    m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
    m_pDB = NULL;
    m_pRS = NULL;

    }

    void CTestVC0Dlg::DoDataExchange(CDataExchange* pDX)
    {
    CDialog::DoDataExchange(pDX);
    //{{AFX_DATA_MAP(CTestVC0Dlg)
    DDX_Text(pDX, IDC_BOOK, m_book);
    DDX_Text(pDX, IDC_CHAPTER, m_chapter);
    DDX_Text(pDX, IDC_TITLE, m_title);
    DDX_Text(pDX, IDC_VERSE, m_verse);
    DDX_Text(pDX, IDC_TEXTDATA, m_textdata);
    //}}AFX_DATA_MAP
    }

    BEGIN_MESSAGE_MAP(CTestVC0Dlg, CDialog)
    //{{AFX_MSG_MAP(CTestVC0Dlg)
    ON_WM_SYSCOMMAND()
    ON_WM_PAINT()
    ON_WM_QUERYDRAGICON()
    //}}AFX_MSG_MAP
    END_MESSAGE_MAP()

    /////////////////////////////////////////////////////////////////////////////
    // CTestVC0Dlg message handlers

    BOOL CTestVC0Dlg::OnInitDialog()
    {
    CDialog::OnInitDialog();

    // Add "About..." menu item to system menu.

    // IDM_ABOUTBOX must be in the system command range.
    ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
    ASSERT(IDM_ABOUTBOX < 0xF000);

    CMenu* pSysMenu = GetSystemMenu(FALSE);
    if (pSysMenu != NULL)
    {
    CString strAboutMenu;
    strAboutMenu.LoadString(IDS_ABOUTBOX);
    if (!strAboutMenu.IsEmpty())
    {
    pSysMenu->AppendMenu(MF_SEPARATOR);
    pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
    }
    }

    // Set the icon for this dialog. The framework does this automatically
    // when the application's main window is not a dialog
    SetIcon(m_hIcon, TRUE); // Set big icon
    SetIcon(m_hIcon, FALSE); // Set small icon

    // *** Initialize / declaration ***
    m_pDB = new CDaoDatabase;
    m_pRS = new CDaoRecordset(m_pDB);

    TCHAR curdir[MAX_PATH]; //MAX_PATH - Maximum length of directory
    CString Databasename;

    // Get Current Directory
    GetCurrentDirectory (MAX_PATH, curdir );

    //DataBase name, KJV.mdb at Current Directory
    Databasename = (CString)curdir + _T("\\KJV.mdb");
    m_pDB->Open(Databasename);

    m_pRS->Open(dbOpenDynaset, "SELECT * from BibleTable", 0);

    //Move to the 2nd record
    m_pRS->Move(2);
    //Display the content of the record
    CalculValue();
    //Stiuation of controls
    SetButtons(TRUE);

    // TODO: Add extra initialization here

    return TRUE; // return TRUE unless you set the focus to a control
    }

    void CTestVC0Dlg::OnSysCommand(UINT nID, LPARAM lParam)
    {
    (.......................)
    }

    void CTestVC0Dlg::OnPaint()
    {
    (.......................)
    }

    HCURSOR CTestVC0Dlg::OnQueryDragIcon()
    {
    (.......................)
    }
    //Display the contents of the KJV database record
    void CTestVC0Dlg::CalculValue()
    {
    COleVariant var;
    var = m_pRS->GetFieldValue(_T("Book"));
    m_book = CString(V_BSTRT(&var));

    var = m_pRS->GetFieldValue(_T("BookTitle"));
    m_title = CString(V_BSTRT(&var));

    var = m_pRS->GetFieldValue(_T("Chapter"));
    m_chapter = CString(V_BSTRT(&var));

    var = m_pRS->GetFieldValue(_T("Verse"));
    m_verse = CString(V_BSTRT(&var));

    var = m_pRS->GetFieldValue(_T("TextData"));
    m_textdata = CString(V_BSTRT(&var));

    UpdateData(FALSE
    );
    return;
    }

    //To enable or disable navigation controls
    void CTestVC0Dlg::SetButtons(BOOL bVal)
    {
    GetDlgItem(IDC_RECORD_FIRST)->EnableWindow(!bVal);
    GetDlgItem(IDC_RECORD_PREV)->EnableWindow(!bVal);
    GetDlgItem(IDC_RECORD_NEXT)->EnableWindow(bVal);
    GetDlgItem(IDC_RECORD_LAST)->EnableWindow(bVal);
    }
Return to Main