修改 cxFilter 使之支持Oracle的日期型。
在DataControler 里有一份文件 cxFilter.pas,此文件定义了在 cxgrid 中进行 Filter 时的一些动作,此次正好我要用到,于是看了一下,发现其中的日期型有点问题。
在第863 行附近改成如下:
1
function TcxFilterOperator.GetExpressionValue(const AValue: Variant): string;
2
var
3
AVarType: Integer;
4
begin
5
if not PrepareExpressionValue(AValue, Result) then
6
begin
7
AVarType := VarType(AValue);
8
if (AVarType = varString) or (AVarType = varOleStr) then // <- VarTypeIsStr()
9
Result := QuotedStr(VarToStr(AValue))
10
else
11
if AVarType = varDate then
12
begin
13
// DateTimeFormat:='YYYY-MM-DD'; //临时定义日期格式
14
Result:=' TO_DATE('+QuotedStr( CriteriaItem.Criteria.ConvertDateToStr(
15
AValue))+','+Quotedstr('YYYY-MM-DD')+')';
16
end
17
// 原来的日期没有加 to_date ,Oracle 不认。
18
// Result := '''' + CriteriaItem.Criteria.ConvertDateToStr(AValue) + ''''
19
else
20
if AVarType = varBoolean then
21
Result := CriteriaItem.Criteria.ConvertBoolToStr(AValue)
22
else
23
if AVarType = varNull then
24
Result := 'NULL'
25
else
26
Result := VarToStr(AValue);
27
CriteriaItem.Criteria.FormatFilterTextValue(CriteriaItem, AValue, Result);
28
end;
29
end;
function TcxFilterOperator.GetExpressionValue(const AValue: Variant): string;2
var3
AVarType: Integer;4
begin5
if not PrepareExpressionValue(AValue, Result) then6
begin7
AVarType := VarType(AValue);8
if (AVarType = varString) or (AVarType = varOleStr) then // <- VarTypeIsStr()9
Result := QuotedStr(VarToStr(AValue))10
else11
if AVarType = varDate then12
begin13
// DateTimeFormat:='YYYY-MM-DD'; //临时定义日期格式14
Result:=' TO_DATE('+QuotedStr( CriteriaItem.Criteria.ConvertDateToStr(15
AValue))+','+Quotedstr('YYYY-MM-DD')+')';16
end17
// 原来的日期没有加 to_date ,Oracle 不认。18
// Result := '''' + CriteriaItem.Criteria.ConvertDateToStr(AValue) + ''''19
else20
if AVarType = varBoolean then21
Result := CriteriaItem.Criteria.ConvertBoolToStr(AValue)22
else23
if AVarType = varNull then24
Result := 'NULL'25
else26
Result := VarToStr(AValue);27
CriteriaItem.Criteria.FormatFilterTextValue(CriteriaItem, AValue, Result);28
end;29
end;
于是,这个世界清静了,不过,这个日期定义太死了,没有时间。而实际上在使用时我一般都不带时间的,所以总觉得不完美,应该在外面定义的时候把这个 format 定义出来,这样比较好。
还有一处,cxFilter 在处理 为空和不为空的时候出现这种 = NULL 和 <> NULL ,而Oracle是不接受这种的,要改成 Is NULL 和 Is Not Null 。
浙公网安备 33010602011771号