Code : Tout sélectionner
#include <ButtonConstants.au3>
#include <StaticConstants.au3>
#include <TreeViewConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <Misc.au3>
#Include <File.au3>
#include <Array.au3>
#include <SliderConstants.au3>
#include <ListviewConstants.au3>
#include <ScreenCapture.au3>
#include <GuiTreeView.au3>
#include <FTPEx.au3>
#include <String.au3>
#include <Date.au3>
#include <GuiListView.au3>
#include <ArrayEx.au3>
#include <EditConstants.au3>
#include <WinAPI.au3>
Opt("MustDeclareVars", 1)
Opt("GUIOnEventMode", 1)
Opt("MouseCoordMode", 2)
$Debug_LV = False ;
;==[Définition variables Globales]==================================
Global $MainGUI, $child, $IDLine, $Sxx_xx, $server, $aFTPFileList, $sRemotePath, $sHost, $iFlag, $sLogin, $sPassword, $iPassive, $iPort, $iPortHelp, $aFind, $CellName, $FileToOpen, $hConnect
Global $g, $a, $LVitem, $hGUI, $aItems, $IndexItemListView, $Display, $hImage, $Sxx_xx, $MaxXY, $aMaxXY, $aEchx, $aEchxSF , $aEchxSBC, $aEchxM, $na, $b, $bord_D, $bord_sup
Global $Hcourbe = 400, $Wcourbe = 600, $left = 30, $coeffH, $Path, $Open, $conn, $pos2, $preread, $Label8, $Child, $coeffV, $array, $max_y, $NoCurveToTrace = False
Global $echx, $echx2, $HelpEff, $HelpEff2, $MON_CHEMIN, $MON_FICHIER_FTP_A_LIRE
_BuildTheMainGui()
Func _BuildTheMainGui() ;==[Construction du GUI principal]====
$MainGUI = GUICreate("Mon GUI General", 1201, 861, 195, 70)
GUISetOnEvent($GUI_EVENT_CLOSE, "_Exit")
Global $Group1 = GUICtrlCreateGroup("Infos:", 1016, 0, 177, 129)
Global $Group2 = GUICtrlCreateGroup("Selection:", 1016, 136, 177, 401)
Global $Group3 = GUICtrlCreateGroup("Etat connexion:", 1016, 744, 177, 105)
Global $Group4 = GUICtrlCreateGroup("Description:", 664, 536, 337, 313)
Global $Label1 = GUICtrlCreateLabel("Nom PC:", 1024, 24, 56, 20)
Global $Label2 = GUICtrlCreateLabel(@ComputerName, 1024, 40, 161, 20, $SS_CENTER)
Global $Label3 = GUICtrlCreateLabel("Adresse IP PC:", 1024, 56, 100, 20)
Global $Label4 = GUICtrlCreateLabel(@IPAddress1, 1024, 72, 160, 20, $SS_CENTER)
Global $Label5 = GUICtrlCreateLabel("User:", 1024, 88, 38, 20)
Global $Label6 = GUICtrlCreateLabel(@UserName, 1024, 104, 163, 20, $SS_CENTER)
Global $Label7 = GUICtrlCreateLabel("Nom serveur:", 1024, 768, 91, 20)
Global $Label10 = GUICtrlCreateLabel("", 672, 568, 320, 35)
Global $Edit1 = GUICtrlCreateEdit("", 664, 8, 337, 529, BitOR($ES_AUTOVSCROLL, $ES_AUTOHSCROLL, $ES_READONLY, $ES_WANTRETURN))
;==[Définition arborescence TreeView (Potentiellement améliorable par une architecture auto du serveur]======
Global $TreeView1 = GUICtrlCreateTreeView(1024, 160, 161, 337)
Global $TreeView1_0 = GUICtrlCreateTreeViewItem("Dossier", $TreeView1)
Global $TreeView1_1 = GUICtrlCreateTreeViewItem("Dossier1", $TreeView1_0)
Global $TreeView1_2 = GUICtrlCreateTreeViewItem("Dossier2", $TreeView1_1)
;etc....
Global $TreeView1_24 = GUICtrlCreateTreeViewItem("Dossier3", $TreeView1)
Global $TreeView1_25 = GUICtrlCreateTreeViewItem("Dossier4", $TreeView1_24)
Global $TreeView1_26 = GUICtrlCreateTreeViewItem("Dossier5", $TreeView1_25)
;etc...
Global $Valider = GUICtrlCreateButton("Valider", 1024, 504, 161, 25)
GUICtrlSetOnEvent($Valider, "_FindTheFiles")
;==[ListView]=====================
Global $ListView1 = GUICtrlCreateListView("Nom|Date|Taille (Octet)", 8, 544, 649, 305, BitOR($LVS_SHOWSELALWAYS, $LVS_REPORT))
_GUICtrlListView_SetExtendedListViewStyle($ListView1, BitOR($LVS_EX_GRIDLINES, $LVS_EX_FULLROWSELECT, $LVS_EX_SUBITEMIMAGES))
_GUICtrlListView_SetColumnWidth($ListView1, 0, 200)
_GUICtrlListView_SetColumnWidth($ListView1, 1, 200)
_GUICtrlListView_SetColumnWidth($ListView1, 2, 200)
GUICtrlSetCursor ($ListView1, 0)
GUICtrlSetCursor ($TreeView1, 0)
GUICtrlSetCursor ($Valider, 0)
;==[Définition des Polices et Fonts]===================================
GUICtrlSetFont($Group1, 8, 400, 0, "Tahoma")
GUICtrlSetFont($Label1, 8, 800, 0, "Tahoma")
GUICtrlSetFont($Label3, 8, 800, 0, "Tahoma")
GUICtrlSetFont($Label5, 8, 800, 0, "Tahoma")
GUICtrlSetFont($Group2, 8, 400, 0, "Tahoma")
GUICtrlSetFont($Group3, 8, 400, 0, "Tahoma")
GUICtrlSetFont($Label7, 8, 800, 0, "Tahoma")
GUICtrlSetFont($ListView1, 8, 400, 0, "Tahoma")
GUICtrlSetFont($Group4, 8, 400, 0, "Tahoma")
GUISetState(@SW_SHOW, $MainGUI)
_CreateNormalImageList()
_GUICtrlTreeView_SetNormalImageList($TreeView1, $hImage)
EndFunc
GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")
Func _FindTheFiles()
_GUICtrlListView_DeleteAllItems(GUICtrlGetHandle($ListView1))
Global $item = GUICtrlRead($TreeView1) ; Get the controlID of the current selected treeview item
If $item = 0 Then
MsgBox(64, "", "Selectionner le produit.")
Else
Global $text = GUICtrlRead($item, 1) ; Get the text of the treeview item
If $text == "" Then
MsgBox(16, "Erreur", "Erreur sur retour info Item")
Else
Global $toto = _GUICtrlTreeView_GetTree($TreeView1, $item)
Global $DecomposeTreeView = StringSplit($toto, '|', 1)
If $DecomposeTreeView[0] = 1 Then
MsgBox(16, "Administrateur", "Veuillez selectionner une ligne!")
ElseIf $DecomposeTreeView[0] = 2 And $DecomposeTreeView[1] <> "Courbes OK" Then
MsgBox(16, "Administrateur", "Veuillez selectionner une station!")
ElseIf $DecomposeTreeView[0] = 2 And $DecomposeTreeView[1] = "Courbes OK" Then
_DefinitionChemin()
$Label8 = GUICtrlCreateLabel($server, 1024, 784, 161, 20, $SS_CENTER)
ElseIf $DecomposeTreeView[0] = 3 And $DecomposeTreeView[1] <> "Courbes OK" Then
_DefinitionChemin()
$Label8 = GUICtrlCreateLabel($server, 1024, 784, 161, 20, $SS_CENTER)
EndIf
EndIf
EndIf
EndFunc
Func _DefinitionChemin() ;==[Définition du chemin en fonction du choix dans le TreeView]=====
;Ici la concordance entre l'architecture de ma TreeView et celle des dossiers sur mon serveur....
;Je n'ai rien mis ici car données privées ^^
GUICtrlSetData($Label10, $DecomposeTreeView[1] & " " & $DecomposeTreeView[2] & " " & $DecomposeTreeView[3] & " - " & $CellName)
_Connexion()
EndFunc
Func _Connexion()
Global $aListFTP[1][4], $Output, $aFile
_FTP_Download($aListFTP, $MON_CHEMIN, $server, 1)
;==[ Remplissage des champs "Station", "Nom" et "Date" de la ListView $ListView1 ]====
Local $NbreFichier = UBound($aListFTP) - 1
If $NbreFichier = 0 Then
MsgBox(64, "", "Aucune courbe disponible.")
Else
Dim $aItems[$NbreFichier][3]
For $iI = 0 To UBound($aItems)-1
$aItems[$iI][0] = $aListFTP[$iI+1][1]
$aItems[$iI][1] = $aListFTP[$iI+1][2]
$aItems[$iI][2] = $aListFTP[$iI+1][3]
Next
_GUICtrlListView_AddArray($ListView1, $aItems)
EndIF
;==[ On charge le(s) image(s) ]====
$hImage = _GUIImageList_Create(16, 16, 5, 3)
_GUIImageList_AddIcon($hImage, @SystemDir & "\shell32.dll", 0)
;==[On affecte le(s) image(s) }====
_GUICtrlListView_SetImageList($ListView1, $hImage, 1)
If UBound($aFTPFileList) - 1 <> "0" then
GUICtrlSetData(GUICtrlCreateLabel("", 672, 600, 320, 20), UBound($aListFTP) - 1 & " fichier(s) trouvé(s)")
Else
GUICtrlSetData(GUICtrlCreateLabel("", 672, 600, 320, 20), "Aucun fichier trouvé")
Endif
EndFunc
Func _FTP_Download(ByRef $aFTPFileList, $sRemotePath, $sHost, $iFlag, $sLogin = "LOGIN", $sPassword = "PASSWORD", $iPassive = 1, $iPort = $iPortHelp)
Local $hFtp, $hSession, $aFind, $hFind, $Result = 1
$hFtp = _FTP_Open("MyAutoItFTP")
$hSession = _FTP_Connect($hFtp, $sHost, $sLogin, $sPassword, $iPassive, $iPort)
$aFind = _FTP_FindFileFirst($hSession, $sRemotePath, $hFind)
While Not @error
$Path = $sRemotePath & '/' & $aFind[10]
If BitAND($aFind[1], $FILE_ATTRIBUTE_DIRECTORY) Then
If Not _FTP_Download($aFTPFileList, $sRemotePath & '/' & $aFind[10], $sHost, $sLogin, $sPassword, $iPassive, $iPort) Then
Return 0
EndIf
If $iFlag = 0 Or $iFlag = 2 Then
Local $iUBound = UBound($aFTPFileList)
ReDim $aFTPFileList[$iUBound + 1][4]
$aFTPFileList[$iUBound][0] = $sRemotePath & '/' & $aFind[10] & '/'
$aFTPFileList[$iUBound][0] = $aFind[10]; & '/'
EndIf
Else
If $iFlag = 0 Or $iFlag = 1 Then
Local $iUBound = UBound($aFTPFileList)
ReDim $aFTPFileList[$iUBound + 1][4]
$aFTPFileList[$iUBound][1] = $aFind[10]; & '/'
$aFTPFileList[$iUBound][2] = _FTPFileTimeLoHiToStr($aFind[6], $aFind[7])
$aFTPFileList[$iUBound][3] = _FTPFileSizeLoHi($aFind[8], $aFind[9])
EndIf
EndIf
$aFind = _FTP_FindFileNext($hFind)
WEnd
_FTP_FindFileClose($hFind)
_FTP_Close($hFtp)
$aFTPFileList[0][0] = UBound($aFTPFileList) - 1
Return $Result
EndFunc ;==>_FTP_Download
Func _FTPFileTimeLoHiToStr($LoDWORD, $HiDWORD)
Local $FileTime = DllStructCreate("dword;dword")
If Not $LoDWORD And Not $HiDWORD Then Return SetError(1, 0, "")
DllStructSetData($FileTime, 1, $LoDWORD)
DllStructSetData($FileTime, 2, $HiDWORD)
Local $date = _Date_Time_FileTimeToStr($FileTime,1)
Return SetError(@error, @extended, $date)
EndFunc
Func _FTPFileSizeLoHi($LoDWORD, $HiDWORD)
Return BitOR(BitShift($LoDWORD, -32), BitAND($HiDWORD, 0xFFFFFFFF))
EndFunc
Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam)
#forceref $hWnd, $iMsg, $iwParam
Local $hWndFrom, $iIDFrom, $iCode, $tNMHDR, $hWndListView, $tInfo
Local $tBuffer
$hWndListView = $ListView1
If Not IsHWnd($ListView1) Then $hWndListView = GUICtrlGetHandle($ListView1)
$tNMHDR = DllStructCreate($tagNMHDR, $ilParam)
$hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom"))
$iIDFrom = DllStructGetData($tNMHDR, "IDFrom")
$iCode = DllStructGetData($tNMHDR, "Code")
$NoCurveToTrace = False
Switch $hWndFrom
Case $hWndListView
Switch $iCode
Case $NM_DBLCLK ; Sent by a list-view control when the user double-clicks an item with the left mouse button
_EffacementEdit()
$tInfo = DllStructCreate($tagNMITEMACTIVATE, $ilParam)
If _GUICtrlListView_GetNextItem($ListView1) = -1 Then
Return
Else
$IndexItemListView = _GUICtrlListView_GetNextItem($ListView1)
$FileToOpen = _GUICtrlListView_GetItemText($ListView1, $IndexItemListView)
_OpenAndLoadAll()
EndIf
EndSwitch
EndSwitch
Return $GUI_RUNDEFMSG
EndFunc ;==>WM_NOTIFY
Func _EffacementEdit() ;==[Effacement contenu de l'Edit (Aperçu de mon fichier)]====
GUICtrlSetData($Edit1, "")
EndFunc
Func _OpenAndLoadAll()
_BuildTheArrays() ;== Construction des mes Arrays
If $NoCurveToTrace = False Then ;Si courbe à tracer alors car données trouvées dans le fichier lu
_BuildTheCurve()
Else
_ClearTheCurve() ;J'efface l'ancienne courbe...
Return
EndIf
EndFunc
Func _BuildTheArrays()
$Open = _FTP_Open("MyAutoItFTP")
$Conn = _FTP_Connect($Open, $server, $sLogin, $sPassword, 1, $iPortHelp)
If $conn = 0 Then
MsgBox(0,"Retour de connexion:", @error & @LF & @extended)
EndIf
Local $h_File = _FTP_FileOpen($Conn, $MON_FICHIER_FTP_A_LIRE)
Local $Size = 10000000
Local $HEX = _FTP_FileRead($h_File, $Size)
$preread = _HexToString($HEX)
_FTP_Close($Conn)
;==[Lecture du fichier]==================================================================================================
Global $res = StringRegExp($preread, "(-?\d+(?:[.,]\d*)?\h*);\h*(-?\d+(?:[.,]\d*)?)", 3, StringInStr($preread, "'mm';'kN'"))
$Display = $preread
If NOT IsArray($res) OR IsFloat(Ubound($res)) Then
MsgBox(16, "", "Pas de données pour tracer une courbe.")
$NoCurveToTrace = True
_RemplissageEdit() ;Je remplis mon Edit avec les données avant la ligne 'mm';'kN' de mon fichier...
Return
EndIf
Local $n = 0
Global $array[UBound($res)][2]
For $i = 0 to UBound($res)-1 Step 2
$array[$n][0] = $res[$i]
$array[$n][1] = $res[$i + 1]
$n += 1
Next
;==[Valeurs extrêmes]====================
Global $max_x = _ArrayMaxOrMin($array, "max", 1)
Global $max_y = _ArrayMaxOrMin($array, "max", 2)
;==[Echelle verticale]================
$na = Number(StringLen(Int($max_y))-1)
$b = 10^$na
$bord_sup = Ceiling($max_y/$b)*$b ;Local $bord_sup
Local $middleV = $bord_sup/2
$coeffV = $Hcourbe/$bord_sup
;==[Echelle horizontale]=======
$bord_D = Ceiling($max_x) ;Local $bord_D
Local $middleH = ($bord_D)/2
$coeffH = $Wcourbe/$bord_D
;==[Array pour les coordonnées sur le graphique]====
Dim $a[UBound($res)/2][2]
For $i = 0 to (UBound($res)/2)-1
$a[$i][0] = $array[$i][0]*$coeffH
$a[$i][1] = $Hcourbe - $array[$i][1]*$coeffV
Next
_RemplissageEdit()
EndFunc
Func _BuildTheCurve() ;==[Création de mon Graphique]====
$child = GUICreate("Curve", $Wcourbe+$left, $Hcourbe+100, 0, 0, $WS_POPUP, BitOR($WS_EX_MDICHILD, $WS_EX_COMPOSITED), $MainGUI)
;==[Affichage de l'échelle y]==================
$na = Number(StringLen(Int($bord_sup))-1) ;Local $na
$b = 10^$na ;Local $b
For $i = 0 to $bord_sup step $b/2
$HelpEff = GuiCtrlCreateLabel("", 0, $Hcourbe-$i*$coeffV+3, $left, 20, 2)
GuiCtrlSetFont($HelpEff, 8, 400, 0, "Tahoma")
GuiCtrlSetData($HelpEff, Round($i, 2) & " " & ChrW(9472) )
GUICtrlSetBkColor($HelpEff, $GUI_BKCOLOR_TRANSPARENT)
If $i>0 AND $i<$bord_sup Then
$HelpEff2 = GuiCtrlCreateLabel("", $left, $Hcourbe-$i*$coeffV+10, $Wcourbe, 1)
GUICtrlSetBkColor($HelpEff2, 0xaaaaff)
EndIf
Next
;==[Affichage du y maxi]======
For $i = 0 to UBound($array)-1
If $array[$i][1] = $max_y Then
$MaxXY = GuiCtrlCreateLabel("Course: " & $array[$i][0] & "mm | Effort MAXI: " & $max_y, $left+10, $Hcourbe-$max_y*$coeffV-5, 250, 15)
GUICtrlSetBkColor($MaxXY, 0xeeeeff)
GUICtrlSetColor($MaxXY, 0xff0000)
$aMaxXY = GuiCtrlCreateLabel("", $left, $Hcourbe-$max_y*$coeffV+9, $Wcourbe, 1)
GUICtrlSetBkColor($aMaxXY, 0xffaaaa)
EndIf
Next
;==[Affichage de l'échelle x]================
$na = Number(StringLen(Int($bord_D))-1);Local
$b = 10^$na ;Local
For $i = 0 to $bord_D Step $b
$echx = GuiCtrlCreateLabel("I", $left+$i*$coeffH, $Hcourbe+10-1, 2, 10, 1)
$echx2 = GuiCtrlCreateLabel($i, $left+$i*$coeffH-4, $Hcourbe+10+8, 15, 15, 1)
GuiCtrlSetFont(-1, 8, 400, 0, "Tahoma")
GUICtrlSetBkColor(-1, $GUI_BKCOLOR_TRANSPARENT)
Next
;==[Graphique]====
$g = GUICtrlCreateGraphic($left, 10, $Wcourbe, $Hcourbe)
GUICtrlSetBkColor($g, 0xffffff)
GUICtrlSetColor($g, 0)
GUICtrlSetGraphic($g, $GUI_GR_MOVE, $a[0][0], $a[0][1])
GUICtrlSetGraphic($g, $GUI_GR_PENSIZE, 2)
For $i = 0 to UBound($a)-1
GUICtrlSetGraphic($g, $GUI_GR_COLOR, 0xff)
GUICtrlSetGraphic($g, $GUI_GR_LINE, $a[$i][0], $a[$i][1])
Next
;==[Listview]=====
Local $LV = GuiCtrlCreateListview(" | ", $left+100, $Hcourbe+40, 170, 60, BitOR($GUI_SS_DEFAULT_LISTVIEW,$LVS_NOCOLUMNHEADER,$WS_BORDER), BitOR($WS_EX_CLIENTEDGE,$LVS_EX_GRIDLINES))
GUICtrlSendMsg($LV, $LVM_SETCOLUMNWIDTH, 0, 80)
GUICtrlSendMsg($LV, $LVM_SETCOLUMNWIDTH, 1, 80)
GuiCtrlCreateListViewItem("Course|Effort", $LV)
$LVitem = GuiCtrlCreateListViewItem(" | ", $LV)
GUISetState()
EndFunc
Func _RemplissageEdit()
Local $aString = _StringToArray2D($Display, @CRLF, ";", 1)
;UBound($aString) -> Nombre de ligne de $aString
Local $l = 0
local $sSearch = "'mm'"
Local $iIndex = _ArraySearch($aString, $sSearch, 0, 0, 0, 1)
For $i = 0 to $iIndex - 1
GUICtrlSetData($Edit1, $aString[$i][0] & $aString[$i][1] & $aString[$i][2] & @CRLF, $Edit1)
Next
EndFunc
Func _ArrayMaxOrMin($avArray, $op = "max", $iCol = 1)
Local $iIndex = 0, $iRows = UBound($avArray), $iDims = UBound($avArray, 0)
If $op = "max" Then $op = "<"
If $op = "min" Then $op = ">"
Switch $iDims
Case 1 ; 1D
For $i = 0 To $iRows-1
If Execute(Number($avArray[$iIndex]) &$op& Number($avArray[$i])) Then $iIndex = $i
Next
Return $avArray[$iIndex]
Case 2 ; 2D
For $i = 0 To $iRows-1
If Execute(Number($avArray[$iIndex][$iCol-1]) &$op& Number($avArray[$i][$iCol-1])) Then $iIndex = $i
Next
Return $avArray[$iIndex][$iCol-1]
EndSwitch
EndFunc
Do
If WinExists($child) And $NoCurveToTrace = False Then
_Display()
Sleep(10)
Else
EndIf
Until GUIGetMsg($MainGUI) = $GUI_EVENT_CLOSE
Func _CreateNormalImageList() ;==[Définition des images pour dossier(s) TreeView]====
$hImage = _GUIImageList_Create(16, 16, 5, 3)
_GUIImageList_AddIcon($hImage, "shell32.dll", 3)
EndFunc ;==>_CreateNormalImageList
Func _Exit();==[Fonction Exit]====
Exit
EndFunc
Func _Display()
If $NoCurveToTrace = False And WinExists($child) Then
Local $j = "", $tolerance = 2
Local $b = GUIGetCursorInfo($child)
If $b[4] = $g Then
Local $pos = MouseGetPos()
For $i = 0 to UBound($a)-1
If $pos[0]-$left>$a[$i][0]-$tolerance AND $pos[0]-$left<$a[$i][0]+$tolerance AND _
$pos[1]-10>$a[$i][1]-$tolerance AND $pos[1]-10<$a[$i][1]+$tolerance Then
Do
$pos2 = MouseGetPos()
If $array[$i][0]<>$j Then
ToolTip($array[$i][0] & " x " & $array[$i][1])
GUICtrlSetData($LVitem, $array[$i][0] & "|" & $array[$i][1])
$j = $array[$i][0]
EndIf
Until $pos[0]<$pos2[0]-$tolerance OR $pos[0]>$pos2[0]+$tolerance OR _
$pos[1]<$pos2[1]-$tolerance OR $pos[1]>$pos2[1]+$tolerance
ToolTip("")
EndIf
Next
EndIf
EndIf
EndFunc
Func _ClearTheCurve() ;==[Effacement du GUI Courbe]====
If (WinExists($child) And $NoCurveToTrace = False) Then GUIDelete($child)
EndFunc