淮阴工学院
《ASP.NET+数据库设计开发实习》报告
系(院): 计算机工程学院
专 业:计算机科学与技术 班 级: NIIT1111
学生姓名: 耿 帅 学号: 1111305106
指导教师: 王媛媛 张海艳
学年学期: 20## ~ 20## 学年 第 1 学期
2013 年 12 月 15 日
目 录
1 需求分析.... 1
1.1 学生需求分析.... 1
1.2 教师需求分析.... 1
1.3 管理员需求分析.... 1
2数据库、数据表设计.... 1
2.1 创建数据库.... 1
2.2 创建数据表.... 2
2.3 数据库关系图.... 3
3数据库、数据表设计.... 4
3.1 系统框架.... 4
3.2 母版页.... 5
3.3 学生界面.... 8
3.4 教师界面.... 12
3.5 注册界面.... 13
4使用到的技术.... 18
4.1 后台.... 18
4.2 前台.... 19
5 测试.... 19
1 需求分析
1.1 学生需求分析
学生可以登录到系统,如果还没有账户,首先注册账户,或者在学生登失败时提醒注册账户。学生登录到系统后可以查看有关课程、自己的信息、已选课信息,查收收到的信息,修改自己的信息(包括登录密码、联系方式等),学生可以选课、听课、下载资料、上传问题等。
1.2 教师需求分析
教师可以登录到系统,如果还没有账户,首先注册账户,或者在教师登失败时提醒先注册账户。教师登录系统后,可以向管理员申请注册新的授课信息,查看自己授课信息。
1.3 管理员需求分析
管理员可以登录到系统,注册账号,删除学生和教师的账户信息,安排本系统可以进行的课程,发布公告,推荐最新课程等。
2数据库、数据表设计
因为预计远程教育系统的修改操作会比查询操作多,故在设计数据库是大部分表采用了3NF,这样在修改时会比较方便。我初期设计了八个表,以满足系统的基本需求,在后期的系统实现过程中,根据需要添加或修改相应表。八个表分别是UserAccount,StudentInfo,InstructorInfo,ManagerInfo,Course,SelectCourse,DivingClass(GivingCourse),Information。
2.1 创建数据库
CREATE DATABASE RemoteEdu
ON PRIMARY
(
NAME=RemoteEdu,
FILENAME='E:\RemoteEdu\RemoteEdu.mdf', --在目录E:\RemoteEdu\下创建数据--库RemoteEdu
SIZE=3MB,
MAXSIZE=50MB,
FILEGROWTH=1MB
)
2.2 创建数据表
1.创建UserAccount表:
create table UserAccount (
Account char(8) primary key,
Name char(4) not null,
Duty char(10) not null,
Password char(8) not null,
)
2.创建StudentInfo表:
create table StudentInfo
(
IdentityNo char(18) primary key,
name char(4) not null,
Account char(8) foreign key references UserAccount(Account),
Sex char(2) not null,
PhoneNum char(11) not null,
Email varchar(20) not null,
Birth datetime not null,
discribtion varchar(200),
)
3.创建InstructorInfo表:
create table InstructorInfo
(
IdentityNo char(18) primary key,
name char(4) not null,
Account char(8) foreign key references UserAccount(Account),
Sex char(2) not null,
PhoneNum char(11) not null,
Email varchar(20) not null,
Birth datetime not null,
Discribtion varchar(200)
)
4.创建ManagerInfo表:
create table ManagerInfo
(
IdentityNo char(18) primary key,
name char(4) not null,
Account char(8) foreign key references UserAccount(Account),
Sex char(2) not null,
PhoneNum char(11) not null,
Email varchar(20) not null,
Birth datetime not null,
discribtion varchar(200),
)
5.创建Course表:
create table Course
(
CourseNo char(8) primary key,
CourseName char(20) not null,
CourseDescribe varchar(100),
Price float,
Type char(10)
)
6.创建DivingClass表:
create table DivingClass
(
CourseNo char(8) not null foreign key references Course(CourseNo),
IdentityNo char(18)not null foreign key references InstructorInfo(IdentityNo),
date datetime,
primary key(CourseNo,IdentityNo)
)
7.创建SelectCourse表:
create table SelectCourse
(
IdentityNo char(18) not null foreign key references StudentInfo(IdentityNo),
CourseNo char(8) not null foreign key references Course(CourseNo),
date datetime,
primary key(IdentityNo,CourseNo)
)
8.创建Information表:
create table Information
(
我收到的信息varchar(500),
发送者char(8) foreign key references UserAccount(Account),
接收者char(8)foreign key references UserAccount(Account),
日期datetime,
primary key(发送者,接收者)
)
2.3 数据库关系图
图2-1 数据库关系图
3数据库、数据表设计
3.1 系统框架
图3-1 系统框架
3.2 母版页
3.2.1 主要代码
html:
<head runat="server">
<title></title>
<style type="text/css">
#Top{ width:840px; height:80px; margin:0 auto; background-color:Orange;}
#SiteMap{ width:840px; height:25px; margin:0 auto; background-color:#ccc; position:relative;}
#ContentPlaceHolder{ width:840px; height:500px; margin :0 auto;}
#Footer{ width:840px; height:50px; margin:0 auto; background-color:Gray; position:relative;}
a{ text-decoration:none;}
</style>
</head>
<body>
<form id="form1" runat="server">
<div id="Top" style=" position:relative; top: 0px; left: 0px;">
</div>
<div id="SiteMap">
</div>
<div id="ContentPlaceHolder">
<asp:ContentPlaceHolder id="ContentPlaceHolder1" runat="server">
</asp:ContentPlaceHolder>
</div>
<div id="Footer">
</div>
</form>
</body>
C#:
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.Data;
public partial class MasterPage : System.Web.UI.MasterPage
{
string duty;
string constring = "Data Source=SDWM-20130407KX\\SQLEXPRESS;Initial Catalog=RemoteEdu;Integrated Security=true;MultipleActiveResultSets=True";
SqlConnection con;
protected void Page_Load(object sender, EventArgs e)
{
con = new SqlConnection();
con.ConnectionString = constring;
con.Open();
}
protected void RadioButtonList1_SelectedIndexChanged(object sender, EventArgs e)
{
if (RadioButtonList1.Text.Equals("学生"))
{
duty = "学生";
}
if (RadioButtonList1.Text.Equals("教师"))
{
duty = "教师";
}
if (RadioButtonList1.Text.Equals("管理员"))
{
duty = "管理员";
}
}
SqlCommand cmd = new SqlCommand("select Account,Password from UserAccount", con);
SqlDataReader dr = cmd.ExecuteReader();
while (dr.Read())
{
if (dr[0].ToString().Equals(TextBox1.Text))
{
if (duty.Equals("学生"))
{
string str_id = TextBox1.Text;
Session["ID"] = str_id;
Response.Redirect("StudentInterface.aspx");
}
if (duty.Equals("教师"))
{
string str_id = TextBox1.Text;
Session["ID"] = str_id;
Response.Redirect("TeacherInterface.aspx");
}
if (duty.Equals("管理员"))
{
string str_id = TextBox1.Text;
Session["ID"] = str_id;
Response.Redirect("ManagerInterface.aspx");
}
}
}
Response.Write("输入不正确¨");
}
}
3.2.2 部分功能
设置一个Banner盒子,用来显示系统的标识;一个SiteMap盒子,用来显示整个系统路径;一个Footer盒子,用来显示系统制作这的信息。点击“登录”,弹出登录对话框,根据输的信息进入不同的用户界面。
3.2.3 截图
图3-2母版页
3.3 学生界面
3.3.1 主要代码
html:
<div style=" width:200px; height:500px; float:left; position:relative; background-color:#B9B9FF;">
<div><a href="#" id="我的选课信息">我的选课信息</a></div>
<div><a href="#" id="我的账户管理">我的账户管理</a></div>
<div><a href="#" id="收到的信息">收到的信息</a></div>
<div><a href="#" id="我的收藏">的收藏</a></div>
<div><a href="#" id="我的笔录">我的笔录</a></div>
<div><a href="#" id="选择课程">选择课程</a></div>
<div><a href="#" id="上课">上课</a></div>
<div><a href="#" id="资料下载">资料下载</a></div>
</div>
<script type="text/javascript">
$(function () {
$("#登录").click(function () {
$("#登录界面").toggle();
});
$("#我的选课信息").click(function () {
$("#收到信息").hide();
$("#gridView1").show();
$("#区域二").hide();
$("#区域四").hide();
$("#区域五").hide();
$("#区域六¨´").hide();
$("#区域七").hide();
$("#区域八").hide();
$("#默认").hide();
});
});
</script>
C#:
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.Data;
public partial class StudentInterface : System.Web.UI.Page
{
string constring = "Data Source=SDWM-20130407KX\\SQLEXPRESS;Initial Catalog=RemoteEdu;Integrated Security=true;MultipleActiveResultSets=True";
SqlConnection con;
protected void Page_Load(object sender, EventArgs e)
{
con = new SqlConnection();
con.ConnectionString = constring;
con.Open();
SqlCommand cmd = new SqlCommand("select UserAccount.Name,UserAccount.Account,Sex,PhoneNum,UserAccount.Duty,IdentityNo,Birth,Password,Email from UserAccount join StudentInfo on UserAccount.Account=StudentInfo.Account where UserAccount.Account='" + Session["ID"].ToString() + "'", con);
DataSet ds = new DataSet();
SqlDataAdapter da = new SqlDataAdapter("select SelectCourse.CourseNo,CourseName,CourseDescribe,Price,Type from SelectCourse join Course on SelectCourse.CourseNo=Course.CourseNo join StudentInfo on StudentInfo.IdentityNo=SelectCourse.IdentityNo where StudentInfo.Account='" + Session["ID"].ToString() + "'", con);
da.Fill(ds);
GridView1.DataSource = ds;
GridView1.DataBind();
DataSet ds2 = new DataSet();
SqlDataAdapter da2 = new SqlDataAdapter("select 我收到的信息,发送者,日期¨from Information where 接收者='" + Session["ID"].ToString() + "'", con);
da2.Fill(ds2);
GridView2.DataSource = ds2;
GridView2.DataBind();
DataSet ds3 = new DataSet();
SqlDataAdapter da3 = new SqlDataAdapter("select DivingClass.CourseNo as 课号,Course.CourseName as 课程名称,InstructorInfo.name as 授课老师,InstructorInfo.IdentityNo as 教师号,CourseDescribe as 课程简介,Price as 价格,type as 分类from DivingClass join Course on DivingClass.CourseNo=Course.CourseNo join InstructorInfo on InstructorInfo.IdentityNo=DivingClass.IdentityNo", con);
da3.Fill(ds3);
GridView3.DataSource = ds3;
GridView3.DataBind();
SqlDataReader dr=cmd.ExecuteReader();
while(dr.Read())
{
Label1.Text = dr[0].ToString();
Label2.Text = dr[1].ToString();
Label3.Text = dr[0].ToString();
Label4.Text = dr[2].ToString();
Label5.Text = dr[3].ToString();
Label6.Text = dr[4].ToString();
Label7.Text = dr[5].ToString();
Label8.Text = dr[6].ToString();
}
}
protected void Button2_Click(object sender, EventArgs e)
{
Session["ID1"] = Label2.Text;
Response.Redirect("编辑区域.aspx");
}
protected void GridView3_SelectedIndexChanged(object sender, EventArgs e)
{
Session["课号"] =GridView3.SelectedRow.Cells[1].Text;
Session["教师号"] = GridView3.SelectedRow.Cells[4].Text;
Session["学生账号"] = Session["ID"];
//Response.Write(Session["学生账号"].ToString());
Response.Redirect("SelectCourse.aspx");
}
}
3.3.2 部分功能
学生里面有我的选课信息、我的账户管理、收到的信息、的收藏、我的笔录、选择课程等几个功能模块,点击分别切换界面。
3.3.3 截图
图3-3
图3-4 学生选课信息
图3-5 学生编辑界面
3.4 教师界面
3.4.1 主要代码
C#:
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.Data;
public partial class TeacherInterface : System.Web.UI.Page
{
string constring = "Data Source=SDWM-20130407KX\\SQLEXPRESS;Initial Catalog=RemoteEdu;Integrated Security=true;MultipleActiveResultSets=True";
SqlConnection con;
protected void Page_Load(object sender, EventArgs e)
{
con = new SqlConnection();
con.ConnectionString = constring;
con.Open();
SqlCommand cmd = new SqlCommand("select UserAccount.Name,UserAccount.Account,Sex,PhoneNum,UserAccount.Duty,IdentityNo,Birth,Password,Email from UserAccount join InstructorInfo on UserAccount.Account=InstructorInfo.Account where UserAccount.Account='" + Session["ID"].ToString() + "'", con);
DataSet ds = new DataSet();
DataSet ds2 = new DataSet();
SqlDataAdapter da = new SqlDataAdapter("select DivingClass.CourseNo,CourseName,CourseDescribe,Price,Type from DivingClass join Course on DivingClass.CourseNo=Course.CourseNo join InstructorInfo on InstructorInfo.IdentityNo=DivingClass.IdentityNo where InstructorInfo.Account='" + Session["ID"].ToString() + "'", con);
SqlDataAdapter da2 = new SqlDataAdapter("select 我收到的信息发送者日期from Information where 接收者='" + Session["ID"].ToString() + "'", con);
da.Fill(ds);
GridView1.DataSource = ds;
GridView1.DataBind();
da2.Fill(ds2);
GridView2.DataSource = ds2;
GridView2.DataBind();
SqlDataReader dr = cmd.ExecuteReader();
while (dr.Read())
{
Label1.Text = dr[0].ToString();
Label2.Text = dr[1].ToString();
Label3.Text = dr[0].ToString();
Label4.Text = dr[2].ToString();
Label5.Text = dr[3].ToString();
Label6.Text = dr[4].ToString();
Label7.Text = dr[5].ToString();
Label8.Text = dr[6].ToString();
}
}
protected void Button2_Click(object sender, EventArgs e)
{
Session["ID1"] = Label2.Text;
Response.Redirect("编辑区域aspx");
}
}
3.4.2 部分功能
与学生框架基本相似
3.4.3 截图
图3-5 教师收信界面
3.5 注册界面
3.5.1 主要代码
C#:
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.Data;
public partial class 注册界面: System.Web.UI.Page
{
string constring = "Data Source=SDWM-20130407KX\\SQLEXPRESS;Initial Catalog=RemoteEdu;Integrated Security=true;MultipleActiveResultSets=True";
SqlConnection con;
protected void Page_Load(object sender, EventArgs e)
{
Label3.Visible = false;
}
protected void Button1_Click(object sender, EventArgs ee)
{
con = new SqlConnection();
con.ConnectionString = constring;
if (!TextBox1.Text.Equals("") & !TextBox2.Text.Equals("") & !TextBox3.Text.Equals("") & !DropDownList1.Text.Equals("") & !TextBox5.Text.Equals("") &
!TextBox6.Text.Equals("") & !TextBox7.Text.Equals("") & !TextBox8.Text.Equals("") & !TextBox9.Text.Equals("") & !TextBox10.Text.Equals(""))
{
con.Open();
SqlCommand cmd1 = new SqlCommand("select Account from UserAccount", con);
SqlDataReader rd1 = cmd1.ExecuteReader();
if (DropDownList1.Text.Equals("学生"))//-----学生
{
int i = 0;
SqlCommand cmd2 = new SqlCommand("select IdentityNo from StudentInfo", con);
SqlDataReader rd2 = cmd2.ExecuteReader();
while (rd1.Read())
{
if (TextBox1.Text.Equals(rd1[0]))
{
rd1.Close();
i = 1;
break;
}
}
while (rd2.Read())
{
if (TextBox6.Text.Equals(rd2[0]))
{
rd2.Close();
i = 1;
break;
}
}
rd1.Close();
rd2.Close();
if (i != 1)
{
SqlCommand cmd3 = new SqlCommand("insert UserAccount values('" + TextBox1.Text.ToString() + "','" + TextBox5.Text.ToString() + "','" + DropDownList1.Text.ToString() + "','" + TextBox2.Text.ToString() + "')", con);
SqlCommand cmd4 = new SqlCommand("insert StudentInfo values('" + TextBox6.Text.ToString() + "','" + TextBox5.Text.ToString() + "','" + TextBox1.Text.ToString() + "','" + TextBox7.Text.ToString() + "','" + TextBox8.Text.ToString() + "','" + TextBox9.Text.ToString() + "','" + TextBox10.Text.ToString() + "','')", con);
if (cmd3.ExecuteNonQuery() != 0)
{
if (cmd4.ExecuteNonQuery() != 0)
{
Label2.Visible = true;
Label1.Visible = false;
Label3.Visible = false;
con.Close();
}
}
}
if (i == 1)
{
Label1.Visible = true;
Label2.Visible = false;
Label3.Visible = false;
}
}
if (DropDownList1.Text.Equals("教师"))//-----教师
{
int i = 0;
SqlCommand cmd2 = new SqlCommand("select IdentityNo from InstructorInfo", con);
SqlDataReader rd2 = cmd2.ExecuteReader();
while (rd1.Read())
{
if (TextBox1.Text.Equals(rd1[0]))
{
rd1.Close();
i = 1;
break;
}
}
while (rd2.Read())
{
if (TextBox6.Text.Equals(rd2[0]))
{
rd2.Close();
i = 1;
break;
}
}
rd1.Close();
rd2.Close();
if (i != 1)
{
SqlCommand cmd3 = new SqlCommand("insert UserAccount values('" + TextBox1.Text.ToString() + "','" + TextBox5.Text.ToString() + "','" + DropDownList1.Text.ToString() + "','" + TextBox2.Text.ToString() + "')", con);
SqlCommand cmd4 = new SqlCommand("insert InstructorInfo values('" + TextBox6.Text.ToString() + "','" + TextBox5.Text.ToString() + "','" + TextBox1.Text.ToString() + "','" + TextBox7.Text.ToString() + "','" + TextBox8.Text.ToString() + "','" + TextBox9.Text.ToString() + "','" + TextBox10.Text.ToString() + "','')", con);
if (cmd3.ExecuteNonQuery() != 0)
{
if (cmd4.ExecuteNonQuery() != 0)
{
Label2.Visible = true;
con.Close();
}
}
}
if (i == 1)
{
Label1.Visible = true;
}
}
if (DropDownList1.Text.Equals("管理员"))//-----管理员
{
int i = 0;
SqlCommand cmd2 = new SqlCommand("select IdentityNo from ManagerInfo", con);
SqlDataReader rd2 = cmd2.ExecuteReader();
while (rd1.Read())
{
if (TextBox1.Text.Equals(rd1[0]))
{
rd1.Close();
i = 1;
break;
}
}
while (rd2.Read())
{
if (TextBox6.Text.Equals(rd2[0]))
{
rd2.Close();
i = 1;
break;
}
}
rd1.Close();
rd2.Close();
if (i != 1)
{
SqlCommand cmd3 = new SqlCommand("insert UserAccount values('" + TextBox1.Text.ToString() + "','" + TextBox5.Text.ToString() + "','" + DropDownList1.Text.ToString() + "','" + TextBox2.Text.ToString() + "')", con);
SqlCommand cmd4 = new SqlCommand("insert ManagerInfo values('" + TextBox6.Text.ToString() + "','" + TextBox5.Text.ToString() + "','" + TextBox1.Text.ToString() + "','" + TextBox7.Text.ToString() + "','" + TextBox8.Text.ToString() + "','" + TextBox9.Text.ToString() + "','" + TextBox10.Text.ToString() + "','')", con);
if (cmd3.ExecuteNonQuery() != 0)
{
if (cmd4.ExecuteNonQuery() != 0)
{
Label2.Visible = true;
con.Close();
}
}
}
if (i == 1)
{
Label1.Visible = true;
}
}
}
else
{
Label3.Visible = true;
}
}
}
3.5.2 部分功能
注册用户信息,向数据库里插入该用户的有关信息。
3.5.3 截图
图3-6 注册界面
4使用到的技术
4.1 后台
Sql Server 2005,数据库技术中的参照完整性约束、实体约束,ADO.NET技术连接数据库,C#等。
4.2 前台
ASP.NET技术、Web开发技术、Jscript、css、photoshop等。
5 测试
右击“Default.aspx”文件,选择“用浏览器查看”,首页运行成功。单机“注册”,显示用户注册界面,正确输入相应信息后单机确定按钮提交,如果注册成功,弹出成功提示框,如果入册未成功,弹出失败提示信息。注册成功后,进入Sql Server 2005,输入查询语句查询用户表所有信息,显示新插入的记录。点击“登录”,弹出登录对话框,正确输入用户名和密码,选择用户职业,点击确定按钮,进入相应的用户界面学生界面有选课信息,查看、编辑个人资料,完善个人资料,查收信息以及发送信选择课程等模块。教师界面有授课信息,账户管理,收到的信息,我的收藏,申请课程,授上传资料等模块。经过一系列测试,各个模块的功能能够正长运行。
总 结
这学期我们学了数据库系统及应用和ASP.NET技术,将两者结合来做课程设计我认为更能锻炼我们的学以致用能力,另外,利用这两项技术,做出来的东西更贴近使用价值。我这次选的课题是远程教育系统,刚看到这个课题是,不知道如何下手,因为首先我要了解远程教育的体系结构。于是我上网了解了一些远程教育机构,包括它们一些基本功能,界面风格,个种用户的使用流程等,为我的初步设计做好准备。我首先分了系统所需要的基本数据集合,初步建立起几个基本表,以满足前期设计过程中的基本功能。在进行前台设计是,又先后对数据库、数据表进行了几次改动。前台设计尽量用系统平台提供的一些组件,像gridview,radiobutton等,这样界面效果会更好些。在前台设计是,我参照了一些网站的优点,尽量做到界面清晰简洁,操作容易,最大程度满足用户需求。总之,通过这次课程设计,我学到到了许多在课堂没有的知识,加强了系统分析能力,更多考虑到用户需求。在这里要感谢我的两位指导老师,王媛媛老师和张海艳老师。
参考文献
1 刘金岭,冯万利.数据库系统及应用教程.清华大学出版社,2013
2 微软公司.ASP.NET标准教程.中国劳动社会保障出版社,2003
3 王辉 黄红超.ASP.NET实用教程.清华大学出版社2005