-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUpdateEmployee.java
More file actions
195 lines (160 loc) · 6.87 KB
/
UpdateEmployee.java
File metadata and controls
195 lines (160 loc) · 6.87 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
package employee.management.system;
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import java.sql.*;
public class UpdateEmployee extends JFrame implements ActionListener{
JTextField tfeducation, tffname, tfaddress, tfphone, tfaadhar, tfemail, tfsalary, tfdesignation;
JLabel lblempId;
JButton add, back;
String empId;
UpdateEmployee(String empId) {
this.empId = empId;
getContentPane().setBackground(Color.WHITE);
setLayout(null);
JLabel heading = new JLabel("Update Employee Detail");
heading.setBounds(320, 30, 500, 50);
heading.setFont(new Font("SAN_SERIF", Font.BOLD, 25));
add(heading);
JLabel labelname = new JLabel("Name");
labelname.setBounds(50, 150, 150, 30);
labelname.setFont(new Font("serif", Font.PLAIN, 20));
add(labelname);
JLabel lblname = new JLabel();
lblname.setBounds(200, 150, 150, 30);
add(lblname);
JLabel labelfname = new JLabel("Father's Name");
labelfname.setBounds(400, 150, 150, 30);
labelfname.setFont(new Font("serif", Font.PLAIN, 20));
add(labelfname);
tffname = new JTextField();
tffname.setBounds(600, 150, 150, 30);
add(tffname);
JLabel labeldob = new JLabel("Date of Birth");
labeldob.setBounds(50, 200, 150, 30);
labeldob.setFont(new Font("serif", Font.PLAIN, 20));
add(labeldob);
JLabel lbldob = new JLabel();
lbldob.setBounds(200, 200, 150, 30);
add(lbldob);
JLabel labelsalary = new JLabel("Salary");
labelsalary.setBounds(400, 200, 150, 30);
labelsalary.setFont(new Font("serif", Font.PLAIN, 20));
add(labelsalary);
tfsalary = new JTextField();
tfsalary.setBounds(600, 200, 150, 30);
add(tfsalary);
JLabel labeladdress = new JLabel("Address");
labeladdress.setBounds(50, 250, 150, 30);
labeladdress.setFont(new Font("serif", Font.PLAIN, 20));
add(labeladdress);
tfaddress = new JTextField();
tfaddress.setBounds(200, 250, 150, 30);
add(tfaddress);
JLabel labelphone = new JLabel("Phone");
labelphone.setBounds(400, 250, 150, 30);
labelphone.setFont(new Font("serif", Font.PLAIN, 20));
add(labelphone);
tfphone = new JTextField();
tfphone.setBounds(600, 250, 150, 30);
add(tfphone);
JLabel labelemail = new JLabel("Email");
labelemail.setBounds(50, 300, 150, 30);
labelemail.setFont(new Font("serif", Font.PLAIN, 20));
add(labelemail);
tfemail = new JTextField();
tfemail.setBounds(200, 300, 150, 30);
add(tfemail);
JLabel labeleducation = new JLabel("Higest Education");
labeleducation.setBounds(400, 300, 150, 30);
labeleducation.setFont(new Font("serif", Font.PLAIN, 20));
add(labeleducation);
tfeducation = new JTextField();
tfeducation.setBounds(600, 300, 150, 30);
add(tfeducation);
JLabel labeldesignation = new JLabel("Designation");
labeldesignation.setBounds(50, 350, 150, 30);
labeldesignation.setFont(new Font("serif", Font.PLAIN, 20));
add(labeldesignation);
tfdesignation = new JTextField();
tfdesignation.setBounds(200, 350, 150, 30);
add(tfdesignation);
JLabel labelaadhar = new JLabel("Aadhar Number");
labelaadhar.setBounds(400, 350, 150, 30);
labelaadhar.setFont(new Font("serif", Font.PLAIN, 20));
add(labelaadhar);
JLabel lblaadhar = new JLabel();
lblaadhar.setBounds(600, 350, 150, 30);
add(lblaadhar);
JLabel labelempId = new JLabel("Employee id");
labelempId.setBounds(50, 400, 150, 30);
labelempId.setFont(new Font("serif", Font.PLAIN, 20));
add(labelempId);
lblempId = new JLabel();
lblempId.setBounds(200, 400, 150, 30);
lblempId.setFont(new Font("serif", Font.PLAIN, 20));
add(lblempId);
try {
Conn c = new Conn();
String query = "select * from employee where empId = '"+empId+"'";
ResultSet rs = c.s.executeQuery(query);
while(rs.next()) {
lblname.setText(rs.getString("name"));
tffname.setText(rs.getString("fname"));
lbldob.setText(rs.getString("dob"));
tfaddress.setText(rs.getString("address"));
tfsalary.setText(rs.getString("salary"));
tfphone.setText(rs.getString("phone"));
tfemail.setText(rs.getString("email"));
tfeducation.setText(rs.getString("education"));
lblaadhar.setText(rs.getString("aadhar"));
lblempId.setText(rs.getString("empId"));
tfdesignation.setText(rs.getString("designation"));
}
} catch (Exception e) {
e.printStackTrace();
}
add = new JButton("Update Details");
add.setBounds(250, 550, 150, 40);
add.addActionListener(this);
add.setBackground(Color.BLACK);
add.setForeground(Color.WHITE);
add(add);
back = new JButton("Back");
back.setBounds(450, 550, 150, 40);
back.addActionListener(this);
back.setBackground(Color.BLACK);
back.setForeground(Color.WHITE);
add(back);
setSize(900, 700);
setLocation(300, 50);
setVisible(true);
}
public void actionPerformed(ActionEvent ae) {
if (ae.getSource() == add) {
String fname = tffname.getText();
String salary = tfsalary.getText();
String address = tfaddress.getText();
String phone = tfphone.getText();
String email = tfemail.getText();
String education = tfeducation.getText();
String designation = tfdesignation.getText();
try {
Conn conn = new Conn();
String query = "update employee set fname = '"+fname+"', salary = '"+salary+"', address = '"+address+"', phone = '"+phone+"', email = '"+email+"', education = '"+education+"', designation = '"+designation+"' where empId = '"+empId+"'";
conn.s.executeUpdate(query);
JOptionPane.showMessageDialog(null, "Details updated successfully");
setVisible(false);
new Home();
} catch (Exception e) {
e.printStackTrace();
}
} else {
setVisible(false);
new Home();
}
}
public static void main(String[] args) {
new UpdateEmployee("");
}
}