0% found this document useful (0 votes)
22 views11 pages

Com Puther

Uploaded by

spacedevil1234
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)
22 views11 pages

Com Puther

Uploaded by

spacedevil1234
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/ 11

import tkinter as tk

from tkinter import messagebox


import mysql.connector

from datetime import datetime

# Create the database connection


def create_db_connection():
connection = mysql.connector.connect(
host="localhost", # your MySQL host
user="root", # MySQL username
password="your_password", # MySQL password
database="hotel_management"

)
return connection

# Function to add a room


def add_room():
room_type = room_type_entry.get()
price = price_entry.get()

if room_type and price:


conn = create_db_connection()

cursor = conn.cursor()
cursor.execute('''INSERT INTO rooms (room_type, status, price)
VALUES (%s, %s, %s)''', (room_type, 'Available', float(price)))
conn.commit()
conn.close()

messagebox.showinfo("Success", "Room added successfully!")


else:
messagebox.showerror("Error", "Please fill in all fields.")

# Function to add a guest


def add_guest():
first_name = first_name_entry.get()
last_name = last_name_entry.get()
phone = phone_entry.get()

email = email_entry.get()

if first_name and last_name and phone and email:


conn = create_db_connection()
cursor = conn.cursor()
cursor.execute('''INSERT INTO guests (first_name, last_name, phone,
email)
VALUES (%s, %s, %s, %s)''', (first_name, last_name, phone,
email))
conn.commit()
conn.close()

messagebox.showinfo("Success", "Guest added successfully!")


else:
messagebox.showerror("Error", "Please fill in all fields.")

# Function to book a room


def book_room():
guest_id = guest_id_entry.get()
room_id = room_id_entry.get()
check_in = check_in_entry.get()
check_out = check_out_entry.get()

if guest_id and room_id and check_in and check_out:


conn = create_db_connection()

cursor = conn.cursor()

# Get room price


cursor.execute('SELECT price FROM rooms WHERE room_id = %s',
(room_id,))
room_price = cursor.fetchone()[0]

# Calculate total price based on check-in and check-out dates


check_in_date = datetime.strptime(check_in, '%Y-%m-%d')
check_out_date = datetime.strptime(check_out, '%Y-%m-%d')
total_price = room_price * (check_out_date - check_in_date).days
# Insert the booking
cursor.execute('''INSERT INTO bookings (guest_id, room_id, check_in,
check_out, total_price)
VALUES (%s, %s, %s, %s, %s)''', (guest_id, room_id, check_in,
check_out, total_price))
conn.commit()
conn.close()

messagebox.showinfo("Success", "Room booked successfully!")


else:
messagebox.showerror("Error", "Please fill in all fields.")

# Function to make a payment


def make_payment():
booking_id = booking_id_entry.get()
amount = amount_entry.get()

if booking_id and amount:


conn = create_db_connection()
cursor = conn.cursor()

payment_date = datetime.now().strftime('%Y-%m-%d')

cursor.execute('''INSERT INTO payments (booking_id, amount,


payment_date)
VALUES (%s, %s, %s)''', (booking_id, float(amount),
payment_date))
conn.commit()
conn.close()

messagebox.showinfo("Success", "Payment made successfully!")


else:
messagebox.showerror("Error", "Please fill in all fields.")

# Function to view rooms


def view_rooms():
conn = create_db_connection()
cursor = conn.cursor()
cursor.execute('SELECT * FROM rooms')

rooms = cursor.fetchall()
conn.close()

rooms_text = ""
for room in rooms:
rooms_text += f"Room ID: {room[0]} | Type: {room[1]} | Status: {room[2]}
| Price: ${room[3]}\n"

messagebox.showinfo("Rooms", rooms_text)

# Function to view guests


def view_guests():
conn = create_db_connection()
cursor = conn.cursor()
cursor.execute('SELECT * FROM guests')
guests = cursor.fetchall()

conn.close()

guests_text = ""
for guest in guests:
guests_text += f"Guest ID: {guest[0]} | Name: {guest[1]} {guest[2]} |
Phone: {guest[3]} | Email: {guest[4]}\n"

messagebox.showinfo("Guests", guests_text)

# Main window setup


window = tk.Tk()

window.title("Hotel Management System")

# Room section
room_label = tk.Label(window, text="Room Type:")

room_label.grid(row=0, column=0)
room_type_entry = tk.Entry(window)
room_type_entry.grid(row=0, column=1)

price_label = tk.Label(window, text="Price:")

price_label.grid(row=1, column=0)
price_entry = tk.Entry(window)
price_entry.grid(row=1, column=1)

add_room_button = tk.Button(window, text="Add Room",


command=add_room)
add_room_button.grid(row=2, column=0, columnspan=2)

# Guest section
first_name_label = tk.Label(window, text="First Name:")
first_name_label.grid(row=3, column=0)
first_name_entry = tk.Entry(window)
first_name_entry.grid(row=3, column=1)

last_name_label = tk.Label(window, text="Last Name:")


last_name_label.grid(row=4, column=0)
last_name_entry = tk.Entry(window)
last_name_entry.grid(row=4, column=1)

phone_label = tk.Label(window, text="Phone:")

phone_label.grid(row=5, column=0)
phone_entry = tk.Entry(window)
phone_entry.grid(row=5, column=1)

email_label = tk.Label(window, text="Email:")

email_label.grid(row=6, column=0)
email_entry = tk.Entry(window)
email_entry.grid(row=6, column=1)

add_guest_button = tk.Button(window, text="Add Guest",


command=add_guest)
add_guest_button.grid(row=7, column=0, columnspan=2)

# Booking section
guest_id_label = tk.Label(window, text="Guest ID:")
guest_id_label.grid(row=8, column=0)
guest_id_entry = tk.Entry(window)
guest_id_entry.grid(row=8, column=1)

room_id_label = tk.Label(window, text="Room ID:")


room_id_label.grid(row=9, column=0)
room_id_entry = tk.Entry(window)
room_id_entry.grid(row=9, column=1)

check_in_label = tk.Label(window, text="Check-in Date (YYYY-MM-DD):")

check_in_label.grid(row=10, column=0)
check_in_entry = tk.Entry(window)
check_in_entry.grid(row=10, column=1)

check_out_label = tk.Label(window, text="Check-out Date (YYYY-MM-


DD):")
check_out_label.grid(row=11, column=0)
check_out_entry = tk.Entry(window)
check_out_entry.grid(row=11, column=1)

book_room_button = tk.Button(window, text="Book Room",


command=book_room)
book_room_button.grid(row=12, column=0, columnspan=2)

# Payment section
booking_id_label = tk.Label(window, text="Booking ID:")
booking_id_label.grid(row=13, column=0)
booking_id_entry = tk.Entry(window)
booking_id_entry.grid(row=13, column=1)

amount_label = tk.Label(window, text="Amount:")


amount_label.grid(row=14, column=0)
amount_entry = tk.Entry(window)
amount_entry.grid(row=14, column=1)

make_payment_button = tk.Button(window, text="Make Payment",


command=make_payment)
make_payment_button.grid(row=15, column=0, columnspan=2)
# View section
view_rooms_button = tk.Button(window, text="View Rooms",
command=view_rooms)
view_rooms_button.grid(row=16, column=0)

view_guests_button = tk.Button(window, text="View Guests",


command=view_guests)

view_guests_button.grid(row=16, column=1)

window.mainloop()
Expected Output

1. View Rooms:

yaml

Copy code

Room ID: 1 | Type: Single | Status: Available | Price: $50.00

Room ID: 2 | Type: Double | Status: Available | Price: $75.00

Room ID: 3 | Type: Suite | Status: Available | Price: $120.00

2. View Guests:

yaml

Copy code

Guest ID: 1 | Name: John Doe | Phone: 1234567890 | Email: [email protected]

Guest ID: 2 | Name: Jane Smith | Phone: 9876543210 | Email: [email protected]

3. Book Room: Success message confirming the booking and total price
calculated based on room price and duration.

4. Make Payment: Success message confirming the payment.

You might also like