主题:关于日期选择问题.求助!
cf222222
[专家分:30] 发布于 2006-08-29 21:13:00
各位高手,我又来了.我想请教一个问题:我生成了一个数据表,表中有一个字段是"登记日期"(日期型),现在程序中有一个要求,要在表单中的Grid1中显示今天登记的,前三天登记的,前一周内登记的记录.如何实现呢.数据过滤时如何设置条件啊.请高手解答.
回复列表 (共24个回复)
11 楼
cf222222 [专家分:30] 发布于 2006-08-30 13:57:00
我无法实现,所以在此求救.又不能发图.真急人.高手有联系方法吗/
12 楼
zyh199102 [专家分:0] 发布于 2006-08-30 15:42:00
你可以根据条件生成一个临时表,再用该临时表作为表格的数据源就可以了
13 楼
cf222222 [专家分:30] 发布于 2006-08-30 19:15:00
我的表单是这样设计的,有一个容器中放一个Optiongroup1,其中有四个按钮.分别是"今天入住","三天内入住","一周内入住"和"所有入住者".下面放有一个grid1,表单的数据环境中有数据表,我希望点击"今天入住"时,数据表中登记日期为今天的就显示在grid1中,其他按钮同理.怎样可以实现啊.我希望高手能出现给点实质性的意见.
生成临时表啊,使用select语句之类的我也懂一些,只是不知道怎么实现啊.
14 楼
0901chang [专家分:10660] 发布于 2006-08-30 20:36:00
我也不会用select语句,我用最笨的方法
copy to 临时表 for 条件
然后在表单的 init 中书写需要的指令,在grid1中显示和编辑你需要的字段,请你参考:
s0_屏高度=sysmetric(2)
s0_屏宽度=sysmetric(1)
thisform.grid1.RecordSource="临时表"
with thisform.grid1.Column1
.Header1.Caption="序号"
if s0_屏宽度>=1024.and.s0_屏高度>=768
.Width=48
else
.Width=42
endi
.ControlSource="临时表.序号"
endwith
with thisform.grid1.Column2
.Header1.Caption="姓名"
if s0_屏宽度>=1024.and.s0_屏高度>=768
.Width=78
else
.Width=68
endi
.ControlSource="临时表.姓名"
.ReadOnly=.t.
endwith
...
...
thisform.grid1.column1.setfocus
thisform.refresh
15 楼
cf222222 [专家分:30] 发布于 2006-08-30 23:03:00
多谢各位的回贴,除了14楼的我不知道该怎么测试之外,其余的我都进行了测试,没有办法达到目的,我对表单进行了改进了.勉强通过了.是这样做的.
还是定义一个Optiongroup1,里面有四个选项,分别是今天登记,三天内登记,一周内登记,所有登记者.下面用一个list1来显示过滤后的数据,代码如下:
在表单form1的init中写代码:
if !used("情况表")
use 情况表
endif
select 情况表
select * from database!情况表 where 日期=date() into cursor temp_gg
thisform.list1.rowsource="temp_gg.姓名,编号"
thisform.list1.rowsourcetype=6
thisform.list1.click
在option1.gotfocus中写入如下代码:
for i=1 to thisform.list1.listcount
thisform.list1.removeitem(i)
endfor
select 情况表
select * from database!情况表 where 日期=date() into cursor temp_gg
thisform.list1.rowsource="temp_gg.姓名,编号"
thisform.list1.rowsourcetype=6
thisform.list1.listindex=1
thisform.list1.click
在option2.gotfocus中写入如下代码:
for i=1 to thisform.list1.listcount
thisform.list1.removeitem(i)
endfor
select 情况表
select * from database!情况表 where 日期>date()-3 into cursor temp_gg
thisform.list1.rowsource="temp_gg.姓名,编号"
thisform.list1.rowsourcetype=6
thisform.list1.listindex=1
thisform.list1.click
在option3.gotfocus中写入如下代码:
for i=1 to thisform.list1.listcount
thisform.list1.removeitem(i)
endfor
select 情况表
select * from database!情况表 where 日期>date()-7 into cursor temp_gg
thisform.list1.rowsource="temp_gg.姓名,编号"
thisform.list1.rowsourcetype=6
thisform.list1.listindex=1
thisform.list1.click
在option4.gotfocus中写入如下代码:
for i=1 to thisform.list1.listcount
thisform.list1.removeitem(i)
endfor
select 情况表
select * from database!情况表 where .t. into cursor temp_gg
thisform.list1.rowsource="temp_gg.姓名,编号"
thisform.list1.rowsourcetype=6
thisform.list1.listindex=1
thisform.list1.click
在list1.click写如下代码:
select * from 情况表 where 病人姓名=alltrim(thisform.list1.value) into;
cursor 临时表
thisform.text1.value=alltrim(临时表.编号)
thisform.text2.value=alltrim(临时表.姓名)
thisform.text3.value=alltrim(临时表.科别)
thisform.text4.value=alltrim(临时表.医师)
现在写在这里,希望起到引玉的作用.希望能够有高手提供更好的处理方法.
谢谢大家的回复与帮助.
16 楼
fyyylyl [专家分:8550] 发布于 2006-08-31 08:33:00
Thisform.OptionGroup1.Click:
Select 表
Do Case
Case This.Value=1
Set Filter To 登记日期=date()
Case This.Value=2
Set Filter To 登记日期>date()-3
Case This.Value=3
Set Filter To 登记日期>date()-7
Case This.Value=4
Set Filter To
EndCase
Go top
Thisform.Grid1.Refresh
足矣!
17 楼
cf222222 [专家分:30] 发布于 2006-08-31 13:11:00
不知16楼的高手是否自己测试过,反正我反复测试没有成功.(我的系统XP sp2版+vfp6.0),有些问题看似简单,其实完全不是我们想象的那么简单,如果没有亲自试验,就发现不了问题的所在.
18 楼
xingfuwuyu123 [专家分:310] 发布于 2006-08-31 15:28:00
把GRID控件设置数据源为表,然后用3楼的方法,最后加一句:
thisform.grid1.refresh
19 楼
cf222222 [专家分:30] 发布于 2006-08-31 20:52:00
18楼老兄,我前面已经说过了.这方法我已经试过了.没有成功.
20 楼
fyyylyl [专家分:8550] 发布于 2006-08-31 23:17:00
如有狐友愿意,帮LZ测试一下16楼的代码!
我来回复