-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
289 lines (244 loc) · 9 KB
/
main.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
from tkinter import messagebox
from tkinter import ttk
from tkinter import *
import mysql.connector
con=mysql.connector.connect(host="localhost",user="root",password="Mynameissql",database="cars")
check=0
def enter():
def addcar():
e1=ent1.get()
e2=ent2.get()
e3=ent3.get()
cur=con.cursor()
x='y'
cur.execute("insert into cars(car_id,brand,rent,available) values(%s,%s,%s,%s)",(e1,e2,e3,x))
con.commit()
carid.delete(0,END)
brand.delete(0,END)
price.delete(0,END)
messagebox.showinfo('success',"car inserted!")
#function for deleting a car
def delcar():
e1=ent1.get()
e2=ent2.get()
e3=ent3.get()
cur=con.cursor()
x='y'
cur.execute("delete from cars where car_id=%s and available=%s",(e1,x))
con.commit()
carid.delete(0,END)
brand.delete(0,END)
price.delete(0,END)
messagebox.showinfo('success','car deleted!!')
#creating the main window
root=Toplevel()
root.geometry("500x500")
root.title("Car Rental System")
#creating a notebook for tabs(admin,book,return)
notebook=ttk.Notebook(root)
notebook.pack()
#creating 3 frames
frame1=Frame(notebook,width=500,height=500)
frame2=Frame(notebook,width=500,height=500)
frame3=Frame(notebook,width=500,height=500)
frame1.pack(fill="both",expand=1)
frame2.pack(fill="both",expand=1)
frame3.pack(fill="both",expand=1)
notebook.add(frame1,text="admin")
notebook.add(frame2,text="book")
notebook.add(frame3,text="return")
ent1=IntVar()
ent2=StringVar()
ent3=IntVar()
#adding and droping car window
lab=Label(frame1,text="WELCOME TO CAR RENTAL SYSTEM").pack()
lab1=Label(frame1,text="CARID").place(x=150,y=50)
carid=Entry(frame1,textvariable=ent1)
carid.place(x=200,y=50)
lab2=Label(frame1,text="BRAND").place(x=150,y=80)
brand=Entry(frame1,textvariable=ent2)
brand.place(x=200,y=80)
lab3=Label(frame1,text="RENT").place(x=150,y=110)
price=Entry(frame1,textvariable=ent3)
price.place(x=200,y=110)
but1=Button(frame1,text="ADD CAR",command=addcar).place(x=200,y=200)
but2=Button(frame1,text="DROP CAR",command=delcar).place(x=300,y=200)
#displaying available cars
labf=Label(frame2,text="AVAILABLE CARS").pack()
treescroll=Frame(frame2)
treescroll.pack()
scroll=Scrollbar(frame2)
scroll.pack(side=RIGHT,fill=Y)
tree=ttk.Treeview(frame2,yscrollcommand=scroll.set) #yscrollcommand=scroll.set)
scroll.config(command=tree.yview)
tree['show']='headings'
s=ttk.Style(root)
s.theme_use("clam")
tree.pack()
tree['columns']=("car_id","brand","rent")
cur=con.cursor()
y='y'
cur.execute("select car_id,brand,rent from cars where available='y'")
tree.column("car_id",width=50,minwidth=50,anchor=CENTER)
tree.column("brand",width=100,minwidth=100,anchor=CENTER)
tree.column("rent",width=150,minwidth=150,anchor=CENTER)
#headings
tree.heading("car_id",text="carid",anchor=CENTER)
tree.heading("brand",text="brand",anchor=CENTER)
tree.heading("rent",text="rent",anchor=CENTER)
i=0
for row in cur:
tree.insert('',i,text='',values=(row[0],row[1],row[2]))
i+=1
con.commit()
ent4=IntVar()
ent5=StringVar()
ent6=StringVar()
ent7=StringVar()
ent8=StringVar()
#function to book a car
def bookcar():
a=ent4.get()
b=ent5.get()
c=ent6.get()
d=ent7.get()
e=ent8.get()
cur=con.cursor()
cur.execute("insert into users(name,email,startdate,loc) values(%s,%s,%s,%s)",(b,c,d,e))
con.commit()
cur=con.cursor()
cur.execute("select user_id from users where name=%s and email=%s",(b,c))
ac=0
for r in cur:
ac=r[0]
con.commit()
cur=con.cursor()
n='n'
cur.execute("insert into manages(user_id,car_id) values(%s,%s)",(ac,a))
x='n'
cur.execute("update cars set available=%s where car_id=%s",(x,a))
con.commit()
cur.execute("delete from manages where car_id not in (select car_id from cars)")
con.commit()
cur.execute("delete from users where user_id not in (select user_id from manages)")
con.commit()
messagebox.showinfo("success","car booked")
carbook.delete(0,END)
carname.delete(0,END)
carmail.delete(0,END)
cardate.delete(0,END)
carloc.delete(0,END)
def returncar():
root1=Toplevel()
root1.geometry("600x600")
root1.title("RETURN CAR")
lab=Label(root1,text="CARS TO BE RETURNED").pack()
tree1=ttk.Treeview(root1)
tree1["show"]="headings"
s=ttk.Style(root1)
s.theme_use("clam")
tree1["columns"]=("carid","userid","name","email")
tree1.column("carid",width=70,minwidth=70,anchor=CENTER)
tree1.column("userid",width=70,minwidth=70,anchor=CENTER)
tree1.column("name",width=150,minwidth=150,anchor=CENTER)
tree1.column("email",width=150,minwidth=150,anchor=CENTER)
tree1.heading("carid",text="carid",anchor=CENTER)
tree1.heading("userid",text="userid",anchor=CENTER)
tree1.heading("name",text="name",anchor=CENTER)
tree1.heading("email",text="email",anchor=CENTER)
cur=con.cursor()
cur.execute("select car_id,user_id,name,email from manages natural join users natural join cars where available='n'")
i=0
for row in cur:
tree1.insert('',i,text='',values=(row[0],row[1],row[2],row[3]))
i+=1
con.commit()
def rccar():
s1=bt1.get()
s2=bt2.get()
s3=bt3.get()
cur=con.cursor()
y='y'
cur.execute("update cars set available=%s where car_id=%s",(y,s1))
con.commit()
cur.execute("delete from manages where car_id=%s and user_id=%s",(s1,s2))
con.commit()
messagebox.showinfo("car returned","thank u come again!")
b1.delete(0,END)
b2.delete(0,END)
b3.delete(0,END)
bt1=IntVar()
bt2=IntVar()
bt3=StringVar()
l1=Label(root1,text="CARID").place(x=210,y=270)
b1=Entry(root1,textvariable=bt1)
b1.place(x=260,y=270)
l2=Label(root1,text="USERID").place(x=210,y=300)
b2=Entry(root1,textvariable=bt2)
b2.place(x=260,y=300)
l3=Label(root1,text="NAME").place(x=210,y=330)
b3=Entry(root1,textvariable=bt3)
b3.place(x=260,y=330)
b4=Button(root1,text="RETURN CAR",command=rccar).place(x=250,y=370)
vsb=ttk.Scrollbar(root1,orient="vertical")
vsb.configure(command=tree1.yview)
tree1.configure(yscrollcommand=vsb.set)
vsb.pack(fill=Y,side=RIGHT)
tree1.pack()
root1.mainloop()
lab4=Label(frame2,text="CARID").place(x=150,y=270)
carbook=Entry(frame2,textvariable=ent4)
carbook.place(x=200,y=270)
lab5=Label(frame2,text="NAME").place(x=150,y=300)
carname=Entry(frame2,textvariable=ent5)
carname.place(x=200,y=300)
lab6=Label(frame2,text="EMAIL").place(x=150,y=330)
carmail=Entry(frame2,textvariable=ent6)
carmail.place(x=200,y=330)
lab7=Label(frame2,text="DATE").place(x=150,y=360)
cardate=Entry(frame2,textvariable=ent7)
cardate.place(x=200,y=360)
lab8=Label(frame2,text="LOCATION").place(x=150,y=390)
carloc=Entry(frame2,textvariable=ent8)
carloc.place(x=220,y=390)
but3=Button(frame2,text="BOOK CAR",command=bookcar).place(x=200,y=420)
b10=Button(frame2,text="REFRESH",command=enter).place(x=290,y=420)
la=Label(frame3,text="RETURN CAR PORTAL").place(x=190,y=10)
but4=Button(frame3,text="GO TO RETURN CAR",command=returncar).place(x=200,y=100)
#tree.pack()
frame2.mainloop()
root.mainloop()
def submit():
c=0
username=a.get()
password=b.get()
cur.execute("select *from admin")
for i in cur:
if i[0]==username and i[1]==password:
global check
c=1
check=1
if c==1:
messagebox.showinfo("valid!","welcome!")
enter()
else:
messagebox.showwarning("not valid!!","try again!")
r=Tk()
r.title("LOGIN CAR RENTAL SYSTEM")
r.geometry("500x500")
s=ttk.Style(r)
s.theme_use("clam")
cur=con.cursor()
a=StringVar()
b=StringVar()
t=Label(r,text="CAR RENTAL ADMIN LOGIN").pack()
user=Label(r,text="USERNAME").place(x=150,y=150)
g=Entry(r,textvariable=a)
g.place(x=220,y=150)
passw=Label(r,text="PASSWORD").place(x=150,y=180)
h=Entry(r,textvariable=b)
h.place(x=220,y=180)
bo=Button(r,text="SUBMIT",command=submit)
bo.place(x=250,y=220)
con.commit()
r.mainloop()