0% found this document useful (0 votes)
8 views6 pages

Cafe Management Class 12

Uploaded by

Dinesh Karan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views6 pages

Cafe Management Class 12

Uploaded by

Dinesh Karan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 6

Creating a simple café management system with Python and MySQL involves several components,

including database setup, Python scripts for the backend, and a basic interface (either console-based or
using a GUI framework like Tkinter). Below is a simplified version of how you might structure such a
project.

### Step 1: Setting Up MySQL Database

First, you need to set up a MySQL database. You can use the following SQL commands to create a simple
database for the café management system.

```sql

CREATE DATABASE cafe_management;

USE cafe_management;

CREATE TABLE menu (

id INT AUTO_INCREMENT PRIMARY KEY,

item_name VARCHAR(255) NOT NULL,

price DECIMAL(10, 2) NOT NULL,

stock INT NOT NULL

);

CREATE TABLE orders (

id INT AUTO_INCREMENT PRIMARY KEY,

item_id INT,

quantity INT,

order_date DATETIME DEFAULT CURRENT_TIMESTAMP,


FOREIGN KEY (item_id) REFERENCES menu(id)

);

```

### Step 2: Installing Required Packages

Make sure you have the `mysql-connector-python` package installed. You can install it using pip:

```bash

pip install mysql-connector-python

```

### Step 3: Python Code

Here's a basic example of a Python script for managing the café's menu and orders:

```python

import mysql.connector

from mysql.connector import Error

def create_connection():

connection = None

try:

connection = mysql.connector.connect(

host='localhost',
user='root',

password='123456789',

database='cafe_management'

print("Connection to MySQL DB successful")

except Error as e:

print(f"The error '{e}' occurred")

return connection

def add_menu_item(connection, item_name, price, stock):

cursor = connection.cursor()

query = "INSERT INTO menu (item_name, price, stock) VALUES (%s, %s, %s)"

cursor.execute(query, (item_name, price, stock))

connection.commit()

cursor.close()

def view_menu(connection):

cursor = connection.cursor()

cursor.execute("SELECT * FROM menu")

rows = cursor.fetchall()

for row in rows:

print(row)

cursor.close()

def place_order(connection, item_id, quantity):


cursor = connection.cursor()

query = "INSERT INTO orders (item_id, quantity) VALUES (%s, %s)"

cursor.execute(query, (item_id, quantity))

connection.commit()

cursor.close()

def main():

connection = create_connection()

while True:

print("\nCafé Management System")

print("1. Add Menu Item")

print("2. View Menu")

print("3. Place Order")

print("4. Exit")

choice = input("Choose an option: ")

if choice == '1':

item_name = input("Enter item name: ")

price = float(input("Enter item price: "))

stock = int(input("Enter item stock: "))

add_menu_item(connection, item_name, price, stock)

elif choice == '2':


view_menu(connection)

elif choice == '3':

item_id = int(input("Enter item ID to order: "))

quantity = int(input("Enter quantity: "))

place_order(connection, item_id, quantity)

elif choice == '4':

break

else:

print("Invalid choice. Please try again.")

connection.close()

if __name__ == "__main__":

main()

```

### Step 4: Notes

- **Connection Handling**: The `create_connection` function handles connecting to the MySQL


database. Ensure you replace `your_username` and `your_password` with your actual MySQL
credentials.

- **Error Handling**: Basic error handling is included to catch connection issues.

- **Menu Management**: You can add items to the menu and view the current menu items.

- **Order Management**: Allows placing orders based on the menu items.


- **Exit Option**: The loop continues until the user chooses to exit.

### Step 5: Running the Program

1. Start your MySQL server.

2. Create the database and tables using the provided SQL script.

3. Run the Python script in your terminal or command prompt.

This code provides a foundational structure, which you can expand with features like updating menu
items, removing items, or generating reports based on orders.

You might also like