-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCAR PARKING PROJECT.py
358 lines (288 loc) · 10.7 KB
/
CAR PARKING PROJECT.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
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
import mysql.connector as sql
import time
from datetime import date
global mydb, cursor
mydb = sql.connect(
host='localhost', database='parking_system', user='root', password='S@ndip4337')
cursor = mydb.cursor()
def clear():
for _ in range(5):
print()
def display_parking_type_records():
cursor.execute('select * from parking_type;')
records = cursor.fetchall()
for row in records:
print(row)
def login():
while True:
clear()
uname = input('Enter your name :')
upass = input('Enter your Password :')
cursor.execute('select * from login where name="{}" and pwd ="{}"'.format(uname, upass))
cursor.fetchall()
rows = cursor.rowcount
if rows != 1:
print('Invalid Login details..... Try again')
else:
print('You are eligible for operating this system............')
break
def add_parking_type_record():
clear()
name = input('Enter Parking Type( 1. Two wheelar 2. Car 3. Bus 4. Truck 5. Trolly ) : ')
price = input('Enter Parking Price per day : ')
sql = 'insert into parking_type(name,price) values("{}",{});'.format(name, price)
cursor.execute(sql)
print('\n\n New Parking Type added....')
cursor.execute('select max(id) from parking_type')
no = cursor.fetchone()
print(' New Parking Type ID is : {} \n\n\n'.format(no[0]))
wait = input('\n\n\nPress any key to continue............')
def add_parking_slot_record():
clear()
print("PARKING TYPE RECORDS:")
display_parking_type_records()
print("*" * 100)
parking_type_id = input(
'Enter Parking Type ID FROM ABOVE LIST(1,2,3...etc):')
status = input('Enter current Status ( Open/Full ) :')
sql = 'insert into parking_space(type_id,status) values ("{}","{}");'.format(parking_type_id, status)
cursor.execute(sql)
print('\n\n New Parking Space Record added....')
cursor.execute('select max(id) from parking_space;')
no = cursor.fetchone()
print(' Your Parking ID is : {} \n\n\n'.format(no[0]))
wait = input('\n\n\nPress any key to continue............')
def modify_parking_type_record():
clear()
print(' M O D I F Y P A R K I N G T Y P E S C R E E N ')
print('-' * 100)
display_parking_type_records()
print('-' * 100)
print('1. Parking Type Name \n')
print('2. Parking Price \n')
print('3. delete any perking_type \n')
choices = [1, 2, 3]
choice = 0
while choice not in choices:
choice = int(input("enter choice between 1/2/3:"))
field = ''
if choice == 1:
field = 'name'
park_id = input('Enter Parking Type ID :')
value = input('Enter new values :')
sql = 'update parking_type set ' + field + ' = "{}" where id ="{}";'.format(value,park_id)
cursor.execute(sql)
if choice == 2:
field = 'price'
park_id = input('Enter Parking Type ID :')
value = input('Enter new values :')
sql = 'update parking_type set ' + field + ' = "' + value + '" where id =' + park_id + ';'
cursor.execute(sql)
if choice == 3:
park_id = input('Enter Parking Type ID which you want to delete :')
sql = 'delete from parking_type where id = ' + park_id + ';'
cursor.execute(sql)
print('Record updated successfully................')
display_parking_type_records()
wait = input('\n\n\nPress any key to continue............')
def modify_parking_space_record():
clear()
print(' M O D I F Y P A R K I N G S P A C E R E C O R D ')
print('-' * 100)
print('1. Parking Type ID(1-Two Wheelar, 2: Car 3.Bus etc ): ')
print('2. status \n')
choice = [1, 2]
choices = 0
while choices not in choice:
choices = int(input("enter choice between 1/2:"))
if choices == 1:
field = 'type_id'
print('\n\n\n')
crime_id = input('Enter Parking Space ID :')
value = input('Enter new values :')
sql = 'update parking_space set ' + field + \
' = "' + value + '" where id =' + crime_id + ';'
cursor.execute(sql)
print('Record updated successfully................')
wait = input('\n\n\nPress any key to continue............')
if choices == 2:
field = 'status'
print('\n\n\n')
crime_id = input('Enter Parking Space ID :')
value = input('Enter new values :')
sql = 'update parking_space set ' + field + \
' = "' + value + '" where id =' + crime_id + ';'
cursor.execute(sql)
print('Record updated successfully................')
wait = input('\n\n\nPress any key to continue............')
def add_new_vehicle():
clear()
print('Vehicle Login Screen ')
print('-' * 100)
vehicle_id = input('Enter Vehicle Number :')
parking_id = input('Enter parking ID :')
entry_date = date.today()
sql = 'insert into transaction(vehicle_id,parking_id,entry_date) values \
("{}","{}","{}");'.format(vehicle_id, parking_id, entry_date)
cursor.execute(sql)
cursor.execute('update parking_space set status ="full" where id ={}'.format(parking_id))
print('\n\n\n Record added successfully.................')
wait = input('\n\n\nPress any key to continue.....')
def remove_vehicle():
clear()
print('Vehicle Logout Screen')
print('-' * 100)
vehicle_id = input('Enter vehicle No :')
exit_date = date.today()
sql = 'select parking_id,price,entry_date from transaction tr,parking_space ps, parking_type pt \
where tr.parking_id = ps.id and ps.type_id = pt.id and \
vehicle_id ="' + vehicle_id + '" and exit_date is NULL;'
cursor.execute(sql)
record = cursor.fetchone()
days = (exit_date - record[2]).days
if days == 0:
days = days + 1
amount = record[1] * days
clear()
print('Logout Details ')
print('-' * 100)
print('Parking ID : {}'.format(record[0]))
print('Vehicle ID : {}'.format(vehicle_id))
print('Parking Date : {}'.format(record[2]))
print('Current Date : {}'.format(exit_date))
print('Amount Payable : {}'.format(amount))
wait = input('press any key to continue......')
# update transaction and parking space tables
sql1 = 'update transaction set exit_date ="{}" , amount ={} where vehicle_id ="{}" \
and exit_date is NULL;'.format(exit_date, amount, vehicle_id)
sql2 = 'update parking_space set status ="open" where id = {}'.format(record[0])
cursor.execute(sql1)
cursor.execute(sql2)
wait = input('Vehicle Out from our System Successfully.......\n Press any key to continue....')
def search_menu():
clear()
print(' S E A R C H P A R K I N G M E N U ')
print('1. Parking ID \n')
print('2. Vehicle Parked \n')
print('3. Free Space \n')
choices = [1, 2, 3]
choice = 0
while choice not in choices:
choice = int(input("enter choice between 1/2/3:"))
field = ''
if choice == 1:
field = 'id'
if choice == 2:
field = 'vehicle No'
if choice == 3:
field = 'status'
value = input('Enter value to search :')
if choice == 1 or choice == 3:
sql = 'select ps.id,name,price, status \
from parking_space ps , parking_type pt where ps.id = pt.id AND ps.id ={}'.format(value)
else:
sql = 'select id,vehicle_id,parking_id,entry_date from transaction where exit_date is NULL;'
cursor.execute(sql)
results = cursor.fetchall()
records = cursor.rowcount
for row in results:
print(row)
if records < 1:
print('Record not found \n\n\n ')
wait = input('\n\n\nPress any key to continue......')
def parking_status(status):
clear()
print('Parking Status :', status)
print('-' * 100)
sql = "select * from parking_space where status ='{}'".format(status)
cursor.execute(sql)
records = cursor.fetchall()
for row in records:
print(row)
wait = input('\n\n\nPress any key to continue.....')
def vehicle_status_report():
clear()
print('Vehicle Status - Currently Parked')
print('-' * 100)
sql = 'select * from transaction where exit_date is NULL;'
cursor.execute(sql)
records = cursor.fetchall()
for row in records:
print(row)
wait = input('\n\n\nPress any key to continue.....')
def money_collected():
clear()
start_date = input('Enter start Date(yyyy-mm-dd): ')
end_date = input('Enter End Date(yyyy-mm-dd): ')
sql = "select sum(amount) from transaction where \
entry_date ='{}' and exit_date ='{}'".format(start_date, end_date)
cursor.execute(sql)
result = cursor.fetchone()
clear()
print('Total money Collected from {} to {} = {}'.format(start_date, end_date,result[0]))
wait = input('\n\n\nPress any key to continue.....')
def report_menu():
while True:
clear()
print(' P A R K I N G R E P O R T S ')
print('-' * 100)
print('1. Parking Types \n')
print('2. Free Space \n')
print('3. Ocupied Space \n')
print('4. Vehicle Status \n')
print('5. Money Collected \n')
print('6. Exit \n')
choices = [1, 2, 3,4,5,6]
choice = 0
while choice not in choices:
choice = int(input("enter choice between 1/2/3/4/5/6:"))
field = ''
if choice == 1:
display_parking_type_records()
if choice == 2:
parking_status("open")
if choice == 3:
parking_status("full")
if choice == 4:
vehicle_status_report()
if choice == 5:
money_collected()
if choice == 6:
break
def main_menu():
login()
while True:
clear()
print(' P A R K I N G M A N A G E M E N T S Y S T E M')
print('*' * 100)
print("\n1. Add New Parking Type")
print("\n2. Add New Parking Slot")
print('\n3. Modify Parking Type Record')
print('\n4. Modify Parking Slot Record')
print('\n5. Vehicle Login ')
print('\n6. Vehicle Logout')
print('\n7. Search menu')
print('\n8. Report menu')
print('\n9. Close application')
print('\n\n')
choice = int(input('Enter your choice ...: '))
if choice == 1:
add_parking_type_record()
if choice == 2:
add_parking_slot_record()
if choice == 3:
modify_parking_type_record()
if choice == 4:
modify_parking_space_record()
if choice == 5:
add_new_vehicle()
if choice == 6:
remove_vehicle()
if choice == 7:
search_menu()
if choice == 8:
report_menu()
if choice == 9:
break
if __name__ == "__main__":
main_menu()