-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEventFind.java
247 lines (186 loc) · 6.35 KB
/
EventFind.java
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
import java.io.*;
import java.util.ArrayList;
import java.util.Iterator;
import java.awt.*;
import javax.swing.*;
import java.sql.*;
import java.awt.event.*;
class EventFind extends JFrame implements ActionListener{
Font thead,comfont;
JLabel header, ename_label, evenue_label, edate_label, eduration_label, image_label;
JTextField evenue_text, edate_text, eduration_text;
JComboBox<String> event_combo;
JButton search_event, update_event, reset, select_date, insert_photo;
FileDialog fd;
File f;
Connection conn;
String events[];
public EventFind(){
setLayout(null);
try{
Class.forName("com.mysql.jdbc.Driver");
conn = DriverManager.getConnection("jdbc:mysql://localhost/seminar", "root", "");
comfont = new Font("Times New Roman", Font.BOLD, 18);
Statement st = conn.createStatement();
ResultSet rs1 = st.executeQuery("SELECT * FROM event");
ArrayList<String> addEvent = new ArrayList<String>();
while(rs1.next()){
addEvent.add(rs1.getString(2));
}
events = new String[addEvent.size()];
Iterator itr = addEvent.iterator();
int i = 0;
while(itr.hasNext()){
events[i]=(String)itr.next();
i++;
}
} catch(Exception error1){
JOptionPane.showMessageDialog(this,"Error: "+error1);
}
thead = new Font("Times New Roman", Font.BOLD, 30);
header = new JLabel("Event Details");
header.setFont(thead);
ename_label = new JLabel("Select Event Name:");
event_combo = new JComboBox<>(events);
evenue_label = new JLabel("Event Venue:");
evenue_text = new JTextField(20);
edate_label = new JLabel("Event Date:");
select_date = new JButton("Select Event Date");
edate_text = new JTextField(20);
eduration_label = new JLabel("Event Duration: (in Hours)");
eduration_text = new JTextField(20);
search_event = new JButton("Search Event");
update_event = new JButton("Update Event");
reset = new JButton("Reset");
insert_photo = new JButton("Insert Photo");
image_label = new JLabel();
header.setBounds(240,10,300,100);
ename_label.setFont(comfont);
event_combo.setFont(comfont);
ename_label.setBounds(10,80,300,50);
event_combo.setBounds(10,120,300,40);
evenue_label.setFont(comfont);
evenue_text.setFont(comfont);
evenue_label.setBounds(10,170,300,40);
evenue_text.setBounds(10,210,300,40);
edate_label.setFont(comfont);
eduration_label.setFont(comfont);
edate_text.setFont(comfont);
eduration_text.setFont(comfont);
edate_label.setBounds(10,260,300,40);
edate_text.setBounds(10,300,300,40);
eduration_label.setBounds(10,360,300,40);
eduration_text.setBounds(10,400,300,40);
search_event.setFont(comfont);
search_event.setBounds(10,500,150,40);
update_event.setBounds(10,560,150,40);
reset.setBounds(170,560,150,40);
select_date.setBounds(330,560,170,40);
insert_photo.setBounds(510,560,150,40);
update_event.setFont(comfont);
reset.setFont(comfont);
select_date.setFont(comfont);
insert_photo.setFont(comfont);
image_label.setBounds(400,100,250,250);
add(header);
add(ename_label);
add(event_combo);
add(evenue_label);
add(evenue_text);
add(edate_label);
add(select_date);
select_date.addActionListener(this);
add(edate_text);
add(eduration_label);
add(eduration_text);
add(search_event);
search_event.addActionListener(this);
add(update_event);
update_event.addActionListener(this);
add(reset);
reset.addActionListener(this);
add(insert_photo);
insert_photo.addActionListener(this);
add(image_label);
setSize(700,650);
setTitle("Event Details");
//setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setVisible(true);
}
public void actionPerformed(ActionEvent e){
if(e.getSource() == select_date){
//System.out.println("Calling DatePicker");
edate_text.setText(new DatePicker(this).setPickedDate());
}
if(e.getSource() == search_event){
String enames = (String)event_combo.getSelectedItem();
try{
PreparedStatement pst2 = conn.prepareStatement("SELECT * FROM event WHERE ename = ?");
pst2.setString(1, enames);
ResultSet st2 = pst2.executeQuery();
if(st2.next()){
evenue_text.setText(st2.getString(3));
edate_text.setText(st2.getString(4));
eduration_text.setText(st2.getString(5));
Blob b = st2.getBlob(6);
ImageIcon i = new ImageIcon(b.getBytes(1,(int)b.length()));
image_label.setIcon(i);
JOptionPane.showMessageDialog(this,"Event Fetched!");
} else {
JOptionPane.showMessageDialog(this,"Event Not Found!");
}
} catch(Exception error2){
JOptionPane.showMessageDialog(this,"Exception Here...");
System.out.println(error2);
}
}
if(e.getSource() == update_event){
try{
String selectEvent = (String)event_combo.getSelectedItem();
String edate = edate_text.getText();
String evenue = evenue_text.getText();
String eduration = eduration_text.getText();
int dur = Integer.parseInt(eduration);
FileInputStream eposter = new FileInputStream(f);
Date dt=Date.valueOf(edate);
//System.out.println(dt);
PreparedStatement st = conn.prepareStatement("UPDATE event SET ename = ?, evenue = ?, edate = ?, eduration = ?, eposter = ? WHERE ename = ?");
st.setString(2,evenue);
st.setDate(3,dt);
st.setInt(4,dur);
st.setBinaryStream(5,(InputStream)eposter, (long)f.length());
st.setString(6,selectEvent);
int x = st.executeUpdate();
if(x > 0){
JOptionPane.showMessageDialog(this,"Event Updated!");
event_combo.removeAllItems();
Statement st5 = conn.createStatement();
ResultSet rs5 = st5.executeQuery("SELECT * FROM event");
int k = 0;
while(rs5.next()){
event_combo.insertItemAt(rs5.getString(2), k);
k++;
}
}
}catch(Exception q){
JOptionPane.showMessageDialog(this,"Exception Here...");
System.out.println(q);
}
}
if(e.getSource() == reset){
edate_text.setText("");
evenue_text.setText("");
eduration_text.setText("");
}
if(e.getSource() == insert_photo){
fd = new FileDialog(this, "Open File");
fd.setVisible(true);
f = new File(fd.getDirectory()+fd.getFile());
ImageIcon poster = new ImageIcon(fd.getDirectory()+fd.getFile());
image_label.setIcon(poster);
}
}
public static void main(String args[]){
new EventFind();
}
}