当前位置:文档之家› Web应用开发技术实验报告

Web应用开发技术实验报告

实验一:简单计算器实验代码:using System;using System.Collections.Generic;using System.Linq;using System.Web;using System.Web.UI;using System.Web.UI.WebControls;public partial class c1 : System.Web.UI.Page{protected void Page_Load(object sender, EventArgs e){}protected void change1(object sender, EventArgs e){double n1 = double.Parse(t1.Text) + double.Parse(t2.Text);this.t4.Text = n1.ToString();}protected void change2(object sender, EventArgs e){double n1 = double.Parse(t1.Text) - double.Parse(t2.Text);this.t4.Text = n1.ToString();}protected void change3(object sender, EventArgs e){double n1 = double.Parse(t1.Text) * double.Parse(t2.Text);this.t4.Text = n1.ToString();}protected void change4(object sender, EventArgs e){double n1 = double.Parse(t1.Text) / double.Parse(t2.Text);this.t4.Text = n1.ToString();}}界面:运行界面:实验二:个人所得税实验代码:using System;using System.Collections.Generic;using System.Linq;using System.Web;using System.Web.UI;using System.Web.UI.WebControls;public partial class tax_Default : System.Web.UI.Page{protected void Page_Load(object sender, EventArgs e){}protected void Button1_Click(object sender, EventArgs e){double a = Convert.ToDouble(TextBox1.Text);double c =a-3500;if (c <= 0){TextBox1.Text = "工¤资哩?收?入?大洙??500才?纳é税©,?清?重?新?输?入?"; }else if (c <= 1500){TextBox4.Text = Convert.ToString(c * 0.03);TextBox5.Text = Convert.ToString(a - c * 0.03); /*将?一?个?基õ本?数簓据Y类え?型í转羇为a另ⅷ?一?个?基õ本?类え?型í,?* 将?指?定¨的?双?精?度è浮?点?数簓的?值μ转羇换?其?等台?效§的?字?符?串?表括?示?形?式?*/}else if (1500 < c && c <= 4500){TextBox4.Text = Convert.ToString(c * 0.1 - 105);TextBox5.Text = Convert.ToString(a - (c * 0.1 - 105));}else if (4500 <c && c <= 9000){TextBox4.Text = Convert.ToString(c * 0.2 - 555);TextBox5.Text = Convert.ToString(a - (c * 0.2 - 555));}else if (9000 < c && c <= 35000){TextBox4.Text = Convert.ToString(c * 0.25 - 1005);TextBox5.Text = Convert.ToString(a - (c * 0.25 - 1005)); }else if (35000 < c && c <= 55000){TextBox4.Text = Convert.ToString(c * 0.3 - 2755);TextBox5.Text = Convert.ToString(a - (c * 0.3 - 2755)); }else if (55000 < c && c <= 80000){TextBox4.Text = Convert.ToString(c * 0.35 - 5505);TextBox5.Text = Convert.ToString(a - (c * 0.35 - 5505)); }else if (80000 < c){TextBox4.Text = Convert.ToString(c * 0.45 - 13505);TextBox5.Text = Convert.ToString(a - (c * 0.45 - 13505)); }}protected void Button2_Click(object sender, EventArgs e){TextBox1.Text = "";TextBox4.Text = "";TextBox5.Text = "";}}界面:运行界面:实验三:文件上传实验代码:FileUpload.aspx.csusing System;using System.Collections.Generic;using System.Linq;using System.Web;using System.Web.UI;using System.Web.UI.WebControls;public partial class FileUpload : System.Web.UI.Page{protected void Page_Load(object sender, EventArgs e){}protected void Button1_Click(object sender, EventArgs e){string str = "";//如?果?FileUpload控?件t包悒?含?文?件tif (FileUpload1.HasFile){try{//生Θ??整?的?文?件t名?:绝?对?路·径?+文?件t名?string fn = Server.MapPath(Request.ApplicationPath) +"\\Uploads\\" + FileUpload1.FileName;//保馈?存?文?件tFileUpload1.SaveAs(fn);//如?果?保馈?存?成é功|,生Θ?成é结á果?信?息¢str += "客í户§端?文?件t:阰" + FileUpload1.PostedFile.FileName;str += "<br/>?器ô端?保馈?存?:阰" + fn;str += "<br/>文?件t类え?型í:阰" + FileUpload1.PostedFile.ContentType; str += "<br/>文?件t大洙?小?:阰"+ FileUpload1.PostedFile.ContentLength; }catch (Exception ex){//如?果?文?件t保馈?存?时骸?发ぁ?生Θ?异皑?常£,则ò显?示?异皑?常£信?息¢str += "保馈?存?文?件t出?错洙?:阰" + ex.Message;}}else{//如?果?不?包悒?含?文?件t,给?出??示?str = "无T上?传?文?件t。

£";}Label1.Text = str;}}Login.aspx.csusing System;using System.Collections.Generic;using System.Linq;using System.Web;using System.Web.UI;using System.Web.UI.WebControls;public partial class Login : System.Web.UI.Page{protected void LoginBtn_Click(object sender, EventArgs e){//应畖该?先è判D断?用?户§信?息¢是?否?合?法ぁ?,?本??略? Session["UserId"] = Server.HtmlEncode(UserId.Text.Trim());Session["Password"] = Server.HtmlEncode(Password.Text.Trim()); Response.Redirect("FileUpload.aspx");}}界面:Login.aspxFileUpload.aspx运行界面:实验四:使用数据库实验代码:using System;using System.Collections.Generic;using System.Linq;using System.Web;using System.Web.UI;using System.Web.UI.WebControls;public partial class_Default : System.Web.UI.Page{protected void Page_Load(object sender, EventArgs e){}protected void ListBox1_SelectedIndexChanged(object sender, EventArgs e) {if (ListBox1.SelectedIndex != -1){ListBox2.SelectedIndex = ListBox1.SelectedIndex;TextBox1.Text = ListBox1.SelectedItem.Text;TextBox2.Text = ListBox2.SelectedItem.Text;}}protected void ListBox2_SelectedIndexChanged(object sender, EventArgs e) {if (ListBox2.SelectedIndex != -1){ListBox1.SelectedIndex = ListBox2.SelectedIndex;TextBox2.Text = ListBox2.SelectedItem.Text;TextBox1.Text = ListBox1.SelectedItem.Text;}}}界面:运行界面:实验五:点名抽查实验代码:using System;using System.Collections.Generic;using System.Linq;using System.Web;using System.Web.UI;using System.Web.UI.WebControls;using System.Data.OleDb;using System.Data;using System.Configuration;public partial class Default2 : System.Web.UI.Page{private string connectionString =ConfigurationManager.ConnectionStrings["ExcelConnectionString"].ConnectionString;private static int serialnum;protected void Page_Load(object sender, EventArgs e){if (!Page.IsPostBack){serialnum = 0;}}protected void Button1_Click(object sender, EventArgs e){if (DropDownList1.SelectedValue == "软è?工¤12班悒?){serialnum = serialnum + 1;do{SerialText.Text = serialnum.ToString();OleDbConnection conn = new OleDbConnection(connectionString);string cmdText = "SELECT * FROM [Software1$] where 序ò号?='" + SerialText.Text + "' ";OleDbCommand command = new OleDbCommand(cmdText, conn);try{//打洙?开a连?接óconn.Open();//执′行D查é询ˉOleDbDataReader dr = command.ExecuteReader();while (dr.Read()){TextBox1.Text = dr["学§号?"].ToString();TextBox2.Text = dr["姓?名?"].ToString();}dr.Close();}catch (OleDbException OleDbex){//显?示?错洙?误ó信?息¢Response.Write(OleDbex.Message + "<br />");}finally{//关?闭?数簓据Y库a链ⅰ?接óconn.Close();}}while (serialnum > 36);}else if (DropDownList1.SelectedValue == "软è?卓?12班悒?){serialnum = serialnum + 1;do{SerialText.Text = serialnum.ToString();OleDbConnection conn = new OleDbConnection(connectionString);string cmdText = "SELECT * FROM [Software2$] where 序ò号?='" + SerialText.Text + "' ";OleDbCommand command = new OleDbCommand(cmdText, conn);try{//打洙?开a连?接óconn.Open();//执′行D查é询ˉOleDbDataReader dr = command.ExecuteReader();while (dr.Read()){TextBox1.Text = dr["学§号?"].ToString();TextBox2.Text = dr["姓?名?"].ToString();}dr.Close();}catch (OleDbException OleDbex){//显?示?错洙?误ó信?息¢Response.Write(OleDbex.Message + "<br />");}finally{//关?闭?数簓据Y库a链ⅰ?接óconn.Close();}}while (serialnum > 30);}}protected void Button2_Click(object sender, EventArgs e){int RecCount = CalRecordCount();Random random = new Random();int count = random.Next(1, RecCount) + 1;SerialText.Text = count.ToString();OleDbConnection conn = new OleDbConnection(connectionString);string cmdText;if (DropDownList1.SelectedValue == "软è?工¤12班悒?){cmdText = "SELECT * FROM [Software1$] where 序ò号?='" + SerialText.Text + "' ";}else{cmdText = "SELECT * FROM [Software2$] where 序ò号?='" + SerialText.Text + "' ";}OleDbCommand command = new OleDbCommand(cmdText, conn);try{//打洙?开a连?接óconn.Open();//执′行D查é询ˉOleDbDataReader dr = command.ExecuteReader();while (dr.Read()){TextBox1.Text = dr["学§号?"].ToString();TextBox2.Text = dr["姓?名?"].ToString();}dr.Close();}catch (OleDbException OleDbex){//显?示?错洙?误ó信?息¢Response.Write(OleDbex.Message + "<br />");}finally{//关?闭?数簓据Y库a链ⅰ?接óconn.Close();}}private int CalRecordCount(){int RecCount = 0;string cmdText;OleDbConnection conn = new OleDbConnection(connectionString);if (DropDownList1.SelectedValue == "软è?工¤12班悒?){cmdText = "SELECT * FROM [Software1$] ";}else{cmdText = "SELECT * FROM [Software2$] ";}OleDbCommand command = new OleDbCommand(cmdText, conn);try{//打洙?开a连?接óconn.Open();//执′行D查é询ˉOleDbDataReader dr = command.ExecuteReader();while (dr.Read()){RecCount = RecCount + 1;}dr.Close();return RecCount;}catch (OleDbException OleDbex){//显?示?错洙?误ó信?息¢Response.Write(OleDbex.Message + "<br />");return RecCount;}finally{//关?闭?数簓据Y库a链ⅰ?接óconn.Close();}}protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e) {serialnum = 0;}protected void TextBox1_TextChanged(object sender, EventArgs e){}protected void SerialText_TextChanged(object sender, EventArgs e){}}界面:运行界面:。

相关主题