$
This commit is contained in:
parent
3f25c14e3d
commit
fd6b0e8bad
@ -1,7 +1,7 @@
|
||||
package Test;
|
||||
|
||||
import API.Etudiant;
|
||||
import API.Groupe;
|
||||
import API.*;
|
||||
import MNP.*;
|
||||
|
||||
// TODO: Trier ca pour faire un import par package utilises (j'ai eu la flemme de le faire)
|
||||
import javax.swing.*;
|
||||
@ -29,14 +29,18 @@ public class Controller implements ActionListener, ListSelectionListener {
|
||||
|
||||
private JTable currentJTableUse;
|
||||
private JComboBox<String> list;
|
||||
private JComboBox<String> requestTypeSelector;
|
||||
|
||||
private JTextArea content;
|
||||
|
||||
private ArrayList<String> tmpStud;
|
||||
|
||||
private int x;
|
||||
|
||||
public Controller(BDatabase db) {
|
||||
this.db = db;
|
||||
this.e = this.db.getEtuList();
|
||||
this.g = this.db.getGroupeList();
|
||||
System.out.println(this.getMemberCount(-1) + " ");
|
||||
this.sv = new StudentView(this.e, this.g, this);
|
||||
this.pv = new ProfView(this.e, this.g, this);
|
||||
this.av = new AdminView(this.e, this.g, this);
|
||||
@ -47,7 +51,7 @@ public class Controller implements ActionListener, ListSelectionListener {
|
||||
*
|
||||
* Recuperer le nombre de membre d'un groupe
|
||||
*
|
||||
* @param groupe_id le groupes
|
||||
* @param id le groupes
|
||||
* @return le nombre de membre
|
||||
* */
|
||||
public int getMemberCount(int id) {
|
||||
@ -97,7 +101,6 @@ public class Controller implements ActionListener, ListSelectionListener {
|
||||
|
||||
this.parent.updateTable(liste);
|
||||
|
||||
|
||||
//forModal.add(liste);
|
||||
//BFrame frame = new BFrame(frameTitle, loca_x, loca_y, size_x, size_y, this.parent, forModal);
|
||||
}
|
||||
@ -146,12 +149,10 @@ public class Controller implements ActionListener, ListSelectionListener {
|
||||
@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();
|
||||
String groupeOption = this.pv.getComboSelection();
|
||||
int groupeIndex = 0;
|
||||
String text = this.pv.getSearchStud();
|
||||
|
||||
if(Objects.equals(command, "pv::GetStudList")) {
|
||||
String[][] data = new String[this.e.size()][2];
|
||||
@ -182,7 +183,15 @@ public class Controller implements ActionListener, ListSelectionListener {
|
||||
);
|
||||
}
|
||||
|
||||
else if(Objects.equals(command, "pv::GetListFiltered")) {
|
||||
else if(Objects.equals(command, "pv::GetListFiltered") ||
|
||||
Objects.equals(command, "sv::GetListFiltered")) {
|
||||
|
||||
if(Objects.equals(command, "pv::GetListFiltered")) {
|
||||
groupeIndex = this.pv.getComboSelectionIndex();
|
||||
} else {
|
||||
groupeIndex = this.sv.getComboSelectionIndex();
|
||||
}
|
||||
|
||||
String[][] data = new String[this.e.size()][1];
|
||||
|
||||
String[] titre = {
|
||||
@ -370,6 +379,157 @@ public class Controller implements ActionListener, ListSelectionListener {
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
else if(Objects.equals(command, "sv::GetGrup")) {
|
||||
String[][] data = new String[this.g.size()][];
|
||||
|
||||
String[] title = new String[] {
|
||||
"ID", "Nom", "Taille"
|
||||
};
|
||||
|
||||
for(int i = 0; i <= this.g.size()-1; i++) {
|
||||
data[i] = new String[]{
|
||||
String.valueOf(this.g.get(i).getId()),
|
||||
this.g.get(i).getName(),
|
||||
this.getMemberCount(i) + "/" + this.g.get(i).getMax()
|
||||
};
|
||||
}
|
||||
|
||||
DisplayWithListner(
|
||||
"Liste des groupes",
|
||||
350,
|
||||
400,
|
||||
this.sv.getX(),
|
||||
this.sv.getY(),
|
||||
this.createJTable(data, title)
|
||||
);
|
||||
}
|
||||
|
||||
else if(Objects.equals(command, "sv::MakeRequest")) {
|
||||
JPanel forModal = new JPanel(new GridBagLayout());
|
||||
BLayout settings = new BLayout();
|
||||
settings.setPositionY(0);
|
||||
settings.setPositionX(0);
|
||||
|
||||
/**
|
||||
* TODO:
|
||||
* - Demande de type...
|
||||
* - Vers quel groupe
|
||||
* - possible ou nn
|
||||
* - message
|
||||
* - Valider
|
||||
* */
|
||||
|
||||
settings.setPositionY(1);
|
||||
JLabel requestT = new JLabel("Dans quel groupe souhaitez-vous aller ?");
|
||||
forModal.add(requestT, settings);
|
||||
|
||||
settings.setPositionY(2);
|
||||
this.requestTypeSelector = new JComboBox<>();
|
||||
|
||||
for(int i = 0; i <= this.g.size()-1; i++) {
|
||||
this.requestTypeSelector.addItem(this.g.get(i).getName());
|
||||
}
|
||||
|
||||
forModal.add(this.requestTypeSelector, settings);
|
||||
|
||||
settings.setPositionY(3);
|
||||
forModal.add(new JLabel(" "), settings);
|
||||
|
||||
settings.setPositionY(4);
|
||||
this.content = new JTextArea();
|
||||
this.content.setPreferredSize(new Dimension(450, 250));
|
||||
forModal.add(this.content, settings);
|
||||
|
||||
settings.setPositionY(5);
|
||||
forModal.add(new JLabel(" "), settings);
|
||||
|
||||
settings.setPositionY(6);
|
||||
JButton confirmRequ = new JButton("Envoyer");
|
||||
confirmRequ.addActionListener(this);
|
||||
confirmRequ.setActionCommand("sv::SendRequest");
|
||||
forModal.add(confirmRequ, settings);
|
||||
|
||||
DisplayModal(
|
||||
"Veuillez entrer un message...",
|
||||
750,
|
||||
500,
|
||||
1,
|
||||
1,
|
||||
forModal
|
||||
);
|
||||
}
|
||||
|
||||
else if(Objects.equals(command, "sv::SendRequest")) {
|
||||
int groupe = (int) this.requestTypeSelector.getSelectedIndex();
|
||||
String message = this.content.getText();
|
||||
System.out.println(groupe);
|
||||
|
||||
// Etudiant qui est supposé utiliser cette vue
|
||||
Etudiant forTest = new EtudiantNP("Boudjemline", "Bilal", -1);
|
||||
int id = 115;
|
||||
int x = this.getMemberCount(-1);
|
||||
int type;
|
||||
int y = this.getMemberCount(groupe);
|
||||
|
||||
if(x > y || x == y) { // Type 1
|
||||
type = 1;
|
||||
} else { // Type 2
|
||||
type = 2;
|
||||
}
|
||||
|
||||
if(this.db.insertRow("fi_demandes", 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 requete a ete envoyer avec succes !",
|
||||
"Requete.",
|
||||
JOptionPane.INFORMATION_MESSAGE
|
||||
);
|
||||
} else {
|
||||
JOptionPane.showMessageDialog(
|
||||
this.sv,
|
||||
"Une erreur est survenue lors de l'envoie de votre message...\nVeuillez reesayer plus tard.",
|
||||
"Erreur avec la base de données.",
|
||||
JOptionPane.ERROR_MESSAGE
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
else if(Objects.equals(command, "sv::ShowRequest")) {
|
||||
JPanel forModal = new JPanel();
|
||||
int nbMessage;
|
||||
int moi = 115;
|
||||
|
||||
ArrayList<String> idm = this.db.fetchAll("SELECT id FROM fi_demandes WHERE id_eleve = " + moi);
|
||||
ArrayList<String> message = this.db.fetchAll("SELECT message FROM fi_demandes WHERE id_eleve = " + moi);
|
||||
ArrayList<String> statut = this.db.fetchAll("SELECT statut FROM fi_demandes WHERE id_eleve = " + moi);
|
||||
|
||||
Object[][] data = new Object[idm.size()][];
|
||||
|
||||
String[] title = new String[] {
|
||||
"ID", "Contenu", "Statut"
|
||||
};
|
||||
|
||||
for(int i = 0; i <= idm.size()-1; i++) {
|
||||
String[] info = {
|
||||
"#" + idm.get(i), message.get(i), statut.get(i)
|
||||
};
|
||||
|
||||
data[i] = info;
|
||||
}
|
||||
|
||||
Display(
|
||||
"Vos demandes",
|
||||
500,
|
||||
500,
|
||||
1,
|
||||
1,
|
||||
this.createJTable(data, title)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -485,13 +645,11 @@ public class Controller implements ActionListener, ListSelectionListener {
|
||||
return this.av;
|
||||
}
|
||||
|
||||
|
||||
public ArrayList<Etudiant> getEtudiants () {
|
||||
return this.e;
|
||||
}
|
||||
|
||||
|
||||
public ArrayList<Groupe> getGroupes() {
|
||||
return this.g;
|
||||
}
|
||||
}
|
||||
}
|
@ -18,7 +18,6 @@ public class StudentView extends JPanel {
|
||||
private final ArrayList<Groupe> g;
|
||||
private final Controller listener;
|
||||
private JComboBox<String> groupeOption;
|
||||
private JTextField text;
|
||||
|
||||
public StudentView(ArrayList<Etudiant> e, ArrayList<Groupe> g, Controller listener) {
|
||||
super();
|
||||
@ -36,10 +35,6 @@ public class StudentView extends JPanel {
|
||||
return (String) this.groupeOption.getSelectedItem();
|
||||
}
|
||||
|
||||
public String getSearchStud() {
|
||||
return this.text.getText();
|
||||
}
|
||||
|
||||
public int getComboSelectionIndex() {
|
||||
return this.groupeOption.getSelectedIndex();
|
||||
}
|
||||
@ -47,11 +42,11 @@ public class StudentView extends JPanel {
|
||||
public void Display() {
|
||||
BLayout settings = new BLayout();
|
||||
settings.setPositionX(0);
|
||||
settings.setPositionY(6);
|
||||
settings.setPositionY(1);
|
||||
|
||||
settings.setPositionY(0);
|
||||
JButton studList = new JButton("Voir la liste des etudiants");
|
||||
studList.setActionCommand("pv::GetStudList");
|
||||
JButton studList = new JButton("Voir la liste des groupes");
|
||||
studList.setActionCommand("sv::GetGrup");
|
||||
studList.addActionListener(this.listener);
|
||||
this.add(studList, settings);
|
||||
|
||||
@ -78,47 +73,28 @@ public class StudentView extends JPanel {
|
||||
settings.setPadding(new Insets(0, 0, 0, 0));
|
||||
settings.setAnchor(GridBagConstraints.EAST);
|
||||
JButton confirm = new JButton("Rechercher");
|
||||
confirm.setActionCommand("pv::GetListFiltered");
|
||||
confirm.setActionCommand("sv::GetListFiltered");
|
||||
confirm.addActionListener(this.listener);
|
||||
this.add(confirm, settings);
|
||||
|
||||
settings.setAnchor(GridBagConstraints.CENTER);
|
||||
|
||||
settings.setPositionY(4);
|
||||
settings.setAnchor(GridBagConstraints.CENTER);
|
||||
this.add(new JLabel(" "), settings);
|
||||
|
||||
settings.setPositionY(5);
|
||||
JLabel pf = new JLabel("Rechercher un etudiant : ");
|
||||
this.add(pf, settings);
|
||||
JButton makeRequest = new JButton("Faire une requete");
|
||||
makeRequest.setActionCommand("sv::MakeRequest");
|
||||
makeRequest.addActionListener(this.listener);
|
||||
this.add(makeRequest, settings);
|
||||
|
||||
settings.setPositionY(6);
|
||||
settings.setPadding(new Insets(0, 0, 0, 50));
|
||||
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 )
|
||||
e.consume();
|
||||
}
|
||||
});
|
||||
this.add(this.text, settings);
|
||||
|
||||
settings.setPositionY(6);
|
||||
settings.setPadding(new Insets(0, 0, 0, 0));
|
||||
settings.setAnchor(GridBagConstraints.EAST);
|
||||
JButton searchTLetters = new JButton("Rechercher");
|
||||
searchTLetters.addActionListener(this.listener);
|
||||
searchTLetters.setActionCommand("pv::SearchStudentPer3Letters");
|
||||
this.add(searchTLetters, settings);
|
||||
settings.setAnchor(GridBagConstraints.CENTER);
|
||||
|
||||
settings.setPositionY(7);
|
||||
this.add(new JLabel(" "), settings);
|
||||
|
||||
settings.setPositionY(8);
|
||||
JButton changGrp = new JButton("Changer de groupe");
|
||||
changGrp.addActionListener(this.listener);
|
||||
this.add(changGrp, settings);
|
||||
settings.setPositionY(7);
|
||||
JButton showRequest = new JButton("Voir mes requetes");
|
||||
showRequest.setActionCommand("sv::ShowRequest");
|
||||
showRequest.addActionListener(this.listener);
|
||||
this.add(showRequest, settings);
|
||||
|
||||
this.repaint();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user