1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86
| import sqlite3
#import creation
# import cartouche
# import ajout_supp
import tkinter
from pathlib import Path
import os
#cart = cartouche.Cartouches()
def valider_scan(entry_code_barre):
# recuperation du code barre
code_barre = entry_code_barre.get()
# vidage de l'entry
entry_code_barre.delete(0, 'end')
# connexion bdd
chemin_bdd = "cartouche.db"
connection = sqlite3.connect(chemin_bdd)
curseur = connection.cursor()
# test si le code barre existe
nb_ligne = curseur.execute("""SELECT COUNT(*) FROM cartouches WHERE code_barre=?""", (code_barre, )).fetchone()[0]
print(f'{nb_ligne=}')
if nb_ligne == 0:
# # s'il n existe pas on ajoute
# creation.creation_cartouche(cart)
curseur.execute("""INSERT INTO cartouches(nom, type, quantite, code_barre) VALUES(?, ?, ?, ?)""", ('nom', 'type', 1, code_barre))
connection.commit()
else:
# si le code barre existe on demande si on ajoute ou en supprime
#ajout_supp.ajout_supp_cartouche(cart)
# recupere le nombre de cartouche
row = curseur.execute("""SELECT * FROM cartouches WHERE code_barre=?""", (code_barre,)).fetchone()
print(f'{row}')
nb_cartouche = curseur.execute("""SELECT quantite FROM cartouches WHERE code_barre=?""", (code_barre,)).fetchone()[0]
# if cart.ajout == "ajout":
# # on ajoute une cartouche
nb_cartouche += 1
# on met a jour la valeur dans la bdd
curseur.execute("""UPDATE cartouches SET quantite=? WHERE code_barre=?""", (nb_cartouche, code_barre))
connection.commit()
# if cart.ajout == "supp":
# # on supprime une cartouche
# nb_cartouche -= 1
# # on met a jour la valeur dans la bdd
# curseur.execute("""UPDATE cartouches SET quantite=? WHERE code_barre=?""", (nb_cartouche, code_barre))
# connection.commit()
# fermeture de la bdd
connection.close()
"""
fenetre principale
"""
if __name__ == '__main__':
chemin_bdd = "cartouche.db"
if not os.path.exists(chemin_bdd):
with sqlite3.connect(chemin_bdd) as c:
c.execute('CREATE TABLE cartouches(nom, type, quantite, code_barre)')
win_scan = tkinter.Tk()
win_scan.title("scan des codes barres des cartouches")
win_scan.geometry("400x100")
label_scan = tkinter.Label(win_scan, text="en attente de scan ...")
entry_scan = tkinter.Entry(win_scan)
label_scan.pack(padx=10, pady=10)
entry_scan.pack(padx=10, pady=10)
# permet d'entrer dans le entry
entry_scan.focus_set()
entry_scan.bind('<Return>',lambda e: valider_scan(entry_scan))
win_scan.mainloop() |
Partager