-
Notifications
You must be signed in to change notification settings - Fork 0
/
s.py
185 lines (146 loc) · 7.19 KB
/
s.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
from datetime import date
from tkinter import *
from tkinter import messagebox
import random
import sqlite3
root = Tk()
root.state('zoomed')
bus_logo = PhotoImage(file=".\\images\\Bus_for_project.png")
Label(root, image=bus_logo).grid(row=0, column=5, columnspan=15)
Label(root, text="Online Bus Booking System", bg="Light Blue",
fg="Red", font="Arial 20").grid(row=1, column=5, columnspan=15)
Label(root, text="Enter Journey Details", bg="Light Green",
font="Arial 10").grid(row=2, column=5, 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_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 Name,Bus_type,Seat_available,Capacity,Fare from Bus_details as b,Operator_details as o,Running_details,
# Route_details as f, Route_details as t where f.Sname=? and t.Sname=?
# and f.S_Id<t.S_Id and f.R_Id=b.Op_Id and o.Op_Id=b.Op_Id ''', (fro.get(), to.get()))
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()
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
def proceed():
# messagebox.askyesno("", "Do you want to 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)
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()
# time = 6
# bus_id = 1
# transaction_id = random.randint(100, 200)
# cur.execute("insert into Booking_history values('"+name.get()+"','"+gender_type.get() +
# "','"+no_of_seats .get()+"','"+mobile_number.get() + "','"+age.get()+"','"+b_id.get()+"')")
m = int(mobile_number.get())
n = name.get()
ns = int(no_of_seats.get())
g = gender_type.get()
a = age.get()
b = b_id.get()
d = date.today()
j = journey_date.get()
f = fro.get()
o = random.randint(1, 100)
print(type(m))
print(type(n))
print(type(ns))
print(type(g))
print(type(a))
print(type(b))
print(type(d))
print(type(j))
print(type(f))
print(type(o))
# cur.execute('''insert into Booking_history(Phone,Passenger_name ,No_of_passenger,Gender,Age)values(?,?,?,?,?)''', (m, n, ns, g, a))
cur.execute('''insert into Booking_history(Phone,Passenger_name ,No_of_passenger,Gender,Age,B_Id,Date,Journey_date,Boarding_station,Booking_ref)values(?,?,?,?,?,?,?,?,?,?)''', (m, n, ns, g, a, b, d, j, f, o))
# print(bus_ticket.get())
# # # cur.execute("INSERT INTO Operator_details(Op_Id,Name,Address,Email,Phone)VALUES(1,)")))
# cur.execute('''insert into Booking_history(Phone,Passenger_name ,No_of_passenger,Gender,Age,B_Id)
# values(?,?,?,?,?,?);''',[mobile_number.get(), name, no_of_seats,gender_type, age))
con.commit()
cur.execute("update Running_details set Seat_available=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()
# ticket = cur.fetchall()
# print("Success")
# else:
# messagebox.showinfo("", "Please fill all the field")
Button(root, text="Proceed to Book",
command=proceed).grid(row=5, column=10)
Button(root, text="Show Bus", command=show_bus).grid(row=3, column=9, pady=20)
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()