· 4 years ago · Jan 21, 2021, 11:18 AM
1from functools import partial
2from tkinter import *
3import tkinter as tk
4from tkinter import messagebox as MessageBox
5from tkinter import ttk
6
7from PIL import Image, ImageTk
8from tkcalendar import DateEntry
9import sqlite3 as sql
10from sqlite3 import Error
11import re
12#import system
13
14
15# Define display frame to show different frames
16def display_frames(frame):
17 frame.tkraise()
18
19
20# <<<<<<<<<<<<<<<<<<<<<< Driver Part >>>>>>>>>>>>>>>>>>>>>>
21
22def driver_registration_page(frame):
23 d_frame = Frame(frame, bd=2, relief=GROOVE, bg="white")
24 d_frame.place(x=175, y=55, width=500, height=510)
25
26 # Create a registration label
27 label_registration = Label(d_frame, text="Registration Form", bg="white", font=("times", 20, "bold")).pack(side=TOP, fill=X)
28
29 name_label = Label(d_frame, text="Full Name", bg="white", font=("times", 15, "bold")).place(x=80, y=100)
30 address_label = Label(d_frame, text="Address", bg="white", font=("times", 15, "bold")).place(x=98, y=150)
31 phone_label = Label(d_frame, text="Phone Number", bg="white", font=("times", 15, "bold")).place(x=44, y=200)
32 email_label = Label(d_frame, text="Email", bg="white", font=("times", 15, "bold")).place(x=113, y=250)
33 password_label = Label(d_frame, text="Password", bg="white", font=("times", 15, "bold")).place(x=83, y=300)
34 confirm_label = Label(d_frame, text="Confirm Password", bg="white", font=("times", 15, "bold")).place(x=10, y=350)
35 license_label = Label(d_frame, text="License Plate", bg="white", font=("times", 15, "bold")).place(x=50, y=400)
36
37 driver_name_text = Entry(d_frame, textvariable=driver_name, bd=2, relief=GROOVE, bg="white", width=30, font=("", 12)).place(x=200, y=100, height=33)
38 driver_address_text = Entry(d_frame, textvariable=driver_address, bd=2, relief=GROOVE, bg="white", width=30, font=("", 12)).place(x=200, y=150, height=33)
39 driver_phone_text = Entry(d_frame, textvariable=driver_phone, bd=2, relief=GROOVE, bg="white", width=30, font=("", 12)).place(x=200, y=200, height=33)
40 email_text = Entry(d_frame, textvariable=driver_email, bd=2, relief=GROOVE, bg="white", width=30, font=("", 12)).place(x=200, y=250, height=33)
41 driver_password_text = Entry(d_frame, textvariable=driver_password, bd=2, relief=GROOVE, bg="white", width=30, font=("", 12)).place(x=200, y=300, height=33)
42 driver_confirm_text = Entry(d_frame, textvariable=driver_confirm, bd=2, relief=GROOVE, bg="white", width=30, font=("", 12)).place(x=200, y=350, height=33)
43 driver_license_text = Entry(d_frame, textvariable=driver_license, bd=2, relief=GROOVE, bg="white", width=30, font=("", 12)).place(x=200, y=400, height=33)
44
45 submit_button = Button(d_frame, text="Submit", bd=1, width=10, height=1, font=("times", 15, "bold"))
46 submit_button.place(x=130, y=455)
47
48 exit_button = Button(d_frame, text="Exit", bd=1, width=10, height=1, command=driver_registration_exit, font=("times", 15, "bold"))
49 exit_button.place(x=280, y=455)
50
51def driver_registration_exit():
52 exit1 = MessageBox.askyesno("Exit", "Do You really want to exit?")
53 if exit1 == True:
54 display_frames(home_frame)
55
56
57def driver_home_page(frame):
58 frame2 = Frame(frame, relief=GROOVE, bd=3)
59 frame2.place(x=180, y=70, width=530, height=480)
60
61 # #== Back ground Image ==
62 # bg_image = ImageTk.PhotoImage(file="Images/login.jpg")
63 # bg_label = Label(frame, image=bg_image)
64 # bg_label.place(x=180, y=30, width=420, height=510)
65
66 login_label = Label(frame2, text="Driver Login system", font=("times", 25, "bold")).place(x=110, y=75)
67 email_label = Label(frame2, text="Email", font=("times", 18, "bold")).place(x=65, y=210)
68 password_label = Label(frame2, text="Password", font=("times", 18, "bold")).place(x=30, y=260)
69
70 email_text = Entry(frame2, bd=2, width=28, textvariable=driver_email, relief=GROOVE, font=("", 12)).place(x=170, y=210, width=270, height=35)
71 password_text = Entry(frame2, bd=2, width=28, textvariable=driver_password, relief=GROOVE, font=("", 12)).place(x=170, y=260, width=270, height=35)
72
73 button_login = Button(frame2, text="Login", relief=GROOVE, bd=2, fg="blue", width=18, font=("times", 18, "bold"))
74 button_login.place(x=170, y=350)
75 button_register = Button(frame2, text="Signup", relief=GROOVE, bd=2, fg="green", width=18, command=lambda: display_frames(driver_registration_frame), font=("times", 18, "bold"))
76 button_register.place(x=170, y=400)
77 button_back = Button(frame2, text="Back", relief=GROOVE, bd=2, command=lambda: display_frames(home_frame), font=("times", 18, "bold"))
78 button_back.grid(row=0, column=0, sticky="nw")
79
80
81# Define a function to check whether table exists in database or not
82def table_exist(conn, tablename):
83 chk_tab = conn.execute(
84 "SELECT (name) FROM sqlite_master WHERE type='table' AND name='{name}'".format(name=tablename))
85 if chk_tab == tablename:
86 return True
87 return False
88
89# Define a function for checking validate email
90def check_email(email):
91 regex = '^[A-Za-z0-9]+[\._]?[a-z0-9]+[@]\w+[.]\w{2,3}$'
92 if (re.search(regex, email)):
93 return True
94 else:
95 return False
96
97
98# Define a function for checking password length
99def check_password_length(pwd):
100 if len(pwd) >5:
101 return True
102 else:
103 return False
104
105
106# <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
107
108
109def check_empty(data):
110 print(data)
111 for d in data:
112 if len(d) <= 0:
113 return False
114 return True
115
116def add_id_to_temp(id):
117 file = open('temp/temp.txt','w')
118 file.write(id)
119 file.close()
120
121def get_id_from_temp():
122 file = open('temp/temp.txt','r')
123 id=file.readline()
124 file.close()
125 return id
126
127
128def filter_signup(email, data):
129 conn = sql.connect("databases/{}/{}".format(data, data + '_login.db'))
130 chck = table_exist(conn, "LOGIN")
131 cursor = conn.execute("SELECT email,password FROM LOGIN")
132 for row in cursor:
133 print(row[0])
134 if row[0] == email:
135 conn.close()
136 return True
137 conn.close()
138 return False
139
140def check_dublicate(email,table,data):
141 conn = sql.connect("databases/{}/{}".format(data, data+'.db' ))
142 chck = table_exist(conn, "{}".format(table))
143 print(chck)
144 if chck:
145 cursor = conn.execute("SELECT email FROM {}".format(table))
146 for row in cursor:
147 print(row[0])
148 if row[0] == email:
149 conn.close()
150 return True
151 conn.close()
152 return False
153 else:
154 return None
155
156
157
158def get_your_trip(conn, userid):
159 customer_booking_query = conn.execute("SELECT rowid, Name, Phone, PickAddress, DropAddress, Time, Date, active,driver FROM Booking")
160 temp=[]
161 for row in customer_booking_query:
162 print(row)
163 if row[1] == userid:
164 temp.append(row)
165 return temp
166
167
168def list_to_str(data):
169 temp=""
170 for i in range(1,len(data)):
171 temp+=data[i]
172 temp+=" "
173 return temp.rstrip()
174
175def delete_customer_reservation(id,conn,frame,taxi_list):
176 print(taxi_list,"chck list")
177 row_id= taxi_list[id][0]
178 if taxi_list[id][7]==1:
179 newconn = sql.connect("databases/trips/trips.db")
180 newconn.execute("UPDATE ACTIVE set active=0 WHERE email='{}'".format(taxi_list[8]))
181 newconn.commit()
182 newconn.close()
183 conn.execute("DELETE FROM RESERVED WHERE id={}".format(row_id))
184 conn.commit()
185 conn.close()
186 display_frames(customer_home_frame)
187
188
189
190def complete_ride(data):
191 conn = sql.connect("databases/Customer_Booking/Booking.db")
192 row_id = data[0]
193 if data[7] == 1:
194 newconn = sql.connect("databases/Driver_Trip_Information/Trips.db")
195 newconn.execute("UPDATE ACTIVE set active=0 WHERE email='{}'".format(data[8]))
196 newconn.commit()
197 newconn.close()
198 conn.execute("DELETE FROM Booking WHERE id={}".format(row_id))
199 conn.commit()
200 conn.close()
201 display_frames(driver_home_frame)
202
203def customer_confirm_booking_page(frame):
204 title_frame = Frame(frame,bg="#F9F9F9")
205 title_frame.pack(pady=(150,0))
206
207 body = tk.Frame(frame, bg="#F9F9F9")
208 body.pack()
209
210 conn = sql.connect("databases/Customer_Booking/Booking.db")
211 check1_table = table_exist(conn,"Booking")
212 if check1_table:
213 taxi_list = get_your_trip(conn, get_id_from_temp())
214 print("tc",taxi_list)
215 if len(taxi_list) ==0:
216 txt= "No Reservation!"
217 error = Label(body, text=txt, fg="#AFADAD", background="#F5F5F5", font=("Arial", 20, "bold"))
218 error.configure(height=3, width=20)
219 error.pack(pady=(200, 0))
220 else:
221 Id_label = Label(title_frame, text="Id", font=("arial", 9, "bold"), fg="#454545", bg="#E6E6E6")
222 Id_label.configure(width=7, height=2)
223 Id_label.pack(side=LEFT, padx=(0, 1), pady=(0, 5))
224 Name_label = Label(title_frame, text="Name", font=("arial", 9, "bold"), fg="#454545", bg="#E6E6E6")
225 Name_label.configure(width=10, height=2)
226 Name_label.pack(side=LEFT, padx=(0, 1), pady=(0, 5))
227 Phone_label = Label(title_frame, text="Phone", font=("arial", 9, "bold"), fg="#454545", bg="#E6E6E6")
228 Phone_label.configure(width=10, height=2)
229 Phone_label.pack(side=LEFT, padx=(0, 1), pady=(0, 5))
230 Pickaddress_label = Label(title_frame, text="Pick-Address", font=("arial", 9, "bold"), fg="#454545", bg="#E6E6E6")
231 Pickaddress_label.configure(width=10, height=2)
232 Pickaddress_label.pack(side=LEFT, padx=(0, 1), pady=(0, 5))
233 dropaddress_label = Label(title_frame, text="Drop-Address", font=("arial", 9, "bold"), fg="#454545", bg="#E6E6E6")
234 dropaddress_label.configure(width=12, height=2)
235 dropaddress_label.pack(side=LEFT, padx=(0, 1), pady=(0, 5))
236 Time_label = Label(title_frame, text="Time", font=("arial", 9, "bold"), fg="#454545", bg="#E6E6E6")
237 Time_label.configure(width=10, height=2)
238 Time_label.pack(side=LEFT, padx=(0, 1), pady=(0, 5))
239 Date_label = Label(title_frame, text="Date", font=("arial", 9, "bold"), fg="#454545", bg="#E6E6E6")
240 Date_label.configure(width=10, height=2)
241 Date_label.pack(side=LEFT, padx=(0, 1), pady=(0, 5))
242
243 count = 1
244 del_btn_list=[]
245 for data in taxi_list:
246 Id=IntVar()
247 Id.set(data[0])
248 body = tk.Frame(frame, bg="#F9F9F9")
249 body.pack()
250 Id_label = Label(body, text=str(count))
251 Id_label.configure(width=7, height=2)
252 Id_label.pack(side=LEFT, padx=(20, 1), pady=(0, 3))
253 Name_label = Label(body, text=data[2])
254 Name_label.configure(width=12, height=2)
255 Name_label.pack(side=LEFT, padx=(0, 1), pady=(0, 3))
256 Phone_label = Label(body, text=data[3])
257 Phone_label.configure(width=10, height=2)
258 Phone_label.pack(side=LEFT, padx=(0, 1), pady=(0, 3))
259 Pickaddress_label = Label(body, text=data[4])
260 Pickaddress_label.configure(width=12, height=2)
261 Pickaddress_label.pack(side=LEFT, padx=(0, 1), pady=(0, 3))
262 Dropaddress_label = Label(body, text=data[5])
263 Dropaddress_label.configure(width=12, height=2)
264 Dropaddress_label.pack(side=LEFT, padx=(0, 1), pady=(0, 3))
265 Time_label = Label(body, text=data[6])
266 Time_label.configure(width=12, height=2)
267 Time_label.pack(side=LEFT, padx=(0, 1), pady=(0, 3))
268 Date_label = Label(body, text=data[7])
269 Date_label.configure(width=12, height=2)
270 Date_label.pack(side=LEFT, padx=(0, 1), pady=(0, 3))
271
272 delimg = img_src("images/delete.png",(20,20))
273 delete = Button(body,image=delimg,border=0,bg="#F9F9F9",textvariable =id ,command=partial(delete_customer_reservation,taxi_list.index(data),conn,frame,taxi_list))
274 delete.image=delimg
275 delete.pack(side=LEFT)
276 del_btn_list.append(delete)
277 count += 1
278 else:
279 conn.close()
280 status_frame=Frame(frame,bg="#F9F9F9")
281 status_frame.pack(fill=BOTH)
282 dr_label=Label(status_frame,text="Driver email: ",font=("Arial",10,"bold"),bg="#F9F9F9")
283 dr_label.pack(side=LEFT,pady=(10,0),padx=(50,0))
284 driver=Label(status_frame,text=data[8])
285 driver.pack(side=LEFT,pady=(10,0))
286
287def img_src(src, imgsize):
288 openimg = Image.open(src)
289 w, h = openimg.size
290 if sum(imgsize) > 1:
291 openimg = openimg.resize(imgsize, Image.CUBIC)
292 timg = ImageTk.PhotoImage(openimg)
293 return timg
294
295
296def get_driver_trip():
297 conn = sql.connect("databases/Customer_Booking/Booking.db")
298 chck_tbl = table_exist(conn, "Booking")
299 temp = []
300 if chck_tbl:
301 query = conn.execute(
302 "SELECT rowId,Name, Phone, PickAddress, DropAddress, Time, Date, Active, Driver FROM Booking")
303
304 for row in query:
305 print(row[1])
306 if row[8] == get_id_from_temp():
307 temp.append(row)
308
309 return temp
310
311
312
313# <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< Driver Part >>>>>>>>>>>>>>>>>>>>>>>>>>
314
315def driver_registration_database():
316 chk_pwd = check_password_length(driver_password.get())
317 eml_check = check_email(driver_email.get())
318 if driver_name.get()=="" or driver_address.get()=="" or driver_phone.get()=="" or driver_email.get()=="" or driver_password.get()=="" or driver_confirm.get()=="" or driver_license.get()=="":
319 MessageBox.showerror("Error", "All fields are required to fill")
320 elif not eml_check:
321 MessageBox.showerror("Error", "Enter valid email")
322 return None
323 elif not chk_pwd:
324 MessageBox.showerror("Error", "Password length must be greater than 8")
325 return None
326 elif driver_password.get() != driver_confirm.get():
327 MessageBox.showerror("Error", "Password didnot match")
328
329 else:
330 try:
331 # Create a database if not exist
332 conn = sql.connect("Employee_info.db")
333
334 # Create a cursor to run queries
335 c = conn.cursor()
336
337 c.execute("""CREATE TABLE IF NOT EXISTS driver_information(
338 Id INTEGER PRIMARY KEY AUTOINCREMENT,
339 Name VARCHAR (100) NOT NULL,
340 Address VARCHAR (100) NOT NULL,
341 Phone VARCHAR (50) NOT NULL,
342 Email VARCHAR (100) UNIQUE NOT NULL,
343 Password VARCHAR (50) NOT NULL,
344 License VARCHAR (50) NOT NULL
345 )""")
346
347 # Execute
348 c.execute("SELECT * FROM driver_information WHERE Email=?", (driver_email.get(),))
349
350 driver = c.fetchone()
351
352 if driver != None:
353 MessageBox.showerror("Error", "User already Exist, Please try another email")
354 else:
355 # Execute Insert query against the database
356 c.execute("INSERT INTO driver_information(Name, Address, Phone, Email, Password, License) VALUES('{}','{}','{}','{}','{}','{}')"
357 .format(driver_name.get(), driver_address.get(), driver_phone.get(), driver_email.get(), driver_password.get(), driver_license.get()))
358
359 conn.commit()
360 conn.close()
361 MessageBox.showinfo("", "Registration Successfully")
362 display_frames(driver_home_frame)
363
364 # Deleting all information
365 driver_text_name.delete(0, END)
366 driver_text_address.delete(0, END)
367 driver_text_phone.delete(0, END)
368 driver_text_email.delete(0, END)
369 driver_text_password.delete(0, END)
370 driver_text_confirm.delete(0, END)
371 driver_text_license.delete(0, END)
372
373 except Error as e:
374 MessageBox.showerror("Error", f"Error due to: {str(e)}")
375
376
377def driver_registration_page(frame):
378 d_frame = Frame(frame, bd=2, relief=GROOVE, bg="white")
379 d_frame.place(x=175, y=55, width=500, height=510)
380
381 global driver_text_name
382 global driver_text_address
383 global driver_text_phone
384 global driver_text_email
385 global driver_text_password
386 global driver_text_confirm
387 global driver_text_license
388
389 # Create a registration label
390 label_registration = Label(d_frame, text="Registration Form", bg="white", font=("times", 20, "bold")).pack(side=TOP, fill=X)
391
392 name_label = Label(d_frame, text="Full Name", bg="white", font=("times", 15, "bold")).place(x=80, y=100)
393 address_label = Label(d_frame, text="Address", bg="white", font=("times", 15, "bold")).place(x=98, y=150)
394 phone_label = Label(d_frame, text="Phone Number", bg="white", font=("times", 15, "bold")).place(x=44, y=200)
395 email_label = Label(d_frame, text="Email", bg="white", font=("times", 15, "bold")).place(x=113, y=250)
396 password_label = Label(d_frame, text="Password", bg="white", font=("times", 15, "bold")).place(x=83, y=300)
397 confirm_label = Label(d_frame, text="Confirm Password", bg="white", font=("times", 15, "bold")).place(x=10, y=350)
398 license_label = Label(d_frame, text="License Plate", bg="white", font=("times", 15, "bold")).place(x=50, y=400)
399
400 driver_text_name = Entry(d_frame, textvariable=driver_name, bd=2, relief=GROOVE, bg="white", width=30, font=("", 12))
401 driver_text_name.place(x=200, y=100, height=33)
402 driver_text_address = Entry(d_frame, textvariable=driver_address, bd=2, relief=GROOVE, bg="white", width=30, font=("", 12))
403 driver_text_address.place(x=200, y=150, height=33)
404 driver_text_phone = Entry(d_frame, textvariable=driver_phone, bd=2, relief=GROOVE, bg="white", width=30, font=("", 12))
405 driver_text_phone.place(x=200, y=200, height=33)
406 driver_text_email = Entry(d_frame, textvariable=driver_email, bd=2, relief=GROOVE, bg="white", width=30, font=("", 12))
407 driver_text_email.place(x=200, y=250, height=33)
408 driver_text_password = Entry(d_frame, textvariable=driver_password, bd=2, relief=GROOVE, bg="white", width=30, font=("", 12))
409 driver_text_password.place(x=200, y=300, height=33)
410 driver_text_confirm = Entry(d_frame, textvariable=driver_confirm, bd=2, relief=GROOVE, bg="white", width=30, font=("", 12))
411 driver_text_confirm.place(x=200, y=350, height=33)
412 driver_text_license = Entry(d_frame, textvariable=driver_license, bd=2, relief=GROOVE, bg="white", width=30, font=("", 12))
413 driver_text_license.place(x=200, y=400, height=33)
414
415 submit_button = Button(d_frame, text="Submit", bd=1, width=10, height=1, command=driver_registration_database, font=("times", 15, "bold"))
416 submit_button.place(x=130, y=455)
417 exit_button = Button(d_frame, text="Exit", bd=1, width=10, height=1, command=lambda: display_frames(home_frame), font=("times", 15, "bold"))
418 exit_button.place(x=280, y=455)
419
420def driver_login_database():
421 # Checking whether the condition is meet or not
422 if driver_login_email.get() == "" or driver_login_password.get() == "":
423 MessageBox.showerror("Error", "All fields are required")
424 else:
425 try:
426 con = sql.connect('Employee_info.db')
427 c = con.cursor()
428
429 # Execute
430 c.execute("SELECT * FROM driver_information WHERE Email=? and Password=?", (driver_login_email.get(), driver_login_password.get()))
431 que = c.fetchone()
432 # print(que)
433 if que == None:
434 MessageBox.showerror("Error", "Invalid email & password")
435 else:
436 MessageBox.showinfo("Success", "Welcome")
437 display_frames(customer_booking_frame)
438
439 except Error as e:
440 MessageBox.showerror("Error", f"Error due to: {str(e)}")
441
442def driver_home_page(frame):
443 frame2 = Frame(frame, relief=GROOVE, bd=3)
444 frame2.place(x=180, y=70, width=530, height=480)
445
446 # #== Back ground Image ==
447 # bg_image = ImageTk.PhotoImage(file="Images/login.jpg")
448 # bg_label = Label(frame, image=bg_image)
449 # bg_label.place(x=180, y=30, width=420, height=510)
450
451 # Label
452 login_label = Label(frame2, text="Driver Login system", font=("times", 25, "bold"))
453 login_label.place(x=110, y=75)
454 email_label = Label(frame2, text="Email", font=("times", 18, "bold"))
455 email_label.place(x=65, y=210)
456 password_label = Label(frame2, text="Password", font=("times", 18, "bold"))
457 password_label.place(x=30, y=260)
458 email_text = Entry(frame2, bd=2, width=28, textvariable=driver_login_email, relief=GROOVE, font=("", 12))
459 email_text.place(x=170, y=210, width=270, height=35)
460 password_text = Entry(frame2, bd=2, width=28, textvariable=driver_login_password, relief=GROOVE, font=("", 12))
461 password_text.place(x=170, y=260, width=270, height=35)
462
463 button_login = Button(frame2, text="Login", relief=GROOVE, bd=2, fg="blue", width=18, command=driver_login_database, font=("times", 18, "bold"))
464 button_login.place(x=170, y=350)
465 button_register = Button(frame2, text="Signup", relief=GROOVE, bd=2, fg="green", width=18, command=lambda: display_frames(driver_registration_frame), font=("times", 18, "bold"))
466 button_register.place(x=170, y=400)
467 button_back = Button(frame2, text="Back", relief=GROOVE, bd=2, command=lambda: display_frames(home_frame), font=("times", 18, "bold"))
468 button_back.grid(row=0, column=0, sticky="nw")
469
470
471
472
473# <<<<<<<<<<<<<<<<< CUSTOMER Part>>>>>>>>>>>>>>>>>>>>>>>>>>>
474
475def customer_registration_database():
476 chk_pwd = check_password_length(customer_password.get())
477 eml_check = check_email(customer_email.get())
478
479 # Checking whether the field is empty or not
480 if customer_name.get() == "" or customer_address.get() == "" or customer_phone.get() == "" or customer_email.get() == "" or customer_password.get() == "" or customer_confirm.get() == "":
481 MessageBox.showerror("Error", "All fields are required to fill")
482 elif not eml_check:
483 MessageBox.showerror("Error", "Enter valid email")
484 return None
485 elif not chk_pwd:
486 MessageBox.showerror("Error", "Password length must be greater than 8")
487 return None
488 elif customer_password.get() != customer_confirm.get():
489 MessageBox.showerror("Error", "Password didnot match")
490 else:
491 try:
492 # Create a database if not exist
493 conn = sql.connect('Employee_info.db')
494
495 # Create a cursor to run queries
496 c = conn.cursor()
497 c.execute("""CREATE TABLE IF NOT EXISTS customer_information(
498 Id INTEGER PRIMARY KEY AUTOINCREMENT,
499 Name VARCHAR NOT NULL,
500 Address VARCHAR (100) NOT NULL,
501 Phone VARCHAR (50) NOT NULL,
502 Email VARCHAR (100) UNIQUE NOT NULL,
503 Password VARCHAR (50) NOT NULL
504 )""")
505 # Execute
506 c.execute("SELECT * FROM customer_information WHERE Email=?", (customer_email.get(),))
507 em = c.fetchone()
508
509 if em != None:
510 MessageBox.showerror("Error", "User already Exist, Please try another email")
511 else:
512 # Execute Insert query against the database
513 c.execute("INSERT INTO customer_information(Name, Address, Phone, Email, Password) VALUES(?,?,?,?,?)",
514 (customer_name.get(), customer_address.get(), customer_phone.get(), customer_email.get(),
515 customer_password.get()))
516
517 conn.commit()
518 conn.close()
519 MessageBox.showinfo("", "Registration Successfull")
520 display_frames(customer_home_frame)
521
522 # Deleting all information
523 customer_text_fullname.delete(0, END)
524 customer_text_address.delete(0, END)
525 customer_text_phone.delete(0, END)
526 customer_text_email.delete(0, END)
527 customer_text_password.delete(0, END)
528 customer_text_confirm.delete(0, END)
529
530 except Error as e:
531 MessageBox.showerror("Error", f"Error due to: {str(e)}")
532
533
534def customer_login_database():
535 # Checking whether the condition is meet or not
536 if customer_login_email.get() == "" or customer_login_password.get() == "":
537 MessageBox.showerror("Error", "All fields are required")
538 else:
539 try:
540 con = sql.connect('Employee_info.db')
541 c = con.cursor()
542
543 # Execute
544 c.execute("SELECT * FROM customer_information WHERE Email=? and Password=?", (customer_login_email.get(), customer_login_password.get()))
545 que = c.fetchone()
546 # print(que)
547 if que == None:
548 MessageBox.showerror("Error", "Invalid email & password")
549 else:
550 MessageBox.showinfo("Success", "Welcome")
551 em = open("temp/temp.txt","w")
552 em.write(customer_login_email.get())
553 em.close()
554 display_frames(customer_booking_frame)
555
556 except Error as e:
557 MessageBox.showerror("Error", f"Error due to: {str(e)}")
558
559
560def customer_confirm_booking_page(frame):
561 title_frame = Frame(frame,bg="#F9F9F9")
562 title_frame.pack(pady=(150,0))
563
564 body = tk.Frame(frame, bg="#F9F9F9")
565 body.pack()
566
567 conn = sql.connect("Employee_info.db")
568 check1_table = table_exist(conn,"Booking")
569 if check1_table:
570 taxi_list = get_your_trip(conn, get_id_from_temp())
571 print("tc",taxi_list)
572 if len(taxi_list) ==0:
573 txt= "No Reservation!"
574 error = Label(body, text=txt, fg="#AFADAD", background="#F5F5F5", font=("Arial", 20, "bold"))
575 error.configure(height=3, width=20)
576 error.pack(pady=(200, 0))
577 else:
578 Id_label = Label(title_frame, text="Id", font=("arial", 9, "bold"), fg="#454545", bg="#E6E6E6")
579 Id_label.configure(width=7, height=2)
580 Id_label.pack(side=LEFT, padx=(0, 1), pady=(0, 5))
581 Name_label = Label(title_frame, text="Name", font=("arial", 9, "bold"), fg="#454545", bg="#E6E6E6")
582 Name_label.configure(width=10, height=2)
583 Name_label.pack(side=LEFT, padx=(0, 1), pady=(0, 5))
584 Phone_label = Label(title_frame, text="Phone", font=("arial", 9, "bold"), fg="#454545", bg="#E6E6E6")
585 Phone_label.configure(width=10, height=2)
586 Phone_label.pack(side=LEFT, padx=(0, 1), pady=(0, 5))
587 Pickaddress_label = Label(title_frame, text="Pick-Address", font=("arial", 9, "bold"), fg="#454545", bg="#E6E6E6")
588 Pickaddress_label.configure(width=10, height=2)
589 Pickaddress_label.pack(side=LEFT, padx=(0, 1), pady=(0, 5))
590 dropaddress_label = Label(title_frame, text="Drop-Address", font=("arial", 9, "bold"), fg="#454545", bg="#E6E6E6")
591 dropaddress_label.configure(width=12, height=2)
592 dropaddress_label.pack(side=LEFT, padx=(0, 1), pady=(0, 5))
593 Time_label = Label(title_frame, text="Time", font=("arial", 9, "bold"), fg="#454545", bg="#E6E6E6")
594 Time_label.configure(width=10, height=2)
595 Time_label.pack(side=LEFT, padx=(0, 1), pady=(0, 5))
596 Date_label = Label(title_frame, text="Date", font=("arial", 9, "bold"), fg="#454545", bg="#E6E6E6")
597 Date_label.configure(width=10, height=2)
598 Date_label.pack(side=LEFT, padx=(0, 1), pady=(0, 5))
599
600 count = 1
601 del_btn_list=[]
602 for data in taxi_list:
603 Id=IntVar()
604 Id.set(data[0])
605 body = tk.Frame(frame, bg="#F9F9F9")
606 body.pack()
607 Id_label = Label(body, text=str(count))
608 Id_label.configure(width=7, height=2)
609 Id_label.pack(side=LEFT, padx=(20, 1), pady=(0, 3))
610 Name_label = Label(body, text=data[2])
611 Name_label.configure(width=12, height=2)
612 Name_label.pack(side=LEFT, padx=(0, 1), pady=(0, 3))
613 Phone_label = Label(body, text=data[3])
614 Phone_label.configure(width=10, height=2)
615 Phone_label.pack(side=LEFT, padx=(0, 1), pady=(0, 3))
616 Pickaddress_label = Label(body, text=data[4])
617 Pickaddress_label.configure(width=12, height=2)
618 Pickaddress_label.pack(side=LEFT, padx=(0, 1), pady=(0, 3))
619 Dropaddress_label = Label(body, text=data[5])
620 Dropaddress_label.configure(width=12, height=2)
621 Dropaddress_label.pack(side=LEFT, padx=(0, 1), pady=(0, 3))
622 Time_label = Label(body, text=data[6])
623 Time_label.configure(width=12, height=2)
624 Time_label.pack(side=LEFT, padx=(0, 1), pady=(0, 3))
625 Date_label = Label(body, text=data[7])
626 Date_label.configure(width=12, height=2)
627 Date_label.pack(side=LEFT, padx=(0, 1), pady=(0, 3))
628
629 delimg = img_src("images/delete.png",(20,20))
630 delete = Button(body,image=delimg,border=0,bg="#F9F9F9",textvariable =id ,command=partial(delete_customer_reservation,taxi_list.index(data),conn,frame,taxi_list))
631 delete.image=delimg
632 delete.pack(side=LEFT)
633 del_btn_list.append(delete)
634 count += 1
635 else:
636 conn.close()
637 status_frame=Frame(frame,bg="#F9F9F9")
638 status_frame.pack(fill=BOTH)
639 dr_label=Label(status_frame,text="Driver email: ",font=("Arial",10,"bold"),bg="#F9F9F9")
640 dr_label.pack(side=LEFT,pady=(10,0),padx=(50,0))
641 driver=Label(status_frame,text=data[8])
642 driver.pack(side=LEFT,pady=(10,0))
643
644def checktable(c):
645 c.cursor()
646 c.execute("CREATE TABLE IF NOT EXISTS reservation (id INTEGER PRIMARY KEY AUTOINCREMENT,pickup text,dropoff text,time text, date text,email text)")
647 c.commit()
648def get_email():
649 f = open("temp/temp.txt","r")
650 g=f.read()
651
652 f.close()
653 return g
654
655def customer_booking_db(datas):
656 customer_entry = sql.connect("customer_book.db")
657 email=get_email()
658 checktable(customer_entry)
659 customer_entry.execute("INSERT INTO reservation (pickup,dropoff,time,date,email) VALUES(?,?,?,?,?)",(datas[0],datas[1],datas[2]+datas[3],datas[4],email))
660 customer_entry.commit()
661
662# Define a function customer booking page
663def customer_booking_page(frame):
664
665
666 f_login = Frame(frame, relief=GROOVE, bd=2)
667 f_login.place(x=180, y=30, width=570, height=570)
668
669 book_label = Label(f_login, text="Book A Taxi", relief=GROOVE, bg="blue", font=("times", 25, "bold"))
670 book_label.pack(side=TOP, fill=X)
671 pick_label = Label(f_login, text="Pick-Up Address", font=("times", 18, "bold"))
672 pick_label.place(x=5, y=100)
673 drop_label = Label(f_login, text="Drop-Off Address", font=("times", 18, "bold"))
674 drop_label.place(x=5, y=150)
675 time_label = Label(f_login, text="Pick-Up Time", font=("times", 18, "bold"))
676 time_label.place(x=5, y=200)
677 ap_option = OptionMenu(f_login, am_pm, "AM", "PM")
678 ap_option.place(x=415, y=200)
679 date_label = Label(f_login, text="Select Date", font=("times", 18, "bold"))
680 date_label.place(x=5, y=250)
681
682 pick_text = Entry(f_login, bd=2, width=30, textvariable=pickup, relief=GROOVE, font=("", 12))
683 pick_text.place(x=240, y=100, height=35)
684 drop_text = Entry(f_login, bd=2, width=30, textvariable=dropoff, relief=GROOVE, font=("", 12))
685 drop_text.place(x=240, y=150, height=35)
686 t_entry = Entry(f_login, textvariable=time, bd=2, width=18, relief=GROOVE, font=("", 12))
687 t_entry.place(x=240, y=200, height=35)
688 d_entry = DateEntry(f_login, bd=2, width=18, year=2021, month=1, day=10, textvariable=date, font=("", 12))
689 d_entry.delete(0, END)
690 d_entry.place(x=240, y=250, height=35)
691
692 s1_button = Button(f_login, width=7, text="Reserve",command=lambda :customer_booking_db([pickup.get(),dropoff.get(),time.get(),am_pm.get(),date.get()]), font=("times", 18, "bold"))
693 s1_button.place(x=50, y=470)
694 s2_button = Button(f_login, width=7, text="View", command=lambda: display_frames(customer_confirm_booking_frame), font=("times", 18, "bold"))
695 s2_button.place(x=170, y=470)
696 s3_button = Button(f_login, text="Cancel", width=7, font=("times", 18, "bold"))
697 s3_button.place(x=290, y=470)
698 s4_button = Button(f_login, text="Exit", width=7, command=lambda: display_frames(customer_home_frame), font=("times", 18, "bold"))
699 s4_button.place(x=410, y=470)
700
701
702# Define a function customer registration page
703def customer_registration_page(frame):
704 global customer_text_fullname
705 global customer_text_address
706 global customer_text_phone
707 global customer_text_email
708 global customer_text_password
709 global customer_text_confirm
710
711 # Creating a new frame inside frame
712 frame3 = Frame(frame, relief=GROOVE, bd=3)
713 frame3.place(x=180, y=50, width=530, height=500)
714
715 register_label = Label(frame3, text="Registration Form", bg="green", font=("times", 20, "bold"))
716 register_label.grid(row=0, column=0, columnspan=2, padx=60, sticky=E)
717
718 label_fullname = Label(frame3, text="Full Name", font=("times", 18, "bold")).grid(row=1, column=0, pady=15)
719 customer_text_fullname = Entry(frame3, bd=2, textvariable=customer_name, relief=GROOVE, bg="white", width=25, font=("times", 13))
720 customer_text_fullname.grid(row=1, column=1, padx=20, ipady=6)
721
722 label_address = Label(frame3, text="Address", font=("times", 18, "bold")).grid(row=2, column=0, pady=15)
723 customer_text_address = Entry(frame3, bd=2, textvariable=customer_address, relief=GROOVE, bg="white", width=25, font=("times", 13))
724 customer_text_address.grid(row=2, column=1, padx=20, ipady=6)
725
726 label_phone = Label(frame3, text="Phone No.", font=("times", 18, "bold")).grid(row=3, column=0, pady=15)
727 customer_text_phone = Entry(frame3, bd=2, textvariable=customer_phone, relief=GROOVE, bg="white", width=25, font=("times", 13))
728 customer_text_phone.grid(row=3, column=1, padx=20, ipady=6)
729
730 label_email = Label(frame3, text="Email", font=("times", 18, "bold")).grid(row=4, column=0, pady=15)
731 customer_text_email = Entry(frame3, bd=2, textvariable=customer_email, relief=GROOVE, bg="white", width=25, font=("times", 13))
732 customer_text_email.grid(row=4, column=1, padx=20, ipady=6)
733
734 label_password = Label(frame3, text="Password", font=("times", 18, "bold")).grid(row=5, column=0, pady=15)
735 customer_text_password = Entry(frame3, bd=2, textvariable=customer_password, relief=GROOVE, bg="white", width=25, font=("times", 13))
736 customer_text_password.grid(row=5, column=1, padx=20, ipady=6)
737
738 label_confirm = Label(frame3, text="Confirm Password", font=("times", 18, "bold")).grid(row=6, column=0, pady=15)
739 customer_text_confirm = Entry(frame3, bd=2, textvariable=customer_confirm, relief=GROOVE, bg="white", width=25, font=("times", 13))
740 customer_text_confirm.grid(row=6, column=1, padx=20, ipady=6)
741
742 button_submit = Button(frame3, text="Submit", width=8, height=1, relief=GROOVE, command=customer_registration_database, font=("times", 15, "bold"))
743 button_submit.place(x=130, y=440)
744
745 button_exit = Button(frame3, text="Exit", width=10, height=1, relief=GROOVE, command=lambda: display_frames(customer_home_frame), font=("times", 15, "bold"))
746 button_exit.place(x=260, y=440)
747
748
749# Define a function customer home page
750def customer_home_page(frame):
751 # load = Image.open("Images\\login.png")
752 # ren = ImageTk.PhotoImage(load)
753 # img = Label(root, image=ren)
754 # img.place(x=0, y=0, relwidth=1, relheight=1)
755
756 # Create a new frame inside frame
757 frame2 = Frame(frame, relief=GROOVE, bd=3)
758 frame2.place(x=180, y=70, width=530, height=480)
759
760 # Label
761 login_label = Label(frame2, text="Customer Login system", font=("times", 25, "bold"))
762 login_label.place(x=110, y=75)
763
764 email_label = Label(frame2, text="Email", font=("times", 18, "bold"))
765 email_label.place(x=65, y=210)
766
767 password_label = Label(frame2, text="Password", font=("times", 18, "bold"))
768 password_label.place(x=30, y=260)
769
770 # Entry
771 email_text = Entry(frame2, bd=2, width=28, textvariable=customer_login_email, relief=GROOVE, font=("", 12))
772 email_text.place(x=170, y=210, width=270, height=35)
773
774 password_text = Entry(frame2, bd=2, width=28, textvariable=customer_login_password, relief=GROOVE, font=("", 12))
775 password_text.place(x=170, y=260, width=270, height=35)
776
777 # Button
778 button_login = Button(frame2, text="Login", relief=GROOVE, bd=2, fg="blue", width=18, command=customer_login_database, font=("times", 18, "bold"))
779 button_login.place(x=170, y=350)
780
781 button_register = Button(frame2, text="Signup", relief=GROOVE, bd=2, fg="green", width=18, command=lambda: display_frames(customer_registration_frame), font=("times", 18, "bold"))
782 button_register.place(x=170, y=400)
783
784 button_back = Button(frame2, text="Back", relief=GROOVE, bd=2, command=lambda :display_frames(home_frame), font=("times", 18, "bold"))
785 button_back.grid(row=0, column=0, sticky="nw")
786
787
788#<<<<<<<<<<<<<<<<<<<<<<< Home Page >>>>>>>>>>>>>>>>>>>>>>>
789
790# Define home page function
791def home_page(frame):
792 frame1 = Frame(frame, bd=2, relief=GROOVE)
793 frame1.place(x=180, y=60, width=530, height=480)
794
795 # Create a label taxi booking system
796 label1 = Label(frame1, text="Taxi Booking System", bd=4, bg="blue", font=("times", 20, "bold"), relief=SUNKEN, height=2)
797 label1.pack(side=TOP, fill=X)
798
799 # create a button admin, customer and driver
800 button_admin = Button(frame1, text="Admin", bd=2, height=1, width=20, bg="red",command=lambda :admin(frame) , font=("times", 20, "bold"))
801 button_admin.pack(pady=20)
802
803 button_customer = Button(frame1, text="Customer", bd=2, height=1, width=20, bg="green", command=lambda: display_frames(customer_home_frame), font=("times", 20, "bold"))
804 button_customer.pack()
805
806 button_driver = Button(frame1, text="Driver", bd=2, height=1, width=20, command=lambda: display_frames(driver_home_frame), bg="yellow", font=("times", 20, "bold"))
807 button_driver.pack(pady=20)
808
809 button_exit = Button(frame1, text="Quit", bd=2, height=1, width=20, command=lambda: root.destroy(), bg="yellow", font=("times", 20, "bold"))
810 button_exit.pack(pady=30)
811
812
813# <<<<<<<<<<<<<<<<<<<<<<<<<<<< Admin Part >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
814
815def admin(frame):
816 frame.master.destroy()
817 def get_customer_list():
818 conn = sql.connect("customer_book.db")
819 query = conn.execute("SELECT Id, pickup, dropoff, time, date, email FROM reservation")
820 temp = []
821 for row in query:
822 temp.append(row)
823 conn.close()
824 return temp
825
826 def get_available_driver():
827 conn = sql.connect("Employee_info.db")
828 temp = []
829 query = conn.execute("SELECT email,name FROM driver_information")
830 for row in query:
831
832 temp.append(row[0])
833 conn.close()
834 return temp
835
836 def refresh(frame):
837 frame.destroy()
838 frame = Frame(window, background="#F9F9F9")
839 frame.pack(fill=BOTH, expand=YES)
840 print(frame)
841 body(frame)
842
843 def register_driver(email, id, driver):
844 print(email.get(), id)
845 verify = MessageBox.askokcancel("Verify", "{} will be selected driver for this customer.".format(email.get()))
846
847
848
849 def card(canvas, datas, x, y, driver_var, root):
850 driver_var.trace('w', lambda name, index, mode, email=driver_var: register_driver(email, datas[0], drivers))
851 canvas.create_rectangle(40 + x, 50 + y, 290 + x, 200 + y, fill="#E7E6E6", outline="#E7E6E6")
852
853 email = Label(root, text="Email : " + datas[5], bg="#E7E6E6")
854 canvas.create_window(80 + x, 60 + y, window=email, anchor=NW)
855 pcka_lbl = Label(root, text="From : " + datas[1], bg="#E7E6E6")
856 canvas.create_window(80 + x, 80 + y, window=pcka_lbl, anchor=NW)
857 drpa_lbl = Label(root, text="To : " + datas[2 ], bg="#E7E6E6")
858 canvas.create_window(80 + x, 100 + y, window=drpa_lbl, anchor=NW)
859 time_lbl = Label(root, text="Time : " + datas[3], bg="#E7E6E6")
860 canvas.create_window(150 + x, 100 + y, window=time_lbl, anchor=NW)
861 date_lbl = Label(root, text="Date : " + datas[4], bg="#E7E6E6")
862 canvas.create_window(80 + x, 120 + y, window=date_lbl, anchor=NW)
863
864 drivers = get_available_driver()
865 option_lbl = OptionMenu(root, driver_var, *drivers)
866 option_lbl.configure(width=20, border=0)
867 canvas.create_window(80 + x, 165 + y, window=option_lbl, anchor=NW)
868 return email
869
870 def body(root):
871 Label(root, text="ADMIN PANEL", font=("Arial", 20, "bold"), fg="#3D3D3D").pack(ipady=(10))
872
873 canvas = Canvas(root, bd=0, highlightthickness=0, bg="#F9F9F9",
874 scrollregion=(0, 0, 500, 500))
875 canvas.pack(fill=BOTH, expand=YES)
876
877 customers = get_customer_list()
878 x, y, count = 0, 0, 1
879
880 for datas in customers:
881
882 card(canvas, datas, x, y, StringVar(), root)
883 x += 260
884 if count % 2 == 0:
885 x = 0
886 y += 160
887
888 count += 1
889
890 window = tk.Tk()
891 w = 600
892 h = 600
893
894 window.geometry(str(w) + 'x' + str(h))
895 window.title("Admin")
896 window.wm_resizable(False, False)
897 frame = Frame(window)
898 frame.pack(fill=BOTH, expand=YES)
899
900 body(frame)
901
902 window.mainloop()
903
904
905
906
907# Creating a new window
908root = tk.Tk()
909
910root.title("Taxi Login System")
911#root.state("zoomed")
912root.geometry("850x650+250+20")
913root.rowconfigure(0, weight=1)
914root.columnconfigure(0, weight=1)
915root.configure(bg="lightblue")
916root.resizable(False, False)
917
918
919# Global variables of customers
920customer_login_email = StringVar()
921customer_login_password = StringVar()
922
923pickup = StringVar()
924dropoff = StringVar()
925date = StringVar()
926time = StringVar()
927am_pm = StringVar()
928customer_name = StringVar()
929customer_address = StringVar()
930customer_phone = StringVar()
931customer_email = StringVar()
932customer_password = StringVar()
933customer_confirm = StringVar()
934
935
936
937
938
939# Global variables of drivers
940driver_login_email = StringVar()
941driver_login_password = StringVar()
942driver_name = StringVar()
943driver_address = StringVar()
944driver_phone = StringVar()
945driver_email = StringVar()
946driver_password = StringVar()
947driver_confirm = StringVar()
948driver_license = StringVar()
949
950
951
952
953
954
955# Frames for customer, driver and admin system
956home_frame = tk.Frame(root, bg="red")
957# admin_login_frame = tk.Frame(root, bg="lightblue")
958customer_home_frame = tk.Frame(root, bg="green")
959driver_home_frame = tk.Frame(root, bg="blue")
960customer_login_frame = tk.Frame(root)
961customer_registration_frame = tk.Frame(root)
962customer_booking_frame = tk.Frame(root)
963driver_login_frame = tk.Frame(root)
964driver_registration_frame = tk.Frame(root)
965reserve_taxi_frame = tk.Frame(root)
966
967# StringVariable
968pick = StringVar()
969drop = StringVar()
970dates = StringVar()
971times = StringVar()
972ap = StringVar()
973ap.set("AM")
974
975# Creating a list to store all the frames
976my_frames = [home_frame, customer_home_frame, driver_home_frame, customer_login_frame, customer_registration_frame
977 ,customer_booking_frame, driver_login_frame, driver_registration_frame, reserve_taxi_frame]
978
979
980# Creating a loop for frames
981for frame in my_frames:
982 frame.grid(row=0, column=0, sticky="nsew")
983
984
985home_page(home_frame)
986# admin_login_page(admin_login_frame)
987customer_home_page(customer_home_frame)
988customer_registration_page(customer_registration_frame)
989customer_booking_page(customer_booking_frame)
990driver_home_page(driver_home_frame)
991driver_registration_page(driver_registration_frame)
992#customer_reservation_page(customer_login_frame)
993#view_trips(customer_reservation_frame)
994
995
996display_frames(home_frame)
997
998root.mainloop()
999