2022-11-15 17:38:45 +01:00
|
|
|
package Test;
|
|
|
|
|
|
|
|
import API.*;
|
|
|
|
import MNP.*;
|
2022-11-15 17:53:53 +01:00
|
|
|
import javax.swing.JComboBox;
|
|
|
|
import javax.swing.JTextField;
|
|
|
|
import javax.swing.JButton;
|
|
|
|
import javax.swing.JLabel;
|
|
|
|
import javax.swing.JTable;
|
2022-11-15 18:28:51 +01:00
|
|
|
import javax.swing.JOptionPane;
|
2022-11-15 17:53:53 +01:00
|
|
|
import javax.swing.JScrollPane;
|
|
|
|
import java.awt.Dimension;
|
|
|
|
import java.awt.Insets;
|
|
|
|
import java.awt.GridBagConstraints;
|
|
|
|
import java.awt.event.ActionListener;
|
|
|
|
import java.awt.event.ActionEvent;
|
|
|
|
import java.awt.event.KeyAdapter;
|
|
|
|
import java.awt.event.KeyEvent;
|
2022-11-15 18:28:51 +01:00
|
|
|
import java.sql.SQLException;
|
2022-11-15 17:38:45 +01:00
|
|
|
import java.util.ArrayList;
|
|
|
|
|
|
|
|
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);
|
2022-11-15 18:57:04 +01:00
|
|
|
settings.setPositionY(6);
|
2022-11-15 17:38:45 +01:00
|
|
|
|
|
|
|
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);
|
2022-11-15 17:53:53 +01:00
|
|
|
settings.setPadding(new Insets(0, 0, 0, 50));
|
2022-11-15 17:38:45 +01:00
|
|
|
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);
|
2022-11-15 17:53:53 +01:00
|
|
|
settings.setPadding(new Insets(0, 0, 0, 0));
|
2022-11-15 17:38:45 +01:00
|
|
|
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);
|
2022-11-15 17:53:53 +01:00
|
|
|
settings.setPadding(new Insets(0, 0, 0, 50));
|
2022-11-15 17:38:45 +01:00
|
|
|
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);
|
2022-11-15 17:53:53 +01:00
|
|
|
settings.setPadding(new Insets(0, 0, 0, 0));
|
2022-11-15 17:38:45 +01:00
|
|
|
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") {
|
2022-11-15 18:28:51 +01:00
|
|
|
if(this.text.getText().length() < 3 || this.text.getText() == null) {
|
|
|
|
JOptionPane.showMessageDialog(
|
|
|
|
this,
|
|
|
|
"Veuillez ecrire au moins 3 lettres",
|
|
|
|
"Erreur.",
|
|
|
|
JOptionPane.ERROR_MESSAGE
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
char[] beg = this.text.getText().toCharArray();
|
|
|
|
|
|
|
|
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
|
|
|
|
);
|
|
|
|
|
|
|
|
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());
|
|
|
|
|
|
|
|
if(filtreEleveGroupe.size() == 0 || filtreEleveNom.size() == 0 || filtreElevePrenom.size() == 0) {
|
|
|
|
JOptionPane.showMessageDialog(
|
|
|
|
this,
|
|
|
|
"Eleve introuvable !",
|
|
|
|
"Erreur.",
|
|
|
|
JOptionPane.ERROR_MESSAGE
|
|
|
|
);
|
|
|
|
|
|
|
|
frame.closeBFrame();
|
|
|
|
} else {
|
|
|
|
String[] titre = {
|
|
|
|
"Nom",
|
|
|
|
"Prenom",
|
|
|
|
"Groupe"
|
|
|
|
};
|
2022-11-15 17:38:45 +01:00
|
|
|
|
2022-11-15 18:28:51 +01:00
|
|
|
String[][] data = new String[filtreEleveNom.size()][2];
|
2022-11-15 17:38:45 +01:00
|
|
|
|
2022-11-15 18:28:51 +01:00
|
|
|
for(int i = 0; i <= filtreEleveNom.size()-1; i++){
|
|
|
|
data[i] = new String[]{
|
|
|
|
filtreEleveNom.get(i),
|
|
|
|
filtreElevePrenom.get(i),
|
|
|
|
String.valueOf(filtreEleveGroupe.get(i))
|
|
|
|
};
|
|
|
|
}
|
2022-11-15 17:38:45 +01:00
|
|
|
|
2022-11-15 18:28:51 +01:00
|
|
|
JTable liste = new JTable(data, titre) {
|
|
|
|
public boolean editCellAt(int row, int column, java.util.EventObject e) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
};
|
2022-11-15 17:38:45 +01:00
|
|
|
|
2022-11-15 18:28:51 +01:00
|
|
|
liste.getTableHeader().setReorderingAllowed(false);
|
|
|
|
liste.setFillsViewportHeight(true);
|
2022-11-15 17:38:45 +01:00
|
|
|
|
2022-11-15 18:28:51 +01:00
|
|
|
JScrollPane scroll = new JScrollPane(liste);
|
|
|
|
frame.getContentPane().add(scroll);
|
2022-11-15 17:38:45 +01:00
|
|
|
|
2022-11-15 18:28:51 +01:00
|
|
|
frame.openBFrame();
|
2022-11-15 17:38:45 +01:00
|
|
|
}
|
2022-11-15 18:28:51 +01:00
|
|
|
}
|
2022-11-15 17:38:45 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|