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"
};
int i, j;
int i;
for (i = 0; i <= this.e.size() - 1; i++) {
if (this.e.get(i).getGroupe() == -1) {
@ -621,11 +621,16 @@ public class Controller implements ActionListener, ListSelectionListener {
}
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 = {
"Id",
"Etudiant",
"Groupe demande",
"Message",
@ -635,22 +640,21 @@ public class Controller implements ActionListener, ListSelectionListener {
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]"
};
ArrayList<String> 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[i] = info;
data.add(info);
}
}
String[][] stringArray = data.stream().map(u -> u.toArray(new String[0])).toArray(String[][]::new);
DisplayWithListner(this.createJTable(data, titre));
}
DisplayWithListner(this.createJTable(stringArray, titre));
}
@Override
@ -698,16 +702,25 @@ 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 {
@ -715,11 +728,11 @@ public class Controller implements ActionListener, ListSelectionListener {
this.parent,
"Impossible d'accepter la demande",
"Echec",
JOptionPane.INFORMATION_MESSAGE);
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();