« ImportByFormatDef (rtl) » : différence entre les versions

De Wiki1000
 
Aucun résumé des modifications
 
(6 versions intermédiaires par 3 utilisateurs non affichées)
Ligne 1 : Ligne 1 :
<source lang="delphi">Procedure IntegrateByFormatDef(const aCodeFormat:string; const aData:TStrings; aRefObject:TitObject; const aLogLevel:FormatLogLevel);</source>
<source lang="delphi">Procedure ImportbyFormatDef(const aCodeFormat:string; const aData:TStrings; aRefObject:TitObject; const aLogLevel:FormatLogLevel);</source>


Cette méthode permet d'importer un fichier en utilisant un format.
Cette méthode permet d'importer un fichier en utilisant un format.


{|class="wikitable"
{|class="wikitable"
|-
!Paramètre
!Usage
|-
|-
|aCodeFormat
|aCodeFormat
Ligne 32 : Ligne 35 :


<source lang="delphi">
<source lang="delphi">
//Procedure _doImport;
var
vFormatCode : String;
vFormatIntegrationFichier : TFormatIntegrationFichier;
vidxRem  : Integer;
vTimeOrg : LongInt;
vTimeInt : LongInt;
vTimeLst : LongInt;
vTimeCom : LongInt;
vTrackingMode : FormatLogLevel;
begin
begin
  // Locate the format definition
  // Recherche du format en dur
  vFormatCode := 'INT_SEPA_SCT_PAIN.001.001.03';
  vFormatIntegrationFichier := TFormatIntegrationFichier.Find('(code=%1)','',true,[vFormatCode]);
  // Set logging mode
  if estVerbeux then
    vTrackingMode := Format_Log_Level_Verbose
  else
    vTrackingMode := Format_Log_Level_None;
  if Assigned(vFormatIntegrationFichier) then
  begin
  // Start a long transaction
  ClassManager.BeginLongTran(1,'TImportRemiseBancaire');
  try
    CreerSessionImport;
    // Load the source file in a TStrings
    ProgressMessage(Format(_TP('Chargement du fichier %s.'),[FichierImport]));
    content.LoadFromFile(FichierImport);
    vTimeOrg := GetTickCount;
    ProgressMessage(Format(_TP('Intégration du fichier %s.'),[FichierImport]));
    // Import the source file here
    ImportbyFormatDef(vFormatIntegrationFichier.GetFileFormatNameRef,Content.Strings,self,vTrackingMode);
    vTimeInt := GetTickCount;
    ProgressMessage(Format(_TP('Intégration en %s ms.'),[TickToString(vTimeInt-vTimeOrg)]));
    ProgressMessage(_TP('Fermeture de la transaction.'));
    ClassManager.CommitlongTran;
    vTimeCom := GetTickCount;
    ProgressMessage(Format(_TP('Clôture transaction en %s Ms, sur un total de %s Ms.'),[TickToString(vTimeCom-vTimeLst),TickToString(vTimeCom-vTimeOrg)]));
  except
    ClassManager.RollBacklongTran;
    ProgressMessage(Format(_TP('Erreur d''import : %s'),[e.Message]));
    raise;
  end;
end
else
  ERule.Create(Format(_TP('Le format %s n''a pas été trouvé.'),[vFormatCode]));
end;
end;
</source>
</source>


Voir aussi:
Voir aussi:
* [[ImportByFormatDefXmlSAX (rtl)|ImportByFormatDefXmlSAX (rtl)]]


{{Footer|Développement DSM}}
{{Footer|Développement DSM}}
[[category:RTL Framework]]
[[category:RTL Framework]]
[[Category:RTL Format de fichier]]
[[Category:RTL Format de fichier]]

Dernière version du 4 novembre 2017 à 10:00

Procedure ImportbyFormatDef(const aCodeFormat:string; const aData:TStrings; aRefObject:TitObject; const aLogLevel:FormatLogLevel);

Cette méthode permet d'importer un fichier en utilisant un format.

Paramètre Usage
aCodeFormat Code du format à utiliser pour l'import.
aData Contenu du fichier à importer.
aRefObject Objet racine tous les objets qui seront créés.
aLogLevel Niveau de journalisation.

Le journal généré se situe dans répertoire [container L1000]/logs

Trois niveaux de journalisation sont possibles :

  • Format_Log_Level_None
aucune trace
  • Format_Log_Level_Data_Errors
trace les erreurs d'accès au données (formule erronée...) utile pour la mise au point des nouveaux formats
  • Format_Log_Level_Verbose
trace l'exploration du fichier / du modèle (trace importante en taille) + Format_Log_Level_Data_Errors

Exemple

//Procedure _doImport;
var
 vFormatCode : String;
 vFormatIntegrationFichier : TFormatIntegrationFichier;
 vidxRem  : Integer;
 vTimeOrg : LongInt;
 vTimeInt : LongInt;
 vTimeLst : LongInt;
 vTimeCom : LongInt;
 vTrackingMode : FormatLogLevel;
begin
  // Locate the format definition
  // Recherche du format en dur
  vFormatCode := 'INT_SEPA_SCT_PAIN.001.001.03';
  vFormatIntegrationFichier := TFormatIntegrationFichier.Find('(code=%1)','',true,[vFormatCode]);

  // Set logging mode
  if estVerbeux then
    vTrackingMode := Format_Log_Level_Verbose
  else
    vTrackingMode := Format_Log_Level_None;

  if Assigned(vFormatIntegrationFichier) then
  begin
   // Start a long transaction
   ClassManager.BeginLongTran(1,'TImportRemiseBancaire');
   try
     CreerSessionImport;

     // Load the source file in a TStrings
     ProgressMessage(Format(_TP('Chargement du fichier %s.'),[FichierImport]));
     content.LoadFromFile(FichierImport);

     vTimeOrg := GetTickCount;
     ProgressMessage(Format(_TP('Intégration du fichier %s.'),[FichierImport]));

     // Import the source file here
     ImportbyFormatDef(vFormatIntegrationFichier.GetFileFormatNameRef,Content.Strings,self,vTrackingMode);

     vTimeInt := GetTickCount;
     ProgressMessage(Format(_TP('Intégration en %s ms.'),[TickToString(vTimeInt-vTimeOrg)]));

     ProgressMessage(_TP('Fermeture de la transaction.'));

     ClassManager.CommitlongTran; 
     vTimeCom := GetTickCount;
     ProgressMessage(Format(_TP('Clôture transaction en %s Ms, sur un total de %s Ms.'),[TickToString(vTimeCom-vTimeLst),TickToString(vTimeCom-vTimeOrg)]));
   except
     ClassManager.RollBacklongTran;
     ProgressMessage(Format(_TP('Erreur d''import : %s'),[e.Message]));
     raise;
   end;
 end
 else
   ERule.Create(Format(_TP('Le format %s n''a pas été trouvé.'),[vFormatCode]));
end;

Voir aussi:

Développement DSMDéveloppement DSM