我有一个包含此列的网格:nrcrt,deadline,dateEnd,content。 截止日期和dateEnd列格式为“yyyy-MM-dd HH:mm:ss” 如果截止日期大于dateEnd且小于今天,我想将网格行颜色设置为红色。
thisform.grid1.SetAll("DynamicForeColor", "IIF(CTOD(SUBSTR(deadline , 1, 10)) >CTOD(SUBSTR(dateEnd , 1, 10)) and CTOD(SUBSTR(deadline , 1, 10)) <DATE() , 0, 255)")
但它不起作用。
答案 0 :(得分:0)
您缺少要应用它的网格元素,例如Columns。
thisform.grid1.SetAll("DynamicForeColor", "Iif(Ttod(Ctot(Stuff(deadline, 11, 1, "T"))) > Ttod(Ctot(Stuff(dateend, 11, 1, "T"))) and Ttod(Ctot(Stuff(deadline, 11, 1, "T"))) <DATE(), 0, 255)", "Column")
如果'截止日期'和'dateend'是表格中的字符类型,并且形式为“yyyy-MM-dd HH:mm:ss”,那么Stuff()命令将使“yyyy-MM- DD的Ť强> HH:MM:SS,”
然后可以使用Ttod()将该表单转换为日期。
将计算列添加到网格光标所基于的SELECT(可能没有直接将其绑定到表格中)可能会更容易,即
select ;
deadline, dateend, blah, ;
Iif(Ttod(Ctot(Stuff(deadline, 11, 1, "T"))) > Ttod(Ctot(Stuff(dateend,;
11, 1, "T"))) and Ttod(Ctot(Stuff(deadline, 11, 1, "T"))) <DATE(), 0,;
255) as forecolor ;
from mytable into cursor gridcursor
然后您的网格ForeColor只是:
thisform.grid1.SetAll("DynamicForeColor", "forecolor", "Column")
答案 1 :(得分:0)
您只需要在日期时间字符串值前加上'^',并将其转换为ttod(ctot())。
thisform.grid1.SetAll("DynamicForeColor", ;
"(IIF(ttod(ctot('^'+deadline)) > ttod(ctot('^' + dateEnd)) and ttod(ctot('^'+deadline)) < DATE(), 0, 255))")
您不需要指定第3个参数,因为DynamicForeColor只能应用于Column和衍生物。
答案 2 :(得分:0)
注意:你的表达对我来说没有意义,你应该修改你需要的东西:
Create Cursor SampleData (Id i Autoinc, deadline c(20), dateEnd c(20))
Insert Into SampleData (deadline, dateEnd) Values ('2016/02/29 11:30:00','')
Insert Into SampleData (deadline, dateEnd) Values ('2016/02/01 12:00:00','2016/01/30 12:00:00')
Insert Into SampleData (deadline, dateEnd) Values ('2016/02/01 12:00:00','2016/02/01 12:00:00')
Insert Into SampleData (deadline, dateEnd) Values ('2016/02/01 12:00:00','2016/02/02 12:00:00')
Insert Into SampleData (deadline, dateEnd) Values ('2016/02/20 12:00:00','2016/02/19 12:00:00')
Insert Into SampleData (deadline, dateEnd) Values ('2016/02/20 12:00:00','2016/02/20 12:00:00')
Insert Into SampleData (deadline, dateEnd) Values ('2016/02/20 12:00:00','2016/02/21 12:00:00')
Insert Into SampleData (deadline, dateEnd) Values ('2016/03/01 12:00:00','2016/02/29 12:00:00')
Insert Into SampleData (deadline, dateEnd) Values ('2016/03/01 12:00:00','2016/03/01 12:00:00')
Insert Into SampleData (deadline, dateEnd) Values ('2016/03/01 12:00:00','2016/03/02 12:00:00')
Locate
Public oForm
oForm = Createobject('SampleForm')
oForm.Show()
Define Class SampleForm As Form
Height=600
Width=800
Add Object myGrid As Grid With ;
RecordSource='SampleData', Height=600, Width=800, Anchor = 15
Procedure Init
This.myGrid.SetAll('DynamicForeColor', '(thisform.GetMeColor())')
Endproc
Procedure GetMeColor
Local deadline, dateEnd, lnColor
deadline = Ttod(Ctot('^'+SampleData.deadline))
dateEnd = Ttod(Ctot('^'+SampleData.dateEnd))
Do Case
Case m.deadline > m.dateEnd And m.deadline < Date()
lnColor=0
Case m.dateEnd > Date() And m.dateEnd < Date()+7
lnColor=Rgb(102,205,170)
Otherwise
lnColor=255
EndCase
Return m.lnColor
Endproc
Enddefine