From 8f8cd80bbb175128df04bf35b72d3dd30e377fbc Mon Sep 17 00:00:00 2001 From: besson Date: Thu, 8 Dec 2022 21:46:45 +0100 Subject: [PATCH] a --- src/Test/Controller.java | 104 ++++++++++++++++++++++----------------- 1 file changed, 58 insertions(+), 46 deletions(-) diff --git a/src/Test/Controller.java b/src/Test/Controller.java index eb3d9c7..c7f6a47 100644 --- a/src/Test/Controller.java +++ b/src/Test/Controller.java @@ -293,7 +293,7 @@ public class Controller implements ActionListener, ListSelectionListener { "Action" }; - int i, j; + int i; for (i = 0; i <= this.e.size() - 1; i++) { if (this.e.get(i).getGroupe() == -1) { @@ -621,38 +621,42 @@ public class Controller implements ActionListener, ListSelectionListener { } else if (Objects.equals(command, "av::ShowRequestFromStudent")) { - this.r = this.db.getRequestList(); - - Object[][] data = new Object[this.r.size()][5]; - - String[] titre = { - "Etudiant", - "Groupe demande", - "Message", - "Type", - "Action" - }; - - for (int i = 0; i <= this.r.size() - 1; i++) { - if (this.r.get(i).getStatut().equals("Pas encore de reponse")) { - Object[] info = { - this.getEtuNameById(this.r.get(i).getEtuId()), - this.getGroupeById(this.r.get(i).getWitchGroupe()), - this.r.get(i).getMessage(), - this.r.get(i).getType(), - "[DECISION]" - }; - - data[i] = info; - } - } - - - - DisplayWithListner(this.createJTable(data, titre)); + showRequest(); } } + private void showRequest() { + this.r = this.db.getRequestList(); + ArrayList> data = new ArrayList<>(); + + String[] titre = { + "Id", + "Etudiant", + "Groupe demande", + "Message", + "Type", + "Action" + }; + + for (int i = 0; i <= this.r.size() - 1; i++) { + if (this.r.get(i).getStatut().equals("Pas encore de reponse")) { + ArrayList info = new ArrayList<>(); + info.add(this.r.get(i).getIdMessage() + ""); + info.add(this.getEtuNameById(this.r.get(i).getEtuId())); + info.add(this.getGroupeById(this.r.get(i).getWitchGroupe())); + info.add(this.r.get(i).getMessage()); + info.add(this.r.get(i).getType() + ""); + info.add("[DECISION]"); + + data.add(info); + } + } + + String[][] stringArray = data.stream().map(u -> u.toArray(new String[0])).toArray(String[][]::new); + + DisplayWithListner(this.createJTable(stringArray, titre)); + } + @Override public void valueChanged(ListSelectionEvent e) { if (!e.getValueIsAdjusting()) { @@ -698,28 +702,37 @@ public class Controller implements ActionListener, ListSelectionListener { private void makeDecision(TableModel tm, int[] cell) { int choice = JOptionPane.showConfirmDialog(this.parent, "Accepter la demande ?"); - int id = getIDGroupeByName((String) tm.getValueAt(cell[0], 1)); - System.out.println((String) tm.getValueAt(cell[0], 1) + ","); + int idDestinationGroup = getIDGroupeByName((String) tm.getValueAt(cell[0], 2)); + String idMessage = (String) tm.getValueAt(cell[0], 0); + String idEleve = this.db.fetchAll("SELECT id_eleve FROM fi_demandes WHERE id = " + idMessage).get(0); if (choice == 0) { - if (this.db.updateRow("UPDATE fi_demandes SET statut = 'Acceptée' WHERE id = " + id)) { - if (this.db.updateRow("UPDATE fi_demandes SET statut = 'Acceptée' WHERE id = " + id)) { - JOptionPane.showMessageDialog(this.parent, "La demande a bien été acceptée", "Succès",JOptionPane.INFORMATION_MESSAGE); - + if (this.db.updateRow("UPDATE fi_demandes SET statut = 'Acceptée' WHERE id = " + idMessage)) { + if (this.db.updateRow("UPDATE fi_eleves SET groupe = " + idDestinationGroup + " WHERE id = " + idEleve)) { + JOptionPane.showMessageDialog( + this.parent, + "La demande a bien été acceptée", + "Succès", + JOptionPane.INFORMATION_MESSAGE); + this.showRequest(); } else { - + JOptionPane.showMessageDialog( + this.parent, + "Echec de validation", + "Echec", + JOptionPane.ERROR_MESSAGE); } } else { JOptionPane.showMessageDialog( - this.parent, - "Impossible d'accepter la demande", - "Echec", - JOptionPane.INFORMATION_MESSAGE); + this.parent, + "Impossible d'accepter la demande", + "Echec", + JOptionPane.ERROR_MESSAGE); } - } else { - if (this.db.updateRow("UPDATE fi_demandes SET statut = 'Refusée' WHERE id = " + id)) { + } else if (choice == 1){ + if (this.db.updateRow("UPDATE fi_demandes SET statut = 'Refusée' WHERE id = " + idDestinationGroup)) { JOptionPane.showMessageDialog( this.parent, "La demande a bien été refusée", @@ -731,7 +744,7 @@ public class Controller implements ActionListener, ListSelectionListener { this.parent, "Impossible de refuser la demande", "Echec", - JOptionPane.INFORMATION_MESSAGE); + JOptionPane.ERROR_MESSAGE); } } } @@ -743,8 +756,7 @@ public class Controller implements ActionListener, ListSelectionListener { String grupDelName = (String) tm.getValueAt(cell[0], 0); if (this.db.updateRow("DELETE FROM fi_groupe WHERE nom = '" + grupDelName + "'")) { - if (this.db.updateRow( - "UPDATE fi_eleves SET groupe = -1 WHERE groupe = " + this.getIDGroupeByName(grupDelName))) { + if (this.db.updateRow("UPDATE fi_eleves SET groupe = -1 WHERE groupe = " + this.getIDGroupeByName(grupDelName))) { this.e = this.db.getEtuList(); this.g = this.db.getGroupeList();