restauration de l'API et ajout de possibilité plusieur promo

This commit is contained in:
2022-11-13 15:00:55 +01:00
parent 0eabe2b4bb
commit c06ff537ad
3 changed files with 36 additions and 55 deletions

View File

@@ -29,20 +29,12 @@ import fr.iutfbleau.projetIHM2022FI2.MNP.GroupeNP;
public class Model{
private FenetreGroupe fenGr;
private FenetreEtudiant fenEtu;
private AbstractGroupeFactory agf;
private Set<Groupe> promo;
private JFrame fenetre;
private Set<Etudiant> etu;
public Model(){
this.etu=null;
this.getPromo();
System.out.println(this.agf.getPromotion().monPrint());
Groupe racineDeLaPartition = agf.getPromotion().getSousGroupes().iterator().next();
System.out.println(racineDeLaPartition.monPrint());
for(Groupe g : racineDeLaPartition.getSousGroupes()){
System.out.println(g.monPrint());
}
this.fenGr=new FenetreGroupe(this.agf.getPromotion(), this);
this.fenEtu=new FenetreEtudiant(this.agf.getPromotion());
this.fenGr=new FenetreGroupe(this.promo.iterator().next(), this);
this.fenEtu=new FenetreEtudiant(this.promo.iterator().next());
this.fenetre=new JFrame();
this.fenetre.setSize(1200, 720);
this.fenetre.setLocation(100,100);
@@ -55,7 +47,7 @@ public class Model{
}
private void getPromo(){
this.agf=null;
this.promo=new LinkedHashSet<>();
try{
Class.forName("org.mariadb.jdbc.Driver");
try{
@@ -63,22 +55,17 @@ public class Model{
"jdbc:mariadb://dwarves.iut-fbleau.fr/chaignea",
"chaignea", "Chaigneauphpmyadmin");
try{
//on récupère le premier groupe de la BD (donc la racine de tous les autres)
PreparedStatement pst = cnx.prepareStatement(
"SELECT `id`, `nom`, `min`, `max`, `value`, `id-parent` FROM `Groupe` join `TYPE` on Groupe.Type=TYPE.name ORDER BY Groupe.id ASC; ");
"SELECT `id`, `nom`, `min`, `max`, `value`, `id-parent` FROM `Groupe` join `TYPE` on Groupe.Type=TYPE.name where Groupe.id=`Groupe`.`id-parent` ORDER BY Groupe.id ASC;");
try{
ResultSet rs = pst.executeQuery();
try{
if(rs.first()){
Groupe promo=new GroupeNP(rs.getInt(1), rs.getString(2), rs.getInt(3), rs.getInt(4), TypeGroupe.getType(rs.getString(5)), null);
this.agf=new AbstractGroupeFactoryNP(promo);
this.addSousGroupe(promo, cnx);
}
while(rs.next()){
Groupe g=new GroupeNP(rs.getInt(1), rs.getString(2), rs.getInt(3), rs.getInt(4), TypeGroupe.getType(rs.getString(5)), null);
if(agf.knows(g)==false){
agf.addGroupe(g);
this.addSousGroupe(g, cnx);
}
//on image qu'il puisse avoir plusieur promo
this.promo.add(new GroupeNP(rs.getInt(1), rs.getString(2), rs.getInt(3), rs.getInt(4), TypeGroupe.getType(rs.getString(5)), null));
//on y ajoute tous ses sous-groupe
this.addSousGroupe(promo.iterator().next(), cnx);
}
}catch(SQLException e){
System.out.println("erreur dans la prise de resultat");
@@ -109,9 +96,7 @@ public class Model{
ResultSet rs=pst.executeQuery();
try{
while(rs.next()){
System.out.println(g.getName()+" id= "+g.getId()+" "+rs.getString(2));
Groupe nouveau=new GroupeNP(rs.getInt(1), rs.getString(2), rs.getInt(3), rs.getInt(4), TypeGroupe.getType(rs.getString(5)), g);
this.agf.addGroupe(nouveau);
g.addSousGroupe(nouveau);
this.addSousGroupe(nouveau, cnx);
}
@@ -136,16 +121,21 @@ public class Model{
pst.setInt(1, g.getId());
ResultSet rs=pst.executeQuery();
try{
//On vérifie dans toutes le promo si personne ne connait déja l'Etudiant(s) du même noms
while(rs.next()){
if(g==this.agf.getPromotion()){
this.agf.addToGroupe(g, new EtudiantNP(rs.getString(1), rs.getString(2)));
}else{
for(Groupe m:this.promo){
AbstractGroupeFactory agf=new AbstractGroupeFactoryNP(m);
Set<Etudiant> contenue=agf.getEtudiants(rs.getString(1));
if(contenue.iterator().hasNext()){
for(Etudiant e:contenue){
agf.addToGroupe(g, e);
//Si il est connu on le/les ajoute
if(contenue.iterator().hasNext()){
for(Etudiant e:contenue){
g.addEtudiant(e);
}
//autrement on les crée
}else{
agf.addToGroupe(g, new EtudiantNP(rs.getString(1), rs.getString(2)));
}
}
}
}
}catch(SQLException e){