The Visual Basic .Net Form - Book.vb, Text Codes
 
 
 

       
      Return



  The Form -  Book.vb ...

 
 

 The codes  corresponding ...
    1st part -  Resize, View, Navigation  and Show Forms
    
   The text Code is red color, corresponding to Load data in the Statusbar control
   The text Code is Maroon color,  corresponding to activate the button btnabout
 
 
Public Class About

Inherits System.Windows.Forms.Form


 

' Variables

Dim View_Listview As Integer

Dim vrow As Integer

' Select command

Dim selectCMD As System.Data.OleDb.OleDbCommand = New OleDb.OleDbCommand("SELECT Book, BookTitle, Chapter, Verse, TextData FROM BibleTable ORDER BY Book, Chapter, Verse")

' Dataadapter

Dim bookDA As System.Data.OleDb.OleDbDataAdapter = New OleDb.OleDbDataAdapter(selectCMD)

      Windows Form Designer generated code

Private Sub Book_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

' Resize

' PictureBox Controls

Me.PictureBox1.Left = (Me.Line1.Left - Me.PictureBox1.Width) / 2

Me.PictureBox2.Left = Me.Line1.Left + Me.Line1.Width + ((Me.Width - (Me.Line1.Left + Me.Line1.Width)) - Me.PictureBox2.Width) / 2

' Tabcontrol control

Me.TabControl1.Left = Me.Line1.Left + Me.Line1.Width + ((Me.Width - (Me.Line1.Left + Me.Line1.Width)) - Me.TabControl1.Width) / 2 - 3

Try

Me.OleDbInsertCommand1.Connection = Me.OleDbConnection1

'Attempt to load the dataset.

Me.LoadDataSet()

' display the 2nd record of The 'BibleTable' table

Me.BindingContext(objBKJV2002dset, "BibleTable").Position = 2

' Navigation controls, enebled(False or True

NavigationFP(False)

NavigationNL(True)

Catch eLoad As System.Exception

'Add your error handling code here.

'Display error message, if any.

System.Windows.Forms.MessageBox.Show(eLoad.Message)

End Try

Me.objBKJV2002dset_PositionChanged()

' ListView control, set the view to show details.

ListView1.View = View.Details

View_Listview = 1

' ComboBox controls, search by Address

' Dataset

Dim KJVDSet As New DataSet

selectCMD.Connection() = Me.OleDbConnection1 ' Select command

selectCMD.CommandTimeout = 30

Me.OleDbConnection1.Open()

bookDA.Fill(KJVDSet, "bibletable")

Me.OleDbConnection1.Close()

'1- Cmbbook stores the orders of all books.

'2- Cmbbookrecno stores the orders of the KJV records corresponding to the items of Cmbbook.

'3- Cmbtitle stores the titles of books

'4- Cmbtitlerecno stores the orders of the KJV records corresponding to the items of Cmbtitle.

For vrow = 2 To KJVDSet.Tables(0).Rows.Count - 1

If KJVDSet.Tables(0).Rows(vrow).Item(2) = "001" And _

KJVDSet.Tables(0).Rows(vrow).Item(3) = "001" Then

Me.Cmbtitle.Items.Add(Trim(KJVDSet.Tables(0).Rows(vrow).Item(1)))

Me.Cmbbook.Items.Add(Trim(KJVDSet.Tables(0).Rows(vrow).Item(0)))

End If

Next

Me.Cmbtitle.Text = "Select"

Me.Cmbbook.Text = "Select"

Me.Cmbchapter.Text = "no select"

Me.Cmbverse.Text = "no select"

 

' StatusBar Panel N1 = Message

fMainForm.StatusBarPanel1.Text = "Ready ... "

End Sub

Public Sub LoadDataSet()

'Create a new dataset to hold the records returned from the call to FillDataSet.

'A temporary dataset is used because filling the existing dataset would

'require the databindings to be rebound.

Dim objDataSetTemp As APP_VBNet.BKJV2002dset

objDataSetTemp = New APP_VBNet.BKJV2002dset

Try

'Attempt to fill the temporary dataset.

Me.FillDataSet(objDataSetTemp)

Catch eFillDataSet As System.Exception

'Add your error handling code here.

Throw eFillDataSet

End Try

Try

'Empty the old records from the dataset.

objBKJV2002dset.Clear()

'Merge the records into the main dataset.

objBKJV2002dset.Merge(objDataSetTemp)

Catch eLoadMerge As System.Exception

'Add your error handling code here.

Throw eLoadMerge

End Try

End Sub

Public Sub FillDataSet(ByVal dataSet As APP_VBNet.BKJV2002dset)

'Turn off constraint checking before the dataset is filled.

'This allows the adapters to fill the dataset without concern

'for dependencies between the tables.

dataSet.EnforceConstraints = False

Try

'Open the connection.

Me.OleDbConnection1.Open()

'Attempt to fill the dataset through the OleDbDataAdapter1.

Me.OleDbDataAdapter1.Fill(dataSet)

Catch fillException As System.Exception

'Add your error handling code here.

Throw fillException

Finally

'Turn constraint checking back on.

dataSet.EnforceConstraints = True

'Close the connection whether or not the exception was thrown.

Me.OleDbConnection1.Close()

End Try

End Sub

Private Sub objBKJV2002dset_PositionChanged()

Me.lblNavLocation.Text = (((Me.BindingContext(objBKJV2002dset, "BibleTable").Position).ToString + " of ") _

+ ((Me.BindingContext(objBKJV2002dset, "BibleTable").Count) - 1).ToString)

' Navigation controls enebled(True or False

If Me.BindingContext(objBKJV2002dset, "BibleTable").Position + 1 = 3 Then

NavigationFP(False)

NavigationNL(True)

ElseIf Me.BindingContext(objBKJV2002dset, "BibleTable").Position + 1 = Me.BindingContext(objBKJV2002dset, "BibleTable").Count Then

NavigationFP(True)

NavigationNL(False)

Else

NavigationFP(True)

NavigationNL(True)

End If

End Sub

Private Sub NavigationFP(ByVal bval As Boolean)

Me.btnNavFirst.Enabled = bval

Me.btnNavPrev.Enabled = bval

End Sub

Private Sub NavigationNL(ByVal bval As Boolean)

Me.btnNavNext.Enabled = bval

Me.btnLast.Enabled = bval

End Sub

Private Sub btnNavFirst_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnNavFirst.Click

' The database KJV2002 begin with the 2nd record

Me.BindingContext(objBKJV2002dset, "BibleTable").Position = 2

Me.objBKJV2002dset_PositionChanged()

End Sub

Private Sub btnNavPrev_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnNavPrev.Click

' The database KJV2002 begin with the 2nd record

If Me.BindingContext(objBKJV2002dset, "BibleTable").Position > 2 Then

Me.BindingContext(objBKJV2002dset, "BibleTable").Position = (Me.BindingContext(objBKJV2002dset, "BibleTable").Position - 1)

Me.objBKJV2002dset_PositionChanged()

End If

End Sub

 

Private Sub btnNavNext_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnNavNext.Click

Me.BindingContext(objBKJV2002dset, "BibleTable").Position = (Me.BindingContext(objBKJV2002dset, "BibleTable").Position + 1)

Me.objBKJV2002dset_PositionChanged()

End Sub

Private Sub btnLast_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLast.Click

Me.BindingContext(objBKJV2002dset, "BibleTable").Position = (Me.objBKJV2002dset.Tables("BibleTable").Rows.Count - 1)

Me.objBKJV2002dset_PositionChanged()

End Sub

Private Sub btnAbout_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAbout.Click

' StatusBar Panel N1 = Message

fMainForm.StatusBarPanel1.Text = "About Form, moment ... "

' Call the About.vb Form

Dim f As New About

f.Show()

End Sub

Private Sub btnDone_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDone.Click

'Close the connection whether or not the exception was thrown.

Me.OleDbConnection1.Close()

Me.Close()

End Sub

   
   2nd part -  search By word
  
 In this part, use dataadapter , dataset and Select command - ( bookDA, KJVDset and  SelectCMD ) created by software

      Note:
         *  
Select command
              
Dim selectCMD As System.Data.OleDb.OleDbCommand = New OleDb.OleDbCommand("...")

      *   Dataadapter
           
Dim bookDA As System.Data.OleDb.OleDbDataAdapter = New OleDb.OleDbDataAdapter(selectCMD)

       *   Dataset
           
Dim KJVDSet As New DataSet

 

 
Private Sub TxtWord_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TxtWord.KeyPress

'The btnSearch is enabled, if the lenght of the word typed in the TxtWord control > 1

If Len(TxtWord.Text) > 1 Then

Me.btnSearch.Enabled = True

Me.btnView.Enabled = False

End If

End Sub

Private Sub btnSearch_GotFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSearch.GotFocus

Me.lbinfo1.Text = "Moment ..."

End Sub

Private Sub btnSearch_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSearch.Click

' Dataset

Dim KJVDSet As New DataSet

' Variable

Dim IFound As Integer = 0

selectCMD.Connection() = Me.OleDbConnection1 ' Select command ...

selectCMD.CommandTimeout = 30

Me.OleDbConnection1.Open()

bookDA.Fill(KJVDSet, "BibleTable")

Me.OleDbConnection1.Close()

' Clear ...

Me.lbinfo1.Text = ""

ListView1.Clear()

' Allow the user to edit item text.

ListView1.LabelEdit = True

' Allow the user to rearrange columns.

ListView1.AllowColumnReorder = True

' Select the item and subitems when selection is made.

ListView1.FullRowSelect = True

' Display grid lines.

ListView1.GridLines = True

' Column Header

ListView1.Columns.Add("Position", 60, HorizontalAlignment.Center)

ListView1.Columns.Add("Book", 40, HorizontalAlignment.Left)

ListView1.Columns.Add("Book title", 75, HorizontalAlignment.Left)

ListView1.Columns.Add("Chapter", 45, HorizontalAlignment.Left)

ListView1.Columns.Add("Verse", 45, HorizontalAlignment.Left)

For vrow = 2 To KJVDSet.Tables(0).Rows.Count - 1

If InStr(LCase(KJVDSet.Tables(0).Rows(vrow).Item(4)), LCase(Me.TxtWord.Text)) Then

' Create item and four sets of subitems.

Dim item1 As New ListViewItem(vrow.ToString, 0)

' Place a check mark next to the item.

item1.SubItems.Add(KJVDSet.Tables(0).Rows(vrow).Item(0))

item1.SubItems.Add(KJVDSet.Tables(0).Rows(vrow).Item(1))

item1.SubItems.Add(KJVDSet.Tables(0).Rows(vrow).Item(2))

item1.SubItems.Add(KJVDSet.Tables(0).Rows(vrow).Item(3))

'Add the items to the ListView.

ListView1.Items.AddRange(New ListViewItem() {item1})

' Number of verse found

IFound = IFound + 1

If IFound > 5000 Then

Me.lbinfo1.Text = " Search results for [" + Me.TxtWord.Text + "] - more then" + IFound.ToString + " verses found."

Me.TxtWord.Text = ""

Me.TxtWord.Enabled = True

Me.btnSearch.Enabled = False

Me.btnView.Enabled = True

Exit Sub

End If

End If

Next

'Display the number of items found

If IFound > 0 Then

Me.lbinfo1.Text() = " Search results for [" + Me.TxtWord.Text + "] - " + IFound.ToString + " verses found."

Else

Me.lbinfo1.Text() = " Search results for [" + Me.TxtWord.Text + "] - 0 verse found."

End If

Me.TxtWord.Text = ""

Me.TxtWord.Enabled = True

Me.btnSearch.Enabled = False

Me.btnView.Enabled = True

 

End Sub

Private Sub ListView1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles ListView1.Click

Me.BindingContext(objBKJV2002dset, "BibleTable").Position = ListView1.SelectedItems.Item(0).Text

Me.objBKJV2002dset_PositionChanged()

End Sub

Private Sub btnView_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnView.Click

View_Listview = View_Listview + 1

If View_Listview < 1 Or View_Listview > 4 Then

View_Listview = 1

End If

If View_Listview = 1 Then

ListView1.View = View.Details

ElseIf View_Listview = 2 Then

ListView1.View = View.LargeIcon

ElseIf View_Listview = 3 Then

ListView1.View = View.List

ElseIf View_Listview = 4 Then

ListView1.View = View.SmallIcon

End If

End Sub

   
    3th part, search By address
         In this part, use dataadapter , dataset and Select command - ( bookDA, KJVDset and  SelectCMD ) created by software

 
 
Private Sub Cmbtitle_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Cmbtitle.SelectedIndexChanged

Dim VPosition As Integer = 0

' Dataset

Dim KJVDSet As New DataSet

selectCMD.Connection() = OleDbConnection1 ' Select command

selectCMD.CommandTimeout = 30

Me.OleDbConnection1.Open()

bookDA.Fill(KJVDSet, "bibletable")

Me.OleDbConnection1.Close()

'1- Cmbbook stores the orders of all books.

'2- Cmbtitle stores the titles of books

'3- The Cmbchapter stores all chapters orders of the book corresponding to the item selected

'4- The Cmbverse stores all verses orders of the 1st chapter of the book

Me.Cmbchapter.Items.Clear()

Me.Cmbverse.Items.Clear()

 

For vrow = 2 To KJVDSet.Tables(0).Rows.Count - 1

If KJVDSet.Tables(0).Rows(vrow).Item(1) = Me.Cmbtitle.SelectedItem And _

KJVDSet.Tables(0).Rows(vrow).Item(2) = "001" And _

KJVDSet.Tables(0).Rows(vrow).Item(3) = "001" Then

VPosition = vrow

Me.Cmbchapter.Items.Add(Trim(KJVDSet.Tables(0).Rows(vrow).Item(2)))

Me.Cmbverse.Items.Add(Trim(KJVDSet.Tables(0).Rows(vrow).Item(3)))

GoTo NextA1

End If

Next

NextA1:

For vrow = VPosition + 1 To KJVDSet.Tables(0).Rows.Count - 1

If KJVDSet.Tables(0).Rows(vrow).Item(1) = Me.Cmbtitle.SelectedItem Then

If KJVDSet.Tables(0).Rows(vrow).Item(2) = "001" Then

Me.Cmbverse.Items.Add(Trim(KJVDSet.Tables(0).Rows(vrow).Item(3)))

Else

If KJVDSet.Tables(0).Rows(vrow).Item(3) = "001" Then

Me.Cmbchapter.Items.Add(Trim(KJVDSet.Tables(0).Rows(vrow).Item(2)))

End If

End If

End If

Next

 

'1- The record displays into the Record data boxes, includes the following data:

' the order and title of the book corresponding to the item selected,

' the 1st chapter order of the book,

' the 1st verse order of the 1st chapter

' and the contents of the verse.

'2- In the Cmbtitle, displays the item selected

'3- In the Cmbbook, displays the title of the book corresponding to the item selected

'4- In the Cmbchapter, displays the 1st chapter order of the book

'5- In the Cmbverse, displays the 1st verse order of the 1st chapter

Me.BindingContext(objBKJV2002dset, "BibleTable").Position = VPosition

Me.objBKJV2002dset_PositionChanged()

Me.Cmbbook.SelectedIndex = Me.Cmbtitle.SelectedIndex

Me.Cmbchapter.SelectedIndex = 0

Me.Cmbverse.SelectedIndex = 0

End Sub

Private Sub Cmbbook_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles Cmbbook.SelectedIndexChanged

Dim VPosition As Integer = 0

' Dataset

Dim KJVDSet As New DataSet

selectCMD.Connection() = OleDbConnection1 ' Select command

selectCMD.CommandTimeout = 30

Me.OleDbConnection1.Open()

bookDA.Fill(KJVDSet, "bibletable")

Me.OleDbConnection1.Close()

'1- Cmbbook stores the orders of all books.

'2- Cmbtitle stores the titles of books

'3- The Cmbchapter stores all chapters orders of the book corresponding to the item selected

'4- The Cmbverse stores all verses orders of the 1st chapter of the book

Me.Cmbchapter.Items.Clear()

Me.Cmbverse.Items.Clear()

 

For vrow = 2 To KJVDSet.Tables(0).Rows.Count - 1

If KJVDSet.Tables(0).Rows(vrow).Item(0) = Me.Cmbbook.SelectedItem And _

KJVDSet.Tables(0).Rows(vrow).Item(2) = "001" And _

KJVDSet.Tables(0).Rows(vrow).Item(3) = "001" Then

VPosition = vrow

Me.Cmbchapter.Items.Add(Trim(KJVDSet.Tables(0).Rows(vrow).Item(2)))

Me.Cmbverse.Items.Add(Trim(KJVDSet.Tables(0).Rows(vrow).Item(3)))

GoTo NextA2

End If

Next

NextA2:

For vrow = VPosition + 1 To KJVDSet.Tables(0).Rows.Count - 1

If KJVDSet.Tables(0).Rows(vrow).Item(0) = Me.Cmbbook.SelectedItem Then

If KJVDSet.Tables(0).Rows(vrow).Item(2) = "001" Then

Me.Cmbverse.Items.Add(Trim(KJVDSet.Tables(0).Rows(vrow).Item(3)))

Else

If KJVDSet.Tables(0).Rows(vrow).Item(3) = "001" Then

Me.Cmbchapter.Items.Add(Trim(KJVDSet.Tables(0).Rows(vrow).Item(2)))

End If

End If

End If

Next

'1- The record displays into the Record data boxes, includes the following data:

' the order and title of the book corresponding to the item selected,

' the 1st chapter order of the book,

' the 1st verse order of the 1st chapter

' and the contents of the verse.

'2- In the Cmbtitle, displays the title of the book corresponding to the item selected

'3- In the Cmbbook, displays the item selected

'4- In the Cmbchapter, displays the 1st chapter order of the book

'5- In the Cmbverse, displays the 1st verse order of the 1st chapter

Me.BindingContext(objBKJV2002dset, "BibleTable").Position = VPosition

Me.objBKJV2002dset_PositionChanged()

Me.Cmbtitle.SelectedIndex = Me.Cmbbook.SelectedIndex

Me.Cmbchapter.SelectedIndex = 0

Me.Cmbverse.SelectedIndex = 0

End Sub

Private Sub Cmbchapter_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles Cmbchapter.SelectedIndexChanged

Dim VPosition As Integer = 0

' Dataset

Dim KJVDSet As New DataSet

selectCMD.Connection() = OleDbConnection1 ' Select command

selectCMD.CommandTimeout = 30

Me.OleDbConnection1.Open()

bookDA.Fill(KJVDSet, "bibletable")

Me.OleDbConnection1.Close()

Me.Cmbverse.Items.Clear()

For vrow = 2 To KJVDSet.Tables(0).Rows.Count - 1

If KJVDSet.Tables(0).Rows(vrow).Item(0) = Me.Cmbbook.Text And _

KJVDSet.Tables(0).Rows(vrow).Item(2) = Me.Cmbchapter.SelectedItem And _

KJVDSet.Tables(0).Rows(vrow).Item(3) = "001" Then

VPosition = vrow

Me.Cmbverse.Items.Add(Trim(KJVDSet.Tables(0).Rows(vrow).Item(3)))

GoTo NextA3

End If

Next

NextA3:

For vrow = VPosition + 1 To KJVDSet.Tables(0).Rows.Count - 1

If KJVDSet.Tables(0).Rows(vrow).Item(0) = Me.Cmbbook.SelectedItem And _

KJVDSet.Tables(0).Rows(vrow).Item(2) = Me.Cmbchapter.SelectedItem Then

Me.Cmbverse.Items.Add(Trim(KJVDSet.Tables(0).Rows(vrow).Item(3)))

End If

Next

'1- The record displays into the Record data boxes, includes the following data:

' the order and title of the book corresponding to the item selected,

' the 1st chapter order of the book,

' the 1st verse order of the 1st chapter

' and the contents of the verse.

'2- In the Cmbtitle, displays the title of the book

'3- In the Cmbbook, displays the title of the book

'4- In the Cmbchapter, displays the item selected

'5- In the Cmbverse, displays the 1st verse order of the 1st chapter

Me.BindingContext(objBKJV2002dset, "BibleTable").Position = VPosition

Me.objBKJV2002dset_PositionChanged()

Me.Cmbverse.SelectedIndex = 0

End Sub

Private Sub Cmbverse_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles Cmbverse.SelectedIndexChanged

Dim VPosition As Integer = 0

' Dataset

Dim KJVDSet As New DataSet

selectCMD.Connection() = OleDbConnection1 ' Select command

selectCMD.CommandTimeout = 30

OleDbConnection1.Open()

bookDA.Fill(KJVDSet, "bibletable")

Me.OleDbConnection1.Close()

For vrow = 2 To KJVDSet.Tables(0).Rows.Count - 1

If KJVDSet.Tables(0).Rows(vrow).Item(0) = Me.Cmbbook.Text And _

KJVDSet.Tables(0).Rows(vrow).Item(2) = Me.Cmbchapter.Text And _

KJVDSet.Tables(0).Rows(vrow).Item(3) = Me.Cmbverse.SelectedItem Then

VPosition = vrow

GoTo NextA4

End If

Next

NextA4:

'1- The record displays into the Record data boxes, includes the following data:

' the order and title of the book corresponding to the item selected,

' the 1st chapter order of the book,

' the 1st verse order of the 1st chapter

' and the contents of the verse.

'2- In the Cmbtitle, displays the title of the book

'3- In the Cmbbook, displays the title of the book

'4- In the Cmbchapter, displays the book chapter

'5- In the Cmbverse, displays the item selected

Me.BindingContext(objBKJV2002dset, "BibleTable").Position = VPosition

Me.objBKJV2002dset_PositionChanged()

End Sub

End Class



 

      Return