This commit is contained in:
pro.boooooo
2022-11-15 17:38:45 +01:00
parent be835c9cb7
commit 818035d374
101 changed files with 12432 additions and 0 deletions

178
src/Test/BDatabase.java Normal file
View File

@@ -0,0 +1,178 @@
package Test;
/* [BPakage.BDatabase]
* Desc: To create Operationnal Database Link fast :)
* GitHub: https://github.com/lalBi94
* Created by: Bilal Boudjemline
* 28/09/2022 at 20:35
* */
import java.sql.*;
import java.sql.Connection;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Iterator;
import org.mariadb.jdbc.*;
/**
* <p>Methodes pour les interaction avec une base de donnees</p>
*
* @author <a href="https://github.com/lalBi94">Bilal Boudjemline</a>
*/
public class BDatabase {
private final String db_host;
private final String db_name;
private final String db_user;
private final String db_password;
protected Connection sharedObject;
private boolean status;
public BDatabase() {
this.db_host = "jdbc:mariadb://dwarves.iut-fbleau.fr/";
this.db_name = "brinet";
this.db_user = "brinet";
this.db_password = "Aignan41!";
try {
Class.forName("org.mariadb.jdbc.Driver");
} catch(ClassNotFoundException e) {
e.printStackTrace();
}
try {
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.");
}
}
/**
* Recuperer les informations d'un requete de type SELECT.
*
* @param request Le SELECT a faire (il y aura plus d'argument prochainement)
* @return Les resultats engendre par la requete
*/
public ArrayList<String> fetchAll(String request) {
try {
ArrayList<String> toReturn = new ArrayList<String>();
ResultSet rs = this.sharedObject.prepareStatement(request).executeQuery();
for(int i = 0; rs.next(); i++) {
toReturn.add(i, String.valueOf(rs.getString(1)));
}
return toReturn;
} catch(SQLException e) {
System.out.println("Erreur de la requete : " + e);
return null;
}
}
/**
* Insert une ligne dans une table.
*
* @param table La table
* @param col Tableau qui contient les colonnes d'affectation
* @param value Valeur des colonnes
* @return Retourne true si ca a reussit et false dans le cas inverse
*/
public boolean insertRow(String table, String[] col, String[] value) {
StringBuilder collumns = new StringBuilder();
StringBuilder values = new StringBuilder();
Iterator<String> iteCol = Arrays.stream(col).iterator();
Iterator<String> iteVal = Arrays.stream(value).iterator();
collumns.append("(");
while(iteCol.hasNext()) {
collumns.append(iteCol.next()).append(", ");
}
collumns.setLength(collumns.length()-2);
collumns.append(")");
values.append("(");
while(iteVal.hasNext()) {
values.append("\"").append(iteVal.next()).append("\"").append(", ");
}
values.setLength(values.length()-2);
values.append(")");
String request = "INSERT INTO " + table + collumns + " VALUES" + values + ";";
System.out.println(request);
try {
this.sharedObject.prepareStatement(request).executeQuery();
System.out.println("Succes: " + request);
return true;
} catch(SQLException e) {
return false;
}
}
/**
* 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
*/
public boolean updateRow(String request) {
try {
this.sharedObject.prepareStatement(request).executeQuery();
System.out.println("Succes: " + request);
return true;
} catch(SQLException e) {
return false;
}
}
/**
* Recuperer l'objet Connection pour pouvoir utiliser ses methodes.
*
* @return L 'objet Connection.
*/
public Connection getSharedObject() {
return this.sharedObject;
}
/**
* Recuperer l'utilisateur courant.
*
* @return L 'utilisateur.
*/
public String getUser() {
return this.db_user;
}
/**
* Recuperer l'hote courant.
*
* @return L 'hote.
*/
public String getHost() {
return this.db_host;
}
/**
* Recuperer le nom de la base de donnees.
*
* @return Le nom de la base de donnees.
*/
public String getDatabaseName() {
return this.db_name;
}
/**
* Recuperer le status de connection.
*
* @return Le status de connection.
*/
public boolean getStatus() {
return this.status;
}
@Override
public String toString() {
return this.db_host + "\n" + this.db_name + "\n" + this.db_user + "\n";
}
}

174
src/Test/BFrame.java Normal file
View File

@@ -0,0 +1,174 @@
package Test;
/* [BPackage.BFrame]
* Desc: To create Operationnal JFrame with utils methods fast :)
* GitHub: https://github.com/lalBi94
* Created by: Bilal Boudjemline
* 28/09/2022 at 20:35
* */
import javax.swing.JFrame;
import javax.swing.SwingUtilities;
import javax.swing.ImageIcon;
import java.awt.GridBagLayout;
import java.awt.GridLayout;
import java.awt.event.WindowEvent;
/**
* <p>Pour creer une fenetre rapidement avec les methodes simplifier</p>
*
* @author <a href="https://github.com/lalBi94">Bilal Boudjemline</a>
*/
public class BFrame extends JFrame {
private final String title;
private int location_x = 1;
private int location_y = 1;
private int width = 500;
private int height = 500;
private int killProcess = 3;
private boolean isOpen = false;
/**
* Avec le titre et mode de fermeture.
*
* @param title Le titre de la fenetre
* @param oC Mode de fermeture de la fenetre
*/
public BFrame(String title, int oC) {
this.title = title;
this.killProcess = oC;
initBFrame();
}
/**
* Avec le titre, la taille (en L et l) et mode de fermeture.
*
* @param titlee Le titre de la fenetre
* @param size_x La longueur de la fenetre
* @param size_y La largeur y de la fenetre
* @param oC Mode de fermeture de la fenetre
*/
public BFrame(String titlee, int size_x, int size_y, int oC) {
this.title = titlee;
this.width = size_x;
this.height = size_y;
this.killProcess = oC;
initBFrame();
}
/**
* Avec le titre, la locasation (en x et y), la taille (en L et l) et mode de fermeture.
*
* @param title Le titre de la fenetre
* @param loca_x La localisation en x de la fenetre
* @param loca_y La localisation en y de la fenetre
* @param size_x La longueur de la fenetre
* @param size_y La largeur de la fenetre
* @param oC Mode de fermeture de la fenetre
*/
public BFrame(String title, int loca_x, int loca_y, int size_x, int size_y, int oC) {
this.title = title;
this.location_x = loca_x;
this.location_y = loca_y;
this.width = size_x;
this.height = size_y;
this.killProcess = oC;
initBFrame();
}
/**
* Avec le titre, la locasation (en x et y), la taille (en L et l), le layout et le mode de fermeture.
*
* @param title Le titre de la fenetre
* @param loca_x La localisation en x de la fenetre
* @param loca_y La localisation en y de la fenetre
* @param size_x La longueur de la fenetre
* @param size_y La largeur de la fenetre
* @param layout Layout a utiliser dispo : GridBagLayout / GridLayout
* @param layout_row the layout row
* @param layout_col the layout col
* @param oC Mode de fermeture de la fenetre
*/
public BFrame(String title, int loca_x, int loca_y, int size_x, int size_y, String layout, int layout_row, int layout_col, int oC) {
this.title = title;
this.location_x = loca_x;
this.location_y = loca_y;
this.width = size_x;
this.height = size_y;
this.killProcess = oC;
initBFrame(layout, layout_row, layout_col);
}
/**
* Initialiser la fenetre sans Layout par def.
*/
protected void initBFrame() {
ImageIcon icon = new ImageIcon("assets/logo.png");
this.setTitle(this.title);
this.setLocation(this.location_x, this.location_y);
this.setSize(this.width, this.height);
this.setLayout(new GridBagLayout());
this.setIconImage(icon.getImage());
this.setDefaultCloseOperation(this.killProcess);
}
/**
* Initialiser la fenetre avec Layout
*
* @param layout the layout
* @param row the row
* @param col the col
*/
protected void initBFrame(String layout, int row, int col) {
ImageIcon icon = new ImageIcon("assets/logo.png");
this.setTitle(this.title);
this.setLocation(this.location_x, this.location_y);
this.setSize(this.width, this.height);
if(layout == "GridLayout") {
this.setLayout(new GridLayout(row, col));
} else {
System.out.println("Un layout doit etre fourni.");
}
this.setIconImage(icon.getImage());
this.setDefaultCloseOperation(this.killProcess);
}
/**
* Ouvrir la fenetre
*/
public void openBFrame() {
this.isOpen = true;
this.setVisible(true);
}
/**
* Fermer la fenetre
*/
public void closeBFrame() {
this.isOpen = false;
this.setVisible(false);
this.dispatchEvent(new WindowEvent(this, WindowEvent.WINDOW_CLOSING));
}
/**
* Rafraichir la fenetre
*/
public void refreshBFrame() {
SwingUtilities.updateComponentTreeUI(this);
}
/**
* Statut de visibilite de la fenetre
*/
public boolean isVisible() {
return this.isOpen;
}
@Override
public String toString() {
return this.title + ": is opened";
}
}

171
src/Test/BLayout.java Normal file
View File

@@ -0,0 +1,171 @@
package Test;
/* [BPakage.BLayout]
* Desc: To create a layout fast :)
* GitHub: https://github.com/lalBi94
* Created by: Bilal Boudjemline
* 28/09/2022 at 20:35
* */
import java.awt.GridBagConstraints;
import java.awt.Insets;
/**
* <p>Pour creer un layout de type GridBagLayout rapidement avec les methodes simplifier.</p>
*
* @author <a href="https://github.com/lalBi94">Bilal Boudjemline</a>
*/
public class BLayout extends GridBagConstraints {
public int PositionOnX = 0;
public int PositionOnY = 0;
public int takeCaseOnX = 1;
public int takeCaseOnY = 1;
public double sizeOnX = 0.0f;
public double sizeOnY = 0.0f;
public int padding_top = 1;
public int padding_left = 1;
public int padding_bottom = 1;
public int padding_right = 1;
public Insets padding = new Insets(this.padding_top, this.padding_left, this.padding_bottom, this.padding_right);
public int positionOnScreen = GridBagConstraints.NORTH;
public int filler = GridBagConstraints.BASELINE;
public BLayout() {
initLayout();
}
/**
* @param positionX Position en X.
* @param positionY Position en y.
* @param manyCaseX Combien le component prend de case en x.
* @param manyCaseY Combien le component prend de case en y.
* @param sizeX Taille en double en x.
* @param sizeY Taille en double en y.
* @param pad Le padding.
* @param positionOnScreen La position sur la frame (centre, north etc...).
* @param filling Remplissage (H, V, B).
*/
public BLayout(int positionX, int positionY, int manyCaseX, int manyCaseY, double sizeX,
double sizeY, Insets pad, int positionOnScreen, int filling) {
this.PositionOnX = positionX;
this.PositionOnY = positionY;
this.takeCaseOnX = manyCaseX;
this.takeCaseOnY = manyCaseY;
this.sizeOnX = sizeX;
this.sizeOnY = sizeY;
this.padding_top = pad.top;
this.padding_left = pad.left;
this.padding_bottom = pad.bottom;
this.padding_right = pad.right;
this.padding = pad;
this.positionOnScreen = positionOnScreen;
this.filler = filling;
initLayout();
}
/**
* Initialiser le layout pour le changer dans GridBagConstraint (Valeur attribuer par def.).
* */
private void initLayout() {
this.gridx = this.PositionOnX;
this.gridy = this.PositionOnY;
this.gridheight = this.takeCaseOnX;
this.gridwidth = this.takeCaseOnY;
this.weightx = this.sizeOnX;
this.weighty = this.sizeOnY;
this.insets = this.padding;
this.anchor = this.positionOnScreen;
this.fill = this.filler;
}
/**
* Changer le cuseur en x.
*
* @param by par quoi
*/
public void setPositionX(int by) {
this.PositionOnX = by;
initLayout();
}
/**
* Changer le cuseur en y.
*
* @param by par quoi
*/
public void setPositionY(int by) {
this.PositionOnY = by;
initLayout();
}
/**
* Changer la place occupe en x.
*
* @param by par quoi
*/
public void setTakeCaseOnX(int by) {
this.takeCaseOnX = by;
initLayout();
}
/**
* Changer la place occupe en y.
*
* @param by par quoi
*/
public void setTakeCaseOnY(int by) {
this.takeCaseOnY = by;
initLayout();
}
/**
* Mettre sa taille en x.
*
* @param by par quoi
*/
public void setSizeX(double by) {
this.sizeOnX = by;
initLayout();
}
/**
* Mettre sa taille en y.
*
* @param by par quoi
*/
public void setSizeY(double by) {
this.sizeOnY = by;
initLayout();
}
/**
* Mettre un padding.
*
* @param by par quoi
*/
public void setPadding(Insets by) {
this.padding = by;
initLayout();
}
/**
* Mettre une ancre.
*
* @param by par quoi
*/
public void setAnchor(int by) {
this.positionOnScreen = by;
initLayout();
}
/**
* Mettre un remplissage.
*
* @param by par quoi
*/
public void setFill(int by) {
this.filler = by;
initLayout();
}
}

266
src/Test/ProfView.java Normal file
View File

@@ -0,0 +1,266 @@
package Test;
import API.*;
import MNP.*;
import java.awt.*;
import java.awt.event.*;
import java.util.ArrayList;
import javax.swing.*;
public class ProfView extends BFrame implements ActionListener {
private final ArrayList<Etudiant> e;
private final ArrayList<Groupe> g;
private JComboBox groupeOption;
private JTextField text;
private BDatabase db;
public ProfView(ArrayList<Etudiant> e, ArrayList<Groupe> g, BDatabase db) {
super(
"Vue professeur",
1,
1,
500,
500,
3
);
this.e = e;
this.g = g;
this.db = db;
Display();
}
public void Display() {
BLayout settings = new BLayout();
settings.setPositionX(0);
settings.setPositionY(3);
settings.setPositionY(0);
JButton studList = new JButton("Voir la liste des etudiants");
studList.setActionCommand("fi::GetStudList");
studList.addActionListener(this);
this.add(studList, settings);
settings.setPositionY(1);
this.add(new JLabel(" "), settings);
settings.setPositionY(2);
JLabel gs = new JLabel("Afficher les etudiants se trouvant dans le groupe :");
this.add(gs, settings);
settings.setPositionY(3);
String[] groupeList = new String[this.g.size()];
for(int i = 0; i <= this.g.size()-1; i++) {
groupeList[i] = this.g.get(i).getName();
}
this.groupeOption = new JComboBox(groupeList);
this.groupeOption.setPreferredSize(new Dimension(110, 30));
this.add(groupeOption, settings);
settings.setPositionY(3);
settings.setAnchor(GridBagConstraints.EAST);
JButton confirm = new JButton("Rechercher");
confirm.setActionCommand("fi::GetListFiltered");
confirm.addActionListener(this);
this.add(confirm, settings);
settings.setAnchor(GridBagConstraints.CENTER);
settings.setPositionY(4);
this.add(new JLabel(" "), settings);
settings.setPositionY(5);
JLabel pf = new JLabel("Rechercher un etudiant : ");
this.add(pf, settings);
settings.setPositionY(6);
this.text = new JTextField();
this.text.setPreferredSize(new Dimension(110, 30));
text.addKeyListener(new KeyAdapter() {
public void keyTyped(KeyEvent e) {
if (text.getText().length() >= 3 ) // limit textfield to 3 characters
e.consume();
}
});
this.add(this.text, settings);
settings.setPositionY(6);
settings.setAnchor(GridBagConstraints.EAST);
JButton searchTLetters = new JButton("Rechercher");
searchTLetters.addActionListener(this);
searchTLetters.setActionCommand("fi::SearchStudentPer3Letters");
this.add(searchTLetters, settings);
this.openBFrame();
this.refreshBFrame();
}
@Override
public void actionPerformed(ActionEvent e) {
String command = e.getActionCommand();
if (command == "fi::GetStudList") {
BFrame frame = new BFrame(
"Liste des eleves",
1,
1,
500,
500,
"GridLayout",
1,
1,
2
);
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;
}
JTable liste = new JTable(data, titre) {
public boolean editCellAt(int row, int column, java.util.EventObject e) {
return false;
}
};
liste.getTableHeader().setReorderingAllowed(false);
liste.setFillsViewportHeight(true);
JScrollPane scroll = new JScrollPane(liste);
frame.getContentPane().add(scroll);
frame.openBFrame();
} else if(command == "fi::GetListFiltered") {
BFrame frame = new BFrame(
"Liste des eleves du " + this.groupeOption.getSelectedItem(),
1,
1,
500,
500,
"GridLayout",
1,
1,
2
);
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() == this.groupeOption.getSelectedIndex()) {
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];
}
JTable liste = new JTable(data_final, titre) {
public boolean editCellAt(int row, int column, java.util.EventObject e) {
return false;
}
};
liste.getTableHeader().setReorderingAllowed(false);
liste.setFillsViewportHeight(true);
JScrollPane scroll = new JScrollPane(liste);
frame.getContentPane().add(scroll);
frame.openBFrame();
} else if(command == "fi::SearchStudentPer3Letters") {
/**
* Faire l'interface du filtrage.
* */
char[] beg = this.text.getText().toCharArray();
ArrayList<Etudiant> listFiltered = new ArrayList<>();
char[] cur;
for(int i = 0; i <= this.e.size()-1; i++) {
cur = this.e.get(i).getNom().toCharArray();
if(cur[0] == beg[0] && cur[1] == beg[1] && cur[2] == beg[2]) {
listFiltered.add(new EtudiantNP(
this.e.get(i).getNom(),
this.e.get(i).getPrenom(),
this.e.get(i).getGroupe()
));
}
}
BFrame frame = new BFrame(
"Liste d'eleves d'ou les noms commence par " + beg[0] + beg[1] + beg[2],
1,
1,
500,
500,
"GridLayout",
1,
1,
2
);
String[] titre = {
"Nom",
"Prenom",
"Groupe"
};
String[][] data = new String[listFiltered.size()][2];
for(int i = 0; i <= listFiltered.size()-1; i++){
data[i] = new String[]{
this.e.get(i).getNom(),
this.e.get(i).getPrenom(),
String.valueOf(this.e.get(i).getGroupe())
};
}
JTable liste = new JTable(data, titre) {
public boolean editCellAt(int row, int column, java.util.EventObject e) {
return false;
}
};
liste.getTableHeader().setReorderingAllowed(false);
liste.setFillsViewportHeight(true);
JScrollPane scroll = new JScrollPane(liste);
frame.getContentPane().add(scroll);
frame.openBFrame();
frame.refreshBFrame();
}
}
}

View File

@@ -0,0 +1,70 @@
package Test;
import API.*;
import MNP.*;
import java.util.*;
public class TestTexteMNP {
public static void main(String[] args) {
/**
* Objet de la base de donnee contenant des methodes utile a notre developpement
* */
BDatabase bd = new BDatabase();
/**
* Chargement des eleves
* */
ArrayList<Etudiant> listEtu = new ArrayList<>();
ArrayList<String> studPrenom = bd.fetchAll("SELECT prenom FROM fi_eleves");
ArrayList<String> studNom = bd.fetchAll("SELECT nom FROM fi_eleves");
ArrayList<String> 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) {
listEtu.add(
new EtudiantNP(
studNom.get(i),
studPrenom.get(i),
Integer.parseInt(studGroupe.get(i), 10)
)
);
//System.out.println(listEtu.get(i).monPrint());
} 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<Groupe> listGroupe = new ArrayList<>();
ArrayList<String> groupeId = bd.fetchAll("SELECT id FROM fi_groupe");
ArrayList<String> groupeNom = bd.fetchAll("SELECT nom FROM fi_groupe");
ArrayList<String> groupeMin = bd.fetchAll("SELECT min FROM fi_groupe");
ArrayList<String> 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.");
new ProfView(listEtu, listGroupe, bd);
}
}

Binary file not shown.