Code : Tout sélectionner
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <GuiToolbar.au3>
#include <StaticConstants.au3>
#include <TabConstants.au3>
#include <ToolbarConstants.au3>
#include <WindowsConstants.au3>
#include <Constants.au3>
#include <SQLite.au3>
#include <SQLite.dll.au3>
#include <ComboConstants.au3>
Global $bdd=@ScriptDir & "\sqbdd.db",$medoc="cachets",$Col=6
Global $page=1
Global $pagemax=1
_SQLite_Startup ()
If @error Then
MsgBox(16, "SQLite Error", "SQLite.dll Can't be Loaded!")
Exit - 1
EndIf
if Not FileExists($bdd) Then
$ex=MsgBox(1,"Erreur","Bdd introuvable " & @CRLF & "Créer une nouvelle ?")
If $ex=1 Then
makebase()
Else
Exit
EndIf
EndIf
$Form1 = GUICreate("BDD", 444, 400);, 199, 298)
$Tab1 = GUICtrlCreateTab(8, 48, 425, 337)
GUICtrlSetResizing(-1, $GUI_DOCKWIDTH+$GUI_DOCKHEIGHT)
$TabSheet2 = GUICtrlCreateTabItem("Operations")
$Label7 = GUICtrlCreateLabel("Rechercher : ", 48, 104, 69, 17)
$Input7 = GUICtrlCreateInput("", 144, 104, 121, 21)
$Button1 = GUICtrlCreateButton("Trouve !", 296, 104, 75, 25, $WS_GROUP)
$Button2 = GUICtrlCreateButton("Ajouter", 56, 192, 75, 25, $WS_GROUP)
$Button3 = GUICtrlCreateButton("Effacer", 176, 192, 75, 25, $WS_GROUP)
$Button4 = GUICtrlCreateButton("Modifier", 296, 192, 75, 25, $WS_GROUP)
$Button6 = GUICtrlCreateButton("Afficher", 176, 144, 75, 25, $WS_GROUP)
$Edit1 = GUICtrlCreateEdit("", 56, 240, 321, 113, BitOR($ES_AUTOVSCROLL,$ES_AUTOHSCROLL,$ES_WANTRETURN,$WS_VSCROLL))
$PPlus = GUICtrlCreateButton(">", 304, 356, 51, 22, $WS_GROUP)
$PMoinS = GUICtrlCreateButton("<", 71, 356, 51, 22, $WS_GROUP)
$Label1 = GUICtrlCreateLabel("Page : ", 160, 360, 102, 17)
GUICtrlCreateTabItem("")
$Label8 = GUICtrlCreateLabel("Base", 32, 16, 28, 17)
$path_base = GUICtrlCreateInput("", 72, 16, 137, 21)
$Label9 = GUICtrlCreateLabel("Nb d'enregistrement", 248, 16, 150, 17)
GUISetState(@SW_SHOW)
vmax()
Afpage($page)
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
_SQLite_Shutdown ()
Exit
Case $Button2
insertbase()
Case $Button3
$id=InputBox("Effacer","Numero d ID")
delentre($id)
Case $PPlus
$page +=1
If $page > $pagemax Then $page -=1
Afpage($page)
GUICtrlSetData($Label1,"Page : " & $page & " / " & $pagemax)
Case $PMoinS
$page -=1
If $page <= 0 Then $page =1
Afpage($page)
GUICtrlSetData($Label1,"Page : " & $page & " / " & $pagemax)
Case $Button6
$id=InputBox("Afficher","Numero d ID")
Afinfo($id)
Case $Button4
$id=InputBox("Modifier","Numero d ID")
modif($id)
Case $Button1
$id=GUICtrlRead($Input7)
If $id="" Then
MsgBox(0,"Erreur","Rien a chercher")
Else
recher($id)
EndIf
EndSwitch
WEnd
; ============================Fonctions
Func vmax()
Local $hQuery, $aRow, $compte
_SQLite_Open ($bdd)
_SQlite_Query (-1, "SELECT count(*)FROM " & $medoc & " ;", $hQuery)
While _SQLite_FetchData ($hQuery, $aRow) = $SQLITE_OK
$compte &= $aRow[0]
WEnd
_SQLite_Close()
GUICtrlSetData($Label9,"Nb d'enregistrement : " & $compte)
GUICtrlSetData($path_base,$bdd)
$pagemax=Ceiling($compte/10)
GUICtrlSetData($Label1,"Page : " & $page & " / " & $pagemax)
EndFunc
Func Afpage($arg)
Local $hQuery, $aRow, $sMsg
$arg=($arg-1)*10
_SQLite_Open ($bdd)
_SQlite_Query (-1, "SELECT * FROM " & $medoc & " LIMIT " & $arg & ",10 ;", $hQuery) ; the query
While _SQLite_FetchData ($hQuery, $aRow) = $SQLITE_OK
$sMsg &= "ID : " & $aRow[0] & ": Nom : " & $aRow[1] & @CRLF
WEnd
_SQLite_Close()
GUICtrlSetData($Edit1,$sMsg)
EndFunc
Func Afinfo($arg)
Local $hQuery, $aRow, $sMsg
_SQLite_Open ($bdd)
_SQlite_Query (-1, "SELECT * FROM " & $medoc & " WHERE id=" & $arg & ";", $hQuery) ; the query
While _SQLite_FetchData ($hQuery, $aRow) = $SQLITE_OK
$sMsg &= "ID : " & $aRow[0] & @CRLF & @CRLF &"Nom : " & $aRow[1] & @CRLF &@CRLF & "Composition : " & $aRow[2]& @CRLF &@CRLF & "Laboratoire : " & $aRow[3]& @CRLF &@CRLF & "Coordonnées labo : " & $aRow[4]& @CRLF &@CRLF & "Proprités : " & $aRow[5]& @CRLF &@CRLF & "Posologie : " & $aRow[6]
WEnd
_SQLite_Close()
If $sMsg="" Then
MsgBox(0,"Erreur","ID introuvable")
Else
$Afi = GUICreate("Produit", 405, 294);, 302, 218)
$Editprod = GUICtrlCreateEdit("", 32, 40, 337, 209)
$Bton1 = GUICtrlCreateButton("Ok", 152, 256, 75, 25, $WS_GROUP)
GUISetState(@SW_SHOW)
GUICtrlSetData($Editprod,$sMsg)
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $Bton1
GUIDelete($Afi)
ExitLoop
EndSwitch
WEnd
EndIf
EndFunc
Func modif($arg)
Local $hQuery, $aRow, $sMsg
_SQLite_Open ($bdd)
_SQlite_Query (-1, "SELECT * FROM " & $medoc & " WHERE id=" & $arg & ";", $hQuery) ; the query
While _SQLite_FetchData ($hQuery, $aRow) = $SQLITE_OK
$sMsg &= $aRow[0] & "|" &$aRow[1] & "|" &$aRow[2] & "|" &$aRow[3] & "|" &$aRow[4] & "|" &$aRow[5] & "|" &$aRow[6]
WEnd
If $sMsg="" Then
MsgBox(0,"Erreur","ID introuvable")
_SQLite_Close()
Else
$aRow=StringSplit($sMsg,"|")
popupinfos()
GUICtrlsetdata($infosI1,$aRow[2])
GUICtrlsetdata($infosI2,$aRow[3])
GUICtrlsetdata($infosI3,$aRow[4])
GUICtrlsetdata($infosI4,$aRow[5])
GUICtrlsetdata($infosI5,$aRow[6])
GUICtrlsetdata($infosI6,$aRow[7])
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $infosB1
$name=_sqlSpecialChars(GUICtrlRead($infosI1))
$Compo=_sqlSpecialChars(GUICtrlRead($infosI2))
$Labo=_sqlSpecialChars(GUICtrlRead($infosI3))
$Adrlab=_sqlSpecialChars(GUICtrlRead($infosI4))
$Propri=_sqlSpecialChars(GUICtrlRead($infosI5))
$Poso=_sqlSpecialChars(GUICtrlRead($infosI6))
If $name & $Compo & $Labo & $Adrlab & $Propri & $Poso ="" Then
MsgBox(0,"","Pas d infos a enregistrer")
GUIDelete($infos)
_SQLite_Close ()
ExitLoop
EndIf
_SQLite_Exec (-1, "UPDATE " & $medoc & " SET NOM='" & $name & "',COMPOSITION='"& $Compo & "',LABORATOIRE='" & $Labo & "',COORLABO='"& $Adrlab &"',PROPRIETES='" & $Propri & "',POSOLOGIE='"& $Poso & "' WHERE id="& $arg & ";")
_SQLite_Close ()
GUIDelete($infos)
vmax()
Afpage($page)
ExitLoop
Case $infosB2
_SQLite_Close()
GUIDelete($infos)
ExitLoop
EndSwitch
WEnd
EndIf
EndFunc
Func delentre($arg)
Local $hQuery, $aRow, $sMsg
_SQLite_Open ($bdd)
_SQlite_Query (-1, "SELECT * FROM " & $medoc & " WHERE id=" & $arg & ";", $hQuery)
While _SQLite_FetchData ($hQuery, $aRow) = $SQLITE_OK
$sMsg &= $aRow[0] & "|" &$aRow[1] & "|" &$aRow[2] & "|" &$aRow[3] & "|" &$aRow[4] & "|" &$aRow[5] & "|" &$aRow[6]
WEnd
If $sMsg="" Then
MsgBox(0,"Erreur","ID introuvable")
_SQLite_Close()
Else
$aRow=StringSplit($sMsg,"|")
popupinfos()
GUICtrlsetdata($infosI1,$aRow[2])
GUICtrlsetdata($infosI2,$aRow[3])
GUICtrlsetdata($infosI3,$aRow[4])
GUICtrlsetdata($infosI4,$aRow[5])
GUICtrlsetdata($infosI5,$aRow[6])
GUICtrlsetdata($infosI6,$aRow[7])
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $infosB1
$req=_SQLite_Exec (-1, "DELETE FROM " & $medoc & " WHERE id="& $arg &";")
_SQLite_Close()
If $req<>$SQLITE_OK Then Exit MsgBox(0,"Erreur","Erreur a l efacement !!")
GUIDelete($infos)
vmax()
Afpage($page)
ExitLoop
Case $infosB2
_SQLite_Close()
GUIDelete($infos)
ExitLoop
EndSwitch
WEnd
EndIf
EndFunc
Func makebase()
_SQLite_Open ($bdd)
If @error > 0 Then Exit MsgBox(16, "SQLite Error", "Impossible de créer la Base de donnée!")
_SQLite_Exec (-1, "CREATE TABLE " & $medoc & " (id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,NOM ,COMPOSITION , LABORATOIRE , COORLABO , PROPRIETES , POSOLOGIE);")
_SQLite_Close ()
EndFunc
Func recher($arg)
Local $hQuery, $aRow, $sMsg,$first,$sMsg
$first=0
_SQLite_Open ($bdd)
_SQlite_Query (-1, "SELECT * FROM " & $medoc & " WHERE NOM LIKE '%"&$arg & "%';", $hQuery) ; the query
While _SQLite_FetchData ($hQuery, $aRow) = $SQLITE_OK
$sMsg &= $aRow[0] & " : " & $aRow[1] & "|"
If $first=0 Then $first=$aRow[0] & " : " & $aRow[1]
WEnd
_SQLite_Close()
If $sMsg="" Then
MsgBox(0,"Recherche","Aucun resultat")
Return
EndIf
$Find = GUICreate("Resultats", 393, 288)
Global $Afres = GUICtrlCreateEdit("", 32, 56, 337, 209)
;$Bt1 = GUICtrlCreateButton("Selection", 296, 24, 75, 25, $WS_GROUP)
$Combo = GUICtrlCreateCombo("", 40, 24, 233, 25)
GUICtrlSetData($Combo,$sMsg,$first)
GUISetState(@SW_SHOW)
$id0=StringSplit(GUICtrlRead($Combo),":")
$id1=$id0[1]
afcombo($id1)
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
GUIDelete($Find)
ExitLoop
Case $Combo
$id0=StringSplit(GUICtrlRead($Combo),":")
$id1=$id0[1]
afcombo($id1)
EndSwitch
WEnd
EndFunc
Func afcombo($arg)
Local $hQuery, $aRow, $sMsg
_SQLite_Open ($bdd)
_SQlite_Query (-1, "SELECT * FROM " & $medoc & " WHERE id=" & $arg & ";", $hQuery) ; the query
While _SQLite_FetchData ($hQuery, $aRow) = $SQLITE_OK
$sMsg &= "ID : " & $aRow[0] & @CRLF & @CRLF &"Nom : " & $aRow[1] & @CRLF &@CRLF & "Composition : " & $aRow[2]& @CRLF &@CRLF & "Laboratoire : " & $aRow[3]& @CRLF &@CRLF & "Coordonnées labo : " & $aRow[4]& @CRLF &@CRLF & "Proprités : " & $aRow[5]& @CRLF &@CRLF & "Posologie : " & $aRow[6]
WEnd
_SQLite_Close()
GUICtrlSetData($Afres,$sMsg)
EndFunc
Func _sqlSpecialChars($in)
$in = StringReplace($in, "'", "''")
$in = StringReplace($in, '\', '\\')
Return $in
EndFunc
Func insertbase()
popupinfos()
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $infosB1
$name=_sqlSpecialChars(GUICtrlRead($infosI1))
$Compo=_sqlSpecialChars(GUICtrlRead($infosI2))
$Labo=_sqlSpecialChars(GUICtrlRead($infosI3))
$Adrlab=_sqlSpecialChars(GUICtrlRead($infosI4))
$Propri=_sqlSpecialChars(GUICtrlRead($infosI5))
$Poso=_sqlSpecialChars(GUICtrlRead($infosI6))
If $name & $Compo & $Labo & $Adrlab & $Propri & $Poso ="" Then
MsgBox(0,"","Pas d infos a enregistrer")
GUIDelete($infos)
Return
EndIf
_SQLite_Open ($bdd)
If @error > 0 Then Exit MsgBox(16, "SQLite Error", "Impossible de lire la Base de donnée!")
_SQLite_Exec (-1, "Insert into " & $medoc & " values (NULL,'" & $name & "','"& $Compo & "','" & $Labo & "','"& $Adrlab &"','" & $Propri & "','"& $Poso & " ');")
_SQLite_Close ()
GUIDelete($infos)
vmax()
Afpage($page)
ExitLoop
Case $infosB2
GUIDelete($infos)
ExitLoop
EndSwitch
WEnd
EndFunc
Func popupinfos()
Global $infos=GUICreate("Infos", 459, 250);, 211, 351)
Global $infosL1 = GUICtrlCreateLabel("NOM", 24, 24, 29, 17)
Global $infosL2 = GUICtrlCreateLabel("COMPOSITION", 24, 54, 79, 17)
Global $infosL3 = GUICtrlCreateLabel("LABORATOIRE", 24, 84, 80, 17)
Global $infosL4 = GUICtrlCreateLabel("COORDONNEES LABO", 24, 114, 119, 17)
Global $infosL5 = GUICtrlCreateLabel("PROPRIETES", 24, 144, 73, 17)
Global $infosL6 = GUICtrlCreateLabel("POSOLOGIE RECOMMANDEE", 24, 174, 154, 17)
Global $infosI1 = GUICtrlCreateInput("", 200, 24, 169, 21)
Global $infosI2 = GUICtrlCreateInput("", 200, 54, 241, 21)
Global $infosI3 = GUICtrlCreateInput("", 200, 84, 241, 21)
Global $infosI4 = GUICtrlCreateInput("", 200, 114, 241, 21)
Global $infosI5 = GUICtrlCreateInput("", 200, 144, 241, 21)
Global $infosI6 = GUICtrlCreateInput("", 200, 174, 241, 21)
Global $infosB1 = GUICtrlCreateButton("Ok", 120, 216, 75, 25, $WS_GROUP)
Global $infosB2 = GUICtrlCreateButton("Annule", 224, 216, 75, 25, $WS_GROUP)
GUISetState(@SW_SHOW)
EndFunc