Code : Tout sélectionner
; *************************************************************
; * INTERFACAGE DE FICHIER PLAT - ECRIT PAR GHOST LINE - 2009 *
; *************************************************************
#include <File.au3>
#include <Array.au3>
#include <ButtonConstants.au3>
#include <ComboConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
; -------------------------------------------------------------
; * DECLARATION DES VARIABLES *
; -------------------------------------------------------------
$chemin_entree = "m:\timeless\orli\recu\bck\"
;$chemin_entree = "c:\"
$i = 1
$j = 1
$l = 0
$z = 0
$y = 0
$CountLines = 0
$recherche = "1101" ; Pourrait tout aussi bien être un n° de commande, ou tout autre chose
$date_debut = "20090801"
$date_fin = "20090813"
$type_fichier = "*.paq"
$exemple_commentaire = "1101"
$exemple_stock = ""
Dim $array[1][6]
Local $array_fichiers_ok[1]
Local $array_fichiers_ok_recherche[1]
; -------------------------------------------------------------
; * PROGRAMME *
; -------------------------------------------------------------
; * BLOC SELECTION DES FICHIERS ELIGIBLES
$liste_fichiers = _FileListToArray($chemin_entree, $type_fichier,0)
; * BLOC RECHERCHE FICHIER PAR DATE DE CREATION
$nombre_lignes_fichier = 0
For $z = 1 to $liste_fichiers[0]
$Date_creation = StringLeft(FileGetTime($chemin_entree&$liste_fichiers[$z],1,1),8)
if $Date_creation >= $date_debut Then
if $Date_creation <= $date_fin Then
$nombre_lignes_fichier += 1
_ArrayAdd($array_fichiers_ok, $chemin_entree&$liste_fichiers[$z])
EndIf
EndIf
Next
; * BLOC RECHERCHE DANS UN FICHIER
$nombre_lignes_fichier_ok = 0
For $y= 1 to $nombre_lignes_fichier
If _ReplaceStringInFile($array_fichiers_ok[$y], $recherche, $recherche) Then
_ArrayAdd($array_fichiers_ok_recherche, $array_fichiers_ok[$y])
$nombre_lignes_fichier_ok = $nombre_lignes_fichier_ok + 1
EndIf
Next
If $nombre_lignes_fichier_ok = 0 Then
MsgBox (0,"","Aucun fichier trouvé remplissant ces critères")
EndIf
; BARRE DE PROGRESSION DU PARCOURS DES FICHIERS
for $k = 1 To $nombre_lignes_fichier_ok
$CountLines += _FileCountLines($array_fichiers_ok_recherche[$k]) ; On compte le total des lignes OK dans tous les fichiers pour la barre de progression
Next
ProgressOn("Analyse des fichiers",$nombre_lignes_fichier_ok&" fichier(s) en cours d'analyse ...")
; * BLOC LECTURE : ON STOCKE LES RESULTATS CORRESPONDANTS D'UN FICHIER DANS UNE ARRAY
For $k = 1 To $nombre_lignes_fichier_ok
$fichier_entree = $array_fichiers_ok_recherche[$k]
$fichier_a_traiter = FileOpen($fichier_entree,0)
While 1
$pourcentage = ($i + $l) * 100 / $CountLines ; <-- paramètres barre de progression
ProgressSet($pourcentage) ; <-- barre de progression
$ligne = FileReadLine($fichier_a_traiter,$i+1)
If @error = -1 Then ExitLoop ; code erreur de FileReadLine : on arrive a la fin du fichier ? on quitte la boucle
$num_commande = StringStripWS(StringMid($ligne,7,9),2)
$recept_caisse = StringStripWS(StringMid($ligne,41,5),2)
$commentaire = StringStripWS(StringMid($ligne,54,20),2)
$quantite = StringStripWS(StringMid($ligne,90,10),2)
$date_exped = StringStripWS(StringMid($ligne,115,8),2)
$stock_dest = StringStripWS(StringMid($ligne,154,5),2)
Select
Case $exemple_commentaire <> ""
If $exemple_commentaire = $commentaire Then
ReDim $array [UBound($array) + 1] [6]
$array[$j-1] [0] = $num_commande
$array[$j-1] [1] = $recept_caisse
$array[$j-1] [2] = $commentaire
$array[$j-1] [3] = $quantite
$array[$j-1] [4] = $date_exped
$array[$j-1] [5] = $stock_dest
$j = $j + 1
EndIf
Case $exemple_stock <> ""
If $exemple_stock = $stock_dest Then
ReDim $array [UBound($array) + 1] [6]
$array[$j-1] [0] = $num_commande
$array[$j-1] [1] = $recept_caisse
$array[$j-1] [2] = $commentaire
$array[$j-1] [3] = $quantite
$array[$j-1] [4] = $date_exped
$array[$j-1] [5] = $stock_dest
$j += 1
EndIf
EndSelect
$i += 1
WEnd
$l = $l + $i
$i = 0
FileClose($fichier_entree)
Next
ProgressOff()
_ArrayDisplay($array)
;~ ; * BLOC GUI *
;~ $Form1 = GUICreate("Recherche commandes Albi", 559, 351, 231, 156)
;~ $Group1 = GUICtrlCreateGroup(" Listes des commandes ", 8, 0, 193, 257)
;~ $List1 = GUICtrlCreateList("", 16, 16, 177, 227)
;~ GUICtrlCreateGroup("", -99, -99, 1, 1)
;~ $Group2 = GUICtrlCreateGroup(" Critères de recherche ", 208, 0, 257, 257)
;~ $Checkbox1 = GUICtrlCreateCheckbox("Entre le", 216, 24, 57, 17)
;~ $Checkbox2 = GUICtrlCreateCheckbox("Code stock magasin :", 216, 104, 121, 17)
;~ $Checkbox3 = GUICtrlCreateCheckbox("Recherche sur le commentaire :", 216, 168, 177, 17)
;~ $Label1 = GUICtrlCreateLabel("et le", 240, 48, 24, 17)
;~ $stock_mag = GUICtrlCreateInput("", 344, 104, 73, 21)
;~ $rech_com = GUICtrlCreateInput("", 216, 192, 233, 21)
;~ $datedebut = GUICtrlCreateDate("2009/08/06 15:45:28", 272, 24, 186, 21)
;~ $datefin = GUICtrlCreateDate("2009/08/06 15:45:48", 272, 48, 186, 21)
;~ GUICtrlCreateGroup("", -99, -99, 1, 1)
;~ $reinit = GUICtrlCreateButton("Réinitialiser", 472, 8, 81, 33, $WS_GROUP)
;~ $rechercher = GUICtrlCreateButton("Rechercher", 472, 48, 81, 33, $WS_GROUP)
;~ $quitter = GUICtrlCreateButton("Quitter", 472, 264, 81, 81, $WS_GROUP)
;~ $sortie = GUICtrlCreateEdit("", 8, 264, 457, 81)
;~ GUICtrlSetData(-1, "")
;~ GUICtrlSetCursor (-1, 2)
;~ GUISetState(@SW_SHOW)
;~ While 1
;~ $nMsg = GUIGetMsg()
;~ Switch $nMsg
;~ Case $GUI_EVENT_CLOSE, $quitter
;~ Exit
;~ EndSwitch
;~ WEnd