Skip to content

Commit

Permalink
finished the add recherche etudiant interface
Browse files Browse the repository at this point in the history
  • Loading branch information
saaya-code committed Mar 25, 2024
1 parent 4a3a790 commit 7d93793
Show file tree
Hide file tree
Showing 9 changed files with 303 additions and 20 deletions.
2 changes: 2 additions & 0 deletions .idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions src/ExercicesTP/CRUD/DemandeDAO.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package ExercicesTP.CRUD;

public class DemandeDAO {
}
12 changes: 7 additions & 5 deletions src/ExercicesTP/CRUD/EtudiantDAO.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand All @@ -97,6 +98,7 @@ public Etudiant[] getAllEtudiants() {
return etudiants;
} catch (SQLException e) {
throw new RuntimeException(e);

}
}

Expand Down
8 changes: 3 additions & 5 deletions src/ExercicesTP/CRUD/FormationDAO.java
Original file line number Diff line number Diff line change
@@ -1,19 +1,17 @@
package ExercicesTP.CRUD;

import ExercicesTP.Formation;
import ExercicesTP.Config;
import TP_Base.MyConnexion;
import ExercicesTP.interfaces.FormationDaoCRUD;
import java.sql.*;

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);
}
Expand Down
142 changes: 142 additions & 0 deletions src/ExercicesTP/Helpers/TableModelDemande.java
Original file line number Diff line number Diff line change
@@ -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<Object[]> data;
ResultSetMetaData rsmd;
EtudiantDAO dao;

public TableModelDemande(ResultSet rs, EtudiantDAO dao){
data = new ArrayList<Object[]>();
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<rsmd.getColumnCount();i++){
ligne[i] = rs.getObject(i+1);
}
data.add(ligne);
}
}catch(SQLException SQLErr){
System.out.println("Error "+SQLErr);
}


}

public void updateTableWithNewResultSet(ResultSet rs){
data = new ArrayList<Object[]>();
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<rsmd.getColumnCount();i++){
ligne[i] = rs.getObject(i+1);
}
data.add(ligne);
}
}catch(SQLException SQLErr){
System.out.println("Error "+SQLErr);
}
fireTableDataChanged();
}


@Override
public int getRowCount() {
return data.size();
}

@Override
public int getColumnCount() {
try {
return rsmd.getColumnCount();
} catch (SQLException e) {
return 0;
}
}

@Override
public Object getValueAt(int rowIndex, int columnIndex) {
return data.get(rowIndex)[columnIndex];
}

@Override
public String getColumnName(int column) {
try {
return rsmd.getColumnName(column + 1);
} catch (SQLException e) {
return null;
}
}

@Override
public boolean isCellEditable(int rowIndex, int columnIndex) {
return false;
}
int colmunNameToIndex(String colmunName){
for (int i = 0; i < getColumnCount(); i++) {
if(getColumnName(i).equalsIgnoreCase(colmunName)){
return i;
}
}
return -1;
}
Boolean stringToBool(String str){
return str.equalsIgnoreCase("true");
}

@Override
public void setValueAt(Object aValue, int rowIndex, int columnIndex) {
}


public void insertFormation(String nom, String lieu, Date date){
this.dao.addEtudiant(new Formation(id, titre, dateF, lieu,certification));
data.add(new Object[]{id, titre, dateF, lieu, certification});
fireTableDataChanged();
JOptionPane.showMessageDialog(null, "done");
}



public void supprimerFormation(int id){
int option = JOptionPane.showConfirmDialog(null, "est ce que vous etes sure ?");
if(option == JOptionPane.NO_OPTION || option == JOptionPane.CANCEL_OPTION){
JOptionPane.showMessageDialog(null, "annulé");
return;
}

this.dao.deleteFormation(id);
for(int i = 0; i < data.size(); i++){
if((int)data.get(i)[colmunNameToIndex("id")] == id){
data.remove(i);
fireTableDataChanged();
JOptionPane.showMessageDialog(null, "done");
return;
}
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,13 @@
import java.sql.ResultSetMetaData;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Objects;

public class TableModel extends AbstractTableModel {
public class TableModelFormation extends AbstractTableModel {
ArrayList<Object[]> data;
ResultSetMetaData rsmd;
FormationDAO dao;

public TableModel(ResultSet rs, FormationDAO dao){
public TableModelFormation(ResultSet rs, FormationDAO dao){
data = new ArrayList<Object[]>();
this.dao = dao;
try {
Expand Down
6 changes: 3 additions & 3 deletions src/ExercicesTP/IHM/IHMAffichageFormation.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import javax.swing.*;
import ExercicesTP.CRUD.FormationDAO;
import ExercicesTP.Helpers.TableModel;
import ExercicesTP.Helpers.TableModelFormation;

import java.awt.*;

Expand All @@ -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;


Expand All @@ -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);


Expand Down
127 changes: 127 additions & 0 deletions src/ExercicesTP/IHM/IHMRechercheEtudiant.java
Original file line number Diff line number Diff line change
@@ -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<String> filiereComboBox,demandesBox;
private JComboBox<Integer> 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<String>();
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
}


}
Loading

0 comments on commit 7d93793

Please sign in to comment.