From d9425b0df35cb425c98ab5f8aeb41c9f03293c71 Mon Sep 17 00:00:00 2001 From: saaya-code Date: Mon, 15 Apr 2024 16:12:23 +0100 Subject: [PATCH] added IHMAFFICHETEDUANT --- src/ExercicesTP/CRUD/EtudiantDAO.java | 22 ++++++++ .../IHM/IHMAffichageFormation.java | 6 ++ src/ExercicesTP/IHM/IHMAfficheEtudiant.java | 55 +++++++++++++++++++ src/ExercicesTP/IHM/IHMRechercheEtudiant.java | 29 ++++++++++ src/ExercicesTP/IHM/Principale.java | 7 +++ 5 files changed, 119 insertions(+) create mode 100644 src/ExercicesTP/IHM/IHMAfficheEtudiant.java diff --git a/src/ExercicesTP/CRUD/EtudiantDAO.java b/src/ExercicesTP/CRUD/EtudiantDAO.java index 5309c50..3032a6b 100644 --- a/src/ExercicesTP/CRUD/EtudiantDAO.java +++ b/src/ExercicesTP/CRUD/EtudiantDAO.java @@ -141,6 +141,28 @@ public void insertDemande(int idFormation, int idEtudiant){ } } + public int supprimeDemandePublic(int idEtudiant, String lieu, String titre){ + PreparedStatement ps = null; + try { + ps = con.prepareStatement("SELECT id FROM demandeetd WHERE IdEtudiant = ? and IdFormation in (SELECT IdF FROM formation WHERE lieu = ? and titre = ?)"); + ps.setInt(1, idEtudiant); + ps.setString(2, lieu); + ps.setString(3, titre); + ResultSet rs = ps.executeQuery(); + int result = 0; + if (rs.next()) { + int id = rs.getInt(1); + System.out.println("id : "+id); + ps = con.prepareStatement("DELETE FROM demandeetd WHERE id = ?"); + ps.setInt(1, id); + result = ps.executeUpdate(); + } + return result; + } catch (SQLException e) { + throw new RuntimeException(e); + } + } + public ResultSet selection(String rq){ try { return st.executeQuery(rq); diff --git a/src/ExercicesTP/IHM/IHMAffichageFormation.java b/src/ExercicesTP/IHM/IHMAffichageFormation.java index adbf760..9f22924 100644 --- a/src/ExercicesTP/IHM/IHMAffichageFormation.java +++ b/src/ExercicesTP/IHM/IHMAffichageFormation.java @@ -106,9 +106,15 @@ private void addEventListeners(){ if(!lieuTextField.getText().isEmpty()){ rq += "lieu = '"+lieuTextField.getText()+"' AND "; } + if(certificationCheckbox.isSelected()){ + rq += "certif = true AND "; + } rq = rq.substring(0, rq.length()-4); model.updateTableWithNewResultSet(formationDAO.selection(rq)); }); + cancelButton.addActionListener((e)->{ + dispose(); + }); } } diff --git a/src/ExercicesTP/IHM/IHMAfficheEtudiant.java b/src/ExercicesTP/IHM/IHMAfficheEtudiant.java new file mode 100644 index 0000000..c7c45d7 --- /dev/null +++ b/src/ExercicesTP/IHM/IHMAfficheEtudiant.java @@ -0,0 +1,55 @@ +package ExercicesTP.IHM; + +import ExercicesTP.CRUD.EtudiantDAO; +import ExercicesTP.Helpers.TableModelEtudiant; + +import javax.swing.*; +import java.awt.*; + +public class IHMAfficheEtudiant extends JInternalFrame { + EtudiantDAO dao; + JScrollPane jsp; + public TableModelEtudiant model; + JTable jt_Formation; + JButton exitButton; + JButton refreshButton; + + public IHMAfficheEtudiant(EtudiantDAO dao){ + this.dao = dao; + setTitle("Affichage des étudiants"); + setSize(400, 400); + initializeComponents(); + createLayout(); + addEventListeners(); + setVisible(true); + } + void initializeComponents(){ + jt_Formation = new JTable(); + jsp = new JScrollPane(jt_Formation); + String rq = "SELECT * FROM Etudiant;"; + model = new TableModelEtudiant(dao.selection(rq), this.dao); + jt_Formation.setModel(model); + refreshButton = new JButton("Rafrachir"); + exitButton = new JButton("Exit"); + + } + void createLayout(){ + + this.add(jsp, BorderLayout.CENTER); + JPanel pane = new JPanel(); + pane.add(refreshButton); + pane.add(exitButton); + this.add(pane,BorderLayout.SOUTH); + + } + void addEventListeners(){ + refreshButton.addActionListener(e->{ + String rq = "SELECT * FROM ETUDIANT"; + model.updateTableWithNewResultSet(dao.selection(rq)); + JOptionPane.showMessageDialog(this, "Refresh avec success"); + }); + exitButton.addActionListener(e->{ + dispose(); + }); + } +} diff --git a/src/ExercicesTP/IHM/IHMRechercheEtudiant.java b/src/ExercicesTP/IHM/IHMRechercheEtudiant.java index 3bd3406..26ffd26 100644 --- a/src/ExercicesTP/IHM/IHMRechercheEtudiant.java +++ b/src/ExercicesTP/IHM/IHMRechercheEtudiant.java @@ -183,12 +183,41 @@ private void addEventListeners() { model.updateTableWithNewResultSet(dao.selection("SELECT titre,lieu,datef FROM FORMATION f,demandeetd d,ETUDIANT e WHERE (e.id=d.idEtudiant) and (f.idF = d.idFormation) and e.id = "+numEtdField.getText()+";")); JOptionPane.showMessageDialog(this, "Etudiant modifié"); }); + cancelButton.addActionListener(e -> dispose()); supprimerButton.addActionListener(e -> { dao.deleteEtudiant(Integer.parseInt(numEtdField.getText())); model.updateTableWithNewResultSet(dao.selection("SELECT titre,lieu,datef FROM FORMATION f,demandeetd d,ETUDIANT e WHERE 7=5;")); JOptionPane.showMessageDialog(this, "Etudiant supprimé"); clearInputs(); }); + supprimerDemandeButton.addActionListener(e -> { + // get the selected row + int row = jt_Etudiant.getSelectedRow(); + // get the selected formation + String titre = (String) model.getValueAt(row, 0); + int numEtud = Integer.parseInt(numEtdField.getText()); + String lieu = (String) model.getValueAt(row, 1); + System.out.println("Num etd : "+ numEtud + " titre : "+titre + " lieu : "+lieu); + System.out.println(dao.supprimeDemandePublic(numEtud,lieu,titre)); + model.updateTableWithNewResultSet(dao.selection("SELECT titre,lieu,datef FROM FORMATION f,demandeetd d,ETUDIANT e WHERE (e.id=d.idEtudiant) and (f.idF = d.idFormation) and e.id = "+numEtdField.getText()+";")); + JOptionPane.showMessageDialog(this, "Demande supprimée"); + }); + ajouterDemandeButton.addActionListener(e -> { + int numEtud = Integer.parseInt(numEtdField.getText()); + String titre = (String) demandesBox.getSelectedItem(); + String rq = "SELECT idF FROM FORMATION WHERE titre = '"+titre+"';"; + ResultSet rs = dao.selection(rq); + try { + if(rs.next()){ + int idF = rs.getInt(1); + dao.insertDemande(idF,numEtud); + model.updateTableWithNewResultSet(dao.selection("SELECT titre,lieu,datef FROM FORMATION f,demandeetd d,ETUDIANT e WHERE (e.id=d.idEtudiant) and (f.idF = d.idFormation) and e.id = "+numEtdField.getText()+";")); + JOptionPane.showMessageDialog(this, "Demande ajoutée"); + } + }catch (SQLException ex){ + ex.printStackTrace(); + } + }); numEtdField.addKeyListener(new java.awt.event.KeyAdapter() { public void keyReleased(java.awt.event.KeyEvent evt) { rechercheButton.setEnabled(!numEtdField.getText().isEmpty()); diff --git a/src/ExercicesTP/IHM/Principale.java b/src/ExercicesTP/IHM/Principale.java index acf2a2e..2e259df 100644 --- a/src/ExercicesTP/IHM/Principale.java +++ b/src/ExercicesTP/IHM/Principale.java @@ -117,6 +117,13 @@ public void actionPerformed(ActionEvent e) { desktop.add(ihmRechercheEtud); } }); + menuItemAfficherEtudiant.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + IHMAfficheEtudiant ihmRechercheEtud = new IHMAfficheEtudiant(etudiantDAO); + desktop.add(ihmRechercheEtud); + } + });