-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdelete.java
More file actions
386 lines (312 loc) · 14.8 KB
/
delete.java
File metadata and controls
386 lines (312 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
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
package user_design;
import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.text.SimpleDateFormat;
import java.time.LocalDate;
import java.time.temporal.ChronoUnit;
import java.util.ArrayList;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JButton;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.*;
public class delete extends javax.swing.JFrame implements ActionListener {
String email="saif@gmail.com";
private String IDN;
private String user="c##fanan2";
private String password="0000";
private PreparedStatement statement;
private ResultSet rs;
ArrayList <Integer> bl;
public delete() {
this.bl = new ArrayList<Integer>();
initComponents();
try
{
try (Connection conn = DriverManager.getConnection(
"jdbc:oracle:thin:@localhost:1521:orcl", user, this.password)) {
if(conn!=null)
{
String query="Select IDN from USER1 where Email='"+email+"'";
statement = conn.prepareStatement(query);
rs= statement.executeQuery();
if(rs.next())
{
IDN=rs.getString("IDN");
}
conn.close();
}
}
}
catch(SQLException Ex)
{
Logger.getLogger(delete.class.getName()).log(Level.SEVERE, null, Ex);
}
this.bl = new ArrayList<Integer>();
initComponents();
try{
Connection con2 =conn.getConncetion();
con2.setAutoCommit(false);
System.out.println("hi1");
String query = "select distinct bsq from booking_user where idn="+IDN;
Statement ps2= con2.createStatement();
System.out.println("hi2");
ps2.executeUpdate(query);
ResultSet rs2=ps2.executeQuery(query);
System.out.println("hi1");
this.getContentPane().setLayout(new FlowLayout());
while(rs2.next()){
int f= Integer.parseInt(rs2.getString("BSQ"));
bl.add(f);
}
con2.close();}
catch(Exception v){
Logger.getLogger(delete.class.getName()).log(Level.SEVERE, null, v);
}
int count=0;
bo.removeAll();
offer.setLayout(new GridLayout(10,4));
for(int i=0;i< bl.size();i++){
try {
Connection con =conn.getConncetion();
con.setAutoCommit(false);
System.out.println("hi1");
String query = "select distinct offer.OSQ,offer.date_to,offer.date_from,offer.to_des,offer.from_des, booking.hname,booking.room_type,booking.aname,booking.classd,booking.totcost from offer,booking where booking.ido=offer.osq and bsq="+bl.get(i);
Statement ps= con.createStatement();
System.out.println("hi2");
ps.executeUpdate(query);
ResultSet rs=ps.executeQuery(query);
System.out.println("hi1");
this.getContentPane().setLayout(new FlowLayout());
while(rs.next()){
System.out.println("hi3");
tod =rs.getString("Date_to");
System.out.println(rs.getString("Date_to"));
fromd = rs.getString("Date_from");
todes= rs.getString("to_Des");
fromdes= rs.getString("From_des");
System.out.println("hi35");
id=Integer.parseInt(rs.getString("OSQ"));
classd= Integer.parseInt(rs.getString("classd"));
hotel=rs.getString("hname");
airport=rs.getString("aname");
room=rs.getString("room_type");
System.out.println("hi34");
//JTextPane t1= new JTextPane ();
// System.out.println(id+hotel+airport);
// this.appendToPane(t1,"From Date :"+fromd+"\n");
//java.util.Date d1 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse(fromd);
//java.util.Date d2 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse(tod);
/* String []aa=fromd.split(" ");
String []bb=tod.split(" ");
LocalDate dd1=LocalDate.parse(aa[0]);
LocalDate dd2=LocalDate.parse(bb[0]);
long day= ChronoUnit.DAYS.between(dd2, dd1);
System.out.println(day);*/
long day=10;
cost = day*hprice +tprice+sprices;
cost=cost+cost*.2;
JTextArea t1= new JTextArea ();
// t1.append("From Date :"+fromd+"\n");
// t1.append("From Date :"+fromd+"\n");
// t1.append("To Date :"+tod+"\n");
// t1.append(" From :"+fromdes+"\n");
// t1.append("To :"+todes+"\n");
// t1.append("Hotel Name :"+hotel+"\n");
// t1.append("Room Type :"+room+"\n");
// t1.append("Airport name :"+airport+"\n");
// t1.append("Flight Class :"+classd+"\n");
// t1.append("Discription :"+descrp+"\n");
// t1.append("Total Cost :"+cost+"\n");
t1.setName(count+"");
count++;
JButton b= new JButton ("Delete");
// p.setPreferredSize(new Dimension(350,190));
JButton b2= new JButton ("Show Details");
// p.setPreferredSize(new Dimension(350,190));
JPanel p= new JPanel (new BorderLayout());
b.setPreferredSize(new Dimension(20,20));
b2.setPreferredSize(new Dimension(20,20));
JPanel pb = new JPanel(new GridLayout(3,1));
JTextArea tt= new JTextArea();
tt.setText("From :"+fromdes+" \t"+"To :"+todes+"\t"+"Cost :"+cost);
pb.add(tt);
pb.add(b2);
pb.add(b);
p.add(t1,BorderLayout.CENTER);
p.add(pb,BorderLayout.SOUTH);
String tip=
"From Date :"+fromd+"\n"+
"To Date :"+tod+"\n"+
" From :"+fromdes+"\n"+
"To :"+todes+"\n"+
"Hotel Name :"+hotel+"\n"+
"Room Type :"+room+"\n"+
"Airport name :"+airport+"\n"+
"Flight Class :"+classd+"\n"+
"Discription :"+descrp+"\n";
// settip(p,tip);
bo.add(p);
this.add(bo,BorderLayout.CENTER);
this.revalidate();
this.repaint();
b2.addActionListener(this);
b2.setActionCommand("dt/"+tip);
b.addActionListener(this);
b.setActionCommand("d/"+bl.get(i)+" "+id+" "+hotel+" "+room+" "+airport+" "+classd+" "+cost);
// t1.insert(airport,300);
// t1.insert(classd+"",400);
// t1.insert(room,5000);
// t1.insert(descrp,600);
// t1.insert(fromdes,700);
// t1.insert(todes,800);
// listt.add(t1);
// GridBagConstraints gtf= new GridBagConstraints();
// gtf.fill=GridBagConstraints.HORIZONTAL;
// gtf.weightx=.5;
// gtf.gridx=0;
// gtf.gridwidth=2;
// gtf.gridy=3+listt.size();
// add (t1,gtf);
// revalidate();
// repaint();
// t1.setText(id+"");
// this.getContentPane().setLayout(new FlowLayout());
// this.add(t1);
}
// JOptionPane.showMessageDialog(null, "no");
con.close();
} catch (Exception ex) {
Logger.getLogger(delete.class.getName()).log(Level.SEVERE, null, ex);
}
}
}
@SuppressWarnings("unchecked")
JPanel offer = new JPanel();
String tod;
String fromd;
String descrp;
String todes;
String fromdes;
String hotel;
String airport;
int id;
String room;
double cost;
int classd;
int hprice;
int tprice;
int sprices;
int ssq;
JPanel bo = new JPanel(new GridLayout(3,10,5,5));
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
private void initComponents() {
jPanel1 = new javax.swing.JPanel();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
jPanel1.setBackground(new java.awt.Color(204, 255, 255));
javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
jPanel1.setLayout(jPanel1Layout);
jPanel1Layout.setHorizontalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 814, Short.MAX_VALUE)
);
jPanel1Layout.setVerticalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 154, Short.MAX_VALUE)
);
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addContainerGap()
.addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addContainerGap())
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap(137, Short.MAX_VALUE))
);
pack();
}// </editor-fold>//GEN-END:initComponents
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
/* Set the Nimbus look and feel */
//<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
/* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
* For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
*/
try {
for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
if ("Nimbus".equals(info.getName())) {
javax.swing.UIManager.setLookAndFeel(info.getClassName());
break;
}
}
} catch (ClassNotFoundException ex) {
java.util.logging.Logger.getLogger(delete.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(delete.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(delete.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(delete.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
}
//</editor-fold>
/* Create and display the form */
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new delete().setVisible(true);
}
});
}
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JPanel jPanel1;
// End of variables declaration//GEN-END:variables
@Override
public void actionPerformed(ActionEvent e) {
//To change body of generated methods, choose Tools | Templates.
String ac= e.getActionCommand();
String []ids= ac.split("/");
if(ids[0].equals("dt")){
JOptionPane.showMessageDialog(rootPane, ids[1]);
}
else{
// b.setActionCommand("b/"+id+" "+hotel+" "+room+" "+airport+" "+classd+" "+cost);
String [] info =ids[1].split(" ");
System.out.println(Double.parseDouble(info[5]));
double fcost=Double.parseDouble(info[5]);
System.out.println(info[0]+" "+info[1]+" "+info[2]+" "+info[3]+" "+info[4]+" "+fcost);
try{
Connection con2 =conn.getConncetion();
con2.setAutoCommit(false);
System.out.println("hi1");
String query = "delete from booking_user where idn="+IDN+" and bsq="+info[0];
Statement ps2= con2.createStatement();
System.out.println("hi2");
ps2.executeUpdate(query);
con2.commit();
con2.close();
}
catch(Exception exx){
Logger.getLogger(delete.class.getName()).log(Level.SEVERE, null, exx);
}
}
}
}