$
This commit is contained in:
parent
37eec841b8
commit
dd088c00a2
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -17,7 +17,9 @@ import java.util.Iterator;
|
||||
import org.mariadb.jdbc.*;
|
||||
|
||||
/**
|
||||
* <p>Methodes pour les interaction avec une base de donnees</p>
|
||||
* <p>
|
||||
* Methodes pour les interaction avec une base de donnees
|
||||
* </p>
|
||||
*
|
||||
* @author <a href="https://github.com/lalBi94">Bilal Boudjemline</a>
|
||||
*/
|
||||
@ -43,7 +45,8 @@ public class BDatabase {
|
||||
}
|
||||
|
||||
try {
|
||||
this.sharedObject = DriverManager.getConnection(this.db_host + this.db_name, this.db_user, this.db_password);
|
||||
this.sharedObject = DriverManager.getConnection(this.db_host + this.db_name, this.db_user,
|
||||
this.db_password);
|
||||
this.status = true;
|
||||
} catch (SQLException e) {
|
||||
System.out.println("Erreur de liaison avec la base de donnees.");
|
||||
@ -113,7 +116,8 @@ public class BDatabase {
|
||||
}
|
||||
|
||||
/**
|
||||
* Faire des requetes de type UPDATE SET (il y aura plus d'argument prochainement).
|
||||
* Faire des requetes de type UPDATE SET (il y aura plus d'argument
|
||||
* prochainement).
|
||||
*
|
||||
* @param request La requete
|
||||
* @return Si oui ou non ca a fonctionne
|
||||
@ -121,6 +125,7 @@ public class BDatabase {
|
||||
public boolean updateRow(String request) {
|
||||
try {
|
||||
this.sharedObject.prepareStatement(request).executeQuery();
|
||||
System.out.println("Succes:" + request);
|
||||
return true;
|
||||
} catch (SQLException e) {
|
||||
return false;
|
||||
@ -149,7 +154,7 @@ public class BDatabase {
|
||||
* Recuperer la liste des etudiants (FIProjet Contexte)
|
||||
*
|
||||
* @return La liste des etudiants
|
||||
* */
|
||||
*/
|
||||
public ArrayList<Etudiant> getEtuList() {
|
||||
ArrayList<Etudiant> listEtu = new ArrayList<>();
|
||||
ArrayList<String> studPrenom = this.fetchAll("SELECT prenom FROM fi_eleves");
|
||||
@ -163,17 +168,13 @@ public class BDatabase {
|
||||
new EtudiantNP(
|
||||
studNom.get(i),
|
||||
studPrenom.get(i),
|
||||
Integer.parseInt(studGroupe.get(i), 10)
|
||||
)
|
||||
);
|
||||
Integer.parseInt(studGroupe.get(i), 10)));
|
||||
} catch (NumberFormatException ignore) {
|
||||
listEtu.add(
|
||||
new EtudiantNP(
|
||||
studNom.get(i),
|
||||
studPrenom.get(i),
|
||||
-1
|
||||
)
|
||||
);
|
||||
-1));
|
||||
}
|
||||
} else {
|
||||
System.out.println("[!] Erreur lors du chargement de la liste des etudiants.");
|
||||
@ -190,32 +191,28 @@ public class BDatabase {
|
||||
* Recuperer la liste des groupes (FIProjet contexte)
|
||||
*
|
||||
* @return La liste des groupes
|
||||
* */
|
||||
*/
|
||||
public ArrayList<Groupe> getGroupeList() {
|
||||
ArrayList<Groupe> listGroupe = new ArrayList<>();
|
||||
ArrayList<String> groupeId = this.fetchAll("SELECT id FROM fi_groupe");
|
||||
ArrayList<String> groupeNom = this.fetchAll("SELECT nom FROM fi_groupe");
|
||||
ArrayList<String> groupeMin = this.fetchAll("SELECT min FROM fi_groupe");
|
||||
ArrayList<String> groupeMax = this.fetchAll("SELECT max FROM fi_groupe");
|
||||
|
||||
for (int i = 0; i <= groupeNom.size() - 1; i++) {
|
||||
if(groupeId.get(i) != null && groupeNom.get(i) != null && groupeMin.get(i) != null && groupeMax.get(i) != null) {
|
||||
if (groupeId.get(i) != null && groupeNom.get(i) != null && groupeMin.get(i) != null
|
||||
&& groupeMax.get(i) != null) {
|
||||
listGroupe.add(
|
||||
new GroupeNP(
|
||||
Integer.parseInt(groupeId.get(i), 10),
|
||||
groupeNom.get(i),
|
||||
Integer.parseInt(groupeMin.get(i), 10),
|
||||
Integer.parseInt(groupeMax.get(i), 10)
|
||||
)
|
||||
);
|
||||
Integer.parseInt(groupeMax.get(i), 10)));
|
||||
} else {
|
||||
System.out.println("[!] Erreur lors du chargement de la liste des groupes.");
|
||||
System.exit(-1);
|
||||
}
|
||||
}
|
||||
|
||||
System.out.println("[+] Liste des groupes chargees.");
|
||||
|
||||
return listGroupe;
|
||||
}
|
||||
|
||||
@ -223,7 +220,7 @@ public class BDatabase {
|
||||
* Recuperer les requetes
|
||||
*
|
||||
* @return la liste des requetes
|
||||
* */
|
||||
*/
|
||||
public ArrayList<Requete> getRequestList() {
|
||||
ArrayList<Requete> toReturn = new ArrayList<>();
|
||||
ArrayList<String> requestId = this.fetchAll("SELECT id FROM fi_demandes");
|
||||
@ -241,9 +238,7 @@ public class BDatabase {
|
||||
Integer.parseInt(requestEtu.get(i)),
|
||||
Integer.parseInt(requestType.get(i)),
|
||||
Integer.parseInt(requestWitchGrup.get(i)),
|
||||
requestStatut.get(i)
|
||||
)
|
||||
);
|
||||
requestStatut.get(i)));
|
||||
}
|
||||
|
||||
return toReturn;
|
||||
|
@ -15,7 +15,6 @@ import java.awt.event.ActionListener;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Objects;
|
||||
|
||||
|
||||
/**
|
||||
* Récupérer les actions des utilisateurs avec des ActionListener
|
||||
* et ListSelectionListener afin de lancer la vue demandée ou les
|
||||
@ -76,7 +75,7 @@ public class Controller implements ActionListener, ListSelectionListener {
|
||||
*
|
||||
* @param id le groupe
|
||||
* @return le nombre de membres
|
||||
* */
|
||||
*/
|
||||
public int getMemberCount(int id) {
|
||||
int j = 0;
|
||||
|
||||
@ -88,11 +87,13 @@ public class Controller implements ActionListener, ListSelectionListener {
|
||||
|
||||
return j;
|
||||
}
|
||||
|
||||
/**
|
||||
* Pour créer une JTable
|
||||
*
|
||||
* @param data Les données
|
||||
* @param title Les titres
|
||||
* */
|
||||
*/
|
||||
private JTable createJTable(Object[][] data, String[] title) {
|
||||
return new JTable(data, title) {
|
||||
public boolean editCellAt(int row, int column, java.util.EventObject e) {
|
||||
@ -105,7 +106,7 @@ public class Controller implements ActionListener, ListSelectionListener {
|
||||
* Pour afficher une JTable sans listener
|
||||
*
|
||||
* @param liste La JTable
|
||||
* */
|
||||
*/
|
||||
private void Display(JTable liste) {
|
||||
liste.getTableHeader().setReorderingAllowed(false);
|
||||
liste.setFillsViewportHeight(true);
|
||||
@ -117,7 +118,7 @@ public class Controller implements ActionListener, ListSelectionListener {
|
||||
* Pour afficher une JTable contenant un listener
|
||||
*
|
||||
* @param liste La JTable
|
||||
* */
|
||||
*/
|
||||
private void DisplayWithListner(JTable liste) {
|
||||
ListSelectionModel lsm = liste.getSelectionModel();
|
||||
lsm.addListSelectionListener(this);
|
||||
@ -129,7 +130,8 @@ public class Controller implements ActionListener, ListSelectionListener {
|
||||
}
|
||||
|
||||
/**
|
||||
* Pour afficher une modale classique pour plus de libertées (panel a créer au préalable)
|
||||
* Pour afficher une modale classique pour plus de libertées (panel a créer au
|
||||
* préalable)
|
||||
*
|
||||
* @param frameTitle Le titre de la fenêtre
|
||||
* @param size_x Taille en x
|
||||
@ -137,7 +139,7 @@ public class Controller implements ActionListener, ListSelectionListener {
|
||||
* @param loca_x Localisation en x
|
||||
* @param loca_y Localisation en y
|
||||
* @param forModal Le panel a mettre dans la fenêtre (libre)
|
||||
* */
|
||||
*/
|
||||
private void DisplayModal(String frameTitle, int size_x, int size_y, int loca_x, int loca_y, JPanel forModal) {
|
||||
this.currentModal = new BFrame(frameTitle, loca_x, loca_y, size_x, size_y, this.parent, forModal);
|
||||
}
|
||||
@ -216,14 +218,16 @@ public class Controller implements ActionListener, ListSelectionListener {
|
||||
this.pv,
|
||||
"Veuillez écrire 3 lettres",
|
||||
"Erreur.",
|
||||
JOptionPane.ERROR_MESSAGE
|
||||
);
|
||||
JOptionPane.ERROR_MESSAGE);
|
||||
} else {
|
||||
char[] beg = text.toCharArray();
|
||||
|
||||
ArrayList<String> filtreEleveNom = db.fetchAll("SELECT nom FROM fi_eleves WHERE nom LIKE '" + beg[0] + beg[1] + beg[2] + "%'");
|
||||
ArrayList<String> filtreElevePrenom = db.fetchAll("SELECT prenom FROM fi_eleves WHERE nom LIKE '" + beg[0] + beg[1] + beg[2] + "%'");
|
||||
ArrayList<String> filtreEleveGroupe = db.fetchAll("SELECT groupe FROM fi_eleves WHERE nom LIKE '" + beg[0] + beg[1] + beg[2] + "%'");
|
||||
ArrayList<String> filtreEleveNom = db
|
||||
.fetchAll("SELECT nom FROM fi_eleves WHERE nom LIKE '" + beg[0] + beg[1] + beg[2] + "%'");
|
||||
ArrayList<String> filtreElevePrenom = db
|
||||
.fetchAll("SELECT prenom FROM fi_eleves WHERE nom LIKE '" + beg[0] + beg[1] + beg[2] + "%'");
|
||||
ArrayList<String> filtreEleveGroupe = db
|
||||
.fetchAll("SELECT groupe FROM fi_eleves WHERE nom LIKE '" + beg[0] + beg[1] + beg[2] + "%'");
|
||||
|
||||
System.out.println(filtreEleveGroupe.size() + filtreElevePrenom.size() + filtreEleveGroupe.size());
|
||||
|
||||
@ -232,8 +236,7 @@ public class Controller implements ActionListener, ListSelectionListener {
|
||||
this.pv,
|
||||
"Elève introuvable !",
|
||||
"Erreur.",
|
||||
JOptionPane.ERROR_MESSAGE
|
||||
);
|
||||
JOptionPane.ERROR_MESSAGE);
|
||||
} else {
|
||||
String[] titre = {
|
||||
"Nom",
|
||||
@ -312,32 +315,30 @@ public class Controller implements ActionListener, ListSelectionListener {
|
||||
else if (Objects.equals(command, "crtll::ActionAddAndMoveGrup")) {
|
||||
this.tmpStud.add(String.valueOf(this.list.getSelectedIndex()));
|
||||
|
||||
String query =
|
||||
"UPDATE fi_eleves SET groupe=" + this.tmpStud.get(2) +
|
||||
String query = "UPDATE fi_eleves SET groupe=" + this.tmpStud.get(2) +
|
||||
" WHERE nom='" + this.tmpStud.get(0) +
|
||||
"' AND prenom='" + this.tmpStud.get(1) + "'"
|
||||
;
|
||||
"' AND prenom='" + this.tmpStud.get(1) + "'";
|
||||
|
||||
System.out.println(query);
|
||||
|
||||
if (db.updateRow(query)) {
|
||||
JOptionPane.showMessageDialog(
|
||||
this.currentModal,
|
||||
this.tmpStud.get(0) + " " + this.tmpStud.get(1) + " a bien ete deplace dans le " + this.list.getSelectedItem(),
|
||||
this.tmpStud.get(0) + " " + this.tmpStud.get(1) + " a bien ete deplace dans le "
|
||||
+ this.list.getSelectedItem(),
|
||||
"Déplacement effectué",
|
||||
JOptionPane.INFORMATION_MESSAGE
|
||||
);
|
||||
JOptionPane.INFORMATION_MESSAGE);
|
||||
|
||||
this.e = this.db.getEtuList();
|
||||
|
||||
System.out.println("[+] Modification de " + this.tmpStud.get(1) + " " + this.tmpStud.get(0) + " effectue");
|
||||
System.out.println(
|
||||
"[+] Modification de " + this.tmpStud.get(1) + " " + this.tmpStud.get(0) + " effectue");
|
||||
} else {
|
||||
JOptionPane.showMessageDialog(
|
||||
this.currentModal,
|
||||
this.tmpStud.get(0) + " " + this.tmpStud.get(1) + " n'a pas pu etre deplace",
|
||||
"Erreur lors du déplacement",
|
||||
JOptionPane.ERROR_MESSAGE
|
||||
);
|
||||
JOptionPane.ERROR_MESSAGE);
|
||||
}
|
||||
}
|
||||
|
||||
@ -372,7 +373,7 @@ public class Controller implements ActionListener, ListSelectionListener {
|
||||
* - possible ou nn
|
||||
* - message
|
||||
* - Valider
|
||||
* */
|
||||
*/
|
||||
|
||||
settings.setPositionY(1);
|
||||
JLabel requestT = new JLabel("Dans quel groupe souhaitez-vous aller ?");
|
||||
@ -410,8 +411,7 @@ public class Controller implements ActionListener, ListSelectionListener {
|
||||
500,
|
||||
this.parent.getLocation().x + (this.parent.getSize().width - 750) / 2,
|
||||
this.parent.getLocation().y + (this.parent.getSize().height - 500) / 2,
|
||||
forModal
|
||||
);
|
||||
forModal);
|
||||
}
|
||||
|
||||
else if (Objects.equals(command, "sv::SendRequest")) {
|
||||
@ -433,22 +433,21 @@ public class Controller implements ActionListener, ListSelectionListener {
|
||||
}
|
||||
|
||||
if (this.db.insertRow("fi_demandes", new String[] {
|
||||
"id_eleve", "id_groupe", "message", "type"}, new String[] {
|
||||
"id_eleve", "id_groupe", "message", "type" },
|
||||
new String[] {
|
||||
String.valueOf(id), String.valueOf(groupe), message, String.valueOf(type)
|
||||
})) {
|
||||
JOptionPane.showMessageDialog(
|
||||
this.pv,
|
||||
"Votre requête a été envoyé avec succès !",
|
||||
"Requête.",
|
||||
JOptionPane.INFORMATION_MESSAGE
|
||||
);
|
||||
JOptionPane.INFORMATION_MESSAGE);
|
||||
} else {
|
||||
JOptionPane.showMessageDialog(
|
||||
this.sv,
|
||||
"Une erreur est survenue lors de l'envoi de votre message...\nVeuillez réessayer plus tard.",
|
||||
"Erreur avec la base de données.",
|
||||
JOptionPane.ERROR_MESSAGE
|
||||
);
|
||||
JOptionPane.ERROR_MESSAGE);
|
||||
}
|
||||
}
|
||||
|
||||
@ -531,8 +530,7 @@ public class Controller implements ActionListener, ListSelectionListener {
|
||||
500,
|
||||
this.parent.getLocation().x + (this.parent.getSize().width - 750) / 2,
|
||||
this.parent.getLocation().y + (this.parent.getSize().height - 500) / 2,
|
||||
forModal
|
||||
);
|
||||
forModal);
|
||||
}
|
||||
|
||||
else if (Objects.equals(command, "av::CreateGrupOnDatabase")) {
|
||||
@ -540,13 +538,14 @@ public class Controller implements ActionListener, ListSelectionListener {
|
||||
String max = this.l2.getText();
|
||||
String min = this.l3.getText();
|
||||
|
||||
this.db.updateRow("ALTER TABLE fi_groupe AUTO_INCREMENT=" + this.g.size());
|
||||
|
||||
if (this.db.insertRow("fi_groupe", new String[] { "nom", "min", "max" }, new String[] { nom, min, max })) {
|
||||
JOptionPane.showMessageDialog(
|
||||
this.parent,
|
||||
"Groupe" + nom + "creer !",
|
||||
"Succes",
|
||||
JOptionPane.INFORMATION_MESSAGE
|
||||
);
|
||||
JOptionPane.INFORMATION_MESSAGE);
|
||||
|
||||
this.g = this.db.getGroupeList();
|
||||
} else {
|
||||
@ -554,8 +553,7 @@ public class Controller implements ActionListener, ListSelectionListener {
|
||||
this.parent,
|
||||
"La creation du groupe : " + nom + " à échoué.",
|
||||
"Erreur",
|
||||
JOptionPane.ERROR_MESSAGE
|
||||
);
|
||||
JOptionPane.ERROR_MESSAGE);
|
||||
}
|
||||
}
|
||||
|
||||
@ -588,15 +586,13 @@ public class Controller implements ActionListener, ListSelectionListener {
|
||||
this.parent,
|
||||
"Le groupe : " + grupToChange + " a bien ete renommé par : " + newName,
|
||||
"Succes",
|
||||
JOptionPane.INFORMATION_MESSAGE
|
||||
);
|
||||
JOptionPane.INFORMATION_MESSAGE);
|
||||
} else {
|
||||
JOptionPane.showMessageDialog(
|
||||
this.parent,
|
||||
"Echec du changement de nom du groupe : " + grupToChange,
|
||||
"Erreur",
|
||||
JOptionPane.ERROR_MESSAGE
|
||||
);
|
||||
JOptionPane.ERROR_MESSAGE);
|
||||
}
|
||||
|
||||
this.g = this.db.getGroupeList();
|
||||
@ -698,7 +694,8 @@ 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();
|
||||
|
||||
@ -706,15 +703,13 @@ public class Controller implements ActionListener, ListSelectionListener {
|
||||
this.parent,
|
||||
"Le groupe : " + grupDelName + " a bien ete supprime",
|
||||
"Succes",
|
||||
JOptionPane.INFORMATION_MESSAGE
|
||||
);
|
||||
JOptionPane.INFORMATION_MESSAGE);
|
||||
} else {
|
||||
JOptionPane.showMessageDialog(
|
||||
this.parent,
|
||||
"Echec de la suppression du groupe : " + grupDelName,
|
||||
"Erreur",
|
||||
JOptionPane.ERROR_MESSAGE
|
||||
);
|
||||
JOptionPane.ERROR_MESSAGE);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -741,7 +736,6 @@ public class Controller implements ActionListener, ListSelectionListener {
|
||||
settings.setPositionY(3);
|
||||
forModal.add(new JLabel(" "), settings);
|
||||
|
||||
|
||||
settings.setPositionY(4);
|
||||
forModal.add(new JLabel(" "), settings);
|
||||
|
||||
@ -756,8 +750,7 @@ public class Controller implements ActionListener, ListSelectionListener {
|
||||
300,
|
||||
this.parent.getLocation().x + (this.parent.getSize().width - 600) / 2,
|
||||
this.parent.getLocation().y + (this.parent.getSize().height - 300) / 2,
|
||||
forModal
|
||||
);
|
||||
forModal);
|
||||
}
|
||||
|
||||
private void addMoveStudent(TableModel tm, int[] cell, String action) {
|
||||
@ -793,8 +786,7 @@ public class Controller implements ActionListener, ListSelectionListener {
|
||||
JLabel intro = new JLabel(
|
||||
stringSet[0] + tm.getValueAt(cell[0], 0) + " " +
|
||||
tm.getValueAt(cell[0], 1) +
|
||||
" dans le groupe : "
|
||||
);
|
||||
" dans le groupe : ");
|
||||
forModal.add(intro, settings);
|
||||
|
||||
settings.setPositionX(1);
|
||||
@ -838,8 +830,7 @@ public class Controller implements ActionListener, ListSelectionListener {
|
||||
250,
|
||||
this.parent.getLocation().x + (this.parent.getSize().width - 500) / 2,
|
||||
this.parent.getLocation().y + (this.parent.getSize().height - 250) / 2,
|
||||
forModal
|
||||
);
|
||||
forModal);
|
||||
|
||||
this.g = this.db.getGroupeList();
|
||||
this.parent.updateTable(this.initTable());
|
||||
@ -858,6 +849,7 @@ public class Controller implements ActionListener, ListSelectionListener {
|
||||
this.e.get(i).getPrenom(),
|
||||
this.getGroupeById(this.e.get(i).getGroupe())
|
||||
};
|
||||
|
||||
data[i] = info;
|
||||
}
|
||||
return createJTable(data, title);
|
||||
@ -901,5 +893,7 @@ public class Controller implements ActionListener, ListSelectionListener {
|
||||
return this.g;
|
||||
}
|
||||
|
||||
public void setMainMenu(MainMenu m) {this.parent = m;}
|
||||
public void setMainMenu(MainMenu m) {
|
||||
this.parent = m;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user