Vue locale (langage)
De Wiki1000
(Différences entre les versions)
| Ligne 156 : | Ligne 156 : | ||
begin | begin | ||
... | ... | ||
| + | end; | ||
| + | </source> | ||
| + | |||
| + | '''Vue avec jointure :''' | ||
| + | |||
| + | <source lang="delphi"> | ||
| + | //Procedure expensePendings(req:Tjson; var res:TObject); | ||
| + | Type | ||
| + | ExpenseView = viewOf(TNoteFrais) | ||
| + | vp: TValideurPossible = join(ValidationEtat.EtatPossible.EtatMetier, EtatNF); | ||
| + | aManager:string = vp.ContactEtablissement.oidutilisateur; | ||
| + | // | ||
| + | aDate:TDatetime = nDate; | ||
| + | aRef:string = referencePiece; | ||
| + | aReason:string = Caption; | ||
| + | aAmountOrg:TMoney = MontantTTC; | ||
| + | aAmountAct:TMoney = MontantRetenu; | ||
| + | aQuantity:TQuantity = Quantite; | ||
| + | aUser:string = Salarie.Operateur.oidutilisateur; | ||
| + | aType:string = FraisSalarie.Caption; | ||
| + | aMode:Integer = FraisSalarie.modeRemboursement; | ||
| + | aAmountMax:TMoney = FraisSalarie.montantPlafond; | ||
| + | aStatus:Integer = Statut; | ||
| + | end; | ||
| + | |||
| + | var json:TJson; ls:TSelector; indx,ctn:Integer; inst:ExpenseView; | ||
| + | AWhere,AOrder:string; Args:Array[0..5] of variant; | ||
| + | begin | ||
| + | json := TJson.Create(''); | ||
| + | res := json; | ||
| + | // | ||
| + | AWhere := '(aManager=%1) and (aStatus=%2)'; | ||
| + | Args[0] := GlbUserName; | ||
| + | Args[1] := StatutNF_AValider; | ||
| + | AOrder := 'aUser,-aDate'; | ||
| + | |||
| + | indx := 0; ctn := 0; | ||
| + | ls := ExpenseView.CreateSelector(AWhere,AOrder,true,Args); | ||
| + | foreachP inst in ls.AsCursor do | ||
| + | begin | ||
| + | . . . | ||
| + | end; | ||
end; | end; | ||
</source> | </source> | ||
Version du 31 mars 2014 à 07:56
Les vues locales sont des type de données vues déclarées localement à l'intérieur d'une opération.
Par exemple le code suivant déclare une vue MyView et effectue une recherche sur cette vue :
function foo(const S:string):Integer; Type MyView = viewof(ClassA) unCode:string = unCodeA; unEntier:Integer = refB.unEntierB; end; var inst:MyView; begin inst := MyView.Find('unCode=%1','',true,['B1']); if Assigned(inst) then begin ... end; end
Le périmètre du type est limité à la procédure, il n'est donc pas possible de passer les objets de la vue en paramètre à d'autres fonctions (pour cela utilisez une vue globale).
La syntaxe pour définir une vue locale :
BNF style grammar :
<nom_vue> ::= ViewOf(<class_dec>) [<attributes>] end
<class_dec> ::= <class_names> | <class_name> <class_dec>
<class_names> ::= <class_name>| [<class_name> ,]
<class_name> ::= identifier
<class_dec> ::= distinct
<attributes> ::= <attribute_def> | <attribute_def> <where_def>
<attribute_def> ::= <simple_attribute_def> | <simple_attribute_def> <attribute_directive>
<simple_attribute_def> ::= <attribute_dec> | <attribute_dec> = <attribute_ref>
<attribute_dec> ::= <attribute_name> : <type_name>
<attribute_ref> ::= <main_class_attribute_name> | <operator>(<main_class_attribute_name>)
<operator> ::= <aggregate_operator> | <date_operator> | <join_operator>
<aggregate_operator> ::= count|sum|max|min
<date_operator> ::= year|month|quarter|week|day|dayofyear|dayofweek|hour|minute|second
<join_operator> ::= join
<attribute_directive> ::= primary | orderby | orderby desc
<where_def> ::= [ <expression> ]
Type
NomDeVue = ViewOf(NomDeClassePrincipale)
Attribut : Type;
Attribut : Type = AliasDe;
Attribut : Type = operator(AliasDe);
Attribut : Type = AliasDe primary;
Attribut : Type = AliasDe orderby;
Attribut : Type = AliasDe orderby desc;
[ expression ]
end;
Les vues peuvent utiles pour effectuer des traitement sur des classes complexes, par exemples :
Curseur sur une classe vue :
function foo(const S:string):Integer; Type MyView = viewof(ClassA) newCode:string; unCode:string = unCodeA; unEntier:Integer = refB.unEntierB; end; var inst:MyView; cursor:MyViewCursor begin Result := 0; cursor := MyView.CreateCursorWhere(''unCode=%1'','''',true,[S]); foreach inst in cursor do begin Result := Result + inst.unEntier; end; end;
Vue sur une interface :
function foo(const S:string):Integer; Type MyView = viewof(InterfaceA, ClassA1, ClassA2) unCode:string = unCodeA primary; .... end; begin ... end;
Vue sur des combinaisons uniques d'attributs :
function foo(const S:string):Integer; Type MyView = viewof(ClassA distinct) unCode:string = unCodeA primary; unEntier:Integer = refB.unEntierB; end; begin ... end;
Vue avec agrégats :
function foo(const S:string):Integer; Type MyView = viewof(ClassA) unCode:string = unCodeA primary; unEntier:Integer = sum(unEntier); end; begin ... end;
Vue avec un opérateur de date :
function foo(const S:string):Integer; Type MyView = viewof(ClassC distinct) unCode:string = unCodeC primary; unMois:Integer = month(uneDate); end; begin ... end;
Vue avec filtre :
function foo(const S:string):Integer; Type MyView = viewof(ClassA) unCodeAA:string = unCodeA; unCodeBB:string = refB.unCodeB; [ unCodeA='A1' ] end; begin ... end;
Vue avec jointure :
//Procedure expensePendings(req:Tjson; var res:TObject); Type ExpenseView = viewOf(TNoteFrais) vp: TValideurPossible = join(ValidationEtat.EtatPossible.EtatMetier, EtatNF); aManager:string = vp.ContactEtablissement.oidutilisateur; // aDate:TDatetime = nDate; aRef:string = referencePiece; aReason:string = Caption; aAmountOrg:TMoney = MontantTTC; aAmountAct:TMoney = MontantRetenu; aQuantity:TQuantity = Quantite; aUser:string = Salarie.Operateur.oidutilisateur; aType:string = FraisSalarie.Caption; aMode:Integer = FraisSalarie.modeRemboursement; aAmountMax:TMoney = FraisSalarie.montantPlafond; aStatus:Integer = Statut; end; var json:TJson; ls:TSelector; indx,ctn:Integer; inst:ExpenseView; AWhere,AOrder:string; Args:Array[0..5] of variant; begin json := TJson.Create(''); res := json; // AWhere := '(aManager=%1) and (aStatus=%2)'; Args[0] := GlbUserName; Args[1] := StatutNF_AValider; AOrder := 'aUser,-aDate'; indx := 0; ctn := 0; ls := ExpenseView.CreateSelector(AWhere,AOrder,true,Args); foreachP inst in ls.AsCursor do begin . . . end; end;
Voir aussi :
| Whos here now: Members 0 Guests 0 Bots & Crawlers 1 |