HEBERGEMENT SITES INTERNET
CGI, ISAPI, ASP, Dot NET,
PHP & MySql,
DELPHI - Firebird & INTERBASE
 


Le but de ce didactitiel est de vous faire découvrir pas à pas, la construction d'une application pour le web avec Delphi 5/6. Il ne sera pas question ici, de faire le tour des technologies et possibilités offertes par la dernière version de l'outil de programmation, mais simplement de vous donner la marche à suivre pour créer une application portable.

 

unit uCaddyIsapi;
(*-------------------------------------------------------------------
  Le but de cet exemple est de démontrer la simplicité du développement
  pour le web avec Delphi.

  - Vos objets Delphi sont écrit comme pour une application classique
  - Il suffit ensuite d'écrire les interfaces ISAPI / CGI ou Objet Com ASP
    pour les utiliser sur le web.

    Cette méthode présente également l'avantage de pouvoir tester vos objets
    sans avoir recours à un serveur web et à séparer les problèmes éventuels
    liés à chaques parties (L'objet Delphi, La DLL Isapi, ect)

    TCaddyISAPI
    -----------
       Hiérarchie :       TBaseObject       (Objet commun ISAPI / ASP)
			       |
			  TCustomISAPI      (Objet Commun aux ISAPIs)
			       |
			  TCaddyISAPI       (encapsule TCaddydbText)

     Cet objet ne fait pas grand chose d'autre que de proposer une
     interface ISAPI pour l'objet TCaddydbText (commun à toutes les technos
     Progamme Windows, ISAPI, ASP)

   ATTENTION
   --------
     Ne pas utiliser la version fichiers textes du caddy en production.
     Vous devez développer une version base de données ou consulter le site
     web www.delphiCenter.net pour voir si il existe d'autres versions

  Version 1.0, copyrigth www.delphiCenter.net Mai 2001
Auteur : JJM Email de l'auteur : jjm@delphiCenter.net ------------------------------------------------------------------*) interface Uses Windows, Messages, SysUtils, Classes, uCustomIsapi, uCustomCaddy, uConstCaddy, isapiapp, HTTPApp; Type TCaddyISAPI = Class(TCustomIsapi) fRef : String; fDesc : String; fidArt: Integer; fQte : Integer; fPuht : Integer; fCodeTaxe : Integer; fIdCom : Integer; fIdCust : String; fDate : TDateTime; fNextUrl : String; fBackUrl : String; fPostUrl : String; fReportPageHtm : String; fReportLineHtm : String; fReportTaxeHtm : String; fCaddy : TCustomCaddyLines; Procedure InitReportHtm; Procedure SpareParams; Procedure SetNextUrl; Public Constructor Create(aRequest : TWebRequest); Override; Destructor Destroy; Override; function SetItems : Boolean; function SetQuantity : Boolean; Function ShowReport : String; // proposition de l'objet Caddy Property Caddy : TCustomCaddyLines Read fCaddy; // Proposition des paramètres de la requete web Property isapiRef : String Read fRef; Property isapiDesc : String Read fDesc; Property isapiidArt: Integer Read fIDArt; Property isapiQte : Integer Read fQte; Property isapiPuht : Integer Read fPuHt; Property isapiCodeTaxe : Integer Read fCodeTaxe; Property isapiIdCom : Integer Read fIDCom; Property isapidDate : TDateTime Read fdate; Property isapiNextUrl : String Read fNextUrl; // Proposition des modèles (templates) Property ReportPageHtm : String Read fReportPageHtm; Property ReportLineHtm : String read fReportLineHtm; Property ReportTaxeHtm : String read fReportTaxeHtm; End; implementation Uses IniFiles; { TCaddyISAPI } constructor TCaddyISAPI.Create(aRequest: TWebRequest); begin inherited; fCaddy := TCaddydbText.Create; fCaddy.fRepData:=SetFilePath(''); // force le rep Datas SpareParams; // Recupération des paramètres de la requÊte end; destructor TCaddyISAPI.Destroy; begin inherited; fCaddy.Free; end; procedure TCaddyISAPI.SpareParams; begin With RequestContent do begin fidArt:=SetStrValueToInt(Values['IDART'],0); fRef:=Values['REF']; fDesc:=Values['DESC']; fQte:=SetStrValueToInt(Values['QTE'],0); fpuHt:=Trunc(SetStrValueToDouble(Values['PUHT'],0)*100); // prix en centimes. fCodeTaxe:=SetStrValueToInt(Values['CODETAXE'],0); fIDCom:=SetStrValueToInt(Values['IDCom'],-1); if fIdCom<>-1 then fCaddy.idCom:=fIdCom; fIDCust:=Values['IDCust']; fDate:=SetStrValueToDate(Values['DATE'],Date); fNextUrl:=VerifUrl(Values['NEXTURL']); fBackUrl:=VerifUrl(Values['BACKURL']); fPostUrl:=VerifUrl(Values['POSTURL']); end; end; procedure TCaddyISAPI.InitReportHtm; Var MyIni : TIniFile; begin MyIni:=TInifile.create(IniFileName); try With MyIni do begin // Chargement des templates fReportPageHtm:=LoadTxtFile(SetFilePath(ReadString('REPORTS','ReportPage',''))); fReportLineHtm:=LoadTxtFile(SetFilePath(ReadString('REPORTS','ReportLine',''))); fReportTaxeHtm:=LoadTxtFile(SetFilePath(ReadString('REPORTS','ReportTaxe',''))); end; finally Myini.free; end; end; function TCaddyISAPI.ShowReport : String; Var I,R : Integer; slLines : TSTringList; thisLine : String; thisPage : String; TotalHt : Double; TotalTTC : Double; begin // Affichage du contenu du caddy Try Result:=''; With fCaddy do begin // IDCom:=fIDCom; // Gestion du numéro de commande InitReportHtm; // Lecture des fichiers "templates" thisPage:=fReportPageHtm; slLines := TSTringList.Create; Try // Récupération des lignes du caddy (lignes de commande) For i:=0 to fCaddy.Count-1 do Begin thisLine:=fReportLineHtm; // template ligne ReplaceTag(thisLine,tagIDArt,IntToStr(GetidArt(i))); ReplaceTag(thisLine,tagRef,GetRef(i)); ReplaceTag(thisLine,tagDesc,GetDesc(i)); ReplaceTag(thisLine,tagPuHt,FloatToStrF(GetPuHt(i)/100,ffCurrency,7,2)); ReplaceTag(thisLine,tagQte,IntToStr(GetQte(i))); ReplaceTag(ThisLine,tagTaxe,
FloatToStrF(GetTxTaxe(GetCodeTaxe(i)),ffNumber,4,2)+'%'); ReplaceTag(thisLine,tagtotalNT,
FloatToStrF((GetQte(i)*GetPuHt(i))/100,ffCurrency,8,2)); slLines.add(ThisLine); end; if slLines.Count<=0 then slLines.Text:='<B>Pas d''articles en commande</B>'; ReplaceTag(thisPage,tagComLines,slLines.text); // Affichage des différents montants en fonction des taxes slLines.clear; For i:=cMinTaxe to cMaxTaxe do begin R:=Caddy.GetTotalTaxesByCode(i); if R>0 then begin ThisLine:=fReportTaxeHtm; ReplaceTag(ThisLine,tagTaxe,FloatToStrF(GetTxTaxe(i),ffNumber,4,2)+'%'); ReplaceTag(ThisLine,tagTotaltx,FloatToStrF(r/100,ffCurrency,8,2)); slLines.add(ThisLine); end; end; ReplaceTag(thisPage,tagComTaxesLines,slLines.text); // Recalcule les totaux du caddy TotalHt:=fCaddy.TotalNT / 100; TotalTTC:=fCaddy.TotalWT / 100; ReplaceTag(thisPage,tagTotalNt,FloatToStrF(TotalHt,ffCurrency,8,2)); ReplaceTag(thisPage,tagTotaltx,FloatToStrF(TotalTTC-TotalHT,ffCurrency,8,2)); ReplaceTag(thisPage,tagTotalWt,FloatToStrF(TotalTTC,ffCurrency,8,2)); ReplaceTag(thisPage,tagIDCom,IntToStr(fIdCom)); ReplaceTag(thisPage,tagIDCust,fIdCust); ReplaceTag(thisPage,tagPostUrl,fPostUrl); ReplaceTag(thisPage,tagBackUrl,fBackUrl); Result:=thisPage+'<BR>'+fCaddy.Errors.Text; Finally slLines.Free; end; end; Except On e:Exception do AddError('TCaddyISAPI.ShowReport : '+E.Message); end; end; function TCaddyISAPI.SetItems: Boolean; begin Result:=True; Try fCaddy.SetItems(fRef, fDesc,fidArt,fQte,fPuht,fCodeTaxe); fIdCom:=fCaddy.IDCom; SetNextUrl; Except On e:Exception Do begin AddError(fCaddy.Errors.Text); Result:=False; end; end; end; function TCaddyISAPI.SetQuantity: Boolean; begin Result:=True; Try fCaddy.SetQuantity(fRef,fQte); fIdCom:=fCaddy.IDCom; SetNextUrl; Except On e:Exception Do begin AddError(fCaddy.Errors.Text); Result:=False; end; end; end; procedure TCaddyISAPI.SetNextUrl; begin if fNextUrl<>'' then begin if Pos('?',fNextUrl)>0 then fNextUrl:=fNextUrl+'&idCom='+IntToStr(fIDCom) else fNextUrl:=fNextUrl+'?idCom='+IntToStr(fIDCom); if fidCust<>'' then fNextUrl:=fNextUrl+'&idCust='+fidCust; end; end; end.

(C)Cotelem Mai 2001   Accueil   Retour