分享
 
 
 

通用查询组件设计(续三)

王朝delphi·作者佚名  2006-01-09
窄屏简体版  字體: |||超大  

通用查询组件设计

作者:nxyc_twz@163.com

前段时间由于工作较忙,无暇整理本组件的相关文档,请大家谅解!以后我会陆续整理公布该组件的所有相关文档及源码!

procedure TMyFieldInfo.SetVariables(d: TDataset);

var

value : String;

begin

//设置变量值

if AnsiUpperCase(FilterValue) = 'NULL' then //如果FilterValue为空,则退出

exit;

if FieldType = ftString then //如果字段类型为字符串型,则

begin

if CaseSensitive then //如果大小写敏感

case MatchType of //匹配类型

fdMatchStart, fdMatchAny : //起始部分匹配或任意位置匹配

value := FilterValue;

fdMatchEnd : //结束部分匹配

value := '%' + FilterValue;

fdMatchExact : //非匹配记录

value := FilterValue;

end

else //大小写不敏感

case MatchType of

fdMatchStart, fdMatchAny : //起始部分匹配或任意位置匹配

value := AnsiUpperCase(FilterValue);

fdMatchEnd : //结束部分匹配

value := '%' + AnsiUpperCase(FilterValue); {do not localize}

fdMatchExact : //非匹配记录

value := AnsiUpperCase(FilterValue);

end;

end

else//字段类型为非字符串型

value := FilterValue;

if MatchType <> fdMatchRange then//如果匹配类型不为按范围

TQuery(d).ParamByName(FieldName + 'Filter').Value := value

else //否则

begin

if CaseSensitive then //如果大小写敏感

begin

if StartingValue <> '' then //如果起始范围值不为空

TQuery(d).ParamByName(FieldName + 'Start').Value := StartingValue;

if EndingValue <> '' then //如果结束范围不为空

TQuery(d).ParamByName(FieldName + 'End').Value := EndingValue;

end

else //大小写敏感

begin

if StartingValue <> '' then //如果起始范围值不为空

TQuery(d).ParamByName(FieldName + 'Start').Value := AnsiUpperCase(StartingValue);

if EndingValue <> '' then //如果结束范围值不为空

TQuery(d).ParamByName(FieldName + 'End').Value := AnsiUpperCase(EndingValue);

end;

end;

end

end;

字段定义类

TMyFieldInfo = class //字段类

public

FieldName : String; //字段名

FieldOrigin : String;

FieldType : TFieldType; //字段类型

DisplayLabel : String; //显示的名称

MatchType : TDBFilterMatchType; //匹配类型

FilterValue : String; //过滤值

StartingValue : String; //开始值

EndingValue : String; //结束值

CaseSensitive : boolean; //是否大小写敏感

NonMatching : boolean; //不匹配

procedure Assign(o : TMyFieldInfo); //指定字段定义

function CreateSQL : String; //创建SQL语句

procedure SetVariables( d : TDataset); //设置字段变量

end;

指定字段定义

procedure TMyFieldInfo.Assign(o : TMyFieldInfo);

begin

//指定字段信息

FieldName := o.FieldName;

FieldOrigin := o.FieldOrigin;

FieldType := o.FieldType;

DisplayLabel := o.DisplayLabel;

MatchType := o.MatchType;

FilterValue := o.FilterValue;

StartingValue := o.StartingValue;

EndingValue := o.EndingValue;

CaseSensitive := o.CaseSensitive;

NonMatching := o.NonMatching;

end;

创建SQL语句

function TMyFieldInfo.CreateSQL: String;

var

Field : String;

begin

//创建SQL语句

if FieldOrigin <> '' then

Field := FieldOrigin

else

Field := FieldName;

if NonMatching then

Result := ' not ( '

else

Result := ' ( ';

if AnsiUpperCase(FilterValue) = 'NULL' then

begin

Result := Result + Format('%s is NULL) ', [Field]);

exit;

end;

if FieldType = ftString then

begin

if CaseSensitive then

case MatchType of

fdMatchStart:

Result := Result + Format('%0:s starting with :%1:sFilter ) ', [Field, FieldName]);

fdMatchAny:

Result := Result + Format('%0:s containing :%1:sFilter ) ', [Field, FieldName]);

fdMatchEnd :

Result := Result + Format('%0:s = :%1:sFilter ) ', [Field, FieldName]);

fdMatchExact :

Result := Result + Format('%0:s = :%1:sFilter ) ', [Field, FieldName]);

fdMatchRange :

begin

if StartingValue <> '' then

Result := Result + Format('%0:s >= :%1:sStart)', [Field, FieldName]);

if (StartingValue <> '') and (EndingValue <> '') then

Result := Result + ' and (';

if EndingValue <> '' then

Result := Result + Format('%0:s <= :%1:sEnd)', [Field, FieldName]);

end;

end

else

case MatchType of

fdMatchStart:

Result := Result + Format('UPPER(%0:s) starting with :%1:sFilter ) ', [Field, FieldName]); {do not localize}

fdMatchAny:

Result := Result + Format('UPPER(%0:s) containing :%1:sFilter ) ', [Field, FieldName]); {do not localize}

fdMatchEnd :

Result := Result + Format('UPPER(%0:s) like :%1:sFilter ) ', [Field, FieldName]); {do not localize}

fdMatchExact :

Result := Result + Format('UPPER(%0:s) = :%1:sFilter ) ', [Field, FieldName]); {do not localize}

fdMatchRange :

begin

if FieldType = ftString then

begin

if StartingValue <> '' then

Result := Result + Format('UPPER(%0:s) >= :%1:sStart)', [Field, FieldName]); {do not localize}

if (StartingValue <> '') and (EndingValue <> '') then

Result := Result + ' and ('; {do not localize}

if EndingValue <> '' then

Result := Result + Format('UPPER(%0:s) <= :%1:sEnd)', [Field, FieldName]); {do not localize}

end

else

begin

if StartingValue <> '' then

Result := Result + Format('%0:s >= :%1:sStart)', [Field, FieldName]); {do not localize}

if (StartingValue <> '') and (EndingValue <> '') then

Result := Result + ' and ('; {do not localize}

if EndingValue <> '' then

Result := Result + Format('%0:s <= :%1:sEnd)', [Field, FieldName]); {do not localize}

end

end;

end;

end

else

case MatchType of

fdMatchRange :

begin

if StartingValue <> '' then

Result := Result + Format('%0:s >= :%1:sStart)', [Field, FieldName]); {do not localize}

if (StartingValue <> '') and (EndingValue <> '') then

Result := Result + ' and ('; {do not localize}

if EndingValue <> '' then

Result := Result + Format('%0:s <= :%1:sEnd)', [Field, FieldName]); {do not localize}

end;

else

Result := Result + Format('%0:s = :%1:sFilter ) ', [Field, FieldName]); {do not localize}

end;

end;

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
2023年上半年GDP全球前十五强
 百态   2023-10-24
美众议院议长启动对拜登的弹劾调查
 百态   2023-09-13
上海、济南、武汉等多地出现不明坠落物
 探索   2023-09-06
印度或要将国名改为“巴拉特”
 百态   2023-09-06
男子为女友送行,买票不登机被捕
 百态   2023-08-20
手机地震预警功能怎么开?
 干货   2023-08-06
女子4年卖2套房花700多万做美容:不但没变美脸,面部还出现变形
 百态   2023-08-04
住户一楼被水淹 还冲来8头猪
 百态   2023-07-31
女子体内爬出大量瓜子状活虫
 百态   2023-07-25
地球连续35年收到神秘规律性信号,网友:不要回答!
 探索   2023-07-21
全球镓价格本周大涨27%
 探索   2023-07-09
钱都流向了那些不缺钱的人,苦都留给了能吃苦的人
 探索   2023-07-02
倩女手游刀客魅者强控制(强混乱强眩晕强睡眠)和对应控制抗性的关系
 百态   2020-08-20
美国5月9日最新疫情:美国确诊人数突破131万
 百态   2020-05-09
荷兰政府宣布将集体辞职
 干货   2020-04-30
倩女幽魂手游师徒任务情义春秋猜成语答案逍遥观:鹏程万里
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案神机营:射石饮羽
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案昆仑山:拔刀相助
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案天工阁:鬼斧神工
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案丝路古道:单枪匹马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:与虎谋皮
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:李代桃僵
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:指鹿为马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:小鸟依人
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:千金买邻
 干货   2019-11-12
 
推荐阅读
 
 
 
>>返回首頁<<
 
靜靜地坐在廢墟上,四周的荒凉一望無際,忽然覺得,淒涼也很美
© 2005- 王朝網路 版權所有