asp.net| Design | Web page design
This article takes the driving school management system as an example, describes how to use asp.net and SQL Server 2000来 to carry on the Dynamic Web page design, satisfies the user to the database real-time update and the inquiry request.
keywords asp.net; C #; SQL Server 2000
Introduction
In recent years, with the rapid development of Internet and the improvement of Web page making technology, the design of information management system software of driving school is becoming simpler and more standardized. Here we will adopt asp.net Dynamic Web technology, by writing C # script language to the SQL Server 2000 database operation, to achieve many of the functions of the system, such as "Registration entry", "Registration Information query", "Confirm qualified students", "Student data query" and so on.
asp.net, C # and Ado.net
1, ASP. NET is a powerful Web server-side technology introduced by Microsoft, ASP, compared with ASP. NET has more high-performance compilation features and caching mechanisms. Supports multiple development languages, including C #, J #, Visual Basic, and JScript. ASP. NET Detach program code and display content, make the code look more concise. Because ASP.net's program code is compiled, it executes more quickly than an ASP.
2. The C # language is a new programming language developed by Microsoft for the. NET platform. It is a developing language of object-oriented objects, so it has encapsulation, inheritance and polymorphism. C # syntax is concise, efficient, and can be used with other. NET language is compatible with code written in the
3, ADO. NET is used to provide data access services in the Microsoft. NET platform. It acts on the server side to access and update the database by executing SQL commands. Ado.net mainly includes Connection,dataset and command three objects, their main functions are as follows:
Connection object: Connection database;
DataSet object: Accessing the contents of the database;
Command object: Executes query directives on the database and performs non-query (update, delete, add, and so on) commands.
Web Design
The following will take the driving school management system software "student data query and modify" as an example to explain the problem of web design. (C #)
First, build a database named "JX" in SQL Server 2000 that contains tables "model", "Student data", and view "v Student data".
Secondly, "Student data query and modification" mainly consists of three pages, for: xy_search.aspx, xy_search_win.aspx, xy_search_detail.aspx, respectively for the input query conditions, display query results, Displays the details of one of the records and modifies them as needed.
1, xy_search.aspx
In this page, you design the page based on the user's query criteria by selecting the control in the Toolbox Web form with the left mouse button, dragging it to the page, placing it in the appropriate place, and then setting the properties of the control, and other controls are similar. As shown in Figure 1.
Figure 1
The page is designed to be written in the background code, in the Xy_search.aspx.cs:
Using System.Data.SqlClient;
Using system.data.sqltypes;//Add namespaces
public string name1
{
Get
{
Return
TextBox9.Text.Trim ();
}
}
Defines the content in TextBox9 as a public variable and sets the Visible property of the text box to False
private void Page_Load (object sender, System.EventArgs e)
{
Page.registerstartupscript ("Focus", "<script language= javascript> document.getElementById" (' TextBox1 '). focus ();</script> ")//Insert Java Script (Focus TextBox1)
if (! IsPostBack)//Check whether it is the first time to load this page
{
SqlConnection myconnection=new SqlConnection ("Server=jxserver;uid=sa;pwd=1818;database=jx");
Myconnection.open ()//Connection database
SqlDataAdapter Myadapter=new SqlDataAdapter ("select * from Model", myconnection);//Create Myadapter Object
DataSet mydataset=new DataSet (); Create a myDataSet object
Myadapter.fill (myDataSet, "model");//Add the record that executes the SELECT statement to the myDataSet dropdownlist1.datasource=mydataset.tables["model"]. DefaultView;
Specify DROPDOWNLIST1 data source
Dropdownlist1.datatextfield= "Model";
Specifies that the DropDownList1 text value is the ' model ' field in the ' Model ' table
dropdownlist1.datavaluefield= "Model ID";
The value value of the specified DropDownList1 is the ' Model ID ' field in the ' Model ' table
Dropdownlist1.databind ()//binding Data
Dropdownlist1.selectedvalue= "C1";//Specifies that the default value of DropDownList1 is C1
Myconnection.close ()//Close database connection
}
}//Place user code here to initialize the page
/* Due to the implementation of the deletion function can be implemented at the same time query function, so only the deletion function for example * *
private void Button2_Click (object sender, System.EventArgs e)
{
Textbox9.text = "Where name like '" + TextBox1.Text.Trim () + "'";
Define name fuzzy query criteria statement
Server.Transfer ("xy_search_win.aspx");
Transfer Name query criteria statement to second page
}
private void Button4_Click (object sender, System.EventArgs e)
{
Textbox9.text = "where voucher number = '" + TextBox2.Text.Trim () + "'";
Certificate Number = value of TextBox2.Text
Server.Transfer ("xy_search_win.aspx");
}
private void Button6_click (object sender, System.EventArgs e)
{
Extbox9.text = "where learning number = '" + TextBox3.Text.Trim () + "'";
School Number = value of TextBox3.Text
Server.Transfer ("xy_search_win.aspx");
}
private void Button8_click (object sender, System.EventArgs e)
{
Textbox9.text = "Where learning number like '" +textbox4.text.trim () + "%";
Fuzzy matching of value between school number and Textbox4.text
Server.Transfer ("xy_search_win.aspx");
}
private void Button10_click (object sender, System.EventArgs e)
{
Textbox9.text = "Where registration date between '" + TextBox5.Text.Trim () + "' and '" + TextBox6.Text.Trim () + "";
Textbox5.text>= Registration Date <=textbox6.text
Server.Transfer ("xy_search_win.aspx");
}
private void Button12_click (object sender, System.EventArgs e)
{
Textbox9.text = "Where to apply for the vehicle species = '" +dropdownlist1.selectedvalue.tostring (). Trim () + "'";
Type of =dropdownlist1 the value value of the selected item
Server.Transfer ("xy_search_win.aspx");
}
private void Button14_click (object sender, System.EventArgs e)
{
Textbox9.text = "where owed amount between" +convert.todecimal (TextBox7.Text.Trim ()) + "and" +convert.todecimal ( TextBox8.Text.Trim ()) + "";
Note To convert the string type to currency type decimal
Server.Transfer ("xy_search_win.aspx");
}2, Xy_search_win.aspx
The results of the query are displayed in this page, as shown in Figure 2, and you can also select any record for deletion and editing. Note: Add the ' delete ' and ' select ' Columns in DataGrid1 's property builder and set the text of the selected column to ' edit '.
Figure 2
The Xy_search_win.aspx.cs code is as follows:
Using system.data.sqlclient;//Add namespaces
public class Xy_search_win:System.Web.UI.Page
{
Public Xy_search sourcepage;
Define the first page as the source page for the current page
public string name1
{
Get
{
Return Datagrid1.items[datagrid1.selectedindex]. CELLS[2]. Text.tostring ();
}
}//defines the selected line's ' Learning number ' as a public variable
private void Search1 ()//defines a query subroutine
{
SqlConnection myconnection= New SqlConnection ("SERVER=JXSERVER;UID=SA;PWD=1818;DATABASE=JX");
Myconnection.open ()//Connection database JX
SqlDataAdapter adapter1= New SqlDataAdapter ("Select study number, name, register, contact method, certificate number, training method, amount owed, notes from V Student Information" + TextBox1.Text + "Ord Er by school Number ", MyConnection); Query view
DataSet mydataset=new DataSet (); Adapter1.fill (myDataSet, "result1");
datagrid1.datasource=mydataset.tables["RESULT1"];
Datagrid1.datakeyfield= "School Number";//Specify keyword Ke Weixue number
Datagrid1.databind ()//binding Data
Myconnection.close ();
}
private void Page_Load (object sender, System.EventArgs e)
{
if (! IsPostBack)
{
Sourcepage= (Xy_search) Context.Handler;
Use the Context.Handler property to get a reference to the previous page instance object
textbox1.text=sourcepage.name1;//The query statement that passed the first page to TextBox1.
SEARCH1 ()//Call Query subroutine display query results
}
}
private void Datagrid1_deletecommand (Object Source,system.web.ui.webcontrols.datagridcommandeventargs e)/"Delete" Button Action Code
{
SqlConnection myconnection =new SqlConnection ("Server=jxserver;uid=sa;pwd=1818;database=jx");
Myconnection.open ();
String mydelete= "Delete from trainee data where school number = '" +datagrid1.datakeys[(int) e.item.itemindex]+ "'";//delete "Student data" table School Number ' equals the number of the selected line
SqlCommand mycommand=new SqlCommand (Mydelete, MyConnection);//Create MyCommand Object
Mycommand.executenonquery ()//Execute SQL statement
Myconnection.close ();
Search1 ();//re-invoke subroutine Refresh page;
}
private void
DataGrid1_SelectedIndexChanged (object sender, System.EventArgs e)
Edit Button Command
{
Server.Transfer ("xy_search_detail.aspx");
}
Go to third page for detailed editing
}
3, Xy_search_detail.aspx
In this page, you can edit the item with the * number in the student data, and the properties ' ReadOnly ' of the text box of the other item is set to TRUE and cannot be modified, as shown in Figure 3
Figure 3
Using System.Data.SqlClient;
public class Xy_search_detail:System.Web.UI.Page
{
Public Xy_search_win sourcepage;//Set the second page as the source page for the current page
private void Myselect1 ()//define query subroutine
{
SqlConnection myconnection =new SqlConnection ("Server=jxserver;uid=sa;pwd=1818;database=jx");
Myconnection.open ();
String myselect1= "Select school number, name, sex, registration of vehicle, identification number, mobile phone, PHS, home telephone, office telephone, memo from trainee data where to learn number = '" +textbox10.text+ "";//Query view, Textbox10.text a number for the second page.
SqlCommand mycommand1=new SqlCommand (Myselect1, MyConnection);
SqlDataReader myReader1 =mycommand1.executereader ()//Read operation
while (Myreader1.read ())//When the record is not empty, executes {...} The program in
{
Textbox1.text=myreader1.getstring (0);//School number assignment to TextBox1
Textbox2.text=myreader1.getstring (1);//Name
Textbox3.text=myreader1.getstring (2);//gender
Textbox4.text=myreader1.getstring (3);//Registration of vehicle
Textbox5.text=myreader1.getstring (4);//Certificate number
if (Myreader1.isdbnull (5) ==false)
{
Textbox9.text=myreader1.getstring (5);
Cell phone
}
Determine if the data for this record's cell phone is empty
else {textbox9.text= "";}
if (Myreader1.isdbnull (6) ==false)
{textbox11.text=myreader1.getstring (6);//PHS}
else {textbox11.text= "";}
if (Myreader1.isdbnull (7) ==false)
{textbox12.text=myreader1.getstring (7);//Home Telephone}
else {textbox12.text= "";}
if (Myreader1.isdbnull (8) ==false)
{textbox13.text=myreader1.getstring (8);//Office Telephone
}
else {textbox13.text= "";}
if (Myreader1.isdbnull (9) ==false)
{textbox7.text=myreader1.getstring (9);} Note
else {textbox7.text= "";}
}
Myreader1.close ();
Myconnection.close ();
}
private void Page_Load (object sender, System.EventArgs e)
{
if (! IsPostBack)
{
Sourcepage= (Xy_search_win) Context.Handler;
textbox10.text=sourcepage.name1;//the ' School Number ' value of the second page to the third page
Label3.text= "";//Prompt label empty
Myselect1 ()//Call query data subroutine
}
}
private void Button1_Click (object sender, System.EventArgs e)//Modify button command
{
SqlConnection myconnection=new SqlConnection ("Server=jxserver;uid=sa;pwd=1818;database=jx");
Myconnection.open ();
String Lxfs=textbox9.text.trim () + "+" +textbox11.text.trim () + "+" +_
TextBox12.Text.Trim () + "+" +textbox13.text.trim () + "+"; Define how to contact
String myupdate= "Update trainee Data Set _"
Cell phone = ' "+textbox9.text.trim () +" ', phs = ' "+textbox11.text.trim () +" ', _
Home phone = ' "+textbox12.text.trim () +" ', Office tel = ' "+textbox13.text.trim () +" ', _
Remark = ' +textbox7.text+ ', contact = ' "+lxfs+" ' where learning number = ' +textbox10.text.trim () + ' ";
SqlCommand myCommand2 = new SqlCommand (myupdate,myconnection);
Mycommand2.executenonquery ()//
Label3.text= "modified successfully, please continue!" ";
Myconnection.close ();
}
private void Button2_Click (object sender, System.EventArgs e)/"Reset" button command
{
Label3.text= "";//Prompt label empty
Myselect1 ()//Call query data subroutine
}
}
Concluding remarks
This article briefly describes how to use visualstudio.net2003 to develop asp.netweb applications. The developed system has the characteristics of fast query, large storage and high reliability, and effectively improves the efficiency of driving school management system.