-
Notifications
You must be signed in to change notification settings - Fork 3
/
StudentPageController.java
133 lines (116 loc) · 5.13 KB
/
StudentPageController.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 sample;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.control.*;
import javafx.scene.control.cell.PropertyValueFactory;
import javafx.stage.Stage;
import java.io.IOException;
import java.sql.*;
public class StudentPageController {
//creating required objects
public TableView<Subject> Table = new TableView<Subject>();
public Label display;
public TableColumn<Subject, String> subjectcol;
public TableColumn<Subject, Integer> presentcol;
public TableColumn<Subject, Integer> latecol;
public TableColumn<Subject, Integer> excusedcol;
public TableColumn<Subject, Integer> unexcusedcol;
public TableColumn<Subject, String> monthcol;
String studrno;
@FXML
Label TitleLabel;
@FXML
ChoiceBox<String> subject = new ChoiceBox<String>();
@FXML
ChoiceBox<String> month = new ChoiceBox<String>();
Stage dialogStage = new Stage();
Scene scene;
ObservableList<Subject> list = FXCollections.observableArrayList();
//default constructor
public StudentPageController() throws SQLException {
}
//function executed when display record button is clicked.
public void DisplayRecords(ActionEvent actionEvent) {
String sub = "";
String mon = "";
//stores value selected from the combo box by a student
sub = subject.getValue();
mon = month.getValue();
String subjectname = setsubjectname(sub);
//create table for each subject chosen
String tablename = sub;
//sql commands to read required details from database
try {
Connection con = DriverManager.getConnection("jdbc:mysql://localhost/login", "root", "Mridula56");
Statement s = con.createStatement();
String getrec = "Select * from " + tablename + " where month = '" + mon + "' and rno='" + studrno + "'";
ResultSet rs = s.executeQuery(getrec);
while (rs.next()) {
if (rs.getString(2).equals(studrno)) ; //check whether given roll number exists(is in database)
{
Subject o = new Subject(subjectname, mon, rs.getInt(2), rs.getInt(3), rs.getInt(4), rs.getInt(5));
list.add(o); //adds the details of a particukar student as rows in the table displayed
}
}
try { //set properties to cells of each column of the table
monthcol.setCellValueFactory(new PropertyValueFactory<>("Monthname"));
subjectcol.setCellValueFactory(new PropertyValueFactory<>("Subname"));
presentcol.setCellValueFactory(new PropertyValueFactory<>("Present"));
latecol.setCellValueFactory(new PropertyValueFactory<>("Late"));
excusedcol.setCellValueFactory(new PropertyValueFactory<>("Excused"));
unexcusedcol.setCellValueFactory(new PropertyValueFactory<>("Unexcused"));
Table.setItems(list);
rs.close();
}catch (Exception e){ //to catch if any exception occurs
e.printStackTrace();
}
} //to catch if any SQL error is thrown
catch (SQLException throwables) {
throwables.printStackTrace();
}
}
//a function to return subject name correspoding to subject code chosen
public String setsubjectname(String sname){
String sn = new String();
if (sname.equals("19Z301")) {
sn = "Linear Algebra";
} else if (sname.equals("19Z302")) {
sn = "Data Structures";
} else if (sname.equals("19Z303")) {
sn = "Computer Architecture";
} else if (sname.equals("19Z304")) {
sn = "Discrete Structures";
} else if (sname.equals("19Z305")) {
sn = "Object Oriented Programming";
} else if (sname.equals("19Z306")) {
sn = "Economics for Engineers";
} else if (sname.equals("19Z310")) {
sn = "Data Structures Lab";
} else if (sname.equals("19Z311")) {
sn = "OOP Lab";
} else if (sname.equals("19K312")) {
sn = "Environmental Studies";
}
return sn;
}
//to set label for the frame.Ladel is the students roll number
public void setLabelText(String rollnum) {
studrno = rollnum;
TitleLabel.setText(rollnum + " Attendance Viewer");
}
//log out function to redirect back to role select frame
public void logOut(ActionEvent event) throws IOException {
Stage dialogStage = new Stage();
Parent root = FXMLLoader.load(getClass().getResource("RoleSelect.fxml"));
((Stage) (((Button) event.getSource()).getScene().getWindow())).close();
Scene scene = new Scene(root);
dialogStage.setScene(scene);
dialogStage.setTitle("Attendance Management System: CSE-G2");
dialogStage.show();
}
}