1、项目背景:数据库原理课程设计
2、编写目的:掌握数据库设计原理及相关软件的使用
3、软件定义:学生信息管理系统
4、开发环境:Power builder 9.0
二、需求分析1、 问题的提出:为了高效率的完成学生信息的管理,决定开发学生信息管理系统。
2、 需完成的功能:(1) 能录入、修改、查询、输出学生的档案信息,这些信息包括学生的基本情况、简历情况、获得奖励情况、受到处分情况、学生的家庭信息、学生的体检情况等。(2) 能录入、修改、查询、输出学生的入校成绩、各学期各门课的成绩信息,并支持按年级、班级等条件的统计、查询、报表输出。
3、E-R图:
三、数据表:
info
|sno|sname|sex|age|depart|price|exp|home|health|grade|class|other|
--------------------------------------------------------------------------------------
course
--------------------------
|cno|cname|teacher|
--------------------------
exam
--------------------
|sno|cno|score|
info
| Column Name | Date Type | Width | 空值情况 |
| Sno | Char | 20 | 主关键字 |
| Sname | Char | 10 | 不为空 |
| Sex | Char | 2 | 不为空 |
| age | Numeric | 4 | 可为空 |
| Depart | Char | 10 | 不为空 |
| Prize | Char | 200 | 可为空 |
| Home | Char | 200 | 可为空 |
| Health | Char | 200 | 可为空 |
| Other | Char | 200 | 可为空 |
| Grade | Char | 3 | 不为空 |
| Class | Char | 3 | 不为空 |
| Column Name | Date Type | Width | 空值情况 |
| Sno | Char | 20 | 主关键字 |
| Cno | Char | 20 | 不为空 |
| Score | Char | 3 | 可为空 |
| Column Name | Date Type | Width | 空值情况 |
| Cno | Char | 20 | 主关键字 |
| Cname | Char | 10 | 不为空 |
| Teacher | Char | 5 | 不为空 |
对于关系模式info(|sno|sname|sex|age|depart|price|exp|home|health|grade|class|other|)假定姓名也具有唯一性,那么info就有两个码,这两个码都由单个属性组成,彼此不相交。其它属性不存在对码的传递依赖与部分依赖,又因为info中除学号、姓名外没有其它的因素,所以info属于BCNF。对于关系模式course(|cno|cname|teacher|)中,它只有一个码,这里没有任何属性对课程号部分依赖或传递依赖,同时课程号是唯一的决定因素,所以课程属于BCNF。对于关系模式exam(|sno|cno|score|)有两个码,这两个码都由单个属性组成,彼此不相交,其它属性不存在对码的传递依赖与部分依赖,又因为成绩中除学号、课程号外没有其它的决定因素,所以成绩属于BCNF。四、视图,索引,数据库权限:
create view temp (sno,sname,cname,score)
as select info.sno,info.sname,course.cname,exam.score
from info,exam,course where info.sno=exam.sno and exam.cno=course.cno
CREATE UNIQUE INDEX STUSNO ON info(sno);
GRANT SELECT ON TABLE examTO PUBLIC;
五、软件功能设计功能表:
|-系统维护(下设系统退出)
|-信息录入(下设学生基本信息录入|学生成绩录入)
|-信息查询(下设学生基本信息查询|学生成绩查询*)
|-报表功能描述:退出系统:退出程序。学生数据输入:输入学号、姓名、性别、年龄、出生年月等学生基本信息。成绩输入:输入各学期学生考试成绩。学生信息查询:查询学生基本信息。学生成绩查询:查询学生考试成绩。按年级输出报表:输出全年级学生各科目考试成绩。按班级输出报表:输出全班学生各科目考试成绩。六、程序代码及控件描述启动封面:(w_start)
Open事件代码:
SQLCA.dbms="ODBC"
SQLCA.database=""
SQLCA.userid=""
SQLCA.dbpass=""
SQLCA.logid=""
SQLCA.logpass=""
SQLCA.dbparm="C"
SQLCA.lock=""
SQLCA.autocommit=false
connect using SQLCA;
IF SQLCA.Sqlcode <> 0 then
messagebox("无法连接数据库!",SQLCA.sqlerrtext)
close(w_start)
// else
// open(w_startscc)
end if
CommandButton.text=“进入系统”
CommandButton clicked事件代码:
open(w_main)
close(w_start)
主程序窗口(w_main):
title=“学生信息管理系统 V1.0”
包含菜单m_main
窗口(w_infoinput)
Open事件代码:
dw_1.SetTransObject(SQLCA)
dw_1.Retrieve()
控件datawindow的dataobject属性:i_info(一个freeform风格的数据窗口对象,显示info表的全部列)
commandbutton(text属性:保存)clicked事件的代码:dw_1.Update()
commandbutton(text属性:取消)clicked事件的代码:dw_1.Retrieve()
commandbutton(text属性:插入)clicked事件的代码:dw_1.InsertRow(dw_1.GetRow())
commandbutton(text属性:删除)clicked事件的代码:dw_1.DeleteRow(dw_1.GetRow())
窗口(w_scoreinput)
Open事件代码:
dw_1.SetTransObject(SQLCA)
dw_1.Retrieve()
控件datawindow的dataobject属性:i_score (一个freeform风格的数据窗口对象,显示exam表的全部列)
commandbutton(text属性:保存)clicked事件的代码:dw_1.Update()
commandbutton(text属性:取消)clicked事件的代码:dw_1.Retrieve()
commandbutton(text属性:插入)clicked事件的代码:dw_1.InsertRow(dw_1.GetRow())
commandbutton(text属性:删除)clicked事件的代码:dw_1.DeleteRow(dw_1.GetRow())
窗口(w_query)控件statictext的text属性:“请输入学号:”
控件groupbox包含24个statictext控件,它们的text属性分别对应info表的字段名和查询结果控件SingleLineEdit的text属性为null
commandbutton(text属性:查询)clicked事件的代码:
Connect;
if SQLCA.SQLCode<0 then
MessageBox("连接错误",SQLCA.SQLErrText,Exclamation!)
end if
//MessageBox("done",SQLCA.SQLErrText,Exclamation!)
int Stu_id
string Stu_name,Stu_xuehao,Stu_sex,Stu_age,Stu_home
string Stu_birth,Stu_depart,Stu_price,Stu_info,Stu_health
Stu_id=Integer(sle_id.Text)
select info.sno,info.sname,info.sex,info.age,
info.depart,info.prize,info.exp,info.home,
info.health,info.grade,info.class,info.other
Into :Stu_sno,:Stu_sname,:Stu_sex,:Stu_age,
:Stu_depart,:Stu_prize, :Stu_exp,:Stu_home,
:Stu_health,:Stu_grade:Stu_class, :Stu_other
From student Where info.sno=:Stu_id;
IF SQLCA.SQLCode=100 THEN
MessageBox("学生查询","对不起,没有该学生")
ELSEIF SQLCA.SQLCode>0 THEN
MessageBox("数据库错误",SQLCA.SQLErrText,Exclamation!)
END IF
窗口(w_squery)控件groupbox(text属性为:“选择查询模式”)包含2个RadioButton控件,它们的text属性分别为按年级查询和按班级查询控件SingleLineEdit(text属性为Null)功能为获得输入的年级/班级编号控件CommandButton(text属性为确定)的Clicked事件代码:
integer n
integer slen
slen=Len(sle_1.text)
n=asc(sle_1.text)-48
if (slen>1 or slen=0) then
messagebox("错误","数据非法!")
sle_1.text=""
elseif (n<1 or n>9) then
messagebox("错误","数据非法!")
end if
connect using SQLCA;
if rb_1.checked=true then
select info.sno,info.sname,exam.cno,course.cname,exam.score
from info,course,exam
where info.sno =exam.sno and ,exam.cno =course.cno and info.grade=n
end if
if rb_2.checked=true then
select info.sno,info.sname,exam.cno,course.cname,exam.score
from info,course,exam
where info.sno =exam.sno and ,exam.cno =course.cno and info.class=n
end if
窗口(w_table)控件groupbox(text属性为:“选择模式”)包含2个RadioButton控件,它们的text属性分别为按年级输出和按班级输出控件SingleLineEdit(text属性为Null)功能为获得输入的年级/班级编号控件CommandButton(text属性为确定)的Clicked事件代码:
integer n
integer slen
slen=Len(sle_1.text)
n=asc(sle_1.text)-48
if (slen>1 or slen=0) then
messagebox("错误","数据非法!")
sle_1.text=""
elseif (n<1 or n>9) then
messagebox("错误","数据非法!")
end if
connect using SQLCA;
if rb_1.checked=true then
select * from dep_exam,info where info.grade=n
end if
if rb_2.checked=true then
select * from dep_exam,info where info.class=n
主菜单(m_main)代码:退出系统clicked事件的代码:close(w_main)
学生基本信息输入clicked事件的代码:Open(w_infoinput)
学生成绩输入clicked事件的代码:Open(w_scoreinput)
学生基本信息查询clicked事件的代码:Open(w_query)
学生成绩查询clicked事件的代码:Open(w_squery)
报表clicked事件的代码:Open(w_table)
七、设计心得 通过这次课程设计,我更加熟练的掌握了使用PowerBuilder进行数据库软件开发的方法,加深了对数据库课程知识的理解。由于时间仓促,软件还有很多不足之处,如:成绩查询部分不够完善,成绩输入模块不支持学生成绩批量输入,软件代码交冗余、效率不高等等,都是对PB操作不熟练,对相关功能缺乏认识造成的。在今后的学习中我会加强理论与实践的结合,通过不断的摸索来弥补自己在软件制作方面的差距。
最新回复