-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProject.py
More file actions
323 lines (283 loc) · 14.8 KB
/
Project.py
File metadata and controls
323 lines (283 loc) · 14.8 KB
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
#importing tkinter and pyodbc
import tkinter as tk
from tkinter import *
from tkinter import ttk
from tkinter import messagebox
from tkinter.messagebox import showinfo
from tk import *
import pyodbc
#Connecting Database
connection = pyodbc.connect('Driver={SQL Server};' 'Server=DESKTOP-4LORV5Q\SQLEXPRESS;'
'Database=FRS;' 'Trusted_connection=yes;')
cursor = connection.cursor()
#Main Menu
root = Tk()
root.wm_title("FLIGHT RESERVATION SYSTEM")
root['background']='#21618C'
Label(root,text="Flight Reservation System", font=('{Product Sans} 30 bold underline'), fg='#ffffff', bg= '#21618C').grid()
#main menu text
Label(root,text="\nWelcome to our Airline Reservation!\nWe are glad to have you here and are\nexcited to help you plan your next trip.\n",
font=('{Product Sans} 20 italic '), fg='#ffffff', bg= '#21618C').grid(row=3,column=0, padx=10, pady=10,sticky=E)
root.geometry('490x550')
#Search Function
def fun1():
root.destroy()
root1=Tk()
root1.title("FLIGHT SEARCHING")
root1.geometry('480x300')
root1['background']='#21618C'
Label(root1,text="Search your Flight", font=('{Product Sans} 30 bold underline'),fg='#ffffff', bg= '#21618C').grid(sticky=W)
Label(root1,text="\nPlease enter the following details to search your flight.\n", font=('{Product Sans} 15 italic '), fg='#ffffff', bg= '#21618C').grid(sticky=W)
## Creating a Boarding Dropdown
Label(root1,text="Boarding: ", font=('{Product Sans} 15 bold '), fg='#ffffff', bg= '#21618C').grid(row=2,column=0,sticky=W)
def place_dropdown():
cur = connection.cursor()
cur.execute("select PlaceName from Places")
data = []
for Place in cur.fetchall():
data.append(Place[0])
return data
q1 = StringVar()
w1=ttk.Combobox(root1, height=10,width=20,textvariable=q1, state = 'readonly')
w1['values'] = place_dropdown()
w1.grid(row=2,column=0)
##Creating a Destination
Label(root1,text="Destination: ", font=('{Product Sans} 15 bold '), fg='#ffffff', bg= '#21618C').grid(row=3,column=0,sticky=W)
q2 = StringVar()
w2=ttk.Combobox(root1, height=10,width=20,textvariable=q2, state = 'readonly')
w2['values'] = place_dropdown()
w2.grid(row=3,column=0)
## Creating a Day of Travel
Label(root1,text="Day of travel: ", font=('{Product Sans} 15 bold '), fg='#ffffff', bg= '#21618C').grid(row=4,column=0,sticky=W)
w3=ttk.Combobox(root1,height=10,width=20,values=["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"])
w3.grid(row=4,column=0)
#Search Button Functions
def search_function():
a=w1.get()
b=w2.get()
c=w3.get()
cur=connection.cursor()
if a=='' or b=='' or c=='':
messagebox.showerror("Error","Cant leave any field empty")
else:
if a!=b:
cur.execute("select FlightName , Dep_time , Arr_time , Source , Destination from Flight where source=? and destination=?",(a,b))
z = cur.fetchall()
#creating a searched flight window
root1.destroy()
root2=Tk()
root2.title("SEARCHED FLIGHT")
root2.geometry('480x300')
root2['background']='#21618C'
Label(root2,text="Available Flights", font=('{Product Sans} 30 bold underline'),fg='#ffffff', bg= '#21618C').grid(sticky=W)
Label(root2,text="\nThese are the available flights", font=('{Product Sans} 15 italic '), fg='#ffffff', bg= '#21618C').grid(sticky=W)
T = tk.Text(root2, height=5, width=55)
T.grid(row=2,column=0)
T.insert(tk.END, z)
#book flight button
B2=Button(root2,text="Book Flight", font=('Poppins 10 bold'),height=0,width=12,fg='#21618C', borderwidth=3, relief="flat",
bg='#ffffff', activebackground='#21618C',activeforeground='#ffffff',command=fun2).grid(row=4,column=0, padx=10, pady=10,sticky=N)
root2.mainloop()
else:
messagebox.showerror("Oops","Boarding and Destination can't be same")
#search button
Bs=Button(root1,text="Search", font=('Poppins 10 bold'), height=0,width=10,fg='#21618C', borderwidth=3, relief="flat",
bg='#ffffff', activebackground='#21618C',activeforeground='#ffffff', command=search_function).grid(row=5,column=0,padx=5, pady=5,sticky=N)
root1.mainloop()
#Booking Button Function
def fun2():
root3=Tk()
root3.title('FLIGHT BOOKING')
root3.geometry('490x600')
root3['background']='#21618C'
Label(root3,text="Book your Flight", font=('{Product Sans} 30 bold underline'),fg='#ffffff', bg= '#21618C').grid(sticky=W)
Label(root3,text="\nPlease enter the following details to book your flight.\n", font=('{Product Sans} 15 italic '), fg='#ffffff', bg= '#21618C').grid(sticky=W)
#creating boarding field
Label(root3,text="Boarding",font=('{Product Sans} 15 bold '), fg='#ffffff', bg= '#21618C').grid(row=2,column=0,sticky=W)
def place_dropdown():
cur = connection.cursor()
cur.execute("select PlaceName from Places")
data = []
for Place in cur.fetchall():
data.append(Place[0])
return data
q1 = StringVar()
w1=ttk.Combobox(root3, height=10,width=20,textvariable=q1, state = 'readonly')
w1['values'] = place_dropdown()
w1.grid(row=2,column=0)
#creating destination field
Label(root3,text="Destination:",font=('{Product Sans} 15 bold '), fg='#ffffff', bg= '#21618C').grid(row=3,column=0,sticky=W)
q2 = StringVar()
w2=ttk.Combobox(root3, height=10,width=20,textvariable=q2, state = 'readonly')
w2['values'] = place_dropdown()
w2.grid(row=3,column=0)
#creating class field
#function for class dropdown menu
def class_dropdown():
cur = connection.cursor()
cur.execute("select Class_type from Class")
data1 = []
for classes in cur.fetchall():
data1.append(classes[0])
return data1
Label(root3,text="Class:",font=('{Product Sans} 15 bold '), fg='#ffffff', bg= '#21618C').grid(row=4,column=0,sticky=W)
q3 = StringVar()
w3=ttk.Combobox(root3, height=10,width=20,textvariable=q3, state = 'readonly')
w3['values'] = class_dropdown()
w3.grid(row=4,column=0)
#creating FirstName field
Label(root3,text="First Name: ",font=('{Product Sans} 15 bold '), fg='#ffffff', bg= '#21618C').grid(row=5,column=0,sticky=W)
firstname = Entry(root3, width=23)
firstname.grid(row=5, column=0)
#creating LastName field
Label(root3,text="Last Name: ",font=('{Product Sans} 15 bold '), fg='#ffffff', bg= '#21618C').grid(row=6,column=0,sticky=W)
lastname = Entry(root3, width=23)
lastname.grid(row=6, column=0)
#creating Email field
Label(root3,text="Email: ",font=('{Product Sans} 15 bold '), fg='#ffffff', bg= '#21618C').grid(row=7,column=0,sticky=W)
email = Entry(root3, width=23)
email.grid(row=7, column=0)
#creating MobileNo field
Label(root3,text="Mobile No: ",font=('{Product Sans} 15 bold '), fg='#ffffff', bg= '#21618C').grid(row=8,column=0,sticky=W)
mobile = Entry(root3, width=23)
mobile.grid(row=8, column=0)
#creating PassportNo field
Label(root3,text="Passport No: ",font=('{Product Sans} 15 bold '), fg='#ffffff', bg= '#21618C').grid(row=9,column=0,sticky=W)
passport = Entry(root3, width=23)
passport.grid(row=9, column=0)
#creating DOB field
Label(root3,text="Date of Birth: ",font=('{Product Sans} 15 bold '), fg='#ffffff', bg= '#21618C').grid(row=10,column=0,sticky=W)
dob = Entry(root3, width=23)
dob.grid(row=10, column=0)
Label(root3,text="(YYYY-MM-DD)", font=('{Product Sans} 10 '), fg='#ffffff', bg= '#21618C').grid(row=10,column=0,sticky=E)
#creating Address field
Label(root3,text="Address ",font=('{Product Sans} 15 bold '), fg='#ffffff', bg= '#21618C').grid(row=11,column=0,sticky=W)
address = Entry(root3, width=23)
address.grid(row=11, column=0)
#creating Gender field
Label(root3,text="Gender: ", font=('{Product Sans} 15 bold '), fg='#ffffff', bg= '#21618C').grid(row=12,column=0,sticky=W)
g1=ttk.Combobox(root3,height=10,width=20,values=["Male","Female"])
g1.grid(row=12,column=0)
#creating Day field
Label(root3,text="Day of travel: ", font=('{Product Sans} 15 bold '), fg='#ffffff', bg= '#21618C').grid(row=13,column=0,sticky=W)
w4=ttk.Combobox(root3,height=10,width=20,values=["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"])
w4.grid(row=13,column=0)
#fuction to book flight
def book():
a = w1.get()
b = w2.get()
c = w3.get()
d = firstname.get()
e = lastname.get()
f = email.get()
g = mobile.get()
h = passport.get()
i = dob.get()
j = address.get()
k = g1.get()
l = w4.get()
cur=connection.cursor()
if a=='' or b=='' or c=='' or d=='' or e=='' or f=='' or g=='' or h=='' or i=='' or j=='' or k=='' or l=='':
messagebox.showerror("Error","Cant leave any field empty")
else:
if a!=b:
cur.execute("insert into Passenger (F_Name,L_Name,Email,DOB,Gender,[Address],Source, Destination, Class,[Day],PassportNo,MobileNo) values(?,?,?,?,?,?,?,?,?,?,?,?)",(d,e,f,i,k,j,a,b,c,l,h,g))
connection.commit()
root3.destroy()
root6=Tk()
root6.title('TICKET')
root6.geometry('480x300')
root6['background']='#21618C'
Label(root6,text="YOUR TICKET", font=('{Product Sans} 30 bold underline'),fg='#ffffff', bg= '#21618C').grid(sticky=W)
cur.execute("insert into Ticket (Source,Destination,PassportNo,F_Name,L_Name,[Day],Class,MobileNo) values(?,?,?,?,?,?,?,?)",(a,b,h,d,e,l,c,g))
connection.commit()
cur.execute("select F_Name,L_Name,Source, Destination, Class,[Day],PassportNo from Passenger where PassportNo=?",h)
z1 = cur.fetchall()
T1 = tk.Text(root6, height=5, width=55)
T1.grid(row=2,column=0)
T1.insert(tk.END, z1)
Label(root6,text="TICKET ID", font=('{Product Sans} 15 bold '), fg='#ffffff', bg= '#21618C').grid(row=3,column=0,sticky=W)
cur.execute("select Ticket_id from Ticket where PassportNo=?",h)
z2 = cur.fetchall()
T2 = tk.Text(root6, height=5, width=55)
T2.grid(row=4,column=0)
T2.insert(tk.END, z2)
root6.mainloop()
else:
messagebox.showerror("Oops","Boarding and Destination can't be same")
#Inserting/book flight button
B4=Button(root3,text="Book Flight", font=('Poppins 10 bold'),height=0,width=12,fg='#21618C', borderwidth=3, relief="flat",
bg='#ffffff', activebackground='#21618C',activeforeground='#ffffff',command=book).grid(row=14,column=0, padx=10, pady=10,sticky=N)
#Cancel Button Fuction
def fun3():
root.destroy()
root4=Tk()
root4.title("FLIGHT CANCELLATION")
root4.geometry('480x350')
root4['background']='#21618C'
Label(root4,text="Cancel your Flight", font=('{Product Sans} 30 bold underline'),fg='#ffffff', bg= '#21618C').grid(sticky=W)
Label(root4,text="\nPlease enter the following details to cancel your flight.\n", font=('{Product Sans} 15 italic '), fg='#ffffff', bg= '#21618C').grid(sticky=W)\
#creating PassportNo field
Label(root4,text="Passport No: ",font=('{Product Sans} 15 bold '), fg='#ffffff', bg= '#21618C').grid(row=2,column=0,sticky=W)
passport = Entry(root4, width=23)
passport.grid(row=2, column=0)
#creating TicketNo field
Label(root4,text="Ticket No: ",font=('{Product Sans} 15 bold '), fg='#ffffff', bg= '#21618C').grid(row=3,column=0,sticky=W)
ticket = Entry(root4, width=23)
ticket.grid(row=3, column=0)
#creating boarding field
Label(root4,text="Boarding",font=('{Product Sans} 15 bold '), fg='#ffffff', bg= '#21618C').grid(row=4,column=0,sticky=W)
def place_dropdown():
cur = connection.cursor()
cur.execute("select PlaceName from Places")
data = []
for Place in cur.fetchall():
data.append(Place[0])
return data
q1 = StringVar()
w1=ttk.Combobox(root4, height=10,width=20,textvariable=q1, state = 'readonly')
w1['values'] = place_dropdown()
w1.grid(row=4,column=0)
#creating Class field
def class_dropdown():
cur = connection.cursor()
cur.execute("select Class_type from Class")
data1 = []
for classes in cur.fetchall():
data1.append(classes[0])
return data1
Label(root4,text="Class:",font=('{Product Sans} 15 bold '), fg='#ffffff', bg= '#21618C').grid(row=5,column=0,sticky=W)
q3 = StringVar()
w3=ttk.Combobox(root4, height=10,width=20,textvariable=q3, state = 'readonly')
w3['values'] = class_dropdown()
w3.grid(row=5,column=0)
#cancel button operation
def cancel():
a = passport.get()
b = ticket.get()
c = w1.get()
d = w3.get()
cur=connection.cursor()
if a=='' or b=='' or c=='' or d=='':
messagebox.showerror("Oops","You can't Enter the leave any field empty")
else:
if a!=b:
cur.execute('Delete From Ticket where PassportNo = ? and Ticket_id = ?',(a,b))
cur.execute('Delete From Passenger where PassportNo = ?',a)
connection.commit()
messagebox.showinfo("RESERVATION CANCEL","Your Reservation is Cancelled!")
else:
messagebox.showerror("Oops","PassportNo and TicketNo Can't be same Enter Again!")
#Cancel Reservation button
B4=Button(root4,text="Cancel Reservation", font=('Poppins 10 bold'),height=0,width=17,fg='#21618C', borderwidth=3, relief="flat",
bg='#ffffff', activebackground='#21618C',activeforeground='#ffffff',command=cancel).grid(row=6,column=0, padx=10, pady=10,sticky=N)
#Button Of Search Flight in Main Menu
B1=Button(root,text="Search Flight", font=('Poppins 15 bold'),height=0,width=15,fg='#21618C', borderwidth=3, relief="flat",
bg='#ffffff', activebackground='#21618C',activeforeground='#ffffff', command=fun1).grid(row=4,column=0, padx=10, pady=10,sticky=N)
#Button Of Book Flight in Main Menu
B2=Button(root,text="Book Flight", font=('Poppins 15 bold'),height=0,width=15,fg='#21618C', borderwidth=3, relief="flat",
bg='#ffffff', activebackground='#21618C',activeforeground='#ffffff', command=fun2).grid(row=5,column=0, padx=10, pady=10,sticky=N)
#Button Of Cancel Booking in Main Menu
B3=Button(root,text="Cancel Booking", font=('Poppins 15 bold'),height=0,width=15,fg='#21618C', borderwidth=3,relief="flat",
bg='#ffffff', activebackground='#21618C',activeforeground='#ffffff', command=fun3).grid(row=6,column=0, padx=10, pady=10,sticky=N)
root.mainloop()