(图一)
一张表,所有信息都是根据这张学生档案进行有关的操作,主要的字段有:学号、姓名、年级、专业、性别、出生年月、民族、籍贯、政治面貌、家庭地址、邮政编码、联系电话、入学时间、备注。其中日期的数据类型为日期/时间天型,其它的数据类型为文本型;成绩表中字段为:学号、姓名、年级、专业、学期、考试时间、考试科目、考试地点、课程性质、科目分数、违纪类型、备注;课程表中字段为:专业、年级、学期、课程名称、教材、任课老师、课时、上课地点、课程性质、考试性质;用户资料中的字段包括:用户名、密码、身份。
数据库与vb的连接:本系统的数据链接采用的是ado方法,打开控制面板,打开odbc数据源图标,选择“系统dsn”标签,点击“添加”按钮,在弹出的“创建新数据源”对话框中选择名称为“microsoft access drive(*.mdb)”,点击“完成”按钮,在odbc microsoft access 安装对话框中在数据源名中输入信息,在数据库这个框中, 单击“选择”按钮,在弹出的选择数据库这一对话框架中,在驱动器下拉列表框中选择本系统数据库所在驱动器,在目录中选择库所在的文件夹,在文件类型中选择选“access数据库(*.mdb)”,在数据库名中选择本系统的数据库,点击“确定”按钮即完成数据链接。
在vb中,用adodc链接数据库,用datagrid或data将库中的数据在界面中显示出来,本系统采用datagrid。在界面上右击adodc控制,在弹出的快捷菜单中选择属性,在属性对话框中,在“属性”这一标签中, 选中单选框“use odbc data source name”,并在下拉文本框中选择已经配置好的数据源名信息,再在“recordsoure”标签中,在commard text(sql)文本框中输入查询语句,如:select * from 学生档案。同时,将桌面的datagrid控件选中,在属性框中,将它的datasoure设为adodc。
我们可以设置datagrid控件的外观:选中该控件,右击,在弹出的快捷菜单中选择“检索字段”,在弹出的对话框中单击“确定”,这时,表格中出现了表的字段。然后再右击,同样,在弹出的快捷菜单中选择“编辑”,我们就可以所在的表格的宽度进行调整。
各功能的实现
课程管理:课程设置(如:界面如图二)
(图二)
运行程序后,进入课程管理模块,课程管理模块的第一块是课程设置,在这模块中可以把专业、年级、学期、课程名称、教材、任课老师、课时、上课地点、课程性质和考试性质等信息输入,以便使用。
下面为其代码:
private sub command1_click()
dim mycon as new adodb.connection
dim myrs as new adodb.recordset
dim zhuanye, nianji, xueqi, kecheng, jiaocai, renkls, keshi, shangkedd, kechengxz, kaoshixz as string
zhuanye = text1.text
nianji = text2.text
xueqi = dtpicker1.value
kecheng = text4.text
jiaocai = text5.text
renkls = text6.text
keshi = text7.text
shangkedd = text8.text
kechengxz = combo1.text
kaoshixz = combo2.text
if trim(zhuanye) = "" or trim(nianji) = "" or trim(xueqi) = "" or trim(kecheng) = "" or trim(jiaocai) = "" or trim(renkls) = "" or trim(keshi) = "" or trim(shangkedd) = "" or trim(kechengxz) = "" or trim(kaoshixz) = "" then
msgbox "请填写要修改课程资料的内容!"
combo1.text = ""
combo2.text = ""
exit sub
end if
private sub command3_click()
unload me
frm_findgrean.show 1
end sub
private sub datagrid1_click()
'frm_updategrean.adodc1.recordsource = "select * from 课程表 where 专业 = '" & trim(datagrid1.row) & "'"
'text1.text = frm_updategrean.adodc1.recordset.fields("专业")
'text2.text = frm_updategrean.adodc1.recordset.fields("年级")
'text3.text = frm_updategrean.adodc1.recordset.fields("学期")
'text4.text = frm_updategrean.adodc1.recordset.fields("课程名称")
'text5.text = frm_updategrean.adodc1.recordset.fields("教材")
'text6.text = frm_updategrean.adodc1.recordset.fields("任课老师")
'text7.text = frm_updategrean.adodc1.recordset.fields("课时")
'text8.text = frm_updategrean.adodc1.recordset.fields("上课地点")
'combo1.text = frm_updategrean.adodc1.recordset.fields("课程性质")
'combo2.text = frm_updategrean.adodc1.recordset.fields("考试性质")
end sub
private sub dtpicker1_callbackkeydown(byval keycode as integer, byval shift as integer, byval callbackfield as string, callbackdate as date)
end sub
private sub form_activate()
frm_findgrean.adodc1.recordsource = strtiaojian
frm_findgrean.adodc1.refresh
set datagrid1.datasource = frm_findgrean.adodc1
end sub
end sub
课程管理:课程查询(如:界面如图三)
(图三)
当输入查询类别、运算符和条件后可以查找到所需要的课程设置,或按查询时间来查询,输入所要查找的时间段,就可查到所要的课程设置。
代码如下:
dim sqlstr as string
private sub combo1_change()
end sub
private sub combo2_change()
end sub
private sub combo4_change()
end sub
private sub combo5_change()
end sub
private sub combo7_change()
end sub
private sub command1_click()
dim a as string
dim kccx1 as string
dim kccx2 as string
dim str1 as string
dim str2 as string
if option3.value = true then
a = trim(combo2)
select case a
case "="
kccx1 = "" & combo1.text & " " & combo2.text & " '" & trim(text1) & "'"
case "like"
kccx1 = "instr(1," & combo1.text & ",'" & trim(text1.text) & "')<>0 "
end select
a = trim(combo4)
select case a
case "="
kccx2 = "" & combo3.text & " " & combo4.text & " '" & trim(text2) & "'"
case "like"
kccx2 = "instr(1," & combo3.text & ",'" & trim(text2.text) & "')<>0 "
end select
if option1.value = true then
if kccx1 = "" then
strtiaojian = "select * from 课程表 where " & kccx2
elseif kccx2 = "" then
strtiaojian = "select * from 课程表 where " & kccx1
else
strtiaojian = "select * from 课程表 where " & kccx1 & "and " & kccx2
end if
elseif option2.value = true then
if kccx1 = "" then
strtiaojian = "select * from 课程表 where " & kccx2
elseif kccx2 = "" then
strtiaojian = "select * from 课程表 where " & kccx1
else
strtiaojian = "select * from 课程表 where " & kccx1 & "or " & kccx2
end if
else
if kccx1 = "" then
strtiaojian = "select * from 课程表 where " & kccx2
elseif kccx2 = "" then
strtiaojian = "select * from 课程表 where " & kccx1
else
msgbox "请选择连接方式!", vbokonly, "警告"
exit sub
end if
end if
if (kccx1 & kccx2) = "" then
msgbox "请输入查询类别!", vbokonly, "警告"
exit sub
else
unload me
frm_updategrean.show 1
end if
end if
if option4.value = true then
if val(combo6) > val(combo9) then
msgbox "请正确选择年份!", vbokonly + vbexclamation, "信息提示"
combo6.setfocus
exit sub
else
if val(combo6) = val(combo9) then
if val(combo7) > val(combo10) then
msgbox "请正确选择月份!", vbokonly + vbexclamation, "信息提示"
combo7.setfocus
exit sub
else
if val(combo7) = val(combo10) then
if val(combo8) > val(combo11) then
msgbox "请正确选择日期!", vbokonly + vbexclamation, "信息提示"
combo8.setfocus
exit sub
end if
end if
end if
end if
end if
if combo6.text = "" or combo7.text = "" or combo8.text = "" or combo9.text = "" or combo10.text = "" or combo11.text = "" then
msgbox "请输入完整的日期", vbokonly, "警告"
exit sub
end if
if sqlstr = "" then
sqlstr = "" & trim(combo5.text) & ">=#" & format(str1, "yyyy-mm-dd") & "# and " & trim(combo5.text) & "<= #" & format(str2, "yyyy-mm-dd") & "#"
else
sqlstr = sqlstr & " and " & trim(combo5.text) & ">=#" & format(str1, "yyyy-mm-dd") & "# and " & trim(combo5.text) & "<= #" & format(str2, "yyyy-mm-dd") & "#"
end if
if sqlstr = "" then
msgbox "请先输入查找时间!"
exit sub
end if
strtiaojian = "select 专业,年级,学期,课程名称,教材,任课老师,课时,上课地点,课程性质,考试性质 from 课程表 where " & sqlstr
unload me
frm_updategrean.show 1
end if
if option3.value <> true and option4.value <> true then
msgbox "请选择查询方式!", vbokonly, "警告"
exit sub
end if
end sub
private sub command3_click()
unload me
end sub
private sub form_load()
dim i, j as integer
for i = 1999 to 2010
combo6.additem i
combo9.additem i
next i
combo6.listindex = 0
combo9.listindex = 0
for i = 1 to 12
combo7.additem i
combo10.additem i
next i
combo7.listindex = 0
combo10.listindex = 0
for i = 1 to 31
combo8.additem i
combo11.additem i
next i
combo8.listindex = 0
combo11.listindex = 0
combo1.additem ("专业")
combo1.additem ("年级")
combo1.additem ("课程名称")
combo1.additem ("教材")
combo1.additem ("任课老师")
'combo1.additem ("课时")
combo1.additem ("课程性质")
combo1.additem ("考试性质")
combo2.additem ("=")
combo3.additem ("专业")
combo3.additem ("年级")
combo3.additem ("课程名称")
combo3.additem ("教材")
combo3.additem ("任课老师")
'combo3.additem ("课时")
combo3.additem ("课程性质")
combo3.additem ("考试性质")
combo4.additem ("=")
combo5.additem ("学期")
combo1.text = ""
combo2.text = ""
text1.text = ""
combo3.text = ""
combo4.text = ""
text2.text = ""
combo5.text = ""
combo6.text = ""
combo7.text = ""
combo8.text = ""
combo9.text = ""
combo10.text = ""
combo11.text = ""
end sub
7.1.2 打印统计
运行打印统计后可以按条件把符合条件的各种信息以报表形式罗列出来,各种信息还可以以打印出来或以报表形式保存。打印统计包括班级统计分析、档案统计分析、课程统计分析、成绩统计分析和交费统计分析五类。
班级统计分析(如:界面如图四)
(图四)
代码如下:
private sub command1_click()
dim sqloriginal as string
dim sqladd as string
dim sqlorder as string
dim strsql as string
sqloriginal = "select 年级,专业,人数,辅导员,备注 from 班级表 "
sqladd = "where 年级=年级 and 专业=专业 "
sqlorder = ""
if check1.value = 1 and isnumeric(text1) then
sqladd = sqladd + "and 年级='" + text1 + "'"
end if
if check2.value = 1 and not isnull(text2) then
sqladd = sqladd + "and 专业='" + text2 + "'"
end if
if check3.value = 1 and isnumeric(text3) then
sqladd = sqladd + "and 人数='" + text3 + "'"
end if
if check4.value = 1 and not isnull(text4) then
sqladd = sqladd + "and 辅导员='" + text4 + "'"
end if
strsql = sqloriginal + sqladd + sqlorde
if dat_main.rsdat_class.state = 1 then
dat_main.rsdat_class.close
end if
dat_main.rsdat_class.open strsql
dat_class.show vbmodal
text1.text = ""
text2.text = ""
text3.text = ""
text4.text = ""
end sub
private sub command2_click()
unload me
end sub
private sub form_load()
text1.text = ""
text2.text = ""
text3.text = ""
text4.text = ""
end sub
private sub text1_change()
end sub
private sub text3_change()
end sub
档案分析统计(如:界面如图五)
(图五)
代码如下:
private sub command1_click()
dim sqloriginal as string
dim sqladd as string
dim sqlorder as string
dim strsql as string
on error resume next
sqloriginal = "select * from 学生档案 "
sqladd = "where 学号=学号 and 姓名=姓名 "
sqlorder = ""
if check1.value = 1 and isnumeric(text1) then
sqladd = sqladd + "and 学号='" + text1 + "'"
end if
if check2.value = 1 and not isnull(text2) then
sqladd = sqladd + "and 姓名='" + text2 + "'"
end if
if check3.value = 1 and not isnull(text3) then
sqladd = sqladd + "and 专业='" + text3 + "'"
end if
if check4.value = 1 and isdate(dtpicker1) then
sqladd = sqladd + " and 出生年月= # " & dtpicker1.value & "#"
end if
strsql = sqloriginal + sqladd + sqlorde
if dat_main.rsdat_strudent.state = 1 then
dat_main.rsdat_strudent.close
end if
dat_main.rsdat_strudent.open strsql
dat_strudent.show vbmodal
text1.text = ""
text2.text = ""
text3.text = ""
end sub
private sub command2_click()
unload me
end sub
private sub form_load()
'combo1.additem ("男")
'combo1.additem ("女")
text1.text = ""
text2.text = ""
text3.text = ""
end sub
private sub text1_change()
end sub
课程统计分析(如:界面如图六)
(图六)
代码如下:
private sub command1_click()
dim sqloriginal as string
dim sqladd as string
dim sqlorder as string
dim strsql as string
sqloriginal = "select * from 课程表 "
sqladd = "where 专业=专业 and 课程名称=课程名称 "
sqlorder = ""
if check1.value = 1 and not isnull(text1) then
sqladd = sqladd + "and 专业='" + text1 + "'"
end if
if check2.value = 1 and not isnull(combo1) then
sqladd = sqladd + "and 课程性质='" + combo1 + "'"
end if
'if check3.value = 1 and not isnumeric(text2) then
'sqladd = sqladd + "and 课时='" + text2 + "'"
'end if
if check4.value = 1 and not isnull(text3) then
sqladd = sqladd + "and 课程名称='" + text3 + "'"
end if
strsql = sqloriginal + sqladd + sqlorde
if dat_main.rsdat_grean.state = 1 then
dat_main.rsdat_grean.close
end if
dat_main.rsdat_grean.open strsql
dat_grean.show vbmodal
text1.text = ""
combo1.text = ""
'text2.text = ""
text3.text = ""
end sub
private sub command2_click()
unload me
end sub
private sub form_load()
text1.text = ""
'text2.text = ""
text3.text = ""
combo1.text = ""
combo1.additem ("必修")
combo1.additem ("选修")
combo1.additem ("自开")
end sub
private sub text3_change()
end sub
成绩统计分析(如:界面如图七)
(图七)
代码如下:
private sub command1_click()
dim sqloriginal as string
dim sqladd as string
dim sqlorder as string
dim strsql as string
on error resume next
sqloriginal = "select * from 成绩表 "
sqladd = "where 学号=学号 and 姓名=姓名 "
sqlorder = ""
if check1.value = 1 and isnumeric(text1) then
sqladd = sqladd + "and 学号='" + text1 + "'"
end if
if check2.value = 1 and not isnull(text2) then
sqladd = sqladd + "and 姓名='" + text2 + "'"
end if
if check3.value = 1 and not isnull(text3) then
sqladd = sqladd + "and 考试科目='" + text3 + "'"
end if
if check4.value = 1 then
sqladd = sqladd + "and 科目分数<60"
end if
strsql = sqloriginal + sqladd + sqlorde
if dat_main.rsdat_chengj.state = 1 then
dat_main.rsdat_chengj.close
end if
dat_main.rsdat_chengj.open strsql
dat_chengj.show vbmodal
text1.text = ""
text2.text = ""
text3.text = ""
end sub
private sub command2_click()
unload me
end sub
private sub form_load()
text1.text = ""
text2.text = ""
text3.text = ""
'text4.text = ""
end sub
private sub text1_change()
end sub
交费统计分析(如:界面如图八)
(图八)
代码如下:
private sub command1_click()
dim sqloriginal as string
dim sqladd as string
dim sqlorder as string
dim strsql as string
sqloriginal = "select 学号,姓名,学期,本学期应交费用,实际交费,本次欠费 from 交费表 "
sqladd = "where 学号=学号 and 姓名=姓名 "
sqlorder = ""
if check1.value = 1 and isnumeric(text1) then
sqladd = sqladd + "and 学号='" + text1 + "'"
end if
if check2.value = 1 and not isnull(text2) then
sqladd = sqladd + "and 姓名='" + text2 + "'"
end if
if check3.value = 1 and isnumeric(text3) then
sqladd = sqladd + "and 实际交费='" + text3 + "'"
end if
if check4.value = 1 and isnumeric(text4) then
sqladd = sqladd + "and 本次欠费='" + text4 + "'"
end if
strsql = sqloriginal + sqladd + sqlorde
if dat_main.rsdat_jiaof.state = 1 then
dat_main.rsdat_jiaof.close
end if
dat_main.rsdat_jiaof.open strsql
dat_jiaof.show vbmodal
text1.text = ""
text2.text = ""
text3.text = ""
text4.text = ""
end sub
private sub command2_click()
unload me
end sub
private sub form_load()
text1.text = ""
text2.text = ""
text3.text = ""
text4.text = ""
end sub