Repository navigation
Expand file tree
/
Copy pathLecturer.java
More file actions
454 lines (357 loc) · 15.5 KB
/
Copy pathLecturer.java
File metadata and controls
454 lines (357 loc) · 15.5 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
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
import java.awt.*;
import java.io.File;
import javax.swing.*;
import javax.swing.table.DefaultTableModel;
public class Lecturer extends User {
String[] module;
public Lecturer(String[] data, DBConnect x){
db = x;
id = Integer.parseInt(data[0]);
username = data[1];
ManagedBy = Integer.parseInt(data[4]);
email = data[5];
password = data[2];
firstName = data[6];
lastName = data[7];
gender = data[8];
dob = data[9];
userType = data[3];
module = db.read("SELECT Module_Id FROM Module WHERE Lecturer_Id = " + id + ";");
}
public String[] getModule(){
if(module.length == 0){
return null;
}
return module;
}
public void viewModule(){
ImageIcon image = new ImageIcon("logo.jpg");
JFrame frame = new JFrame();
frame.setTitle("Module");
frame.setIconImage(image.getImage());
frame.setResizable(false);
frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
frame.setSize(750,200);
if (module.length == 0) {
JOptionPane.showMessageDialog(null, "No modules found for this lecturer.", "Error", JOptionPane.ERROR_MESSAGE);
return;
}
String[][] rowData = new String[1][6];
String[] result = db.read("SELECT Module_Name, Course_Id, Module_Description, Semester, Credits FROM Module WHERE Module_Id = " + module[0] + ";");
rowData[0][0] = module[0];
rowData[0][1] = result[0];
rowData[0][2] = result[1];
rowData[0][3] = result[2];
rowData[0][4] = result[3];
rowData[0][5] = result[4];
String[] columnNames = {"Module Id", "Module Name", "Course Id", "Module Description", "Semester", "Credits"};
DefaultTableModel model = new DefaultTableModel(rowData, columnNames);
JTable table = new JTable(model);
JScrollPane scrollPane = new JScrollPane(table);
frame.add(scrollPane, BorderLayout.CENTER);
frame.setVisible(true);
}
public void updateModuleName(){
ImageIcon image = new ImageIcon("logo.jpg");
JFrame frame = new JFrame();
frame.setTitle("Update Name");
frame.setIconImage(image.getImage());
frame.setResizable(false);
frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
frame.setSize(400,400);
JPanel panel = new JPanel();
panel.setLayout(null);
panel.setVisible(true);
frame.setVisible(true);
JButton submit = new JButton();
submit.setText("Update");
submit.setBounds(140,200,120,50);
JLabel name = new JLabel("Module Name");
name.setBounds(50,10,300,30);
JTextField namef = new JTextField();
namef.setBounds(50,40,300,30);
panel.add(submit);
panel.add(name);
panel.add(namef);
frame.add(panel);
submit.addActionListener(e -> updateModuleName2(namef.getText()));
}
public void updateModuleName2(String name){
Driver d = new Driver();
boolean error = d.valid_length(name,"module name",30);
if (error) {
return;
} else {
db.write("UPDATE Module SET Module_Name = '" + name + "' WHERE Module_Id = " + module[0] + ";");
JOptionPane.showMessageDialog(null, "Module updated.", "Complete", JOptionPane.PLAIN_MESSAGE);
}
}
public void updateModuleDescription(){
ImageIcon image = new ImageIcon("logo.jpg");
JFrame frame = new JFrame();
frame.setTitle("Update Description");
frame.setIconImage(image.getImage());
frame.setResizable(false);
frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
frame.setSize(400,400);
JPanel panel = new JPanel();
panel.setLayout(null);
panel.setVisible(true);
frame.setVisible(true);
JButton submit = new JButton();
submit.setText("Update");
submit.setBounds(140,200,120,50);
JLabel description = new JLabel("Module Description");
description.setBounds(50,10,300,30);
JTextField descriptionf = new JTextField();
descriptionf.setBounds(50,40,300,30);
panel.add(submit);
panel.add(description);
panel.add(descriptionf);
frame.add(panel);
submit.addActionListener(e -> updateModuleDescription2(descriptionf.getText()));
}
public void updateModuleDescription2(String description){
Driver d = new Driver();
boolean error = d.valid_length(description,"module description",250);
if (error) {
return;
} else {
db.write("UPDATE Module SET Module_Description = '" + description + "' WHERE Module_Id = " + module[0] + ";");
JOptionPane.showMessageDialog(null, "Module updated.", "Complete", JOptionPane.PLAIN_MESSAGE);
}
}
public void updateModuleSemester(){
ImageIcon image = new ImageIcon("logo.jpg");
JFrame frame = new JFrame();
frame.setTitle("Update Semester");
frame.setIconImage(image.getImage());
frame.setResizable(false);
frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
frame.setSize(400,400);
JPanel panel = new JPanel();
panel.setLayout(null);
panel.setVisible(true);
frame.setVisible(true);
JButton submit = new JButton();
submit.setText("Update");
submit.setBounds(140,200,120,50);
JLabel semester = new JLabel("Module Semester");
semester.setBounds(50,10,300,30);
JRadioButton semester1B = new JRadioButton();
semester1B.setText("Semester 1");
semester1B.setBounds(50,40,100,30);
JRadioButton semester2B = new JRadioButton();
semester2B.setText("Semester 2");
semester2B.setBounds(150,40,100,30);
panel.add(submit);
panel.add(semester);
panel.add(semester1B);
panel.add(semester2B);
frame.add(panel);
ButtonGroup BG1 = new ButtonGroup();
BG1.add(semester1B);
BG1.add(semester2B);
submit.addActionListener(e -> updateModuleSemester2(semester1B, semester2B));
}
public void updateModuleSemester2(JRadioButton s1, JRadioButton s2){
int semester;
if (s1.isSelected()) {
semester = 1;
} else if (s2.isSelected()) {
semester = 2;
} else {
JOptionPane.showMessageDialog(null, "You haven't selected an option", "Error", JOptionPane.ERROR_MESSAGE);
return;
}
db.write("UPDATE Module SET Semester = '" + semester + "' WHERE Module_Id = " + module[0] + ";");
JOptionPane.showMessageDialog(null, "Module updated.", "Complete", JOptionPane.PLAIN_MESSAGE);
}
public void updateModuleCredits(){
ImageIcon image = new ImageIcon("logo.jpg");
JFrame frame = new JFrame();
frame.setTitle("Update Credits");
frame.setIconImage(image.getImage());
frame.setResizable(false);
frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
frame.setSize(400,400);
JPanel panel = new JPanel();
panel.setLayout(null);
panel.setVisible(true);
frame.setVisible(true);
JButton submit = new JButton();
submit.setText("Update");
submit.setBounds(140,200,120,50);
JLabel credits = new JLabel("Module Credits");
credits.setBounds(50,10,300,30);
JRadioButton credits10 = new JRadioButton();
credits10.setText("10 Credits");
credits10.setBounds(50,40,100,30);
JRadioButton credits20 = new JRadioButton();
credits20.setText("20 Credits");
credits20.setBounds(150,40,100,30);
panel.add(submit);
panel.add(credits);
panel.add(credits10);
panel.add(credits20);
frame.add(panel);
ButtonGroup BG1 = new ButtonGroup();
BG1.add(credits10);
BG1.add(credits20);
submit.addActionListener(e -> updateModuleCredits2(credits10, credits20));
}
public void updateModuleCredits2(JRadioButton c10, JRadioButton c20){
int credits;
if (c10.isSelected()) {
credits = 10;
} else if (c20.isSelected()) {
credits = 20;
} else {
JOptionPane.showMessageDialog(null, "You haven't selected an option", "Error", JOptionPane.ERROR_MESSAGE);
return;
}
db.write("UPDATE Module SET Credits = '" + credits + "' WHERE Module_Id = " + module[0] + ";");
JOptionPane.showMessageDialog(null, "Module updated.", "Complete", JOptionPane.PLAIN_MESSAGE);
}
public void uploadNotes1(){
ImageIcon image = new ImageIcon("logo.jpg");
JFrame frame = new JFrame();
frame.setTitle("Update Name");
frame.setIconImage(image.getImage());
frame.setResizable(false);
frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
frame.setSize(400,500);
JPanel panel = new JPanel();
panel.setLayout(null);
panel.setVisible(true);
frame.setVisible(true);
JButton submit = new JButton();
submit.setText("Upload");
submit.setBounds(140,400,120,50);
JLabel description = new JLabel("Note Description");
description.setBounds(50,10,300,30);
JLabel data = new JLabel("Note Data");
data.setBounds(50,90,300,30);
JTextField descriptionf = new JTextField();
descriptionf.setBounds(50,40,300,30);
JTextField dataf = new JTextField();
dataf.setBounds(50,120,300,200);
panel.add(submit);
panel.add(description);
panel.add(data);
panel.add(descriptionf);
panel.add(dataf);
frame.add(panel);
submit.addActionListener(e -> uploadNotes2(descriptionf.getText(), data.getText()));
}
public void uploadNotes2(String desc, String content){
Driver d = new Driver();
boolean error = d.valid_length(desc,"module description",200);
if (error) {
return;
}
db.write("INSERT INTO Notes (Module_Id, Description, Data) VALUES (" + module[0] + ", '" + desc + "', '"+ content +"');");
JOptionPane.showMessageDialog(null, "Notes uploaded.", "Notes Uploaded", JOptionPane.PLAIN_MESSAGE);
}
public void viewStudents() {
ImageIcon image = new ImageIcon("logo.jpg");
JFrame frame = new JFrame();
frame.setTitle("Students in Module");
frame.setIconImage(image.getImage());
frame.setResizable(false);
frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
frame.setSize(750,400);
String[] result = db.read("SELECT Student_Id FROM Student_Module WHERE Module_Id = " + module[0] + ";");
String[][] rowData = new String[result.length][6];
for (int i = 0; i < result.length; i++) {
String[] result2 = db.read("SELECT First_Name, Surname FROM User WHERE User_Id = " + result[i] + ";");
String[] result3 = db.read("SELECT Exam_Mark, Lab_Mark, Decision FROM Student_Module WHERE Student_Id = " + result[i] + ";");
rowData[i][0] = result[i];
rowData[i][1] = result2[0];
rowData[i][2] = result2[1];
rowData[i][3] = result3[0];
rowData[i][4] = result3[1];
rowData[i][5] = result3[2];
}
String[] columnNames = {"Student Id", "First Name", "Surname", "Exam Mark", "Lab Mark", "Decision"};
DefaultTableModel model = new DefaultTableModel(rowData, columnNames);
JTable table = new JTable(model);
JScrollPane scrollPane = new JScrollPane(table);
frame.add(scrollPane, BorderLayout.CENTER);
frame.setVisible(true);
}
public void setMarks(){
ImageIcon image = new ImageIcon("logo.jpg");
JFrame frame = new JFrame();
frame.setTitle("Students in Module");
frame.setIconImage(image.getImage());
frame.setResizable(false);
frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
frame.setSize(400,500);
JPanel panel = new JPanel();
panel.setLayout(null);
panel.setVisible(true);
frame.setVisible(true);
JButton submit = new JButton();
submit.setText("Update");
submit.setBounds(140,300,120,50);
JLabel id = new JLabel("Student Id");
id.setBounds(50,10,300,30);
JLabel exam = new JLabel("Exam Mark");
exam.setBounds(50,90,300,30);
JLabel lab = new JLabel("Lab Mark");
lab.setBounds(50,180,300,30);
JTextField idf = new JTextField();
idf.setBounds(50,40,300,30);
JTextField examf = new JTextField();
examf.setBounds(50,120,300,30);
JTextField labf = new JTextField();
labf.setBounds(50,210,300,30);
panel.add(id);
panel.add(idf);
panel.add(exam);
panel.add(examf);
panel.add(lab);
panel.add(labf);
panel.add(submit);
frame.add(panel);
submit.addActionListener(e -> {
Integer studentId = Integer.parseInt(idf.getText());
Integer examMark = Integer.parseInt(examf.getText());
Integer labMark = Integer.parseInt(labf.getText());
try {
setExamMark(studentId, examMark, Integer.parseInt(module[0]));
setLabMark(studentId, labMark, Integer.parseInt(module[0]));
} catch (NumberFormatException ex) {
JOptionPane.showMessageDialog(null, "Please enter valid numeric values for id and mark", "Invalid Input", JOptionPane.ERROR_MESSAGE);
}
});
}
//ALL methods pertaining to marks will need to be adjusted for Lab and Exam marks.
public void setExamMark(Integer student, Integer mark, Integer module){
String[] exists = db.read("SELECT Student_Id FROM Student_Module WHERE Student_Id = " + student + " AND Module_Id = " + module + ";");
if(exists.length == 0) {
JOptionPane.showMessageDialog(null, "That student is not in your module", "Error", JOptionPane.ERROR_MESSAGE);
return;
}
if (mark > 100 || mark < 0){
JOptionPane.showMessageDialog(null, "That mark is invalid", "Invalid Input", JOptionPane.ERROR_MESSAGE);
return;
}
db.write("UPDATE Student_Module SET Exam_Mark = " + mark + " WHERE Student_Id = " + student + " AND Module_Id = " + module + ";");
JOptionPane.showMessageDialog(null, "Student '"+student+"' has been given a '"+mark+"' for the module '"+module+"' exam.", "Mark Assigned", JOptionPane.PLAIN_MESSAGE);
}
public void setLabMark(Integer student, Integer mark, Integer module){
String[] exists = db.read("SELECT Student_Id FROM Student_Module WHERE Student_Id = " + student + " AND Module_Id = " + module + ";");
if(exists.length == 0) {
JOptionPane.showMessageDialog(null, "That student is not in your module", "Error", JOptionPane.ERROR_MESSAGE);
return;
}
if (mark > 100 || mark < 0){
JOptionPane.showMessageDialog(null, "That mark is invalid", "Invalid Input", JOptionPane.ERROR_MESSAGE);
return;
}
db.write("UPDATE Student_Module SET Lab_Mark = " + mark + " WHERE Student_Id = " + student + " AND Module_Id = " + module + ";");
JOptionPane.showMessageDialog(null, "Student '"+student+"' has been given a '"+mark+"' for the module '"+module+"' lab.", "Mark Assigned", JOptionPane.PLAIN_MESSAGE);
}
}