⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 uinfoquery.pas

📁 Delphi实战演练一书的配套光盘
💻 PAS
字号:
unit UInfoQuery;

interface

uses
  Windows, Messages, SysUtils, Classes, HTTPApp, Db, DBTables, DBWeb;

type
  TQiCheWebModule = class(TWebModule)
    QiCheRoot: TPageProducer;
    QiCheQuery: TQuery;
    QiCheDetailQuery: TQuery;
    ChaXuncsT: TTable;
    procedure QiCheWebModuleInfoQueryAction(Sender: TObject;
      Request: TWebRequest; Response: TWebResponse; var Handled: Boolean);
    procedure QiCheWebModuledetailqueryAction(Sender: TObject;
      Request: TWebRequest; Response: TWebResponse; var Handled: Boolean);
    procedure QiCheWebModuleRootAction(Sender: TObject;
      Request: TWebRequest; Response: TWebResponse; var Handled: Boolean);
    private
    { Private declarations }
//    ScriptName: String;
    public
    { Public declarations }
    end;

var
  QiCheWebModule: TQiCheWebModule;

implementation

{$R *.DFM}

procedure TQiCheWebModule.QiCheWebModuleRootAction(Sender: TObject;
  Request: TWebRequest; Response: TWebResponse; var Handled: Boolean);
begin
 response.content:=QiCheRoot.content;
end;

procedure TQiCheWebModule.QiCheWebModuleInfoQueryAction(Sender: TObject;
  Request: TWebRequest; Response: TWebResponse; var Handled: Boolean);
  var
  i:integer;
  CaptionStr,colstr1,colstr2,colstr3:string;
  begin
    i:=0;
    //由于Delphi的Case语句不支持字符类型的分支,所以需将客户请求
    //转换成相应的序数值
    if Request.query='QIC' THEN  i:=0;
    if Request.query='Qjx' THEN  i:=1;
    if Request.query='Qmr' THEN  i:=2;
    if Request.query='Qwx' THEN  i:=3;
    if Request.query='Jyz' THEN  i:=4;
    if Request.query='Qzl' THEN  i:=5;
    if Request.query='Qsc' THEN  i:=6;
    //为了减少程序的壅余、精炼程序,对与汽车有关的所有查询都采用同一个查询组件
    //,实现动态查询和动态生成响应客户请求的HTML表格
    QiCheQuery.close;
    //关闭当前查询
    QiCheQuery.sql.clear;
    //清除当前查询的SQL语句
    ChaXuncsT.open;
    //打开记载访问次数的表
    ChaXuncsT.edit;
    //设置访问次数的表为编辑状态
    case i of
      0:begin
        //修改汽车的访问次数(客户每访问一次,访问次数加1)
        ChaXuncsT.fields[3].value:=ChaXuncsT.fields[3].value+1;
//        Footstr:='您是第'+IntToStr(ChaXuncsT.fields[3].value)+'个来访者.';
        //根据客户请求参数转换的序号生成响应的SQL语句和HTML表的显示标题
        CaptionStr:='  二手汽车';
        QiCheQuery.sql.add('select * from QiChe where 编号 like '''+'QIC%''');
        colstr1:='品牌';
        colstr2:='型号';
        colstr3:='车辆类型';
        end;
      1:begin
        ChaXuncsT.fields[4].value:=ChaXuncsT.fields[4].value+1;
//        Footstr:='您是第'+IntToStr(ChaXuncsT.fields[4].value)+'个来访者.';
        CaptionStr:='    汽车驾校';
        QiCheQuery.sql.add('select * from QiChejx where 编号 like '''+'Qjx%''');
        colstr1:='名称';
        colstr2:='地址';
        colstr3:='交通';
        end;
      2:begin
        ChaXuncsT.fields[5].value:=ChaXuncsT.fields[5].value+1;
//        Footstr:='您是第'+IntToStr(ChaXuncsT.fields[5].value)+'个来访者.';
        CaptionStr:='    汽车美容';
        QiCheQuery.sql.add('select * from QiChemr where 编号 like '''+'Qmr%''');
        colstr1:='名称';
        colstr2:='保养项目';
        colstr3:='地址';
        end;
      3:begin
        ChaXuncsT.fields[6].value:=ChaXuncsT.fields[6].value+1;
//        Footstr:='您是第'+IntToStr(ChaXuncsT.fields[6].value)+'个来访者.';
        CaptionStr:='    汽车维修';
        QiCheQuery.sql.add('select * from QiChewx where 编号 like '''+'Qwx%''');
        colstr1:='名称';
        colstr2:='维修类型';
        colstr3:='服务时间';
        end;
      4:begin
        ChaXuncsT.fields[7].value:=ChaXuncsT.fields[7].value+1;
//        Footstr:='您是第'+IntToStr(ChaXuncsT.fields[7].value)+'个来访者.';
        CaptionStr:='    汽车加油站';
        QiCheQuery.sql.add('select * from Jiayouz where 编号 like '''+'Jyz%''');
        colstr1:='名称';
        colstr2:='品种';
        colstr3:='服务时间';
        end;
      5:begin
        ChaXuncsT.fields[8].value:=ChaXuncsT.fields[8].value+1;
//        Footstr:='您是第'+IntToStr(ChaXuncsT.fields[8].value)+'个来访者.';
        CaptionStr:='    汽车租赁';
        QiCheQuery.sql.add('select * from QiChezl where 编号 like '''+'Qzl%''');
        colstr1:='名称';
        colstr2:='服务项目';
        colstr3:='服务时间';
        end;
      6:begin
        ChaXuncsT.fields[9].value:=ChaXuncsT.fields[9].value+1;
//        Footstr:='您是第'+IntToStr(ChaXuncsT.fields[9].value)+'个来访者.';
        CaptionStr:='    汽车市场';
        QiCheQuery.sql.add('select * from QiChesc where 编号 like '''+'Qsc%''');
        colstr1:='名称';
        colstr2:='服务项目';
        colstr3:='地址';
        end;
    end;
    ChaXuncsT.post;
    ChaXuncsT.close;
    QiCheQuery.open;
    //打开动态查询
    QiCheQuery.First;
    //形成HTML表的标题和表头信息,在该表中有四列信息,前三列为基本信息,第四列用于
    //形成完成显示详细信息而必须的超级链接和条件,此处的条件是完成查询当前记录的
    //信息后部分
    Response.content:='<HTML><HEAD><TITLE>汽车信息</TITLE></HEAD><BODY>'#13+
      '<H1>'+CaptionStr+'</H1>'#13+'<table border>'#13;
    Response.content:=Response.content+'<TR BgColor="White"><TH>'+
          colstr1+'</TH><TH>'+colstr2+'</TH><TH>'+colstr3+
          '</TH><TH>其它</TH></TR>';
    while not QiCheQuery.EOF do
    //当表的记录指针不在末尾时,获取当前表的所有前三个字段
    begin
      Response.content:=Response.content+Format(
      '<tr><td>%s</td><td>%s</td><td>%s</td><td><a HREF="%S/rundetail?%s">%s</a></td></tr>'#13,
      [QiCheQuery.fields[1].AsString,QiCheQuery.fields[2].AsString,QiCheQuery.fields[3].AsString,Request.ScriptName,QiCheQuery.fields[0].AsString,'更多信息见...']);
      //获取下一个记录
      QiCheQuery.Next;
    end;
//    Response.content:=Response.content+'<TFOOT><TR>'+Footstr+'</TR></table></BODY></HTML>'#13;
    Response.content:=Response.content+'</table></BODY></HTML>'#13;
    //最终完成响应客户请求的HTML表格

  end;

procedure TQiCheWebModule.QiCheWebModuledetailqueryAction(Sender: TObject;
  Request: TWebRequest; Response: TWebResponse; var Handled: Boolean);
  var
    i:integer;
//  F1:TextFile;
    CaptionStr:string;
  begin
{   AssignFile(F1,'C:\String1.txt');
    Rewrite(F1);
    str1:=Request.Query;
    Write(F1,Str1);
    CloseFile(F1);
}
    i:=0;
    //IF语句根据客户请求参数判别下一步应执行的查询。
    if pos('QIC',Request.query)>0 THEN  i:=0;
    if pos('Qjx',Request.query)>0 THEN  i:=1;
    if pos('Qmr',Request.query)>0 THEN  i:=2;
    if pos('Qwx',Request.query)>0 THEN  i:=3;
    if pos('Jyz',Request.query)>0 THEN  i:=4;
    if pos('Qzl',Request.query)>0 THEN  i:=5;
    if pos('Qsc',Request.query)>0 THEN  i:=6;
    QiCheDetailQuery.close;
    //关闭当前的查询
    QiCheDetailQuery.SQL.clear;
    //清除当前查询的SQL语句
    case i of
      0:begin
        //根据客户请求的参数,产生相应的查询语句和显示标题
        CaptionStr:='   二手汽车';
        QiCheDetailQuery.sql.add('select * from QiChe where 编号='''+Request.Query+'''');
        end;
      1:begin
        CaptionStr:='          汽车驾校';
        QiCheDetailQuery.sql.add('select * from QiChejx where 编号='''+Request.Query+'''');
        end;
      2:begin
        CaptionStr:='         汽车美容';
        QiCheDetailQuery.sql.add('select * from QiChemr where 编号='''+Request.Query+'''');
        end;
      3:begin
        CaptionStr:='     汽车维修';
        QiCheDetailQuery.sql.add('select * from QiChewx where 编号='''+Request.Query+'''');
        end;
      4:begin
        CaptionStr:='     汽车加油站';
        QiCheDetailQuery.sql.add('select * from Jiayouz where 编号='''+Request.Query+'''');
        end;
      5:begin
        CaptionStr:='          汽车租赁';
        QiCheDetailQuery.sql.add('select * from QiChezl where 编号='''+Request.Query+'''');
        end;
      6:begin
        CaptionStr:='         汽车市场';
        QiCheDetailQuery.sql.add('select * from QiChesc where 编号='''+Request.Query+'''');
        end;
    end;
    QiCheDetailQuery.open;
    response.content:=
        '<html><body><head<title>'+CaptionStr+'</title></head>'#13+
        '<table border><center>'#13;
    //信息分成两屏显示,在第一屏中显示三个字段内容,而第二屏是从第四个字段开始显示.
    //表格显示形式为字段名和字段值,每个字段显示一行,
    //用字段的总数(QiCheDetailQuery.fieldcount)控制循环次数
    for i:=1 to QiCheDetailQuery.fieldcount-3 do
      response.content:=response.content+
        '<tr><td>'+QiCheDetailQuery.fields[i].fieldname+'</td>'#13+'<td>'+
        QiCheDetailQuery.fields[i].asstring+'</td></tr>'#13;
    response.content:=response.content+
         '</center></table><hr>'#13+'</body></html>'#13;
   //最终完成响应客户请求的HTML表格
   End;

end.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -