-
Notifications
You must be signed in to change notification settings - Fork 2
/
CarInfoForParking.py
263 lines (216 loc) · 10.4 KB
/
CarInfoForParking.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
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
from tkinter import font
import tkinter
from datetime import datetime, date
import GenerateRandomInfo
import SendEmail
import mysql.connector
mydb = mysql.connector.Connect(
host='localhost',
user='root',
password='Kiran@982326',
database='ParkingLot'
)
# class for getting all car information
class Enter_car(object):
def __init__(self):
self.carNumber = None
self.carType = None
self.carColor = None
self.__cardType = None
self.__cardNumber = None
self.SpotNum = None
self.date = None
self.timeNow = None
def carInfoFrame(self):
# frame for getting all car information from user
self.f3 = tkinter.Frame()
self.f3.place(x=0, y=0, width=640, height=480)
self.f3.config(bg='#FA8072')
label = tkinter.Label(self.f3, text="Parking Ticket Information", bg='#FFDAB9')
label.grid(row=0, column=1, sticky='w')
label['font'] = tkinter.font.Font(size=15, family='Helvetica', weight='bold')
# label and entry for car number
carNumberLabel = tkinter.Label(self.f3, text="Car Number : ", width=20, bg='#FFDAB9')
carNumberLabel.grid(row=1, column=0, sticky='ne')
carNumberLabel['font'] = tkinter.font.Font(size=10, family='Helvetica', weight='bold')
self.carNumberEntry = tkinter.Entry(self.f3)
CN = GenerateRandomInfo.CarNumberRand()
self.carNumberEntry.insert(0, CN) # insert an information in entry box
self.carNumberEntry.grid(row=1, column=1, sticky='n')
# label and entry for car color
carColorLabel = tkinter.Label(self.f3, text="Car Color : ", width=20, bg='#FFDAB9')
carColorLabel.grid(row=2, column=0, sticky='ne')
carColorLabel['font'] = tkinter.font.Font(size=10, family='Helvetica', weight='bold')
self.carColorEntry = tkinter.Entry(self.f3)
CC = GenerateRandomInfo.CarColorRand()
self.carColorEntry.insert(0, CC) # insert an information in entry box
self.carColorEntry.grid(row=2, column=1, sticky='n')
# label and entry for car type
carTypeLabel = tkinter.Label(self.f3, text=" Car Type : ", width=20, bg='#FFDAB9')
carTypeLabel.grid(row=3, column=0, sticky='ne')
carTypeLabel['font'] = tkinter.font.Font(size=10, family='Helvetica', weight='bold')
self.carTypeEntry = tkinter.Entry(self.f3)
CT = GenerateRandomInfo.CarTypeRand()
self.carTypeEntry.insert(0, CT)
self.carTypeEntry.grid(row=3, column=1, sticky='n')
# label and entry for card type
cardTypeLabel = tkinter.Label(self.f3, text=" Card Type : ", width=20, bg='#FFDAB9')
cardTypeLabel.grid(row=4, column=0, sticky='ne')
cardTypeLabel['font'] = tkinter.font.Font(size=10, family='Helvetica', weight='bold')
self.cardTypeEntry = tkinter.Entry(self.f3)
CardT = GenerateRandomInfo.getCardType()
self.cardTypeEntry.insert(0, CardT)
self.cardTypeEntry.grid(row=4, column=1, sticky='n')
# label and entry for card number
cardNumberLabel = tkinter.Label(self.f3, text=" Card Number : ", width=20, bg='#FFDAB9')
cardNumberLabel.grid(row=5, column=0, sticky='ne')
cardNumberLabel['font'] = tkinter.font.Font(size=10, family='Helvetica', weight='bold')
self.cardNumberEntry = tkinter.Entry(self.f3)
CardN = GenerateRandomInfo.getCardNumber()
self.cardNumberEntry.insert(0, CardN)
self.cardNumberEntry.grid(row=5, column=1, sticky='n')
ok = tkinter.Button(self.f3, text="Ok", bg='#FF7F50', activebackground='#FFA500',
command=self.CheckInfo)
ok.grid(row=5, column=1, sticky='e')
cancel = tkinter.Button(self.f3, text="Cancel", bg='#FF7F50', activebackground='#FFA500',
command=self.f3.destroy)
cancel.grid(row=5, column=2, sticky='w')
self.f3.rowconfigure(0, weight=1)
self.f3.rowconfigure(1, weight=1)
self.f3.rowconfigure(2, weight=1)
self.f3.rowconfigure(3, weight=1)
self.f3.rowconfigure(4, weight=1)
self.f3.rowconfigure(5, weight=2)
self.f3.columnconfigure(0, weight=1)
self.f3.columnconfigure(1, weight=1)
self.f3.columnconfigure(2, weight=1)
# methode for showing an warning
def WarningWindow(self):
self.window = tkinter.Tk()
self.window.title("PARKING LOT")
self.window.geometry("200x100-200-400")
self.window.config(bg="#FA8072")
self.window['pady'] = 5
label = tkinter.Label(self.window, text="WARNING!", bg='#FA8072')
label.pack(side='top')
label['font'] = tkinter.font.Font(size=15, family='Helvetica', weight='bold')
label2 = tkinter.Label(self.window, text='Please Enter all information.', bg='#FA8072')
label2.pack(side='top')
# ok button for destroy frame
ok = tkinter.Button(self.window, text="OK", bg='#FF7F50', activebackground='#FFA500',
command=self.window.destroy)
ok.pack(side='bottom', anchor='n')
ok['font'] = tkinter.font.Font(size=15)
# ok['pady'] = 5
self.window.minsize(200, 100)
self.window.maxsize(200, 100)
self.window.mainloop()
# check methode for checking all information of car
def CheckInfo(self):
if self.carColorEntry.get() and self.carTypeEntry.get() and self.carNumberEntry.get() and self.cardTypeEntry.get() and self.cardNumberEntry.get():
self.info()
self.storeInfoInDB()
return self.ParkingTicket()
else:
return self.WarningWindow()
# methode for assigned all info
def info(self):
self.carNumber = self.carNumberEntry.get()
self.carType = self.carTypeEntry.get()
self.carColor = self.carColorEntry.get()
self.__cardType = self.cardTypeEntry.get()
self.__cardNumber = self.cardNumberEntry.get()
self.SpotNum = GenerateRandomInfo.getSpotNumDB()
now = datetime.now()
self.date = date.today()
self.timeNow = now.strftime('%I:%M %p')
# methode for show user parking ticket
def ParkingTicket(self):
arr1 = ['\tCar Number', '\tCar Type', '\tCar Color', '\tParking Date', '\tParking Time', '\tSpot Number']
arr2 = [self.carNumber, self.carType, self.carColor, self.date, self.timeNow, self.SpotNum]
# frame for parking ticket
self.f4 = tkinter.Frame()
self.f4.place(x=0, y=0, width=640, height=480)
self.f4.config(bg='#FA8072')
label = tkinter.Label(self.f4, text='Parking Ticket', bg='#FFDAB9')
label.grid(row=0, column=1, sticky='we')
label['padx'] = 100
label['font'] = tkinter.font.Font(size=15, family='Helvetica', weight='bold')
# frame for show all parking ticket info on frame f4
la = tkinter.Frame(self.f4)
la.place(x=160, y=90, width=330, height=260)
la.config(bg='#90EE90')
la['padx'] = 8
# show all information on parking ticket
for i in range(6):
text = tkinter.Label(la, text=arr1[i], bg='#90EE90')
text.grid(row=i, column=0, sticky='w')
text['font'] = tkinter.font.Font(size=10, family='Helvetica', weight='bold')
colon = tkinter.Label(la, text=':', bg='#90EE90')
colon.grid(row=i, column=1, sticky='w')
colon['font'] = tkinter.font.Font(size=10, family='Helvetica', weight='bold')
data = tkinter.Label(la, text=arr2[i], bg='#90EE90')
data.grid(row=i, column=2, sticky='w')
data['font'] = tkinter.font.Font(size=10, family='Helvetica', weight='bold')
# configure the row of frame la
for i in range(6):
la.rowconfigure(i, weight=1)
# configure the column of frame la
la.columnconfigure(0, weight=1)
la.columnconfigure(1, weight=1)
la.columnconfigure(2, weight=3)
# ok button on f4 frame
okButton = tkinter.Button(self.f4, text=' Ok ', bg='#FF7F50', activebackground='#FFA500',
command=self.destroyFrame)
okButton.grid(row=2, column=1, sticky='ne')
# backButton = tkinter.Button(self.f4, text='Back', bg='#FF7F50', activebackground='#FFA500',
# command=self.f4.destroy)
# backButton.grid(row=2, column=2, sticky='en')
# print button on f4 frame
getTicketButton = tkinter.Button(self.f4, text='Get Ticket', bg='#FF7F50', activebackground='#FFA500',
command=self.sendInfoToMail)
getTicketButton.grid(row=2, column=1, sticky='nw')
# configure the row of frame f4
self.f4.rowconfigure(0, weight=1)
self.f4.rowconfigure(1, weight=3)
self.f4.rowconfigure(2, weight=1)
# configure the column of frame f4
self.f4.columnconfigure(0, weight=1)
self.f4.columnconfigure(1, weight=2)
self.f4.columnconfigure(2, weight=1)
# destroy Frame f4 and f3
def destroyFrame(self):
# self.storeInfoInDB()
self.f4.destroy()
self.f3.destroy()
def sendInfoToMail(self):
# parking ticket
str = f"""
__________________________________________
\t\tCar Number : {self.carNumber}
\t\tCar Type : {self.carType}
\t\tCar Color : {self.carColor}
\t\tDate : {self.date}
\t\tParking Time : {self.timeNow}
\t\tSpot : {self.SpotNum}
_________________________________________"""
# object of sendEmail class
obj = SendEmail.sendParkingTicket(str)
obj.windowForEmail()
# Store Information in Data base
def storeInfoInDB(self):
myc = mydb.cursor()
sql = "INSERT INTO ParkingLot.ParkingInfo(CarNumber, CarColor, CarType, CardType, CardNumber, ParkingTime, ParkingDate, SpotNum) VALUES(%s, %s, %s, %s, %s, %s, %s, %s)"
val = [str(self.carNumber),
str(self.carColor),
str(self.carType),
str(self.__cardType),
str(self.__cardNumber),
str(self.timeNow),
str(self.date),
self.SpotNum]
myc.execute(sql, val)
sql = "UPDATE ParkingSpot SET Spot = 'Parked' WHERE SrNum = %s"
val = [self.SpotNum]
myc.execute(sql, val)
mydb.commit()