The Visual C# 2010 Form - BookForm.cs, Text Codes
 
 
 

       
      Return



  The Form -  BookForm.cs  ...

 
 

 The codes  corresponding ...
       
  
 
//1st part -  Resize, View, Navigation  and Show Forms

using System;

using System.Collections.Generic;

using System.ComponentModel;

using System.Data;

using System.Drawing;

using System.Linq;

using System.Text;

using System.Windows.Forms;

namespace App_CAKJV10

{

public partial class BookForm : Form

{

// Variables

// Declaration, MainForm Form

App_CAKJV10.MainForm fm = new MainForm();

//connection

System.Data.OleDb.OleDbConnection bConnection1 = new System.Data.OleDb.OleDbConnection();

// Select command

System.Data.OleDb.OleDbCommand selectCMDda;

// Data adapter

System.Data.OleDb.OleDbDataAdapter da = new System.Data.OleDb.OleDbDataAdapter();

// Select command

System.Data.OleDb.OleDbCommand selectCMD;

// Data adapter

System.Data.OleDb.OleDbDataAdapter bookDA = new System.Data.OleDb.OleDbDataAdapter();

private System.Data.OleDb.OleDbCommand oleDbSelectCommand1;

private System.Data.OleDb.OleDbCommand oleDbInsertCommand1;

private System.Data.OleDb.OleDbConnection oleDbConnection1;

// DataSet

System.Data.DataSet KJVDSet;

int View_Listview;

int vrow;

public BookForm()

{

InitializeComponent();

}

private void BookForm_Load(object sender, EventArgs e)

{

this.bConnection1.ConnectionString = @"Provider=""Microsoft.Jet.OLEDB.4.0"";Data Source=""C:\App_CAKJV10\App_CAKJV10\pic\KJV2002.mdb"";Persist Security Info=False;User ID=Admin;Mode=Share Deny None;Jet OLEDB:Engine Type=5;Jet OLEDB:Database Locking Mode=1;Jet OLEDB:Global Partial Bulk Ops=2;Jet OLEDB:Global Bulk Transactions=1;Jet OLEDB:Create System Database=False;Jet OLEDB:Encrypt Database=False;Jet OLEDB:Don't Copy Locale on Compact=False;Jet OLEDB:Compact Without Replica Repair=False;Jet OLEDB:SFP=False";

try

{

// Attempt to load the dataset.

this.LoadDataSet();

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

this.BindingContext[bookdset1, "BibleTable"].Position = 2;

// ListView control, set the view to show details.

this.listView1.View = View.Details;

View_Listview = 1;

// ComboBox controls, search by Address

selectCMD = new System.Data.OleDb.OleDbCommand("SELECT Book, BookTitle, Chapter, Verse, TextData FROM BibleTable ORDER BY Book, Chapter, Verse", bConnection1);

selectCMD.Connection = bConnection1;

bookDA.SelectCommand = selectCMD;

KJVDSet = new System.Data.DataSet();

bConnection1.Open();

bookDA.Fill(KJVDSet, "BibleTable");

bConnection1.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; vrow <= KJVDSet.Tables["BibleTable"].Rows.Count - 1; vrow++)

{

if ((KJVDSet.Tables["BibleTable"].Rows[vrow]["Chapter"].ToString() == "001") && (KJVDSet.Tables["BibleTable"].Rows[vrow]["Verse"].ToString() == "001"))

{

this.cmbtitle.Items.Add(KJVDSet.Tables["BibleTable"].Rows[vrow]["BookTitle"].ToString());

this.cmbbook.Items.Add(KJVDSet.Tables["BibleTable"].Rows[vrow]["Book"].ToString());

}

}

 

}

catch (System.Exception eLoad)

{

// Add your error handling code here.

// Display error message, if any.

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

}

this.bookdset1_PositionChanged();

// Navigation controls, enebled(False or True

NavigationFP(false);

NavigationNL(true);

this.cmbtitle.Text = "Select";

this.cmbbook.Text = "Select";

this.cmbchapter.Text = "no select";

this.cmbverse.Text = "no select";

 

// StatusBar Panel N1 = Message

fm.Show();

fm.statusBarPanel1.Text = "Ready... ";

fm.Refresh();

}

public void 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.

App_CAKJV10.Bookdset objDataSetTemp;

objDataSetTemp = new App_CAKJV10.Bookdset();

try

{

// Attempt to fill the temporary dataset.

this.FillDataSet(objDataSetTemp);

}

catch (System.Exception eFillDataSet)

{

// Add your error handling code here.

throw eFillDataSet;

}

try

{

// Empty the old records from the dataset.

bookdset1.Clear();

// Merge the records into the main dataset.

bookdset1.Merge(objDataSetTemp);

}

catch (System.Exception eLoadMerge)

{

// Add your error handling code here.

throw eLoadMerge;

}

}

public void FillDataSet(App_CAKJV10.Bookdset dataSet)

{

// 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;

selectCMDda = new System.Data.OleDb.OleDbCommand("SELECT Book, BookTitle, Chapter, Verse, TextData FROM BibleTable ORDER BY Book, Chapter, Verse", bConnection1);

selectCMDda.Connection = bConnection1;

da.SelectCommand = selectCMDda;

try

{

// Open the connection.

bConnection1.Open();

// Attempt to fill the dataset through the DataAdapter da.

// this.oleDbDataAdapter1

da.Fill(dataSet, "BibleTable");

}

catch (System.Exception fillException)

{

// 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.

bConnection1.Close();

}

}

private void NavigationFP(Boolean bval)

{

this.btnNavFirst.Enabled = bval;

this.btnNavPrev.Enabled = bval;

}

private void NavigationNL(Boolean bval)

{

this.btnNavNext.Enabled = bval;

this.btnLast.Enabled = bval;

}

private void bookdset1_PositionChanged()

{

this.lblNavLocation.Text = ((((this.BindingContext[bookdset1, "BibleTable"].Position + 1)).ToString() + " of ")

+ (this.BindingContext[bookdset1, "BibleTable"].Count - 1).ToString());

// Navigation controls enebled(True or False

if ((this.BindingContext[bookdset1, "BibleTable"].Position) <= 2)

{

NavigationFP(false);

NavigationNL(true);

}

else

{

if ((this.BindingContext[bookdset1, "BibleTable"].Position + 1) >= (this.BindingContext[bookdset1, "BibleTable"].Count))

{

NavigationFP(true);

NavigationNL(false);

}

else

{

NavigationFP(true);

NavigationNL(true);

}

}

}

private void btnNavFirst_Click(object sender, EventArgs e)

{

this.BindingContext[bookdset1, "BibleTable"].Position = 2;

this.bookdset1_PositionChanged();

}

private void btnNavPrev_Click(object sender, EventArgs e)

{

if (this.BindingContext[bookdset1, "BibleTable"].Position > 2)

{

this.BindingContext[bookdset1, "BibleTable"].Position = (this.BindingContext[bookdset1, "BibleTable"].Position - 1);

this.bookdset1_PositionChanged();

}

}

private void btnNavNext_Click(object sender, EventArgs e)

{

this.BindingContext[bookdset1, "BibleTable"].Position = (this.BindingContext[bookdset1, "BibleTable"].Position + 1);

this.bookdset1_PositionChanged();

}

private void btnLast_Click(object sender, EventArgs e)

{

this.BindingContext[bookdset1, "BibleTable"].Position = (this.bookdset1.Tables["BibleTable"].Rows.Count - 1);

this.bookdset1_PositionChanged();

}

private void btnDone_Click(object sender, EventArgs e)

{

this.Close();

// StatusBar Panel 1, Message ...

fm.Show();

fm.statusBarPanel1.Text = "Hello ...";

fm.Refresh();

}

 

// 2nd part -  search By word

 

private void TxtWord_KeyPress(object sender, System.Windows.Forms.KeyPressEventArgs e)

{

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

if (this.TxtWord.Text.Length > 1)

{

this.btnsearch.Enabled = true;

this.btnview.Enabled = false;

}

}

private void btnsearch_Enter(object sender, EventArgs e)

{

this.lbinfo1.Text = "Moment ...";

}

private void btnsearch_Click(object sender, EventArgs e)

{

// Variable

int IFound = 0;

selectCMD = new System.Data.OleDb.OleDbCommand("SELECT Book, BookTitle, Chapter, Verse, TextData FROM BibleTable ORDER BY Book, Chapter, Verse", bConnection1);

selectCMD.Connection = bConnection1;

bookDA.SelectCommand = selectCMD;

KJVDSet = new System.Data.DataSet();

bConnection1.Open();

bookDA.Fill(KJVDSet, "BibleTable");

bConnection1.Close();

// Clear ...

this.listView1.Clear();

// Allow the user to edit item text.

this.listView1.LabelEdit = true;

// Allow the user to rearrange columns.

this.listView1.AllowColumnReorder = true;

// Select the item and subitems when selection is made.

this.listView1.FullRowSelect = true;

// Display grid lines.

this.listView1.GridLines = true;

// Column Header

this.listView1.Columns.Add("Position", 60, HorizontalAlignment.Center);

this.listView1.Columns.Add("Book", 40, HorizontalAlignment.Left);

this.listView1.Columns.Add("Book title", 75, HorizontalAlignment.Left);

this.listView1.Columns.Add("Chapter", 45, HorizontalAlignment.Left);

this.listView1.Columns.Add("Verse", 45, HorizontalAlignment.Left);

for (vrow = 2; vrow <= KJVDSet.Tables["BibleTable"].Rows.Count - 1; vrow++)

{

// Use RichEdit control to store TextData field

this.richTextData.Text = KJVDSet.Tables["BibleTable"].Rows[vrow]["TextData"].ToString().ToLower();

// Search by Word operation, Use the Find function of RichText control if the TxtWord Value exist

if (this.richTextData.Find(this.TxtWord.Text.ToLower()) != -1)

{

// Create item and four sets of subitems.

ListViewItem item1 = new ListViewItem(System.Convert.ToString(vrow), 0);

// Place a check mark next to the item.

item1.SubItems.Add(KJVDSet.Tables["BibleTable"].Rows[vrow]["Book"].ToString());

item1.SubItems.Add(KJVDSet.Tables["BibleTable"].Rows[vrow]["BookTitle"].ToString());

item1.SubItems.Add(KJVDSet.Tables["BibleTable"].Rows[vrow]["Chapter"].ToString());

item1.SubItems.Add(KJVDSet.Tables["BibleTable"].Rows[vrow]["Verse"].ToString());

//Add the items to the ListView.

listView1.Items.AddRange(new ListViewItem[] { item1 });

// Number of verse found

IFound = IFound + 1;

if (IFound > 5000)

{

this.lbinfo1.Text = " Search results for [" + this.TxtWord.Text + "] - more then" + System.Convert.ToString(IFound) + " verses found.";

goto ExitPt;

}

}

}

//'Display the number of items found

if (IFound > 0)

this.lbinfo1.Text = " Search results for [" + this.TxtWord.Text + "] - " + System.Convert.ToString(IFound) + " verses found.";

else

{

this.lbinfo1.Text = " Search results for [" + this.TxtWord.Text + "] - 0 verse found.";

}

ExitPt:

this.TxtWord.Text = "";

this.TxtWord.Enabled = true;

this.btnsearch.Enabled = false;

this.btnview.Enabled = true;

}

private void btnview_Click(object sender, EventArgs e)

{

View_Listview = View_Listview + 1;

switch (View_Listview)

{

case 1:

this.listView1.View = View.Details;

break;

case 2:

this.listView1.View = View.LargeIcon;

break;

case 3:

this.listView1.View = View.List;

break;

case 4:

this.listView1.View = View.SmallIcon;

break;

case 5:

goto case 1;

}

}

private void listView1_Click(object sender, EventArgs e)

{

this.BindingContext[bookdset1, "BibleTable"].Position = System.Convert.ToInt16(this.listView1.SelectedItems[0].Text); // convert string to int

this.bookdset1_PositionChanged();

}

 

// 3th part, search By address

 

private void cmbtitle_SelectedIndexChanged(object sender, EventArgs e)

{

int VPosition = 0;

selectCMD = new System.Data.OleDb.OleDbCommand("SELECT Book, BookTitle, Chapter, Verse, TextData FROM BibleTable ORDER BY Book, Chapter, Verse", bConnection1);

selectCMD.Connection = bConnection1;

bookDA.SelectCommand = selectCMD;

KJVDSet = new System.Data.DataSet();

bConnection1.Open();

bookDA.Fill(KJVDSet, "BibleTable");

bConnection1.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

**/

this.cmbchapter.Items.Clear();

this.cmbverse.Items.Clear();

for (vrow = 2; vrow <= KJVDSet.Tables["BibleTable"].Rows.Count - 1; vrow++)

{

if ((KJVDSet.Tables["BibleTable"].Rows[vrow]["BookTitle"].ToString() == this.cmbtitle.SelectedItem.ToString()) && (KJVDSet.Tables["BibleTable"].Rows[vrow]["Chapter"].ToString() == "001") && (KJVDSet.Tables["BibleTable"].Rows[vrow]["Verse"].ToString() == "001"))

{

VPosition = vrow;

this.cmbchapter.Items.Add(KJVDSet.Tables["BibleTable"].Rows[vrow]["Chapter"].ToString());

this.cmbverse.Items.Add(KJVDSet.Tables["BibleTable"].Rows[vrow]["Verse"].ToString());

goto NextA1;

}

}

 

NextA1:

for (vrow = VPosition + 1; vrow <= KJVDSet.Tables["BibleTable"].Rows.Count - 1; vrow++)

{

if (KJVDSet.Tables["BibleTable"].Rows[vrow]["BookTitle"].ToString() == this.cmbtitle.SelectedItem.ToString())

{

if (KJVDSet.Tables["BibleTable"].Rows[vrow]["Chapter"].ToString() == "001")

{

this.cmbverse.Items.Add(KJVDSet.Tables["BibleTable"].Rows[vrow]["Verse"].ToString());

}

else

{

if (KJVDSet.Tables["BibleTable"].Rows[vrow]["Verse"].ToString() == "001")

{

this.cmbchapter.Items.Add(KJVDSet.Tables["BibleTable"].Rows[vrow]["Chapter"].ToString());

}

}

}

}

/**

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

**/

this.BindingContext[bookdset1, "BibleTable"].Position = VPosition;

this.bookdset1_PositionChanged();

this.cmbbook.SelectedIndex = this.cmbtitle.SelectedIndex;

this.cmbchapter.SelectedIndex = 0;

this.cmbverse.SelectedIndex = 0;

}

private void cmbbook_SelectedIndexChanged(object sender, EventArgs e)

{

int VPosition = 0;

selectCMD = new System.Data.OleDb.OleDbCommand("SELECT Book, BookTitle, Chapter, Verse, TextData FROM BibleTable ORDER BY Book, Chapter, Verse", bConnection1);

selectCMD.Connection = bConnection1;

bookDA.SelectCommand = selectCMD;

KJVDSet = new System.Data.DataSet();

bConnection1.Open();

bookDA.Fill(KJVDSet, "BibleTable");

bConnection1.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

**/

this.cmbchapter.Items.Clear();

this.cmbverse.Items.Clear();

for (vrow = 2; vrow <= KJVDSet.Tables["BibleTable"].Rows.Count - 1; vrow++)

{

if ((KJVDSet.Tables["BibleTable"].Rows[vrow]["Book"].ToString() == this.cmbbook.SelectedItem.ToString()) && (KJVDSet.Tables["BibleTable"].Rows[vrow]["Chapter"].ToString() == "001") && (KJVDSet.Tables["BibleTable"].Rows[vrow]["Verse"].ToString() == "001"))

{

VPosition = vrow;

this.cmbchapter.Items.Add(KJVDSet.Tables["BibleTable"].Rows[vrow]["Chapter"].ToString());

this.cmbverse.Items.Add(KJVDSet.Tables["BibleTable"].Rows[vrow]["Verse"].ToString());

goto NextA2;

}

}

NextA2:

for (vrow = VPosition + 1; vrow <= KJVDSet.Tables["BibleTable"].Rows.Count - 1; vrow++)

{

if ((KJVDSet.Tables["BibleTable"].Rows[vrow]["Book"].ToString() == this.cmbbook.SelectedItem.ToString()))

{

if (KJVDSet.Tables["BibleTable"].Rows[vrow]["Chapter"].ToString() == "001")

{

this.cmbverse.Items.Add(KJVDSet.Tables["BibleTable"].Rows[vrow]["Verse"].ToString());

}

else

{

if (KJVDSet.Tables["BibleTable"].Rows[vrow]["Verse"].ToString() == "001")

{

this.cmbchapter.Items.Add(KJVDSet.Tables["BibleTable"].Rows[vrow]["Chapter"].ToString());

}

}

}

}

/**

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

**/

this.BindingContext[bookdset1, "BibleTable"].Position = VPosition;

this.bookdset1_PositionChanged();

this.cmbtitle.SelectedIndex = this.cmbbook.SelectedIndex;

this.cmbchapter.SelectedIndex = 0;

this.cmbverse.SelectedIndex = 0;

}

private void cmbchapter_SelectedIndexChanged(object sender, EventArgs e)

{

int VPosition = 0;

selectCMD = new System.Data.OleDb.OleDbCommand("SELECT Book, BookTitle, Chapter, Verse, TextData FROM BibleTable ORDER BY Book, Chapter, Verse", bConnection1);

selectCMD.Connection = bConnection1;

bookDA.SelectCommand = selectCMD;

KJVDSet = new System.Data.DataSet();

bConnection1.Open();

bookDA.Fill(KJVDSet, "BibleTable");

bConnection1.Close();

this.cmbverse.Items.Clear();

for (vrow = 2; vrow <= KJVDSet.Tables["BibleTable"].Rows.Count - 1; vrow++)

{

if ((KJVDSet.Tables["BibleTable"].Rows[vrow]["Book"].ToString() == this.cmbbook.Text) && (KJVDSet.Tables["BibleTable"].Rows[vrow]["Chapter"].ToString() == this.cmbchapter.SelectedItem.ToString()) && (KJVDSet.Tables["BibleTable"].Rows[vrow]["Verse"].ToString() == "001"))

{

VPosition = vrow;

this.cmbverse.Items.Add(KJVDSet.Tables["BibleTable"].Rows[vrow]["Verse"].ToString());

goto NextA3;

}

}

NextA3:

for (vrow = VPosition + 1; vrow <= KJVDSet.Tables["BibleTable"].Rows.Count - 1; vrow++)

{

if ((KJVDSet.Tables["BibleTable"].Rows[vrow]["Book"].ToString() == this.cmbbook.Text) && (KJVDSet.Tables["BibleTable"].Rows[vrow]["Chapter"].ToString() == this.cmbchapter.SelectedItem.ToString()))

{

this.cmbverse.Items.Add(KJVDSet.Tables["BibleTable"].Rows[vrow]["Verse"].ToString());

}

}

/**

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

**/

this.BindingContext[bookdset1, "BibleTable"].Position = VPosition;

this.bookdset1_PositionChanged();

this.cmbverse.SelectedIndex = 0;

}

private void cmbverse_SelectedIndexChanged(object sender, EventArgs e)

{

int VPosition = 0;

selectCMD = new System.Data.OleDb.OleDbCommand("SELECT Book, BookTitle, Chapter, Verse, TextData FROM BibleTable ORDER BY Book, Chapter, Verse", bConnection1);

selectCMD.Connection = bConnection1;

bookDA.SelectCommand = selectCMD;

KJVDSet = new System.Data.DataSet();

bConnection1.Open();

bookDA.Fill(KJVDSet, "BibleTable");

bConnection1.Close();

for (vrow = 2; vrow <= KJVDSet.Tables["BibleTable"].Rows.Count - 1; vrow++)

{

if ((KJVDSet.Tables["BibleTable"].Rows[vrow]["Book"].ToString() == this.cmbbook.Text) && (KJVDSet.Tables["BibleTable"].Rows[vrow]["Chapter"].ToString() == this.cmbchapter.Text) && (KJVDSet.Tables["BibleTable"].Rows[vrow]["Verse"].ToString() == this.cmbverse.SelectedItem.ToString()))

{

VPosition = vrow;

goto NextA4;

}

}

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

**/

this.BindingContext[bookdset1, "BibleTable"].Position = VPosition;

this.bookdset1_PositionChanged();

}

private void TxtWord_TextChanged(object sender, EventArgs e)

{

}

}

}

   
  Notes:
      1st part -  Resize, View, Navigation  and Show Forms
   
   2nd part -  search By word
  
 In this part, use dataadapter , dataset and Select command - ( bookDA, KJVDset and  SelectCMD ) created by software

      Note:
         *  
Select command
              
System.Data.OleDb.OleDbCommand selectCMD ;

      *   Dataadapter
           
System.Data.OleDb.OleDbDataAdapter bookDA = new System.Data.OleDb.OleDbDataAdapter();

      *   Dataset
           
System.Data.DataSet KJVDSet;
 

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

 Note:

      *   Select command
           
System.Data.OleDb.OleDbCommand selectCMD ;

      *   Dataadapter
           
System.Data.OleDb.OleDbDataAdapter bookDA = new System.Data.OleDb.OleDbDataAdapter();

      *   Dataset
           
System.Data.DataSet KJVDSet;


 

   



 

      Return