-
Notifications
You must be signed in to change notification settings - Fork 0
/
seat_bookings.py
179 lines (139 loc) · 6.35 KB
/
seat_bookings.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
from datetime import date
from tkinter import *
from tkinter import messagebox
import random
import sqlite3
root = Tk()
h,w,= root.winfo_screenheight(),root.winfo_screenwidth()
root.geometry('%dx%d+0+0'%(w,h))
root.state('zoomed')
bus_logo = PhotoImage(file=".\\images\\Bus_for_project.png")
Label(root, image=bus_logo).grid(row=0, column=6, columnspan=10)
Label(root, text="Online Bus Booking System", bg="Light Blue",
fg="Red", font="Arial 20").grid(row=1, column=6, columnspan=15)
Label(root, text="Enter Journey Details", bg="Light Green",
font="Arial 10").grid(row=2, column=6, pady=15, columnspan=15)
Label(root, text='To').grid(row=3, column=3)
to = Entry(root)
to.grid(row=3, column=4, pady=20)
Label(root, text='From').grid(row=3, column=5)
fro = Entry(root)
fro.grid(row=3, column=6, pady=20)
Label(root, text='Journey Date').grid(row=3, column=7)
journey_date = Entry(root)
journey_date.grid(row=3, column=8)
def show():
Button(root, text="Proceed to Book",
command=proceed).grid(row=5, column=10)
def show_bus():
if to.get() == "" and fro.get() == "" and journey_date.get() == "":
messagebox.showerror("Error", "<Please fill all the journey details>")
elif to.get() == "" and fro.get() == "":
messagebox.showerror("Error", "<Please fill the field <To and From>")
elif fro.get() == "" and journey_date.get() == "":
messagebox.showerror(
"Error", "Please fill the field <From and Journey Date>")
elif journey_date.get() == "" and to.get() == "":
messagebox.showerror(
"Error", "Please fill the field <To and Journey Date>")
elif to.get() == "":
messagebox.showerror("Error", "Please fill the fieldd <To>")
elif fro.get() == "":
messagebox.showerror("Error", "Please fill the field <From>")
elif journey_date.get() == "":
messagebox.showerror("Error ", "Please enter the field <Journey Date>")
else:
Label(root, text="Select Bus").grid(row=4, column=4)
Label(root, text="Operator").grid(row=4, column=5)
Label(root, text="Bus Type").grid(row=4, column=6)
Label(root, text="Available").grid(row=4, column=7)
Label(root, text="Capacity").grid(row=4, column=8)
Label(root, text="Fare").grid(row=4, column=9)
con = sqlite3.Connection("Bus_database")
cur = con.cursor()
cur.execute("select o.Name,b.Bus_type,d.Seat_available,b.Capacity,b.Fare ,b.B_Id from Operator_details as o,Bus_details as b,Running_details as d ,Route_details as r ,Route_details as e where o.Op_Id=b.Op_Id and r.S_Id>e.S_Id and b.B_Id=d.B_Id and r.R_Id=b.R_Id and e.R_Id=b.R_Id and r.Sname=? and e.Sname=? and d.Date=?", (fro.get(), to.get(), journey_date.get(),))
name = cur.fetchall()
global b_id
b_id = IntVar()
n = 5
for i in name:
Radiobutton(root, text="Book Now", variable=b_id,
value=i[5]).grid(row=n, column=4)
Label(root, text=i[0]).grid(row=n, column=5)
Label(root, text=i[1]).grid(row=n, column=6)
Label(root, text=i[2]).grid(row=n, column=7)
Label(root, text=i[3]).grid(row=n, column=8)
Label(root, text=i[4]).grid(row=n, column=9)
n = n+1
show()
Button(root, text="Show Bus", command=show_bus).grid(row=3, column=9, pady=20)
def proceed():
Label(root, text='Fill Passenger Details to book bus ticket', font='Arial 18 bold ',
fg='red', bg='light blue').grid(row=20, column=6, pady=20, columnspan=15)
Label(root, text="Name").grid(row=22, column=3)
name = Entry(root)
name.grid(row=22, column=4)
Label(root, text="Gender").grid(row=22, column=5)
gender_type = StringVar()
gender_option = ["Male", "Female"]
gender_menu = OptionMenu(
root, gender_type, *gender_option).grid(row=22, column=6)
Label(root, text="No of Seats").grid(row=22, column=7)
no_of_seats = Entry(root)
no_of_seats.grid(row=22, column=8)
Label(root, text="Mobile No").grid(row=22, column=9)
mobile_number = Entry(root)
mobile_number.grid(row=22, column=10)
print(mobile_number)
Label(root, text="Age").grid(row=22, column=11)
age = Entry(root)
age.grid(row=22, column=12)
Button(root, text="Book Seat", command=bus_ticket).grid(
row=22, column=13, padx=5)
con = sqlite3.Connection("Bus_database")
cur = con.cursor()
m = mobile_number.get()
n = name.get()
ns = no_of_seats.get()
g = gender_type.get()
a = age.get()
b = b_id.get()
d = date.today()
j = journey_date.get()
o = random.randint(1, 100)
f = fro.get()
# print(m)
# print(n)
# print(ns)
# print(g)
# print(a)
# print(b)
# print(d)
# print(j)
# print(f)
# print(o)
if mobile_number.get() != "" and name.get() != "" and no_of_seats.get() != "" and gender_type.get() != "" and age.get() != "":
# cur.execute("insert into Booking_history values('"+mobile_number.get() + "','"+name.get()+"','"+no_of_seats .get()+"','"+gender_type.get() +
# "','"+age.get()+"','"+b_id.get()+"','"+date.today()+"','"+journey_date.get()+"','"+random.randint(1, 100)+"','"+fro.get()+"')")
cur.execute('''insert into Booking_history(Phone,Passenger_name ,No_of_passenger,Gender,Age,B_Id,Date,Journey_date,Booking_ref,Boarding_station)values(?,?,?,?,?,?,?,?,?,?)''', (m, n, ns, g, a, b, d, j, o, f))
con.commit()
cur.execute("update Running_details set r.Seat_available=r.Seat_available-No_of_passenger from Running_details as r ,Booking_history as b where b.B_Id=r.B_Id and b.Journey_date=r.Date")
con.commit()
con.close()
else:
messagebox.showerror("","Please fill all the details")
def bus_ticket():
check = messagebox.askyesno(
"Booking Confirmation", "Click Yes to book ticket")
if check:
root.destroy()
import bus_ticket
else:
messagebox.showerror("", "Booking Failed")
def home():
root.destroy()
import booking_details
home_logo = PhotoImage(file=".\\images\\home.png")
Button(root, fg='black', bg='light green', image=home_logo,
command=home).grid(row=3, column=10)
root.mainloop()