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


import psycopg2

# ПОДСТАВЬ СВОИ ДАННЫЕ ДЛЯ ПОДКЛЮЧЕНИЯ К БАЗЕ ДАННЫХ
DB_CONFIG = {
    "dbname": "publishing_center",   # название твоей БД
    "user": "postgres",              # твой пользователь
    "password": "123456",            # твой пароль
    "host": "localhost",
    "port": 5432
}

def show_all_orders():
    try:
        conn = psycopg2.connect(**DB_CONFIG)
        cur = conn.cursor()
        
        # Вытаскиваем все заказы с данными книг и заказчиков
        cur.execute("""
            SELECT 
                o.order_id,
                o.order_date,
                o.execute_date,
                o.quantity,
                b.title AS book_title,
                b.sale_price,
                c.name AS customer_name,
                c.phone AS customer_phone
            FROM orders o
            JOIN book b ON o.book_code = b.book_code
            JOIN customer c ON o.customer_id = c.customer_id
            ORDER BY o.order_date DESC;
        """)
        
        rows = cur.fetchall()
        cur.close()
        conn.close()
        
        if not rows:
            print("Заказов нет.")
            return
        
        print("\n" + "="*80)
        print("ВСЕ ЗАКАЗЫ В СИСТЕМЕ")
        print("="*80)
        
        for order in rows:
            order_id, order_date, execute_date, qty, title, price, cust_name, cust_phone = order
            print(f"\nЗаказ №{order_id}")
            print(f"  Заказчик: {cust_name} (тел: {cust_phone})")
            print(f"  Книга: {title}")
            print(f"  Количество: {qty} шт.")
            print(f"  Цена за шт.: {price:.2f} руб.")
            print(f"  Дата заказа: {order_date}")
            print(f"  Дата выполнения: {execute_date if execute_date else 'ЕЩЁ НЕ ВЫПОЛНЕН'}")
            print("-"*40)
            
    except Exception as e:
        print(f"ОШИБКА: {e}")
        print("Проверь настройки подключения к БД!")

# ЗАПУСК
if __name__ == "__main__":
    show_all_orders()
    input("\nНажми Enter для выхода...")  # чтобы окно не закрылось сразу