-
Notifications
You must be signed in to change notification settings - Fork 1
/
Book2.jsp
315 lines (270 loc) · 8.5 KB
/
Book2.jsp
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
<%@page import="java.sql.DriverManager"%>
<%@page import="java.sql.ResultSet"%>
<%@page import="java.sql.PreparedStatement"%>
<%@page import="java.sql.Connection"%>
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Booking</title>
<!-- To Import CSS And jquery for the Graphical Button Style -->
<link rel="stylesheet" href="button/button_css/jquery-ui-1.8.17.custom.css">
<link rel="stylesheet" href="button/button_css/jquery.ui.button.css">
<script src="button/button_js/jquery-1.7.1.js"></script>
<script src="button/button_js/jquery.ui.core.js"></script>
<script src="button/button_js/jquery.ui.widget.js"></script>
<script src="button/button_js/jquery.ui.button.js"></script>
<!-- To Import CSS And jquery for the Graphical Button Style -->
<!-- Script To Call Graphical Button Style -->
<script>
$(function() {
$("#format").buttonset(); //To Set Graphical Button Style To The Check Box
$("#format1").buttonset();
});
</script>
<!-- Script To Call Graphical Button Style -->
<%!
Connection con = null;
PreparedStatement pstmt = null;
ResultSet rs = null;
public void jspInit(){
try{
Class.forName("com.mysql.jdbc.Driver");
con = DriverManager.getConnection("jdbc:mysql://localhost:3306/train","root","");
}
catch(Exception e ){
e.printStackTrace();
}
}
%>
<script type="text/javascript">
function check(ele){
var ad = document.form1.adult.value;
var child = document.form1.child.value;
var no = document.form1.seat.length;
var chk=0;
var total = parseInt(ad) + parseInt(child);
for(var i=0; i<no; i++){
if (document.form1.seat[i].checked == true){
chk = chk +1;
}
}
if( chk > total){
ele.checked=false;
alert("Maximm "+total+" Seats Selected");
}
}
function scrolldown(){
window.scrollTo(0, screen.height + 400);
}
function scrollup(){
window.scrollTo(0, window.height);
}
</script>
</head>
<body>
<div>
<form name="form1" action="">
<%
int tno=0;
String dt = "";
String clas="";
String adult="";
String child="";
String class1="";
String ch = "";
String[] seats= new String[72];
int no_seats = 0;
String[] wait= new String[10];
int no_wait = 0;
int block = 0;
try{
tno = Integer.parseInt(request.getParameter("tno"));
dt = request.getParameter("date1");
clas = request.getParameter("clas");
adult = request.getParameter("adult");
child = request.getParameter("child");
ch = request.getParameter("ch");//Coach Name
%>
<input name="ch" type="hidden" value='<%= ch %>' />
<%
if (clas.equals("sl")){ //Differnt class have differnet no of seats per coach
no_seats = 72;
no_wait = 10;
block = 4;
}else if(clas.equals("a1")){
no_seats = 18;
no_wait = 5;
block = 2;
}else if(clas.equals("a2")){
no_seats = 45;
no_wait = 5;
block = 3;
}else if(clas.equals("a3")){
no_seats = 64;
no_wait = 10;
block = 4;
}
int avail_seats=0;
loop: for(int i=1; i <= no_seats; i++){
if(ch.equals(null)){
break loop;
}
String s = "Sno_"+i;
String sql2="select "+s+" from "+ch+" where train_no=? and dep_date=?;";
pstmt = con.prepareStatement(sql2);
pstmt.setInt(1,tno);
pstmt.setString(2,dt);
rs = pstmt.executeQuery();
while(rs.next()){
if(rs.getString(1) == null){
//out.print("<input type='checkbox'>");
//out.println(s);
seats[i-1]="A"; //Stores Available into the seats array which holds the seats booked or not
avail_seats = avail_seats + 1;
}
else{
//out.print("<input type='checkbox' checked='checked' disabled='disabled' />");
//out.println(s);
seats[i-1]="B"; //Stores Booked in seats[]
}
}
}
loop1: for(int i=1; i <= no_wait; i++){
if(ch.equals(null)){
break loop1;
}
String w = "wait_"+i;
String sql3="select "+w+" from "+ch+" where train_no=? and dep_date=?;";
pstmt = con.prepareStatement(sql3);
pstmt.setInt(1,tno);
pstmt.setString(2,dt);
rs = pstmt.executeQuery();
while(rs.next()){
if(rs.getString(1) == null){
//out.print("<input type='checkbox'>");
//out.println(s);
wait[i-1]="A"; //Stores Available into the wait array which holds the seats booked or not
}
else{
//out.print("<input type='checkbox' checked='checked' disabled='disabled' />");
//out.println(s);
wait[i-1]="B"; //Stores Booked tickets in wait[]
}
}
}
%>
<%-- out.println("<table>");
out.println("<tr><th colspan="+block+"> Reservation Seats </th> </tr><tr>");
for(int j=0; j <= no_seats -1 ; j++){
String sno ="Sno_"+(j+1);
if (seats[j]=="A"){
int no = j+1;
out.println("<td>SeatNo:"+no+"</td>");
out.print("<td><input name='seat' type='checkbox' onclick='check(this)' value='S"+no+"'></td>");
}
else{
out.println("<td>SeatNo:"+(j+1)+"</td>");
out.print("<td><input type='checkbox' checked='checked' disabled='disabled' /></td>");
}
if ((j+1) % block == 0){ //To Give the space between seats
out.println("</tr><tr>");
}
}
out.println("</table>");
out.println("<br />");
--%>
<br />
<div style="font-size: 12pt">
Available Seat <img height="30px" width="50px" src="./images/avilable.PNG">
Booked Seat<img height="30px" width="50px" src="./images/booked.PNG">
Selected Seat<img height="30px" width="50px" src="./images/selected.PNG"> <br/><br/>
</div>
<h4>Coach:<%= ch %></h4>
<h4>Available Seats:<%=avail_seats%></h4>
<p style="font-weight: bold; color: navy;"> Reservation Seats</p>
<div style="position: fixed; bottom:5%; left:58%;">
<input type="button" value="Go To Top" onclick="scrollup()"> <br/><br/>
<input type="button" value="Go To Bottom" onclick="scrolldown()">
</div>
<div id='format'>
<%
for(int j=0; j <= no_seats -1 ; j++){
int no = j+1;
if (seats[j]=="A"){
out.print(" ");
out.print("<input type='checkbox' name='seat' id='s"+no+"' value='S"+no+"' onclick='check(this)' /> <label for='s"+no+"' title='AVAILABLE' style=''>S"+no+"</label>");
out.print(" ");
}
else{
out.print(" ");
out.print("<input type='checkbox' id='s"+no+"' checked='checked' disabled='disabled' /> <label for='s"+no+"' title='BOOKED' style=''>S"+no+"</label>");
out.print(" ");
}
if ((j+1) % block == 0){ //To Give the space between seats
out.print("<br/>");
out.print("<br/>");
}
}
%>
</div>
<br />
<p style="font-weight: bold; color: navy;"> Waiting List Seats</p>
<div id='format1'>
<%
for(int j=0; j <= no_wait - 1 ; j++){
int no = j+1;
if (wait[j]=="A"){
out.print(" ");
out.print("<input type='checkbox' name='seat' id='w"+no+"' value='W"+no+"' onclick='check(this)' /> <label for='w"+no+"' title='AVAILABLE'>W"+no+"</label>");
out.print(" ");
}
else{
out.print(" ");
out.print("<input type='checkbox' id='w"+no+"' checked='checked' disabled='disabled' /> <label for='w"+no+"' title='BOOKED'>W"+no+"</label>");
out.print(" ");
}
if ((j+1) % 5 == 0){ //To Give the space between seats
out.print("<br/>");
out.print("<br/>");
}
}
%>
</div>
<span style='color: red; font-size: 10pt;'> * Please Select Adjacent Seats in Waiting List </span>
<%--
out.println("<table>");
out.println("<tr><th colspan="+block+"> Waiting List Seats </th> </tr><tr>");
for(int j=0; j <= no_wait -1 ; j++){
String sno ="Sno_"+(j+1);
if (wait[j]=="A"){
int no = j+1;
out.println("<td>WL No:"+no+"</td>");
out.print("<td><input name='seat' type='checkbox' onclick='check(this)' value='W"+no+"'></td>");
}
else{
out.println("<td>SeatNo:"+(j+1)+"</td>");
out.print("<td><input type='checkbox' checked='checked' disabled='disabled' /></td>");
}
if ((j+1) % 5 == 0){ //To Give the space between seats
out.println("</tr><tr>");
}
}
out.println("</table>");
out.println("<div align='left'> <span style='color: red; font-size: 10pt;'> * Please Select Adjacent Seats in Waiting List </span> </div>");
--%>
<%
}
catch(Exception e){
// e.printStackTrace();
}
%>
<input name="adult" type="hidden" value='<%= adult %>'>
<input name="child" type="hidden" value='<%= child %>'>
<input name="clas" type="hidden" value='<%= clas %>'>
</form>
</div>
<div id="footer"></div>
</body>
</html>