diff --git a/FIProjetIHM2022.iml b/FIProjetIHM2022.iml
index fdc4f2f..6327e61 100644
--- a/FIProjetIHM2022.iml
+++ b/FIProjetIHM2022.iml
@@ -9,5 +9,6 @@
+
\ No newline at end of file
diff --git "a/Icon\r" "b/Icon\r"
deleted file mode 100644
index e69de29..0000000
diff --git a/out/production/FIProjetIHM2022/BButton.class b/out/production/FIProjetIHM2022/BButton.class
index 77e12d2..f2de263 100644
Binary files a/out/production/FIProjetIHM2022/BButton.class and b/out/production/FIProjetIHM2022/BButton.class differ
diff --git a/out/production/FIProjetIHM2022/BDatabase.class b/out/production/FIProjetIHM2022/BDatabase.class
index 687ca3f..c0920ce 100644
Binary files a/out/production/FIProjetIHM2022/BDatabase.class and b/out/production/FIProjetIHM2022/BDatabase.class differ
diff --git a/out/production/FIProjetIHM2022/BFrame.class b/out/production/FIProjetIHM2022/BFrame.class
index a320868..694dc9e 100644
Binary files a/out/production/FIProjetIHM2022/BFrame.class and b/out/production/FIProjetIHM2022/BFrame.class differ
diff --git a/out/production/FIProjetIHM2022/BImage.class b/out/production/FIProjetIHM2022/BImage.class
index d27c60e..7547f0b 100644
Binary files a/out/production/FIProjetIHM2022/BImage.class and b/out/production/FIProjetIHM2022/BImage.class differ
diff --git a/out/production/FIProjetIHM2022/BInput.class b/out/production/FIProjetIHM2022/BInput.class
index 411dc9b..8b1ff1e 100644
Binary files a/out/production/FIProjetIHM2022/BInput.class and b/out/production/FIProjetIHM2022/BInput.class differ
diff --git a/out/production/FIProjetIHM2022/BLabel.class b/out/production/FIProjetIHM2022/BLabel.class
index 174fc97..a319dea 100644
Binary files a/out/production/FIProjetIHM2022/BLabel.class and b/out/production/FIProjetIHM2022/BLabel.class differ
diff --git a/out/production/FIProjetIHM2022/BLayout.class b/out/production/FIProjetIHM2022/BLayout.class
index b0b2590..ac2086b 100644
Binary files a/out/production/FIProjetIHM2022/BLayout.class and b/out/production/FIProjetIHM2022/BLayout.class differ
diff --git a/out/production/FIProjetIHM2022/Home.class b/out/production/FIProjetIHM2022/Home.class
index 1fd9e4a..2feef08 100644
Binary files a/out/production/FIProjetIHM2022/Home.class and b/out/production/FIProjetIHM2022/Home.class differ
diff --git a/out/production/FIProjetIHM2022/LoginConnection.class b/out/production/FIProjetIHM2022/LoginConnection.class
index 6b5b5cb..ce3a51d 100644
Binary files a/out/production/FIProjetIHM2022/LoginConnection.class and b/out/production/FIProjetIHM2022/LoginConnection.class differ
diff --git a/out/production/FIProjetIHM2022/Main.class b/out/production/FIProjetIHM2022/Main.class
index ddd23b7..bc54df4 100644
Binary files a/out/production/FIProjetIHM2022/Main.class and b/out/production/FIProjetIHM2022/Main.class differ
diff --git a/out/production/FIProjetIHM2022/ManageStudent.class b/out/production/FIProjetIHM2022/ManageStudent.class
index 2f1c3eb..8594e9c 100644
Binary files a/out/production/FIProjetIHM2022/ManageStudent.class and b/out/production/FIProjetIHM2022/ManageStudent.class differ
diff --git a/src/BDatabase.java b/src/BDatabase.java
index 22f4a05..4533dc2 100644
--- a/src/BDatabase.java
+++ b/src/BDatabase.java
@@ -17,7 +17,7 @@ public class BDatabase {
public String db_name;
public String db_user;
protected String db_password;
- protected Connection link;
+ protected Connection sharedObject;
protected int current_user;
public BDatabase() {
@@ -33,7 +33,7 @@ public class BDatabase {
}
try {
- this.link = 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);
System.out.println("Success Connected.");
} catch (SQLException e) {
System.out.println("Error with SQL connexion.\n" + e);
@@ -44,7 +44,7 @@ public class BDatabase {
public ArrayList fetchAll(String request) {
try {
ArrayList toReturn = new ArrayList();
- ResultSet rs = this.link.prepareStatement(request).executeQuery();
+ ResultSet rs = this.sharedObject.prepareStatement(request).executeQuery();
for(int i = 0; rs.next(); i++) {
toReturn.add(i, String.valueOf(rs.getString(1)));
@@ -58,8 +58,18 @@ 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;
+ }
+ }
+
public Connection getSharedObject() {
- return this.link;
+ return this.sharedObject;
}
public String getUser() {
diff --git a/src/Main.java b/src/Main.java
index 7a1d672..6ba01a1 100644
--- a/src/Main.java
+++ b/src/Main.java
@@ -4,9 +4,9 @@ import java.io.IOException;
public class Main {
public static void main(String[] args) throws IOException {
// test
- // BDatabase db = new BDatabase();
- // ManageStudent test = new ManageStudent(db);
+ BDatabase db = new BDatabase();
+ ManageStudent test = new ManageStudent(db);
- LoginConnection goToLogin = new LoginConnection("Grup'App", 400, 400, JFrame.EXIT_ON_CLOSE);
+ //LoginConnection goToLogin = new LoginConnection("Grup'App", 400, 400, JFrame.EXIT_ON_CLOSE);
}
}
\ No newline at end of file
diff --git a/src/ManageStudent.java b/src/ManageStudent.java
index 4f35eaa..b76aa62 100644
--- a/src/ManageStudent.java
+++ b/src/ManageStudent.java
@@ -1,23 +1,25 @@
-import javax.swing.JFrame;
-import javax.swing.JList;
+import javax.swing.*;
import java.awt.GridBagConstraints;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
-import java.lang.reflect.Array;
+import java.sql.Array;
import java.util.ArrayList;
+import java.util.Objects;
public class ManageStudent extends BFrame implements ActionListener {
+ protected BDatabase sharedObject;
+ protected BFrame tempFrame;
+ protected BLayout settings;
protected BInput inSearch;
- protected BButton btnSearch;
- protected JList student;
protected BButton moveTo;
+ protected BButton btnSearch;
protected BButton addTo;
protected BButton seeReq;
- protected BDatabase sharedObject;
- protected ArrayList tmp;
- protected ArrayList tmp2;
+ protected JList student;
+ protected JList grupList;
protected String[] data;
- protected BLayout settings;
+ protected int tmpForAddGrup;
+ protected int tmpForAddGrupWho;
public ManageStudent(BDatabase so) {
super("Manageur d'Eleve", 800, 400, JFrame.DISPOSE_ON_CLOSE);
@@ -31,10 +33,10 @@ public class ManageStudent extends BFrame implements ActionListener {
this.add(inSearch, this.settings);
this.btnSearch = new BButton("Rechercher");
- this.settings.setPositionX(1);
- this.settings.setPositionY(0);
this.btnSearch.setActionCommand("search");
this.btnSearch.addActionListener(this);
+ this.settings.setPositionX(1);
+ this.settings.setPositionY(0);
this.add(btnSearch, this.settings);
this.student = refreshList("");
@@ -54,13 +56,17 @@ public class ManageStudent extends BFrame implements ActionListener {
this.settings.setFill(GridBagConstraints.NONE);
this.settings.setAnchor(GridBagConstraints.CENTER);
- this.moveTo = new BButton("Deplacer");
+ this.moveTo = new BButton("Deplacer dans un groupe");
+ this.moveTo.setActionCommand("move");
+ this.moveTo.addActionListener(this);
this.settings.setPositionX(2);
this.settings.setPositionY(1);
this.add(moveTo, this.settings);
- this.addTo = new BButton("Ajouter");
+ this.addTo = new BButton("Ajouter dans un groupe");
+ this.addTo.setActionCommand("add");
+ this.addTo.addActionListener(this);
this.settings.setPositionX(3);
this.settings.setPositionY(1);
this.add(addTo, this.settings);
@@ -75,33 +81,149 @@ public class ManageStudent extends BFrame implements ActionListener {
}
protected JList refreshList(String student) {
- this.tmp = new ArrayList<>();
- this.tmp2 = new ArrayList<>();
+ ArrayList tmp = new ArrayList<>();
+ ArrayList tmp2 = new ArrayList<>();
+ ArrayList tmp3 = new ArrayList<>();
- this.tmp = this.sharedObject.fetchAll(
+ tmp = this.sharedObject.fetchAll(
"SELECT nom FROM Membres WHERE nom LIKE '%" + student + "%'"
);
- this.tmp2 = this.sharedObject.fetchAll(
+ tmp2 = this.sharedObject.fetchAll(
"SELECT prenom FROM Membres WHERE nom LIKE '%" + student + "%'"
);
+ tmp3 = this.sharedObject.fetchAll(
+ "SELECT idCompte FROM Membres WHERE nom LIKE '%" + student + "%'"
+ );
+
this.data = new String[tmp.size()];
for(int i = 0; i <= tmp.size()-1; i++) {
- this.data[i] = tmp.get(i) + " " + tmp2.get(i);
- System.out.println(this.data[i] + " | " + i);
+ this.data[i] = "[" + tmp3.get(i) + "] " + tmp.get(i) + " " + tmp2.get(i);
+ System.out.println(this.data[i]);
}
return new JList<>(this.data);
}
+ protected void addInGrup(int who) {
+ this.tmpForAddGrupWho = who;
+
+ this.tempFrame = new BFrame("Choisissez un groupe", 300, 200, JFrame.DISPOSE_ON_CLOSE);
+ BLayout settings = new BLayout();
+ ArrayList tmp = this.sharedObject.fetchAll(
+ "SELECT intitule FROM Groupes"
+ );
+
+ String[] grupListTmp = new String[tmp.size()];
+
+ for(int i = 0; i <= tmp.size()-1; i++) {
+ grupListTmp[i] = tmp.get(i);
+ }
+
+ this.grupList = new JList<>(grupListTmp);
+ settings.setPositionY(0);
+ this.tempFrame.add(this.grupList, settings);
+
+ BButton btn = new BButton("Ajouter");
+ btn.addActionListener(this);
+ btn.setActionCommand("addInGrup");
+ settings.setPositionY(1);
+ this.tempFrame.add(btn, settings);
+
+ this.tempFrame.openBFrame();
+ }
+
+ protected void moveToOtherGrup(int who) {
+ this.tmpForAddGrupWho = who;
+
+ this.tempFrame = new BFrame("Choissez un groupe", 300, 200, JFrame.DISPOSE_ON_CLOSE);
+ BLayout settings = new BLayout();
+ String tmp = this.sharedObject.fetchAll(
+ "SELECT G.intitule FROM Membres M, Groupes G WHERE M.idCompte=" + who
+ ).get(0);
+
+ JLabel tmp2 = new JLabel("Il est actuellement dans : [" + tmp + "]");
+ settings.setPositionY(0);
+ this.tempFrame.add(tmp2, settings);
+
+ ArrayList gr = this.sharedObject.fetchAll(
+ "SELECT intitule FROM Groupes"
+ );
+
+ String[] grupListTmp = new String[gr.size()];
+
+ for(int i = 0; i <= gr.size()-1; i++) {
+ grupListTmp[i] = gr.get(i);
+ }
+
+ this.grupList = new JList<>(grupListTmp);
+ settings.setPositionY(1);
+ this.tempFrame.add(this.grupList, settings);
+
+ BButton btn = new BButton("Deplacer");
+ btn.addActionListener(this);
+ btn.setActionCommand("moveToOtherGrup");
+ settings.setPositionY(2);
+ this.tempFrame.add(btn, settings);
+
+ this.tempFrame.openBFrame();
+ }
+
@Override
public void actionPerformed(ActionEvent e) {
- if(e.getActionCommand() == "search") {
+ int idCompte = Integer.parseInt(
+ this.student.getSelectedValue().charAt(1) + "", 10
+ );
+
+ System.out.println(idCompte);
+
+ // ManageStudent's frame
+ if(Objects.equals(e.getActionCommand(), "search")) {
this.add(refreshList(this.inSearch.getText()), this.settings);
- } else {
- System.out.println("ok");
+ } else if(Objects.equals(e.getActionCommand(), "add")){
+ this.addInGrup(idCompte);
+ } else if(Objects.equals(e.getActionCommand(), "move")) {
+ this.moveToOtherGrup(idCompte);
+ }
+
+ // addInGrup's frame
+ if(Objects.equals(e.getActionCommand(), "addInGrup")) {
+ this.tmpForAddGrup = Integer.parseInt(
+ this.sharedObject.fetchAll(
+ "SELECT idGroupe FROM Groupes WHERE intitule='" + this.grupList.getSelectedValue() + "'"
+ ).get(0), 10
+ );
+
+ if(this.sharedObject.updateRow(
+ "UPDATE Membres SET idGroupe=" + this.tmpForAddGrup + " WHERE idCompte=" + this.tmpForAddGrupWho)
+ ) {
+ JOptionPane.showMessageDialog(this, "L'ajout a bien ete effectue !");
+ } else {
+ JOptionPane.showMessageDialog(this, "Erreur lors de l'ajout.");
+ }
+
+ this.tempFrame.closeBFrame();
+ }
+
+ // moveToOtherGrup's frame
+ if(Objects.equals(e.getActionCommand(), "moveToOtherGrup")) {
+ this.tmpForAddGrup = Integer.parseInt(
+ this.sharedObject.fetchAll(
+ "SELECT idGroupe FROM Groupes WHERE intitule='" + this.grupList.getSelectedValue() + "'"
+ ).get(0), 10
+ );
+
+ if(this.sharedObject.updateRow(
+ "UPDATE Membres SET idGroupe=" + this.tmpForAddGrup + " WHERE idCompte=" + this.tmpForAddGrupWho)
+ ) {
+ JOptionPane.showMessageDialog(this, "Le deplacement a bien ete effectue !");
+ } else {
+ JOptionPane.showMessageDialog(this, "Erreur lors du deplacement.");
+ }
+
+ this.tempFrame.closeBFrame();
}
}
}