当前位置:文档之家› 杭电-aspnet期末样卷

杭电-aspnet期末样卷

期末样卷一、描述1、打开VS2010,新建一个空网站项目,命名为“[学号]姓名”,保存在磁盘考生目录;2、利用VS2010新建一个本地数据库,命名为“Books.mdf”,保存在项目App_Data目录;或使用已有数据库文件“Books.mdf”;3、整体目录结构如下图:4、数据库中包含三张表:5、把压缩包内三篇短文放置在目录Books下。

二、试题1、面向对象题(20分)。

周三下午1:30 6/312创建一个抽象类:书类(Book),包含书号BookID、书名BookName,价格Price,包含一个抽象方法int FindWord(string word);创建一个教材类(TeachingMaterial)继承于书类,包含内容Content属性信息;实现FindWord ()方法,要求根据输入参数word 在Content中查找出现的次数。

2、控件应用题(30分)新建模板页MasterPage.master,模板页含有站点地图信息;并新建一个内容页TestControl.aspx,如下图构建注册页面,使用相对应的验证控件进行输入数据的有效性验证。

点击取消按钮清除文本框内已填写数据,点击确定按钮进行提交。

3、数据库题(50分)主页面MainPage.aspx主要由一个GridView构成,页面打开时GridView显示Book表中的信息,并允许选择删除一条Book信息(注意如删除书本信息,必须同时考虑删除订单信息)---------------------------------------------------------------------using System;using System.Collections.Generic;using System.Linq;using System.Web;/// <summary>/// Student 的摘要说明/// </summary>public class Student:Human{//....public Student(){//// TODO: 在此处添加构造函数逻辑//}public override void Work(){//}public void getInfo(params int[] numbers) {foreach (int num in numbers){//if num is Prime ouput num;}}private bool isPrime(int num){return true;}}public abstract class Human{public int Height { get; set; }public float Weight { get; set; }private string _name;public string Name{get { return _name; }set { _name = value; }}public abstract void Work();}--------------------------------------------------------------------- <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %><!DOCTYPE html><html xmlns="/1999/xhtml"><head runat="server"><meta http-equiv="Content-Type" content="text/html; charset=utf-8"/><title></title></head><body><form id="form1" runat="server"><div></div><asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True" DataSourceID="SqlDataSource1" DataTextField="Scholl" DataValueField="SchoolId"></asp:DropDownList><asp:Label ID="Label1" runat="server"Text="Label"></asp:Label><asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataKeyNames="StuId" DataSourceID="SqlDataSource2"><Columns><asp:BoundField DataField="StuId" HeaderText="学号" ReadOnly="True" SortExpression="StuId" /><asp:BoundField DataField="StuName" HeaderText="姓名" SortExpression="StuName" /><asp:BoundField DataField="Scholl" HeaderText="学院" SortExpression="Scholl" /></Columns></asp:GridView><asp:DropDownList ID="DropDownList2" runat="server" DataSourceID="SqlDataSource1" DataTextField="Scholl" DataValueField="SchoolId"></asp:DropDownList><asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString %>" SelectCommand="SELECT Student.StuId, Student.StuName,School.Scholl FROM Student INNER JOIN School ON Student.SchoolId = School.SchoolId WHERE (Student.SchoolId = @SchoolID)"><SelectParameters><asp:ControlParameter ControlID="DropDownList1" Name="SchoolID" PropertyName="SelectedValue" /></SelectParameters></asp:SqlDataSource><asp:Button ID="Button1" runat="server"OnClick="Button1_Click" Text="Button" /><asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString %>" SelectCommand="SELECT * FROM [School]"></asp:SqlDataSource> </form></body></html>--------------------------------using System;using System.Collections.Generic;using System.Linq;using System.Web;using System.Web.UI;using System.Web.UI.WebControls;using System.Data.SqlClient;using System.Configuration;public partial class _Default : System.Web.UI.Page{protected void Page_Load(object sender, EventArgs e){}protected void Button1_Click(object sender, EventArgs e){SqlConnection con = newSqlConnection(ConfigurationManager.ConnectionStrings["ConnectionSt ring"].ConnectionString);con.Open();SqlCommand cmd = con.CreateCommand();mandText = "update student setschoolId="+DropDownList2.SelectedValue+" whereschoolId="+DropDownList1.SelectedValue;cmd.ExecuteNonQuery();mandText = "select Count(*) from student where SchoolId="+DropDownList2.SelectedValue;Label1.Text = cmd.ExecuteScalar().ToString();con.Close();}}--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------Default.aspx.csusing System;using System.Collections.Generic;using System.Linq;using System.Web;using System.Web.UI;using System.Web.UI.WebControls;using System.Data.SqlClient;using System.Configuration;public partial class _Default : System.Web.UI.Page{protected void Page_Load(object sender, EventArgs e){}protected void Button1_Click(object sender, EventArgs e){SqlConnection con = newSqlConnection(ConfigurationManager.ConnectionStrings["ConnectionSt ring"].ConnectionString);con.Open();SqlCommand cmd = con.CreateCommand();mandText = "update stuInfo setschoolID="+DropDownList2.SelectedValue+"where schoolID="+DropDownList1.SelectedValue;cmd.ExecuteNonQuery();mandText = "select count(*) from stuInfo where schoolID="+DropDownList2.SelectedValue;Label1.Text = cmd.ExecuteScalar().ToString();con.Close();}}-----------------------------------------------------------------------------------------<%@ Page Language="C#" AutoEventWireup="true"CodeFile="Default.aspx.cs" Inherits="_Default" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0Transitional//EN""/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="/1999/xhtml"><head runat="server"><title></title></head><body><form id="form1" runat="server"><div><asp:SqlDataSource ID="SqlDataSource1" runat="server"ConnectionString="<%$ ConnectionStrings:ConnectionString %>"DeleteCommand="DELETE FROM [Student] WHERE [StuID] = @StuID"InsertCommand="INSERT INTO [Student] ([StuID], [StuName], [SchoolID]) VALUES (@StuID, @StuName, @SchoolID)"SelectCommand="SELECT * FROM [Student]"UpdateCommand="UPDATE [Student] SET [StuName] = @StuName, [SchoolID] = @SchoolID WHERE [StuID] = @StuID"> <DeleteParameters><asp:Parameter Name="StuID" Type="String" /> </DeleteParameters><InsertParameters><asp:Parameter Name="StuID" Type="String" /><asp:Parameter Name="StuName" Type="String" /><asp:Parameter Name="SchoolID" Type="String" /> </InsertParameters><UpdateParameters><asp:Parameter Name="StuName" Type="String" /><asp:Parameter Name="SchoolID" Type="String" /><asp:Parameter Name="StuID" Type="String" /> </UpdateParameters></asp:SqlDataSource><br />原先的学院ID为:<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>&nbsp; 学院学生数量:<asp:Label ID="Label2" runat="server" Text="Labe2"></asp:Label><br />选择要更新的学院:<asp:DropDownList ID="DropDownList2" runat="server"><asp:ListItem Selected="True">计算机学院</asp:ListItem><asp:ListItem>软件工程学院</asp:ListItem><asp:ListItem Value="电气学院"></asp:ListItem> </asp:DropDownList><br /><asp:Button ID="Button1" runat="server" Text="确定更新" onclick="Button1_Click" /><br /><br /><asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"DataKeyNames="StuID"DataSourceID="SqlDataSource1"><Columns><asp:BoundField DataField="StuID" HeaderText="StuID" ReadOnly="True"SortExpression="StuID" /><asp:BoundField DataField="StuName" HeaderText="StuName"SortExpression="StuName" /><asp:BoundField DataField="SchoolID" HeaderText="SchoolID"SortExpression="SchoolID" /></Columns></asp:GridView><br /></div></form></body></html>using System;using System.Collections.Generic;using System.Linq;using System.Web;using System.Web.UI;using System.Web.UI.WebControls;using System.Configuration;using System.Data.SqlClient;using System.Data;public partial class _Default : System.Web.UI.Page{//建立数据库连接string str =ConfigurationManager.ConnectionStrings["ConnectionString"].Conn ectionString.ToString();SqlConnection conn;protected void Page_Load(object sender, EventArgs e){conn = new SqlConnection(str);//打开数据库conn.Open();//获取原先学院信息string sql = string.Format("select SchoolID from Student");//创建查询器SqlDataAdapter sad = new SqlDataAdapter(sql, conn);//创建结果集DataSet dataSet = new DataSet();//将结果集填入sad.Fill(dataSet);Label1.Text =dataSet.Tables[0].Rows[0]["SchoolID"].ToString();Label2.Text = dataSet.Tables[0].Rows.Count.ToString();conn.Close();}protected void Button1_Click(object sender, EventArgs e){conn = new SqlConnection(str);//打开数据库conn.Open();//更新数据库//建立数据库命令SqlCommand sqlcommd2 = new SqlCommand("update Student set SchoolID=" + (DropDownList2.SelectedIndex + 1) + " where SchoolID=" + Label1.Text.ToString(), conn);//判断是否命令执行成功if (sqlcommd2.ExecuteNonQuery() > 0){Response.Write("更新成功!");GridView1.DataBind();}conn.Close();}}using System;using System.Collections.Generic;using System.Linq;using System.Web;using System.Web.UI;using System.Web.UI.WebControls;using System.Configuration;using System.Data.SqlClient;using System.Data;public partial class _Default : System.Web.UI.Page{//获取连接字符串string str = ConfigurationManager.ConnectionStrings["ConnectionString" ].ConnectionString.ToString();SqlConnection conn;protected void Page_Load(object sender, EventArgs e){conn = new SqlConnection(str);//打开数据库conn.Open();//获取原先学院信息string sql = string.Format("select * from Student");//创建查询器SqlDataAdapter sad = new SqlDataAdapter(sql, conn);.//创建结果集DataSet dataSet = new DataSet();//将结果集填入sad.Fill(dataSet);Label1.Text = dataSet.T ables[0].Rows[0]["SchoolID"].ToString();Label2.Text = dataSet.T ables[0].Rows.Count.ToString();//使用sqlcommd1.ExecuteScalar()进行countSqlCommand sqlcommd1 = new SqlCommand("select count(*) from Student", conn);Label3.Text = sqlcommd1.ExecuteScalar().ToString();//使用sqlcommd1.ExecuteReader()SqlCommand sqlcommd2 = new SqlCommand("select StuName from Student where SchoolID = 2", conn);.SqlDataReader reader = sqlcommd2.ExecuteReader();string str_name = "?";while(reader.Read()){str_name += reader[0] + ",";}Session["name_1"] = str_name;conn.Close();}protected void Button1_Click(object sender, EventArgs e){conn = new SqlConnection(str);//打开数据库conn.Open();//更新数据库//建立数据库命令SqlCommand sqlcommd2 = new SqlCommand("update Student set SchoolID=" + (DropDownList2.SelectedIndex + 1) + " where SchoolID=" + Label1.Text.ToString(), conn);// SqlCommand sqlcommd2 = new SqlCommand("insert into Student (StuID, StuName,SchoolID) values (14105177,'张三',2)" ,conn);// SqlCommand sqlcommd2 = new SqlCommand("delete from Student where StuName = 'HHHH'" ,conn);//判断是否命令执行成功if (sqlcommd2.ExecuteNonQuery() > 0){Response.Write("更新成功!");GridView1.DataBind();}conn.Close();}protected void Button2_Click(object sender, EventArgs e){Response.Redirect("check.aspx");}protected void Button3_Click(object sender, EventArgs e){//打开数据库conn = new SqlConnection(str);conn.Open();SqlCommand sqlcommd2 = new SqlCommand("insert into Student (StuID, StuName,SchoolID) values (14105177,'张三',2)", conn);//判断是否命令执行成功if (sqlcommd2.ExecuteNonQuery() > 0){Response.Write("更新成功!");GridView1.DataBind();}conn.Close();}protected void Button4_Click(object sender, EventArgs e){//打开数据库conn = new SqlConnection(str);conn.Open();SqlCommand sqlcommd2 = new SqlCommand("delete from Student where StuName = '张三'", conn);//判断是否命令执行成功if (sqlcommd2.ExecuteNonQuery() > 0){Response.Write("更新成功!");GridView1.DataBind();}conn.Close();}protected void Button5_Click(object sender, EventArgs e){if (FileUpload1.HasFile){FileUpload1.SaveAs(Server.MapPath("~/uploadFiles/") + FileUpload1.FileName);Image1.ImageUrl = "~/uploadFiles/" + FileUpload1.FileName;Label4.Text = "上传成功!";}}}--------------后台代码:using System;using System.Collections.Generic;using System.Linq;using System.Web;using System.Web.UI;using System.Web.UI.WebControls;using System.Configuration;using System.Data.SqlClient;using System.Data;public partial class _Default : System.Web.UI.Page{//获取连接字符串string str = ConfigurationManager.ConnectionStrings["ConnectionString" ].ConnectionString.ToString();SqlConnection conn;protected void Page_Load(object sender, EventArgs e){conn = new SqlConnection(str);//打开数据库conn.Open();//获取原先学院信息string sql = string.Format("select * from Student");//创建查询器SqlDataAdapter sad = new SqlDataAdapter(sql, conn);//创建结果集DataSet dataSet = new DataSet();//将结果集填入sad.Fill(dataSet);Label1.Text = dataSet.T ables[0].Rows[0]["SchoolID"].ToString();Label2.Text = dataSet.T ables[0].Rows.Count.ToString();//使用sqlcommd1.ExecuteScalar()进行countSqlCommand sqlcommd1 = new SqlCommand("select count(*) from Student", conn);Label3.Text = sqlcommd1.ExecuteScalar().ToString();//使用sqlcommd1.ExecuteReader()SqlCommand sqlcommd2 = new SqlCommand("select StuName from Student where SchoolID = 2", conn);SqlDataReader reader = sqlcommd2.ExecuteReader();string str_name = "?";while(reader.Read()){str_name += reader[0] + ",";}Session["name_1"] = str_name;conn.Close();}protected void Button1_Click(object sender,EventArgs e){conn = new SqlConnection(str);//打开数据库conn.Open();//更新数据库//建立数据库命令SqlCommand sqlcommd2 = new SqlCommand("update Student set SchoolID=" + (DropDownList2.SelectedIndex + 1) + " where SchoolID=" + Label1.Text.ToString(), conn);// SqlCommand sqlcommd2 = new SqlCommand("insert into Student (StuID, StuName,SchoolID) values (14105177,'张三',2)" ,conn);// SqlCommand sqlcommd2 = new SqlCommand("delete from Student where StuName = 'HHHH'" ,conn);.//判断是否命令执行成功if (sqlcommd2.ExecuteNonQuery() > 0){Response.Write("更新成功!");GridView1.DataBind();}conn.Close();}protected void Button2_Click(object sender, EventArgs e){Response.Redirect("check.aspx");}protected void Button3_Click(object sender, EventArgs e){//打开数据库conn = new SqlConnection(str);conn.Open();SqlCommand sqlcommd2 = new SqlCommand("insert into Student (StuID, StuName,SchoolID) values (14105177,'张三',2)", conn);//判断是否命令执行成功if (sqlcommd2.ExecuteNonQuery() > 0){Response.Write("更新成功!");GridView1.DataBind();}conn.Close();}protected void Button4_Click(object sender, EventArgs e){//打开数据库conn = new SqlConnection(str);conn.Open();SqlCommand sqlcommd2 = new SqlCommand("delete from Student where StuName = '张三'",conn);//判断是否命令执行成功if (sqlcommd2.ExecuteNonQuery() > 0){Response.Write("更新成功!");GridView1.DataBind();}conn.Close();}protected void Button5_Click(object sender, EventArgs e){if (FileUpload1.HasFile){FileUpload1.SaveAs(Server.MapPath("~/uploadFiles/") + FileUpload1.FileName);Image1.ImageUrl = "~/uploadFiles/" + FileUpload1.FileName;Label4.Text = "上传成功!";}}}-------------------------using System;using System.Collections.Generic;using System.Linq;using System.Web;using System.Web.UI;using System.Web.UI.WebControls;public partial class check : System.Web.UI.Page{protected void Page_Load(object sender, EventArgs e){string name = Session["name_1"].ToString();Label1.Text = name;}protected void Button1_Click(object sender, EventArgs e){string s = "";List<int> results = new List<int>();for (int i = 0; i < 10; i++){results.Add(i);}for (int i = 0; i < results.Count(); i++){s = s + results[i] + ",";Console.WriteLine(results[i]);}Label1.Text = s;}}-------------------。

相关主题