前言
课程设计要求用VFP写一个小程序,承接上一篇用python写的,特此记录
我的部分
我负责3.10,3.4 3.5 3.6是都要写的
建表建库
没什么好说的,把相关字段填进去就行了,这里他说要每个表多建一个TEMP表,这里有个巧方法,先建好原本的表
然后把这些表全都移去
小心不要点到删除了
然后切到vfp项目目录,选取这些表文件,直接复制,粘贴
得到这些副本文件,然后把他们改名为文件名+TEMP,再从vfp项目里面全都添加进去
这样就省去了重复建表的过程
可视化类
先新建一个类
如下创建一个命令按钮组
比较关键的属性ButtonCount
其他省略
最后布局效果如下
添加click代码
首记录click方法
上一条click方法
IF BOF() .or. RECNO() = 1 MESSAGEBOX("到头啦",48,"移动记录") ELSE SKIP -1 ENDIF thisform.Refresh()
|
其中 BOF()解释如下
RECNO()解释如下
也就是说如果到第一张表,就会调用messagebox()方法弹出提示
如果没有到头,那么就会向下移动一条记录
下一条click方法
同理上一条click方法
IF BOF() .or. RECNO() = RECCOUNT() MESSAGEBOX("到尾啦",48,"移动记录") ELSE SKIP ENDIF thisform.Refresh()
|
reccount()方法定义如下
末记录click方法
添加判断逻辑
如果到头了不能让按钮启用,要让按钮变成灰的
* 如果为空或者只有一条记录 IF BOF() .and. EOF() .or. RECCOUNT() = 1 this.commandtop.Enabled=.f. this.commandpre.Enabled=.f. this.commandnxt.Enabled=.f. this.commandend.Enabled=.f. ENDIF * 如果记录在末尾 IF RECNO()=RECCOUNT() .or. EOF() this.commandtop.Enabled=.t. this.commandpre.Enabled=.t. this.commandnxt.Enabled=.f. this.commandend.Enabled=.f. ELSE * 如果记录在开头 IF RECNO()=1 .or. EOF() this.commandtop.Enabled=.f. this.commandpre.Enabled=.f. this.commandnxt.Enabled=.t. this.commandend.Enabled=.t. ELSE * 如果记录在结尾 this.commandtop.Enabled=.t. this.commandpre.Enabled=.t. this.commandnxt.Enabled=.t. this.commandend.Enabled=.t. ENDIF ENDIF
|
权限代码类
按照要求设定属性就行
车辆管理模块
车辆详细信息查询表单
创建以后直接ctrl+s,命名为车辆详细信息查询
加八个标签七个文本框,ctrl+v 15次
布局设计如下(真的尽力了)
然后运行如下
这里照着他写出现问题了,我表里是没有数据的,所有按钮都应该为灰色,但是这里两个亮的,稍微修改一下buttonclass
很简单
buttonclass的init方法代码现在修改如下(就修改了多了一个else)
IF BOF() .and. EOF() .or. RECCOUNT() = 1 this.commandtop.Enabled=.F. this.commandpre.Enabled=.F. this.commandnxt.Enabled=.F. this.commandend.Enabled=.F. ELSE IF RECNO()=RECCOUNT() .or. EOF() this.commandtop.Enabled=.T. this.commandpre.Enabled=.T. this.commandnxt.Enabled=.F. this.commandend.Enabled=.F. ELSE IF RECNO()=1 .or. EOF() this.commandtop.Enabled=.F. this.commandpre.Enabled=.F. this.commandnxt.Enabled=.T. this.commandend.Enabled=.T. ELSE this.commandtop.Enabled=.T. this.commandpre.Enabled=.T. this.commandnxt.Enabled=.T. this.commandend.Enabled=.T. ENDIF ENDIF ENDIF
|
添加车辆表单
这里由于和上一个表单很相似,直接故技重施
然后按照他的要求,为了保证数据输入的正确性,先将数据输入到车辆temp表中,保证正确以后再确定保存
全都要加个temp
init方法里也要改不然会报错
写到这里的时候报错了
查看replace和right函数的定义
然后发现是我的括号位置写错了,应该这么写
REPLACE 内部编号 WITH RIGHT("00000000"+ALLTRIM(STR(K + 1)),6)
|
这里可以看出来select+use的用法是规定表的次序,1为车辆temp,2为车辆表
添加数据click代码
首先看一下messagebox函数的定义
这个第二个参数规定了messagebox的按钮方式
然后代码都可以理解了
IF LEN(ALLTRIM(thisform.txt品牌.Value))=0 MESSAGEBOX("品牌输入错误",46+2,"错误") thisform.txt品牌.SetFocus ELSE IF LEN(ALLTRIM(thisform.txt型号.Value))=0 MESSAGEBOX("型号输入错误",46+2,"错误") thisform.txt型号.SetFocus ELSE IF LEN(ALLTRIM(thisform.txt底盘.Value))=0 MESSAGEBOX("底盘号输入错误",46+2,"错误") thisform.txt底盘.SetFocus ELSE IF LEN(ALLTRIM(thisform.txt发动机.Value))=0 MESSAGEBOX("发动机号输入错误",46+2,"错误") thisform.txt发动机.SetFocus else SELECT 车辆信息 APPEND FROM 车辆信息temp k = RECCOUNT() SELECT 车辆信息temp ZAP APPEND BLANK replace 内部编号 WITH RIGHT("0000000"+ALLTRIM(STR(k + 1)),6) ENDIF ENDIF ENDIF ENDIF thisform.Refresh()
|
剩余两个按钮
重写按钮
* 把所有清空 thisform.txt编号.Value = "" thisform.txt品牌.Value = "" thisform.txt发动机.Value = "" thisform.txt型号.Value = "" thisform.txt底盘.Value = "" thisform.txt号码.Value = "" thisform.Refresh()
|
取消添加按钮
* 明显是关闭表单 thisform.Release()
|
车辆信息修改表单
故技重施!
他这里要求按钮复用
把删除数据按钮作为一个复用按钮,在点击修改数据后,删除数据变为保存数据,然后进行相应的逻辑
这里把删除数据的对象名改为cmdoperate
修改数据按钮代码
thisform.cmdoperate.Caption = "保存数据" *thisform.txt编号.ReadOnly = .f. thisform.txt底盘.ReadOnly = .f. thisform.txt发动机.ReadOnly = .f. thisform.txt号码.ReadOnly = .f. thisform.txt品牌.ReadOnly = .f. thisform.txt型号.ReadOnly = .f. * 关闭修改数据按钮以防耗费资源误操作 thisform.cmdOperate1.Enabled = .f. thisform.Refresh()
|
删除数据按钮代码
用一个if else作为大判断,判断当前cmdoperate的修改状态如何
* 创建一个本地变量sure LOCAL sure IF thisform.cmdOperate.Caption = "保存数据" sure = MESSAGEBOX("确定修改数据吗",4+32,"提示") IF sure = 6 replace 车辆品牌 WITH ALLTRIM(thisform.txt品牌.Value) replace 发动机编号 WITH ALLTRIM(thisform.txt品牌.Value) replace 车牌号码 WITH ALLTRIM(thisform.txt号码.Value) replace 底盘编号 WITH ALLTRIM(thisform.txt底盘.Value) replace 车辆型号 WITH ALLTRIM(thisform.txt型号.Value) * 恢复控件状态 thisform.cmdoperate.Caption = "删除数据" *thisform.txt编号.ReadOnly = .f. thisform.txt底盘.ReadOnly = .t. thisform.txt发动机.ReadOnly = .t. thisform.txt号码.ReadOnly = .t. thisform.txt品牌.ReadOnly = .t. thisform.txt型号.ReadOnly = .t. * 开启修改数据按钮 thisform.cmdOperate1.Enabled = .t. thisform.Refresh() ENDIF ELSE sure = MESSAGEBOX("确定删除数据吗",4+32,"提示") IF sure = 6 k = thisform.txt编号.Value DELETE FOR 内部编号 = K PACK k = RECCOUNT() thisform.txt总数.Value = k thisform.Refresh() ENDIF ENDIF
|
关闭按钮
经典的
写完咯!
后记
我在写的时候我的宝贝偷拍我给我拍了张照片
真能捣蛋
宝贝真可爱