0% found this document useful (0 votes)
6 views

PROGRAM

Uploaded by

aishwanth676
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views

PROGRAM

Uploaded by

aishwanth676
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 9

PROGRAM

import mysql.connector
from mysql.connector import Error

# Database connection parameters


host = 'localhost'
username = 'root'
password = 'ais1234'
database = 'party_hall_booking'

def create_connection():
"""Create a database connection to the MySQL database."""
conn = None
try:
conn = mysql.connector.connect(
host=host,
user=username,
password=password
)
print("Connection to MySQL DB successful")
except Error as e:
print(f"The error '{e}' occurred")
return conn

def create_database(conn):
"""Create a database for the party hall booking system."""
cursor = conn.cursor()
try:
cursor.execute(f"CREATE DATABASE IF NOT EXISTS
{database}")
print(f"Database '{database}' created successfully")
except Error as e:
print(f"The error '{e}' occurred")

def create_tables(conn):
"""Create tables for hall owners and bookings."""
cursor = conn.cursor()
cursor.execute(f"USE {database}")

# Create table for hall owners


create_owners_table = """
CREATE TABLE IF NOT EXISTS owners (
id INT AUTO_INCREMENT PRIMARY KEY,
name VARCHAR(100) NOT NULL,
email VARCHAR(100) NOT NULL UNIQUE,
phone VARCHAR(15) NOT NULL,
hall_name VARCHAR(100) NOT NULL,
hall_location VARCHAR(100) NOT NULL,
hall_capacity INT NOT NULL,
hall_price DECIMAL(10, 2) NOT NULL
);
"""

# Create table for bookings


create_bookings_table = """
CREATE TABLE IF NOT EXISTS bookings (
id INT AUTO_INCREMENT PRIMARY KEY,
owner_id INT NOT NULL,
customer_name VARCHAR(100) NOT NULL,
customer_email VARCHAR(100) NOT NULL,
booking_date DATE NOT NULL,
booking_time TIME NOT NULL,
guests INT NOT NULL,
payment DECIMAL(10, 2) NOT NULL,
location VARCHAR(100) NOT NULL,
FOREIGN KEY (owner_id) REFERENCES owners (id) ON
DELETE CASCADE
);
"""

cursor.execute(create_owners_table)
cursor.execute(create_bookings_table)
print("Tables created successfully")

def list_halls(conn):
"""List all available halls, filtered by location."""
cursor = conn.cursor()
cursor.execute(f"USE {database}")

location = input("Enter the location to list halls: ")


cursor.execute("SELECT * FROM owners WHERE hall_location =
%s", (location,))
halls = cursor.fetchall()

if halls:
print("Available Party Halls:")
for hall in halls:
print(f"ID: {hall[0]}, Hall Name: {hall[4]}, Location: {hall[5]},
Capacity: {hall[6]}, Price: ${hall[7]:.2f}")
else:
print("No halls available in the specified location.")
return halls # Return the list of halls

def add_hall_owner(conn):
"""Add a new hall owner."""
cursor = conn.cursor()
cursor.execute(f"USE {database}")

name = input("Enter your name: ")


email = input("Enter your email: ")
phone = input("Enter your phone number: ")
hall_name = input("Enter hall name: ")
hall_location = input("Enter hall location: ")
hall_capacity = int(input("Enter hall capacity: "))
hall_price = float(input("Enter hall price per hour: "))

insert_query = """
INSERT INTO owners (name, email, phone, hall_name, hall_location,
hall_capacity, hall_price)
VALUES (%s, %s, %s, %s, %s, %s, %s)
"""
cursor.execute(insert_query, (name, email, phone, hall_name,
hall_location, hall_capacity, hall_price))
conn.commit()
print("Hall owner added successfully.")

def book_hall(conn):
"""Book a hall for a customer."""
cursor = conn.cursor()
cursor.execute(f"USE {database}")

customer_name = input("Enter your name: ")


customer_email = input("Enter your email: ")
booking_date = input("Enter the booking date (YYYY-MM-DD): ")
booking_time = input("Enter the booking time (HH:MM:SS): ")
guests = int(input("Enter number of guests: "))
location = input("Enter the desired location for the hall: ")

# List halls based on location


halls = list_halls(conn)

if not halls: # Check if halls list is empty


print("No halls available for the specified location. Booking failed.")
return

hall_id = int(input("Enter the ID of the hall you want to book: "))


# Get hall price
cursor.execute("SELECT hall_price FROM owners WHERE id = %s",
(hall_id,))
hall_price = cursor.fetchone()

if hall_price is None:
print("Invalid hall ID. Booking failed.")
return

hall_price = hall_price[0]
payment = hall_price

insert_query = """
INSERT INTO bookings (owner_id, customer_name, customer_email,
booking_date, booking_time, guests, payment, location)
VALUES (%s, %s, %s, %s, %s, %s, %s, %s)
"""
cursor.execute(insert_query, (hall_id, customer_name,
customer_email, booking_date, booking_time, guests, payment,
location))
conn.commit()

print("Booking successful!")
generate_receipt(hall_id, customer_name, customer_email,
booking_date, booking_time, guests, payment)

def generate_receipt(hall_id, customer_name, customer_email,


booking_date, booking_time, guests, payment):
"""Generate a receipt for the booking."""
print("\n----- Booking Receipt -----")
print(f"Customer Name: {customer_name}")
print(f"Customer Email: {customer_email}")
print(f"Hall ID: {hall_id}")
print(f"Booking Date: {booking_date}")
print(f"Booking Time: {booking_time}")
print(f"Number of Guests: {guests}")
print(f"Total Payment: ${payment:.2f}")
print("---------------------------\n")

def main():
conn = create_connection()
create_database(conn)
create_tables(conn)

while True:
print("\n1. Add Hall Owner")
print("2. List Halls")
print("3. Book Hall")
print("4. Exit")
choice = input("Choose an option: ")

if choice == '1':
add_hall_owner(conn)
elif choice == '2':
list_halls(conn)
elif choice == '3':
book_hall(conn)
elif choice == '4':
break
else:
print("Invalid choice, please try again.")

conn.close()

if __name__ == "__main__":
main()

OUTPUT
Adding a new hall owner:

Enter your name: John Doe


Enter your email: [email protected]
Enter your phone number: 1234567890
Enter hall name: Grand Palace
Enter hall location: New York
Enter hall capacity: 200
Enter hall price per hour: 500.00
Hall owner added successfully.
BOOKING A HALL
Enter your name: Alice
Enter your email: [email protected]
Enter the booking date (YYYY-MM-DD): 2024-12-01
Enter the booking time (HH:MM:SS): 18:00:00
Enter number of guests: 150
Enter the desired location for the hall: New York
Enter the location to list halls: New York
Available Party Halls:
ID: 1, Hall Name: Grand Palace, Location: New York, Capacity: 200,
Price: $500.00
Enter the ID of the hall you want to book: 1
Booking successful!

----- Booking Receipt -----


Customer Name: Alice
Customer Email: [email protected]
Hall ID: 1
Booking Date: 2024-12-01
Booking Time: 18:00:00
Number of Guests: 150
Total Payment: $500.00
---------------------------

You might also like