Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add some functionalities to stadistics report #76

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions final-progII/src/logic/ControllerLogic.java
Original file line number Diff line number Diff line change
Expand Up @@ -510,5 +510,46 @@ public List<Functionary> functionariesList() throws Exception {
public User getUserLoggedIn() {
return this.userLoggedIn;
}


//This must be implemented later
public Subject subjectWithMoreAbsences(Orientation orientation) throws Exception {

List<Subject> subjectsByOrientation = null;


try {
subjectsByOrientation = this.db.recoverSubjects(orientation);
} catch (Exception ex) {
throw new Exception(errorMessage);
}

for(Subject subject : subjectsByOrientation) {
}

return null;
}

public int getAbsencesIndex() throws Exception {
int amountOfAbsences = 0;
int amountOfStudents = 0;
int absencesIndex= 0;

try {
amountOfAbsences = this.db.recoverAmountOfAbsences();
} catch(Exception ex) {
throw new Exception(errorMessage);
}

try {
amountOfStudents = this.db.recoverAmountOfStudents();
} catch (Exception ex) {
throw new Exception(errorMessage);
}

absencesIndex = amountOfAbsences / amountOfStudents;

return absencesIndex;
}

}
116 changes: 105 additions & 11 deletions final-progII/src/persistence/ControllerDB.java
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ public void toPersistIntoTeaches(Subject subject, Teacher teacher) throws Except
}

}

public void toPersistIntoTakes(Subject subject, Student student, int mark) throws Exception {
try {
System.out.println("Creting a connection object");
Expand All @@ -195,7 +195,6 @@ public void toPersistIntoTakes(Subject subject, Student student, int mark) throw
takesSt.setString(1, subject.getCode());
takesSt.setInt(2, student.getCi());
takesSt.setInt(3, mark);


System.out.println("Execut Update");

Expand Down Expand Up @@ -436,11 +435,10 @@ public Subject recoverSubject(String code) throws Exception {
return subject;

}


public void updateUser(int ci, User user) throws Exception{

public void updateUser(int ci, User user) throws Exception {
try {

System.out.println("Creating a connection for a updateUser method");
this.MySQLconnection();

Expand All @@ -449,7 +447,7 @@ public void updateUser(int ci, User user) throws Exception{
PreparedStatement userSt = this.conn.prepareStatement(
"UPDATE User SET NAME = ?, LASTNAME = ?, BIRTH = ?, MAIL = ?, PASSWORD =? WHERE CI = ?");

userSt.setString(1, user.getName());
userSt.setString(1, user.getName());
userSt.setString(2, user.getLastName());
userSt.setDate(3, java.sql.Date.valueOf(user.getDateBirth()));
userSt.setString(4, user.getMail());
Expand Down Expand Up @@ -608,7 +606,7 @@ public List<Subject> recoverSubjects() throws Exception {

while (subjectRs.next()) {
Teacher teacher = null;

PreparedStatement teachesSt = this.conn.prepareStatement("SELECT * FROM teaches WHERE IDSUBJECT = ?");

teachesSt.setString(1, subjectRs.getString("IDSUBJECT"));
Expand All @@ -635,9 +633,54 @@ public List<Subject> recoverSubjects() throws Exception {
return subjects;

}

//this method must be tested in database environment
public Map<Integer,String> recoverTakes() throws Exception{

public List<Subject> recoverSubjects(Orientation orientation) throws Exception {
List<Subject> subjects = new ArrayList<Subject>();

try {
System.out.println("Creating a Connection Object.");
this.MySQLconnection();

System.out.println("Creating PreparedStatement");
PreparedStatement subjectSt = this.conn.prepareStatement("SELECT * FROM Subject WHERE ORIENTATION = ?");

subjectSt.setString(1, orientation.toString());

System.out.println("Executing Query and creating ResultSet.");
ResultSet subjectRs = subjectSt.executeQuery();

while (subjectRs.next()) {
Teacher teacher = null;

PreparedStatement teachesSt = this.conn.prepareStatement("SELECT * FROM teaches WHERE IDSUBJECT = ?");

teachesSt.setString(1, subjectRs.getString("IDSUBJECT"));

System.out.println("Executing Query and creating ResultSet for the Recover Teaches");
ResultSet teachesRs = teachesSt.executeQuery();

while (teachesRs.next()) {
System.out.println("Database IDTEACHER");
teacher = new Teacher(teachesRs.getInt("CITEACHER"));
}

System.out.println("Database User student ");
Subject subject = new Subject(subjectRs.getString(1), subjectRs.getString(2),
Orientation.valueOf(subjectRs.getString(3)), Generation.valueOf(subjectRs.getString(4)),
teacher);
subjects.add(subject);
}

} catch (Exception ex) {
throw ex;
}

return subjects;

}

// this method must be tested in database environment
public Map<Integer, String> recoverTakes() throws Exception {
Map<Integer, String> studentCIandSubjectCode = new HashMap<Integer, String>();

try {
Expand Down Expand Up @@ -716,4 +759,55 @@ public List<Absence> recoverAbsences() throws Exception {

return absences;
}


public int recoverAmountOfAbsences() throws Exception {
int amountOfAbsences= 0;

try {

System.out.println("Creating a Connection Object.");
this.MySQLconnection();

System.out.println("Creating PreparedStatement");
PreparedStatement absenceSt = this.conn.prepareStatement("SELECT COUNT(IDABSENCE) FROM Absence");

System.out.println("Executing Query and creating ResultSet.");
ResultSet absenceRs = absenceSt.executeQuery();

while (absenceRs.next()) {
amountOfAbsences = absenceRs.getInt(1);
}

} catch (Exception ex) {
throw ex;
}

return amountOfAbsences;
}

public int recoverAmountOfStudents() throws Exception {
int amountOfStudents= 0;

try {

System.out.println("Creating a Connection Object.");
this.MySQLconnection();

System.out.println("Creating PreparedStatement");
PreparedStatement absenceSt = this.conn.prepareStatement("SELECT COUNT(CIUSER) FROM Student");

System.out.println("Executing Query and creating ResultSet.");
ResultSet absenceRs = absenceSt.executeQuery();

while (absenceRs.next()) {
amountOfStudents = absenceRs.getInt(1);
}

} catch (Exception ex) {
throw ex;
}

return amountOfStudents;
}
}
9 changes: 9 additions & 0 deletions final-progII/src/presentation/Menu.java
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,9 @@ public Menu(JPanel panel, JPanel master__panel, CardLayout master__cardLayout) {

JMenuItem listAbsence_menuItem = new JMenuItem("List Absences");
menu_Absence.add(listAbsence_menuItem);

JMenuItem stadisticsReport_menuItem = new JMenuItem("Stadistics Report");
menu_Absence.add(stadisticsReport_menuItem);

ControllerLogic c = new ControllerLogic();

Expand Down Expand Up @@ -154,5 +157,11 @@ public void actionPerformed(ActionEvent e) {
master__cardLayout.show(master__panel, "LIST_STUDENTS_PENDINGS");
}
});

stadisticsReport_menuItem.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
master__cardLayout.show(master__panel, "STADISTICS_REPORT_PANEL");
}
});
}
}
62 changes: 47 additions & 15 deletions final-progII/src/presentation/Screen.java
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,6 @@ public class Screen extends JFrame {
private JTextField textField_26;
private JTextField textField_27;
private JTextField textField_28;
private JTable table_4;
private JTable table_5;
private JTextField subjectStudentExam__textField;
private JTextField noteStudentExam__textField;
private JTextField yearDateExam__textField;
Expand All @@ -126,7 +124,7 @@ public class Screen extends JFrame {
private JTextField textField_31;
private JTextField textField_32;
private JTextField textField_33;
private JTextField textField_34;
private JTextField idAbsenceToDelete__textField;
private JTextField dateMonthCreateFunctionary__textField;
private JTextField dateDayCreateFunctionary__textField;
private JTextField dateMonthCreateTeacher__textField;
Expand All @@ -138,6 +136,7 @@ public class Screen extends JFrame {
private JTextField monthStudent__textField;
private JTextField dayStudent__textField;
private JTable listStudentsPendings__table;

/**
* Launch the application.
*/
Expand Down Expand Up @@ -1198,10 +1197,10 @@ public void actionPerformed(ActionEvent arg0) {
lblNewLabel_53.setBounds(10, 11, 70, 14);
infoConsultAbsences__panel.add(lblNewLabel_53);

idtDelete__textField = new JTextField();
idtDelete__textField.setBounds(10, 260, 53, 20);
infoConsultAbsences__panel.add(idtDelete__textField);
idtDelete__textField.setColumns(10);
idAbsenceToDelete__textField = new JTextField();
idAbsenceToDelete__textField.setBounds(10, 260, 53, 20);
infoConsultAbsences__panel.add(idAbsenceToDelete__textField);
idAbsenceToDelete__textField.setColumns(10);

JLabel lblNewLabel_23 = new JLabel("ID Abscence");
lblNewLabel_23.setBounds(10, 240, 70, 14);
Expand Down Expand Up @@ -1359,9 +1358,9 @@ public void actionPerformed(ActionEvent e) {
master__panel.add(listStudentsPendings__panel, "name_120454282608500");
listStudentsPendings__panel.setLayout(null);

JLabel lblNewLabel_23 = new JLabel("Students with Pendings");
lblNewLabel_23.setBounds(358, 34, 112, 14);
listStudentsPendings__panel.add(lblNewLabel_23);
JLabel lblNewLabel_231 = new JLabel("Students with Pendings");
lblNewLabel_231.setBounds(358, 34, 112, 14);
listStudentsPendings__panel.add(lblNewLabel_231);

listStudentsPendings__table = new JTable();
try {
Expand All @@ -1383,6 +1382,40 @@ public void actionPerformed(ActionEvent e) {
listStudentsPendings__table.setBounds(168, 75, 523, 413);
listStudentsPendings__panel.add(listStudentsPendings__table);

JPanel stadisticsReport__panel = new JPanel();
master__panel.add(stadisticsReport__panel, "STADISTICS_REPORT_PANEL");
stadisticsReport__panel.setLayout(null);

JLabel lblNewLabel_54 = new JLabel("Stadistics Report");
lblNewLabel_54.setBounds(201, 5, 140, 14);
stadisticsReport__panel.add(lblNewLabel_54);

JLabel lblNewLabel_64 = new JLabel("Absences Index");
lblNewLabel_64.setBounds(110, 66, 140, 14);
stadisticsReport__panel.add(lblNewLabel_64);

JLabel absencesIndexReport__lblNewLabel = new JLabel("0");
absencesIndexReport__lblNewLabel.setBounds(235, 66, 46, 14);
stadisticsReport__panel.add(absencesIndexReport__lblNewLabel);

JButton getReportStadisticsReport__btn = new JButton("GET REPORT");
getReportStadisticsReport__btn.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
int absencesIndex = 0;

try {
absencesIndex = controller.getAbsencesIndex();
} catch (Exception ex) {
JOptionPane.showMessageDialog(null, ex.getMessage());
}

absencesIndexReport__lblNewLabel.setText(absencesIndex + "");

}
});
getReportStadisticsReport__btn.setBounds(235, 254, 181, 23);
stadisticsReport__panel.add(getReportStadisticsReport__btn);

btnNewButton_4.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {

Expand Down Expand Up @@ -1594,7 +1627,7 @@ public void actionPerformed(ActionEvent e) {
try {
controller.createUser(teacher);
} catch (Exception e1) {
JOptionPane.showMessageDialog(null, e1.getMessage() );
JOptionPane.showMessageDialog(null, e1.getMessage());
}
}
});
Expand Down Expand Up @@ -1829,10 +1862,10 @@ public void actionPerformed(ActionEvent e) {
deleteAbsence__btnNewButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {

int idAbsence = Integer.parseInt(idtDelete__textField.getText());
int idAbsence = Integer.parseInt(idAbsenceToDelete__textField.getText());

try {

Absence absence = new Absence(idAbsence);
controller.deleteAbsence(absence);

Expand All @@ -1845,5 +1878,4 @@ public void actionPerformed(ActionEvent arg0) {
});

}
}
}}
}