实验三 Aspnet控件应用.docx

上传人:b****6 文档编号:8254922 上传时间:2023-01-30 格式:DOCX 页数:13 大小:172.82KB
下载 相关 举报
实验三 Aspnet控件应用.docx_第1页
第1页 / 共13页
实验三 Aspnet控件应用.docx_第2页
第2页 / 共13页
实验三 Aspnet控件应用.docx_第3页
第3页 / 共13页
实验三 Aspnet控件应用.docx_第4页
第4页 / 共13页
实验三 Aspnet控件应用.docx_第5页
第5页 / 共13页
点击查看更多>>
下载资源
资源描述

实验三 Aspnet控件应用.docx

《实验三 Aspnet控件应用.docx》由会员分享,可在线阅读,更多相关《实验三 Aspnet控件应用.docx(13页珍藏版)》请在冰豆网上搜索。

实验三 Aspnet控件应用.docx

实验三Aspnet控件应用

信息工程学院实验报告

成绩:

指导老师(签名):

课程名称:

《数据库原理》

实验项目名称:

A控件应用实验时间:

11.8

班级:

姓名:

学号:

一、实验目的:

1、掌握WEB控件的应用;

2、掌握WEB表单验证控件的应用;

二、实验设备与器件

Win7,VS2010,SqlServer2008

三、实验内容与步骤

1、设计一个用户基本信息注册表单。

(1)通过利用工具箱所提供的各种组件完成注册界面的设计;

图1-1注册界面的设计

(2)获取各个控件的值;

(3)将控件的值写入student表中,具体程序代码见附录;

2、设计一个用户登录表单。

(1)登录界面设计;

图1-2登录界面的设计

(2)登录事件处理;

根据不同的选择到不同的数据表中查询,如果选择是学生,就到Student表中查询,如果选择的是管理员,就到Manager表中查询;

(3)信息的传递:

用Session对象将学号传到main页面,具体程序代码见附录。

3、设计一个教师开课界面。

(1)开设新课界面设计;

图1-3教师开设新课界面设计

(2)确定事件处理,将内容写入Course表中,具体程序代码见附录。

四、实验结果及分析:

1、用户基本信息注册表单的设计结果。

(1)利用浏览器进行预览,注册界面如下:

图2-1用户注册界面

(2)学生在注册界面进行注册;

图2-2用户进行注册

图2-3已注册学生信息

打开管理员的学生信息管理界面,可以查看注册成功的学生信息,说明已将学生的信息写入student表中。

2、用户登录表单的设计结果。

(1)利用浏览器进行预览,登录界面如下:

图2-4用户登录界面

(2)已注册的学生进行登录

图2-5已注册学生进行登录

图2-6学生成功登录系统界面

(3)管理员进行登录

图2-7管理员进行登录

图2-8管理员成功登录系统界面

在登录界面,根据选择的不同用户,到不同的数据表中查询,如果选择是学生,就到Student表中查询,如果选择的是管理员,就到Manager表中查询,查询记录存在则登录相应的管理系统;

3、教师开课界面的设计结果。

(1)登录管理员系统,点击进入开设新课界面进行预览,界面如下:

图2-9教师开课界面

(2)教师进行开课

 

图2-11开课成功提示

图2-10教师进行开课

图2-12课程管理界面

打开管理员的课程管理界面,可以查看到已开设的课程信息,说明已将教室开课的内容写入写入Course表中。

五、实验总结:

通过这次实验的操作让我受益匪浅,在对实例的开发的期间,逐步掌握WEB控件的应用以及WEB表单验证控件的应用。

包括熟悉了对数据库的建表,导入数据,查询,插入等一系列的操作。

更重要的是通过独立操作并实现相应功能时所带给我的成就感。

 

附录:

//---------------------------------------------学生注册页面程序----------------------------------------

usingSystem;

usingSystem.Collections.Generic;

usingSystem.Linq;

usingSystem.Web;

usingSystem.Web.UI;

usingSystem.Web.UI.WebControls;

usingSystem.Data;

usingSystem.Data.SqlClient;

publicpartialclass注册:

System.Web.UI.Page

{

protectedvoidPage_Load(objectsender,EventArgse)

{

}

protectedvoidButton1_Click(objectsender,EventArgse)

{

stringno=txt_sno.Text;

stringpaw=txt_paw.Text;

stringname=txt_name.Text;

intage=Convert.ToInt16(txt_age.Text);

stringsex="";

if(rd_sex1.Checked)

sex="男";

else

sex="女";

stringdp=dp_p.SelectedItem.Text;

//数据库连接

//stringstrcon="Server=.;Userid=linzhibin;pwd=123;database=MyDate";

stringConstr="Server=(local);IntegratedSecurity=true;DataBase=MyDate;";

SqlConnectioncon=newSqlConnection(Constr);

//编写Sql语句

stringsqlstr="insertintoStudentvalues('"+no+"','"+paw+"','"+name+"',"+age+",'"+sex+"','"+dp+"')";

//编写SqlCommand对象

SqlCommandcom=newSqlCommand(sqlstr,con);

try

{

con.Open();

com.ExecuteNonQuery();

Response.Write("alert('注册成功!

')");

Response.Redirect("Login.aspx");

}

catch(Exceptionex)

{

Response.Write("alert('注册失败!

')");

}

finally

{

con.Close();

}

}

protectedvoidButton2_Click(objectsender,EventArgse)

{

txt_sno.Text="";

txt_name.Text="";

txt_paw.Text="";

txt_age.Text="";

}

}

//-----------------------------------------用户-登录页面程序----------------------------------------

usingSystem;

usingSystem.Collections.Generic;

usingSystem.Linq;

usingSystem.Web;

usingSystem.Web.UI;

usingSystem.Web.UI.WebControls;

usingSystem.Data;

usingSystem.Data.SqlClient;

publicpartialclassLogin:

System.Web.UI.Page

{

protectedvoidPage_L(objectsender,EventArgse)

{

}

protectedvoidButton0_Click(objectsender,EventArgse)

{

stringname=txt_name.Text;

stringpwd=txt_pwd.Text;

//数据库连接

stringConstr="Server=(local);IntegratedSecurity=true;DataBase=MyDate;";

SqlConnectioncon=newSqlConnection(Constr);

//编写Sql语句

//stringsqlstr="select*fromStudentwhereSno='"+name+"'andpwd='"+pwd+"'";

stringsqlstr="";

//编写SqlCommand对象

if(RadioButton1.Checked)

{

sqlstr="select*fromStudentwhereSno='"+name+"'andpwd='"+pwd+"'";

}

else

sqlstr="select*fromManagerwhereMno='"+name+"'andMpwd='"+pwd+"'";

SqlCommandcom=newSqlCommand(sqlstr,con);

try

{

con.Open();

SqlDataReaderdr=com.ExecuteReader();

if(dr.Read())

{

//说明存在

if(RadioButton1.Checked)

{

//学生登录成功

Session["name"]=dr["Sno"].ToString();

Session["no"]=dr["Sno"].ToString();

Response.Redirect("Student\\main.aspx");

}

else

{

//管理员登录成功

Session["manager"]=dr["Mno"].ToString();

Response.Redirect("Manager\\main.aspx");

}

}

else

Response.Write("alert('用户名或密码不对,请重新输入!

')");

}

catch(Exceptionex)

{

Response.Write(ex);

}

finally

{

con.Close();

}

}

}

//-------------------------------------------教室开设课程页面程序---------------------------------------

usingSystem;

usingSystem.Collections.Generic;

usingSystem.Linq;

usingSystem.Web;

usingSystem.Web.UI;

usingSystem.Web.UI.WebControls;

usingSystem.Data;

usingSystem.Data.SqlClient;

publicpartialclassManager_addCourse:

System.Web.UI.Page

{

protectedvoidPage_Load(objectsender,EventArgse)

{

}

protectedvoidButton3_Click(objectsender,EventArgse)

{

stringno=txt_no.Text;

stringname=txt_name.Text;

stringteacher=txt_teacher.Text;

intcredit=Convert.ToInt32(txt_credit.Text);

stringinfo=txt_info.Text;

//stringstrcon="Server=.;Userid=linzhibin;pwd=123;database=MyDate";

stringConstr="Server=(local);IntegratedSecurity=true;DataBase=MyDate;";

SqlConnectioncon=newSqlConnection(Constr);

//编写Sql语句

stringsqlstr="insertintoCoursevalues('"+no+"','"+name+"',"+credit+",'"+teacher+"','"+info+"')";

//编写SqlCommand对象

SqlCommandcom=newSqlCommand(sqlstr,con);

try

{

con.Open();

com.ExecuteNonQuery();

Response.Write("alert('开课成功!

')");

}

catch(Exceptionex)

{

Response.Write(ex);

}

finally

{

con.Close();

}

}

}

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 小学教育 > 语文

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1