Code : Tout sélectionner
#include <GUIConstantsEx.au3>
#include <File.au3>
#Include <GuiEdit.au3>
#include <outlook.au3>
#include <date.au3>
Opt('MustDeclareVars', 1)
Saisie() ; Interface et saisie des éléments du mail
Confirmation() ; Interface d'edition du mail généré puis validation
ExpedMail() ; Expedition du mail
MessageAng() ; Affichage message en anglais pour copier/coller incident
; ---------------------------------------------------------------------------------------------------------------------------------------------------------
Func Saisie()
Global $contenu_mail, $nom_entrepot, $num_entrepot, $date, $DateDayEn, $DateDay, $Copy_msg, $Dest_msg
Local $menu1, $n1, $n2, $msg, $menustate, $menutext, $ligne, $choix_date, $Button2,$validation1, $DateToDayEn, $DateToDay, $num_ligne, $ligne_conf, $fichier,$fichier_mag
Dim $csvArray
$fichier = FileOpen(@WorkingDir&"\config.ini",0)
If $fichier = -1 Then
MsgBox(0, "Erreur", "Le fichier config.ini n'existe pas dans le répertoire courant du programme.")
Exit
EndIf
For $num_ligne =1 To _FileCountLines(@WorkingDir&"\config.ini")
$ligne_conf = FileReadLine(@WorkingDir&"\config.ini", $num_ligne)
If StringRegExpReplace($ligne_conf, "=.*","") = "Fichier_Ent" Then
$fichier_mag=StringRegExpReplace($ligne_conf, StringRegExpReplace($ligne_conf, "=.*",""),"")
$fichier_mag=StringRegExpReplace($fichier_mag, "=","")
EndIf
If StringRegExpReplace($ligne_conf, "=.*","") = "Dest_msg" Then
$Dest_msg=StringRegExpReplace($ligne_conf, StringRegExpReplace($ligne_conf, "=.*",""),"")
$Dest_msg=StringRegExpReplace($Dest_msg, "=","")
EndIf
If StringRegExpReplace($ligne_conf, "=.*","") = "Copy_msg" Then
$Copy_msg=StringRegExpReplace($ligne_conf, StringRegExpReplace($ligne_conf, "=.*",""),"")
$Copy_msg=StringRegExpReplace($Copy_msg, "=","")
EndIf
Next
If $fichier_mag = "" Then
$fichier_mag = @WorkingDir&"\entrepots.csv"
If FileOpen($fichier_mag,0) = -1 Then
MsgBox(0,"Erreur","Le fichier magasin n'est pas présent dans le répertoire courant.")
Exit
EndIf
EndIf
_FileReadToArray($fichier_mag, $csvArray)
For $X = 1 to $csvArray[0]
$csvArray[$X] = StringRegExpReplace($csvArray[$X], "(;.*)", "")
Next
GUICreate("Selection entrepôt et date", 393, 210, 554, 264)
$choix_date = GUICtrlCreateMonthCal("", 200, 8, 183, 162)
$n1 = GUICtrlCreateListView($csvArray[1], 8, 8, 185, 162)
For $X = 2 to $csvArray[0]
GUICtrlCreateListViewItem($csvArray[$X], $n1)
Next
$Button2 = GUICtrlCreateButton("Quitter", 200, 176, 185, 25)
$n2 = GUICtrlCreateButton("Ok", 8, 176, 185, 25)
GUISetState()
Do
$msg = GUIGetMsg()
If $msg = $choix_date Then
$date = GUICtrlRead($choix_date)
$DateToDayEn = _DateToDayOfWeek(StringLeft($date,4),StringMid($date,6,2),StringRight($date,2))
$DateDayEn = _DateDayOfWeek($DateToDayEn,0)
If $DateDayEn = "Monday" Then $DateDay = "lundi"
If $DateDayEn = "Tuesday" Then $DateDay = "mardi"
If $DateDayEn = "Wednesday" Then $DateDay = "mercredi"
If $DateDayEn = "Thursday" Then $DateDay = "jeudi"
If $DateDayEn = "Friday" Then $DateDay = "vendredi"
If $DateDayEn = "Saturday" Then $DateDay = "samedi"
If $DateDayEn = "Sunday" Then $DateDay = "dimanche"
$date = StringRight($date,2)&"/"&StringMid($date,6,2)&"/"&StringLeft($date,4)
EndIf
If $msg = $Button2 Then
Exit
EndIf
If $msg = $n2 Then
$ligne = GUICtrlRead($n1)
$num_entrepot = StringRegExpReplace((filereadline("d:\entrepots.csv",($ligne-3))), "(.*?;)", "")
$nom_entrepot = StringRegExpReplace((filereadline("d:\entrepots.csv",($ligne-3))), "(;.*)", "")
$validation1 = MsgBox(1, "","Vous allez générer un envoi pour l'entrepôt de "& $nom_entrepot & " ("& $num_entrepot &"), en date du "& $DateDay &" "& $date&".")
If $validation1 = 1 Then
If $DateDay <> "dimanche" Then
$contenu_mail = "Bonjour,"&@CRLF&@CRLF&"Merci de prendre en compte l’arrêt électrique de l’entrepôt de "& $nom_entrepot & " ("& $num_entrepot &"), le "& $DateDay &" "& $date&" après le ok des caisses."&@CRLF&@CRLF&@CRLF&"Cordialement,"&@CRLF&@CRLF&"Le Support Entrepôt"
Else
$contenu_mail = "Bonjour,"&@CRLF&@CRLF&"Merci de prendre en compte l’arrêt électrique de l’entrepôt de "& $nom_entrepot & " ("& $num_entrepot &"), le "& $DateDay &" "& $date&" à **:** AM."&@CRLF&@CRLF&@CRLF&"Cordialement,"&@CRLF&@CRLF&"Le Support Entrepôt"
EndIf
ExitLoop
EndIf
EndIf
Until $msg = $GUI_EVENT_CLOSE
EndFunc
; ---------------------------------------------------------------------------------------------------------------------------------------------------------
Func Confirmation()
Local $GUI,$Btn_Run,$txt_edit,$msg,$Button2
Opt ("RunErrorsFatal", 0)
$GUI = GUICreate ("Confirmation",393, 210, 554, 264)
$Btn_Run = GUICtrlCreateButton ("Expédier", 8, 176, 185, 25)
$txt_edit = GUICtrlCreateEdit ($contenu_mail, 8, 8, 378, 162,$ES_MULTILINE)
$Button2 = GUICtrlCreateButton("Quitter", 200, 176, 185, 25)
GUISetState (@SW_SHOW)
While 1
$msg = GUIGetMsg ()
Select
Case $msg = $GUI_EVENT_CLOSE
Exit
Case $msg = $Button2
Exit
Case $msg = $Btn_Run
$contenu_mail = GUICtrlRead($txt_edit)
ExitLoop
EndSelect
WEnd
EndFunc
; ---------------------------------------------------------------------------------------------------------------------------------------------------------
func ExpedMail()
Local $oOutlook, $mailBody, $olFormatHTML,$xx,$sWarningClick
$oOutlook = _OutlookOpen()
$mailBody = $contenu_mail
If $Dest_msg <> "" Then
_OutlookSendMail($oOutlook, $Dest_msg, $Copy_msg, "", "Coupure électrique sur l'entrepôt "&$nom_entrepot &" ("&$num_entrepot&")"&" le "& $date, $mailBody, "", $olFormatHTML)
Else
_OutlookSendMail($oOutlook, "liste d'adresses des destinataires", "liste d'adresse des CC", "", "Coupure électrique sur l'entrepôt "&$nom_entrepot &" ("&$num_entrepot&")"&" le "& $date, $mailBody, "", $olFormatHTML)
EndIf
EndFunc
; ---------------------------------------------------------------------------------------------------------------------------------------------------------
Func MessageAng()
Local $contenu_ang, $edit_ang, $Quitter, $msg, $GUI
If $DateDay <> "dimanche" Then
$contenu_ang = "Hello,"&@CRLF&@CRLF&"We have an electric cut for maintenance purpose on "&$DateDayEn&", the "&$date&" after the close of day."&@CRLF&@CRLF&"Can you please stop the server 10.245."&$num_entrepot&".148 at *:** PM on *****."&@CRLF&@CRLF&"Thanks in advance"&@CRLF&@CRLF&"BR"
Else
$contenu_ang = "Hello,"&@CRLF&@CRLF&"We have an electric cut for maintenance purpose on "&$DateDayEn&", the "&$date&"."&@CRLF&@CRLF&"Can you please stop the server 10.245."&$num_entrepot&".148 at *:** AM."&@CRLF&@CRLF&"Thanks in advance"&@CRLF&@CRLF&"BR"
EndIf
$GUI = GUICreate ("Message pour l'incident",393, 210, 554, 264)
$edit_ang = GUICtrlCreateEdit ($contenu_ang, 8, 8, 378, 162,$ES_MULTILINE)
$Quitter = GUICtrlCreateButton("Quitter", 200, 176, 185, 25)
GUISetState (@SW_SHOW)
While 1
$msg = GUIGetMsg ()
Select
Case $msg = $GUI_EVENT_CLOSE
Exit
Case $msg = $Quitter
Exit
EndSelect
Wend
EndFunc