diff --git a/FI_PRJ.jar b/FI_PRJ.jar deleted file mode 100644 index 261d00b..0000000 Binary files a/FI_PRJ.jar and /dev/null differ diff --git a/build/API/AbstractChangementFactory.class b/build/API/AbstractChangementFactory.class index ad80235..7bb0ac2 100644 Binary files a/build/API/AbstractChangementFactory.class and b/build/API/AbstractChangementFactory.class differ diff --git a/build/API/AbstractGroupeFactory.class b/build/API/AbstractGroupeFactory.class index cc61166..b07b9a9 100644 Binary files a/build/API/AbstractGroupeFactory.class and b/build/API/AbstractGroupeFactory.class differ diff --git a/build/API/Changement.class b/build/API/Changement.class index 17a2e8e..29fe6e5 100644 Binary files a/build/API/Changement.class and b/build/API/Changement.class differ diff --git a/build/API/Etudiant.class b/build/API/Etudiant.class index 8313375..81c1c3d 100644 Binary files a/build/API/Etudiant.class and b/build/API/Etudiant.class differ diff --git a/build/API/Groupe.class b/build/API/Groupe.class index afe4ab2..2de578e 100644 Binary files a/build/API/Groupe.class and b/build/API/Groupe.class differ diff --git a/build/API/MonPrint.class b/build/API/MonPrint.class index 74b2632..92a67e7 100644 Binary files a/build/API/MonPrint.class and b/build/API/MonPrint.class differ diff --git a/build/API/TypeGroupe.class b/build/API/TypeGroupe.class index 922fef6..8566d06 100644 Binary files a/build/API/TypeGroupe.class and b/build/API/TypeGroupe.class differ diff --git a/build/MNP/AbstractChangementFactoryNP.class b/build/MNP/AbstractChangementFactoryNP.class index 0e1f6e5..29869c1 100644 Binary files a/build/MNP/AbstractChangementFactoryNP.class and b/build/MNP/AbstractChangementFactoryNP.class differ diff --git a/build/MNP/AbstractGroupeFactoryNP.class b/build/MNP/AbstractGroupeFactoryNP.class index 5e35ada..e7f1083 100644 Binary files a/build/MNP/AbstractGroupeFactoryNP.class and b/build/MNP/AbstractGroupeFactoryNP.class differ diff --git a/build/MNP/ChangementNP.class b/build/MNP/ChangementNP.class index 6cd5563..98bad41 100644 Binary files a/build/MNP/ChangementNP.class and b/build/MNP/ChangementNP.class differ diff --git a/build/MNP/EtudiantNP.class b/build/MNP/EtudiantNP.class index 124c014..f1208d6 100644 Binary files a/build/MNP/EtudiantNP.class and b/build/MNP/EtudiantNP.class differ diff --git a/build/MNP/GroupeNP.class b/build/MNP/GroupeNP.class index c6c14b3..d92474f 100644 Binary files a/build/MNP/GroupeNP.class and b/build/MNP/GroupeNP.class differ diff --git a/build/Test/AdminView.class b/build/Test/AdminView.class index 58528fd..b9b0701 100644 Binary files a/build/Test/AdminView.class and b/build/Test/AdminView.class differ diff --git a/build/Test/BDatabase.class b/build/Test/BDatabase.class index a829de3..3ebc35a 100644 Binary files a/build/Test/BDatabase.class and b/build/Test/BDatabase.class differ diff --git a/build/Test/BFrame.class b/build/Test/BFrame.class index 8986649..46f3bab 100644 Binary files a/build/Test/BFrame.class and b/build/Test/BFrame.class differ diff --git a/build/Test/BLayout.class b/build/Test/BLayout.class index 01daf98..6800331 100644 Binary files a/build/Test/BLayout.class and b/build/Test/BLayout.class differ diff --git a/build/Test/Controller$1.class b/build/Test/Controller$1.class index b36326e..ecfd206 100644 Binary files a/build/Test/Controller$1.class and b/build/Test/Controller$1.class differ diff --git a/build/Test/Controller.class b/build/Test/Controller.class index bc15f0e..4c59a33 100644 Binary files a/build/Test/Controller.class and b/build/Test/Controller.class differ diff --git a/build/Test/ProfView$1.class b/build/Test/ProfView$1.class index d377b53..0791bdd 100644 Binary files a/build/Test/ProfView$1.class and b/build/Test/ProfView$1.class differ diff --git a/build/Test/ProfView.class b/build/Test/ProfView.class index 6c7fd19..6846f4a 100644 Binary files a/build/Test/ProfView.class and b/build/Test/ProfView.class differ diff --git a/build/Test/TestTexteMNP.class b/build/Test/TestTexteMNP.class index 0eeaafc..15939cd 100644 Binary files a/build/Test/TestTexteMNP.class and b/build/Test/TestTexteMNP.class differ diff --git a/out/production/FIProjetIHM2022/Test/BDatabase.class b/out/production/FIProjetIHM2022/Test/BDatabase.class index 55dbf8e..d29a226 100644 Binary files a/out/production/FIProjetIHM2022/Test/BDatabase.class and b/out/production/FIProjetIHM2022/Test/BDatabase.class differ diff --git a/out/production/FIProjetIHM2022/Test/Controller.class b/out/production/FIProjetIHM2022/Test/Controller.class index eda2c5c..400f895 100644 Binary files a/out/production/FIProjetIHM2022/Test/Controller.class and b/out/production/FIProjetIHM2022/Test/Controller.class differ diff --git a/out/production/FIProjetIHM2022/Test/TestTexteMNP.class b/out/production/FIProjetIHM2022/Test/TestTexteMNP.class index 74f24ec..d0c0e47 100644 Binary files a/out/production/FIProjetIHM2022/Test/TestTexteMNP.class and b/out/production/FIProjetIHM2022/Test/TestTexteMNP.class differ diff --git a/src/Test/BDatabase.java b/src/Test/BDatabase.java index 0f599c8..2d8d63e 100644 --- a/src/Test/BDatabase.java +++ b/src/Test/BDatabase.java @@ -7,6 +7,8 @@ package Test; * 28/09/2022 at 20:35 * */ +import API.*; +import MNP.*; import java.sql.*; import java.sql.Connection; import java.util.ArrayList; @@ -14,8 +16,6 @@ import java.util.Arrays; import java.util.Iterator; import org.mariadb.jdbc.*; -import javax.crypto.spec.PSource; - /** *

Methodes pour les interaction avec une base de donnees

* @@ -145,6 +145,81 @@ public class BDatabase { return this.db_user; } + /** + * Recuperer la liste des etudiants (FIProjet Contexte) + * + * @return La liste des etudiants + * */ + public ArrayList getEtuList() { + ArrayList listEtu = new ArrayList<>(); + ArrayList studPrenom = this.fetchAll("SELECT prenom FROM fi_eleves"); + ArrayList studNom = this.fetchAll("SELECT nom FROM fi_eleves"); + ArrayList studGroupe = this.fetchAll("SELECT groupe FROM fi_eleves"); + + for(int i = 0; i <= studPrenom.size()-1; i++) { + if(studPrenom.get(i) != null && studNom.get(i) != null && studGroupe.get(i) != null) { + try { + listEtu.add( + new EtudiantNP( + studNom.get(i), + studPrenom.get(i), + Integer.parseInt(studGroupe.get(i), 10) + ) + ); + } catch(NumberFormatException ignore) { + listEtu.add( + new EtudiantNP( + studNom.get(i), + studPrenom.get(i), + -1 + ) + ); + } + } else { + System.out.println("[!] Erreur lors du chargement de la liste des etudiants."); + System.exit(-1); + } + } + + System.out.println("[+] Liste des etudiants chargee."); + + return listEtu; + } + + /** + * Recuperer la liste des groupes (FIProjet contexte) + * + * @return La liste des groupes + * */ + public ArrayList getGroupeList() { + ArrayList listGroupe = new ArrayList<>(); + ArrayList groupeId = this.fetchAll("SELECT id FROM fi_groupe"); + ArrayList groupeNom = this.fetchAll("SELECT nom FROM fi_groupe"); + ArrayList groupeMin = this.fetchAll("SELECT min FROM fi_groupe"); + ArrayList 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) { + 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) + ) + ); + } 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; + } + + /** * Recuperer l'hote courant. * diff --git a/src/Test/Controller.java b/src/Test/Controller.java index b13c497..de9f746 100644 --- a/src/Test/Controller.java +++ b/src/Test/Controller.java @@ -1,378 +1,399 @@ -package Test; - -import API.Etudiant; -import API.Groupe; - -// TODO: Trier ca pour faire un import par package utilises (j'ai eu la flemme de le faire) -import javax.swing.*; -import java.awt.*; - -import javax.swing.event.ListSelectionEvent; -import javax.swing.event.ListSelectionListener; -import javax.swing.table.TableModel; -import java.awt.event.ActionEvent; -import java.awt.event.ActionListener; -import java.util.ArrayList; -import java.util.Objects; - -public class Controller implements ActionListener, ListSelectionListener { - private final BDatabase db; - - private final ProfView pv; - private final AdminView av; - - private BFrame lastModal; - private BFrame currentModal; - - private final ArrayList e; - private final ArrayList g; - - private JTable currentJTableUse; - private JComboBox list; - - private String[] tmpStud; - - public Controller(ArrayList e, ArrayList g) { - this.e = e; - this.g = g; - this.db = new BDatabase(); - this.pv = new ProfView(e, g, this); - System.out.println("[+] Demarrage de la vue professeur -> " + pv); - this.av = new AdminView(e, g, this); - System.out.println("[+] Demarrage de la vue Administrateur -> " + av); - } - - /** - * Pour creer une JTable - * @param data Les donnees - * @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) { - return false; - } - }; - } - - /** - * Pour afficher une JTable sans listener - * - * @param parent La fenetre qui sera bloque - * @param frameTitle Le titre de la fenetre - * @param size_x Taille en x - * @param size_y Taille en y - * @param loca_x Localisation en x - * @param loca_y Localisation en y - * @param liste La JTable - * */ - private void Display(BFrame parent, String frameTitle, int size_x, int size_y, int loca_x, int loca_y, JTable liste) { - JPanel forModal = new JPanel(); - - ListSelectionModel lsm = liste.getSelectionModel(); - liste.getTableHeader().setReorderingAllowed(false); - liste.setFillsViewportHeight(true); - - this.currentJTableUse = liste; - - forModal.add(liste); - - BFrame frame = new BFrame(frameTitle, loca_x, loca_y, size_x, size_y, parent, forModal); - } - - /** - * Pour afficher une JTable contenant un listener - * - * @param parent La fenetre qui sera bloque - * @param frameTitle Le titre de la fenetre - * @param size_x Taille en x - * @param size_y Taille en y - * @param loca_x Localisation en x - * @param loca_y Localisation en y - * @param liste La JTable - * */ - private void DisplayWithListner(BFrame parent, String frameTitle, int size_x, int size_y, int loca_x, int loca_y, JTable liste) { - JPanel forModal = new JPanel(); - - ListSelectionModel lsm = liste.getSelectionModel(); - lsm.addListSelectionListener(this); - liste.getTableHeader().setReorderingAllowed(false); - liste.setFillsViewportHeight(true); - - this.currentJTableUse = liste; - - forModal.add(liste); - - BFrame frame = new BFrame(frameTitle, loca_x, loca_y, size_x, size_y, parent, forModal); - } - - /** - * Pour afficher une modale classique pour plus de liberte (panel a creer au prealable) - * - * @param parent La fenetre qui sera bloque - * @param frameTitle Le titre de la fenetre - * @param size_x Taille en x - * @param size_y Taille en y - * @param loca_x Localisation en x - * @param loca_y Localisation en y - * @param forModal Le panel a mettre dans la fenetre (libre) - * */ - private void DisplayModal(BFrame parent, 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, parent, forModal); - } - - @Override - public void actionPerformed(ActionEvent e) { - String command = e.getActionCommand(); - - String groupeOption = this.pv.getComboSelection(); - int groupeIndex = this.pv.getComboSelectionIndex(); - String text = this.pv.getSearchStud(); - - if(Objects.equals(command, "pv::GetStudList")) { - String[][] data = new String[this.e.size()][2]; - - String[] titre = { - "Nom", - "Prenom", - "Groupe" - }; - - for(int i = 0; i <= this.e.size()-1; i++) { - String[] info = { - this.e.get(i).getNom(), - this.e.get(i).getPrenom(), - String.valueOf(this.e.get(i).getGroupe()) - }; - - data[i] = info; - } - - Display( - this.pv, - "Liste des etudiants", - 350, - 400, - this.pv.getX(), - this.pv.getY(), - this.createJTable(data, titre) - ); - } - - else if(Objects.equals(command, "pv::GetListFiltered")) { - String[][] data = new String[this.e.size()][1]; - - String[] titre = { - "Nom", - "Prenom" - }; - - int i, j; - - for(i = 0, j = 0; i <= this.e.size()-1; i++) { - if(this.e.get(i).getGroupe() == groupeIndex) { - String[] info = { - this.e.get(i).getNom(), - this.e.get(i).getPrenom() - }; - - data[j] = info; - j++; - } - } - - String[][] data_final = new String[j][1]; - for(int x = 0; x <= j-1; x++) { - data_final[x] = data[x]; - } - - Display( - this.pv, - "Liste d'eleve du " + groupeOption, - 350, - 400, - this.pv.getX(), - this.pv.getY(), - this.createJTable(data_final, titre) - ); - } - - else if(Objects.equals(command, "pv::SearchStudentPer3Letters")) { - if(text.length() < 3 || text == null) { - JOptionPane.showMessageDialog( - this.pv, - "Veuillez ecrire 3 lettres", - "Erreur.", - JOptionPane.ERROR_MESSAGE - ); - } else { - char[] beg = text.toCharArray(); - - ArrayList filtreEleveNom = db.fetchAll("SELECT nom FROM fi_eleves WHERE nom LIKE '" + beg[0] + beg[1] + beg[2] + "%'"); - ArrayList filtreElevePrenom = db.fetchAll("SELECT prenom FROM fi_eleves WHERE nom LIKE '" + beg[0] + beg[1] + beg[2] + "%'"); - ArrayList 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()); - - if(filtreEleveGroupe.size() == 0 || filtreEleveNom.size() == 0 || filtreElevePrenom.size() == 0) { - JOptionPane.showMessageDialog( - this.pv, - "Eleve introuvable !", - "Erreur.", - JOptionPane.ERROR_MESSAGE - ); - } else { - String[] titre = { - "Nom", - "Prenom", - "Groupe" - }; - - String[][] data = new String[filtreEleveNom.size()][2]; - - for(int i = 0; i <= filtreEleveNom.size()-1; i++){ - data[i] = new String[]{ - filtreEleveNom.get(i), - filtreElevePrenom.get(i), - String.valueOf(filtreEleveGroupe.get(i)) - }; - } - - Display( - this.pv, - "Recherche", - 350, - 400, - this.pv.getX(), - this.pv.getY(), - this.createJTable(data, titre) - ); - } - } - } - - else if(Objects.equals(command, "av::MoveStudGrup")) { - Object[][] data = new Object[this.e.size()][3]; - - String[] titre = { - "Nom", - "Prenom", - "Groupe", - "Action" - }; - - for(int i = 0; i <= this.e.size()-1; i++) { - Object[] info = { - this.e.get(i).getNom(), - this.e.get(i).getPrenom(), - String.valueOf(this.e.get(i).getGroupe()), - "[DEPLACER]" - }; - - data[i] = info; - } - - DisplayWithListner( - this.av, - "Deplacer un etudiant", - 350, - 400, - this.av.getX(), - this.av.getY(), - this.createJTable(data, titre) - ); - } - - else if(Objects.equals(command, "crtll::ActionMoveGrup")) { - // TODO: CHANGE GROUPE - db.updateRow("UPDATE fi_eleves SET "); - - JOptionPane.showMessageDialog( - this.currentModal, - this.tmpStud[0] + " " + this.tmpStud[1] + " a bien ete deplace dans le " + this.list.getSelectedItem(), - "Deplacement effectue", - JOptionPane.INFORMATION_MESSAGE - ); - } - } - - @Override - public void valueChanged(ListSelectionEvent e) { - if(!e.getValueIsAdjusting()) { - int[] cell = this.currentJTableUse.getSelectedRows(); - int collumnCount = this.currentJTableUse.getColumnCount(); - Object value; - System.out.println(e.getSource()); - - if(cell.length > 0) { - for(int i = 0; i < collumnCount; i++) { - TableModel tm = this.currentJTableUse.getModel(); - value = tm.getValueAt(cell[0], i); - - if(Objects.equals(value, "[DEPLACER]")) { - JPanel forModal = new JPanel(new GridBagLayout()); - BLayout settings = new BLayout(); - this.tmpStud = new String[] { - (String) tm.getValueAt(cell[0], 0), - (String) tm.getValueAt(cell[0], 1) - }; - - settings.setPositionX(0); - settings.setPositionY(0); - JLabel intro = new JLabel( - "Deplacer " + tm.getValueAt(cell[0], 0) + " " + - tm.getValueAt(cell[0], 1) + - " dans le groupe : " - ); - forModal.add(intro, settings); - - settings.setPositionX(1); - settings.setPositionY(0); - forModal.add(new JLabel(" "), settings); - - settings.setPositionX(2); - settings.setPositionY(0); - forModal.add(new JLabel(" "), settings); - - settings.setPositionX(3); - settings.setPositionY(0); - - this.list = new JComboBox<>(); - - for (Groupe groupe : this.g) { - this.list.addItem(groupe.getName()); - } - - forModal.add(list, settings); - - settings.setPositionX(4); - settings.setPositionY(0); - forModal.add(new JLabel(" "), settings); - - settings.setPositionX(5); - settings.setPositionY(0); - forModal.add(new JLabel(" "), settings); - - settings.setPositionX(6); - settings.setPositionY(0); - JButton moveBtn = new JButton("Deplacer"); - moveBtn.setActionCommand("crtll::ActionMoveGrup"); - moveBtn.addActionListener(this); - forModal.add(moveBtn, settings); - - DisplayModal( - this.av, - "Deplacer l'eleve : " - + tm.getValueAt(cell[0], 0) + " " + tm.getValueAt(cell[0], 1), - 500, - 250, - this.av.getX(), - this.av.getY(), - forModal - ); - } - } - } - } - } +package Test; + +import API.Etudiant; +import API.Groupe; + +// TODO: Trier ca pour faire un import par package utilises (j'ai eu la flemme de le faire) +import javax.swing.*; +import java.awt.*; + +import javax.swing.event.ListSelectionEvent; +import javax.swing.event.ListSelectionListener; +import javax.swing.table.TableModel; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.util.ArrayList; +import java.util.Objects; + +public class Controller implements ActionListener, ListSelectionListener { + private final BDatabase db; + + private final ProfView pv; + private final AdminView av; + private BFrame currentModal; + + private ArrayList e; + private ArrayList g; + + private JTable currentJTableUse; + private JComboBox list; + + private ArrayList tmpStud; + + public Controller(BDatabase db) { + this.db = db; + this.e = this.db.getEtuList(); + this.g = this.db.getGroupeList(); + + // Les 3 fenetres s'ouvriront en meme temps (Pour le contexte du projet) + this.pv = new ProfView(e, g, this); + System.out.println("[+] Demarrage de la vue professeur -> " + pv); + this.av = new AdminView(e, g, this); + System.out.println("[+] Demarrage de la vue Administrateur -> " + av); + } + + /** + * Pour creer une JTable + * @param data Les donnees + * @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) { + return false; + } + }; + } + + /** + * Pour afficher une JTable sans listener + * + * @param parent La fenetre qui sera bloque + * @param frameTitle Le titre de la fenetre + * @param size_x Taille en x + * @param size_y Taille en y + * @param loca_x Localisation en x + * @param loca_y Localisation en y + * @param liste La JTable + * */ + private void Display(BFrame parent, String frameTitle, int size_x, int size_y, int loca_x, int loca_y, JTable liste) { + JPanel forModal = new JPanel(); + + ListSelectionModel lsm = liste.getSelectionModel(); + liste.getTableHeader().setReorderingAllowed(false); + liste.setFillsViewportHeight(true); + + this.currentJTableUse = liste; + + forModal.add(liste); + + BFrame frame = new BFrame(frameTitle, loca_x, loca_y, size_x, size_y, parent, forModal); + } + + /** + * Pour afficher une JTable contenant un listener + * + * @param parent La fenetre qui sera bloque + * @param frameTitle Le titre de la fenetre + * @param size_x Taille en x + * @param size_y Taille en y + * @param loca_x Localisation en x + * @param loca_y Localisation en y + * @param liste La JTable + * */ + private void DisplayWithListner(BFrame parent, String frameTitle, int size_x, int size_y, int loca_x, int loca_y, JTable liste) { + JPanel forModal = new JPanel(); + + ListSelectionModel lsm = liste.getSelectionModel(); + lsm.addListSelectionListener(this); + liste.getTableHeader().setReorderingAllowed(false); + liste.setFillsViewportHeight(true); + + this.currentJTableUse = liste; + + forModal.add(liste); + + BFrame frame = new BFrame(frameTitle, loca_x, loca_y, size_x, size_y, parent, forModal); + } + + /** + * Pour afficher une modale classique pour plus de liberte (panel a creer au prealable) + * + * @param parent La fenetre qui sera bloque + * @param frameTitle Le titre de la fenetre + * @param size_x Taille en x + * @param size_y Taille en y + * @param loca_x Localisation en x + * @param loca_y Localisation en y + * @param forModal Le panel a mettre dans la fenetre (libre) + * */ + private void DisplayModal(BFrame parent, 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, parent, forModal); + } + + @Override + public void actionPerformed(ActionEvent e) { + String command = e.getActionCommand(); + + String groupeOption = this.pv.getComboSelection(); + int groupeIndex = this.pv.getComboSelectionIndex(); + String text = this.pv.getSearchStud(); + + this.e = this.db.getEtuList(); + + if(Objects.equals(command, "pv::GetStudList")) { + String[][] data = new String[this.e.size()][2]; + + String[] titre = { + "Nom", + "Prenom", + "Groupe" + }; + + for(int i = 0; i <= this.e.size()-1; i++) { + String[] info = { + this.e.get(i).getNom(), + this.e.get(i).getPrenom(), + String.valueOf(this.e.get(i).getGroupe()) + }; + + data[i] = info; + } + + Display( + this.pv, + "Liste des etudiants", + 350, + 400, + this.pv.getX(), + this.pv.getY(), + this.createJTable(data, titre) + ); + } + + else if(Objects.equals(command, "pv::GetListFiltered")) { + String[][] data = new String[this.e.size()][1]; + + String[] titre = { + "Nom", + "Prenom" + }; + + int i, j; + + for(i = 0, j = 0; i <= this.e.size()-1; i++) { + if(this.e.get(i).getGroupe() == groupeIndex) { + String[] info = { + this.e.get(i).getNom(), + this.e.get(i).getPrenom() + }; + + data[j] = info; + j++; + } + } + + String[][] data_final = new String[j][1]; + for(int x = 0; x <= j-1; x++) { + data_final[x] = data[x]; + } + + Display( + this.pv, + "Liste d'eleve du " + groupeOption, + 350, + 400, + this.pv.getX(), + this.pv.getY(), + this.createJTable(data_final, titre) + ); + } + + else if(Objects.equals(command, "pv::SearchStudentPer3Letters")) { + if(text.length() < 3 || text == null) { + JOptionPane.showMessageDialog( + this.pv, + "Veuillez ecrire 3 lettres", + "Erreur.", + JOptionPane.ERROR_MESSAGE + ); + } else { + char[] beg = text.toCharArray(); + + ArrayList filtreEleveNom = db.fetchAll("SELECT nom FROM fi_eleves WHERE nom LIKE '" + beg[0] + beg[1] + beg[2] + "%'"); + ArrayList filtreElevePrenom = db.fetchAll("SELECT prenom FROM fi_eleves WHERE nom LIKE '" + beg[0] + beg[1] + beg[2] + "%'"); + ArrayList 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()); + + if(filtreEleveGroupe.size() == 0 || filtreEleveNom.size() == 0 || filtreElevePrenom.size() == 0) { + JOptionPane.showMessageDialog( + this.pv, + "Eleve introuvable !", + "Erreur.", + JOptionPane.ERROR_MESSAGE + ); + } else { + String[] titre = { + "Nom", + "Prenom", + "Groupe" + }; + + String[][] data = new String[filtreEleveNom.size()][2]; + + for(int i = 0; i <= filtreEleveNom.size()-1; i++){ + data[i] = new String[]{ + filtreEleveNom.get(i), + filtreElevePrenom.get(i), + String.valueOf(filtreEleveGroupe.get(i)) + }; + } + + Display( + this.pv, + "Recherche", + 350, + 400, + this.pv.getX(), + this.pv.getY(), + this.createJTable(data, titre) + ); + } + } + } + + else if(Objects.equals(command, "av::MoveStudGrup")) { + Object[][] data = new Object[this.e.size()][3]; + + String[] titre = { + "Nom", + "Prenom", + "Groupe", + "Action" + }; + + for(int i = 0; i <= this.e.size()-1; i++) { + Object[] info = { + this.e.get(i).getNom(), + this.e.get(i).getPrenom(), + String.valueOf(this.e.get(i).getGroupe()), + "[DEPLACER]" + }; + + data[i] = info; + } + + DisplayWithListner( + this.av, + "Deplacer un etudiant", + 350, + 400, + this.av.getX(), + this.av.getY(), + this.createJTable(data, titre) + ); + } + + else if(Objects.equals(command, "crtll::ActionMoveGrup")) { + this.tmpStud.add(String.valueOf(this.list.getSelectedIndex())); + + String query = + "UPDATE fi_eleves SET groupe=" + this.tmpStud.get(2) + + " WHERE nom='" + this.tmpStud.get(0) + + "' 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(), + "Deplacement effectue", + JOptionPane.INFORMATION_MESSAGE + ); + + this.e = this.db.getEtuList(); + + 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 deplacement", + JOptionPane.ERROR_MESSAGE + ); + } + } + } + + @Override + public void valueChanged(ListSelectionEvent e) { + if(!e.getValueIsAdjusting()) { + int[] cell = this.currentJTableUse.getSelectedRows(); + int collumnCount = this.currentJTableUse.getColumnCount(); + Object value; + + if(cell.length > 0) { + for(int i = 0; i < collumnCount; i++) { + TableModel tm = this.currentJTableUse.getModel(); + value = tm.getValueAt(cell[0], i); + + if(Objects.equals(value, "[DEPLACER]")) { + JPanel forModal = new JPanel(new GridBagLayout()); + BLayout settings = new BLayout(); + + this.tmpStud = new ArrayList<>(); + this.tmpStud.add((String) tm.getValueAt(cell[0], 0)); + this.tmpStud.add((String) tm.getValueAt(cell[0], 1)); + + settings.setPositionX(0); + settings.setPositionY(0); + JLabel intro = new JLabel( + "Deplacer " + tm.getValueAt(cell[0], 0) + " " + + tm.getValueAt(cell[0], 1) + + " dans le groupe : " + ); + forModal.add(intro, settings); + + settings.setPositionX(1); + settings.setPositionY(0); + forModal.add(new JLabel(" "), settings); + + settings.setPositionX(2); + settings.setPositionY(0); + forModal.add(new JLabel(" "), settings); + + settings.setPositionX(3); + settings.setPositionY(0); + + this.list = new JComboBox<>(); + + for(Groupe groupe : this.g) { + this.list.addItem(groupe.getName()); + } + + forModal.add(list, settings); + + settings.setPositionX(4); + settings.setPositionY(0); + forModal.add(new JLabel(" "), settings); + + settings.setPositionX(5); + settings.setPositionY(0); + forModal.add(new JLabel(" "), settings); + + settings.setPositionX(6); + settings.setPositionY(0); + JButton moveBtn = new JButton("Deplacer"); + moveBtn.setActionCommand("crtll::ActionMoveGrup"); + moveBtn.addActionListener(this); + forModal.add(moveBtn, settings); + + DisplayModal( + this.av, + "Deplacer l'eleve : " + + tm.getValueAt(cell[0], 0) + " " + tm.getValueAt(cell[0], 1), + 500, + 250, + this.av.getX(), + this.av.getY(), + forModal + ); + } + } + } + } + } } \ No newline at end of file diff --git a/src/Test/TestTexteMNP.java b/src/Test/TestTexteMNP.java index f0bf283..ff6ca8e 100644 --- a/src/Test/TestTexteMNP.java +++ b/src/Test/TestTexteMNP.java @@ -1,7 +1,6 @@ package Test; import API.*; -import MNP.*; import java.util.ArrayList; public class TestTexteMNP { @@ -9,73 +8,11 @@ public class TestTexteMNP { /** * Objet de la base de donnee contenant des methodes utile a notre developpement * */ - BDatabase bd = new BDatabase(); - - /** - * Chargement des eleves - * */ - ArrayList listEtu = new ArrayList<>(); - ArrayList studPrenom = bd.fetchAll("SELECT prenom FROM fi_eleves"); - ArrayList studNom = bd.fetchAll("SELECT nom FROM fi_eleves"); - ArrayList studGroupe = bd.fetchAll("SELECT groupe FROM fi_eleves"); - - for(int i = 0; i <= studPrenom.size()-1; i++) { - if(studPrenom.get(i) != null && studNom.get(i) != null && studGroupe.get(i) != null) { - try { - listEtu.add( - new EtudiantNP( - studNom.get(i), - studPrenom.get(i), - Integer.parseInt(studGroupe.get(i), 10) - ) - ); - } catch(NumberFormatException ignore) { - listEtu.add( - new EtudiantNP( - studNom.get(i), - studPrenom.get(i), - -1 - ) - ); - } - } else { - System.out.println("[!] Erreur lors du chargement de la liste des etudiants."); - System.exit(-1); - } - } - - System.out.println("[+] Liste des etudiants chargees."); - - /** - * Chargement des groupes - * */ - ArrayList listGroupe = new ArrayList<>(); - ArrayList groupeId = bd.fetchAll("SELECT id FROM fi_groupe"); - ArrayList groupeNom = bd.fetchAll("SELECT nom FROM fi_groupe"); - ArrayList groupeMin = bd.fetchAll("SELECT min FROM fi_groupe"); - ArrayList groupeMax = bd.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) { - 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) - ) - ); - } else { - System.out.println("[!] Erreur lors du chargement de la liste des groupes."); - System.exit(-1); - } - } - - System.out.println("[+] Liste des groupes chargees."); + BDatabase db = new BDatabase(); /** * Demarrage de l'appli * */ - Controller listener = new Controller(listEtu, listGroupe); + Controller listener = new Controller(db); } }