diff --git a/final-progII/src/logic/ControllerLogic.java b/final-progII/src/logic/ControllerLogic.java index 76b8cd6..149fed3 100644 --- a/final-progII/src/logic/ControllerLogic.java +++ b/final-progII/src/logic/ControllerLogic.java @@ -510,5 +510,46 @@ public List functionariesList() throws Exception { public User getUserLoggedIn() { return this.userLoggedIn; } + + + //This must be implemented later + public Subject subjectWithMoreAbsences(Orientation orientation) throws Exception { + + List 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; + } } diff --git a/final-progII/src/persistence/ControllerDB.java b/final-progII/src/persistence/ControllerDB.java index d59e513..811717b 100644 --- a/final-progII/src/persistence/ControllerDB.java +++ b/final-progII/src/persistence/ControllerDB.java @@ -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"); @@ -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"); @@ -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(); @@ -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()); @@ -608,7 +606,7 @@ public List 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")); @@ -635,9 +633,54 @@ public List recoverSubjects() throws Exception { return subjects; } - - //this method must be tested in database environment - public Map recoverTakes() throws Exception{ + + public List recoverSubjects(Orientation orientation) throws Exception { + List subjects = new ArrayList(); + + 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 recoverTakes() throws Exception { Map studentCIandSubjectCode = new HashMap(); try { @@ -716,4 +759,55 @@ public List 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; + } } diff --git a/final-progII/src/presentation/Menu.java b/final-progII/src/presentation/Menu.java index a167c1c..8363270 100644 --- a/final-progII/src/presentation/Menu.java +++ b/final-progII/src/presentation/Menu.java @@ -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(); @@ -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"); + } + }); } } \ No newline at end of file diff --git a/final-progII/src/presentation/Screen.java b/final-progII/src/presentation/Screen.java index b7fcd4c..5ccf03a 100644 --- a/final-progII/src/presentation/Screen.java +++ b/final-progII/src/presentation/Screen.java @@ -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; @@ -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; @@ -138,6 +136,7 @@ public class Screen extends JFrame { private JTextField monthStudent__textField; private JTextField dayStudent__textField; private JTable listStudentsPendings__table; + /** * Launch the application. */ @@ -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); @@ -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 { @@ -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) { @@ -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()); } } }); @@ -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); @@ -1845,5 +1878,4 @@ public void actionPerformed(ActionEvent arg0) { }); } -} -}} +}