1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234
|
Const ForReading = 1, ForWriting = 2, ForAppending = 8
Dim f_csv, fs_csv
Dim fs_csv1, fs_csv2, fs_csv3, fs_csv4, fs_csv5, fs_csv6, fs_csv7, fs_csv8, fs_csv_all
Dim f_csv1, f_csv2, f_csv3, f_csv4, f_csv5, f_csv6, f_csv7, f_csv8, f_csv_all
Dim Day_csv, Month_csv, Year_csv, nom_rec, nb_char_nom_rec, numero_ligne_csv
Dim path_search_csv, found_csv, found_csv_path, ligne_csv, nom_voie_ligne, array_cellule_csv, date_de_recherche, file_in_folder
Dim no_rec_voie, capteur_actif, capteur_nom, date_time_array, date_ligne, heure_ligne, date_time_ligne, ligne_a_copier, no_voie_csv
Dim fso, folder, fld
'Message : Service occupé, veuillez patientez SVP...
Call ShowSystemAlarm ("Service occupé, veuillez patientez SVP...!")
nom_rec = SmartTags("DB_Rapport_Data_Enregistrement.Nom")
nb_char_nom_rec = Len(nom_rec)
date_de_recherche = SmartTags("Debut_Rec_Day") & "/" & SmartTags("Debut_Rec_Month") & "/" & SmartTags("Debut_Rec_Year") & " " & "00:00:00"
found_csv = "" 'init
file_in_folder = False 'init
'Création des objets file pour la gestion des fichiers csv pour chaque capteur et ouverture des ficheirs csv
Set fs_csv_all = CreateObject("Scripting.FileSystemObject")
On Error Resume Next
Set f_csv_all = fs_csv_all.OpenTextFile((Path_CSVs & "CSV_All.csv"), ForAppending, True)
Set fs_csv1 = CreateObject("Scripting.FileSystemObject")
On Error Resume Next
Set f_csv1 = fs_csv1.OpenTextFile((Path_CSVs & "CSV1.csv"), ForAppending, True)
Set fs_csv2 = CreateObject("Scripting.FileSystemObject")
On Error Resume Next
Set f_csv2 = fs_csv2.OpenTextFile((Path_CSVs & "CSV2.csv"), ForAppending, True)
Set fs_csv3 = CreateObject("Scripting.FileSystemObject")
On Error Resume Next
Set f_csv3 = fs_csv3.OpenTextFile((Path_CSVs & "CSV3.csv"), ForAppending, True)
Set fs_csv4 = CreateObject("Scripting.FileSystemObject")
On Error Resume Next
Set f_csv4 = fs_csv4.OpenTextFile((Path_CSVs & "CSV4.csv"), ForAppending, True)
Set fs_csv5 = CreateObject("Scripting.FileSystemObject")
On Error Resume Next
Set f_csv5 = fs_csv5.OpenTextFile((Path_CSVs & "CSV5.csv"), ForAppending, True)
Set fs_csv6 = CreateObject("Scripting.FileSystemObject")
On Error Resume Next
Set f_csv6 = fs_csv6.OpenTextFile((Path_CSVs & "CSV6.csv"), ForAppending, True)
Set fs_csv7 = CreateObject("Scripting.FileSystemObject")
On Error Resume Next
Set f_csv7 = fs_csv7.OpenTextFile((Path_CSVs & "CSV7.csv"), ForAppending, True)
Set fs_csv8 = CreateObject("Scripting.FileSystemObject")
On Error Resume Next
Set f_csv8 = fs_csv8.OpenTextFile((Path_CSVs & "CSV8.csv"), ForAppending, True)
'Recherche des fichiers concernés par l'enregistrement
Do
'Message : Service occupé, veuillez patientez SVP...
Call ShowSystemAlarm ("Service occupé, veuillez patientez SVP...!")
Day_csv=Day(date_de_recherche)
Month_csv=Month(date_de_recherche)
Year_csv=Year(date_de_recherche)
'Chemin approximatif fichier CSV à rechercher
path_search_csv = Storage_Path & "Annee_" & Year_csv & "\Mois_" & Month_csv & "\Jour_" & Day_csv & "\"
Set fso = CreateObject("Scripting.FileSystemObject")
If fso.FolderExists(path_search_csv) Then
For Each fld In fso.GetFolder(path_search_csv).Files
If Left(fld.Name, nb_char_nom_rec) = nom_rec And Right(fld.Name, 4) = ".csv" Then
'Message : Service occupé, veuillez patientez SVP...
Call ShowSystemAlarm ("Service occupé, veuillez patientez SVP...!")
found_csv = fld.Name
file_in_folder = True
'Création d'un objet file system pour la recherche des 'fichiers csv comprenant les valeurs d'archivages
Set fs_csv = CreateObject("Scripting.FileSystemObject")
On Error Resume Next
'Ouverture du fichier csv trouvé
found_csv_path= Storage_Path & "Annee_" & Year_csv & "\Mois_" & Month_csv & "\Jour_" & Day_csv & "\" & found_csv
Set f_csv = fs_csv.OpenTextFile(found_csv_path, ForReading, True)
If Err.Number=0 Then
'Lire chaque ligne jusqu'à la dernière ligne du fichier
numero_ligne_csv = 1 'init
Do While f_csv.AtEndOfStream = False
ligne_csv = f_csv.ReadLine 'lecture de ligne du fichier csv
array_cellule_csv = Split(ligne_csv, ";")'séparation dés données comprise sur la ligne : chaque cellule -> array
date_time_ligne = Replace(array_cellule_csv(1),Chr(34),"")'suppression des guillemets générés par le split autour de la date et heure
nom_voie_ligne = Replace(array_cellule_csv(0),Chr(34),"")'suppression des guillemets générés par le split
date_time_array = Split(date_time_ligne, " ")'séparation de la date et de l'heure
date_ligne = date_time_array(0)
heure_ligne = date_time_array(1)
'Capteur concerné par la lecture de la ligne
capteur_actif = False
no_rec_voie = 0
no_voie_csv = Right(nom_voie_ligne,17)
If no_voie_csv = "_record[1].Valeur" Then
no_rec_voie = 1
capteur_actif = SmartTags("DB_Rapport_Data_Enregistrement.Actif_capteur[1]")
capteur_nom = SmartTags("DB_Rapport_Data_Enregistrement.Nom_capteur[1]")
End If
If no_voie_csv = "_record[2].Valeur" Then
no_rec_voie = 2
capteur_actif = SmartTags("DB_Rapport_Data_Enregistrement.Actif_capteur[2]")
capteur_nom = SmartTags("DB_Rapport_Data_Enregistrement.Nom_capteur[2]")
End If
If no_voie_csv = "_record[3].Valeur" Then
no_rec_voie = 3
capteur_actif = SmartTags("DB_Rapport_Data_Enregistrement.Actif_capteur[3]")
capteur_nom = SmartTags("DB_Rapport_Data_Enregistrement.Nom_capteur[3]")
End If
If no_voie_csv = "_record[4].Valeur" Then
no_rec_voie = 4
capteur_actif = SmartTags("DB_Rapport_Data_Enregistrement.Actif_capteur[4]")
capteur_nom = SmartTags("DB_Rapport_Data_Enregistrement.Nom_capteur[4]")
End If
If no_voie_csv = "_record[5].Valeur" Then
no_rec_voie = 5
capteur_actif = SmartTags("DB_Rapport_Data_Enregistrement.Actif_capteur[5]")
capteur_nom = SmartTags("DB_Rapport_Data_Enregistrement.Nom_capteur[5]")
End If
If no_voie_csv = "_record[6].Valeur" Then
no_rec_voie = 6
capteur_actif = SmartTags("DB_Rapport_Data_Enregistrement.Actif_capteur[6]")
capteur_nom = SmartTags("DB_Rapport_Data_Enregistrement.Nom_capteur[6]")
End If
If no_voie_csv = "_record[7].Valeur" Then
no_rec_voie = 7
capteur_actif = SmartTags("DB_Rapport_Data_Enregistrement.Actif_capteur[7]")
capteur_nom = SmartTags("DB_Rapport_Data_Enregistrement.Nom_capteur[7]")
End If
If no_voie_csv = "_record[8].Valeur" Then
no_rec_voie = 8
capteur_actif = SmartTags("DB_Rapport_Data_Enregistrement.Actif_capteur[8]")
capteur_nom = SmartTags("DB_Rapport_Data_Enregistrement.Nom_capteur[8]")
End If
If no_voie_csv = "_record[9].Valeur" Then
no_rec_voie = 9
capteur_actif = SmartTags("DB_Rapport_Data_Enregistrement.Actif_capteur[9]")
capteur_nom = SmartTags("DB_Rapport_Data_Enregistrement.Nom_capteur[9]")
End If
If no_voie_csv = "record[10].Valeur" Then
no_rec_voie = 10
capteur_actif = SmartTags("DB_Rapport_Data_Enregistrement.Actif_capteur[10]")
capteur_nom = SmartTags("DB_Rapport_Data_Enregistrement.Nom_capteur[10]")
End If
'Recopie de la ligne du fichier CSV dans le Fichier CSV du capteur en cours
If capteur_actif Then
ligne_a_copier = capteur_nom & ";" & array_cellule_csv(2) & ";" & heure_ligne & ";" & date_ligne & ";" & date_time_ligne
Select Case no_rec_voie
Case 1
f_csv1.WriteLine ligne_a_copier
Case 2
f_csv2.WriteLine ligne_a_copier
Case 3
f_csv3.WriteLine ligne_a_copier
Case 4
f_csv4.WriteLine ligne_a_copier
Case 5
f_csv5.WriteLine ligne_a_copier
Case 6
f_csv6.WriteLine ligne_a_copier
Case 7
f_csv7.WriteLine ligne_a_copier
Case 8
f_csv8.WriteLine ligne_a_copier
Case 9
f_csv8.WriteLine ligne_a_copier
Case 10
f_csv8.WriteLine ligne_a_copier
End Select
End If
'Recopie de la ligne du fichier CSV général '(pour affichage de la courbe à partir de ce fichier)
If no_rec_voie <> 0 Or numero_ligne_csv = 1 Then
f_csv_all.WriteLine ligne_csv
numero_ligne_csv = numero_ligne_csv + 1
End If
Loop
End If
'Fermeture du fichier
f_csv.Close
'Libération des objets
Set f_csv = Nothing
Set fs_csv = Nothing
End If
Next
'on passe au jour suivant (dossier Jour_XX suivant)
date_de_recherche = DateAdd("d",1,date_de_recherche)
Else
file_in_folder = False
End If
Set folder = Nothing
Set fso = Nothing
Loop While (file_in_folder)
'Fermeture des fichiers csv pour chaque capteur
f_csv_all.Close
f_csv1.Close
f_csv2.Close
f_csv3.Close
f_csv4.Close
f_csv5.Close
f_csv6.Close
f_csv7.Close
f_csv8.Close
'Libération des objets
Set f_csv_all = Nothing
Set f_csv1 = Nothing
Set f_csv2 = Nothing
Set f_csv3 = Nothing
Set f_csv4 = Nothing
Set f_csv5 = Nothing
Set f_csv6 = Nothing
Set f_csv7 = Nothing
Set f_csv8 = Nothing
Set fs_csv_all = Nothing
Set fs_csv = Nothing
Set fs_csv1 = Nothing
Set fs_csv2 = Nothing
Set fs_csv3 = Nothing
Set fs_csv4 = Nothing
Set fs_csv5 = Nothing
Set fs_csv6 = Nothing
Set fs_csv7 = Nothing
Set fs_csv8 = Nothing |
Partager