-
Notifications
You must be signed in to change notification settings - Fork 0
/
RemoveEmployee.java
133 lines (117 loc) · 4.34 KB
/
RemoveEmployee.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
package employeemanagement;
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import java.sql.*;
public class RemoveEmployee extends JFrame implements ActionListener{
Choice cEmpId;
JButton delete,back;
RemoveEmployee(){
getContentPane().setBackground(Color.WHITE);
setLayout(null);
JLabel labelempId = new JLabel("Employee Id");
labelempId.setBounds(50, 50, 100, 30);
add(labelempId);
cEmpId=new Choice();
cEmpId.setBounds(200,50,150,30);
add(cEmpId);
try {
Conn c = new Conn();
String query = "select * from employee";
ResultSet rs=c.s.executeQuery(query);
while(rs.next()){
cEmpId.add(rs.getString("empId"));
}
} catch (Exception e) {
e.printStackTrace();
}
JLabel labelname = new JLabel("Name");
labelname.setBounds(50, 100, 100, 30);
add(labelname);
JLabel lblname = new JLabel();
lblname.setBounds(200, 100, 100, 30);
add(lblname);
JLabel labelphone = new JLabel("Phone");
labelname.setBounds(50, 150, 100, 30);
add(labelphone);
JLabel lblphone = new JLabel();
lblphone.setBounds(200, 150, 100, 30);
add(lblphone);
JLabel labelemail = new JLabel("Email");
labelemail.setBounds(50, 200, 100, 30);
add(labelemail);
JLabel lblemail = new JLabel();
lblemail.setBounds(200, 200, 100, 30);
add(lblemail);
try {
Conn c = new Conn();
String query = "select * from employee where empId='"+cEmpId.getSelectedItem()+"'";
ResultSet rs=c.s.executeQuery(query);
while(rs.next()){
lblname.setText(rs.getString("name"));
lblphone.setText(rs.getString("phone"));
lblemail.setText(rs.getString("email"));
}
} catch (Exception e) {
e.printStackTrace();
}
cEmpId.addItemListener(new ItemListener(){
public void itemStateChanged(ItemEvent ie){
try {
Conn c = new Conn();
String query = "select * from employee where empId='"+cEmpId.getSelectedItem()+"'";
ResultSet rs=c.s.executeQuery(query);
while(rs.next()){
lblname.setText(rs.getString("name"));
lblphone.setText(rs.getString("phone"));
lblemail.setText(rs.getString("email"));
}
} catch (Exception e) {
e.printStackTrace();
}
}
});
delete = new JButton("Delete");
delete.setBounds(80, 300, 100, 30);
delete.setBackground(Color.BLACK);
delete.setForeground(Color.WHITE);
delete.addActionListener(this);
add(delete);
back = new JButton("Back");
back.setBounds(220, 300, 100, 30);
back.setBackground(Color.BLACK);
back.setForeground(Color.WHITE);
back.addActionListener(this);
add(back);
ImageIcon i1=new ImageIcon(ClassLoader.getSystemResource("icons/delete.png"));
Image i2=i1.getImage().getScaledInstance(600,400, Image.SCALE_DEFAULT);
ImageIcon i3=new ImageIcon(i2);
JLabel image=new JLabel(i3);
image.setBounds(350,0,600,400);
add(image);
setSize(1000, 400);
setLocation(300, 150);
setVisible(true);
}
public void actionPerformed(ActionEvent ae){
if(ae.getSource()==delete){
try {
Conn c = new Conn();
String query = "delete from employee where empId = '"+cEmpId.getSelectedItem()+"'";
c.s.executeUpdate(query);
JOptionPane.showMessageDialog(null, "Employee Information Deleted successfully");
setVisible(false);
new Home();
} catch (Exception e) {
e.printStackTrace();
}
}
else{
setVisible(false);
new Home();
}
}
public static void main(String args[]){
new RemoveEmployee();
}
}