Cafe Management Code
Cafe Management Code
connector
# Connect to MySQL
def connect():
return mysql.connector.connect(
host="localhost",
user="root",
password="Tiger",
database="cafe_db"
)
mysql.connector.connect(host="localhost",user="root",password="Tiger",database="sto
ck_management")
name = input("Enter item name: ")
quantity = int(input("Enter quantity: "))
price=float(input("Enter price:"))
cursor.execute("INSERT INTO menu(name, quantity,price)VALUES(%s ,%s,%s)",(name,
quantity,price))
print("Item added successfully")
mysql.connector.connect(host="localhost",user="root",password="Tiger",database="sto
ck_management")
item_id = int(input("Enter item ID to update: "))
new_quantity = int(input("Enter new quantity: "))
new_price=float(input("enter the new price:"))
cursor.execute("UPDATE menu SET quantity = %s WHERE id = %s", (new_quantity,
item_id))
cursor.execute("UPDATE menu SET price= %s WHERE id = %s", (new_price, item_id))
print("Item updated successfully")
# Delete item
def delete_item(cursor):
mysql.connector.connect(host="localhost",user="root",password="Tiger",database="sto
ck_management")
item_id = int(input("Enter item ID to delete: "))
cursor.execute("DELETE FROM menu WHERE id = %s", (item_id,))
print("Item deleted successfully")
mysql.connector.connect(host="localhost",user="root",password="Tiger",database="sto
ck_management")
cursor.execute("SELECT * FROM menu")
menu = cursor.fetchall()
count=cursor.rowcount
print("total number of rows retrieved in resultset:",count)
if not menu:
print("No items found")
else:
for item in menu:
print(f"ID: {item[0]}, Name: {item[1]}, Quantity: {item[2]},price:
{item[3]}")
# Main menu
def main_menu():
print("\n Cafe Management System")
print("1.Add Items")
print("2. Update order")
print("3. Delete Item")
print("4. View Items")
print("5. Exit")
# Main function
def main():
conn = connect()
cursor = conn.cursor()
create_table(cursor)
while True:
main_menu()
choice = input("Enter your choice: ")
if choice == "1":
add_item(cursor)
elif choice == "2":
update_item(cursor)
elif choice == "3":
delete_item(cursor)
elif choice == "4":
view_items(cursor)
elif choice == "5":
break
else:
print("Invalid choice")
conn.commit()
conn.close()
print("Thank you for using the Cafe Management System")
if __name__ == "__main__":
main()