Parking
Parking
def connect_to_db():
try:
connection = mysql.connector.connect(
host="localhost",
user="root",
if connection.is_connected():
return connection
except Error as e:
return None
def add_parking_slots():
db = connect_to_db()
cursor = db.cursor()
for _ in range(num_slots):
db.commit()
# Check In Vehicle
def check_in_vehicle():
db = connect_to_db()
if db is None:
return
try:
cursor = db.cursor()
return
slot = cursor.fetchone()
if slot:
slot_id = slot[0]
entry_time = datetime.now()
cursor.execute("""
UPDATE ParkingSlots
db.commit()
else:
except Error as e:
finally:
db.close()
if vehicle_type.lower() == "car":
else:
def check_out_vehicle():
db = connect_to_db()
cursor = db.cursor()
slot = cursor.fetchone()
if slot:
slot_id, vehicle_type, entry_time = slot
exit_time = datetime.now()
cursor.execute("""
UPDATE ParkingSlots
WHERE SlotID = %s
db.commit()
print(f"Vehicle checked out. Slot ID: {slot_id}, Duration: {duration:.2f} hours, Fee: ${fee:.2f}")
else:
db.close()
def view_parking_status():
db = connect_to_db()
if db is None:
return
try:
cursor = db.cursor()
rows = cursor.fetchall()
if rows:
print("SlotID | VehicleNumber | VehicleType | EntryTime | ExitTime | IsOccupied")
else:
except Error as e:
finally:
db.close()
def reserve_slot():
db = connect_to_db()
cursor = db.cursor()
slot = cursor.fetchone()
if slot:
slot_id = slot[0]
db.commit()
else:
db.close()
def slot_utilization_report():
db = connect_to_db()
cursor = db.cursor()
cursor.execute("""
FROM ParkingSlots
GROUP BY SlotID
""")
rows = cursor.fetchall()
print(f"{row[0]} | {row[1]}")
db.close()
def view_daily_revenue():
db = connect_to_db()
if db is None:
return
try:
cursor = db.cursor()
cursor.execute("""
FROM ParkingSlots
GROUP BY DATE(ExitTime)
""")
rows = cursor.fetchall()
if rows:
print("Date | Total Revenue")
print(f"{row[0]} | ${row[1]:.2f}")
else:
except Error as e:
finally:
db.close()
def search_vehicle():
db = connect_to_db()
cursor = db.cursor()
cursor.execute("""
FROM ParkingSlots
WHERE VehicleNumber = %s
""", (vehicle_number,))
vehicle = cursor.fetchone()
if vehicle:
print(f"Vehicle Found: Slot ID: {slot_id}, Type: {vehicle_type}, Entry Time: {entry_time}, Status:
{status}")
else:
db.close()
def admin_login():
db = connect_to_db()
cursor = db.cursor()
admin = cursor.fetchone()
if admin:
print("Login successful!")
return True
else:
print("Invalid credentials.")
return False
def display_parking_availability():
db = connect_to_db()
cursor = db.cursor()
available_slots = cursor.fetchone()[0]
occupied_slots = cursor.fetchone()[0]
db.close()
def register_customer():
db = connect_to_db()
cursor = db.cursor()
try:
cursor.execute("""
db.commit()
print(f"Error: {err}")
db.close()
def view_customers():
db = connect_to_db()
cursor = db.cursor()
rows = cursor.fetchall()
db.close()
def advanced_search():
db = connect_to_db()
cursor = db.cursor()
if choice == 1:
cursor.execute("""
FROM Customers c
""", (f"%{name}%",))
elif choice == 2:
cursor.execute("""
FROM Customers c
WHERE c.Phone = %s
""", (phone,))
elif choice == 3:
cursor.execute("""
FROM Customers c
WHERE c.VehicleNumber = %s
""", (vehicle_number,))
else:
print("Invalid choice.")
return
rows = cursor.fetchall()
if rows:
else:
db.close()
def add_parking_slots():
db = connect_to_db()
cursor = db.cursor()
for _ in range(num_slots):
db.commit()
db.close()
def view_parking_status():
db = connect_to_db()
cursor = db.cursor()
db.close()
def reserve_slot():
db = connect_to_db()
cursor = db.cursor()
slot = cursor.fetchone()
if slot:
slot_id = slot[0]
cursor.execute("""
UPDATE ParkingSlots
WHERE SlotID = %s
db.commit()
else:
def generate_monthly_report():
db = connect_to_db()
cursor = db.cursor()
cursor.execute("""
FROM ParkingSlots
GROUP BY DATE(ExitTime)
""", (f"{month}%",))
rows = cursor.fetchall()
db.close()
# Main Menu
def main():
if not admin_login():
return
while True:
print("14. Exit")
try:
if choice == 1:
add_parking_slots()
elif choice == 2:
check_in_vehicle()
elif choice == 3:
check_out_vehicle()
elif choice == 4:
view_parking_status()
elif choice == 5:
view_daily_revenue()
elif choice == 6:
search_vehicle()
elif choice == 7:
reserve_slot()
elif choice == 8:
slot_utilization_report()
elif choice == 9:
display_parking_availability()
register_customer()
view_customers()
advanced_search()
generate_monthly_report()
break
else:
except ValueError:
if __name__ == "__main__":
main()
mysql
USE ParkingDB;
VehicleType VARCHAR(20),
EntryTime DATETIME,
ExitTime DATETIME,
);