This commit is contained in:
Romain BESSON 2022-12-08 21:46:45 +01:00
parent 2de66d6a9b
commit 8f8cd80bbb

View File

@ -293,7 +293,7 @@ public class Controller implements ActionListener, ListSelectionListener {
"Action" "Action"
}; };
int i, j; int i;
for (i = 0; i <= this.e.size() - 1; i++) { for (i = 0; i <= this.e.size() - 1; i++) {
if (this.e.get(i).getGroupe() == -1) { if (this.e.get(i).getGroupe() == -1) {
@ -621,11 +621,16 @@ public class Controller implements ActionListener, ListSelectionListener {
} }
else if (Objects.equals(command, "av::ShowRequestFromStudent")) { else if (Objects.equals(command, "av::ShowRequestFromStudent")) {
this.r = this.db.getRequestList(); showRequest();
}
}
Object[][] data = new Object[this.r.size()][5]; private void showRequest() {
this.r = this.db.getRequestList();
ArrayList<ArrayList<String>> data = new ArrayList<>();
String[] titre = { String[] titre = {
"Id",
"Etudiant", "Etudiant",
"Groupe demande", "Groupe demande",
"Message", "Message",
@ -635,22 +640,21 @@ public class Controller implements ActionListener, ListSelectionListener {
for (int i = 0; i <= this.r.size() - 1; i++) { for (int i = 0; i <= this.r.size() - 1; i++) {
if (this.r.get(i).getStatut().equals("Pas encore de reponse")) { if (this.r.get(i).getStatut().equals("Pas encore de reponse")) {
Object[] info = { ArrayList<String> info = new ArrayList<>();
this.getEtuNameById(this.r.get(i).getEtuId()), info.add(this.r.get(i).getIdMessage() + "");
this.getGroupeById(this.r.get(i).getWitchGroupe()), info.add(this.getEtuNameById(this.r.get(i).getEtuId()));
this.r.get(i).getMessage(), info.add(this.getGroupeById(this.r.get(i).getWitchGroupe()));
this.r.get(i).getType(), info.add(this.r.get(i).getMessage());
"[DECISION]" info.add(this.r.get(i).getType() + "");
}; info.add("[DECISION]");
data[i] = info; data.add(info);
} }
} }
String[][] stringArray = data.stream().map(u -> u.toArray(new String[0])).toArray(String[][]::new);
DisplayWithListner(this.createJTable(stringArray, titre));
DisplayWithListner(this.createJTable(data, titre));
}
} }
@Override @Override
@ -698,16 +702,25 @@ public class Controller implements ActionListener, ListSelectionListener {
private void makeDecision(TableModel tm, int[] cell) { private void makeDecision(TableModel tm, int[] cell) {
int choice = JOptionPane.showConfirmDialog(this.parent, "Accepter la demande ?"); int choice = JOptionPane.showConfirmDialog(this.parent, "Accepter la demande ?");
int id = getIDGroupeByName((String) tm.getValueAt(cell[0], 1)); int idDestinationGroup = getIDGroupeByName((String) tm.getValueAt(cell[0], 2));
System.out.println((String) tm.getValueAt(cell[0], 1) + ","); 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 (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 = " + idMessage)) {
if (this.db.updateRow("UPDATE fi_demandes SET statut = 'Acceptée' WHERE id = " + id)) { 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); JOptionPane.showMessageDialog(
this.parent,
"La demande a bien été acceptée",
"Succès",
JOptionPane.INFORMATION_MESSAGE);
this.showRequest();
} else { } else {
JOptionPane.showMessageDialog(
this.parent,
"Echec de validation",
"Echec",
JOptionPane.ERROR_MESSAGE);
} }
} else { } else {
@ -715,11 +728,11 @@ public class Controller implements ActionListener, ListSelectionListener {
this.parent, this.parent,
"Impossible d'accepter la demande", "Impossible d'accepter la demande",
"Echec", "Echec",
JOptionPane.INFORMATION_MESSAGE); JOptionPane.ERROR_MESSAGE);
} }
} else { } else if (choice == 1){
if (this.db.updateRow("UPDATE fi_demandes SET statut = 'Refusée' WHERE id = " + id)) { if (this.db.updateRow("UPDATE fi_demandes SET statut = 'Refusée' WHERE id = " + idDestinationGroup)) {
JOptionPane.showMessageDialog( JOptionPane.showMessageDialog(
this.parent, this.parent,
"La demande a bien été refusée", "La demande a bien été refusée",
@ -731,7 +744,7 @@ public class Controller implements ActionListener, ListSelectionListener {
this.parent, this.parent,
"Impossible de refuser la demande", "Impossible de refuser la demande",
"Echec", "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); String grupDelName = (String) tm.getValueAt(cell[0], 0);
if (this.db.updateRow("DELETE FROM fi_groupe WHERE nom = '" + grupDelName + "'")) { if (this.db.updateRow("DELETE FROM fi_groupe WHERE nom = '" + grupDelName + "'")) {
if (this.db.updateRow( if (this.db.updateRow("UPDATE fi_eleves SET groupe = -1 WHERE groupe = " + this.getIDGroupeByName(grupDelName))) {
"UPDATE fi_eleves SET groupe = -1 WHERE groupe = " + this.getIDGroupeByName(grupDelName))) {
this.e = this.db.getEtuList(); this.e = this.db.getEtuList();
this.g = this.db.getGroupeList(); this.g = this.db.getGroupeList();