correctif bug et ajout fonctionnalité

This commit is contained in:
2022-11-16 11:14:29 +01:00
parent 124dfd8a71
commit a444123b99
6 changed files with 209 additions and 168 deletions

View File

@@ -31,14 +31,10 @@ public class Model{
private JFrame fenetre;
private BD bd;
public Model(){
this.fenetre=new JFrame();
this.fenetre.setSize(1200, 720);
this.fenetre.setLocation(100,100);
Chargement ch=new Chargement();
this.fenetre.add(ch, BorderLayout.CENTER);
this.fenetre.setVisible(true);
this.bd=new BD(this.fenetre);
Chargement ch=new Chargement();
this.promo=this.getPromo(ch);
if(this.promo==null){
this.fenGr=new FenetreGroupe(null, this);
this.fenEtu=new FenetreEtudiant(null);
@@ -46,7 +42,7 @@ public class Model{
this.fenGr=new FenetreGroupe(this.promo.getPromotion(), this);
this.fenEtu=new FenetreEtudiant(this.promo.getPromotion());
}
this.fenetre.dispose();
this.fenetre=new JFrame();
this.fenetre.setSize(1200, 720);
this.bd.setFenetre(this.fenetre);
@@ -60,6 +56,8 @@ public class Model{
scroll.getVerticalScrollBar().setUnitIncrement(15);
this.fenetre.add(scroll);
this.fenetre.setVisible(true);
if(this.promo!=null)
this.showGroupe(this.promo.getPromotion());
}
@@ -69,7 +67,6 @@ public class Model{
*/
public void showGroupe(Groupe g){
g=this.bd.refreshALL(g);
this.promo=this.getPromo(null);
this.fenGr=new FenetreGroupe(g, this);
this.fenEtu=new FenetreEtudiant(g);
this.fenetre.getContentPane().removeAll();
@@ -94,33 +91,21 @@ public class Model{
//On ne peut pas supprimer la promo
if(g==this.promo.getPromotion()){
JOptionPane.showMessageDialog(this.fenetre, "impossible de supprimer la promotion", "alerte", JOptionPane.ERROR_MESSAGE);
return;
}else{
//autrement on récupere les groupe a supprimer par ordre avec une fonction recursive
//elle contiendra les sous-groupe remontant j'usqau groupe a supprimer
//On initialise la liste
this.bd.suprGroupe(g);
this.showGroupe(g.getPointPoint());
}
//autrement on récupere les groupe a supprimer par ordre avec une fonction recursive
//elle contiendra les sous-groupe remontant j'usqau groupe a supprimer
LinkedList<Groupe> file=new LinkedList<>();
//On initialise la liste
this.deleteRecursif(file, g);
for(Groupe sup:file){
//on supprime les groupe
this.promo.deleteGroupe(sup);
}
this.showGroupe(g.getPointPoint());
}
/**
* fonction recursive initialisant la liste ordonnée de tous les groupe a supprimer avant de supprimer ce groupe
* @param file la liste
* @param bedelete le groupe a supprimer
*/
private void deleteRecursif(LinkedList<Groupe> file, Groupe bedelete){
//on parcour tous ses sous groupe
for(Groupe g: bedelete.getSousGroupes()){
//qui eux aussi ajouterons leurs sous-groupe a la file
this.deleteRecursif(file, g);
private int getTailleGroupe(Groupe g){
int i=0;
for(Groupe gr: g.getSousGroupes()){
i+=this.getTailleGroupe(gr);
}
// on ajoute le groupe (les sous-groupe ayant déja ajouter leur groupe)
file.add(bedelete);
return 1+i;
}
/**
@@ -130,18 +115,20 @@ public class Model{
* @param name le nom des partition
*/
public void partition(Groupe g, int n, String name){
Chargement ch=new Chargement();
this.promo.createPartition(g, name, n);
//On recherche le groupe Partitionner pour le sauvegarder dans la BD
Groupe creer;
for(Groupe gr: g.getSousGroupes()){
if(gr.getName()==name){
creer=gr;
if(gr.getSousGroupes().size()>0 && gr.getSousGroupes().iterator().next().getName().contains(name)){
this.fenetre.setVisible(false);
this.bd.saveGroupe(gr, 100/this.getTailleGroupe(gr)+1, ch);
this.fenetre.setVisible(true);
break;
}
}
//On dis a la BD de sauvegarder ce groupe et tous ces sous Groupe
this.fenGr.setG(this.bd.refreshGroupe(g));
this.fenGr.refresh();
this.showGroupe(g);
}
/**
@@ -163,18 +150,22 @@ public class Model{
break;
}
}
//on crééer le groupe
this.bd.createGroupe(creer);
//on y ajoute les étudiant
int n=0;
for(Etudiant e:ajout){
if(this.addEtudiant(creer, e)==false)
n++;
}
creer=this.bd.refreshALL(creer);
if(n>0)
JOptionPane.showMessageDialog(this.fenetre, "erreur impossible d'ajouter "+n+" etudiants par manque de place dans le groupe de ses parents", "erreur", JOptionPane.ERROR_MESSAGE);
//Si finalement avec les etudiants qui n'ont pas pus être ajouter le min n'est pas atteint
if(creer.getSize()<creer.getMin()){
if(creer.getEtudiants().size()<=creer.getMin()){
//On le supprime
this.promo.deleteGroupe(creer);
//this.bd.suprGroupe(creer);
JOptionPane.showMessageDialog(this.fenetre, "en raison du manque d'etudiant pour le nombre min le groupe n'a pas pus être créer", "errer", JOptionPane.ERROR_MESSAGE);
}
this.showGroupe(g);
@@ -194,8 +185,11 @@ public class Model{
public void addPromo(int min, int max, String name){
Chargement ch=new Chargement();
this.promo=new AbstractGroupeFactoryNP(name, min, max);
//this.bd.saveGroupe(this.promo.getPromotion());
this.fenetre.setVisible(false);
this.bd.saveGroupe(this.promo.getPromotion(), this.getTailleGroupe(this.promo.getPromotion()), ch);
this.fenetre.setVisible(true);
this.showGroupe(this.bd.refreshALL(this.promo.getPromotion()));
}
@@ -211,10 +205,6 @@ public class Model{
return false;
//On induqe a la BD de sauvegarder cette modification
this.bd.saveEtu(e, g);
//pour un modele NP on l'ajout en local
this.promo.addToGroupe(g, e);
//on refresh avec la bd
this.showGroupe(this.bd.refreshALL(g));
return true;
}
@@ -250,17 +240,19 @@ public class Model{
//on récupère le Groupe de la BD n'ayant pas de Parent (La promo donc)
try{
PreparedStatement pst = cnx.prepareStatement(
"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;");
"SELECT `id`, `nom`, `min`, `max`, `value`, `id-parent` FROM `Groupe` join `TYPE` on Groupe.Type=TYPE.name ORDER BY Groupe.id ASC;");
ResultSet rs = pst.executeQuery();
rs=pst.executeQuery();
rs.last();
int nbgrp=rs.getRow();
rs=pst.executeQuery();
try{
//Si il existe bien une promotion
if(rs.first()){
if(rs.next()){
//On créer le groupe de promo
Groupe groupe=new GroupeNP(rs.getInt(1), rs.getString(2), rs.getInt(3), rs.getInt(4), TypeGroupe.getType(rs.getString(5)), null);
//On lui ajoute tout ses sous-groupe
//et ses etudiants
this.bd.refreshALL(groupe, chargement);
this.init(groupe, (100/nbgrp), chargement);
//On créer la Factory
agf=new AbstractGroupeFactoryNP(groupe);
}else{
@@ -268,7 +260,7 @@ public class Model{
this.promo=null;
}
}catch(SQLException e){
System.out.println("erreur dans la prise de resultat");
System.out.println("hooo");
}
rs.close();
pst.close();
@@ -279,4 +271,15 @@ public class Model{
return agf;
}
public Set<Etudiant> getEtudiant(){
return this.bd.getEtudiant();
}
private void init(Groupe g, int pourcentage, Chargement ch){
this.bd.refreshALL(g);
ch.addPourcent(pourcentage+1);
for(Groupe gr:g.getSousGroupes()){
this.init(gr, pourcentage, ch);
}
}
}