Code : Tout sélectionner
#cs
V02.00 - 27/03/2011 - Simplification du code pour supprimer le Drag and Drop et suppimer la bibliothèque LV_Format_include.au3 & Ajout du Ctrl+C ;
V01.02 - 25/03/2011 - Ctrl+A ;
V01.01 - 25/03/2011 - Intégration de la sélection et de la copie dans le presse papier - Séparateur ;
V01.00 - 23/03/2011 - Création initiale
#ce
#include <Array.au3>
#include <GuiListView.au3>
#include <GuiConstantsEx.au3>
#include <WindowsConstants.au3>
;~ Bibliothèques personnelles
#include '_My_ADODB_Constants.au3'
; ^ Ctrl, + Shift, ! Alt
HotKeySet("^a", "SelectAll" ) ; Ctrl + a
HotKeySet("^c", "CopySelected" ) ; Ctrl + c
Local $haut = 600
Local $pas = 20
Local $col = ''
$col &= 'Article' & '|'
$col &= 'Famille' & '|'
$col &= 'Mot Directeur' & '|'
$col &= 'Désignation' & '|'
$col &= 'Localisation' & '|'
$GUI = GUICreate('RJ - Consultation SILOG - V02.00',950,740)
$lv = GUICtrlCreateListView(StringTrimRight($col,1), 10, 10, 930, $haut - 15, BitOR($LVS_EX_FULLROWSELECT, $LVS_EX_GRIDLINES))
_GUICtrlListView_SetExtendedListViewStyle($lv, BitOR($LVS_EX_GRIDLINES, $LVS_EX_FULLROWSELECT,$LVS_EX_HEADERDRAGDROP ))
GUICtrlSendMsg($lv, $LVM_SETCOLUMNWIDTH, 0, 89)
GUICtrlSendMsg($lv, $LVM_SETCOLUMNWIDTH, 1, 69)
GUICtrlSendMsg($lv, $LVM_SETCOLUMNWIDTH, 2, 150)
GUICtrlSendMsg($lv, $LVM_SETCOLUMNWIDTH, 3, 500)
GUICtrlSendMsg($lv, $LVM_SETCOLUMNWIDTH, 4, 100)
$CodeArticle = GUICtrlCreateLabel("Code Article", 40, $haut, 93, 17)
$CdeArt = GUICtrlCreateInput("", 136,$haut, 190, 17)
$CodeFamille = GUICtrlCreateLabel("Code Famille", 40, $haut+$pas, 93, 17)
$CdeFam = GUICtrlCreateInput("", 136,$haut+$pas, 190, 17)
$MotDirecteur = GUICtrlCreateLabel("Mot directeur", 40, $haut+2*$pas, 93, 17)
$MotDir = GUICtrlCreateInput("", 136,$haut+2*$pas, 190, 17)
$Designation = GUICtrlCreateLabel("Désignation", 40, $haut+3*$pas, 93, 17)
$Des = GUICtrlCreateInput("", 136,$haut+3*$pas, 290, 17)
$Designation1 = GUICtrlCreateLabel("et", 439, $haut+3*$pas, 20, 17)
$Des1 = GUICtrlCreateInput("", 460,$haut+3*$pas, 290, 17)
$Localisation = GUICtrlCreateLabel("Localisation", 40, $haut+4*$pas, 93, 17)
$Loc = GUICtrlCreateInput("", 136,$haut+4*$pas, 190, 17)
$Filtre = GUICtrlCreateButton("Filtre", 500, $haut, 95, 22)
$copy = GUICtrlCreateButton("Copier", 600, $haut, 95, 22)
$Raz = GUICtrlCreateButton("RàZ", 700, $haut, 95, 22)
$Quit = GUICtrlCreateButton("Quitter", 800, $haut, 95, 22)
;$ListView1_0 = GUICtrlCreateListViewItem("1|2|3|4|5", $lv)
;$ListView1_0 = GUICtrlCreateListViewItem("6|7|8|9|0", $lv)
GUISetState(@SW_SHOW, $GUI)
; Register WM_NOTIFY events
GUIRegisterMsg($WM_NOTIFY, "WM_Notify_Events")
_GUICtrlListView_RegisterSortCallBack($lv)
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $copy
CopySelected()
Case $GUI_EVENT_CLOSE
Exit
Case $Quit
Exit
Case $Filtre
FaitFiltre(GUICtrlRead($CdeArt), GUICtrlRead($CdeFam), GUICtrlRead($MotDir), GUICtrlRead($Des), GUICtrlRead($Des1), GUICtrlRead($Loc))
Case $Raz
GUICtrlSetData ($CdeArt, "")
GUICtrlSetData ($CdeFam, "")
GUICtrlSetData ($MotDir, "")
GUICtrlSetData ($Des, "")
GUICtrlSetData ($Des1, "")
GUICtrlSetData ($Loc, "")
_GUICtrlListView_DeleteAllItems($lv)
EndSwitch
WEnd
Exit
;~ -----------------------------------------------
;~ -----------------------------------------------
;~ Fonctions
;~
Func FaitFiltre($CdeArt, $CdeFam, $MotDir, $Des, $Des1, $Loc)
;Ouverture de la connection
$DSN = "DRIVER={SQL Server};SERVER=Nom_du_serveur;DATABASE=Nom_de_la_base;UID=nom_login;PWD=nmot_de_passe;"
Local $conn = ObjCreate("ADODB.Connection")
If $conn=0 Then
MsgBox(0,"RJ - Silog","Connexion impossible")
Exit
EndIf
$conn.ConnectionString = $DSN
$conn.CursorLocation = $adUseClient
$conn.Open()
$rs = ObjCreate( "ADODB.RecordSet" )
Local $sql = ''
$sql &= "SELECT CodeArticle, CodeFamille, MotDirecteur, Designation1, Localisation FROM ARTICLE WHERE "
$sql &= "CodeArticle Like '%" & $CdeArt & "%' AND "
$sql &= "CodeFamille Like '%" & $CdeFam & "%' AND "
$sql &= "MotDirecteur Like '%" & $MotDir & "%' AND "
$sql &= "Designation1 Like '%" & $Des & "%' AND "
$sql &= "Designation1 Like '%" & $Des1 & "%' AND "
$sql &= "Localisation Like '%" & $Loc & "%' "
$rs.Open( $sql, $conn )
_GUICtrlListView_DeleteAllItems($lv)
If $rs.eof Then
msgbox(0,"RJ SILOG","Rien de correspond à votre demande")
Else
If $rs.recordcount>150 then
msgbox(0,"RJ SILOG","Trop de lignes, merci d'affiner votre demande")
else
_GUICtrlListView_DeleteAllItems($lv)
Local $ligne = ''
Do
$ligne &= $rs.Fields("CodeArticle").value & '|'
$ligne &= $rs.Fields("CodeFamille").value & '|'
$ligne &= $rs.Fields("MotDirecteur").value & '|'
$ligne &= $rs.Fields("Designation1").value & '|'
$ligne &= $rs.Fields("Localisation").value & '|'
GUICtrlCreateListViewItem($ligne, $lv)
$ligne = ''
$rs.movenext
until $rs.eof
EndIf
EndIf
$conn.Close
EndFunc
Func SelectAll()
_GUICtrlListView_SetItemSelected ($lv,-1)
EndFunc
Func CopyCodeArt()
ClipPut(_GUICtrlListView_GetItemText ($lv, Number(_GUICtrlListView_GetSelectedIndices($lv))))
EndFunc
Func CopySelected()
If _GUICtrlListView_GetSelectedCount($lv) >0 Then
$id = StringSplit(_GUICtrlListView_GetSelectedIndices($lv),"|")
Local $table = ''
For $t = 1 to UBound($id) - 1
$table &= _GUICtrlListView_GetItemTextString($lv,int($id[$t])) & @CRLF
Next
$table = StringReplace($table,"|",@tab)
ClipPut($table)
EndIf
EndFunc
; WM_NOTIFY event handler
Func WM_Notify_Events($hWndGUI, $MsgID, $wParam, $lParam)
#forceref $hWndGUI, $MsgID, $wParam
Local $hWndFrom, $iCode, $tNMHDR, $hWndListView
If Not IsHWnd($lv) Then $hWndListView = GUICtrlGetHandle($lv)
$tNMHDR = DllStructCreate($tagNMHDR, $lParam)
$hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom"))
$iCode = DllStructGetData($tNMHDR, "Code")
Select
Case $wParam = $lv
Select
Case $iCode = $LVN_COLUMNCLICK
Local $tInfo = DllStructCreate($tagNMLISTVIEW, $lParam)
; Kick off the sort callback
_GUICtrlListView_SortItems($hWndFrom, DllStructGetData($tInfo, "SubItem"))
; No return
Case $iCode = $NM_DBLCLK
CopyCodeArt()
Case Else
$tagNMLISTVIEW1 = DllStructCreate("int;int;int;int;int;uint;uint;uint;int;int;int", $lParam)
Select
Case $iCode = $LVN_BEGINDRAG
Return 1 ; Disable Drag action
EndSelect
EndSelect
EndSelect
$tagNMHDR1 = 0
$iCode = 0
$lParam = 0
EndFunc ;==>WM_Notify_Events