Skip to content

Commit

Permalink
added IHMAFFICHETEDUANT
Browse files Browse the repository at this point in the history
  • Loading branch information
saaya-code committed Apr 15, 2024
1 parent afaf384 commit d9425b0
Show file tree
Hide file tree
Showing 5 changed files with 119 additions and 0 deletions.
22 changes: 22 additions & 0 deletions src/ExercicesTP/CRUD/EtudiantDAO.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
6 changes: 6 additions & 0 deletions src/ExercicesTP/IHM/IHMAffichageFormation.java
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});
}

}
55 changes: 55 additions & 0 deletions src/ExercicesTP/IHM/IHMAfficheEtudiant.java
Original file line number Diff line number Diff line change
@@ -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();
});
}
}
29 changes: 29 additions & 0 deletions src/ExercicesTP/IHM/IHMRechercheEtudiant.java
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
7 changes: 7 additions & 0 deletions src/ExercicesTP/IHM/Principale.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
});



Expand Down

0 comments on commit d9425b0

Please sign in to comment.