-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathViewEmployee.java
More file actions
105 lines (87 loc) · 2.99 KB
/
ViewEmployee.java
File metadata and controls
105 lines (87 loc) · 2.99 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
package employee.management.system;
import javax.swing.*;
import java.awt.*;
import java.sql.*;
import net.proteanit.sql.DbUtils;
import java.awt.event.*;
public class ViewEmployee extends JFrame implements ActionListener{
JTable table;
Choice cemployeeId;
JButton search, print, update, back;
ViewEmployee() {
getContentPane().setBackground(Color.WHITE);
setLayout(null);
JLabel searchlbl = new JLabel("Search by Employee Id");
searchlbl.setBounds(20, 20, 150, 20);
add(searchlbl);
cemployeeId = new Choice();
cemployeeId.setBounds(180, 20, 150, 20);
add(cemployeeId);
try {
Conn c = new Conn();
ResultSet rs = c.s.executeQuery("select * from employee");
while(rs.next()) {
cemployeeId.add(rs.getString("empId"));
}
} catch (Exception e) {
e.printStackTrace();
}
table = new JTable();
try {
Conn c = new Conn();
ResultSet rs = c.s.executeQuery("select * from employee");
table.setModel(DbUtils.resultSetToTableModel(rs));
} catch (Exception e) {
e.printStackTrace();
}
JScrollPane jsp = new JScrollPane(table);
jsp.setBounds(0, 100, 900, 600);
add(jsp);
search = new JButton("Search");
search.setBounds(20, 70, 80, 20);
search.addActionListener(this);
add(search);
print = new JButton("Print");
print.setBounds(120, 70, 80, 20);
print.addActionListener(this);
add(print);
update = new JButton("Update");
update.setBounds(220, 70, 80, 20);
update.addActionListener(this);
add(update);
back = new JButton("Back");
back.setBounds(320, 70, 80, 20);
back.addActionListener(this);
add(back);
setSize(900, 700);
setLocation(300, 100);
setVisible(true);
}
public void actionPerformed(ActionEvent ae) {
if (ae.getSource() == search) {
String query = "select * from employee where empId = '"+cemployeeId.getSelectedItem()+"'";
try {
Conn c = new Conn();
ResultSet rs = c.s.executeQuery(query);
table.setModel(DbUtils.resultSetToTableModel(rs));
} catch (Exception e) {
e.printStackTrace();
}
} else if (ae.getSource() == print) {
try {
table.print();
} catch (Exception e) {
e.printStackTrace();
}
} else if (ae.getSource() == update) {
setVisible(false);
new UpdateEmployee(cemployeeId.getSelectedItem());
} else {
setVisible(false);
new Home();
}
}
public static void main(String[] args) {
new ViewEmployee();
}
}