-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathMangerFuctions.java
More file actions
290 lines (233 loc) · 10.5 KB
/
MangerFuctions.java
File metadata and controls
290 lines (233 loc) · 10.5 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
/*
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
*/
package manager_ui;
import java.lang.System.Logger;
import java.lang.System.Logger.Level;
import java.sql.*;
import javax.swing.JOptionPane;
/**
*
* @author EASY LIFE
*/
public class MangerFuctions {
static String url="jdbc:oracle:thin:@Localhost:1521:orcl";
static String user="c##fanan2";
static String password="0000";
static Connection conn=null;
static ResultSet showAllOffers(){
ResultSet rs=null;
try {
conn = DriverManager.getConnection(url,user,password);
conn.setAutoCommit(false);
Statement st=conn.createStatement();
String s="Select * from offer";
rs=st.executeQuery(s);
/* while(rs.next()){
System.out.println(rs.getInt(1)+" "+rs.getString(2)+" "+rs.getDate(3)+" "+rs.getDate(4)+" "+rs.getString(5)+" "+rs.getString(6));
}*/
//conn.close();
} catch (SQLException ex) {
java.util.logging.Logger.getLogger(MangerFuctions.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
}
return rs;
}
static ResultSet getHotelInfo(int offerID){
ResultSet rs=null;
try {
conn = DriverManager.getConnection(url,user,password);
String s;
conn.setAutoCommit(false);
Statement st=conn.createStatement();
if(offerID==0){
s="Select * from hotel";
rs=st.executeQuery(s);
return rs;
}
if(offerID>0){
s="Select * from hotoffer where ido="+offerID;
// String s="Select * from hotoffer";
rs=st.executeQuery(s);
rs.next();
s="Select * from hotel where hname='"+rs.getString(2)+"' AND room_type='"+rs.getString(3) +"'";
rs=st.executeQuery(s);
}
} catch (SQLException ex) {
java.util.logging.Logger.getLogger(MangerFuctions.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
}
return rs;
}
static ResultSet getAirInfo(int offerID){
ResultSet rs=null;
try {
String s;
conn = DriverManager.getConnection(url,user,password);
conn.setAutoCommit(false);
Statement st=conn.createStatement();
if(offerID==0){ s="Select * from airport ";
rs=st.executeQuery(s);
return rs;
}
if(offerID>0){
s="Select * from airoffer where ido="+offerID;
// String s="Select * from airoffer ";
rs=st.executeQuery(s);
rs.next();
s="Select * from airport where aname='"+rs.getString(2)+"' AND classd="+rs.getInt(3);
rs=st.executeQuery(s);
}
} catch (SQLException ex) {
java.util.logging.Logger.getLogger(MangerFuctions.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
}
return rs;
}
static void closeConn(){
try {
conn.close();
} catch (SQLException ex) {
java.util.logging.Logger.getLogger(MangerFuctions.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
}
}
static void AddNewOffer(Offer newOffer){
System.out.println(newOffer.toString());
String url,user,password;
url="jdbc:oracle:thin:@Localhost:1521:orcl";
user="c##fanan2";
password="0000";
Connection conn;
try {
conn = DriverManager.getConnection(url,user,password);
conn.setAutoCommit(false);
Statement st=conn.createStatement();
String s="insert into offer values("+newOffer.OSQ+",'"+newOffer.descrption+"',"+"TO_DATE('"+newOffer.Date_to+"','dd/mm/yyyy')"+","+"TO_DATE('"+newOffer.Date_from+"','dd/mm/yyyy')"+",'"+newOffer.to_des+"','"+newOffer.from_des+"','"+newOffer.Img+"')";//nfyhjukiolikujyhtgfrdeswertyuioiujyhtgfrdesderftgyhuji
String hotOffer="insert into hotoffer values("+newOffer.OSQ+",'"+newOffer.hname+"','"+newOffer.room_type+"')";
String airoffer="insert into airoffer values("+newOffer.OSQ+",'"+newOffer.Aname+"',"+newOffer.classd+")";
st.execute(s);
conn.commit();
st.execute(hotOffer);
conn.commit();
st.execute(airoffer);
conn.commit();
JOptionPane.showMessageDialog(null, "Offer Added");
conn.close();
} catch (SQLException ex) {
java.util.logging.Logger.getLogger(MangerFuctions.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
JOptionPane.showMessageDialog(null, "Offer not Added");
}
}
static void AddHotel(String hname,String hAddress,int stars,int hotelPrice,String roomTypes){
String url,user,password;
url="jdbc:oracle:thin:@Localhost:1521:orcl";
user="c##fanan2";
password="0000";
Connection conn;
try {
conn = DriverManager.getConnection(url,user,password);
conn.setAutoCommit(false);
Statement st=conn.createStatement();
String s="insert into hotel values('"+hname+"','"+hAddress+"',"+stars+","+"1"+","+hotelPrice+",'"+roomTypes+"')";
try{
st.execute(s);
JOptionPane.showMessageDialog(null, "Hotel "+hname+" was added sucssesfuly!\nYou can use it in making any offer to the users"); }
catch(SQLException ex) {
JOptionPane.showMessageDialog(null, "Hotel "+hname+" wasn't added \nTry again"); }
conn.commit();
conn.close();
} catch (SQLException ex) {
java.util.logging.Logger.getLogger(MangerFuctions.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
}
}
static int getOfferSeq(){
int seq=0;
ResultSet rs=null;
try {
conn = DriverManager.getConnection(url,user,password);
conn.setAutoCommit(false);
Statement st=conn.createStatement();
String s="Select OSQ.nextval from DUAL";
rs=st.executeQuery(s);
rs.next();
seq=rs.getInt(1);
//conn.close();
} catch (SQLException ex) {
java.util.logging.Logger.getLogger(MangerFuctions.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
}
return seq;
}
static void AddAirport (String aname,String aAddress,int TicketPrice,int classs){
String url="jdbc:oracle:thin:@Localhost:1521:orcl";
String user="c##fanan2";
String password="0000";
Connection conn;
try {
conn = DriverManager.getConnection(url,user,password);
conn.setAutoCommit(false);
Statement st=conn.createStatement();
String s="insert into airport values('"+aname+"','"+aAddress+"',2"+","+TicketPrice+","+classs+")";
try{
st.execute(s);
JOptionPane.showMessageDialog(null, "Airport "+aname+" was added sucssesfuly!\nYou can use it in making any offer to the users"); }
catch(SQLException ex) {
JOptionPane.showMessageDialog(null, "Airport "+aname+" wasn't added \nTry again"); }
conn.commit();
conn.close();
} catch (SQLException ex) {
java.util.logging.Logger.getLogger(MangerFuctions.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
}
}
static void UpdateOffer(Offer newOffer){
System.out.println(newOffer.toString());
String url,user,password;
url="jdbc:oracle:thin:@Localhost:1521:orcl";
user="c##fanan2";
password="0000";
Connection conn;
try {
conn = DriverManager.getConnection(url,user,password);
conn.setAutoCommit(false);
Statement st=conn.createStatement();
String s="update offer set OSQ="+newOffer.OSQ+",DESCRIPTION='"+newOffer.descrption+"',DATE_TO="+"TO_DATE('"+newOffer.Date_to+"','dd/mm/yyyy')"+",DATE_FROM="+"TO_DATE('"+newOffer.Date_from+"','dd/mm/yyyy')"+",TO_DES='"+newOffer.to_des+"',FROM_DES='"+newOffer.from_des+"',IMG='"+newOffer.Img+"' where OSQ="+newOffer.OSQ;//nfyhjukiolikujyhtgfrdeswertyuioiujyhtgfrdesderftgyhuji
String hotOffer="update hotoffer set hname='"+newOffer.hname+"',room_type='"+newOffer.room_type+"' where IDO="+newOffer.OSQ;
String airoffer="update airoffer set aname='"+newOffer.Aname+"',classd="+newOffer.classd+" where IDO="+newOffer.OSQ;
st.executeUpdate(s);
conn.commit();
st.executeUpdate(hotOffer);
conn.commit();
st.executeUpdate(airoffer);
conn.commit();
JOptionPane.showMessageDialog(null, "Offer updated");
conn.close();
} catch (SQLException ex) {
java.util.logging.Logger.getLogger(MangerFuctions.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
JOptionPane.showMessageDialog(null, "Offer not updated");
}
}
static void DeleteOffer(Offer newOffer){
System.out.println(newOffer.toString());
String url,user,password;
url="jdbc:oracle:thin:@Localhost:1521:orcl";
user="c##fanan2";
password="0000";
Connection conn;
try {
conn = DriverManager.getConnection(url,user,password);
conn.setAutoCommit(false);
Statement st=conn.createStatement();
String s="delete from offer where OSQ="+newOffer.OSQ;//nfyhjukiolikujyhtgfrdeswertyuioiujyhtgfrdesderftgyhuji
String hotOffer="delete from hotoffer where IDO="+newOffer.OSQ;
String airoffer="DELETE FROM airoffer WHERE IDO="+newOffer.OSQ;
st.executeUpdate(hotOffer);
conn.commit();
st.executeUpdate(airoffer);
conn.commit();
st.executeUpdate(s);
conn.commit();
JOptionPane.showMessageDialog(null, "Offer deleted");
conn.close();
} catch (SQLException ex) {
java.util.logging.Logger.getLogger(MangerFuctions.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
JOptionPane.showMessageDialog(null, "Offer not deleted");
}
}
}