using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;

namespace DataBooks
{
/// <summary>
/// Summary description for Form1.
/// </summary>
public class Form1 : System.Windows.Forms.Form
{
private System.Data.OleDb.OleDbCommand oleDbSelectCommand1;
private System.Data.OleDb.OleDbCommand oleDbInsertCommand1;
private System.Data.OleDb.OleDbCommand oleDbUpdateCommand1;
private System.Data.OleDb.OleDbCommand oleDbDeleteCommand1;
private System.Data.OleDb.OleDbConnection conRnR;
private System.Data.OleDb.OleDbDataAdapter daBooks;
private DataBooks.dsBooks dsBooks1;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.Label label3;
private System.Windows.Forms.Label authorLabel;
private System.Windows.Forms.Label IsbnLabel;
private System.Windows.Forms.Label titleLabel;
private System.Windows.Forms.Button nextButton;
private System.Windows.Forms.Button previousButton;
private System.Windows.Forms.Button firstButton;
private System.Windows.Forms.Button lastButton;
private System.Windows.Forms.Label label4;
private System.Windows.Forms.Label label5;
private System.Windows.Forms.Label recordNumberLabel;
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.Container components = null;

public Form1()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();

//
// TODO: Add any constructor code after InitializeComponent call
//
}

/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}

#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.oleDbSelectCommand1 = new System.Data.OleDb.OleDbCommand();
this.conRnR = new System.Data.OleDb.OleDbConnection();
this.oleDbInsertCommand1 = new System.Data.OleDb.OleDbCommand();
this.oleDbUpdateCommand1 = new System.Data.OleDb.OleDbCommand();
this.oleDbDeleteCommand1 = new System.Data.OleDb.OleDbCommand();
this.daBooks = new System.Data.OleDb.OleDbDataAdapter();
this.dsBooks1 = new DataBooks.dsBooks();
this.label1 = new System.Windows.Forms.Label();
this.label2 = new System.Windows.Forms.Label();
this.label3 = new System.Windows.Forms.Label();
this.authorLabel = new System.Windows.Forms.Label();
this.IsbnLabel = new System.Windows.Forms.Label();
this.titleLabel = new System.Windows.Forms.Label();
this.nextButton = new System.Windows.Forms.Button();
this.previousButton = new System.Windows.Forms.Button();
this.firstButton = new System.Windows.Forms.Button();
this.lastButton = new System.Windows.Forms.Button();
this.label4 = new System.Windows.Forms.Label();
this.recordNumberLabel = new System.Windows.Forms.Label();
this.label5 = new System.Windows.Forms.Label();
((System.ComponentModel.ISupportInitialize)(this.dsBooks1)).BeginInit();
this.SuspendLayout();
//
// oleDbSelectCommand1
//
this.oleDbSelectCommand1.CommandText = "SELECT ISBN, Title, Author FROM Books";
this.oleDbSelectCommand1.Connection = this.conRnR;
//
// conRnR
//
this.conRnR.ConnectionString = @"Provider=Microsoft.Jet.OLEDB.4.0;Password="""";User ID=Admin;Data Source=C:\360\Programs_managedVCSharp\rnrbooks.mdb;Mode=Share Deny None;Extended Properties="""";Jet OLEDB:System database="""";Jet OLEDB:Registry Path="""";Jet OLEDB:Database Password="""";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:New Database Password="""";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";
//
// oleDbInsertCommand1
//
this.oleDbInsertCommand1.CommandText = "INSERT INTO Books(ISBN, Title, Author) VALUES (?, ?, ?)";
this.oleDbInsertCommand1.Connection = this.conRnR;
this.oleDbInsertCommand1.Parameters.Add(new System.Data.OleDb.OleDbParameter("ISBN", System.Data.OleDb.OleDbType.VarWChar, 13, "ISBN"));
this.oleDbInsertCommand1.Parameters.Add(new System.Data.OleDb.OleDbParameter("Title", System.Data.OleDb.OleDbType.VarWChar, 50, "Title"));
this.oleDbInsertCommand1.Parameters.Add(new System.Data.OleDb.OleDbParameter("Author", System.Data.OleDb.OleDbType.VarWChar, 30, "Author"));
//
// oleDbUpdateCommand1
//
this.oleDbUpdateCommand1.CommandText = "UPDATE Books SET ISBN = ?, Title = ?, Author = ? WHERE (ISBN = ?) AND (Author = ?" +
" OR ? IS NULL AND Author IS NULL) AND (Title = ? OR ? IS NULL AND Title IS NULL)" +
"";
this.oleDbUpdateCommand1.Connection = this.conRnR;
this.oleDbUpdateCommand1.Parameters.Add(new System.Data.OleDb.OleDbParameter("ISBN", System.Data.OleDb.OleDbType.VarWChar, 13, "ISBN"));
this.oleDbUpdateCommand1.Parameters.Add(new System.Data.OleDb.OleDbParameter("Title", System.Data.OleDb.OleDbType.VarWChar, 50, "Title"));
this.oleDbUpdateCommand1.Parameters.Add(new System.Data.OleDb.OleDbParameter("Author", System.Data.OleDb.OleDbType.VarWChar, 30, "Author"));
this.oleDbUpdateCommand1.Parameters.Add(new System.Data.OleDb.OleDbParameter("Original_ISBN", System.Data.OleDb.OleDbType.VarWChar, 13, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "ISBN", System.Data.DataRowVersion.Original, null));
this.oleDbUpdateCommand1.Parameters.Add(new System.Data.OleDb.OleDbParameter("Original_Author", System.Data.OleDb.OleDbType.VarWChar, 30, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "Author", System.Data.DataRowVersion.Original, null));
this.oleDbUpdateCommand1.Parameters.Add(new System.Data.OleDb.OleDbParameter("Original_Author1", System.Data.OleDb.OleDbType.VarWChar, 30, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "Author", System.Data.DataRowVersion.Original, null));
this.oleDbUpdateCommand1.Parameters.Add(new System.Data.OleDb.OleDbParameter("Original_Title", System.Data.OleDb.OleDbType.VarWChar, 50, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "Title", System.Data.DataRowVersion.Original, null));
this.oleDbUpdateCommand1.Parameters.Add(new System.Data.OleDb.OleDbParameter("Original_Title1", System.Data.OleDb.OleDbType.VarWChar, 50, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "Title", System.Data.DataRowVersion.Original, null));
//
// oleDbDeleteCommand1
//
this.oleDbDeleteCommand1.CommandText = "DELETE FROM Books WHERE (ISBN = ?) AND (Author = ? OR ? IS NULL AND Author IS NUL" +
"L) AND (Title = ? OR ? IS NULL AND Title IS NULL)";
this.oleDbDeleteCommand1.Connection = this.conRnR;
this.oleDbDeleteCommand1.Parameters.Add(new System.Data.OleDb.OleDbParameter("Original_ISBN", System.Data.OleDb.OleDbType.VarWChar, 13, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "ISBN", System.Data.DataRowVersion.Original, null));
this.oleDbDeleteCommand1.Parameters.Add(new System.Data.OleDb.OleDbParameter("Original_Author", System.Data.OleDb.OleDbType.VarWChar, 30, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "Author", System.Data.DataRowVersion.Original, null));
this.oleDbDeleteCommand1.Parameters.Add(new System.Data.OleDb.OleDbParameter("Original_Author1", System.Data.OleDb.OleDbType.VarWChar, 30, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "Author", System.Data.DataRowVersion.Original, null));
this.oleDbDeleteCommand1.Parameters.Add(new System.Data.OleDb.OleDbParameter("Original_Title", System.Data.OleDb.OleDbType.VarWChar, 50, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "Title", System.Data.DataRowVersion.Original, null));
this.oleDbDeleteCommand1.Parameters.Add(new System.Data.OleDb.OleDbParameter("Original_Title1", System.Data.OleDb.OleDbType.VarWChar, 50, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "Title", System.Data.DataRowVersion.Original, null));
//
// daBooks
//
this.daBooks.DeleteCommand = this.oleDbDeleteCommand1;
this.daBooks.InsertCommand = this.oleDbInsertCommand1;
this.daBooks.SelectCommand = this.oleDbSelectCommand1;
this.daBooks.TableMappings.AddRange(new System.Data.Common.DataTableMapping[] {
new System.Data.Common.DataTableMapping("Table", "Books", new System.Data.Common.DataColumnMapping[] {
new System.Data.Common.DataColumnMapping("ISBN", "ISBN"),
new System.Data.Common.DataColumnMapping("Title", "Title"),
new System.Data.Common.DataColumnMapping("Author", "Author")})});
this.daBooks.UpdateCommand = this.oleDbUpdateCommand1;
//
// dsBooks1
//
this.dsBooks1.DataSetName = "dsBooks";
this.dsBooks1.Locale = new System.Globalization.CultureInfo("en-US");
this.dsBooks1.Namespace = "http://www.tempuri.org/dsBooks.xsd";
//
// label1
//
this.label1.Location = new System.Drawing.Point(40, 40);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(72, 23);
this.label1.TabIndex = 0;
this.label1.Text = "Author";
//
// label2
//
this.label2.Location = new System.Drawing.Point(40, 88);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(72, 23);
this.label2.TabIndex = 1;
this.label2.Text = "ISBN";
//
// label3
//
this.label3.Location = new System.Drawing.Point(40, 136);
this.label3.Name = "label3";
this.label3.Size = new System.Drawing.Size(72, 23);
this.label3.TabIndex = 2;
this.label3.Text = "Title";
//
// authorLabel
//
this.authorLabel.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
this.authorLabel.DataBindings.Add(new System.Windows.Forms.Binding("Text", this.dsBooks1, "Books.Author"));
this.authorLabel.Location = new System.Drawing.Point(144, 40);
this.authorLabel.Name = "authorLabel";
this.authorLabel.Size = new System.Drawing.Size(200, 23);
this.authorLabel.TabIndex = 3;
//
// IsbnLabel
//
this.IsbnLabel.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
this.IsbnLabel.DataBindings.Add(new System.Windows.Forms.Binding("Text", this.dsBooks1, "Books.ISBN"));
this.IsbnLabel.Location = new System.Drawing.Point(144, 88);
this.IsbnLabel.Name = "IsbnLabel";
this.IsbnLabel.Size = new System.Drawing.Size(200, 23);
this.IsbnLabel.TabIndex = 4;
//
// titleLabel
//
this.titleLabel.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
this.titleLabel.DataBindings.Add(new System.Windows.Forms.Binding("Text", this.dsBooks1, "Books.Title"));
this.titleLabel.Location = new System.Drawing.Point(144, 136);
this.titleLabel.Name = "titleLabel";
this.titleLabel.Size = new System.Drawing.Size(200, 23);
this.titleLabel.TabIndex = 5;
//
// nextButton
//
this.nextButton.Location = new System.Drawing.Point(160, 224);
this.nextButton.Name = "nextButton";
this.nextButton.Size = new System.Drawing.Size(40, 23);
this.nextButton.TabIndex = 6;
this.nextButton.Text = ">";
this.nextButton.Click += new System.EventHandler(this.nextButton_Click);
//
// previousButton
//
this.previousButton.Location = new System.Drawing.Point(272, 224);
this.previousButton.Name = "previousButton";
this.previousButton.Size = new System.Drawing.Size(40, 23);
this.previousButton.TabIndex = 7;
this.previousButton.Text = "<";
this.previousButton.Click += new System.EventHandler(this.previousButton_Click);
//
// firstButton
//
this.firstButton.Location = new System.Drawing.Point(144, 264);
this.firstButton.Name = "firstButton";
this.firstButton.Size = new System.Drawing.Size(80, 23);
this.firstButton.TabIndex = 8;
this.firstButton.Text = "First Record";
this.firstButton.Click += new System.EventHandler(this.firstButton_Click);
//
// lastButton
//
this.lastButton.Location = new System.Drawing.Point(264, 264);
this.lastButton.Name = "lastButton";
this.lastButton.TabIndex = 9;
this.lastButton.Text = "Last Record";
this.lastButton.Click += new System.EventHandler(this.lastButton_Click);
//
// label4
//
this.label4.Location = new System.Drawing.Point(40, 184);
this.label4.Name = "label4";
this.label4.Size = new System.Drawing.Size(88, 23);
this.label4.TabIndex = 10;
this.label4.Text = "Record Number";
//
// recordNumberLabel
//
this.recordNumberLabel.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
this.recordNumberLabel.Location = new System.Drawing.Point(144, 184);
this.recordNumberLabel.Name = "recordNumberLabel";
this.recordNumberLabel.Size = new System.Drawing.Size(200, 23);
this.recordNumberLabel.TabIndex = 11;
//
// label5
//
this.label5.Location = new System.Drawing.Point(64, 240);
this.label5.Name = "label5";
this.label5.Size = new System.Drawing.Size(72, 23);
this.label5.TabIndex = 12;
this.label5.Text = "Navigate";
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(480, 301);
this.Controls.AddRange(new System.Windows.Forms.Control[] {
this.label5,
this.recordNumberLabel,
this.label4,
this.lastButton,
this.firstButton,
this.previousButton,
this.nextButton,
this.titleLabel,
this.IsbnLabel,
this.authorLabel,
this.label3,
this.label2,
this.label1});
this.Name = "Form1";
this.Text = "Form1";
this.Load += new System.EventHandler(this.Form1_Load);
((System.ComponentModel.ISupportInitialize)(this.dsBooks1)).EndInit();
this.ResumeLayout(false);

}
#endregion

/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new Form1());
}

BindingManagerBase bmBooks;
private void Form1_Load(object sender, System.EventArgs e)
{
daBooks.Fill(dsBooks1);
bmBooks = this.BindingContext[dsBooks1, "Books"];
DisplayRecPosn();
}

private void nextButton_Click(object sender, System.EventArgs e)
{
bmBooks.Position ++;
DisplayRecPosn();
}

private void previousButton_Click(object sender, System.EventArgs e)
{
bmBooks.Position --;
DisplayRecPosn();
}

private void firstButton_Click(object sender, System.EventArgs e)
{
bmBooks.Position = 0;
DisplayRecPosn();
}

private void lastButton_Click(object sender, System.EventArgs e)
{
bmBooks.Position = bmBooks.Count - 1;
DisplayRecPosn();
}

private void DisplayRecPosn()
{
int iRecCnt, iRecPosn;
//iRecCnt= dsBooks1.Tables["Books"].Rows.Count;
iRecCnt = bmBooks.Count;
if(iRecCnt == 0)
recordNumberLabel.Text = "No Records";
else
{
iRecPosn = bmBooks.Position + 1;
recordNumberLabel.Text = "Record " + iRecPosn.ToString() + " of " + iRecCnt.ToString();
}
}

}
}