Untitled

 avatar
unknown
python
2 months ago
3.0 kB
1
Indexable
import tkinter as tk
from tkinter import ttk
import sqlite3

# récupère les informations du stock
def get_stock_info():
    conn = sqlite3.connect("db.sqlite")
    cursor = conn.cursor()
    cursor.execute("SELECT * FROM articles")
    articles = cursor.fetchall()
    conn.close()
    return articles

# récupère les informations des commandes
def get_order_info():
    conn = sqlite3.connect("db.sqlite")
    cursor = conn.cursor()
    cursor.execute("""
        SELECT commandes.id, commandes.nom_client, commandes.prenom_client, commandes.adresse, 
               commandes.telephone, articles.nom, commandes.quantite
        FROM commandes
        JOIN articles ON commandes.article_id = articles.id
    """)
    commandes = cursor.fetchall()
    conn.close()
    return commandes

# application principale pour l'administration
class AdminApp:
    def __init__(self, root):
        self.root = root
        self.root.title("Administration - Gestion des stocks et commandes")
        self.root.geometry("800x600")
        
        # crée les onglets pour le stock et les commandes
        self.tab_control = ttk.Notebook(root)
        self.stock_tab = ttk.Frame(self.tab_control)
        self.orders_tab = ttk.Frame(self.tab_control)
        
        self.tab_control.add(self.stock_tab, text="Stock restant")
        self.tab_control.add(self.orders_tab, text="Commandes à traiter")
        self.tab_control.pack(expand=1, fill="both")
        
        # affiche le stock et les commandes
        self.display_stock()
        self.display_orders()
    
    # affiche les informations du stock dans un tableau
    def display_stock(self):
        stock_info = get_stock_info()
        
        columns = ("ID", "Catégorie", "Nom", "Couleur", "Tailles", "Prix", "Quantité", "Image")
        tree = ttk.Treeview(self.stock_tab, columns=columns, show="headings")
        
        # configure les colonnes
        for col in columns:
            tree.heading(col, text=col)
            tree.column(col, width=100, anchor="center")
        
        # ajoute les articles dans le tableau
        for article in stock_info:
            tree.insert("", tk.END, values=article)
        
        tree.pack(expand=1, fill="both", padx=10, pady=10)
    
    # affiche les commandes dans un tableau
    def display_orders(self):
        orders_info = get_order_info()
        
        columns = ("ID", "Nom", "Prénom", "Adresse", "Téléphone", "Article", "Quantité")
        tree = ttk.Treeview(self.orders_tab, columns=columns, show="headings")
        
        # configure les colonnes
        for col in columns:
            tree.heading(col, text=col)
            tree.column(col, width=100, anchor="center")
        
        # ajoute les commandes dans le tableau
        for order in orders_info:
            tree.insert("", tk.END, values=order)
        
        tree.pack(expand=1, fill="both", padx=10, pady=10)

# lance l'application
if __name__ == "__main__":
    root = tk.Tk()
    app = AdminApp(root)
    root.mainloop()
Leave a Comment