J'ai un petit soucis avec la recherche dans une bdd avec sqlite...
Code : Tout sélectionner
_SQlite_Query (-1, "SELECT * FROM produit WHERE cb1='910-000199';", $hQuery)Je galère depuis hier à essayer de lire des tuto sur SQL, mais j'ai l’impression de bien le faire pourtant...
Bref, si vous avez une idée/solution
Merci !
Le code complet si besoin : (tout en bas dans la fonction scan)(y'a beaucoup de chose très moche dedans, mais pour le moment, j'essaye juste d'avoir un truc qui fonctionne. Je rajouterais les contrôles par la suite
Code : Tout sélectionner
[spoiler=]#cs ----------------------------------------------------------------------------
AutoIt Version : 3.3.8.0
Auteur: MonNom
Fonction du Script :
Modèle de Script AutoIt.
#ce ----------------------------------------------------------------------------
; Début du script - Ajouter votre code ci-dessous.
#include <SQLite.au3>
#include <SQLite.dll.au3>
#include <ButtonConstants.au3>
#include <ComboConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
;--------------------------------------
;Variable
;--------------------------------------
Local $hQuery, $aRow, $aNames
;--------------------------------------
;DEMARRAGE TABLE SQL
;--------------------------------------
_SQLite_Startup ()
If @error > 0 Then Exit MsgBox(16, "SQLite Error", "SQLite.dll Can't be Loaded!")
$bdd=_SQLite_Open ("bdd")
If @error > 0 Then Exit MsgBox(16, "SQLite Error", "Can't Load Database!")
_SQLite_Exec (-1, "CREATE TABLE IF NOT EXISTS fournisseur (id INTEGER PRIMARY KEY AUTOINCREMENT ,nom ,code);")
_SQLite_Exec (-1, "CREATE TABLE IF NOT EXISTS marque (id INTEGER PRIMARY KEY AUTOINCREMENT ,nom);")
_SQLite_Exec (-1, "CREATE TABLE IF NOT EXISTS categorie (id INTEGER PRIMARY KEY AUTOINCREMENT ,nom);")
_SQLite_Exec (-1, "CREATE TABLE IF NOT EXISTS produit (id INTEGER PRIMARY KEY AUTOINCREMENT ,nom,cb1,cb2,marque,categorie,fourniseur,pa,pv,stock,date);")
#Region ### START Koda GUI section ### Form=z:\mes documents\surprises\base de donnée stock douchette\form1.kxf
Global $Form1_1 = GUICreate("BDD Stock", 623, 508, 192, 124)
Global $Input1 = GUICtrlCreateInput("", 16, 72, 273, 21)
Global $Button5 = GUICtrlCreateButton("Scan", 168, 98, 121, 25)
Global $Label1 = GUICtrlCreateLabel("Code barre 1 :", 16, 104, 71, 17)
Global $Label2 = GUICtrlCreateLabel("Produit :", 16, 48, 71, 17)
Global $Label3 = GUICtrlCreateLabel("Code barre 2 :", 16, 160, 71, 17)
Global $Input2 = GUICtrlCreateInput("", 16, 128, 273, 21)
Global $Input3 = GUICtrlCreateInput("", 16, 184, 273, 21)
Global $Label4 = GUICtrlCreateLabel("Catégorie :", 16, 224, 55, 17)
Global $Combo1 = GUICtrlCreateCombo("", 16, 248, 273, 25, BitOR($CBS_DROPDOWN,$CBS_AUTOHSCROLL))
Global $Radio1 = GUICtrlCreateRadio("Recherche", 16, 16, 73, 25)
GUICtrlSetState(-1, $GUI_CHECKED)
Global $Radio2 = GUICtrlCreateRadio("Ajout", 104, 16, 57, 25)
Global $Button1 = GUICtrlCreateButton("Valider", 168, 16, 121, 25)
Global $Label5 = GUICtrlCreateLabel("Marque :", 16, 281, 54, 17)
Global $Combo3 = GUICtrlCreateCombo("", 16, 304, 273, 25, BitOR($CBS_DROPDOWN,$CBS_AUTOHSCROLL))
Global $Input7 = GUICtrlCreateInput("", 16, 416, 137, 21)
Global $Label6 = GUICtrlCreateLabel("Prix achat HT :", 16, 392, 75, 17)
Global $Label7 = GUICtrlCreateLabel("Marge :", 168, 392, 90, 17)
Global $Input4 = GUICtrlCreateInput("1.3", 168, 416, 121, 21)
Global $Label8 = GUICtrlCreateLabel("Tarif auto :", 16, 448, 55, 17)
Global $Input5 = GUICtrlCreateInput("", 16, 472, 137, 21)
Global $Label9 = GUICtrlCreateLabel("Prix de vente : ", 168, 448, 75, 17)
Global $Input6 = GUICtrlCreateInput("", 168, 472, 121, 21)
Global $Label10 = GUICtrlCreateLabel("Fournisseurs :", 16, 336, 85, 17)
Global $Combo2 = GUICtrlCreateCombo("", 16, 360, 273, 25, BitOR($CBS_DROPDOWN,$CBS_AUTOHSCROLL))
Global $Button2 = GUICtrlCreateButton("Ajouter catégorie", 112, 216, 177, 25)
Global $Button3 = GUICtrlCreateButton("Ajouter marque", 112, 272, 177, 25)
Global $Button4 = GUICtrlCreateButton("Ajouter fournisseur", 112, 328, 177, 25)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
;--------------------------------------
;Chargement des Combo
;--------------------------------------
_liste_fourniseur()
_liste_marque()
_liste_categorie()
;--------------------------------------
;boucle
;--------------------------------------
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
_SQLite_Close()
_SQLite_Shutdown()
Exit
case $Button1
_bouton_valider()
case $Button5
_scan()
case $Button2
_ajout_cat()
case $Button3
_ajout_marque()
case $Button4
_ajout_fournisseur()
EndSwitch
;~ $Input4 ; Valeur marge
;~ $Input5 ; tarif auto
;~ $Input7 ; tarif HT
;~ $Input6 ; prix de vente
;~ $Label7 ; marge
$tarif_auto = GUICtrlRead($Input7) * GUICtrlRead($Input4) * 1.196
$marge_auto = GUICtrlRead($Input6) - ( GUICtrlRead($Input7) * 1.196)
GUICtrlSetData($Input5, $tarif_auto )
GUICtrlSetData($Label7, "Marge : " & int($marge_auto) & " €" )
sleep(50)
WEnd
;--------------------------------------
;Fonctions
;--------------------------------------
;~ ------------------------------------ Ajout Catégorie
func _ajout_cat()
$input = InputBox("Ajout", "Entrez la catégorie à ajouter :")
if $input = "" Then
MsgBox(0,"","Veuillez remplir tout les champs.")
Else
_SQLite_Exec (-1, "Insert into categorie (nom) values ('" & $input & " ');")
EndIf
_liste_categorie()
EndFunc
;~ ------------------------------------ Ajout Marque
func _ajout_marque()
$input = InputBox("Ajout", "Entrez la marque à ajouter :")
if $input = "" Then
MsgBox(0,"","Veuillez remplir tout les champs.")
Else
_SQLite_Exec (-1, "Insert into marque (nom) values ('" & $input & " ');")
EndIf
_liste_marque()
EndFunc
;~ ------------------------------------ Ajout Fourniseur
func _ajout_fournisseur()
$input = InputBox("Ajout", "Entrez le fournisseur à ajouter :")
$input2 = InputBox("Ajout", "Entrez le code fournisseur :")
if $input = "" Or $input2 = "" Then
MsgBox(0,"","Veuillez remplir tout les champs.")
Else
_SQLite_Exec (-1, "Insert into fournisseur (nom,code) values ('" & $input & "','"& $input2 & " ');")
_liste_fourniseur()
EndIf
EndFunc
;~ ------------------------------------ Listing Fourniseur
func _liste_fourniseur()
_SQLite_Query(-1, "SELECT ROWID,* FROM fournisseur ORDER BY code;", $hQuery)
_SQLite_FetchNames($hQuery, $aNames)
$combo_content = ""
GUICtrlSetData($combo2, $combo_content); vidage du combo
While _SQLite_FetchData($hQuery, $aRow, False, False) = $SQLITE_OK ; Read Out the next Row
;~ _ArrayDisplay($aRow)
$combo_content &= $aRow[2]& " - " & $aRow[3]&"|"
WEnd
GUICtrlSetData($combo2, $combo_content)
EndFunc
;~ ------------------------------------ Listing Categorie
func _liste_categorie()
_SQLite_Query(-1, "SELECT ROWID,* FROM categorie ORDER BY nom;", $hQuery)
_SQLite_FetchNames($hQuery, $aNames)
$combo_content = ""
GUICtrlSetData($combo1, $combo_content); vidage du combo
While _SQLite_FetchData($hQuery, $aRow, False, False) = $SQLITE_OK ; Read Out the next Row
;~ _ArrayDisplay($aRow)
$combo_content &= $aRow[2]&"|"
WEnd
GUICtrlSetData($combo1, $combo_content)
EndFunc
;~ ------------------------------------ Listing Marque
func _liste_marque()
_SQLite_Query(-1, "SELECT ROWID,* FROM marque ORDER BY nom;", $hQuery)
_SQLite_FetchNames($hQuery, $aNames)
$combo_content = ""
GUICtrlSetData($combo3, $combo_content); vidage du combo
While _SQLite_FetchData($hQuery, $aRow, False, False) = $SQLITE_OK ; Read Out the next Row
;~ _ArrayDisplay($aRow)
$combo_content &= $aRow[2]&"|"
WEnd
GUICtrlSetData($combo3, $combo_content)
EndFunc
;~ ------------------------------------ Fonction bouton valider
func _bouton_valider()
if GUICtrlRead($Radio1) = 1 Then
_recherche()
ElseIf GUICtrlRead($Radio2) = 1 Then
_ajout_produit()
EndIf
EndFunc
;~ ------------------------------------ Fonction Recherche
func _recherche()
msgbox(0,"","Recherche")
EndFunc
;~ ------------------------------------ Fonction Ajout produit
func _ajout_produit()
$produit = GUICtrlRead($Input1) ; produit
$cb1 = GUICtrlRead($Input2) ;code barre 1
$cb2 = GUICtrlRead($Input3) ;code barre 2
$c1 = GUICtrlRead($Combo1) ;categorie
$c2 = GUICtrlRead($Combo2) ;fourniseur
$c3 = GUICtrlRead($Combo3) ;marque
$PA = GUICtrlRead($Input7) ;Prix Achat
$PV = GUICtrlRead($Input6) ;Prix vente
$stock = 0
$date = 0
MsgBox(0,"Résumé", "Produit = " & $produit & " ;" & @CRLF & "Code Barre 1 = " & $cb1 & " ;" & @CRLF & "Code Barre 2 = " & $cb2 & " ;" & @CRLF &"Catégorie = " & $c1 & " ;" & @CRLF &"Marque = " & $c3 & " ;" & @CRLF &"Fournisseur = " & $c2 & " ; " )
_SQLite_Exec (-1, "Insert into produit (nom,cb1,cb2,marque,categorie,fourniseur,pa,pv,stock,date) values ('" & $produit & "','"& $cb1 & " ','"& $cb2 & " ','"& $c3 & " ','"& $c1 & " ','"& $c2 & " ','"& $PA & " ','"& $PV & " ','"& $stock & " ','"& $date & " ');")
EndFunc
;~ ------------------------------------ Fonction Scan
func _scan()
;~ if GUICtrlRead($Input2) = "910-000199" Then
;~ GUICtrlSetData($Input1, "Rx250") ;produit
;~ GUICtrlSetData($Input3, "5099206003873");code barre 2
;~ EndIf
$valeur = GUICtrlRead($Input2)
;~ _SQLite_Query(-1, "SELECT ROWID,* FROM produit ORDER BY nom;", $hQuery)
;~ _SQlite_Query (-1, "SELECT * FROM produit WHERE cb1=" & $valeur & ";", $hQuery)
_SQlite_Query (-1, "SELECT * FROM produit WHERE cb1='910-000199';", $hQuery)
_SQLite_FetchNames($hQuery, $aNames)
While _SQLite_FetchData($hQuery, $aRow, False, False) = $SQLITE_OK ; Read Out the next Row
_ArrayDisplay($aRow)
WEnd
EndFunc
[/spoiler]

