-
Notifications
You must be signed in to change notification settings - Fork 3
/
UpdateTeacher.java
254 lines (212 loc) · 9.25 KB
/
UpdateTeacher.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
248
249
250
251
252
253
254
package university.management.system;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.sql.*;
public class UpdateTeacher extends JFrame implements ActionListener{
JTextField tfcourse, tfaddress, tfphone, tfemail, tfbranch;
JLabel labelEmpId;
JButton submit, cancel;
Choice cEmpId;
UpdateTeacher() {
setSize(900, 650);
setLocation(350, 50);
setLayout(null);
JLabel heading = new JLabel("Update Teacher Details");
heading.setBounds(50, 10, 500, 50);
heading.setFont(new Font("Tahoma", Font.ITALIC, 35));
add(heading);
JLabel lblrollnumber = new JLabel("Select Employee Id");
lblrollnumber.setBounds(50, 100, 200, 20);
lblrollnumber.setFont(new Font("serif", Font.PLAIN, 20));
add(lblrollnumber);
cEmpId = new Choice();
cEmpId.setBounds(250, 100, 200, 20);
add(cEmpId);
try {
Conn c = new Conn();
ResultSet rs = c.s.executeQuery("select * from teacher");
while(rs.next()) {
cEmpId.add(rs.getString("empId"));
}
} catch (Exception e) {
e.printStackTrace();
}
JLabel lblname = new JLabel("Name");
lblname.setBounds(50, 150, 100, 30);
lblname.setFont(new Font("serif", Font.BOLD, 20));
add(lblname);
JLabel labelname = new JLabel();
labelname.setBounds(200, 150, 150, 30);
labelname.setFont(new Font("Tahoma", Font.PLAIN, 18));
add(labelname);
JLabel lblfname = new JLabel("Father's Name");
lblfname.setBounds(400, 150, 200, 30);
lblfname.setFont(new Font("serif", Font.BOLD, 20));
add(lblfname);
JLabel labelfname = new JLabel();
labelfname.setBounds(600, 150, 150, 30);
labelfname.setFont(new Font("Tahoma", Font.PLAIN, 18));
add(labelfname);
JLabel lblrollno = new JLabel("Employee Id");
lblrollno.setBounds(50, 200, 200, 30);
lblrollno.setFont(new Font("serif", Font.BOLD, 20));
add(lblrollno);
labelEmpId = new JLabel();
labelEmpId.setBounds(200, 200, 200, 30);
labelEmpId.setFont(new Font("Tahoma", Font.PLAIN, 18));
add(labelEmpId);
JLabel lbldob = new JLabel("Date of Birth");
lbldob.setBounds(400, 200, 200, 30);
lbldob.setFont(new Font("serif", Font.BOLD, 20));
add(lbldob);
JLabel labeldob = new JLabel();
labeldob.setBounds(600, 200, 150, 30);
labeldob.setFont(new Font("Tahoma", Font.PLAIN, 18));
add(labeldob);
JLabel lbladdress = new JLabel("Address");
lbladdress.setBounds(50, 250, 200, 30);
lbladdress.setFont(new Font("serif", Font.BOLD, 20));
add(lbladdress);
tfaddress = new JTextField();
tfaddress.setBounds(200, 250, 150, 30);
add(tfaddress);
JLabel lblphone = new JLabel("Phone");
lblphone.setBounds(400, 250, 200, 30);
lblphone.setFont(new Font("serif", Font.BOLD, 20));
add(lblphone);
tfphone = new JTextField();
tfphone.setBounds(600, 250, 150, 30);
add(tfphone);
JLabel lblemail = new JLabel("Email Id");
lblemail.setBounds(50, 300, 200, 30);
lblemail.setFont(new Font("serif", Font.BOLD, 20));
add(lblemail);
tfemail = new JTextField();
tfemail.setBounds(200, 300, 150, 30);
add(tfemail);
JLabel lblx = new JLabel("Class X (%)");
lblx.setBounds(400, 300, 200, 30);
lblx.setFont(new Font("serif", Font.BOLD, 20));
add(lblx);
JLabel labelx = new JLabel();
labelx.setBounds(600, 300, 150, 30);
labelx.setFont(new Font("Tahoma", Font.PLAIN, 18));
add(labelx);
JLabel lblxii = new JLabel("Class XII (%)");
lblxii.setBounds(50, 350, 200, 30);
lblxii.setFont(new Font("serif", Font.BOLD, 20));
add(lblxii);
JLabel labelxii = new JLabel();
labelxii.setBounds(200, 350, 150, 30);
labelxii.setFont(new Font("Tahoma", Font.PLAIN, 18));
add(labelxii);
JLabel lblaadhar = new JLabel("CNIC Number");
lblaadhar.setBounds(400, 350, 200, 30);
lblaadhar.setFont(new Font("serif", Font.BOLD, 20));
add(lblaadhar);
JLabel labelaadhar = new JLabel();
labelaadhar.setBounds(600, 350, 150, 30);
labelaadhar.setFont(new Font("Tahoma", Font.PLAIN, 18));
add(labelaadhar);
JLabel lblcourse = new JLabel("Education");
lblcourse.setBounds(50, 400, 200, 30);
lblcourse.setFont(new Font("serif", Font.BOLD, 20));
add(lblcourse);
tfcourse = new JTextField();
tfcourse.setBounds(200, 400, 150, 30);
add(tfcourse);
JLabel lblbranch = new JLabel("Department");
lblbranch.setBounds(400, 400, 200, 30);
lblbranch.setFont(new Font("serif", Font.BOLD, 20));
add(lblbranch);
tfbranch = new JTextField();
tfbranch.setBounds(600, 400, 150, 30);
add(tfbranch);
try {
Conn c = new Conn();
String query = "select * from teacher where empId='"+cEmpId.getSelectedItem()+"'";
ResultSet rs = c.s.executeQuery(query);
while(rs.next()) {
labelname.setText(rs.getString("name"));
labelfname.setText(rs.getString("fname"));
labeldob.setText(rs.getString("dob"));
tfaddress.setText(rs.getString("address"));
tfphone.setText(rs.getString("phone"));
tfemail.setText(rs.getString("email"));
labelx.setText(rs.getString("class_x"));
labelxii.setText(rs.getString("class_xii"));
labelaadhar.setText(rs.getString("cnic"));
labelEmpId.setText(rs.getString("empId"));
tfcourse.setText(rs.getString("education"));
tfbranch.setText(rs.getString("department"));
}
} catch (Exception e) {
e.printStackTrace();
}
cEmpId.addItemListener(new ItemListener() {
public void itemStateChanged(ItemEvent ie) {
try {
Conn c = new Conn();
String query = "select * from teacher where empId='"+cEmpId.getSelectedItem()+"'";
ResultSet rs = c.s.executeQuery(query);
while(rs.next()) {
labelname.setText(rs.getString("name"));
labelfname.setText(rs.getString("fname"));
labeldob.setText(rs.getString("dob"));
tfaddress.setText(rs.getString("address"));
tfphone.setText(rs.getString("phone"));
tfemail.setText(rs.getString("email"));
labelx.setText(rs.getString("class_x"));
labelxii.setText(rs.getString("class_xii"));
labelaadhar.setText(rs.getString("cnic"));
labelEmpId.setText(rs.getString("empId"));
tfcourse.setText(rs.getString("education"));
tfbranch.setText(rs.getString("department"));
}
} catch (Exception e) {
e.printStackTrace();
}
}
});
submit = new JButton("Update");
submit.setBounds(250, 500, 120, 30);
submit.setBackground(Color.BLACK);
submit.setForeground(Color.WHITE);
submit.addActionListener(this);
submit.setFont(new Font("Tahoma", Font.BOLD, 15));
add(submit);
cancel = new JButton("Cancel");
cancel.setBounds(450, 500, 120, 30);
cancel.setBackground(Color.BLACK);
cancel.setForeground(Color.WHITE);
cancel.addActionListener(this);
cancel.setFont(new Font("Tahoma", Font.BOLD, 15));
add(cancel);
setVisible(true);
}
public void actionPerformed(ActionEvent ae) {
if (ae.getSource() == submit) {
String empId = labelEmpId.getText();
String address = tfaddress.getText();
String phone = tfphone.getText();
String email = tfemail.getText();
String course = tfcourse.getText();
String branch = tfbranch.getText();
try {
String query = "update teacher set address='"+address+"', phone='"+phone+"', email='"+email+"', education='"+course+"', department='"+branch+"' where empId='"+empId+"'";
Conn con = new Conn();
con.s.executeUpdate(query);
JOptionPane.showMessageDialog(null, "Student Details Updated Successfully");
setVisible(false);
} catch (Exception e) {
e.printStackTrace();
}
} else {
setVisible(false);
}
}
public static void main(String[] args) {
new UpdateTeacher();
}
}