Skip to content

Commit

Permalink
made updates to ui
Browse files Browse the repository at this point in the history
  • Loading branch information
saaya-code committed Mar 26, 2024
1 parent 7d93793 commit a6a89ca
Show file tree
Hide file tree
Showing 6 changed files with 66 additions and 19 deletions.
4 changes: 0 additions & 4 deletions src/ExercicesTP/CRUD/DemandeDAO.java

This file was deleted.

36 changes: 36 additions & 0 deletions src/ExercicesTP/CRUD/EtudiantDAO.java
Original file line number Diff line number Diff line change
Expand Up @@ -112,4 +112,40 @@ private int getRowCount(ResultSet rs) {
throw new RuntimeException(e);
}
}

public Object[] fetchFormationData(int idFormation, int idEtudiant){
PreparedStatement ps = null;
try {
ps = con.prepareStatement("SELECT f.titre, f.lieu, f.datef FROM formation f,Etudiant e,demandeetd d WHERE f.IdF=d.IdFormation and e.id=d.IdEtudiant and f.IdF = ? and e.id = ?");
ps.setInt(1, idFormation);
ps.setInt(2, idEtudiant);
ResultSet rs = ps.executeQuery();
if (rs.next()) {
return new Object[]{rs.getString(2), rs.getDate(3), rs.getString(4)};
}
} catch (SQLException e) {
return null;
}
return null;
}

public void insertDemande(int idFormation, int idEtudiant){
PreparedStatement ps = null;
try {
ps = con.prepareStatement("INSERT INTO demandeetd (IdFormation, IdEtudiant) VALUES (?,?)");
ps.setInt(1, idFormation);
ps.setInt(2, idEtudiant);
ps.executeUpdate();
} catch (SQLException e) {
throw new RuntimeException(e);
}
}

public ResultSet selection(String rq){
try {
return st.executeQuery(rq);
} catch (SQLException e) {
return null;
}
}
}
3 changes: 3 additions & 0 deletions src/ExercicesTP/CRUD/FormationDAO.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ public void deleteFormation(int id) {
}
}




public ResultSet selection(String req){
try{
PreparedStatement ps = con.prepareStatement(req);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package ExercicesTP.Helpers;

import ExercicesTP.CRUD.EtudiantDAO;

import ExercicesTP.Etudiant;

import javax.swing.*;
import javax.swing.table.AbstractTableModel;
Expand All @@ -11,12 +11,13 @@
import java.sql.SQLException;
import java.util.ArrayList;

public class TableModelDemande extends AbstractTableModel {

public class TableModelEtudiant extends AbstractTableModel {
ArrayList<Object[]> data;
ResultSetMetaData rsmd;
EtudiantDAO dao;

public TableModelDemande(ResultSet rs, EtudiantDAO dao){
public TableModelEtudiant(ResultSet rs, EtudiantDAO dao){
data = new ArrayList<Object[]>();
this.dao = dao;
try {
Expand All @@ -41,6 +42,7 @@ public TableModelDemande(ResultSet rs, EtudiantDAO dao){

}


public void updateTableWithNewResultSet(ResultSet rs){
data = new ArrayList<Object[]>();
try {
Expand Down Expand Up @@ -112,9 +114,10 @@ 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});
public void insertDemande(int idFormation, int idEtudiant){
this.dao.insertDemande(idFormation, idEtudiant);
Object[] ligne = this.dao.fetchFormationData(idFormation, idEtudiant);
data.add(ligne);
fireTableDataChanged();
JOptionPane.showMessageDialog(null, "done");
}
Expand All @@ -127,8 +130,7 @@ public void supprimerFormation(int id){
JOptionPane.showMessageDialog(null, "annulé");
return;
}

this.dao.deleteFormation(id);
this.dao.deleteEtudiant(id);
for(int i = 0; i < data.size(); i++){
if((int)data.get(i)[colmunNameToIndex("id")] == id){
data.remove(i);
Expand Down
1 change: 1 addition & 0 deletions src/ExercicesTP/Helpers/TableModelFormation.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package ExercicesTP.Helpers;

import ExercicesTP.CRUD.EtudiantDAO;
import ExercicesTP.CRUD.FormationDAO;
import ExercicesTP.Formation;

Expand Down
23 changes: 16 additions & 7 deletions src/ExercicesTP/IHM/IHMRechercheEtudiant.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import java.awt.*;

import ExercicesTP.CRUD.EtudiantDAO;
import ExercicesTP.Helpers.TableModelEtudiant;
import ExercicesTP.Helpers.TableModelFormation;

public class IHMRechercheEtudiant extends JInternalFrame {
Expand All @@ -13,16 +14,17 @@ public class IHMRechercheEtudiant extends JInternalFrame {
private JComboBox<String> filiereComboBox,demandesBox;
private JComboBox<Integer> niveauComboBox, groupeComboBox;
private JButton ajouterDemandeButton, supprimerDemandeButton, rechercheButton, cancelButton, modifierButton, supprimerButton;
public EtudiantDAO etudiantDAO;
public TableModelFormation model;
public EtudiantDAO dao;
public TableModelEtudiant model;
JTable jt_Etudiant;

public IHMRechercheEtudiant(EtudiantDAO dao) {
super("Recherche d'une formation");

super("Recherche d'un etudiant");
this.dao = dao;
initializeComponents();
createLayout();
addEventListeners();
this.etudiantDAO = dao;
this.setVisible(true);
}

Expand Down Expand Up @@ -55,7 +57,7 @@ private void initializeComponents() {
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);
model = new TableModelEtudiant(dao.selection(rq), dao);
jt_Etudiant.setModel(model);

}
Expand Down Expand Up @@ -90,15 +92,17 @@ private void createLayout() {
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);
JScrollPane scrollPane = new JScrollPane(jt_Etudiant);

addComponent(panel, scrollPane, 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);
//rechercheButton.setEnabled(false);



Expand All @@ -121,6 +125,11 @@ private void clearInputs() {

private void addEventListeners() {
//TODO implement
rechercheButton.addActionListener(e -> {
String rq = "SELECT titre,lieu,datef FROM FORMATION f,demandeetd d,ETUDIANT e WHERE (e.id=d.idEtudiant) and (f.idF = d.idFormation) ;";
model.updateTableWithNewResultSet(dao.selection(rq));

});
}


Expand Down

0 comments on commit a6a89ca

Please sign in to comment.