From 7d9379343b8e53f97bbcfb9d7df92a1e3e845d10 Mon Sep 17 00:00:00 2001 From: saaya-code Date: Mon, 25 Mar 2024 15:31:01 +0100 Subject: [PATCH] finished the add recherche etudiant interface --- .idea/.gitignore | 2 + src/ExercicesTP/CRUD/DemandeDAO.java | 4 + src/ExercicesTP/CRUD/EtudiantDAO.java | 12 +- src/ExercicesTP/CRUD/FormationDAO.java | 8 +- .../Helpers/TableModelDemande.java | 142 ++++++++++++++++++ ...bleModel.java => TableModelFormation.java} | 5 +- .../IHM/IHMAffichageFormation.java | 6 +- src/ExercicesTP/IHM/IHMRechercheEtudiant.java | 127 ++++++++++++++++ src/ExercicesTP/IHM/Principale.java | 17 ++- 9 files changed, 303 insertions(+), 20 deletions(-) create mode 100644 src/ExercicesTP/CRUD/DemandeDAO.java create mode 100644 src/ExercicesTP/Helpers/TableModelDemande.java rename src/ExercicesTP/Helpers/{TableModel.java => TableModelFormation.java} (96%) create mode 100644 src/ExercicesTP/IHM/IHMRechercheEtudiant.java diff --git a/.idea/.gitignore b/.idea/.gitignore index 13566b8..a9d7db9 100644 --- a/.idea/.gitignore +++ b/.idea/.gitignore @@ -6,3 +6,5 @@ # Datasource local storage ignored files /dataSources/ /dataSources.local.xml +# GitHub Copilot persisted chat sessions +/copilot/chatSessions diff --git a/src/ExercicesTP/CRUD/DemandeDAO.java b/src/ExercicesTP/CRUD/DemandeDAO.java new file mode 100644 index 0000000..7c4b342 --- /dev/null +++ b/src/ExercicesTP/CRUD/DemandeDAO.java @@ -0,0 +1,4 @@ +package ExercicesTP.CRUD; + +public class DemandeDAO { +} diff --git a/src/ExercicesTP/CRUD/EtudiantDAO.java b/src/ExercicesTP/CRUD/EtudiantDAO.java index 6805069..969934d 100644 --- a/src/ExercicesTP/CRUD/EtudiantDAO.java +++ b/src/ExercicesTP/CRUD/EtudiantDAO.java @@ -7,20 +7,21 @@ import java.sql.*; -// TODO: Test this class public class EtudiantDAO implements EtudiantDaoCRUD{ - Connection con = null; Statement st = null; - public EtudiantDAO() { - con = MyConnexion.getConnection(Config.URL, Config.USERNAME, Config.PASSWORD); + Connection con = null; + + public EtudiantDAO(Connection con) { try { st = con.createStatement(); + this.con = con; } catch (SQLException e) { throw new RuntimeException(e); } } + @Override public void addEtudiant(Etudiant etudiant) { PreparedStatement ps = null; @@ -76,7 +77,7 @@ public Etudiant getEtudiant(int id) { ResultSet rs = ps.executeQuery(); if (rs.next()) { return new Etudiant(rs.getInt("id"), rs.getString("nom"), rs.getString("prenom"), rs.getString("filiere"), rs.getInt("niveau"), rs.getInt("groupe")); - }else{ + } else { return null; } } catch (SQLException e) { @@ -97,6 +98,7 @@ public Etudiant[] getAllEtudiants() { return etudiants; } catch (SQLException e) { throw new RuntimeException(e); + } } diff --git a/src/ExercicesTP/CRUD/FormationDAO.java b/src/ExercicesTP/CRUD/FormationDAO.java index 02e746a..fd862f9 100644 --- a/src/ExercicesTP/CRUD/FormationDAO.java +++ b/src/ExercicesTP/CRUD/FormationDAO.java @@ -1,8 +1,6 @@ package ExercicesTP.CRUD; import ExercicesTP.Formation; -import ExercicesTP.Config; -import TP_Base.MyConnexion; import ExercicesTP.interfaces.FormationDaoCRUD; import java.sql.*; @@ -10,10 +8,10 @@ public class FormationDAO implements FormationDaoCRUD { Connection con = null; Statement st = null; - public FormationDAO() { - con = MyConnexion.getConnection(Config.URL, Config.USERNAME, Config.PASSWORD); + public FormationDAO(Connection con){ try { - st = con.createStatement(); + this.con = con; + st = con.createStatement(); } catch (SQLException e) { throw new RuntimeException(e); } diff --git a/src/ExercicesTP/Helpers/TableModelDemande.java b/src/ExercicesTP/Helpers/TableModelDemande.java new file mode 100644 index 0000000..e8249e4 --- /dev/null +++ b/src/ExercicesTP/Helpers/TableModelDemande.java @@ -0,0 +1,142 @@ +package ExercicesTP.Helpers; + +import ExercicesTP.CRUD.EtudiantDAO; + + +import javax.swing.*; +import javax.swing.table.AbstractTableModel; +import java.sql.Date; +import java.sql.ResultSet; +import java.sql.ResultSetMetaData; +import java.sql.SQLException; +import java.util.ArrayList; + +public class TableModelDemande extends AbstractTableModel { + ArrayList data; + ResultSetMetaData rsmd; + EtudiantDAO dao; + + public TableModelDemande(ResultSet rs, EtudiantDAO dao){ + data = new ArrayList(); + this.dao = dao; + try { + rsmd = rs.getMetaData(); + + } catch (SQLException e) { + throw new RuntimeException(e); + } + try { + + while (rs.next()) { + Object[] ligne = new Object[rsmd.getColumnCount()]; + for(int i = 0;i(); + try { + rsmd = rs.getMetaData(); + } catch (SQLException e) { + throw new RuntimeException(e); + } + try { + while (rs.next()) { + Object[] ligne = new Object[rsmd.getColumnCount()]; + for(int i = 0;i data; ResultSetMetaData rsmd; FormationDAO dao; - public TableModel(ResultSet rs, FormationDAO dao){ + public TableModelFormation(ResultSet rs, FormationDAO dao){ data = new ArrayList(); this.dao = dao; try { diff --git a/src/ExercicesTP/IHM/IHMAffichageFormation.java b/src/ExercicesTP/IHM/IHMAffichageFormation.java index d23f423..adbf760 100644 --- a/src/ExercicesTP/IHM/IHMAffichageFormation.java +++ b/src/ExercicesTP/IHM/IHMAffichageFormation.java @@ -2,7 +2,7 @@ import javax.swing.*; import ExercicesTP.CRUD.FormationDAO; -import ExercicesTP.Helpers.TableModel; +import ExercicesTP.Helpers.TableModelFormation; import java.awt.*; @@ -12,7 +12,7 @@ public class IHMAffichageFormation extends JInternalFrame { private JCheckBox certificationCheckbox; private JButton rechercheButton, cancelButton, modifierButton, supprimerButton; public FormationDAO formationDAO; - public TableModel model; + public TableModelFormation model; JTable jt_Formation; @@ -35,7 +35,7 @@ public void initilizeComponents() { jt_Formation = new JTable(); String rq = "SELECT * FROM FORMATION;"; - model = new TableModel(formationDAO.selection(rq), formationDAO); + model = new TableModelFormation(formationDAO.selection(rq), formationDAO); jt_Formation.setModel(model); diff --git a/src/ExercicesTP/IHM/IHMRechercheEtudiant.java b/src/ExercicesTP/IHM/IHMRechercheEtudiant.java new file mode 100644 index 0000000..56a8501 --- /dev/null +++ b/src/ExercicesTP/IHM/IHMRechercheEtudiant.java @@ -0,0 +1,127 @@ +package ExercicesTP.IHM; + +import javax.swing.*; +import java.awt.*; + +import ExercicesTP.CRUD.EtudiantDAO; +import ExercicesTP.Helpers.TableModelFormation; + +public class IHMRechercheEtudiant extends JInternalFrame { + + private JLabel numEtdLabel, nomLabel, prenomLabel, filiereLabel, niveauLabel, groupeLabel, listeDemandesLabel; + private JTextField numEtdField, nomField, prenomField ; + private JComboBox filiereComboBox,demandesBox; + private JComboBox niveauComboBox, groupeComboBox; + private JButton ajouterDemandeButton, supprimerDemandeButton, rechercheButton, cancelButton, modifierButton, supprimerButton; + public EtudiantDAO etudiantDAO; + public TableModelFormation model; + JTable jt_Etudiant; + + public IHMRechercheEtudiant(EtudiantDAO dao) { + super("Recherche d'une formation"); + initializeComponents(); + createLayout(); + addEventListeners(); + this.etudiantDAO = dao; + this.setVisible(true); + } + + private void initializeComponents() { + numEtdLabel = new JLabel("Numéro étudiant :"); + nomLabel = new JLabel("Nom :"); + prenomLabel = new JLabel("Prénom :"); + filiereLabel = new JLabel("Filière :"); + niveauLabel = new JLabel("Niveau :"); + groupeLabel = new JLabel("Groupe :"); + listeDemandesLabel = new JLabel("Liste des demandes :"); + + numEtdField = new JTextField(15); + nomField = new JTextField(20); + prenomField = new JTextField(20); + + // Sample data for comboboxes (replace with actual data source) + filiereComboBox = new JComboBox<>(new String[]{"FIA", "Licence Sc Info", "Licence Info de Gest", "Maths Info", "Physique Info", "Chimie Info", "Bio Info", "Eco Info", "Génie Info", "Info de Gestion", "Info de Comm"}); + niveauComboBox = new JComboBox<>(new Integer[]{1, 2, 3}); + groupeComboBox = new JComboBox<>(new Integer[]{1, 2, 3, 4, 5}); + + ajouterDemandeButton = new JButton("Ajouter demande"); + supprimerDemandeButton = new JButton("Supprimer demande"); + rechercheButton = new JButton("Rechercher"); + modifierButton = new JButton("Modifier"); + supprimerButton = new JButton("Supprimer"); + cancelButton = new JButton("Annuler"); + + demandesBox = new JComboBox(); + listeDemandesLabel = new JLabel("Liste des demandes :"); + jt_Etudiant = new JTable(); + String rq = "SELECT titre,lieu,datef FROM FORMATION f,demandeetd d,ETUDIANT e WHERE (e.id=d.idEtudiant) and (f.idF = d.idFormation) ;"; + model = new TableModelFormation(etudiantDAO.selection(rq), etudiantDAO); + jt_Etudiant.setModel(model); + + } + + private void createLayout() { + JPanel panel = new JPanel(new GridBagLayout()); + GridBagConstraints c = new GridBagConstraints(); + JPanel panel2 = new JPanel(new GridBagLayout()); + + // Add labels and corresponding components + c.fill = GridBagConstraints.HORIZONTAL; + addComponent(panel, numEtdLabel, c, 0, 0, 1, 1); + addComponent(panel, numEtdField, c, 1, 0, 2, 1); + addComponent(panel, nomLabel, c, 0, 1, 1, 1); + addComponent(panel, nomField, c, 1, 1, 2, 1); + addComponent(panel, prenomLabel, c, 0, 2, 1, 1); + addComponent(panel, prenomField, c, 1, 2, 2, 1); + addComponent(panel, filiereLabel, c, 0, 3, 1, 1); + addComponent(panel, filiereComboBox, c, 1, 3, 2, 1); + addComponent(panel, niveauLabel, c, 0, 4, 1, 1); + addComponent(panel, niveauComboBox, c, 1, 4, 1, 1); + addComponent(panel, groupeLabel, c, 0, 5, 1, 1); + addComponent(panel, groupeComboBox, c, 1, 5, 1, 1); + + addComponent(panel2, rechercheButton, c, 5, 0, 1, 1); + addComponent(panel2, modifierButton, c, 5, 1, 1, 1); + addComponent(panel2, supprimerButton, c, 5, 2, 1, 1); + addComponent(panel2, cancelButton, c, 5, 3, 1, 1); + + addComponent(panel, ajouterDemandeButton, c, 0, 7, 1, 1); + addComponent(panel, supprimerDemandeButton, c, 1, 7, 1, 1); + addComponent(panel, demandesBox, c, 2,7,1, 1); + + addComponent(panel, listeDemandesLabel, c, 0, 10, 1, 1); + addComponent(panel, jt_Etudiant, c, 2, 10, 6, 1); + + // Add buttons + getContentPane().add(panel); + getContentPane().add(panel2); + getContentPane().setLayout(new FlowLayout()); + modifierButton.setEnabled(false); + supprimerButton.setEnabled(false); + rechercheButton.setEnabled(false); + + + + setSize(700,400); + setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + setVisible(true); + } + + private void addComponent(JPanel panel, JComponent component, GridBagConstraints c, int x, int y, int width, int height) { + c.gridx = x; + c.gridy = y; + c.gridwidth = width; + c.gridheight = height; + panel.add(component, c); + } + + private void clearInputs() { + //TODO implement + } + + private void addEventListeners() { + //TODO implement + } + + +} diff --git a/src/ExercicesTP/IHM/Principale.java b/src/ExercicesTP/IHM/Principale.java index 36047bc..acf2a2e 100644 --- a/src/ExercicesTP/IHM/Principale.java +++ b/src/ExercicesTP/IHM/Principale.java @@ -3,7 +3,7 @@ import ExercicesTP.CRUD.EtudiantDAO; import ExercicesTP.CRUD.FormationDAO; import ExercicesTP.Etudiant; -import TP_Base.Config; +import ExercicesTP.Config; import TP_Base.MyConnexion; import javax.swing.*; @@ -32,6 +32,8 @@ public class Principale extends JFrame { JDesktopPane desktop; FormationDAO formationDao; EtudiantDAO etudiantDAO; + Connection con = null; + Principale() { menuBar = new JMenuBar(); this.setTitle("Gestion des formation"); @@ -40,7 +42,7 @@ public class Principale extends JFrame { desktop = new JDesktopPane(); this.add(desktop); - + con = MyConnexion.getConnection(Config.URL, Config.USERNAME, Config.PASSWORD); menuFormation = new JMenu("Formation"); menuEtudiant = new JMenu("Etudiant"); menuEnseignant = new JMenu("Enseignant"); @@ -75,8 +77,8 @@ public class Principale extends JFrame { menuBar.add(menuEnseignant); this.setJMenuBar(menuBar); this.setVisible(true); - formationDao = new FormationDAO(); - etudiantDAO = new EtudiantDAO(); + formationDao = new FormationDAO(con); + etudiantDAO = new EtudiantDAO(con); // listenners menuItemAjouteurFormation.addActionListener(new ActionListener() { @Override @@ -108,6 +110,13 @@ public void actionPerformed(ActionEvent e) { desktop.add(ihmAjoutEtud); } }); + menuItemRechercherEtudiant.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + IHMRechercheEtudiant ihmRechercheEtud = new IHMRechercheEtudiant(etudiantDAO); + desktop.add(ihmRechercheEtud); + } + });