网络编程 | 站长之家 | 网页制作 | 图形图象 | 操作系统 | 冲浪宝典 | 软件教学 | 网络办公 | 邮件系统 | 网络安全 | 认证考试 | 系统进程
Firefox | IE | Maxthon | 迅雷 | 电驴 | BitComet | FlashGet | QQ | QQ空间 | Vista | 输入法 | Ghost | Word | Excel | wps | Powerpoint
asp | .net | php | jsp | Sql | c# | Ajax | xml | Dreamweaver | FrontPages | Javascript | css | photoshop | fireworks | Flash | Cad | Discuz!
当前位置 > 网站建设学院 > 网络编程 > Delphi
Tag:注入,存储过程,分页,安全,优化,xmlhttp,fso,jmail,application,session,防盗链,stream,无组件,组件,md5,乱码,缓存,加密,验证码,算法,cookies,ubb,正则表达式,水印,索引,日志,压缩,base64,url重写,上传,控件,Web.config,JDBC,函数,内存,PDF,迁移,结构,破解,编译,配置,进程,分词,IIS,Apache,Tomcat,phpmyadmin,Gzip,触发器,socket
网络编程:ASP教程,ASP.NET教程,PHP教程,JSP教程,C#教程,数据库,XML教程,Ajax,Java,Perl,Shell,VB教程,Delphi,C/C++教程,软件工程,J2EE/J2ME,移动开发
本月文章推荐
.TStrings的AddObject方法应用.
.新世纪的五四运动:程序白话文(1).
.搜索字符串在流中的位置.
.Delphi字符串函数大全.
.中港台譯名對照表簡易語法版.
.在Delphi中实现StringTokenizer功.
.改造HINT的输出方式.
.如何在启动机器时自动运行adsl拨.
.数据表的二维表存储及定位.
.Delphi控件的使用经验.
.Delphi的拨号连接类.
.金额大写转换.
.利用Hook技术实现键盘监控.
.用Delphi5.0实现注册表监视.
.Delphi开发单机瘦数据库程序要点.
.用Timer实现定时运行.
.Delphi中MIDAS线程模型种类(MIDA.
.Delphi帮助里的虚拟键值表.
.一个实用的Delphi屏幕拷贝程序的.
.Delphi&BCB一线程序员开.

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

发表日期:2006-2-4


通用查询组件设计

作者: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;

上一篇:窗体的建立时机及缓冲的思想在ini文件中的应用.txt 人气:3947
下一篇:通用查询组件设计(续四) 人气:4069
浏览全部Delphi的内容 Dreamweaver插件下载 网页广告代码 祝你圣诞节快乐 2009年新年快乐