Visual Foxpro编程实例.docx

上传人:小飞机 文档编号:3168640 上传时间:2023-03-11 格式:DOCX 页数:24 大小:44.13KB
返回 下载 相关 举报
Visual Foxpro编程实例.docx_第1页
第1页 / 共24页
Visual Foxpro编程实例.docx_第2页
第2页 / 共24页
Visual Foxpro编程实例.docx_第3页
第3页 / 共24页
Visual Foxpro编程实例.docx_第4页
第4页 / 共24页
Visual Foxpro编程实例.docx_第5页
第5页 / 共24页
亲,该文档总共24页,到这儿已超出免费预览范围,如果喜欢就下载吧!
资源描述

《Visual Foxpro编程实例.docx》由会员分享,可在线阅读,更多相关《Visual Foxpro编程实例.docx(24页珍藏版)》请在三一办公上搜索。

1、Visual Foxpro编程实例实验五 Visual Foxpro编程实践 一. 实验目的与要求 掌握利用Visual Foxpro编制开发自己的应用程序的实践知识,并学会在程序调试中自行发现问题和修改程序代码,最终完成应用程序的无错运行。 二. 相关知识 利用Visual Foxpro自行开发编制应用程序的步骤: 1设置好系统的工作环境(尤其注意工作目录的默认设置)。 2如果是初次进行,应当先建立一个项目,为该项目命名,激活项目管理器。如果是接着上次的工作进行,则打开上次工作的本项目,同样也激活项目管理器。 3在项目管理器的“数据”“数据库”下面创建一个数据库,并命名(如已创建,则跳过本步

2、骤)。 4在项目管理器的“数据”“数据库”“表”下面进行数据表的创建或修改工作,并输入少量的正确数据以便将来的运行调试(如果已经创建了数据表,则跳过本步骤)。 5在项目管理器的“文档”下面创建该应用程序所用到的所有表单,设计好各表单的界面并为表单里的控件填写程序代码.(注意为表单添加各自的数据环境,否则会出错!) 6试运行各表单,发现问题后重新修改有问题的表单的代码,反复调试和修改直至最后能无错运行。 7将应用程序打包发布或制作成安装文件。 三. 实验内容与步骤 本次实验以一个简单的学生成绩管理系统为例。首先,对该系统作一个简单的介绍: 该应用系统为完成学生信息和成绩的管理系统,主要有以下几个

3、应用模块: (1) 用户登录管理: 系统具有管理员功能,只有取得管理员权限的人才能使用本系统。 (2) 数据添加功能: 对学生基本信息、教师基本信息、班级信息、课程信息、学生成绩信息进行添加录入。 (3) 数据查询功能: 对上述信息的基本查询。 (4) 数据修改功能: 对上述信息可进行修改工作。 (5) 统计操作: 可分别按个人成绩、单科成绩统计出最高成绩、最低成绩和平均成绩等。 (6) 打印功能: 对上述信息可进行打印。 实验步骤如下: 1数据库设计: 首先设置好系统的运行环境和工作目录,然后建立项目,为项目命名为“学生成绩管理系统”,激活项目管理器,并在在项目管理器的“数据”“数据库”下面

4、创建一个数据库,命名为“学生成绩管理”,在“数据库”的“表”下面创建以下各数据表: (1) 用户信息表user (表名命名为user即可,不要加汉字。以下同。) 字段名称 用户名 密码 (2) 学生信息表 student 字段名称 学号 姓名 性别 类型 字符型 字符型 字符型 宽度 8 10 2 类型 字符型 字符型 宽度 10 10 班级编号 出生日期 (3) 教师信息表 teacher 字段名称 教师代码 姓名 性别 职称 部门 出生日期 (4) 班级信息表 classes 字段名称 班级编号 年级 专业 系代码 学制 类型 (5) 课程信息表 course 字段名称 课程代码 课程名称

5、 类别 教师代码 (6) 分数信息表 score 字段名称 学号 课程代码 成绩 字符型 日期型 类型 字符型 字符型 字符型 字符型 字符型 日期型 类型 字符型 字符型 字符型 字符型 字符型 字符型 类型 字符型 字符型 字符型 字符型 类型 字符型 字符型 数值型 6 8 宽度 4 10 2 10 10 8 宽度 6 4 10 2 2 4 宽度 6 16 4 4 宽度 8 6 4 创建好以上数据表以后,应该向每个表中添加适量合法数据以便后面的测试。 2.表单设计 2.1登录模块 功能描述: 实现只有指定的用户才能访问系统的功能。并且,只有身份为“管理员”的用户才可以调用修改模块修改数据

6、。 界面设计: 表单名称: login 文件名: login.scx 数据环境: user.dbf 对象设置: 对 象 Form1 Lable1 Lable2 Lable3 Combo1 Cammand1 Cammand2 属 性 Caption Caption Caption Caption RowSource Caption Caption 值 欢迎使用学生成绩管理系统 学生成绩管理系统 请输入用户名: 请输入密码: User.用户名 登录 退出 指定数据值来源类型 指定数据值来源 说 明 RowSourceType 6-字段 函数与方法声明: (1) Command1中的Click事件

7、功能:完成在登录时对输入的用户名和密码的检验,如果数据表user中存在输入的用户名和密码信息,则调用主窗口(如果是管理员则不但调用主窗口,还允许执行主窗口的修改功能),否则提示输入错误。 程序清单: private kl,yh,st st=密码不正确,请重新输入! use user kl=alltrim(thisform.text1.value) yh=alltrim(bo1.value) *将用户输入的用户名和密码的值分别保存在yh和kl变量中 locate for alltrim(bo1.value)= =alltrim(user.用户名) *在user表中查找是否有与yh和kl匹配的记录

8、 if found and alltrim(user.密码)= =kl *正确的用户名和密码 thisform.visible=.f. close tables all do form main.scx if yh= =admin *如果是超级用户管理员,则允许他使用main表单中的第三组按钮(即修改模块) main.optiongroup1.option3.enabled=.t. endif this.parent.text1.value= else *错误的用户名和密码,系统给出提示,延迟2秒 wait window st timeout 2 thisform.text1.value= t

9、hisform.text1.setfocus endif (2) Command2中的Click事件 功能:退出学生成绩管理系统 程序清单: clear events quit (3) Form1的Destroy事件 功能:意外关闭程序窗口时的处理 程序清单: clear events 2.2 主界面模块 功能描述: 主要是提供本系统各功能模块的入口. 界面设计: 表单名称: main 文件名: main.scx 数据环境: 无 对象设置: 对 象 Form1 Lable1 Lable2 Optiongroup1 属 性 Caption Caption Caption ButtonCount

10、值 学生成绩管理系统 欢迎使用学生成绩管理系统 请选择要操作的内容: 6 添加记录 查询记录 修改记录 .F. 统计数据 打印报表 退出系统 Optiongroup1.Option1 Caption Optiongroup1.Option2 Caption Optiongroup1.Option3 Caption Optiongroup1.Option3 Enabled Optiongroup1.Option4 Caption Optiongroup1.Option5 Caption Optiongroup1.Option6 Caption 函数与方法声明: (1) Optiongroup1中

11、的IntelactiveChange事件: 功能: 根据Optiongroup1中的选择单击按钮,调用各重要功能模块. 程序清单: do case case this.value=1 do form 添加 case this.value=2 do form 查询 case this.value=3 do form 修改 case this.value=4 do form 统计 case this.value=5 do form 打印 case this.value=6 thisform.release quit endcase (2) Optiongroup1中的每一个Option的Click

12、事件: 功能: 与(1)中不同,(1)是指在Optiongroup中的各个Option切换时才触发的程序,仅这样还不够,还要编写每个Option被单击时触发的程序才完整。 程序清单: 对应Optiongroup1.Option1的Click事件: do form 添加 (其余类推) 2.3 数据添加模块 功能描述: 用户通过5个不同的页面来完成对学生信息表、教师信息表、班级表、课程表和成绩表的数据添加操作。 界面设计: 表单名称: 添加 文件名: 添加.scx 数据环境: student.dbf, class.dbf, score.dbf, teacher.dbf, course.dbf 对象

13、设置: 对 象 Form1 PageFrame1 Command1 Page1 Page2 Page3 Page4 Page5 Command1 Command2 属 性 Caption PageCount Caption Caption Caption Caption Caption Caption Caption Caption 值 添加 5 返回主菜单 学生表 教师表 班级表 课程表 成绩表 添加 清空 主表单中的Command1 与上面的Command1不同,这是在各个页面中的Command1 说 明 函数与方法声明: 因为添加表单中对于5个表的操作方法类似,所以这里只给出学生表的添加

14、部分,其余4个页面的程序请同学们自己对照思考和编制。 (1) Form1中的Active事件 功能: 设置焦点位置 程序清单: this.pageframe1.page1.text1.setfocus (2) Form1中的Command1的Click事件 功能: 释放当前窗口 程序清单: thisform.release (3) Page1中Command1的Click事件 功能: 将输入的新记录信息添加到学生表中,完成新记录的添加工作 程序清单: num1=alltrim(thisform.pageframe1.page1.text1.value) num2=alltrim(thisfor

15、m.pageframe1.page1.text2.value) num3=alltrim(thisform.pageframe1.page1.text3.value) num4=alltrim(thisform.pageframe1.page1.text4.value) num5=alltrim(dtoc(thisform.pageframe1.page1.text5.value) &并非是alltrim(thisform.pageframe1.page1.text5.value) set exact on do case case num1= messagebox(学号不能为空!,0+48,

16、系统提示!) thisform.pageframe1.page1.text1.setfocus case num2= messagebox(姓名不能为空!,0+48,系统提示!) thisform.pageframe1.page1.text2.setfocus case num3= messagebox(性别不能为空!,0+48,系统提示!) thisform.pageframe1.page1.text3.setfocus case num4= messagebox(班级编号不能为空!,0+48,系统提示!) thisform.pageframe1.page1.text4.setfocus c

17、ase num5= messagebox(出生日期不能为空!,0+48,系统提示!) thisform.pageframe1.page1.text5.setfocus otherwise a=messagebox(确认添加么?,1+64+0,系统提示!) if a=1 select student go bottom insert into student(学号,姓名,性别,班级编号,出生日期) num3,num4,ctod (num5) messagebox(添加成功!) else thisform.pageframe1.page1.text1.setfocus endif endcase

18、(4) Page1中的Command2的Click事件: 功能: 清空当前页面上输入的数据 程序清单: this.parent.text1.value= this.parent.text2.value= this.parent.text3.value= this.parent.text4.value= this.parent.text5.value= values(num1,num2, 由于其它各个页面上的添加数据的操作大同小异,这里不再赘述。 比如: num1=alltrim(thisform.pageframe1.page2.text1.value) num2=alltrim(thisfo

19、rm.pageframe1.page2.text2.value) num3=alltrim(thisform.pageframe1.page2.text3.value) num4=alltrim(thisform.pageframe1.page2.text4.value) num5=alltrim(thisform.pageframe1.page2.text5.value) num6=alltrim(dtoc(thisform.pageframe1.page2.text6.value) &并非是alltrim(thisform.pageframe1.page2.text6.value) set

20、 exact on do case case num1= messagebox(教师代码不能为空!,0+48,系统提示!) thisform.pageframe1.page2.text1.setfocus case num2= messagebox(姓名不能为空!,0+48,系统提示!) thisform.pageframe1.page2.text2.setfocus case num3= messagebox(性别不能为空!,0+48,系统提示!) thisform.pageframe1.page2.text3.setfocus case num4= messagebox(职称不能为空!,0

21、+48,系统提示!) thisform.pageframe1.page2.text4.setfocus case num5= messagebox(部门不能为空!,0+48,系统提示!) thisform.pageframe1.page2.text5.setfocus case num6= messagebox(出生日期不能为空!,0+48,系统提示!) thisform.pageframe1.page2.text6.setfocus otherwise a=messagebox(确认添加么?,1+64+0,系统提示!) if a=1 select student go bottom inse

22、rt into student(教师代码,姓名,性别,职称,部门,出生日期) values(num1,num2,num3,num4,num5,ctod(num6) messagebox(添加成功!) else thisform.pageframe1.page2.text1.setfocus endif endcase 2.4 数据查询模块 功能描述: 用户可以通过不同的页面完成对5个不同表中的数据的查询操作 界面设计: 表单名称: 查询 文件名: 查询.scx 数据环境: student.dbf, class.dbf, score.dbf, teacher.dbf, course.dbf 对象

23、设置: 查询主表单中的对象设置: 对 象 Form1 PageFrame1 Command1 对 象 Combo1 Combo2 Label1 Label2 Label3 Label4 Label5 Label6 Label7 属 性 Caption PageCount Caption 属 性 RowSource RowSource Caption Caption Caption Caption Caption Caption Caption 值 查询 3 返回主菜单 值 Classese.班级编号 Student.姓名 请选择班级代码和姓名 班级代码 姓名 学号 姓名 性别 出生日期 主表单

24、中的Command1 说 明 PageFrame1.Page1中的对象设置: RowSourceType 6-字段 RowSourceType 6-字段 PageFrame1.Page2用来对数据表进行浏览,其界面为: 其中的对象设置: 对 象 Combo1 属 性 RowSourceType RowSource Style Value Label1 Grid1 Caption 值 1-值 学生表,教师表,班级表,课程表,成绩表 2-下拉列表框 1 请选择要浏览的表 RecordSourceType 0-表 PageFrame1.Page3用来进行课程浏览.其界面为: 其中的对象设置: 对 象

25、 Label1 属 性 Caption 值 5 课程代码 CommandGroup1 ButtonCount Label2 Label3 Label4 Caption Caption Caption 课程名称 类别 教师代码 函数与方法声明: (1) Thisform.PageFrame1.Page1中的Deactive事件: 功能: 当前学生情况查询页面被释放时,使数据查询设置过滤条件为空. 程序清单: set filter to (2) Thisform.PageFrame1.Page1.Combo1中的InteractiveChange事件: 功能: 根据下拉列表框的选择,设置班级信息的

26、过滤条件,同时清空文本框信息. 程序清单: public m m=bo1.value select student set filter to 班级编号=m thisform.pageframe1.page1.text1.value= thisform.pageframe1.page1.text2.value= thisform.pageframe1.page1.text3.value= thisform.pageframe1.page1.text4.value= (3) Thisform.PageFrame1.page1.Combo2中的InteractiveChange事件: 功能: 根据

27、前面设置的班级过滤条件对学生信息进行查询,并将结果在当前页面显示 程序清单: locate for 姓名=this.value *用组合框中的值进行查找 if found thisform.pageframe1.page1.text1.value=学号 thisform.pageframe1.page1.text2.value=姓名 thisform.pageframe1.page1.text3.value=性别 thisform.pageframe1.page1.text4.value=出生日期 bo2.value= endif (4) Thisform.PageFrame1.page2中的

28、Init事件: 功能: 在“数据表浏览”页显示时进行相关的初始化工作. 程序清单: with this.grid1 .recordsourcetype=6 .recordsource=student .refresh .columncount=5 .column1.width=60 .column2.width=65 .column3.width=40 .column4.width=70 .column5.width=60 .column1.header1.caption=学号 .column2.header1.caption=姓名 .column3.header1.caption=性别 .c

29、olumn4.header1.caption=出生日期 .column5.header1.caption=班级编号 .readonly=.t. .deletemark=.f. endwith (5) Thisform.PageFrame1.Page2.Combo1中的IntelactiveChange事件 功能: 在“数据表浏览”页中根据下拉组合框中的选择对不同的表进行数据内容显示 程序清单: &加入如下代码,可防止由字段少的表往字段多的表切换时造成数据字段丢失无法显示的问题 with this.parent.grid1 .columncount=6 .column1.width=60 .co

30、lumn2.width=65 .column3.width=50 .column4.width=66 .column5.width=70 .column6.width=70 endwith &即每次都事先把grid先刷新成行数教多的表. do case case this.value=1 with this.parent.grid1 .recordsourcetype=6 .recordsource=student .columncount=5 .column1.width=60 .column2.width=65 .column3.width=40 .column4.width=70 .co

31、lumn5.width=60 .column1.header1.caption=学号 .column2.header1.caption=姓名 .column3.header1.caption=性别 .column4.header1.caption=出生日期 .column5.header1.caption=班级编号 .refresh .readonly=.t. .deletemark=.f. endwith case this.value=2 with this.parent.grid1 .columncount=6 .recordsource=teacher .column1.header1

32、.caption=教师代码 .column2.header1.caption=姓名 .column3.header1.caption=性别 .column4.header1.caption=出生日期 .column5.header1.caption=部门 .column6.header1.caption=技术职务 .column1.width=60 .column2.width=65 .column3.width=50 .column4.width=66 .column5.width=70 .column6.width=70 .refresh .readonly=.t. .deletemark

33、=.f. endwith case this.value=3 with this.parent.grid1 .recordsourcetype=6 .recordsource=classes .columncount=6 .column1.width=60 .column2.width=65 .column3.width=50 .column4.width=70 .column5.width=60 .column6.width=60 .column1.header1.caption=班级编号 .column2.header1.caption=年级 .column3.header1.captio

34、n=专业 .column4.header1.caption=系代码 .column5.header1.caption=学制 .column6.header1.caption=类别 .refresh .readonly=.t. .deletemark=.f. endwith case this.value=4 with this.parent.grid1 .recordsourcetype=6 .recordsource=course .columncount=4 .column1.width=60 .column2.width=100 .column3.width=50 .column4.wi

35、dth=50 .column1.header1.caption=课程代码 .column2.header1.caption=课程名称 .column3.header1.caption=类别 .column4.header1.caption=教师代码 .refresh .readonly=.t. .deletemark=.f. endwith case this.value=5 with this.parent.grid1 .recordsourcetype=6 .recordsource=score .columncount=3 .column1.width=60 .column2.width

36、=100 .column3.width=50 .column1.header1.caption=学号 .column2.header1.caption=课程代码 .column3.header1.caption=成绩 .refresh .readonly=.t. .deletemark=.f. endwith endcase (6) Thisform.PageFrame1.Page3中的Init事件 功能: 当“课程浏览”页面被显示出来时,进行相关的初始化工作. 程序清单: select course this.text1.value=课程代码 this.text2.value=课程名称 th

37、is.text3.value=类别 this.text4.value=教师代码 (7) Thisform.PageFrame1.Page3中的Refresh事件 功能: 在“课程浏览”页面中刷新当前的数据显示 程序清单: select course this.text1.value=课程代码 this.text2.value=课程名称 this.text3.value=类别 this.text4.value=教师代码 (8) Thisform.PageFrame1.Page3中的CommandGroup1的Click事件 功能: 利用按钮组完成对数据库中的记录浏览 程序清单: select c

38、ourse do case case this.value=1 go top case this.value=2 skip -1 if bof messagebox(已到首部!,0+48,系统提示) go top endif case this.value=3 skip if eof messagebox(已到末尾!,0+48,系统提示) go bottom endif case this.value=4 go bottom case this.value=5 thisform.release endcase thisform.refresh 2.5 数据修改模块 功能描述: 用户可以通过不同

39、的页面完成对5个不同表中的数据的修改操作 界面设计: 由于修改表单中对于5个表的操作方法类似,这里只给出第一个页面即“学生表”的设计部分。其余4个页面的设计及相关的程序代码请同学们自己思考并完成。 表单名称: 修改 文件名: 修改.scx 数据环境: student.dbf, class.dbf, score.dbf, teacher.dbf, course.dbf 对象设置: 对 象 Form1 PageFrame1 Command1 Page1.Combo1 Page2.Combo1 Page3.Combo1 Page4.Combo1 Page5.Combo1 Page1.Command1

40、 Page1.Command2 属 性 Caption PageCount Caption RowSource RowSource RowSource RowSource RowSource Caption Caption 值 修改 5 返回: Student.学号 Teacher.教师代码 Classess.班级编号 Course.课程代码 Score.学号 确定 退出 RowSourceType 6-字段 RowSourceType 6-字段 RowSourceType 6-字段 RowSourceType 6-字段 RowSourceType 6-字段 函数与方法声明: (1) Thisform.PageFrame1.Page1中的Activate事件: 功能: 在学生信息修改页面显示时进行初始化操作 程序清单: select student go top this.text1.value=学号 this.text2.value=姓名 this.text3.value=性别 this.text4.value=出生日期 this.text5.value=班级编号 (2) Thisform.PageFrame1.Page1.Combo1中的IntelactiveChange事件: 功能: 根据学号,查找对应的学生信息 程序清单:

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 生活休闲 > 在线阅读


备案号:宁ICP备20000045号-2

经营许可证:宁B2-20210002

宁公网安备 64010402000987号