package
web_VJnet; import
System.Collections.*;
import System.ComponentModel.*;
import System.Data.*;
import System.Drawing.*;
import System.Web.*;
import System.Web.SessionState.*;
import System.Web.UI.*;
import System.Web.UI.WebControls.*;
import System.Web.UI.HtmlControls.*;
/**
* Summary description for Dataweb_booknote.
*/
public
class
Dataweb_booknote
extends System.Web.UI.Page
{
protected
System.Data.OleDb.OleDbCommand oleDbSelectCommand1;
protected
System.Data.OleDb.OleDbCommand oleDbInsertCommand1;
protected
System.Data.OleDb.OleDbCommand oleDbUpdateCommand1;
protected
System.Data.OleDb.OleDbConnection oleDbConnection1;
protected
System.Data.OleDb.OleDbDataAdapter oleDbDataAdapter1;
protected
web_VJnet.Dataweb_booknotedset objDataweb_booknotedset;
protected
System.Web.UI.WebControls.DataGrid masterDataGrid;
protected
System.Web.UI.WebControls.HyperLink HyperLink2;
protected
System.Web.UI.WebControls.TextBox txtoperation;
protected
System.Web.UI.WebControls.Label Label1;
protected
System.Web.UI.WebControls.Panel Panel1;
protected
System.Web.UI.WebControls.Label Label_addinfo;
protected
System.Web.UI.WebControls.Button btn_add;
protected
System.Web.UI.WebControls.Label Label_add2;
protected
System.Web.UI.WebControls.Label Label_add1;
protected
System.Web.UI.WebControls.Label lbnavigation;
protected
System.Web.UI.WebControls.Button LastPage;
protected
System.Web.UI.WebControls.Button NextPage;
protected
System.Web.UI.WebControls.Button PreviousPage;
protected
System.Web.UI.WebControls.Button FirstPage;
protected
System.Web.UI.WebControls.Label Label_nav2;
protected
System.Web.UI.WebControls.Label Label_nav1;
protected
System.Data.OleDb.OleDbCommand oleDbDeleteCommand1;
private
void
Page_Load(Object sender, System.EventArgs e)
{
// Put user code
to initialize the page here
// controls
visible ...
sub_showcontrol(true );
if (get_Session().get_Item("mydatset")
== null)
{
try
{
this.LoadDataSet();
this.masterDataGrid.set_SelectedIndex(-1);
this.masterDataGrid.DataBind();
}
catch
(System.Exception eLoad)
{
this.get_Response().Write(eLoad.get_Message());
}
//!!
get_Session().get_Item("mydatset").equals(this.objDataweb_booknotedset);
// Enable paging.
masterDataGrid.set_AllowPaging(true );
masterDataGrid.set_PageSize(5);
if
(!get_Page().get_IsPostBack())
{
FirstPage_Click(sender, e);
this.Label_addinfo.set_Text("");
this.txtoperation.set_Text("");
}
}
else
{
this.objDataweb_booknotedset.equals(((web_VJnet.
Dataweb_booknotedset)(get_Session().get_Item("mydatset"))));
}
}
Wwb Form
Designer generated code |
public void
LoadDataSet () throws
System.Exception
{
// 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.
web_VJnet.Dataweb_booknotedset objDataSetTemp;
objDataSetTemp =
new web_VJnet.Dataweb_booknotedset();
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.
objDataweb_booknotedset.Clear();
// Merge the
records into the main dataset.
objDataweb_booknotedset.Merge(objDataSetTemp);
}
catch
(System.Exception eLoadMerge)
{
// Add your error
handling code here.
throw
eLoadMerge;
}
}
public
void
FillDataSet (web_VJnet.Dataweb_booknotedset dataSet)
throws
System.Exception
{
// 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.set_EnforceConstraints( false);
try
{
// Open the
connection.
this.oleDbConnection1.Open();
// Attempt to
fill the dataset through the OleDbDataAdapter1.
this.oleDbDataAdapter1.Fill(dataSet);
}
catch
(System.Exception fillException)
{
// Add your error
handling code here.
throw
fillException;
}
finally
{
// Turn
constraint checking back on.
dataSet.set_EnforceConstraints( true);
// Close the
connection whether or not the exception was thrown.
this.oleDbConnection1.Close();
}
}
//controls visible ...
private void
sub_showcontrol( boolean
bval)
{
this.Label_nav1.set_Visible(bval);
this.Label_nav2.set_Visible(bval);
this.FirstPage.set_Visible(bval);
this.PreviousPage.set_Visible(bval);
this.NextPage.set_Visible(bval);
this.LastPage.set_Visible(bval);
this.lbnavigation.set_Visible(bval);
this.Label_add1.set_Visible(bval);
this.Label_add2.set_Visible(bval);
this.btn_add.set_Visible(bval);
this.Label_addinfo.set_Visible(bval);
}
//***************************** Navigation ...
private void
FirstPage_Click(Object sender, System.EventArgs e)
{
masterDataGrid.set_CurrentPageIndex(0);
//Enabled buttons
and bind the data
show_Button(masterDataGrid.get_CurrentPageIndex());
}
//Enabled buttons
and bind the data
private void
show_Button( int
vCurrentPage)
{
int
vcpage = vCurrentPage + 1;
int
vPagecount;
if
(vCurrentPage == 0)
{
FirstPage.set_Enabled( false);
PreviousPage.set_Enabled( false);
NextPage.set_Enabled( true);
LastPage.set_Enabled( true);
masterDataGrid.DataBind();
vPagecount =
masterDataGrid.get_PageCount();
this.lbnavigation.set_Text("Page
: " + System.Convert.ToString(vcpage) + " of " +
System.Convert.ToString(vPagecount) + " ............ info:
Page size = 5");
return;
}
else
{
if
(vCurrentPage == (masterDataGrid.get_PageCount() - 1))
{
FirstPage.set_Enabled( true);
PreviousPage.set_Enabled( true);
NextPage.set_Enabled( false);
LastPage.set_Enabled( false);
masterDataGrid.DataBind();
vPagecount =
masterDataGrid.get_PageCount();
this.lbnavigation.set_Text("Page
: " + System.Convert.ToString(vcpage) + " of " +
System.Convert.ToString(vPagecount) + " ............ info:
Page size = 5");
return;
}
else
{
FirstPage.set_Enabled( true);
PreviousPage.set_Enabled( true);
NextPage.set_Enabled( true);
LastPage.set_Enabled( true);
masterDataGrid.DataBind();
vPagecount =
masterDataGrid.get_PageCount();
this.lbnavigation.set_Text("Page
: " + System.Convert.ToString(vcpage) + " of " +
System.Convert.ToString(vPagecount) + " ............ info:
Page size = 5");
return;
}
}
}
private void
PreviousPage_Click(Object sender, System.EventArgs e)
{
masterDataGrid.set_CurrentPageIndex(System.Math.Max(0,
masterDataGrid.get_CurrentPageIndex() - 1));
//Enabled buttons
and bind the data
show_Button(masterDataGrid.get_CurrentPageIndex());
}
private void
NextPage_Click(Object sender, System.EventArgs e)
{
masterDataGrid.set_CurrentPageIndex(System.Math.Min(masterDataGrid.get_PageCount()
- 1, masterDataGrid.get_CurrentPageIndex() + 1));
//Enabled buttons
and bind the data
show_Button(masterDataGrid.get_CurrentPageIndex());
}
private void
LastPage_Click(Object sender, System.EventArgs e)
{
masterDataGrid.set_CurrentPageIndex(masterDataGrid.get_PageCount()
- 1);
//Enabled buttons
and bind the data
show_Button(masterDataGrid.get_CurrentPageIndex());
}
//
***************************** Edit, Update, Cancel
private void
masterDataGrid_EditCommand(Object source,
System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
this.masterDataGrid.set_EditItemIndex(e.get_Item().get_ItemIndex());
this.masterDataGrid.DataBind();
this.txtoperation.set_Text("Edit
operation");
}
private void
masterDataGrid_CancelCommand(Object source,
System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
this.masterDataGrid.set_EditItemIndex(-1);
this.masterDataGrid.DataBind();
this.Label_addinfo.set_Text("");
this.txtoperation.set_Text("");
}
private void
masterDataGrid_UpdateCommand(Object source,
System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
String vfirstname;
String vfathername;
String vname;
String vcountry;
String vcity;
if (this.txtoperation.get_Text().equals("Edit
operation"))
{
// Gets the value
of the key field of the row being updated
String key =
masterDataGrid.get_DataKeys().get_Item(e.get_Item().get_ItemIndex()).ToString();
// Gets get the
value of the controls (textboxes) that the user
// updated. The
DataGrid columns are exposed as the Cells collection.
// Each cell has
a collection of controls. In this case, there is only one
// control in
each cell -- a TextBox control. To get its value,
// you copy the
TextBox to a local instance (which requires casting)
// and extract
its Text property.
//
// The first
column -- Cells(0) -- contains the Update and Cancel
buttons.
System.Web.UI.WebControls.TextBox
tb;
// Gets the value
the TextBox control in the 2nd column
tb = ((System.Web.UI.WebControls.TextBox)(e.get_Item().get_Cells().get_Item(1).get_Controls().get_Item(0)));
vname = tb.get_Text();
// Gets the value
the TextBox control in the 3th column
tb = ((System.Web.UI.WebControls.TextBox)(e.get_Item().get_Cells().get_Item(2).get_Controls().get_Item(0)));
vfirstname = tb.get_Text();
// Gets the value
the TextBox control in the 4th column
tb = ((System.Web.UI.WebControls.TextBox)(e.get_Item().get_Cells().get_Item(3).get_Controls().get_Item(0)));
vfathername = tb.get_Text();
// Gets the value
the TextBox control in the 5th column
tb = ((System.Web.UI.WebControls.TextBox)(e.get_Item().get_Cells().get_Item(4).get_Controls().get_Item(0)));
vcountry = tb.get_Text();
// Gets the value
the TextBox control in the 6th column
tb = ((System.Web.UI.WebControls.TextBox)(e.get_Item().get_Cells().get_Item(5).get_Controls().get_Item(0)));
vcity = tb.get_Text();
// Finds the row
in the dataset table that matches the
// one the user
updated in the grid. This example uses a
// special Find
method defined for the typed dataset, which
// returns a
reference to the row.
Dataweb_booknotedset.booknoteRow
r;
r =
objDataweb_booknotedset.get_booknote().FindBybookid(System.Convert.ToInt16(key));
// Updates the
dataset table.
r.set_name(vname);
r.set_first_name(vfirstname);
r.set_father_name(vfathername);
r.set_country(vcountry);
r.set_city(vcity);
// Calls a OLE
statement to update the database from the dataset
this.oleDbDataAdapter1.Update(objDataweb_booknotedset,
"booknote");
//this.oleDbDataAdapter1.set_UpdateCommand(this.oleDbUpdateCommand1);
// Takes the
DataGrid row out of editing mode
masterDataGrid.set_EditItemIndex(-1);
// Refreshes the
grid
masterDataGrid.DataBind();
return;
}
if (this.txtoperation.get_Text().equals("Add
operation"))
{
// The first
column -- Cells(0) -- contains the Update and Cancel
buttons.
System.Web.UI.WebControls.TextBox
tb;
// Gets the value
the TextBox control in the 2nd column
tb = ((System.Web.UI.WebControls.TextBox)(e.get_Item().get_Cells().get_Item(1).get_Controls().get_Item(0)));
vname = tb.get_Text();
// Gets the value
the TextBox control in the 3th column
tb = ((System.Web.UI.WebControls.TextBox)(e.get_Item().get_Cells().get_Item(2).get_Controls().get_Item(0)));
vfirstname = tb.get_Text();
// Gets the value
the TextBox control in the 4th column
tb = ((System.Web.UI.WebControls.TextBox)(e.get_Item().get_Cells().get_Item(3).get_Controls().get_Item(0)));
vfathername = tb.get_Text();
// Gets the value
the TextBox control in the 5th column
tb = ((System.Web.UI.WebControls.TextBox)(e.get_Item().get_Cells().get_Item(4).get_Controls().get_Item(0)));
vcountry = tb.get_Text();
// Gets the value
the TextBox control in the 6th column
tb = ((System.Web.UI.WebControls.TextBox)(e.get_Item().get_Cells().get_Item(5).get_Controls().get_Item(0)));
vcity = tb.get_Text();
// Finds the row
in the dataset table that matches the
// one the user
updated in the grid. This example uses a
// special Find
method defined for the typed dataset, which
// returns a
reference to the row.
Dataweb_booknotedset.booknoteRow
r;
r =
objDataweb_booknotedset.get_booknote().AddbooknoteRow(vcity,
vcountry, vfathername, vfirstname, vname);
// Calls a OLE
statement to update the database from the dataset
this.oleDbDataAdapter1.Update(objDataweb_booknotedset,
"booknote");
r.get_Table().AcceptChanges();
//this.oleDbDataAdapter1.set_UpdateCommand(this.oleDbUpdateCommand1);
// Takes the
DataGrid row out of editing mode
masterDataGrid.set_EditItemIndex(-1);
// Refreshes the
grid
masterDataGrid.DataBind();
this.Label_addinfo.set_Text("");
this.txtoperation.set_Text("");
return;
}
}
private void
btn_add_Click (Object sender, System.EventArgs e)
{
//show first page
...
this.FirstPage_Click(sender,
e);
this.txtoperation.set_Text("Add
operation");
//Add new record
DataRow drow = this .objDataweb_booknotedset.get_Tables().get_Item("booknote").NewRow();
drow.set_Item("name", "");
drow.set_Item("first_name", "");
drow.set_Item("father_name", "");
drow.set_Item("country", "");
drow.set_Item("city", "");
this.Label_addinfo.set_Text("New
row to be add ...");
this.objDataweb_booknotedset.get_booknote().get_Rows().InsertAt(drow,
0);
masterDataGrid.set_EditItemIndex(0);
masterDataGrid.DataBind();
}
}
|