-
Notifications
You must be signed in to change notification settings - Fork 100
Expand file tree
/
Copy pathUpdateTeacher.java
More file actions
286 lines (231 loc) · 9.2 KB
/
Copy pathUpdateTeacher.java
File metadata and controls
286 lines (231 loc) · 9.2 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
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
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
import javax.swing.*;
import java.awt.*;
import java.sql.ResultSet;
import java.awt.event.*;
public class UpdateTeacher extends JFrame implements ActionListener{
JTextField addresst,phonet,emailt,tfcource,tfbranch;
JLabel labelempid;
JButton submit,cancel;
Choice cempid;
UpdateTeacher(){
setBounds(120,10,900,600);
setLocation(350,50);
setBackground(Color.WHITE);
setLayout(null);
//heading
JLabel heading = new JLabel("Update Teacher Details");
heading.setBounds(50,10,500,50);
heading.setFont(new Font("Tahoma",Font.ITALIC,35));
add(heading);
// search by roll number
JLabel lblrollnum = new JLabel("Select By Employee Id");
lblrollnum.setBounds(50,100,200,20);
lblrollnum.setFont(new Font("serif",Font.PLAIN,20));
add(lblrollnum);
cempid= new Choice();
cempid.setBounds(250,100,200,20);
add(cempid);
//take the roll number from Mysql
try {
Conn c = new Conn();
ResultSet rs = c.s.executeQuery("select * from teacher");
while (rs.next()){
cempid.add(rs.getString("emploidg"));
}
}catch (Exception e){
e.printStackTrace();
}
//name label
JLabel name = new JLabel("Name");
name.setBounds(50,150,100,30);
name.setFont(new Font("serif",Font.BOLD,20));
add(name);
JLabel labelname =new JLabel();
labelname.setBounds(200,150,150,30);
labelname.setFont(new Font("serif",Font.PLAIN,18));
add(labelname);
// father name label
JLabel father_name = new JLabel("Father Name");
father_name.setBounds(400,150,200,30);
father_name.setFont(new Font("serif",Font.BOLD,20));
add(father_name);
JLabel labelfather =new JLabel();
labelfather.setBounds(600,150,150,30);
labelfather.setFont(new Font("serif",Font.PLAIN,18));
add(labelfather);
// roll number label
JLabel rollNum = new JLabel("Employee Id");
rollNum.setBounds(50,200,200,30);
rollNum.setFont(new Font("serif",Font.BOLD,20));
add(rollNum);
labelempid = new JLabel();
labelempid.setBounds(200,200,200,30);
labelempid.setFont(new Font("serif",Font.PLAIN,18));
add(labelempid);
// Date Of Birth
JLabel DOB = new JLabel("Date Of Birth");
DOB.setBounds(400,200,200,30);
DOB.setFont(new Font("serif",Font.BOLD,20));
add(DOB);
JLabel labeldof = new JLabel();
labeldof.setBounds(600,200,150,30);
labeldof.setFont(new Font("serif",Font.PLAIN,18));
add(labeldof);
//Address label
JLabel address = new JLabel("Address");
address.setBounds(50,250,200,30);
address.setFont(new Font("serif",Font.BOLD,20));
add(address);
addresst=new JTextField();
addresst.setBounds(200,250,150,30);
add(addresst);
//Phone Number
JLabel phoneNum = new JLabel("Phone Number");
phoneNum.setBounds(400,250,200,30);
phoneNum.setFont(new Font("serif",Font.BOLD,20));
add(phoneNum);
phonet=new JTextField();
phonet.setBounds(600,250,150,30);
add(phonet);
//Adress Email
JLabel email_id = new JLabel("Email Id");
email_id.setBounds(50,300,200,30);
email_id.setFont(new Font("serif",Font.BOLD,20));
add(email_id);
emailt=new JTextField();
emailt.setBounds(200,300,150,30);
add(emailt);
//percentage
JLabel percen= new JLabel("Class X (%)");
percen.setBounds(400,300,200,30);
percen.setFont(new Font("serif",Font.BOLD,20));
add(percen);
JLabel xpercent=new JLabel();
xpercent.setBounds(600,300,150,30);
xpercent.setFont(new Font("serif",Font.PLAIN,18));
add(xpercent);
//percentage Xii
JLabel percenxii= new JLabel("Class Xii (%)");
percenxii.setBounds(50,350,200,30);
percenxii.setFont(new Font("serif",Font.BOLD,20));
add(percenxii);
JLabel xiipercen = new JLabel();
xiipercen.setBounds(200,350,150,30);
xiipercen.setFont(new Font("serif",Font.PLAIN,18));
add(xiipercen);
//NIC
JLabel nic= new JLabel("NIC");
nic.setBounds(400,350,200,30);
nic.setFont(new Font("serif",Font.BOLD,20));
add(nic);
JLabel labelnic = new JLabel();
labelnic.setBounds(600,350,150,30);
labelnic.setFont(new Font("serif",Font.PLAIN,18));
add(labelnic);
//Cource label
JLabel courcel= new JLabel("Education");
courcel.setBounds(50,400,200,30);
courcel.setFont(new Font("serif",Font.BOLD,20));
add(courcel);
tfcource= new JTextField();
tfcource.setBounds(200,400,150,30);
add(tfcource);
//Cource Branch
JLabel branchl= new JLabel("Department");
branchl.setBounds(400,400,200,30);
branchl.setFont(new Font("serif",Font.BOLD,20));
add(branchl);
tfbranch= new JTextField();
tfbranch.setBounds(600,400,150,30);
add(tfbranch);
try {
Conn c = new Conn();
String query = "select * from teacher where emploidg='"+cempid.getSelectedItem()+"'";
ResultSet rs = c.s.executeQuery(query);
while (rs.next()){
labelname.setText(rs.getString("nameg"));
labelfather.setText(rs.getString("fatherg"));
labeldof.setText(rs.getString("DoB"));
addresst.setText(rs.getString("addresg"));
phonet.setText(rs.getString("phone"));
emailt.setText(rs.getString("emailg"));
xpercent.setText(rs.getString("x"));
xiipercen.setText(rs.getString("xii"));
labelnic.setText(rs.getString("NIC"));
labelempid.setText(rs.getString("emploidg"));
tfcource.setText(rs.getString("educationg"));
tfbranch.setText(rs.getString("departmentg"));
}
}catch (Exception c){
c.printStackTrace();
}
cempid.addItemListener(new ItemListener() {
@Override
public void itemStateChanged(ItemEvent e) {
try {
Conn c = new Conn();
String query = "select * from teacher where emploidg='"+cempid.getSelectedItem()+"'";
ResultSet rs = c.s.executeQuery(query);
while (rs.next()){
labelname.setText(rs.getString("nameg"));
labelfather.setText(rs.getString("fatherg"));
labelempid.setText(rs.getString("emploidg"));
labeldof.setText(rs.getString("DoB"));
addresst.setText(rs.getString("addresg"));
phonet.setText(rs.getString("phoneg"));
emailt.setText(rs.getString("emailg"));
xpercent.setText(rs.getString("x"));
xiipercen.setText(rs.getString("xii"));
labelnic.setText(rs.getString("NIC"));
tfcource.setText(rs.getString("educationg"));
tfbranch.setText(rs.getString("departmentg"));
}
}catch (Exception c){
c.printStackTrace();
}
}
});
// submit button
submit = new JButton("Update");
submit.setBounds(250,495,120,30);
submit.setBackground(Color.BLACK);
submit.setForeground(Color.WHITE);
submit.addActionListener(this::actionPerformed);
submit.setFont(new Font("Tahoma",Font.BOLD,15));
add(submit);
// cancel button
cancel = new JButton("Cancel");
cancel.setBounds(450,495,120,30);
cancel.setBackground(Color.BLACK);
cancel.setForeground(Color.WHITE);
cancel.addActionListener(this::actionPerformed);
cancel.setFont(new Font("Tahoma",Font.BOLD,15));
add(cancel);
setVisible(true);
}
public void actionPerformed(ActionEvent ae){
if (ae.getSource()==submit){
String emploidg = labelempid.getText();
String addresg = addresst.getText();
String phoneg = phonet.getText();
String emailg = emailt.getText();
String educationg = tfcource.getText();
String departmentg = tfbranch.getText();
try {
String query = "update teacher set addresg='"+addresg+"',phoneg='"+phoneg+"',emailg='"+emailg+"',educationg='"+educationg+"',departmentg='"+departmentg+"'where emploidg='"+emploidg+"'";
Conn con = new Conn();
con.s.executeUpdate(query);
JOptionPane.showMessageDialog(null,"teacher details updated Successfully");
setVisible(false);
}
catch (Exception e){
e.printStackTrace();
}
}else{
setVisible(false);
}
}
public static void main(String[] args) {
new UpdateTeacher();
}
}