| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 2000 人关注过本帖
标题:一个通用的查询程序(试用)
取消只看楼主 加入收藏
沙枣
Rank: 4
来 自:宁夏银川
等 级:业余侠客
威 望:5
帖 子:103
专家分:221
注 册:2015-5-31
结帖率:100%
收藏
已结贴  问题点数:20 回复次数:8 
一个通用的查询程序(试用)
*这个程序是应用软件中的一个过程,只要打开数据表,就可以对任意结构的数据表实现查询,与库结构完全无关,运行环境:win xp/VFP6.0。
*浮动型F、整型I、双精度型B不能被type函数正确识别,只能识别为N型数据,按N型数据处理。
private all
set escape off
set status off
set scoreboard off
set talk off
set menus off
set exact on
set safety off
set color to +7/1
clear
jhh=1
do while jhh<=fcount(1)
if field(jhh)="轮次"
set color to +7/1
clear
jgzdh=messagebox("当前库发现[轮次]字段,是否切除[轮次]字段继续运行?",4+32+0,"条件查询")
if jgzdh=6
*alter改变库结构后,记录指针回到1号记录。
alter table dbf() drop column 轮次
exit
else
wait "[轮次]字段未切除,不能运行本程序." window at 16,52 nowait
tdsj=inkey(1.5)
wait clear
return
endif
endif
jhh=jhh+1
enddo
if upper(right(dbf(1),10))="LSCFZK.DBF"
jgzdh=messagebox("在LSCFZK库中运行本程序将覆盖其现有的数据,"+chr(13)+"是否备份LSCFZK库现有的数据?",4+32+0,"条件查询")
if jgzdh=6
xspxkm=space(40)
define windows win1 from 11,11 to 19,88 system title "LSCFZK库数据备份" color scheme 1
activate windows win1
move windows win1 center
@3,8 say "请输入新的数据库名:"  get xspxkm pict '@A' valid trim(xspxkm)<>"".and.(.not."LSCFZK"$upper(xspxkm)) color ,+6/4
set cursor on
read
set cursor off
clear gets
release windows win1
if upper(right(trim(xspxkm),4))<>".DBF"
xspxkm=trim(xspxkm)+".dbf"
endif
if file(xspxkm)
clear
fgfh=messagebox("["+xspxkm+"]文件已存在,覆盖?",4+32+256,"文件覆盖")
if fgfh=6
copy to &xspxkm
else
clear
wait "目标文件未覆盖,未进行数据备份." window at 16,52 nowait
tdsj=inkey(1)
wait clear
endif
else
copy to &xspxkm
endif
endif
else
*
endif
dimension name2(300),cmop(300),adta(300),bjf(300),meti(300)
bjf(1)="$"
bjf(2)="="
bjf(3)=">"
bjf(4)="<"
bjf(5)=">="
bjf(6)="<="
bjf(7)="<>"
qzkg=0
qxh=1
do while qxh<=fcount()
if len(field(qxh))>qzkg
store len(field(qxh)) to qzkg
endif
qxh=qxh+1
enddo
qxh=1
do while qxh<=fcount()
if int((14-qzkg)/2)=(14-qzkg)/2
store space((14-qzkg)/2)+field(qxh)+space(14-len(field(qxh))-(14-qzkg)/2) to meti(qxh)
else
store space((14-qzkg-1)/2)+field(qxh)+space(14-len(field(qxh))-(14-qzkg-1)/2) to meti(qxh)
endif
qxh=qxh+1
enddo
cxkm=dbf(1)
copy structure to lsbjczk
sele 2
*alter改变库结构后,记录指针回到1号记录。
alter table lsbjczk add column 轮次 N(10)
use
sele 1
store 1 to t1,x3
qxh=1
ydlh1=1
jhdh1=1
inqxh=1
jhh=1
=afields(fac)
do while x3<>2
set color to +7/1,+6/4
clear
@24,12 say "PgUp键上页    PgDn键下页   ↑键上一字段   ↓键下一字段    Enter键确认"
@2,6.7 clear to 20,24
set color to +7/6
@2,6.7 clear to 20,24
@2,6.7 to 20,24
@3,10 say "请选择字段"
set color to +7/3,+6/4
@5,8 clear to 19.4,22.7
cxhh=1
if fcount()>14
if qxh>14
do while ydlh1<=qxh
if ydlh1=qxh
@cxhh+4,8 prompt meti(ydlh1)
else
@cxhh+4,8 say meti(ydlh1)
endif
cxhh=cxhh+1
ydlh1=ydlh1+1
enddo
else
do while ydlh1<=14
if ydlh1=jhdh1
@cxhh+4,8 prompt meti(ydlh1)
else
@cxhh+4,8 say meti(ydlh1)
endif
cxhh=cxhh+1
ydlh1=ydlh1+1
enddo
endif
else
do while ydlh1<=fcount()
if ydlh1=jhdh1
@cxhh+4,8 prompt meti(ydlh1)
else
@cxhh+4,8 say meti(ydlh1)
endif
cxhh=cxhh+1
ydlh1=ydlh1+1
enddo
endif
keyboard chr(13)
menu to jhdh1

do while .t.
anke=inkey(0)
do case
case anke=5.and.qxh>1.and.qxh<=fcount()
qxh=qxh-1
case anke=5.and.qxh=1
qxh=fcount()
case anke=24.and.qxh>=1.and.qxh<fcount()
qxh=qxh+1
case anke=24.and.qxh=fcount()
qxh=1
case anke=3
if qxh+13<=fcount()
qxh=qxh+13
else
qxh=fcount()
endif
case anke=18
if qxh-13>=1
qxh=qxh-13
else
qxh=1
endif
endcase
if qxh>14
ydlh=qxh-13
jhdh=14
else
ydlh=1
jhdh=qxh
endif
ydlh1=ydlh
jhdh1=jhdh

cxhh=1
set color to +7/3,+6/4
@5,8 clear to 19.4,22.7

if fcount()>14
if qxh>14
do while ydlh<=qxh
if ydlh=qxh
@cxhh+4,8 prompt meti(ydlh)
else
@cxhh+4,8 say meti(ydlh)
endif
cxhh=cxhh+1
ydlh=ydlh+1
enddo
else
do while ydlh<=14
if ydlh=jhdh
@cxhh+4,8 prompt meti(ydlh)
else
@cxhh+4,8 say meti(ydlh)
endif
cxhh=cxhh+1
ydlh=ydlh+1
enddo
endif
else
do while ydlh<=fcount()
if ydlh=jhdh
@cxhh+4,8 prompt meti(ydlh)
else
@cxhh+4,8 say meti(ydlh)
endif
cxhh=cxhh+1
ydlh=ydlh+1
enddo
endif
keyboard chr(13)
menu to jhdh
x1=qxh
name2(t1)=field(x1)
tt=type(name2(t1))
if tt="M".or.tt="G"
set color to +7/1
@22,10 say "记忆型/通用型字段不能用于条件查询"
loop
endif
if anke=13
exit
endif
enddo
if tt='C'.or.tt='N'.or.tt='D'.or.tt='Y'.or.tt='T'
@2,27.7 clear to 20,45
set color to +7/6
@2,27.7 clear to 20,45
@2,27.7 to 20,45
@3,30 say "请选择比较符"
set color to +7/3,+6/4
inanke=0
do while .t.
@5,29 clear to 19.4,43.7
incxhh=1
do while incxhh<=7
if inqxh=incxhh
@incxhh+4,29 prompt space(7)+bjf(incxhh)+space(7-len(bjf(incxhh)))
else
@incxhh+4,29 say space(7)+bjf(incxhh)+space(7-len(bjf(incxhh)))
endif
incxhh=incxhh+1
enddo
keyboard chr(13)
menu to x2
inanke=inkey(0)
do case
case inanke=5.and.inqxh>1.and.inqxh<=7
inqxh=inqxh-1
case inanke=5.and.inqxh=1
inqxh=7
case inanke=24.and.inqxh>=1.and.inqxh<7
inqxh=inqxh+1
case inanke=24.and.inqxh=7
inqxh=1
endcase
if inanke=13
exit
endif
enddo
else
@2,27.7 clear to 20,45
set color to +7/6
@2,27.7 clear to 20,45
@2,27.7 to 20,45
@3,29 say "请选择逻辑条件"
set color to +7/3,+6/4
inanke=0
inqxh=1
do while .t.
@5,29 clear to 19.4,43.7
do case
case inqxh=1
@5,29 prompt "    正条件    "
@6.2,29 say "    反条件    "
case inqxh=2
@5,29 say "    正条件    "
@6.2,29 prompt "    反条件    "
endcase
keyboard chr(13)
menu to x2
inanke=inkey(0)
do case
case inanke=5.and.inqxh>1.and.inqxh<=2
inqxh=inqxh-1
case inanke=5.and.inqxh=1
inqxh=2
case inanke=24.and.inqxh>=1.and.inqxh<2
inqxh=inqxh+1
case inanke=24.and.inqxh=2
inqxh=1
endcase
if inanke=13
exit
endif
enddo
endif
x2=inqxh
cmop(t1)=iif(tt<>"L",bjf(x2),iif(x2=1,'','.not.'))
do case
case tt="C"
adta(t1)=space(14)
case tt="N".or.tt="Y"
nagdxs=name2(t1)
adta(t1)=&nagdxs
case tt="D"
adta(t1)=date()
case tt="T"
adta(t1)=dtot(date())
endcase
if tt<>"L"
@2,48 clear to 20,84
set color to +7/6
@2,48 clear to 20,84
@2,48 to 20,84
@3,58 say "请输入查询数据"
set color to +7/6,+6/4
if cmop(t1)<>"$"
@5,51 say name2(t1)+cmop(t1) get adta(t1)
else
adta(t1)=space(10)
do case
case tt="N".or.tt="Y"
@5,62 say "$str("+name2(t1)+",19,"+ltrim(str(fac(x1,4)))+")"
case tt="D"
@5,62 say "$dtoc("+name2(t1)+")"
case tt="T"
@5,62 say "$ttoc("+name2(t1)+")"
case tt="C"
@5,62 say "$"+name2(t1)
endcase
@5,51 get adta(t1)
endif
set cursor on
read
set cursor off
clear gets
endif
set color to +7/1,+6/4
clear
if cmop(t1)<>"$"
do case
case tt="N".or.tt="Y"
adta(t1)=name2(t1)+cmop(t1)+ltrim(str(adta(t1),19,fac(x1,4)))
case tt="D"
adta(t1)=name2(t1)+cmop(t1)+"ctod("+[']+dtoc(adta(t1))+[']+")"
case tt="T"
adta(t1)=name2(t1)+cmop(t1)+"ctot("+[']+ttoc(adta(t1))+[']+")"
case tt="C"
do case
case .not."'"$adta(t1)
adta(t1)='chrtranc('+trim(name2(t1))+",' ','')"+cmop(t1)+[']+chrtranc(adta(t1),' ','')+[']
case .not.'"'$adta(t1)
adta(t1)="chrtranc("+trim(name2(t1))+'," ","")'+cmop(t1)+["]+chrtranc(adta(t1)," ","")+["]
case (.not.'['$adta(t1)).and.(.not.']'$adta(t1))
adta(t1)=[chrtranc(]+trim(name2(t1))+',[ ],[])'+cmop(t1)+'['+chrtranc(adta(t1),[ ],[])+']'
otherwise
adta(t1)="chrtranc("+trim(name2(t1))+'," ","")'+cmop(t1)+["]+"'”[]不能同用"+["]
messagebox("'、”与[]共存,程序运行结果可能不正确.",0,"警告")
endcase
case tt="L"
adta(t1)=cmop(t1)+name2(t1)
endcase
else
do case
case tt="N".or.tt="Y"
adta(t1)=[']+trim(adta(t1))+[']+"$str("+name2(t1)+",19,"+ltrim(str(fac(x1,4)))+")"
case tt="D"
adta(t1)=[']+trim(adta(t1))+[']+"$dtoc("+name2(t1)+")"
case tt="T"
adta(t1)=[']+trim(adta(t1))+[']+"$ttoc("+name2(t1)+")"
case tt="C"
do case
case .not."'"$adta(t1)
adta(t1)=[']+chrtranc(adta(t1),' ','')+[']+"$chrtranc("+name2(t1)+",' ','')"
case .not.'"'$adta(t1)
adta(t1)=["]+chrtranc(adta(t1)," ","")+["]+'$chrtranc('+name2(t1)+'," ","")'
case (.not.'['$adta(t1)).and.(.not.']'$adta(t1))
adta(t1)="["+chrtranc(adta(t1),[ ],[])+"]"+"$chrtranc("+name2(t1)+",[ ],[])"
otherwise
adta(t1)=["]+"'”[]不能同用"+["]+'$chrtranc('+name2(t1)+'," ","")'
messagebox("'、”与[]共存,程序运行结果可能不正确.",0,"警告")
endcase
endcase
endif
dat=adta(t1)
set color to +7/1
clear
if upper(right(cxkm,10))<>"LSCFZK.DBF"
copy to lscfzk for &dat
use lscfzk
else
copy to lsbjpxk for &dat
use lsbjpxk
endif
wa="本次查询:"+dat+"("+ltrim(str(RECCOUNT()))+"条)"
wait wa window at 16,(120-len(wa))/2 nowait
brow
use lsbjczk
if upper(right(cxkm,10))<>"LSCFZK.DBF"
append from lscfzk
else
append from lsbjpxk
endif
replace all 轮次 with jhh for 轮次=0
use
use &cxkm
set color to +7/1,+6/4
clear
x3=messagebox("继续进行条件查询?",4+32+0,"数据查询")
do case
case x3=6
x3=1
case x3=7
x3=2
otherwise
clear
wait "程序发生错误,返回." window at 16,48 nowait
return
endcase
jhh=jhh+1
enddo
use lsbjczk
copy to lscfzk
use lscfzk
jgzdh=messagebox("历次查询结果存于LSCFZK.DBF库,进行后续数据处理?",4+32+256,"条件查询")
if jgzdh=6
brow
endif
use &cxkm
erase lsbjczk.dbf
erase lsbjczk.fpt
erase lsbjpxk.dbf
erase lsbjpxk.fpt
clear
*set exact off
set menus on
set color to +7/1
clear
use
return
搜索更多相关主题的帖子: 应用软件 运行环境 private escape safety 
2015-06-01 17:22
沙枣
Rank: 4
来 自:宁夏银川
等 级:业余侠客
威 望:5
帖 子:103
专家分:221
注 册:2015-5-31
收藏
得分:0 
回复 3楼 hu9jj
3楼好眼力,的确是从foxbase演变过来的,我也曾试过用VFP的表单等各种构件编制应用软件,但遗憾的是,VFP的接口和事件太多,不太容易理顺(VFP的程序要分散在多个控件的多个程序段运行),一个是不能实现我要求的复杂的综合性功能,一个是运行过程中出现各种各样的故障后,我无法把手“伸进去”修理(VFP控件好像暗箱子一样,里面的结构和运行机制无法搞清,现实中又确实会出现种种意想不到的问题),只能推倒重来,三是没有办法实现一程多用。之所以坚持手工的结构化编程,就是要实现一程多用(即用一个程序可以解决一类的问题,而不是一事一程),主攻方向是着力追求功能上的卓越,而舍弃界面上的美观。我现在编制的应用软件(上传的只是一个很小的片断),界面不好看,却可以处理所辖的全部管理业务,挂接了100多个数据库,每个数据库又可以附加若干个报表、打印程序等用于数据输出,可以在不同的管理业务间随意切换,工作效率很高。之所以到平台上来交流,是希望能在程序的功能上听到更好的改进和完善意见,借鉴高手的意见加深对程序的理解,望指教。
2015-06-02 17:28
沙枣
Rank: 4
来 自:宁夏银川
等 级:业余侠客
威 望:5
帖 子:103
专家分:221
注 册:2015-5-31
收藏
得分:0 
回复 10楼 hu9jj
谢谢您的意见,我做的每一个过程都可摘出来,作为一个独立的程序使用,也可以几个程序组在一起成为一个小的程序包,完成一定的功能,提供给朋友临时处理事务用,所有的过程组在一起就是一个软件,故此在每个过程(程序)的开头和结尾都写有set命令组,以求程序完整。一个软件中有很多个程序(过程),各个程序的能适应set命令组并不完全相同,在一处集中设置,有可能干扰某一过程的正确运行,在数千次的软件改良过程中,我好像碰到过,还是谢谢你。
2015-06-03 14:30
沙枣
Rank: 4
来 自:宁夏银川
等 级:业余侠客
威 望:5
帖 子:103
专家分:221
注 册:2015-5-31
收藏
得分:0 
回复 9楼 TonyDeng
我做的程序最主要的就是强调通用性,不管数据表有什么样的结构,也不管库结构经过什么样的变化和修改,只要数据表打开,就可以用这个程序进行单条件查询(还有其它的查询方式约十种),我不限定字段范围,列出所有的字段,让用户从中选择需要的字段进行查询,可以满足所有人的需要。限制字段范围,又会堕入专程专用的圈子,不是我追求的方向。如果要处理涉密的数据表,需要隐藏字段或给字段戴上“面具”,不让用户直观,不适合用这个程序。谢谢你
2015-06-03 14:39
沙枣
Rank: 4
来 自:宁夏银川
等 级:业余侠客
威 望:5
帖 子:103
专家分:221
注 册:2015-5-31
收藏
得分:0 
回复 13楼 wangzhiyi
这个程序“很短”了,不算长,结构也不复杂,但为了把它修理得服贴好用,能够适应各种种样的情况,经过了很多次实战和很多次修改,代码确定比最初设计时长了不少,但与其它的过程比起来,还是一个很简单的小程序。面向对象我确定用心尝试过,最主要的是不能实现我要的功能(好像不听我的指挥),不是面向对象编程的方式不好,要看干什么用,如果针对特定的绑定式事务,面向对象做好了也许会很好用。
2015-06-03 14:51
沙枣
Rank: 4
来 自:宁夏银川
等 级:业余侠客
威 望:5
帖 子:103
专家分:221
注 册:2015-5-31
收藏
得分:0 
回复 12楼 吹水佬
我习惯于将所有的程序行都顶齐的写法,不习惯于“缩进”的写法,那样要多打很多空格,好麻烦。顶齐的写法的确会给阅读程序带来不便,我平时修改程序的办法是将程序段打印出来,在每个if..endif,do...enddo等各种结构间划线连接,然后阅读修改,似乎比“缩进”的写法更直观,个人偏见,请指正。
2015-06-03 14:56
沙枣
Rank: 4
来 自:宁夏银川
等 级:业余侠客
威 望:5
帖 子:103
专家分:221
注 册:2015-5-31
收藏
得分:0 
回复 18楼 wangzhiyi
是一种好习惯,借鉴学习。
2015-06-04 09:52
沙枣
Rank: 4
来 自:宁夏银川
等 级:业余侠客
威 望:5
帖 子:103
专家分:221
注 册:2015-5-31
收藏
得分:0 
回复 23楼 taifu945
代码为王,功能为上,不管用什么,实现不了复杂的综合性功能,尤其是通用性的复合性功能,都是麻烦。
2015-07-13 17:43
沙枣
Rank: 4
来 自:宁夏银川
等 级:业余侠客
威 望:5
帖 子:103
专家分:221
注 册:2015-5-31
收藏
得分:0 
回复 25楼 sylknb
meti(ydlh)是数组,数组名meti你也可以自己定义,ydlh是数组元素的序号;prompt用于显示光带式菜单,是用传统的方法来构建菜单界面。

[ 本帖最后由 沙枣 于 2015-7-16 12:07 编辑 ]
2015-07-16 12:01
快速回复:一个通用的查询程序(试用)
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.023662 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved