




版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、数据库课程设计计算机科学与技术学院20082009 学年第 2学期 数据库原理()课程设计题目: 学生管理系统 班级: 学号: 姓名: 教师: 成绩: 一、需求分析随着社会的进步,各种信息量也逐渐增加,包括在学校内,对学生的信息管理就是一个很重要的环节。对于新录入的学员要及时增添其相关信息到学校数据库,而对于已经毕业的学员也要及时删除。同时,在校学生的信息还可以随时进行更新编辑,以便保证数据的完整性和正确性。此学生信息管理信息系统是面向大学的管理系统,其目的是对学校内的学生,班级,系和学会进行统一有序的管理。1)系统涉及到的各实体以及实体之间的关系如下:学生学号, 姓名,性别,宿舍区, 班号,
2、系号, 学会名班级班号,人数,入校年份,系号系 系号,系名 ,系办公室号 ,人数学会学会名,人数,成立年份,地点经过分析,有两个问题:学会和学生之间是多对多的关系 学生,班级和系形成了循环的主外键的关系,这对于级联删除和级联插入时会出现问题。所以,最终将各个实体表整合如下:学生学号, 姓名,性别,宿舍区, 班号班级班号,人数,入校年份,系号系 系号,系名 ,系办公室号 ,人数学会学会名,人数,成立年份,地点学会成员学号,学会名2)面向的对象有后台管理员和前台注册的用户,他们的权限也不相同,权限范围如下:管理员权限:注册成为管理员后,可以对系,班级,学生,学会以及学会成员分别进行添加,删除,查询
3、和修改,只要符合条件和逻辑便可以将数据写进数据库中,并保证数据没有冗余。同时可以对自己的密码进行修改。普通用户权限:注册成为普通用户后,可以对每个学生的综合信息进行查询,但不能进行添加,删除以及修改操作。进行查询显示的信息使用的是视图,是将学生,班级,系,学会成员四张表进行连接生成的。同时,用户同样可以对自己的密码进行修改。3)存储过程的应用:在普通用户进行信息查询的时候使用了存储过程,用于显示所有学生的相关信息,是基于视图操作的。4)触发器:触发器应用在普通用户注册上,当用户注册的用户名为“管理员”或者是“admin”时,自动在用户名前加上“user_”以便产生歧义。其组织结构图如下:相关数
4、据流图如下(1)管理员活动流图:(2)普通用户数据流图:数据字典:(1) 数据结构:学生含义说明:定义了一个学生的信息结构:组成:学号, 姓名,性别, 出生年月,宿舍区, 班号,系号,学会名数据项:学号含义说明:唯一标识一个学生类型:整型长度:4(2) 数据流:管理员对所有信息进行管理以及普通用户对信息进行查询说明:表示每一位登录者的操作(3) 处理过程: 各项操作(4) 定义一个视图,用于显示普通用户查询的学生信息(5) 定义一个存储过程,用于对视图中的学生信息进行查询(6) 定义一个触发器,用于对普通用户注册的限制,有些用户名不能注册二、结构设计1概念结构设计根据需求,得到的E-R图如下:
5、2.逻辑结构设计:根据以上E-R图可得一下关系模型:学生(学号, 姓名,性别,宿舍区, 班号,系号, 学会名)班级(班号,人数,入校年份,系号)系 (系号,系名 ,系办公室号 ,人数)学会(学会名,人数,成立年份,地点)属于(学号,班号)拥有(班号,系号)加入(学号,学会名)经过化简合并后得到最后的关系模型:学生(学号, 姓名,性别,宿舍区, 班号)班级(班号,人数,入校年份,系号)系 (系号,系名 ,系办公室号 ,人数)学会(学会名,人数,成立年份,地点)学会成员(学号,学会名)根据以上关系,建立各表如下:学生:班级:系:学会:学会成员:管理员,用户登录信息:关系图如下:三、程序代码:1 数
6、据库操作代码如下:1)连接数据库:public class DataConpublic DataCon()/ TODO: 在此处添加构造函数逻辑 public SqlConnection getCon() string sqlCon = server=localhost;uid=sa;pwd=sa;database=sql; SqlConnection myCon = new SqlConnection(sqlCon); return myCon; 2)与数据库进行数据交换:public class DataOperate private SqlCommand sqlcom; /声明一个Sql
7、Command对象public DataOperate()/ TODO: 在此处添加构造函数逻辑 #region DataCon dataCon = new DataCon(); public bool DataCom(string sql) /绑定控件 SqlConnection sqlconn = dataCon.getCon(); sqlconn.Open(); SqlCommand sqlcomm = new SqlCommand(sql, sqlconn); try sqlcomm.ExecuteNonQuery(); return true; catch return false;
8、 finally sqlconn.Close(); #endregion #region DataCon dataCon1 = new DataCon(); public bool gvBind(GridView gv,string sql,string tab) /绑定GridView控件 SqlConnection sqlconn=dataCon1.getCon(); sqlconn.Open(); SqlDataAdapter sqldataadapter=new SqlDataAdapter(sql,sqlconn); DataSet mydataset=new DataSet();
9、sqldataadapter.Fill(mydataset,tab); gv.DataSource=mydataset; try gv.DataBind(); return true; catch return false; finally sqlconn.Close(); #endregion #region DataCon dataCon2 = new DataCon(); public bool dataBind(DataList dl, string sql) /绑定DataList控件 SqlConnection sqlconn = dataCon2.getCon(); sqlcon
10、n.Open(); SqlDataAdapter myadapter = new SqlDataAdapter(sql, sqlconn); DataSet mydataset = new DataSet(); myadapter.Fill(mydataset); dl.DataSource = mydataset; try dl.DataBind(); return true; catch return false; finally sqlconn.Close(); #endregion #region DataCon dataCon3 = new DataCon(); public boo
11、l ExceSQL(string SqlCom) /SQL执行函数 SqlConnection sqlconn = dataCon3.getCon(); sqlconn.Open(); SqlCommand sqlcom=new SqlCommand(SqlCom,sqlconn); try sqlcom.ExecuteNonQuery(); return true; catch return false; finally sqlconn.Close(); #endregion2. 各种控件使用的相应代码:1)GridView的数据绑定:将数据表和所显示内容绑定,将数据库中的信息直接输出 pr
12、ivate void BindGrid() string strConn = server=localhost;uid=sa;pwd=sa;database=sql; myConnection.ConnectionString = strConn; string strCommand = select * from 班级; SqlDataAdapter da = new SqlDataAdapter(strCommand, myConnection); DataSet ds = new DataSet(); da.Fill(ds, cat); GridView2.DataSource = ds
13、.Tablescat.DefaultView; GridView2.DataBind();2)查询按钮:通过和数据库交互查询相应信息 protected void Button1_Click(object sender, EventArgs e) DataOperate sqlBind = new DataOperate(); string sql = select * from 班级 where + DropDownList1.SelectedValue + like % + TextBox1.Text + %; sqlBind.gvBind(GridView2, sql, 班级);3)重置
14、按钮:将所有已填信息清空 protected void Button3_Click(object sender, EventArgs e) TextBox2.Text = ; TextBox3.Text = ; TextBox4.Text = ; TextBox5.Text = ; TextBox1.Focus();4)登录验证框:用户登录时获取用户信息并通过和数据库连接以确定用户身份是否正确 protected void Login1_Authenticate(object sender, AuthenticateEventArgs e) if (Login1.UserName = null
15、) Response.Redirect(index.aspx); else SessionUserName = Login1.UserName; Sessionpswd = Login1.Password; SqlConnection myConnection1 = new SqlConnection(); String strConn = server=localhost;uid=sa;pwd=sa;database=sql; myConnection1.ConnectionString = strConn; myConnection1.Open(); SqlCommand sqlcom =
16、 myConnection1.CreateCommand(); if (RadioButtonList1.Items.FindByText(管理员).Selected = true) sqlcom.CommandText = select count(*) from 管理员 where 用户名= + Login1.UserName + and 密码= + Login1.Password + ; int count_m = Convert.ToInt32(sqlcom.ExecuteScalar(); if (count_m 0) Page.Response.Redirect(后台管理.aspx
17、); else Response.Write(alert(用户名或密码有误!);location=javascript:history.go(-1); return; else sqlcom.CommandText = select count(*) from 用户 where 用户名= + Login1.UserName + and 密码= + Login1.Password + ; int count_m = Convert.ToInt32(sqlcom.ExecuteScalar(); if (count_m 0) Page.Response.Redirect(用户空间.aspx); e
18、lse Response.Write(alert(用户名或密码有误!);location=javascript:history.go(-1); return; myConnection1.Close(); 3. GridView的各种事件函数:1)删除函数:删除指定数据记录 protected void GridView2_RowDeleting(object sender, GridViewDeleteEventArgs e) string strdel = GridView2.DataKeyse.RowIndex.Value.ToString(); string delcommand =
19、delete from 班级 where 班号 like + strdel + ; SqlConnection sqlconn = myCon.getCon(); sqlconn.Open(); da.ExceSQL(delcommand); sqlconn.Close(); BindGrid(); 2)编辑函数:编辑数据记录 protected void GridView2_RowEditing(object sender, GridViewEditEventArgs e) GridView2.EditIndex = (int)e.NewEditIndex; /当前行作为待编辑行 BindG
20、rid(); 3)更新函数:更改数据记录 protected void GridView2_RowUpdated(object sender, GridViewUpdatedEventArgs e) GridView2.EditIndex = -1; protected void GridView2_RowUpdating(object sender, GridViewUpdateEventArgs e) string strupdate = ; string str = GridView2.DataKeyse.RowIndex.Value.ToString();/ 取得当前行的键值 stru
21、pdate = 班号= + (TextBox)GridView2.Rowse.RowIndex.Cells0.Controls0).Text + ,系号= + (TextBox)GridView2.Rowse.RowIndex.Cells1.Controls0).Text + ,人数= + (TextBox)GridView2.Rowse.RowIndex.Cells2.Controls0).Text + ,入校年份= + (TextBox)GridView2.Rowse.RowIndex.Cells3.Controls0).Text + ; string updatecommand = up
22、date 班级 set + strupdate + where 班号= + GridView2.DataKeyse.RowIndex.Value.ToString() + ; string strConn = server=localhost;uid=sa;pwd=sa;database=sql; myConnection.ConnectionString = strConn; SqlCommand mycommand = new SqlCommand(updatecommand, myConnection); mycommand.Connection.Open(); mycommand.Ex
23、ecuteNonQuery(); mycommand.Connection.Close(); GridView2.EditIndex = -1;/表示没有行是可编辑的 BindGrid(); 4)分页函数:可以对GridView中数据记录进行分页显示 protected void GridView2_PageIndexChanged(object sender, EventArgs e) BindGrid(); protected void GridView2_PageIndexChanging(object sender, GridViewPageEventArgs e) GridView2
24、.PageIndex = e.NewPageIndex;4. 存储过程:查询学生信息视图中的内容CREATE PROCEDURE show AS SELECT * FROM 学生信息RETURNGO应用: private void BindGrid() string strConn = server=localhost;uid=sa;pwd=sa;database=sql; myConnection.ConnectionString = strConn; SqlDataAdapter da = new SqlDataAdapter(show, myConnection); /存储过程show da.SelectCommand.CommandType = CommandType.StoredProcedure; DataSet ds = new DataSet(); da.Fill(ds, scores); GridView1.DataSource = ds.Tablesscores.DefaultView; GridView1.DataBind(); 5. 触发器:限制用户注册的用户名CREATE
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 养牛环保管理办法
- 内部处分管理办法
- 内部车辆管理办法
- 军队疫苗管理办法
- 农技推广管理办法
- 农村宗祠管理办法
- 农村老板管理办法
- 农田土地管理办法
- 农行车辆管理办法
- 冬季茶园管理办法
- Python程序设计基础 教案全套-教学设计 林荫 第1-11章 绪论、Python 语法基础- Python 高级运用
- 快消品行业渠道管理与营销自动化方案
- 消防安全操作员培训合同范本
- 绿色农业种植技术推广应用
- 档案调取申请书范本
- 临时用电施工方案完整版
- 蔬菜、豆制品、畜肉、禽肉、水产类食材供应投标方案(技术方案)
- 麻醉药品和精神药品管理应急预案
- 【小升初】2023-2024学年全国升学分班考数学真题模拟试题2套(含解析)
- 10KV开关柜技术讲解
- 游客接待服务中心项目施工进度计划及保证措施
评论
0/150
提交评论