MIni project
MIni project
Ex No:
12
HOTEL RESERVATION SYSTEM
DATE:
AIM:
To Develop Hotel reservation System by connecting database with python front end tools
OBJECTIVE:
The goal of this project is to develop a Hotel Management System that allows hotel staff to efficiently
manage customer details, including adding, updating, searching, deleting, and displaying customer
information. The system features an intuitive graphical user interface (GUI) built with Tkinter in Python
and utilizes a MySQL database to store customer records.
FRONT END:
Python With Tkinter
BACKEND:
MySql Database
MODULES USED:
Adding Customer Details: Staff can input and save customer data, including customer ID, name, room
number, check-in/check-out dates, contact information, and address.
Searching Customers: Users can search for customers by room number to find specific reservations.
Updating Customer Records: Existing customer data can be modified, such as changing the room
number or contact details.
Deleting Customer Records: Staff can remove customer records from the system.
Displaying Customer Information: A table view displays all customer records stored in the database,
allowing easy viewing and management.
Database Interaction: All operations (adding, updating, deleting) interact with a MySQL database to
ensure persistent storage of customer data.
PROGRAM:
import tkinter as tk
from tkinter import ttk, messagebox
import mysql.connector
from mysql.connector import Error
try:
connection = connect_to_db()
if connection:
cursor = connection.cursor()
sql = """INSERT INTO hmt (customer_id, name, room_no, check_in, check_out, contact, address)
VALUES (%s, %s, %s, %s, %s, %s, %s)"""
cursor.execute(sql, (customer["Customer ID"], customer["Name"], customer["Room
No"], customer["Check-In"], customer["Check-Out"], customer["Contact"],
customer["Address"]))
connection.commit()
messagebox.showinfo("Success", "Customer details saved successfully")
clear_entries()
def clear_entries():
entry_customer_id.delete(0, tk.END)
entry_name.delete(0, tk.END)
entry_room_no.delete(0, tk.END)
entry_check_in.delete(0, tk.END)
entry_check_out.delete(0, tk.END)
RegNO : 2127230501158 PAGE NO:
entry_contact.delete(0, tk.END)
# Function to update the table with customer data from the database
def update_table():
hotel_table.delete(*hotel_table.get_children())
customer_list.clear()
try:
connection = connect_to_db()
if connection:
cursor = connection.cursor()
cursor.execute("SELECT customer_id, name, room_no, check_in, check_out, contact, address FROM hmt")
records = cursor.fetchall()
except Error as e:
messagebox.showerror("Database Error", f"Failed to retrieve data from MySQL table:
{e}") finally:
if connection.is_connected():
cursor.close()
connection.close()
found_results =
False try:
connection = connect_to_db()
if connection:
cursor = connection.cursor()
cursor.execute("SELECT customer_id, name, room_no, check_in, check_out, contact, address FROM hmt")
records = cursor.fetchall()
except Error as e:
messagebox.showerror("Database Error", f"Failed to retrieve data from MySQL table:
{e}") finally:
if connection.is_connected():
cursor.close()
connection.close()
if not found_results:
messagebox.showinfo("Search Results", "No matching room number found.")
confirm = messagebox.askyesno("Confirm Delete", f"Are you sure you want to delete customer ID
{customer_id}?")
if confirm:
try:
connection = connect_to_db()
if connection:
cursor = connection.cursor()
sql = "DELETE FROM hmt WHERE customer_id = %s"
cursor.execute(sql, (customer_id,))
connection.commit()
messagebox.showinfo("Success", "Customer details deleted successfully")
update_table()
except Error as e:
messagebox.showerror("Database Error", f"Failed to delete data from MySQL table: {e}")
finally:
if
connection.is_connected()
: cursor.close()
connection.close()
updated_customer = {
confirm = messagebox.askyesno("Confirm Update", f"Are you sure you want to update customer ID
{customer_id}?")
if confirm:
try:
connection = connect_to_db()
if connection:
cursor = connection.cursor()
sql = """UPDATE hmt SET name = %s, room_no = %s, check_in = %s, check_out = %s, contact = %s,
address = %s
WHERE customer_id = %s"""
cursor.execute(sql, (updated_customer["Name"], updated_customer["Room
No"], updated_customer["Check-In"], updated_customer["Check-
Out"], updated_customer["Contact"],
updated_customer["Address"], customer_id)) # Update by
customer_id
connection.commit()
messagebox.showinfo("Success", "Customer details updated successfully")
# Color scheme
# Buttons
tk.Button(input_frame, text="Save", font=("Arial", 12), command=save_customer, bg="darkgreen",
fg="white").grid(row=4, column=0, padx=10, pady=10)
tk.Button(input_frame, text="Clear", font=("Arial", 12), command=clear_entries, bg="darkred",
fg="white").grid(row=4, column=1, padx=10, pady=10)
tk.Button(input_frame, text="Delete", font=("Arial", 12), command=delete_customer, bg="darkorange",
fg="white").grid(row=4, column=2, padx=10, pady=10)
tk.Button(input_frame, text="Update", font=("Arial", 12), command=update_customer, bg="darkblue",
fg="white").grid(row=4, column=3, padx=10, pady=10)
# Search Frame
search_frame = tk.Frame(root, bd=10, relief=tk.GROOVE, padx=10, pady=10, bg=frame_color)
search_frame.pack(side=tk.TOP, fill=tk.X)
columns = ("Customer ID", "Name", "Room No", "Check-In", "Check-Out", "Contact", "Address")
hotel_table = ttk.Treeview(table_frame, columns=columns, show='headings')
hotel_table.pack(fill=tk.BOTH,
expand=True)
RESULT:
Thus the hotel reservation system was developed by connecting mysql database with python and
the project is executed and verified successfully