0% found this document useful (0 votes)
16 views13 pages

Python Restuarant Mangemtn System

Uploaded by

khatri's Arts
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
16 views13 pages

Python Restuarant Mangemtn System

Uploaded by

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

RESTAURANT MANAGEMENT

SYSTEM IN PYTHON WITH SQL

SUYASH KHATRI
RESTAURANT MANAGEMENT SYSTEM
RESTAURANT MANAGEMENT SYSTEM

import mysql.connector

from mysql.connector import Error

def create_connection():

try:

connection = mysql.connector.connect(

host='localhost',

database='resturant_db',

user='ENTER YOUR USER NAME HERE ',

password='ENTER YOUR MYSQL PASSWORD HERE',

charset='utf8'

if connection.is_connected():

print("Connected to MySQL database")

return connection

except Error as e:

print(f"Error: '{e}'")

return None

def close_connection(connection):

if connection.is_connected():

connection.close()

print("MySQL connection is closed")

======================================================================
======================================================================
==========

DATABASES FILE ENDS HERE


RESTAURANT MANAGEMENT SYSTEM

MENU FILE STARTS HERE

from db import create_connection, close_connection

def add_menu_item(name, price, description):

connection = create_connection()

cursor = connection.cursor()

query = "INSERT INTO menu (name, price, description) VALUES (%s, %s, %s)"

values = (name, price, description)

cursor.execute(query, values)

connection.commit()

close_connection(connection)

print("Menu item added successfully.")

def view_menu():

connection = create_connection()

cursor = connection.cursor()

cursor.execute("SELECT * FROM menu")

rows = cursor.fetchall()

close_connection(connection)

return rows

def update_menu_item(item_id, name, price, description):

connection = create_connection()

cursor = connection.cursor()
RESTAURANT MANAGEMENT SYSTEM

query = "UPDATE menu SET name=%s, price=%s, description=%s WHERE id=%s"

values = (name, price, description, item_id)

cursor.execute(query, values)

connection.commit()

close_connection(connection)

print("Menu item updated successfully.")

def delete_menu_item(item_id):

connection = create_connection()

cursor = connection.cursor()

query = "DELETE FROM menu WHERE id=%s"

cursor.execute(query, (item_id,))

connection.commit()

close_connection(connection)

print("Menu item deleted successfully.")

MENU FILE ENDS HERE


RESTAURANT MANAGEMENT SYSTEM

MAIN FILE STARTS HERE

from menu import add_menu_item, view_menu, update_menu_item,


delete_menu_item

def display_menu():

print("\nRestaurant Management System")

print ("1. Add Menu Item")

print ("2. View Menu")

print ("3. Update Menu Item")

print ("4. Delete Menu Item")

print ("5. Exit")

def main():

while True:

display_menu()

choice = input("Enter your choice: ")

if choice == '1':

name = input ("Enter the name of the item: ")

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

description = input ("Enter the description of the item: ")

add_menu_item(name, price, description)

elif choice == '2':

menu = view_menu()
RESTAURANT MANAGEMENT SYSTEM

for item in menu:

print(f"ID: {item[0]}, Name: {item[1]}, Price: {item[2]}, Description: {item[3]}")

elif choice == '3':

item_id = int(input ("Enter the ID of the item to update: "))

name = input ("Enter the new name of the item: ")

price = float(input ("Enter the new price of the item: "))

description = input ("Enter the new description of the item: ")

update_menu_item(item_id, name, price, description)

elif choice == '4':

item_id = int(input ("Enter the ID of the item to delete: "))

delete_menu_item(item_id)

elif choice == '5':

print ("Exiting the system.")

break

else:

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

if __name__ == "__main__":

main()

MAIN FILE ENDS HERE


RESTAURANT MANAGEMENT SYSTEM

MAKE SURE TO ADD THIS FILE IN FOLDER TO MAKE PROGRAMME WORK

IT’S A CSS FILE WHICH WILL TELL PROGRAMME INTERPRETER ITS PATH .

restaurant_management/

├── main.py

├── db.py

└── menu.py

COPY AND PASTE THIS TEXT IN NOTEPAD AND SAVE FILE IN PROGRAMME
FOLDER WITH NAME OF restaurant_mangement.css

PROGRAMME IMAGES ARE BELOW . PLEASE CHECK THOSE IMAGES


RESTAURANT MANAGEMENT SYSTEM
RESTAURANT MANAGEMENT SYSTEM
RESTAURANT MANAGEMENT SYSTEM
RESTAURANT MANAGEMENT SYSTEM
RESTAURANT MANAGEMENT SYSTEM

You might also like