//
Book.cpp : implementation file //
#include "stdafx.h"
#include "KJV_VCNet.h"
#include "Book.h"
#include ".\book.h"
// CBook dialog
IMPLEMENT_DYNAMIC(CBook, CDialog)
CBook::CBook(CWnd* pParent
/*=NULL*/)
: CDialog(CBook::IDD, pParent)
, mm_book(_T(""))
, mm_title(_T(""))
, mm_verse(_T(""))
, mm_chapter(_T(""))
, m_edit1(_T(""))
, m_edit2(_T(""))
, m_found(_T(""))
{
m_pDB = NULL;
m_pRS = NULL;
m_pRSW0 = NULL;
}
CBook::~CBook()
{
}
void
CBook::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
DDX_Text(pDX, IDC_BOOK, mm_book);
DDX_Text(pDX, IDC_TITLE, mm_title);
DDX_Text(pDX, IDC_VERSE, mm_verse);
DDX_Text(pDX, IDC_CHAPTER,
mm_chapter);
DDX_Text(pDX, IDC_EDIT1,
m_edit1);
DDX_Control(pDX, IDC_TAB1,
m_Tab1);
DDX_Control(pDX, IDC_EDIT2,
m_edit2control);
DDX_Text(pDX, IDC_EDIT2,
m_edit2);
DDX_Control(pDX, IDC_DISPLAY,
m_display);
DDX_Control(pDX, IDC_LIST1,
m_list1);
DDX_Control(pDX, IDC_FOUND,
m_foundcontrol);
DDX_Text(pDX, IDC_FOUND, m_found);
DDX_Control(pDX, IDC_TYPE, m_type);
DDX_Control(pDX, IDC_SELECT,
m_select);
DDX_Control(pDX, IDC_TBOOK,
m_tbook);
DDX_Control(pDX, IDC_TTITLE,
m_ttitle);
DDX_Control(pDX, IDC_TCHAPTER,
m_tchapter);
DDX_Control(pDX, IDC_TVERSE,
m_tverse);
DDX_Control(pDX, IDC_LIST_BOOK,
m_listbook);
DDX_Control(pDX, IDC_LIST_TITLE,
m_listtitle);
DDX_Control(pDX, IDC_LIST_CHAPTER,
m_listchapter);
DDX_Control(pDX, IDC_LIST_VERSE,
m_listverse);
}
BEGIN_MESSAGE_MAP(CBook, CDialog)
ON_BN_CLICKED(IDC_FIRST,
OnBnClickedFirst)
ON_BN_CLICKED(IDC_LAST,
OnBnClickedLast)
ON_BN_CLICKED(IDC_NEXT,
OnBnClickedNext)
ON_BN_CLICKED(IDC_PREVIOUS,
OnBnClickedPrevious)
ON_EN_CHANGE(IDC_EDIT2,
OnEnChangeEdit2)
ON_BN_CLICKED(IDC_DISPLAY,
OnBnClickedDisplay)
ON_NOTIFY(NM_CLICK, IDC_LIST1,
OnNMClickList1)
ON_NOTIFY(TCN_SELCHANGE,
IDC_TAB1, OnTcnSelchangeTab1)
ON_LBN_SELCHANGE(IDC_LIST_BOOK,
OnLbnSelchangeListBook)
ON_LBN_SELCHANGE(IDC_LIST_TITLE,
OnLbnSelchangeListTitle)
ON_LBN_SELCHANGE(IDC_LIST_CHAPTER,
OnLbnSelchangeListChapter)
ON_LBN_SELCHANGE(IDC_LIST_VERSE,
OnLbnSelchangeListVerse)
END_MESSAGE_MAP()
// CBook message handlers
BOOL CBook::OnInitDialog()
{
CDialog::OnInitDialog();
// *** 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("\\KJV2002.mdb");
m_pDB->Open(Databasename);
m_pRS->Open(dbOpenDynaset,
"SELECT * from BibleTable", 0);
//Move to first
available record
m_pRS->Move(2);
//Display the
content of record
CalculValue();
//Stiuation of
controls
SetButtons(TRUE);
//**********************
//Initialize the
Tab Comtrol
TC_ITEM TabCtrlItem;
TabCtrlItem.mask = TCIF_TEXT;
TabCtrlItem.pszText = " By word
";
m_Tab1.InsertItem( 0, &TabCtrlItem
);
TabCtrlItem.pszText = " By
address ";
m_Tab1.InsertItem( 1, &TabCtrlItem
);
//********************************
//Make these
controls visible or invisible, for Tab Control
m_select.ShowWindow(SW_HIDE);
m_listbook.ShowWindow(SW_HIDE);
m_listtitle.ShowWindow(SW_HIDE);
m_listchapter.ShowWindow(SW_HIDE);
m_listverse.ShowWindow(SW_HIDE);
m_tbook.ShowWindow(SW_HIDE);
m_ttitle.ShowWindow(SW_HIDE);
m_tchapter.ShowWindow(SW_HIDE);
m_tverse.ShowWindow(SW_HIDE);
m_list1.ShowWindow(SW_SHOW);
m_edit2control.ShowWindow(SW_SHOW);
m_display.ShowWindow(SW_SHOW);
m_type.ShowWindow(SW_SHOW);
m_foundcontrol.ShowWindow(SW_SHOW);
//Show the header
row of List Control
// View property
= Report
int
strWidth1 = m_list1.GetStringWidth(_T("00000"));
m_list1.InsertColumn(1, _T("Record"),
LVCFMT_LEFT,5*strWidth1/3, -1);
m_list1.InsertColumn(2, _T("Bk"),
LVCFMT_LEFT, strWidth1, -1);
m_list1.InsertColumn(3, _T("Title"),
LVCFMT_LEFT, 3*strWidth1, -1);
m_list1.InsertColumn(4, _T("Ch"),
LVCFMT_LEFT, strWidth1, -1);
m_list1.InsertColumn(5, _T("Verse"),
LVCFMT_LEFT, 3*strWidth1/2, -1);
//************************ Initialize the List Boxes **
//Recordset
declaration
if
(m_pRSW0)
if
(m_pRSW0->IsOpen())
m_pRSW0->Close();
delete
m_pRSW0;
m_pRSW0 =
new
CDaoRecordset(m_pDB);
m_pRSW0->Open(dbOpenDynaset,
"SELECT * from BibleTable order by Book", 0);
//Clear the list
boxes
m_listbook.ResetContent();
m_listtitle.ResetContent();
m_listchapter.ResetContent();
m_listverse.ResetContent();
//Move to 2nd
record
m_pRSW0->MoveFirst();
while
(!m_pRSW0->IsEOF())
{
//Values of Book,
Title, Chapter and Verse fields
varbook1 = m_pRSW0->GetFieldValue(_T("Book"));
vartitle1 = m_pRSW0->GetFieldValue(_T("BookTitle"));
varchapter1 = m_pRSW0->GetFieldValue(_T("Chapter"));
varverse1 = m_pRSW0->GetFieldValue(_T("Verse"));
if
((CString(V_BSTRT(&varchapter1)) == "001") && (CString(V_BSTRT(&varverse1))
== "001"))
{
//Add item to
book and title list boxes
m_listbook.AddString(CString(V_BSTRT(&varbook1)));
m_listtitle.AddString(CString(V_BSTRT(&vartitle1)));
}
m_pRSW0->MoveNext();
}
UpdateData(FALSE);
// TODO: Add
extra initialization here
return TRUE; //
return TRUE unless you set the focus to a control
// EXCEPTION: OCX
Property Pages should return FALSE
}
//Display the contents of record
void
CBook::CalculValue()
{
COleVariant var;
var = m_pRS->GetFieldValue(_T("Book"));
mm_book = CString(V_BSTRT(&var));
var = m_pRS->GetFieldValue(_T("BookTitle"));
mm_title = CString(V_BSTRT(&var));
var = m_pRS->GetFieldValue(_T("Chapter"));
mm_chapter = CString(V_BSTRT(&var));
var = m_pRS->GetFieldValue(_T("Verse"));
mm_verse = CString(V_BSTRT(&var));
var = m_pRS->GetFieldValue(_T("TextData"));
m_edit1 = CString(V_BSTRT(&var));
if
(mm_book == _T("01") && mm_chapter == _T("001") &&
mm_verse == _T("001"))
SetButtons(TRUE);
else
{
if
(mm_book == _T("66") && mm_chapter == _T("022") &&
mm_verse == _T("021"))
SetButtons(FALSE);
else
SetButtonsAll(TRUE);
}
UpdateData(FALSE);
return;
}
//To enable or disable navigation controls - SetButtons
function
void
CBook::SetButtons(BOOL bVal)
{
GetDlgItem(IDC_FIRST)->EnableWindow(!bVal);
GetDlgItem(IDC_PREVIOUS)->EnableWindow(!bVal);
GetDlgItem(IDC_NEXT)->EnableWindow(bVal);
GetDlgItem(IDC_LAST)->EnableWindow(bVal);
}
//To enable or disable navigation controls -
SetButtonsAll function
void
CBook::SetButtonsAll(BOOL bVal)
{
GetDlgItem(IDC_FIRST)->EnableWindow(bVal);
GetDlgItem(IDC_PREVIOUS)->EnableWindow(bVal);
GetDlgItem(IDC_NEXT)->EnableWindow(bVal);
GetDlgItem(IDC_LAST)->EnableWindow(bVal);
}
void
CBook::OnBnClickedFirst()
{
m_pRS->MoveFirst();
m_pRS->Move(2);
CalculValue();
// TODO: Add your
control notification handler code here
}
void
CBook::OnBnClickedLast()
{
m_pRS->MoveLast();
CalculValue();
// TODO: Add your
control notification handler code here
}
void
CBook::OnBnClickedNext()
{
m_pRS->MoveNext();
CalculValue();
// TODO: Add your
control notification handler code here
}
void
CBook::OnBnClickedPrevious()
{
m_pRS->MovePrev();
CalculValue();
// TODO: Add your
control notification handler code here
}
void CBook::OnEnChangeEdit2()
{
m_display.EnableWindow(TRUE);
// TODO: If this
is a RICHEDIT control, the control will not
// send this
notification unless you override the CDialog::OnInitDialog()
// function and
call CRichEditCtrl().SetEventMask()
// with the
ENM_CHANGE flag ORed into the mask.
// TODO: Add your
control notification handler code here
}
void
CBook::OnBnClickedDisplay()
{
CString vrecordno, vtextdata,
vbook, vtitle, vchapter, vverse;
CString upperword,lowerword,
leftword, rightword, ulword;
char
chrrecno[40];
int
nNewItem, i, j;
COleVariant var;
//Recordset
declaration
if
(m_pRSW0)
if
(m_pRSW0->IsOpen())
m_pRSW0->Close();
delete
m_pRSW0;
m_pRSW0 =
new
CDaoRecordset(m_pDB);
m_pRSW0->Open(dbOpenDynaset,
"SELECT * from BibleTable", 0);
//Set the
IDC_DISPLAY button disable
m_display.EnableWindow(FALSE);
UpdateData(TRUE);
//Clear the list
control
m_list1.DeleteAllItems();
m_found = "";
//Uppercase style
upperword = m_edit2;
upperword.MakeUpper();
//Lowercase style
lowerword = m_edit2;
lowerword.MakeLower();
//Uppercase +
lowercase style
leftword = m_edit2.Left(1);
rightword =
m_edit2.Right(m_edit2.GetLength() - 1);
leftword.MakeUpper();
rightword.MakeLower();
ulword = leftword + rightword;
i = 0;
m_pRSW0->Move(2);
//Max items to
found = 4999
while
(!m_pRSW0->IsEOF() && i < 5000)
{
//Value of
TextData field
var = m_pRSW0->GetFieldValue(_T("TextData"));
vtextdata = CString(V_BSTRT(&var));
//Search
condition
if
((vtextdata.Find(upperword) != -1) || (vtextdata.Find(lowerword)
!= -1) || (vtextdata.Find(ulword) != -1))
{
//Absolute
position of record
vrecno = m_pRSW0->GetAbsolutePosition();
//Convert long to
string
ltoa(vrecno,chrrecno,10);
vrecordno = CString(chrrecno);
//Value of Book
field
var = m_pRSW0->GetFieldValue(_T("Book"));
vbook = CString(V_BSTRT(&var));
//Value of Title
field
var = m_pRSW0->GetFieldValue(_T("BookTitle"));
vtitle = CString(V_BSTRT(&var));
//Value of
Chapter field
var = m_pRSW0->GetFieldValue(_T("Chapter"));
vchapter = CString(V_BSTRT(&var));
//Value of Verse
field
var = m_pRSW0->GetFieldValue(_T("Verse"));
vverse = CString(V_BSTRT(&var));
//Insert item to
List control
nNewItem =
m_list1.InsertItem(i,vrecordno,1);
m_list1.SetItem(nNewItem,1,LVIF_TEXT,vbook,0,0,0,0);
m_list1.SetItem(nNewItem,2,LVIF_TEXT,vtitle,0,0,0,0);
m_list1.SetItem(nNewItem,3,LVIF_TEXT,vchapter,0,0,0,0);
m_list1.SetItem(nNewItem,4,LVIF_TEXT,vverse,0,0,0,0);
i = i + 1;
j = i - 1;
}
m_pRSW0->MoveNext();
}
//Information
about Items found
if
(i < 1)
m_found = "0 item found.";
else
{
itoa(j+1 ,chrrecno,10);
if
(j >= 4999)
m_found = "More then " + (CString)chrrecno
+ " items found.";
else
m_found = (CString)chrrecno + "
items found.";
}
UpdateData(FALSE);
// TODO: Add your
control notification handler code here
}
void CBook::OnNMClickList1(NMHDR
*pNMHDR, LRESULT *pResult)
{
CString itemselected;
long
itemindex;
COleVariant var;
//Recordset
declaration
if
(m_pRS)
if
(m_pRS->IsOpen())
m_pRS->Close();
delete
m_pRS;
m_pRS =
new
CDaoRecordset(m_pDB);
m_pRS->Open(dbOpenDynaset,
"SELECT * from BibleTable", 0);
//Value of item
selected
itemselected =
m_list1.GetItemText(m_list1.GetSelectionMark(),0) ;
itemindex =
atol(itemselected.GetBuffer(40));
//Display the
record corresponding to the item selected
if
(itemindex > 1)
{
if
(itemindex == 31103)
{
m_pRS->MoveLast();
CalculValue();
SetButtons(FALSE);
}
else
{
m_pRS->Move(itemindex);
CalculValue();
if
(itemindex == 2)
SetButtons(TRUE);
else
SetButtonsAll(TRUE);
}
}
// TODO: Add your
control notification handler code here
*pResult = 0;
}
void CBook::OnTcnSelchangeTab1(NMHDR
*pNMHDR, LRESULT *pResult)
{
int
ntab = m_Tab1.GetCurSel();
switch(ntab)
{
case 0: //tab
label = By word
{
m_select.ShowWindow(SW_HIDE);
m_listbook.ShowWindow(SW_HIDE);
m_listtitle.ShowWindow(SW_HIDE);
m_listchapter.ShowWindow(SW_HIDE);
m_listverse.ShowWindow(SW_HIDE);
m_tbook.ShowWindow(SW_HIDE);
m_ttitle.ShowWindow(SW_HIDE);
m_tchapter.ShowWindow(SW_HIDE);
m_tverse.ShowWindow(SW_HIDE);
m_list1.ShowWindow(SW_SHOW);
m_edit2control.ShowWindow(SW_SHOW);
m_display.ShowWindow(SW_SHOW);
m_type.ShowWindow(SW_SHOW);
m_foundcontrol.ShowWindow(SW_SHOW);
break;
}
case 1: //tab
label = By address
{
m_select.ShowWindow(SW_SHOW);
m_listbook.ShowWindow(SW_SHOW);
m_listtitle.ShowWindow(SW_SHOW);
m_listchapter.ShowWindow(SW_SHOW);
m_listverse.ShowWindow(SW_SHOW);
m_tbook.ShowWindow(SW_SHOW);
m_ttitle.ShowWindow(SW_SHOW);
m_tchapter.ShowWindow(SW_SHOW);
m_tverse.ShowWindow(SW_SHOW);
m_listverse.SetCurSel(-1);
m_list1.ShowWindow(SW_HIDE);
m_edit2control.ShowWindow(SW_HIDE);
m_display.ShowWindow(SW_HIDE);
m_type.ShowWindow(SW_HIDE);
m_foundcontrol.ShowWindow(SW_HIDE);
break;
}
}
// TODO: Add your
control notification handler code here
*pResult = 0;
}
void
CBook::OnLbnSelchangeListBook()
{
CString Valbook;
m_listbook.GetText(m_listbook.GetCurSel(), Valbook);
//Recordset
declaration
if
(m_pRSW0)
if
(m_pRSW0->IsOpen())
m_pRSW0->Close();
delete
m_pRSW0;
m_pRSW0 =
new
CDaoRecordset(m_pDB);
m_pRSW0->Open(dbOpenDynaset,
"SELECT * from BibleTable", 0);
//Clear the list
boxes
m_listchapter.ResetContent();
m_listverse.ResetContent();
//Move to 2nd
record
m_pRSW0->MoveFirst();
vrecno = 0;
while
(!m_pRSW0->IsEOF())
{
//Values of Book,
Title, Chapter and Verse fields
varbook1 = m_pRSW0->GetFieldValue(_T("Book"));
vartitle1 = m_pRSW0->GetFieldValue(_T("BookTitle"));
varchapter1 = m_pRSW0->GetFieldValue(_T("Chapter"));
varverse1 = m_pRSW0->GetFieldValue(_T("Verse"));
if
(CString(V_BSTRT(&varbook1)) == Valbook)
{
if
(CString(V_BSTRT(&varchapter1)) == "001")
{
if
(CString(V_BSTRT(&varverse1)) == "001")
{
m_listchapter.AddString(CString(V_BSTRT(&varchapter1)));
m_listverse.AddString(CString(V_BSTRT(&varverse1)));
vrecno = m_pRSW0->GetAbsolutePosition();
}
else
m_listverse.AddString(CString(V_BSTRT(&varverse1)));
}
else
{
if
(CString(V_BSTRT(&varverse1)) == "001")
{
m_listchapter.AddString(CString(V_BSTRT(&varchapter1)));
}
}
}
m_pRSW0->MoveNext();
}
m_listtitle.SetCurSel(m_listbook.GetCurSel());
m_listchapter.SetCurSel(0);
m_listverse.SetCurSel(0);
m_pRS->MoveFirst();
m_pRS->Move(vrecno);
CalculValue();
UpdateData(FALSE);
// TODO: Add your
control notification handler code here
}
void
CBook::OnLbnSelchangeListTitle()
{
CString Valbook;
m_listbook.SetCurSel(m_listtitle.GetCurSel());
m_listbook.GetText(m_listbook.GetCurSel(), Valbook);
//Recordset
declaration
if
(m_pRSW0)
if
(m_pRSW0->IsOpen())
m_pRSW0->Close();
delete
m_pRSW0;
m_pRSW0 =
new
CDaoRecordset(m_pDB);
m_pRSW0->Open(dbOpenDynaset,
"SELECT * from BibleTable", 0);
//Clear the list
boxes
m_listchapter.ResetContent();
m_listverse.ResetContent();
//Move to 2nd
record
m_pRSW0->MoveFirst();
vrecno = 0;
while
(!m_pRSW0->IsEOF())
{
//Values of Book,
Title, Chapter and Verse fields
varbook1 = m_pRSW0->GetFieldValue(_T("Book"));
vartitle1 = m_pRSW0->GetFieldValue(_T("BookTitle"));
varchapter1 = m_pRSW0->GetFieldValue(_T("Chapter"));
varverse1 = m_pRSW0->GetFieldValue(_T("Verse"));
if
(CString(V_BSTRT(&varbook1)) == Valbook)
{
if
(CString(V_BSTRT(&varchapter1)) == "001")
{
if
(CString(V_BSTRT(&varverse1)) == "001")
{
m_listchapter.AddString(CString(V_BSTRT(&varchapter1)));
m_listverse.AddString(CString(V_BSTRT(&varverse1)));
vrecno = m_pRSW0->GetAbsolutePosition();
}
else
m_listverse.AddString(CString(V_BSTRT(&varverse1)));
}
else
{
if
(CString(V_BSTRT(&varverse1)) == "001")
{
m_listchapter.AddString(CString(V_BSTRT(&varchapter1)));
}
}
}
m_pRSW0->MoveNext();
}
m_listchapter.SetCurSel(0);
m_listverse.SetCurSel(0);
m_pRS->MoveFirst();
m_pRS->Move(vrecno);
CalculValue();
UpdateData(FALSE);
// TODO: Add your
control notification handler code here
}
void
CBook::OnLbnSelchangeListChapter()
{
CString Valbook, Valchapter;
//
m_listbook.SetCurSel(m_listtitle.GetCurSel());
m_listbook.GetText(m_listbook.GetCurSel(), Valbook);
m_listchapter.GetText(m_listchapter.GetCurSel(),
Valchapter);
//Recordset
declaration
if
(m_pRSW0)
if
(m_pRSW0->IsOpen())
m_pRSW0->Close();
delete
m_pRSW0;
m_pRSW0 =
new
CDaoRecordset(m_pDB);
m_pRSW0->Open(dbOpenDynaset,
"SELECT * from BibleTable", 0);
//Clear the list
box
m_listverse.ResetContent();
//Move to 2nd
record
m_pRSW0->MoveFirst();
vrecno = 0;
while
(!m_pRSW0->IsEOF())
{
//Values of Book,
Title, Chapter and Verse fields
varbook1 = m_pRSW0->GetFieldValue(_T("Book"));
varchapter1 = m_pRSW0->GetFieldValue(_T("Chapter"));
varverse1 = m_pRSW0->GetFieldValue(_T("Verse"));
if
((CString(V_BSTRT(&varbook1)) == Valbook) && (CString(V_BSTRT(&varchapter1))
== Valchapter))
{
if
(CString(V_BSTRT(&varverse1)) == "001")
{
m_listverse.AddString(CString(V_BSTRT(&varverse1)));
vrecno = m_pRSW0->GetAbsolutePosition();
}
else
m_listverse.AddString(CString(V_BSTRT(&varverse1)));
}
m_pRSW0->MoveNext();
}
m_listverse.SetCurSel(0);
m_pRS->MoveFirst();
m_pRS->Move(vrecno);
CalculValue();
UpdateData(FALSE);
// TODO: Add your
control notification handler code here
}
void
CBook::OnLbnSelchangeListVerse()
{
CString Valbook, Valchapter,
Valverse;
//
m_listbook.SetCurSel(m_listtitle.GetCurSel());
m_listbook.GetText(m_listbook.GetCurSel(), Valbook);
m_listchapter.GetText(m_listchapter.GetCurSel(),
Valchapter);
m_listverse.GetText(m_listverse.GetCurSel(), Valverse);
//Recordset
declaration
if
(m_pRSW0)
if
(m_pRSW0->IsOpen())
m_pRSW0->Close();
delete
m_pRSW0;
m_pRSW0 =
new
CDaoRecordset(m_pDB);
m_pRSW0->Open(dbOpenDynaset,
"SELECT * from BibleTable", 0);
//Move to 2nd
record
m_pRSW0->MoveFirst();
vrecno = 0;
while
(!m_pRSW0->IsEOF())
{
//Values of Book,
Title, Chapter and Verse fields
varbook1 = m_pRSW0->GetFieldValue(_T("Book"));
varchapter1 = m_pRSW0->GetFieldValue(_T("Chapter"));
varverse1 = m_pRSW0->GetFieldValue(_T("Verse"));
if
((CString(V_BSTRT(&varbook1)) == Valbook) && (CString(V_BSTRT(&varchapter1))
== Valchapter) && (CString(V_BSTRT(&varverse1)) ==
Valverse))
{
vrecno = m_pRSW0->GetAbsolutePosition();
goto
Vstop;
}
m_pRSW0->MoveNext();
}
Vstop:
m_pRS->MoveFirst();
m_pRS->Move(vrecno);
CalculValue();
UpdateData(FALSE);
// TODO: Add your
control notification handler code here
}
|