و هذا كود البرنامج
لقد قمت ببعض التعديلات لكنها لم تعمل مثل تاريخ إنهاء الدواء لم اعرف كيف اجعلها تظهر في واجهة البرنامج ليس داخل الفاتورة
import sqlite3
import tkinter as tk
from tkinter import Label, Button, Entry, StringVar, messagebox, Text, ttk
from datetime import datetime, timedelta
root = tk.Tk()
root.title("Medicine Management")
root.resizable(0, 0)
root.configure(bg="#333333")
def start_application():
login_window = tk.Toplevel(root)
login_window.title("Login")
login_window.geometry("500x400")
login_window.resizable(0, 0)
login_window.configure(bg="#333333")
def create_table():
connection = sqlite3.connect("medicine_database.db")
cursor = connection.cursor()
cursor.execute("""
CREATE TABLE IF NOT EXISTS medicines (
id INTEGER PRIMARY KEY AUTOINCREMENT,
name TEXT,
prix_u REAL,
ppa REAL,
date TEXT,
expiry_date TEXT
)
""")
connection.commit()
connection.close()
def add_medicine(name, prix_u, ppa, date, expiry_date):
connection = sqlite3.connect("medicine_database.db")
cursor = connection.cursor()
cursor.execute("SELECT COUNT(*) FROM medicines")
count = cursor.fetchone()[0]
medicine_number = count + 1
name_with_number = f"{medicine_number}. {name}"
cursor.execute("""
INSERT INTO medicines (name, prix_u, ppa, date, expiry_date)
VALUES (?, ?, ?, ?, ?)
""", (name_with_number, prix_u, ppa, date, expiry_date))
connection.commit()
connection.close()
return name_with_number
def calculate_expiry_date(start_date, months):
start_date = datetime.strptime(start_date, "%d/%m/%Y")
expiry_date = start_date + timedelta(days=30 * months)
return expiry_date.strftime("%Y-%m-%d")
def print_invoice(medicine):
total_price = medicine[2] + medicine[3] # Prix U + PPA
invoice_text.delete(1.0, 'end') # Clear previous content
invoice_text.insert('end', f"Number: {medicine[0]}\n")
invoice_text.insert('end', f"Name: {medicine[1]}\n")
invoice_text.insert('end', f"Prix U: {medicine[2]}\n")
invoice_text.insert('end', f"PPA: {medicine[3]}\n")
invoice_text.insert('end', f"Total Price: {total_price}\n")
messagebox.showinfo("Invoice", "Invoice details are displayed in the table below.")
def save_medicine():
name = name_entry.get()
prix_u = float(prix_u_entry.get())
ppa = float(ppa_entry.get())
date = date_entry.get()
start_date = start_date_entry.get()
months = int(months_entry.get())
expiry_date = calculate_expiry_date(start_date, months)
added_medicine_name = add_medicine(name, prix_u, ppa, date, expiry_date)
connection = sqlite3.connect("medicine_database.db")
cursor = connection.cursor()
cursor.execute("SELECT * FROM medicines ORDER BY id DESC LIMIT 1")
last_medicine = cursor.fetchone()
connection.close()
if last_medicine:
# Print invoice
print_invoice(last_medicine)
total_price = last_medicine[2] + last_medicine[3] # Prix U + PPA
# Update Treeview
invoice_tree.insert("", "end", values=(
last_medicine[0], last_medicine[1], last_medicine[2],
last_medicine[3], total_price, last_medicine[4]
))
else:
messagebox.showerror("Error", "No medicine found.")
name_var = StringVar()
prix_u_var = StringVar()
ppa_var = StringVar()
date_var = StringVar()
start_date_var = StringVar()
months_var = StringVar()
Label(root, text="Medicine Name:", bg="#333333", fg="#2af708").grid(row=0, column=0, padx=10, pady=10)
name_entry = Entry(root, textvariable=name_var)
name_entry.grid(row=0, column=1, padx=10, pady=10)
Label(root, text="Prix U:", bg="#333333", fg="#2af708").grid(row=1, column=0, padx=10, pady=10)
prix_u_entry = Entry(root, textvariable=prix_u_var)
prix_u_entry.grid(row=1, column=1, padx=10, pady=10)
Label(root, text="PPA:", bg="#333333", fg="#2af708").grid(row=2, column=0, padx=10, pady=10)
ppa_entry = Entry(root, textvariable=ppa_var)
ppa_entry.grid(row=2, column=1, padx=10, pady=10)
Label(root, text="Manufacture Date:", bg="#333333", fg="#2af708").grid(row=3, column=0, padx=10, pady=10)
date_entry = Entry(root, textvariable=date_var)
date_entry.grid(row=3, column=1, padx=10, pady=10)
Label(root, text="Start Date:", bg="#333333", fg="#2af708").grid(row=4, column=0, padx=10, pady=10)
start_date_entry = Entry(root, textvariable=start_date_var)
start_date_entry.grid(row=4, column=1, padx=10, pady=10)
Label(root, text="Months for Expiry:", bg="#333333", fg="#2af708").grid(row=5, column=0, padx=10, pady=10)
months_entry = Entry(root, textvariable=months_var)
months_entry.grid(row=5, column=1, padx=10, pady=10)
Button(root, text="Add Medicine", command=save_medicine).grid(row=6, column=0, columnspan=2, pady=10)
invoice_text = Text(root, height=10, width=50, wrap='word', bg="#FFFFFF")
invoice_text.grid(row=7, column=0, columnspan=2, padx=10, pady=10)
invoice_tree = ttk.Treeview(root, columns=("Number", "Name", "Prix U", "PPA", "Total Price", "Sale Date"),
show="headings")
invoice_tree.heading("Number", text="Number")
invoice_tree.heading("Name", text="Name")
invoice_tree.heading("Prix U", text="Prix U")
invoice_tree.heading("PPA", text="PPA")
invoice_tree.heading("Total Price", text="Total Price")
invoice_tree.heading("Sale Date", text="Sale Date")
invoice_tree.grid(row=8, column=0, columnspan=2, padx=10, pady=10)
create_table()
root.mainloop()