-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBookFlight.java
More file actions
237 lines (189 loc) · 8.53 KB
/
BookFlight.java
File metadata and controls
237 lines (189 loc) · 8.53 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
package arilinemanagmentsystem;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.sql.*;
import com.toedter.calendar.JDateChooser;
import java.util.*;
public class BookFlight extends JFrame implements ActionListener{
JTextField tfadhar;
JLabel tfname, tfnationality, tfaddress, labelgender, labelfname, labelfcode;
JButton bookflight, fetchButton, flight;
Choice source, destination;
JDateChooser dcdate;
public BookFlight() {
getContentPane().setBackground(Color.WHITE);
setLayout(null);
JLabel heading = new JLabel("Book Flight");
heading.setBounds(420, 20, 500, 35);
heading.setFont(new Font("Tahoma", Font.PLAIN, 32));
heading.setForeground(Color.BLUE);
add(heading);
JLabel lblaadhar = new JLabel("Aadhar");
lblaadhar.setBounds(60, 80, 150, 25);
lblaadhar.setFont(new Font("Tahoma", Font.PLAIN, 16));
add(lblaadhar);
tfadhar = new JTextField();
tfadhar.setBounds(220, 80, 150, 25);
add(tfadhar);
fetchButton = new JButton("Fetch User");
fetchButton.setBackground(Color.BLACK);
fetchButton.setForeground(Color.WHITE);
fetchButton.setBounds(380, 80, 120, 25);
fetchButton.addActionListener(this);
add(fetchButton);
JLabel lblname = new JLabel("Name");
lblname.setBounds(60, 130, 150, 25);
lblname.setFont(new Font("Tahoma", Font.PLAIN, 16));
add(lblname);
tfname = new JLabel();
tfname.setBounds(220, 130, 150, 25);
add(tfname);
JLabel lblnationality = new JLabel("Nationality");
lblnationality.setBounds(60, 180, 150, 25);
lblnationality.setFont(new Font("Tahoma", Font.PLAIN, 16));
add(lblnationality);
tfnationality = new JLabel();
tfnationality.setBounds(220, 180, 150, 25);
add(tfnationality);
JLabel lbladdress = new JLabel("Address");
lbladdress.setBounds(60, 230, 150, 25);
lbladdress.setFont(new Font("Tahoma", Font.PLAIN, 16));
add(lbladdress);
tfaddress = new JLabel();
tfaddress.setBounds(220, 230, 150, 25);
add(tfaddress);
JLabel lblgender = new JLabel("Gender");
lblgender.setBounds(60, 280, 150, 25);
lblgender.setFont(new Font("Tahoma", Font.PLAIN, 16));
add(lblgender);
labelgender = new JLabel("Gender");
labelgender.setBounds(220, 280, 150, 25);
add(labelgender);
JLabel lblsource = new JLabel("Source");
lblsource.setBounds(60, 330, 150, 25);
lblsource.setFont(new Font("Tahoma", Font.PLAIN, 16));
add(lblsource);
source = new Choice();
source.setBounds(220, 330, 150, 25);
add(source);
JLabel lbldest = new JLabel("Destination");
lbldest.setBounds(60, 380, 150, 25);
lbldest.setFont(new Font("Tahoma", Font.PLAIN, 16));
add(lbldest);
destination = new Choice();
destination.setBounds(220, 380, 150, 25);
add(destination);
try {
Conn c = new Conn();
String query = "select * from flight";
ResultSet rs = c.s.executeQuery(query);
while(rs.next()) {
source.add(rs.getString("source"));
destination.add(rs.getString("destination"));
}
} catch (Exception e) {
e.printStackTrace();
}
flight = new JButton("Fetch Flights");
flight.setBackground(Color.BLACK);
flight.setForeground(Color.WHITE);
flight.setBounds(380, 380, 120, 25);
flight.addActionListener(this);
add(flight);
JLabel lblfname = new JLabel("Flight Name");
lblfname.setBounds(60, 430, 150, 25);
lblfname.setFont(new Font("Tahoma", Font.PLAIN, 16));
add(lblfname);
labelfname = new JLabel();
labelfname.setBounds(220, 430, 150, 25);
add(labelfname);
JLabel lblfcode = new JLabel("Flight Code");
lblfcode.setBounds(60, 480, 150, 25);
lblfcode.setFont(new Font("Tahoma", Font.PLAIN, 16));
add(lblfcode);
labelfcode = new JLabel();
labelfcode.setBounds(220, 480, 150, 25);
add(labelfcode);
JLabel lbldate = new JLabel("Date of Travel");
lbldate.setBounds(60, 530, 150, 25);
lbldate.setFont(new Font("Tahoma", Font.PLAIN, 16));
add(lbldate);
dcdate = new JDateChooser();
dcdate.setBounds(220, 530, 150, 25);
add(dcdate);
ImageIcon i1 = new ImageIcon(ClassLoader.getSystemResource("arilinemanagmentsystem/Icons/details.jpg"));
Image i2 = i1.getImage().getScaledInstance(450, 320, Image.SCALE_DEFAULT);
ImageIcon image = new ImageIcon(i2);
JLabel lblimage = new JLabel(image);
lblimage.setBounds(550, 80, 500, 410);
add(lblimage);
bookflight = new JButton("Book Flight");
bookflight.setBackground(Color.BLACK);
bookflight.setForeground(Color.WHITE);
bookflight.setBounds(220, 580, 150, 25);
bookflight.addActionListener(this);
add(bookflight);
setSize(1100, 700);
setLocation(200, 50);
setVisible(true);
}
public void actionPerformed(ActionEvent ae) {
if (ae.getSource() == fetchButton) {
String adhar = tfadhar.getText();
try {
Conn conn = new Conn();
String query = "select * from passenger1 where adhar = '"+adhar+"'";
ResultSet rs = conn.s.executeQuery(query);
if (rs.next()) {
tfname.setText(rs.getString("name"));
tfnationality.setText(rs.getString("nationality"));
tfaddress.setText(rs.getString("address"));
labelgender.setText(rs.getString("gender"));
} else {
JOptionPane.showMessageDialog(null, "Please enter correct aadhar");
}
} catch (Exception e) {
e.printStackTrace();
}
} else if (ae.getSource() == flight) {
String src = source.getSelectedItem();
String dest = destination.getSelectedItem();
try {
Conn conn = new Conn();
String query = "select * from flight where source = '"+src+"' and destination = '"+dest+"'";
ResultSet rs = conn.s.executeQuery(query);
if (rs.next()) {
labelfname.setText(rs.getString("f_name"));
labelfcode.setText(rs.getString("f_code"));
} else {
JOptionPane.showMessageDialog(null, "No Flights Found");
}
} catch (Exception e) {
e.printStackTrace();
}
} else {
Random random = new Random();
String adhar = tfadhar.getText();
String name = tfname.getText();
String nationality = tfnationality.getText();
String flightname = labelfname.getText();
String flightcode = labelfcode.getText();
String src = source.getSelectedItem();
String des = destination.getSelectedItem();
String ddate = ((JTextField) dcdate.getDateEditor().getUiComponent()).getText();
try {
Conn conn = new Conn();
String query = "insert into reservation values('PNR-"+random.nextInt(1000000)+"', 'TIC-"+random.nextInt(10000)+"', '"+adhar+"', '"+name+"', '"+nationality+"', '"+flightname+"', '"+flightcode+"', '"+src+"', '"+des+"', '"+ddate+"')";
conn.s.executeUpdate(query);
JOptionPane.showMessageDialog(null, "Ticket Booked Successfully");
setVisible(false);
} catch (Exception e) {
e.printStackTrace();
}
}
}
public static void main(String[] args) {
new BookFlight();
}
}