-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
136 lines (109 loc) · 5.24 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
# The code below is the main application
import mysql.connector as mysql
# Connecting to the database.
mydb = mysql.connect(
host="localhost",
user="root",
password="root",
database="CarRentalDatabase"
)
# Creating a cursor object.
mycursor = mydb.cursor()
mycursor = mydb.cursor(buffered=True)
while True:
# Main menu
print("----------------------------------------------------------------")
print("Main Menu")
print("Select one of the Options : ")
print("----------------------------------------------------------------")
print(" press 1 : if you are an employee")
print(" press 2 : if you are a new customer")
print(" press 3 : if you are a want more informatioon about our services")
print(" press 4 : if you want to stop the application4")
# Taking the input from the user and converting it to an integer.
value = int(input("Enter: "))
print("----------------------------------------------------------------")
# Case 1
if value == 1:
print("Please enter you name: ")
name = str(input("Enter: "))
# We get the date of the needed employee
mycursor.execute(f"select * from Employees where Name ='{name}'")
myresult = mycursor.fetchall()
# This is a loop that goes through the results of the query and gets the data from the table.
employeeID = 0
employeeName = ""
employeeEmail = ""
for x in myresult:
# Getting the data from the table.
employeeID = x[0]
employeeName = x[1]
employeeEmail = x[2]
print("What would you like to do?")
print("----------------------------------------------------------------")
print("press 1: to view your information")
print("press 2: to see the taken cars + their customers")
print("press 3: to create a view of the available cars")
# Taking the input from the user and converting it to an integer.
newIn = int(input("Enter: "))
print("----------------------------------------------------------------")
if newIn == 1:
# Printing the data from the table.
print(f"EmployeeID: {employeeID}")
print(f"Name: {employeeName}")
print(f"Email: {employeeEmail}")
print("----------------------------------------------------------------")
elif newIn == 2:
# This query gets the car and joins it with their customer's data
mycursor.execute(f"SELECT Cars.CarBrand, Customers.Name, Customers.Email FROM Cars INNER JOIN Customers ON Customers.CarWanted = Cars.CarBrand;")
myresult = mycursor.fetchall()
for x in myresult:
# Display the date
print(f"CarBrand: {x[0]}", "|", f"Name: {x[1]}", "|", f"Email: {x[2]}")
print("--------------------------------------------------------")
elif newIn == 3:
# This query creates a view of the available cars
mycursor.execute(f"CREATE OR REPLACE VIEW Available AS SELECT Cars.CarID, Cars.CarBrand, Cars.Available from Cars where available = 'TRUE';")
mycursor.execute(f"select * from Available;")
myresult = mycursor.fetchall()
print(myresult)
print("----------------------------------------------------------------")
# A simple error message that is displayed when the user enters an invalid input.
else:
print("Invalid input")
# Case 2
elif value == 2:
#We get the customer name and email address
name = input("Enter name: ")
email = input("Enter email: ")
# We check what cars are available
mycursor.execute(f"select * from Cars where Available ='TRUE'")
myresult = mycursor.fetchall()
# Printing the available cars.
for x in myresult:
print("Available Car: ",x[1])
print("----------------------------------------------------------------")
#The user inputs the wanted car
car = input("Enter car: ")
# This is a query that inserts the values to the table.
sql = "INSERT INTO Customers VALUES (%s, %s ,%s)"
val = (name, email, car)
mycursor.execute(sql, val)
#We change the car's availability status to false
sql = f"UPDATE Cars SET Available = 'FALSE' WHERE CarBrand = '{car}';"
mycursor.execute(sql)
print("Operation was successful, you will be contacted by an employee soon")
print("----------------------------------------------------------------")
# Case 3
elif value== 3:
#We display the employees that are currently working
print("Contact:")
mycursor.execute(f"select * from Employees where Working ='YES'")
myresult = mycursor.fetchall()
for x in myresult:
print(f"Name: {x[1]}", "|", f"Email: {x[2]}")
print("--------------------------------------------------------")
elif value == 4:
break
# Waiting for the user to press any key to go to the main menu.
wait = input("press any key to go to main menu: ")