Загрузка данных


import tkinter as tk
from tkinter import messagebox
from bd import get_connection

def open_catalog(role, full_name):
    login_window.destroy()
    catalog = tk.Tk()
    catalog.title(f"ООО Обувь — товары ({role})")
    catalog.geometry("600x400")
    catalog.configure(bg="white")

    tk.Label(catalog, text=f"Вы вошли как: {full_name} ({role})", bg="white", font=("Times New Roman", 12)).pack(pady=10)

    conn = get_connection()
    cur = conn.cursor()
    cur.execute("SELECT article, name, price, category, stock_qty FROM products ORDER BY name")
    products = cur.fetchall()
    conn.close()

    list_frame = tk.Frame(catalog, bg="white")
    list_frame.pack(fill="both", expand=True, padx=10)

    header = tk.Label(list_frame, text=f"{'Артикул':<10}{'Название':<20}{'Цена':<10}{'Категория':<18}{'Кол-во'}", bg="white", font=("Courier New", 10, "bold"))
    header.pack(anchor="w")

    for article, name, price, category, qty in products:
        line = f"{article:<10}{name:<20}{str(price):<10}{category:<18}{qty}"
        tk.Label(list_frame, text=line, bg="white", font=("Courier New", 10)).pack(anchor="w")

    catalog.mainloop()

def check_login(login_entry, password_entry):
    login = login_entry.get()
    password = password_entry.get()
    conn = get_connection()
    cur = conn.cursor()
    cur.execute("SELECT id, role, full_name FROM users WHERE login = %s AND password = %s", (login, password))
    user = cur.fetchone()
    conn.close()
    if user:
        open_catalog(user[1], user[2])
    else:
        messagebox.showerror("Ошибка", "Неверный логин или пароль")

login_window = tk.Tk()
login_window.title("ООО Обувь — вход")
login_window.geometry("300x260")
login_window.configure(bg="white")

tk.Label(login_window, text="Логин", bg="white", font=("Times New Roman", 11)).pack(pady=(20, 0))
login_entry = tk.Entry(login_window, font=("Times New Roman", 11))
login_entry.pack()

tk.Label(login_window, text="Пароль", bg="white", font=("Times New Roman", 11)).pack(pady=(10, 0))
password_entry = tk.Entry(login_window, show="*", font=("Times New Roman", 11))
password_entry.pack()

tk.Button(login_window, text="Войти", bg="#00FA9A", font=("Times New Roman", 11), command=lambda: check_login(login_entry, password_entry)).pack(pady=20)

tk.Button(login_window, text="Продолжить как гость", bg="white", font=("Times New Roman", 9, "underline"), relief="flat", command=lambda: open_catalog("Гость", "Гость")).pack()

login_window.mainloop()