This commit is contained in:
pro.boooooo
2022-10-07 10:39:13 +02:00
parent f900c6179d
commit 42ad496166
16 changed files with 162 additions and 29 deletions
+1
View File
@@ -9,5 +9,6 @@
<orderEntry type="sourceFolder" forTests="false" /> <orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" name="mariadb-connector" level="project" /> <orderEntry type="library" name="mariadb-connector" level="project" />
<orderEntry type="library" name="mariadb-connector1" level="project" /> <orderEntry type="library" name="mariadb-connector1" level="project" />
<orderEntry type="library" name="mariadb-connector2" level="project" />
</component> </component>
</module> </module>
View File
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
+14 -4
View File
@@ -17,7 +17,7 @@ public class BDatabase {
public String db_name; public String db_name;
public String db_user; public String db_user;
protected String db_password; protected String db_password;
protected Connection link; protected Connection sharedObject;
protected int current_user; protected int current_user;
public BDatabase() { public BDatabase() {
@@ -33,7 +33,7 @@ public class BDatabase {
} }
try { 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."); System.out.println("Success Connected.");
} catch (SQLException e) { } catch (SQLException e) {
System.out.println("Error with SQL connexion.\n" + e); System.out.println("Error with SQL connexion.\n" + e);
@@ -44,7 +44,7 @@ public class BDatabase {
public ArrayList<String> fetchAll(String request) { public ArrayList<String> fetchAll(String request) {
try { try {
ArrayList<String> toReturn = new ArrayList<String>(); ArrayList<String> toReturn = new ArrayList<String>();
ResultSet rs = this.link.prepareStatement(request).executeQuery(); ResultSet rs = this.sharedObject.prepareStatement(request).executeQuery();
for(int i = 0; rs.next(); i++) { for(int i = 0; rs.next(); i++) {
toReturn.add(i, String.valueOf(rs.getString(1))); 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() { public Connection getSharedObject() {
return this.link; return this.sharedObject;
} }
public String getUser() { public String getUser() {
+3 -3
View File
@@ -4,9 +4,9 @@ import java.io.IOException;
public class Main { public class Main {
public static void main(String[] args) throws IOException { public static void main(String[] args) throws IOException {
// test // test
// BDatabase db = new BDatabase(); BDatabase db = new BDatabase();
// ManageStudent test = new ManageStudent(db); 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);
} }
} }
+144 -22
View File
@@ -1,23 +1,25 @@
import javax.swing.JFrame; import javax.swing.*;
import javax.swing.JList;
import java.awt.GridBagConstraints; import java.awt.GridBagConstraints;
import java.awt.event.ActionEvent; import java.awt.event.ActionEvent;
import java.awt.event.ActionListener; import java.awt.event.ActionListener;
import java.lang.reflect.Array; import java.sql.Array;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Objects;
public class ManageStudent extends BFrame implements ActionListener { public class ManageStudent extends BFrame implements ActionListener {
protected BDatabase sharedObject;
protected BFrame tempFrame;
protected BLayout settings;
protected BInput inSearch; protected BInput inSearch;
protected BButton btnSearch;
protected JList<String> student;
protected BButton moveTo; protected BButton moveTo;
protected BButton btnSearch;
protected BButton addTo; protected BButton addTo;
protected BButton seeReq; protected BButton seeReq;
protected BDatabase sharedObject; protected JList<String> student;
protected ArrayList<String> tmp; protected JList<String> grupList;
protected ArrayList<String> tmp2;
protected String[] data; protected String[] data;
protected BLayout settings; protected int tmpForAddGrup;
protected int tmpForAddGrupWho;
public ManageStudent(BDatabase so) { public ManageStudent(BDatabase so) {
super("Manageur d'Eleve", 800, 400, JFrame.DISPOSE_ON_CLOSE); 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.add(inSearch, this.settings);
this.btnSearch = new BButton("Rechercher"); this.btnSearch = new BButton("Rechercher");
this.settings.setPositionX(1);
this.settings.setPositionY(0);
this.btnSearch.setActionCommand("search"); this.btnSearch.setActionCommand("search");
this.btnSearch.addActionListener(this); this.btnSearch.addActionListener(this);
this.settings.setPositionX(1);
this.settings.setPositionY(0);
this.add(btnSearch, this.settings); this.add(btnSearch, this.settings);
this.student = refreshList(""); this.student = refreshList("");
@@ -54,13 +56,17 @@ public class ManageStudent extends BFrame implements ActionListener {
this.settings.setFill(GridBagConstraints.NONE); this.settings.setFill(GridBagConstraints.NONE);
this.settings.setAnchor(GridBagConstraints.CENTER); 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.setPositionX(2);
this.settings.setPositionY(1); this.settings.setPositionY(1);
this.add(moveTo, this.settings); 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.setPositionX(3);
this.settings.setPositionY(1); this.settings.setPositionY(1);
this.add(addTo, this.settings); this.add(addTo, this.settings);
@@ -75,33 +81,149 @@ public class ManageStudent extends BFrame implements ActionListener {
} }
protected JList<String> refreshList(String student) { protected JList<String> refreshList(String student) {
this.tmp = new ArrayList<>(); ArrayList<String> tmp = new ArrayList<>();
this.tmp2 = new ArrayList<>(); ArrayList<String> tmp2 = new ArrayList<>();
ArrayList<String> tmp3 = new ArrayList<>();
this.tmp = this.sharedObject.fetchAll( tmp = this.sharedObject.fetchAll(
"SELECT nom FROM Membres WHERE nom LIKE '%" + student + "%'" "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 + "%'" "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()]; this.data = new String[tmp.size()];
for(int i = 0; i <= tmp.size()-1; i++) { for(int i = 0; i <= tmp.size()-1; i++) {
this.data[i] = tmp.get(i) + " " + tmp2.get(i); this.data[i] = "[" + tmp3.get(i) + "] " + tmp.get(i) + " " + tmp2.get(i);
System.out.println(this.data[i] + " | " + i); System.out.println(this.data[i]);
} }
return new JList<>(this.data); 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<String> 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<String> 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 @Override
public void actionPerformed(ActionEvent e) { 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); this.add(refreshList(this.inSearch.getText()), this.settings);
} else { } else if(Objects.equals(e.getActionCommand(), "add")){
System.out.println("ok"); 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();
} }
} }
} }