-
Notifications
You must be signed in to change notification settings - Fork 0
/
Admin.py
242 lines (206 loc) · 7.31 KB
/
Admin.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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
# Author: Oluwakemi Toluwalase Obadeyi
# Date: 03/10/2023
from Data import *
import sqlite3
import time
# pointing to database file
database = "tbs.db3"
# creating database connection
conn = create_connection(database)
if not conn:
print("Error! cannot create the database connection.")
exit()
# Admin Sign In function
print("RydeEasy Admin Sign In")
print(
"For testing purposes: the customer name is John Doe, the email is [email protected] "
"and the password is admin, this line is to be removed in a final version"
)
while True:
def admin_signin():
print("Please Sign In")
email = input("Enter your email: ")
password = input("Enter your password: ")
with sqlite3.connect("tbs.db3") as db:
cursor = db.cursor()
find_email = "SELECT * FROM Admins WHERE email = ? AND password = ?"
cursor.execute(find_email, [email, password])
results = cursor.fetchall()
if results:
print("Successfully signed in!")
admin_menu()
else:
print("Invalid email or password!")
retry = input("Would you like to try again? y/n: ")
if retry in ("y", "Y", "yes", "Yes"):
admin_signin()
elif retry in ("n", "N", "no", "No"):
print("Goodbye.")
break
# Admin menu function
def admin_menu():
print("Admin Menu")
print("1. View all bookings")
print("2. Create a new driver")
print("3. Cancel a booking")
print("4. View available drivers")
print("5. Logout")
menu_input = input("How can I assist you?: ")
if menu_input == "1":
view_bookings()
if menu_input == "2":
create_new_driver()
if menu_input == "3":
cancel_booking()
if menu_input == "4":
available_drivers()
if menu_input == "5":
exit()
else:
print("Invalid Details.")
admin_menu()
# Create new driver function
def create_new_driver():
print("Create new driver")
found = 0
while found == 0:
firstname = input("Please enter the Driver's first name: ")
with sqlite3.connect("tbs.db3") as db:
cursor = db.cursor()
find_customer = "SELECT * FROM Drivers WHERE firstname = ?"
cursor.execute(find_customer, [firstname])
if cursor.fetchall():
try_again_or_signin = input(
"a driver with the name "
+ firstname
+ " already exists, please add a "
"number at the end of his/her name "
"to continue, enter r to retry, "
"enter n if you "
"no longer wish to add a driver: "
)
if try_again_or_signin in ("r", "R"):
create_new_driver()
elif try_again_or_signin in ("n", "N"):
print()
admin_menu()
else:
print("Invalid Entry, Redirecting...")
create_new_driver()
else:
found = 1
lastname = input("Please enter the Driver's last name: ")
title = input("Please enter the Driver's title: ")
phone_number = input("Please enter the Driver's phone number: ")
car_colour = input("Please enter the Driver's car colour: ")
car_brand = input("Please enter the Driver's car brand : ")
reg_number = input("Please enter the Driver's car registration number: ")
email = input("Please enter email: ")
password = input("Create password (Case Sensitive): ")
cpassword = input("Please confirm password: ")
while password != cpassword:
print("Passwords does not match!")
password = input("Create password (Case Sensitive): ")
cpassword = input("Confirm your password: ")
input_data = """INSERT INTO Drivers(title, firstname, lastname, phone_number,
car_colour, car_brand, reg_number, email, password) VALUES(?,?,?,?,?,?,?,?,?) """
cursor.execute(
input_data,
[
title,
firstname,
lastname,
phone_number,
email,
car_colour,
car_brand,
reg_number,
password,
],
)
db.commit()
# View bookings from customers
def view_bookings():
print("View Bookings")
with sqlite3.connect("tbs.db3") as db:
cursor = db.cursor()
# Bookings which belong to the current customer
sql = """ SELECT * FROM Bookings """
cursor.execute(sql)
booking = cursor.fetchall()
if not booking:
print("No bookings, redirecting to admin Menu...")
time.sleep(2)
admin_menu()
else:
# Showing all the available bookings
for i, b in enumerate(booking, 1):
print(
str(i) + ") "
"Start Address: "
"" + str(b[4]) + " Postcode: "
"" + str(b[5]) + " Time: "
"" + str(b[6]),
""" -> Destination Address: """ + str(b[7]) + " Postcode: "
"" + str(b[8]) + " Date: "
"" + str(b[9]),
)
# Function to return to previous menu
print("\n")
return_to_menu = input(
"Select R To return to the main menu or select C to cancel booking(s): "
)
if return_to_menu in ("r", "R", "return", "Return"):
print("\n")
admin_menu()
elif return_to_menu in ("c", "C", "cancel", "Cancel"):
print("\n")
cancel_booking()
else:
print("Invalid input, redirecting to main menu...")
admin_menu()
# Cancel Booking Function
def cancel_booking():
print("Cancel a booking")
booking = get_bookings(conn) # connection to database
if not booking:
print("There is no booking yet, redirecting to Admin Menu...")
time.sleep(2)
admin_menu()
else:
# Showing all the available bookings
for i, b in enumerate(booking, 0):
print(
str(i) + ") "
"Start Address: "
"" + str(b[4]) + " Postcode: "
"" + str(b[5]) + " Time: "
"" + str(b[6]),
""" -> Destination Address: """ + str(b[7]) + " Postcode: "
"" + str(b[8]) + " Date: "
"" + str(b[9]),
)
_input = input("Select which booking you would like to cancel: ")
index = int(_input)
b = booking[index]
bookingid = b[0]
cancel_previous_booking(conn, bookingid)
print("Booking cancelled.")
print("Redirecting to Main Menu...")
time.sleep(3)
admin_menu()
# View available drivers function
def available_drivers():
print("\n")
drivers = get_drivers(conn)
print("Available drivers:")
for i, driver in enumerate(drivers, 0):
print(
str(i) + "." + str(driver[1]) + " " + str(driver[2]) + " " + str(driver[3])
)
# Return to previous menu function
print("\n")
input("Press 'Enter' to return to the Admin Menu...")
print("\n")
admin_menu()
admin_signin()