-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdriverDashboard.py
221 lines (185 loc) · 12.7 KB
/
driverDashboard.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
from tkinter import *
from tkinter.font import BOLD
from tkinter import ttk
from tkinter import messagebox
import functools
import databaseConnection
#======================================================================GUI_Designing======================================================================================
class DriverDashboardClass:
def __init__(self, root, email):
self.root=root
self.email=email
self.root.geometry("1100x500+10+130")
self.root.title("Assign Driver || CarGO")
self.root.config(bg="white")
self.root.focus_force()
self.root.resizable(0,0)
self.Table()
#===========ProjectIcon=============
photo = PhotoImage(file = "images/taxitrip.png")
self.root.iconphoto(False, photo)
#================titel====================================
title=Label(self.root, text="Driver Dashboard", font=("goudy old style",20,"bold"),bg="#0f4d7d", fg="white").place(x=30,y=15, width=1040)
#===============BookedFrame=========================
foot=LabelFrame(self.root, font=("goudy old style",12,"bold"), bd=2, relief=RIDGE, bg="white")
foot.place(x=30, y=380, width=1040, height=100)
lbl_tl=Label(foot, text="Note: " + self.email +" After completing trip please hit the 'Complete Trip' button to update your status.", font=("goudy old style",15),bg="white").place(x=10,y=35)
#==========================UpdateStatusBtn==============================
btn_Cstatus=Button(foot,text="Complete Trip", command=self.ChangeStatus, font=("goudy old style",15), bg="#4caf50", activebackground="#4caf50", fg="white", activeforeground="white",cursor="hand2").place(x=890,y=35,width=125,height=30)
def Table(self):
#===============BookedFrame=========================
NewBook=LabelFrame(self.root, font=("goudy old style",12,"bold"), bd=2, relief=RIDGE, bg="white")
NewBook.place(x=30, y=70, width=500, height=300)
#================BookedTitel====================================
Bookedtitle=Label(NewBook, text="Your New Trip List", font=("goudy old style",15,"bold"),bg="#418BCA", fg="white").pack(side=TOP,fill=X)
#=================Scrollbar=============================
scrolly=Scrollbar(NewBook,orient=VERTICAL)
scrollx=Scrollbar(NewBook,orient=HORIZONTAL)
#=================BookedTripTable=============================
self.RegistrationTable=ttk.Treeview(NewBook,columns=("booking.booking_id","booking.picDate","booking.dropDate","booking.picTime","booking.dropTime","booking.picAddress","booking.dropAddress","booking.status","registration.name","customer.name"),yscrollcommand=scrolly.set,xscrollcommand=scrollx.set)
scrollx.pack(side=BOTTOM,fill=X) #b.booking_id, b.picDate, b.dropDate, b.picTime, b.dropTime, b.picAddress, b.dropAddress, r.name,c.name
scrolly.pack(side=RIGHT,fill=Y)
scrollx.config(command=self.RegistrationTable.xview)
scrolly.config(command=self.RegistrationTable.yview)
self.RegistrationTable.heading("booking.booking_id",text="Booking ID")
self.RegistrationTable.heading("booking.picDate",text="Pick-Up Date")
self.RegistrationTable.heading("booking.dropDate",text="Drop Date")
self.RegistrationTable.heading("booking.picTime",text="Pick-Up Time")
self.RegistrationTable.heading("booking.dropTime",text="Drop Time")
self.RegistrationTable.heading("booking.picAddress",text="Pick-Up Address")
self.RegistrationTable.heading("booking.dropAddress",text="Drop Address")
self.RegistrationTable.heading("booking.status",text="Status")
self.RegistrationTable.heading("registration.name",text="Driver")
self.RegistrationTable.heading("customer.name",text="Customer")
self.RegistrationTable["show"]="headings"
self.RegistrationTable.column("booking.booking_id",width=80)
self.RegistrationTable.column("booking.picDate",width=100)
self.RegistrationTable.column("booking.dropDate",width=100)
self.RegistrationTable.column("booking.picTime",width=100)
self.RegistrationTable.column("booking.dropTime",width=100)
self.RegistrationTable.column("booking.picAddress",width=100)
self.RegistrationTable.column("booking.dropAddress",width=100)
self.RegistrationTable.column("booking.status",width=100)
self.RegistrationTable.column("registration.name",width=100)
self.RegistrationTable.column("customer.name",width=100)
self.RegistrationTable.pack(fill=BOTH,expand=1)
# self.RegistrationTable.bind("<ButtonRelease-1>",self.get_Booked_data)
self.showNewData()
#===============BookedFrame=========================
ClosedBook=LabelFrame(self.root, font=("goudy old style",12,"bold"), bd=2, relief=RIDGE, bg="white")
ClosedBook.place(x=570, y=70, width=500, height=300)
#================BookedTitel====================================
Closetitle=Label(ClosedBook, text="Your Old Trip List", font=("goudy old style",15,"bold"),bg="#C42F11", fg="white").pack(side=TOP,fill=X)
#=================Scrollbar=============================
scrolly=Scrollbar(ClosedBook,orient=VERTICAL)
scrollx=Scrollbar(ClosedBook,orient=HORIZONTAL)
#=================BookedTripTable=============================
self.RegistrationTable=ttk.Treeview(ClosedBook,columns=("booking.booking_id","booking.picDate","booking.dropDate","booking.picTime","booking.dropTime","booking.picAddress","booking.dropAddress","booking.status","registration.name","customer.name"),yscrollcommand=scrolly.set,xscrollcommand=scrollx.set)
scrollx.pack(side=BOTTOM,fill=X) #b.booking_id, b.picDate, b.dropDate, b.picTime, b.dropTime, b.picAddress, b.dropAddress, r.name,c.name
scrolly.pack(side=RIGHT,fill=Y)
scrollx.config(command=self.RegistrationTable.xview)
scrolly.config(command=self.RegistrationTable.yview)
self.RegistrationTable.heading("booking.booking_id",text="Booking ID")
self.RegistrationTable.heading("booking.picDate",text="Pick-Up Date")
self.RegistrationTable.heading("booking.dropDate",text="Drop Date")
self.RegistrationTable.heading("booking.picTime",text="Pick-Up Time")
self.RegistrationTable.heading("booking.dropTime",text="Drop Time")
self.RegistrationTable.heading("booking.picAddress",text="Pick-Up Address")
self.RegistrationTable.heading("booking.dropAddress",text="Drop Address")
self.RegistrationTable.heading("booking.status",text="Status")
self.RegistrationTable.heading("registration.name",text="Driver")
self.RegistrationTable.heading("customer.name",text="Customer")
self.RegistrationTable["show"]="headings"
self.RegistrationTable.column("booking.booking_id",width=80)
self.RegistrationTable.column("booking.picDate",width=100)
self.RegistrationTable.column("booking.dropDate",width=100)
self.RegistrationTable.column("booking.picTime",width=100)
self.RegistrationTable.column("booking.dropTime",width=100)
self.RegistrationTable.column("booking.picAddress",width=100)
self.RegistrationTable.column("booking.dropAddress",width=100)
self.RegistrationTable.column("booking.status",width=100)
self.RegistrationTable.column("registration.name",width=100)
self.RegistrationTable.column("customer.name",width=100)
self.RegistrationTable.pack(fill=BOTH,expand=1)
# self.RegistrationTable.bind("<ButtonRelease-1>",self.get_Booked_data)
self.showClosedData()
# ======================================================DatabaseConnections=============================================================================
# =====================ShowLoginDriver'sCustomerOnly======================
def showNewData(self):
databaseConnection
# Find_User
find_userId=("SELECT reg_id from registration WHERE email = '%s'" % (self.email))
databaseConnection.cur.execute(find_userId)
userId=databaseConnection.cur.fetchone()[0]
print(userId)
try:
databaseConnection.cur.execute("select booking.booking_id, booking.picDate,booking.dropDate, booking.picTime, booking.dropTime, booking.picAddress, booking.dropAddress, booking.status, registration.name, customer.name from booking LEFT OUTER JOIN registration on registration.reg_id=booking.reg_id JOIN customer on customer.c_id=booking.c_id WHERE booking.status='Conformed' and registration.reg_id=? ",(
userId,
))
rows = databaseConnection.cur.fetchmany()
print(rows)
self.RegistrationTable.delete(*self.RegistrationTable.get_children())
for row in rows:
self.RegistrationTable.insert('', END, values=row)
except Exception as ex:
messagebox.showerror(
"Error", f"Error due to : {str(ex)}", parent=self.root)
# =====================ShowLoginDriver'sCustomerOnly======================
def showClosedData(self):
databaseConnection
# Find_User
find_userId=("SELECT reg_id from registration WHERE email = '%s'" % (self.email))
databaseConnection.cur.execute(find_userId)
userId=databaseConnection.cur.fetchone()[0]
print(userId)
try: #select b.booking_id, b.picDate, b.dropDate, b.picTime, b.dropTime, b.picAddress, b.dropAddress, r.name,c.name from booking b JOIN registration r on r.reg_id=b.reg_id JOIN customer c on c.c_id=b.c_id where b.status='Active' and r.email= ?
databaseConnection.cur.execute("select booking.booking_id, booking.picDate,booking.dropDate, booking.picTime, booking.dropTime, booking.picAddress, booking.dropAddress, booking.status, registration.name, customer.name from booking LEFT OUTER JOIN registration on registration.reg_id=booking.reg_id JOIN customer on customer.c_id=booking.c_id where (booking.status= 'Closed' or booking.status= 'Paid') and registration.reg_id= ? ",(
userId,
))
rows = databaseConnection.cur.fetchall()
print(rows)
self.RegistrationTable.delete(*self.RegistrationTable.get_children())
for row in rows:
self.RegistrationTable.insert('', END, values=row)
except Exception as ex:
messagebox.showerror(
"Error", f"Error due to : {str(ex)}", parent=self.root)
#===============================ToChangeTheStatusOfDriverAndBooking===========================
def ChangeStatus(self):
databaseConnection
# Find_User
find_userId=("SELECT reg_id from registration WHERE email = '%s'" % (self.email))
databaseConnection.cur.execute(find_userId)
userId=databaseConnection.cur.fetchone()[0]
try:
databaseConnection.cur.execute("Update registration set status='Available' where reg_id=?",
(userId,))
databaseConnection.con.commit()
self.ChangeBookingStatus()
messagebox.showinfo("Status", "Status Successfully Updated", parent=self.root)
self.Table()
except Exception as ex:
messagebox.showerror(
"Error", f"Error due to : {str(ex)}", parent=self.root)
def ChangeBookingStatus(self):
databaseConnection
# Find_User
find_userId=("SELECT reg_id from registration WHERE email = '%s'" % (self.email))
databaseConnection.cur.execute(find_userId)
userId=databaseConnection.cur.fetchone()[0]
# Find BookingId
databaseConnection.cur.execute("SELECT booking_id FROM booking WHERE reg_id=? and status='Confirmed'",(userId,))
bookingId=databaseConnection.cur.fetchone()
bookId = functools.reduce(lambda sub, ele: sub * 10 + ele, bookingId)
try:
databaseConnection.cur.execute("Update booking set status='Closed' where booking_id=?",
(bookId, ))
databaseConnection.con.commit()
except Exception as ex:
messagebox.showerror(
"Error", f"Error due to : {str(ex)}", parent=self.root)
#==========MainMethod============
if __name__=="__main__":
root=Tk()
obj=DriverDashboardClass(root)
root.mainloop()