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
|
Private Sub Form_Open(Cancel As Integer)
Dim conBASE As ADODB.Connection
Dim recRAPPELS As ADODB.Recordset
Dim strDir As String
Dim strPCID As String
Dim appFLS As Application
Dim datWAIT As Date
Dim maj As New miseAJour
DoCmd.Maximize
frmCloseWithoutSaving = False
'***************************
'* SCRIPTS DE MISES A JOUR *
'***************************
'Paramètre : Serveur de scripts (+ "tests\" si base test)
strDir = ParamètresLIRE("ServeurMAJ") & "scripts\" & IIf(ParamètresLIRE("BaseTest") = "Oui", "Tests\", "")
'Paramètre : PCID pour les scripts individuels
Set WshShell = CreateObject("WScript.Shell")
strPCID = WshShell.RegRead("HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\ComputerName\ActiveComputerName\ComputerName")
On Error GoTo Err
'On teste la connexion au serveur
Dir (strDir)
On Error GoTo 0
'Recherche et exécution des scripts généraux
Set appFLS = New Application
With appFLS.FileSearch
.LookIn = strDir
.FileName = "SFA-*.vbs"
.Execute msoSortByFileName
End With
If appFLS.FileSearch.FoundFiles.count > 0 Then
'On teste le répertoire Scripts, si il n'est pas présent, on le crée
If Dir(Répertoire(CurrentDb.Name) & "Scripts", vbDirectory + vbHidden) = "" Then
On Error GoTo errScript1
MkDir Répertoire(CurrentDb.Name) & "Scripts"
SetAttr Répertoire(CurrentDb.Name) & "Scripts", vbHidden
End If
For Each FIC In appFLS.FileSearch.FoundFiles
'Script déjà en cours d'exécution ? (Appel d'access qui appelle access... = danger !)
If Dir(Répertoire(CurrentDb.Name) & "Scripts\" & Fichier(CStr(FIC))) = "" Then
'Si le ".log" n'est pas présent en local, on copie le script en local et on l'exécute
If Dir(Répertoire(CurrentDb.Name) & "Scripts\" & Left(Fichier(FIC), Len(Fichier(FIC)) - 4) & ".log") = "" Then
On Error Resume Next
DoCmd.OpenForm "maj"
Forms("maj").Repaint
datWAIT = Now()
Do
FileCopy CStr(FIC), Répertoire(CurrentDb.Name) & "Scripts\" & Fichier(CStr(FIC))
Loop While Répertoire(CurrentDb.Name) & "Scripts\" & Fichier(CStr(FIC)) And DateDiff("s", datWAIT, Now()) < 10
X = ShellExecute(0, "open", Répertoire(CurrentDb.Name) & "Scripts\" & Fichier(CStr(FIC)), vbNullString, "E:\", 1)
Do
Forms("maj").Repaint
Loop While Dir(Répertoire(CurrentDb.Name) & "Scripts\temp.log") = ""
Name Répertoire(CurrentDb.Name) & "Scripts\temp.log" As Left(Répertoire(CurrentDb.Name) & "Scripts\" & Fichier(CStr(FIC)), Len(Répertoire(CurrentDb.Name) & "Scripts\" & Fichier(CStr(FIC))) - 4) & ".log"
Kill Répertoire(CurrentDb.Name) & "Scripts\" & Fichier(CStr(FIC))
On Error GoTo 0
errScript1:
DoCmd.Close acForm, "maj"
'On écrit un événement
CurrentDb.Execute "INSERT INTO LOGS (LOG_Date, LOG_Fichier, LOG_Evénement) " & _
"VALUES ('" & Now() & "', 'Script : " & Fichier(CStr(FIC)) & "', 'Réussie !')"
End If
End If
Next
End If
'Recherche et exécution des scripts personnalisés (sur le nom de machine)
Set appFLS = New Application
With appFLS.FileSearch
.LookIn = strDir
.FileName = strPCID & "*.vbs"
.Execute msoSortByFileName
End With
If appFLS.FileSearch.FoundFiles.count > 0 Then
'On teste le répertoire Scripts, si il n'est pas présent, on le crée
If Dir(Répertoire(CurrentDb.Name) & "Scripts", vbDirectory + vbHidden) = "" Then
On Error GoTo errScript2
MkDir Répertoire(CurrentDb.Name) & "Scripts"
SetAttr Répertoire(CurrentDb.Name) & "Scripts", vbHidden
End If
For Each FIC In appFLS.FileSearch.FoundFiles
'Script déjà en cours d'exécution ? (Appel d'access qui appelle access... = danger !)
If Dir(Répertoire(CurrentDb.Name) & "Scripts\" & Fichier(CStr(FIC))) = "" Then
On Error Resume Next
DoCmd.OpenForm "maj"
Forms("maj").Repaint
datWAIT = Now()
Do
FileCopy CStr(FIC), Répertoire(CurrentDb.Name) & "Scripts\" & Fichier(CStr(FIC))
Loop While Répertoire(CurrentDb.Name) & "Scripts\" & Fichier(CStr(FIC)) And DateDiff("s", datWAIT, Now()) < 10
X = ShellExecute(0, "open", Répertoire(CurrentDb.Name) & "Scripts\" & Fichier(CStr(FIC)), vbNullString, "E:\", 1)
Do
Forms("maj").Repaint
Loop While Dir(Répertoire(CurrentDb.Name) & "Scripts\temp.log") = ""
Kill Répertoire(CurrentDb.Name) & "Scripts\temp.log"
Kill Répertoire(CurrentDb.Name) & "Scripts\" & Fichier(CStr(FIC))
Kill CStr(FIC)
On Error GoTo 0
errScript2:
DoCmd.Close acForm, "maj"
End If
Next
End If
Err:
On Error Resume Next
Contrôle_Sécurité
Contrôle_Version
'Utilisateur
Dim userPass As clsUserPass
Set userPass = New clsUserPass
' 1) On vérifie les informations de l'utilisateur en mode niveau 1.
' Si les informations ne sont pas saisies, la seule chose qu'on demande
' c'est qu'elles soient ressaisies...
userPass.logUser 1
lbl_utilisateur.Caption = userPass.lblUtilisateur
'Mois en cours et semainier
lbl_moisencours = Format(Now(), "mmmm yyyy")
ChargerSemainier lbl_moisencours
'Les visites/actions
cdr_actions.Value = DLookup("Valeur", "Options", "Nom = 'BusinessType'")
Select Case DLookup("Valeur", "Options", "Nom = 'BusinessType'")
Case "1": opt_visites_MouseDown 1, 0, 0, 0
Case "2": opt_appels_MouseDown 1, 0, 0, 0
Case "3": opt_taches_MouseDown 1, 0, 0, 0
Case "4": opt_autres_MouseDown 1, 0, 0, 0
Case "5": opt_tout_MouseDown 1, 0, 0, 0
End Select
'Tri & actifs
cdr_tri.Value = DLookup("Valeur", "Options", "Nom = 'ContactsClientsTri'")
cdr_actifs.Value = DLookup("Valeur", "Options", "Nom = 'ClientsContactsActifs'")
Select Case DLookup("Valeur", "Options", "Nom = 'ContactsClientsTri'")
Case "1": opt_croissant_MouseDown 1, 0, 0, 0
Case "2": opt_decroissant_MouseDown 1, 0, 0, 0
End Select
'Actifs
Select Case DLookup("Valeur", "Options", "Nom = 'ClientsContactsActifs'")
Case "1": opt_actifs_MouseDown 1, 0, 0, 0
Case "2": opt_inactifs_MouseDown 1, 0, 0, 0
Case "3": opt_deux_MouseDown 1, 0, 0, 0
End Select
'La base clients
txt_rechercher = ""
txt_rechercher.SetFocus
txt_rechercher_Change
' Contrôle rappels ?
If gbooOPTIONS = False And DLookup("Valeur", "Options", "Nom = 'OuvrirRappels'") = -1 Then
Set conBASE = CurrentProject.Connection
Set recRAPPELS = New ADODB.Recordset
recRAPPELS.Open "SELECT count(RAPPELS.[ID]) " & _
"FROM RAPPELS LEFT JOIN ACTIONS ON [RAPPELS].[Action]=[ACTIONS].[ID] " & _
"WHERE [RAPPELS].[Lu]=0 And CDate(Format(DateAdd('d',-RAPPELS.[jours],ACTIONS.[dateReelle]),'dd/mm/yyyy'))=CDate(Format(Now(),'dd/mm/yyyy'))", conBASE
'(CDate(Format(Now(),"dd/mm/yyyy"))>=CDate(Format(DateAdd("d",-[jours],[DateReelle]),"dd/mm/yyyy"))) And (CDate(Format(Now(),"dd/mm/yyyy"))<= CDate(Format([DateReelle],"dd/mm/yyyy")))
If recRAPPELS.BOF = False Then
If noNullLng(recRAPPELS(0)) > 0 Then DoCmd.OpenForm "ActionsRappels", , , , , acDialog
End If
recRAPPELS.Close
End If
' Contrôle des fichiers disponibles
If PRODUCTION.isSFAConnected = True Then
If PRODUCTION.isSQLServerConnected = True Then
If PRODUCTION.isFileOnServer = True Then
PRODUCTION.importProductionSAPToAccess
PRODUCTION.actualisationDonnees
PRODUCTION.miseAJourServer
End If
End If
End If
Me.lblInfoFichiersAJour.Caption = "Dernière mise à jour de vos fichiers : " & maj.derniereMiseAJour & "..."
Me.etiVersion.Caption = "Version : " & maj.versionActuelle
End Sub |
Partager