Cs Project
Cs Project
SUBMITTED TO SUBMITTED BY
Mr. Manoj Joshi Harsh Pandey
PGT CS Class 12 th
Roll Number - 2
CERTIFICATE
Harsh Pandey
12th A
INDEX
1. Certificate
2. Acknowledgement
3. Introduction
4. Objective
5. Coding
6. Output
INTRODUCTION
The project is titled "Restaurant Table Reservation
System". This system aims to efficiently manage
customer reservations and table availability in a
restaurant setting. It provides various
functionalities to maintain customer information,
record reservations, view menu details, and
perform essential operations such as searching for
customers and cancelling reservations.
DATABASE = "restaurant_system"
CUSTOMER_INFO_TABLE = "customer_info"
TABLE_RESERVATION_TABLE = "table_rev"
MENU_TABLE = "menu"
try:
connection = mysql.connector.connect(
host="localhost",
user="root",
password="naman*007"
)
if connection.is_connected():
cursor = connection.cursor()
print("Connected to the database successfully")
except Error as e:
print("Error:", e)
def create_database():
try:
cursor.execute(f"CREATE DATABASE {DATABASE}")
print("Database created")
cursor.execute(f"USE {DATABASE}")
print("Database in use!")
except Error as e:
print("Failed to create or use database:", e)
def create_customer_info():
try:
cursor.execute(f"USE {DATABASE}")
customer_table = f'''CREATE TABLE {CUSTOMER_INFO_TABLE} (
customer_id INT PRIMARY KEY,
customer_name VARCHAR(100),
phone_number VARCHAR(15),
email VARCHAR(100)
)'''
chc = input("Are you sure you want to create the table? Y/N: ").lower()
if chc == "y":
cursor.execute(customer_table)
print("Table created")
else:
print("Command aborted")
except Error as e:
print("Failed to create customer information table:", e)
def create_table_reservation():
try:
cursor.execute(f"USE {DATABASE}")
table_reserve = f'''CREATE TABLE {TABLE_RESERVATION_TABLE} (
reservation_id INT PRIMARY KEY,
reservation_time TIME,
reservation_date DATE,
customer_id INT
)'''
chc = input("Are you sure you want to create the table? Y/N: ").lower()
if chc == "y":
cursor.execute(table_reserve)
print("Table created")
else:
print("Command aborted")
except Error as e:
print("Failed to create reservation table:", e)
def insert_reservation():
try:
cursor.execute(f"USE {DATABASE}")
reservation_id = input("Enter reservation ID: ")
customer_id = input("Enter customer ID: ")
reservation_time = input("Enter reservation time (HH:MM:SS): ")
reservation_date = input("Enter reservation date (YYYY-MM-DD): ")
insert_query = f'''INSERT INTO {TABLE_RESERVATION_TABLE}
(reservation_id, customer_id, reservation_time, reservation_date)
VALUES (%s, %s, %s, %s)'''
cursor.execute(insert_query, (reservation_id, customer_id,
reservation_time, reservation_date))
connection.commit()
print("Reservation inserted successfully!")
except Error as e:
print("Failed to insert reservation:", e)
def insert_customer():
try:
cursor.execute(f"USE {DATABASE}")
customer_id = input("Enter customer ID: ")
customer_name = input("Enter customer name: ")
phone = input("Enter phone number of the customer: ")
email = input("Enter the email ID: ")
insert_query = f'''INSERT INTO {CUSTOMER_INFO_TABLE} (customer_id,
customer_name, phone_number, email)
VALUES (%s, %s, %s, %s)'''
cursor.execute(insert_query, (customer_id, customer_name, phone, email))
connection.commit()
print("Customer inserted successfully!", customer_id)
except Error as e:
print("Failed to insert customer:", e)
def show_reservations():
try:
cursor.execute(f"USE {DATABASE}")
show = f"SELECT * FROM {TABLE_RESERVATION_TABLE}"
cursor.execute(show)
reservations = cursor.fetchall()
if reservations:
print(f"{'Reservation ID':<15} {'Customer ID':<15} {'Reservation Time':<20}
{'Reservation Date':<20}")
print("="*70)
for reservation in reservations:
print(f"{reservation[0]:<15} {reservation[1]:<15} {reservation[2]:<20}
{reservation[3]:<20}")
else:
print("No reservations found.")
except Error as e:
print("Failed to retrieve reservations:", e)
def show_customers():
try:
cursor.execute(f"USE {DATABASE}")
show = f"SELECT * FROM {CUSTOMER_INFO_TABLE}"
cursor.execute(show)
customers = cursor.fetchall()
if customers:
print(f"{'Customer ID':<15} {'Customer Name':<20} {'Phone Number':<15}
{'Email':<25}")
print("="*75)
for customer in customers:
print(f"{customer[0]:<15} {customer[1]:<20} {customer[2]:<15}
{customer[3]:<25}")
else:
print("No customers found.")
except Error as e:
print("Failed to retrieve customers:", e)
def display_menu():
try:
cursor.execute(f"USE {DATABASE}")
cursor.execute(f"SELECT * FROM {MENU_TABLE}")
menu_items = cursor.fetchall()
if menu_items:
print(f"{'ID':<5} {'Name':<25} {'Description':<50} {'Price (INR)':<15}
{'Available':<10}")
print("="*100)
for item in menu_items:
print(f"{item[0]:<5} {item[1]:<25} {item[2]:<50} {item[3]:<15} {'Yes' if
item[4] else 'No':<10}")
else:
print("The menu is empty.")
except Error as e:
print("Failed to retrieve menu items:",e)
def cancel_reservation():
try:
cursor.execute(f"USE {DATABASE}")
reservation_id = input("Enter reservation ID to cancel: ")
delete_query = f"DELETE FROM {TABLE_RESERVATION_TABLE} WHERE
reservation_id = %s"
cursor.execute(delete_query, (reservation_id,))
connection.commit()
print("Reservation cancelled successfully!")
except Error as e:
print("Failed to cancel reservation:", e)
def search_customer():
try:
cursor.execute(f"USE {DATABASE}")
search_type = input("Search by ID (1) or name (2): ")
if search_type == "1":
customer_id = input("Enter customer ID: ")
search_query = f"SELECT * FROM {CUSTOMER_INFO_TABLE} WHERE
customer_id = %s"
cursor.execute(search_query, (customer_id,))
elif search_type == "2":
customer_name = input("Enter customer name: ")
search_query = f"SELECT * FROM {CUSTOMER_INFO_TABLE} WHERE
customer_name LIKE %s"
cursor.execute(search_query, (f"%{customer_name}%",))
customers = cursor.fetchall()
if customers:
print(f"{'Customer ID':<15} {'Customer Name':<20} {'Phone Number':<15}
{'Email':<25}")
print("="*75)
for customer in customers:
print(f"{customer[0]:<15} {customer[1]:<20} {customer[2]:<15}
{customer[3]:<25}")
else:
print("Customer not found.")
except Error as e:
print("Failed to search customer:", e)
def check_table_availability():
try:
cursor.execute(f"USE {DATABASE}")
date = input("Enter reservation date (YYYY-MM-DD): ")
time = input("Enter reservation time (HH:MM:SS): ")
check_query = f"SELECT * FROM {TABLE_RESERVATION_TABLE} WHERE
reservation_date = %s AND reservation_time = %s"
cursor.execute(check_query, (date, time))
reservations = cursor.fetchall()
if reservations:
print("No tables available for the specified date and time.")
else:
print("Tables are available for the specified date and time.")
except Error as e:
print("Failed to check table availability:", e)
def menu_choice():
print('''
/////////////////////////////////////
// Welcome to Restaurant Table //
// Reservation System //
///////////////////////////////////
''')
create_database()
while True:
try:
choice = int(input('''
1 > Create new table for customer information
2 > Create new table for reservation information
3 > Insert customer information
4 > Insert new table reservation information
5 > Show existing reservations
6 > Show customer information of all customers
7 > Show menu
8 > Search a customer
9 > Cancel a reservation
10 > Check Table Availibility
11 > Exit
Enter your choice: '''))
if choice == 1:
create_customer_info()
elif choice == 2:
create_table_reservation()
elif choice == 3:
insert_customer()
elif choice == 4:
insert_reservation()
elif choice == 5:
show_reservations()
elif choice == 6:
show_customers()
elif choice == 7:
display_menu()
elif choice == 8:
search_customer()
elif choice == 9:
cancel_reservation()
elif choice == 10:
check_table_availability()
elif choice == 11:
print("Exiting the system.")
break
else:
print("Incorrect choice")
except ValueError:
print("Invalid input. Please enter a number.")
except Error as e:
print("An error occurred:", e)