《数据库系统与应用课程设计》高校教务管理系统
任务书:
- 课程设计题目
高校教务管理系统
- 课程设计任务
主要任务:完成如下的系统功能和数据库结构的创建。并且系统能够试运行。
1.系统功能
系统功能模块图如下:
2.系统数据库结构
基本表如下:
学生:s(sno,sname,sex,age,dept) 表中属性分别为:学号、姓名、性别、年龄和系名。
课程:c(cno,cname,teacher,credit) 表中属性分别为:课号、课名、教师名和学分。
学习:sc(sno,cno,grade) 表中属性分别为:学号、课号、成绩。
用户:user(hm,pwd,role) 表中属性分别为:用户名、密码、权限(0、1、2三等)。
- 课程设计要求
1.基本要求
注意:由于学时数少,要求至少完成以下功能:
(1)用户登录窗口。参见教材p227图8.7。
(2)系统总控菜单窗口。菜单项目(子菜单)如上图。参见教材p229图8.9。
(3)编辑数据:对学生、课程、学习表三个表更新的功能。
(4)查询功能:按学号查学生基本信息。参见教材p236图8.11
(5)统计功能:按班级统计不及格人数和比例。
2.开发的软件工具
系统开发平台及语言:VB6.0 (Visuel Basic),或者其他的语言。
后台数据库管理系统:SQL Server 2005。或者其他的关系数据库管理系统。
3. 评分标准:独立完成:60%;文档资料整理质量:25%;创新:10%;按时交付:5%。
- 课程设计资料
1.主要参考书
教材:第8章。
关于:介绍SQL Server 2005和Visuel Basic其它书籍。
2.交付的文档资料
(1)系统功能图、数据库概念结构的E-R图和数据库基本表的定义(列表给出:表名、
字段名、类型、长度和主关键字)
(2)程序清单。程序打印格式参考第8章。(程序中的关键语句要用注释说明)
(3)小结
-
-
- 新增加的功能(除功能模块图中以外的功能)
- 体会和感想。
-
汇总装订成册:册子封面:系统名称、班级、姓名、学号和日期。
-----------------------------------------------------------------------
试 题:高校教务管理系统
主要功能
1.用户登录窗口。参见教材p227图8.7。
2.系统总控菜单窗口。菜单项目(子菜单)如上图。参见教材p229图8.9。
3.编辑数据:对学生、课程、成绩三个表更新的功能。
4.查询功能:按学号查学生基本信息。参见教材p236图8.11
5.统计功能:按班级统计不及格人数和比例。
要 求:
1.独立完成上述各功能并撰写课程设计报告;
- 各功能须说明实验目的,实验内容,实验数据,实验结果及分析,其中实验数据和实验结果均以计算机截图方式表示;
3.系统功能图、数据库基本表的定义(列表给出:表名、字段名、类型、长度、主关键字和外码(如果有的话));
4. 程序清单。打印格式参考第8章。(程序中的关键语句要用注释说明)
1.课程设计目的
使用Visual Basic6.0语言和SQL Server建立连接,开发高校教务管理系统,并且能成功运行,完成任务设计书中要求的功能。
2.课程设计内容和要求
2.1问题描述
- 系统开发的工具与环境
- 课程设计内容
- 系统功能说明
主要功能
1.用户登录窗口。
2.系统总控菜单窗口。菜单项目(子菜单)如上图。
3.编辑数据:对学生、课程、成绩三个表更新的功能。
4.查询功能:按学号查学生基本信息。
5.统计功能:按班级统计不及格人数和比例。
- 系统数据库结构说明
1.学生:s(sno,sname,sex,age,dept) 表中属性分别为:学号、姓名、性别、年龄和系名。
2.课程:c(cno,cname,teacher,credit) 表中属性分别为:课号、课名、教师名和学分。
3.学习:sc(sno,cno,grade) 表中属性分别为:学号、课号、成绩。
4.用户:users(hm,pwd,role) 表中属性分别为:用户名、密码、权限(0、1、2三等)。
2.2设计要求
1.独立完成上述各功能并撰写课程设计报告;
2.各功能须说明实验目的,实验内容,实验数据,实验结果及分析,其中实验数据和实验结果均以计算机截图方式表示;
3.系统功能图、数据库基本表的定义(列表给出:表名、字段名、类型、长度、主关键字和外码(如果有的话));
4. 程序清单。打印格式参考第8章。(程序中的关键语句要用注释说明)
3.课程设计总体方案及分析
3.1 问题分析
随着学校的规模不断过大,学生数量急剧增加,有关学生的各种信息量也成倍增加。面对庞大的信息量需要有高校教务管理系统来提高学生管理工作的效率。通过这样的系统可以做到信息的规范化管理、科学性统计和快速查询、修改、增加、删除等,从而减少管理方面的工作量。
通过询问身边学生、调查以及网络的查询等方式,我们可以清晰的了解到,一个完整的高校教务管理系统应包含以下功能:用户的信息管理、课程信息管理、成绩信息管理、学生信息管理,并且包含查询和统计功能方便用户使用。根据访问角色的不同,在系统中应体现出对教务资源的访问的权限的不同。
根据上诉,完整的高校教务管理系统功能模块图如下:
3.2 关系模式设计
(1)系统数据库概念结构ER图
(2)系统数据库逻辑结构
基本表如下:
学生:s(sno,sname,sex,age,dept) 表中属性分别为:学号、姓名、性别、年龄和系名。
课程:c(cno,cname,teacher,credit) 表中属性分别为:课号、课名、教师名和学分。
学习:sc(sno,cno,grade) 表中属性分别为:学号、课号、成绩。
用户:users(hm,pwd,role) 表中属性分别为:用户名、密码、权限(0、1、2三等)。
(3)系统数据库结构的定义及数据
数据:
3.3 系统程序结构
1.登录程序
程序窗口:
程序代码:
确认按钮:
Private Sub cmdOK_Click()
Dim sUserName As String
Dim sUserPwd As String
sUserName = Trim(txtUserName.Text)
sUserPwd = Trim(txtUserPwd.Text)
If sUserName = "" Then
Call MsgBox("请输入用户名!", vbOKOnly, "登陆提示")
txtUserName.SetFocus
Exit Sub
End If
If SqlConn.State <> adStateOpen Then DBConnect ("U")
Set SqlRS = ExecSQL("select count(*)num from Users where(username='" + sUserName + "')and(userpwd='" + sUserPwd + "')")
If Not SqlRS.EOF Then
If Int(Trim(SqlRS("num"))) >= 1 Then
SqlRS.Close
Set SqlRS = ExecSQL("select username,role from Users where(username='" + sUserName + "')and(userpwd='" + sUserPwd + "')")
If Not SqlRS.EOF Then
MDIForm1.SetRightForRole (Trim(SqlRS("role")))
Else
MDIForm1.SetRightForRole ("2")
End If
Unload Me
Call MsgBox("登陆成功!", vbOKOnly, "登陆提示")
MDIForm1.Show
Else
Call MsgBox("密码错误,请重新登陆!", vbOKOnly, "登陆提示")
txtUserName.SetFocus
Exit Sub
End If
End If
End Sub
用户名输入框:
Private Sub txtUserName_KeyDown(KeyCode As Integer, Shift As Integer)
If KeyCode = 13 Then txtUserPwd.SetFocus
End Sub
密码输入框:
Private Sub txtUserPwd_KeyDown(KeyCode As Integer, Shift As Integer)
If KeyCode = 13 Then cmdOK_Click
End Sub
关闭按钮:
Private Sub txtUserPwd_KeyDown(KeyCode As Integer, Shift As Integer)
If KeyCode = 13 Then cmdOK_Click
End Sub
2.菜单程序
程序窗口:
程序代码:
Public Sub SetRightForRole(role As String)
If role = "2" Then
UpdateStudent.Visible = False
AddGrade.Visible = False
ElseIf role = "1" Then
End If
End Sub
Private Sub AddClass_Click()
frmClassinfo.SetOpenStyle ("I")
frmClassinfo.Show
frmClassinfo.ZOrder 0
End Sub
Private Sub AddGrade_Click()
frmCourseGrade.Show
frmCourseGrade.ZOrder 0
End Sub
Private Sub AddStudent_Click()
frmStudentInfo.SetOpenStyle ("I")
frmStudentInfo.Show
frmStudentInfo.ZOrder 0
End Sub
Private Sub MDIForm_Load()
If SqlConn.State <> adStateOpen Then
DBConnect ("U")
End If
End Sub
Private Sub SearchStudent_Click()
frmStudentSearch.Show
frmStudentSearch.ZOrder 0
End Sub
Private Sub tc_Click()
Unload Me
End Sub
Private Sub UpdateClass_Click()
frmClassinfo.SetOpenStyle ("U")
frmClassinfo.Show
frmClassinfo.ZOrder 0
End Sub
Private Sub UpdateStudent_Click()
frmStudentInfo.SetOpenStyle ("U")
frmStudentInfo.Show
frmStudentInfo.ZOrder 0
End Sub
3.数据编辑程序
(1)学生信息管理
程序窗口:
程序代码:
新增按钮:
Private Sub cmdNew_Click()
txtSno.Enabled = True
txtSname.Enabled = True
Male.Enabled = True
Female.Enabled = True
txtAge.Enabled = True
txtDept.Enabled = True
txtSno.Text = ""
txtSname.Text = ""
Male.Value = False
Female.Value = False
txtAge.Text = ""
txtDept.Text = ""
txtSno.SetFocus
End Sub
保存按钮:
Private Sub cmdSave_Click()
Dim strSQL As String
Dim strSex As String
If Trim(txtSno.Text) = "" Then
txtSno.SetFocus
Call MsgBox("请输入学生学号!", vbOKOnly, "提示")
Exit Sub
End If
If Trim(txtSname.Text) = "" Then
txtSname.SetFocus
Call MsgBox("请输入学生姓名!", vbOKOnly, "提示")
Exit Sub
End If
If Male.Value = True Then
strSex = "男"
ElseIf Female.Value = True Then
strSex = "女"
End If
If strMode = "I" Then
Set SqlRS = ExecSQL("select count(*) num from s where sno='" + Trim(txtSno.Text) + "'")
If Not SqlRS.EOF Then
If Int(Trim(SqlRS("num"))) >= 1 Then
SqlRS.Close
Call MsgBox("该学生" + Trim(txtSno.Text) + "已经存在,请重新输入", vbOKOnly, "提示")
Exit Sub
End If
End If
SqlRS.Close
strSQL = "INSERT INTO s(sno,sname,sex,age,dept)"
strSQL = strSQL + "VALUES('" + Trim(txtSno.Text) + "','" + Trim(txtSname.Text) + "','" + strSex + "','" + Trim(txtAge.Text) + "','" + Trim(txtDept.Text) + "')"
ElseIf strMode = "U" Then
strSQL = "UPDATE s SET sno='" + Trim(txtSno.Text) + "',sname = '" + Trim(txtSname.Text) + "',"
strSQL = strSQL + "sex='" + strSex + "',age='" + Trim(txtAge.Text) + "',dept='" + Trim(txtDept.Text) + "'"
strSQL = strSQL + "Where sno='" + strNo + "'"
End If
ExecSQL (strSQL)
Call MsgBox("保存成功", vbOKOnly, "提示")
If strMode = "I" Then cmdNew_Click
End Sub
修改按钮:
Private Sub cmdChang_Click()
If strMode = "U" Then
Male.Enabled = True
Female.Enabled = True
txtAge.Enabled = True
txtDept.Enabled = True
cmdSave.Enabled = True
End If
End Sub
查找按钮:
Private Sub cmdFind_Click()
strNo = Trim(txtSno.Text)
If Trim(txtSno.Text) = "" And Trim(txtSname.Text) = "" Then
Call MsgBox("请输入学生学号或姓名!", vbOKOnly, "提示")
Exit Sub
End If
Set SqlRS = ExecSQL("select * from s where sno ='" + Trim(txtSno.Text) + "'or s.sname='" + Trim(txtSname.Text) + "'")
If Not SqlRS.EOF Then
txtSno.Text = Trim(SqlRS("sno"))
strNo = Trim(SqlRS("sno"))
txtSname.Text = Trim(SqlRS("sname"))
If SqlRS("sex") = "男" Then
Male.Value = True
ElseIf SqlRS("sex") = "女" Then
Female.Value = True
Else
Male.Value = True
Female.Value = True
End If
txtAge.Text = Trim(SqlRS("age"))
txtDept.Text = Trim(SqlRS("dept"))
Else
SqlRS.Close
Call MsgBox("没有此学生信息", vbOKOnly, "提示")
Exit Sub
End If
If strMode = "U" Then
cmdChang.Enabled = True
cmdDelete.Enabled = True
cmdSave.Enabled = False
End If
End Sub
删除按钮:
Private Sub cmdDelete_Click()
If vbYes = MsgBox("是否确认删除", vbYesNo, "询问") Then
SqlConn.BeginTrans
SqlCmd.CommandText = "delete from sc where sno ='" + strNo + "'"
SqlCmd.Execute
SqlCmd.CommandText = "delete from s where sno ='" + strNo + "'"
SqlCmd.Execute
SqlConn.CommitTrans
txtSno.Text = ""
txtSname.Text = ""
Male.Value = False
Female.Value = False
txtAge.Text = ""
txtDept.Text = ""
cmdNew.Enabled = False
cmdFind.Enabled = True
cmdChang.Enabled = False
cmdDelete.Enabled = False
cmdSave.Enabled = False
Male.Enabled = False
Female.Enabled = False
txtAge.Enabled = False
txtDept.Enabled = False
txtSno.SetFocus
End If
退出按钮:
Private Sub cmdClose_Click()
Unload Me
End Sub
(2)课程信息管理
程序窗口:
程序代码:
Dim strMode As String
Dim strCno As String
Public Sub SetOpenStyle(str As String)
strMode = str
cmdNew.Enabled = False
cmdSave.Enabled = False
cmdChange.Enabled = False
cmdDelete.Enabled = False
cmdFind.Enabled = False
txtTeacher.Enabled = False
txtCredit.Enabled = False
If str = "F" Then
cmdFind.Enabled = True
ElseIf str = "I" Then
cmdNew.Enabled = True
cmdSave.Enabled = True
txtCno.Enabled = False
txtCname.Enabled = False
ElseIf str = "U" Then
cmdFind.Enabled = True
End If
End Sub
新增按钮:
Private Sub cmdNew_Click()
txtCno.Enabled = True
txtCname.Enabled = True
txtTeacher.Enabled = True
txtCredit.Enabled = True
txtCno.Text = ""
txtCname.Text = ""
txtTeacher.Text = ""
txtCredit.Text = ""
txtCno.SetFocus
End Sub
修改按钮:
Private Sub cmdChange_Click()
txtCno.Enabled = True
txtCname.Enabled = True
txtTeacher.Enabled = True
txtCredit.Enabled = True
cmdSave.Enabled = True
保存按钮:
Private Sub cmdSave_Click()
Dim strSQL As String
If Trim(txtCno.Text) = "" Then
txtCno.SetFocus
Call MsgBox("请输入课号", vbOKOnly, "提示")
Exit Sub
End If
If Trim(txtCname.Text) = "" Then
txtCname.SetFocus
Call MsgBox("请输入课程名", vbOKOnly, "提示")
Exit Sub
End If
If Trim(txtTeacher.Text) = "" Then
txtTeacher.SetFocus
Call MsgBox("请输入教师名", vbOKOnly, "提示")
Exit Sub
End If
If Trim(txtCredit.Text) = "" Then
txtCredit.Text = ""
Call MsgBox("请输入学分", vbOKOnly, "提示")
Exit Sub
End If
If strMode = "I" Then
Set SqlRS = ExecSQL("select count(*)num from c where cno='" + Trim(txtCno.Text) + "'")
If Not SqlRS.EOF Then
If Int(Trim(SqlRS("num"))) >= 1 Then
SqlRS.Close
Call MsgBox("该课程" + Trim(txtCno.Text) + "已经存在", vbOKOnly, "提示")
Exit Sub
End If
End If
SqlRS.Close
strSQL = "INSERT INTO c(cno,cname,teacher,credit)"
strSQL = strSQL + "VALUES('" + Trim(txtCno.Text) + "','" + Trim(txtCname.Text) + "','" + Trim(txtTeacher.Text) + "','" + Trim(txtCredit) + "')"
ElseIf strMode = "U" Then
strSQL = "UPDATE c SET cno='" + Trim(txtCno.Text) + "',cname='" + Trim(txtCname.Text) + "',teacher='" + Trim(txtTeacher.Text) + "',credit='" + Trim(txtCredit.Text) + "'"
strSQL = strSQL + "where cno='" + strCno + "'"
End If
ExecSQL (strSQL)
Call MsgBox("保存成功!", vbOKOnly, "提示")
If strMode = "I" Then cmdNew_Click
End Sub
查询按钮:
Private Sub cmdFind_Click()
strCno = Trim(txtCno.Text)
If Trim(txtCno.Text) = "" And Trim(txtCname.Text) = "" Then
Call MsgBox("请输入课程课号或课名", vbOKOnly, "提示")
Exit Sub
End If
Set SqlRS = ExecSQL("select * from c where cno ='" + Trim(txtCno.Text) + "'or c.cname='" + Trim(txtCname.Text) + "'")
If Not SqlRS.EOF Then
txtCno.Text = Trim(SqlRS("cno"))
strCno = Trim(SqlRS("cno"))
txtCname.Text = Trim(SqlRS("cname"))
txtTeacher.Text = SqlRS("teacher")
txtCredit.Text = SqlRS("credit")
Else
SqlRS.Close
Call MsgBox("没有此课程信息", vbOKOnly, "提示")
Exit Sub
End If
SqlRS.Close
If strMode = "U" Then
cmdChange.Enabled = True
cmdDelete.Enabled = True
cmdSave.Enabled = False
End If
End Sub
删除按钮:
Private Sub cmdDelete_Click()
If vbYes = MsgBox("是否确认删除", vbYesNo, "询问") Then
SqlConn.BeginTrans
SqlCmd.CommandText = "delete from sc where cno ='" + strCno + "'"
SqlCmd.Execute
SqlCmd.CommandText = "delete from c where cno ='" + strCno + "'"
SqlCmd.Execute
SqlConn.CommitTrans
txtCno.Text = ""
txtCname.Text = ""
txtTeacher.Text = ""
txtCredit.Text = ""
cmdNew.Enabled = False
cmdFind.Enabled = True
cmdChange.Enabled = False
cmdDelete.Enabled = False
cmdSave.Enabled = False
txtTeacher.Enabled = False
txtCredit.Enabled = False
txtCno.SetFocus
End If
End Sub
(3)成绩信息管理
程序窗口:
程序代码:
Private Sub cmdClose_Click()
Unload Me
End Sub
查询按钮:
Private Sub cmdFind_Click()
Dim strSQL, stmp As String
Dim strSno, sSno As String
Dim strSname, sSname As String
strSno = Trim(txtSno.Text)
strSname = Trim(txtSname.Text)
strSQL = "select * from V_scgrade"
sSno = ""
If ckbSno.Value = 1 Then
sSno = "sno'" + strSno + "'"
End If
sSname = ""
If ckbSname.Value = 1 Then
sSname = "sname like'%" + strSname + "%'"
End If
stmp = ""
If sSno <> "" Then
If sSname <> "" Then
stmp = sSno + "and" + sSname
Else
stmp = sSno
End If
Else
If sSname <> "" Then
stmp = sSname
End If
End If
If Trim(stmp) <> "" Then
strSQL = strSQL + "where" + stmp
End If
gradeADO.ConnectionString = getConnString
gradeADO.RecordSource = strSQL
gradeADO.Refresh
End Sub
保存按钮:
Private Sub cmdUpdate_Click()
Dim sCno, sSQL As String
If Trim(sNo.Text) = "" Then
Call MsgBox("请选择学生", vbOKOnly, "提示")
Exit Sub
End If
If Trim(cbxCourse.Text) = "" Then
Call MsgBox("请选择输入课程名", vbOKOnly, "提示")
cbxCourse.SetFocus
Exit Sub
End If
If Trim(txtGrade.Text) = "" Then
Call MsgBox("请输入该学生的课程成绩", vbOKOnly, "提示")
txtGrade.SetFocus
Exit Sub
End If
sCno = ""
Set SqlRS = ExecSQL("select cno from c where cname = '" + Trim(cbxCourse.Text) + "'")
If Not SqlRS.EOF Then
sCno = Trim(SqlRS("cno"))
End If
SqlRS.Close
If sCno = "" Then
Call MsgBox("不存在该课程", vbOKOnly, "提示")
cbxCourse.SetFocus
Exit Sub
End If
Set SqlRS = ExecSQL("select count(*) num from sc where sno = '" + Trim(sNo.Text) + "' and cno = '" + sCno + "'")
If Not SqlRS.EOF Then
If Int(Trim(SqlRS("num"))) >= 1 Then
sSQL = "update sc set grade = " + Trim(txtGrade.Text)
sSQL = sSQL + "where sno ='" + Trim(sNo.Text) + "'and cno = '" + sCno + "'"
Else
sSQL = "insert into sc(sno,cno,grade)"
sSQL = sSQL + "values('" + Trim(sNo.Text) + "','" + sCno + "'," + Trim(txtGrade.Text) + ")"
End If
SqlRS.Close
ExecSQL (sSQL)
Call MsgBox("保存成功", vbOKOnly, "提示")
gradeADO.Refresh
End If
End Sub
删除按钮
Private Sub cmdDelete_Click()
If vbYes = MsgBox("是否确认删除学号:" + studentNo + ",课程号:'" + courseNo + "'的学生成绩信息?", vbOKOnly, "提示") Then
ExecSQL ("delete from sc where sno = '" + studentNo + "'and cno = '" + courseNo + "'")
gradeADO.Refresh
End If
End Sub
4.查询程序
程序窗口:
程序代码:
查询按钮:
Private Sub cmdFind_Click()
Dim strSQL, stmp As String
Dim strSno, sSno As String
Dim strSname, sSname As String
Dim strDept, sDept As String
If ckbSno.Value <> 1 And ckbSname.Value <> 1 Then
Call MsgBox("请选择或输入查询条件!", vbOKOnly, "提示")
Exit Sub
End If
strSno = Trim(txtSno.Text)
strSname = Trim(txtSname.Text)
strSQL = "select * from s "
sSno = ""
If ckbSno.Value = 1 Then
sSno = "(Sno like'" + strSno + "%')"
End If
sSname = ""
If ckbSname.Value = 1 Then
sSname = "(Sname like'%" + strSname + "%')"
End If
stmp = ""
If sSno <> "" Then
stmp = sSno
If sSname <> "" Then
stmp = stmp + "and" + sSname
End If
Else
If sSname <> "" Then
stmp = sSname
End If
End If
If Trim(stmp) <> "" Then
strSQL = strSQL + "where" + stmp
End If
studentADO.ConnectionString = getConnString
studentADO.RecordSource = strSQL
studentADO.Refresh
End Sub
关闭按钮:
Private Sub Form_Load()
Unload Me
End Sub
5.统计程序
程序窗口:
程序代码:
DataGrid和ADODC插件进行简单的统计呈现
RecordSource为:select left(Sno,4) SqlClass ,count(*) fail from V_scgrade where Grade<60 group by left(Sno,4)
3.4 实验结果与分析
1.连接数据库
通过adodc得到连接字符Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=计科2103夏妍彦;Data Source=DESKTOP-3D3JVKK
2.登录界面实验
结果:登录成功。
学生信息保存功能实验
结果:保存成功。
学生信息查找功能实验
结果:查找成功。
5.课程信息保存功能实验
结果:保存成功。
6.成绩信息保存功能实验
结果:保存成功。
7.按班级统计不及格人数实验
结果:统计成功。
4.结束语
(1)体会和感想
在做本次高校教务管理系统时,时不时的弹出错误的提示框,正所谓失败乃成功之母,针对这些错误的提示框,不断发现自己出错的地方,通过上网以及查阅资料最终实现高校教务管理系统。此次课设对我来讲是一个很好的深入学习的机会,并且对VB代码与数据库的关系有了更深的理解。现对此次实验过程遇到的错误进行总结:
- 实时错误91:此错误一般是SQL执行码中有拼写错误。
- 实时错误3704:对象关闭时,不允许操作。
- 实时错误424:原因是VB当中文本框输入的内容与数据库格式不符。
- 实时错误-2147217887:此错误的原因是在于VB文本框所填信息的数据类型与数据库的数据类型或限定长度不符。
- 实时错误94:由于数据库内有null。
- 实时错误3021:数据库内所访问的字段没有内容。
(2)增加新的功能
除了要求里的按学号查询学生信息,本文的高校教务系统新增了按姓名查询、按所在系查询的功能,使得使用者可以更方便的查看总体的学生信息。
5. 附录(源代码)
源代码见3.3。