debut de la fin des changements, modif api et correction de bug

This commit is contained in:
2022-12-02 11:20:58 +01:00
parent 35696d3b14
commit 1fb3e881dc
24 changed files with 529 additions and 256 deletions

View File

@@ -162,6 +162,55 @@ public class AbstractChangementFactoryNP implements AbstractChangementFactory {
this.close(cnx);
}
@Override
/**
* permet d'ajouter un nouveau changement. de type 2
*
* @param A groupe actuel
* @param B groupe demandé
* @param e étudiant concerné par le changement
* @param raison la raison du changement de type 2
* @throws java.lang.NullPointerException si un argument est null
* @throws java.lang.IllegalArgumentException si les groupes ou l'étudiant ne sont pas connus de la factory partenaire, ou e n'appartient pas à A ou A et B ne sont pas frères dans l'arbre des groupes.
*
*/
public void createChangement(Groupe A, Etudiant e, Groupe B, String raison){
Objects.requireNonNull(A,"Le groupe d'origine ne peut pas être null");
Objects.requireNonNull(B,"Le groupe d'arrivée ne peut pas être null");
Objects.requireNonNull(e,"L'étudiant ne peut pas être null");
Changement c = new ChangementNP(A,e,B, raison);
this.brain.put(Integer.valueOf(c.getId()),c);
Connection cnx=this.cnx();
try{
PreparedStatement pst=cnx.prepareStatement("SELECT * FROM `Changement` where `idGroupeA`=? AND `idGroupeB`=? AND `idEtudiant`=?; ");
pst.setInt(1, A.getId());
pst.setInt(2, B.getId());
pst.setInt(3, e.getId());
if(!pst.executeQuery().next()){
pst.close();
pst=cnx.prepareStatement("INSERT INTO `Changement` (`id`, `idGroupeA`, `idGroupeB`, `idEtudiant`, `Raison`) VALUES (?, ?, ?, ?, ?);");
pst.setInt(1, c.getId());
pst.setInt(2, A.getId());
pst.setInt(3, B.getId());
pst.setInt(4, e.getId());
pst.setString(5, raison);
pst.executeUpdate();
pst.close();
}else{
pst.close();
JOptionPane.showMessageDialog(this.fenetre, "Vous Avez deja demander a Chnager dans ce Groupe", "erreur", JOptionPane.ERROR_MESSAGE);
}
}catch(SQLException er){
System.out.println(er.toString());
if(this.erreurSQL()){
this.createChangement(A, e, B, raison);
}else{
return;
}
}
this.close(cnx);
}
// **********************
// FONCTION POUR SIMPLIFIER LES Modification BD
@@ -218,8 +267,12 @@ public class AbstractChangementFactoryNP implements AbstractChangementFactory {
while(rs.next()){
Groupe[] ab=new Groupe[2];
this.getGroupe(rs.getInt(2), rs.getInt(3), ab, this.agf.getPromotion());
Etudiant e=new EtudiantNP(rs.getString(5), rs.getString(6), rs.getInt(4));
this.brain.put(rs.getInt(1), new ChangementNP(ab[0], e, ab[1], rs.getInt(1)));
Etudiant e=new EtudiantNP(rs.getString(6), rs.getString(7), rs.getInt(4));
if(rs.getString(5)!=null){
this.brain.put(rs.getInt(1), new ChangementNP(ab[0], e, ab[1], rs.getInt(1), rs.getString(5)));
}else{
this.brain.put(rs.getInt(1), new ChangementNP(ab[0], e, ab[1], rs.getInt(1)));
}
}
pst.close();
}catch(SQLException e){

View File

@@ -249,9 +249,30 @@ public class AbstractGroupeFactoryNP implements AbstractGroupeFactory {
*/
public Set<Etudiant> getEtudiants(String nomEtu){
Set<Etudiant> s=new LinkedHashSet<>();
for(Etudiant e:this.getPromotion().getEtudiants()){
if((e.getNom()).contains(nomEtu)){
s.add(e);
//on retourne tous les etudiants
if(nomEtu==null){
for(Etudiant et:this.getPromotion().getEtudiants()){
s.add(et);
}
//ceux qui sont connu mais pas dans la promo
Connection cnx=this.cnx();
try{
PreparedStatement pst=cnx.prepareStatement("SELECT * FROM Etudiant natural join CONTIENT where Etudiant.id NOT IN (SELECT CONTIENT.idEt FROM CONTIENT) Group by Etudiant.id;");
ResultSet rs=pst.executeQuery();
while(rs.next()){
s.add(new EtudiantNP(rs.getString(2), rs.getString(3), rs.getInt(1)));
}
}catch(SQLException e){
if(this.erreurCO())
return this.getEtudiants(nomEtu);
return null;
}
this.close(cnx);
}else{
for(Etudiant e:this.getPromotion().getEtudiants()){
if((e.getNom()).contains(nomEtu)){
s.add(e);
}
}
}
return s;
@@ -268,16 +289,21 @@ public class AbstractGroupeFactoryNP implements AbstractGroupeFactory {
public Set<Groupe> getGroupesOfEtudiant(Etudiant etu){
if(etu==null)
throw new NullPointerException();
Collection<Groupe> s= this.brain.values();
Set<Groupe> ret=new LinkedHashSet<Groupe>();
for(Groupe g: s){
for(Etudiant e: g.getEtudiants()){
if(etu==e){
ret.add(g);
break;
}
Connection cnx=this.cnx();
try{
PreparedStatement pst=cnx.prepareStatement("SELECT `idGroupe` FROM CONTIENT where idEt=? Group by `idGroupe`;");
pst.setInt(1, etu.getId());
ResultSet rs=pst.executeQuery();
while(rs.next()){
ret.add(this.brain.get(rs.getInt(1)));
}
rs.close();
pst.close();
}catch(SQLException e){
}
this.close(cnx);
return ret;
}
@@ -541,29 +567,29 @@ private boolean saveEtu(Etudiant etudiant, Groupe g){
*/
private void addBDEtudiant(Groupe g, Connection cnx){
try{
//On récupère les etudiants contenue du groupe
PreparedStatement pst;
//Si c'est la promo
pst= cnx.prepareStatement("SELECT Etudiant.nom, Etudiant.prenom, Etudiant.id FROM `CONTIENT` JOIN Etudiant on CONTIENT.idEt=Etudiant.id WHERE CONTIENT.idGroupe=? ORDER BY Etudiant.id ASC");
pst.setInt(1, g.getId());
ResultSet rs=pst.executeQuery();
//Pour tous les étudiants
while(rs.next()){
boolean exist=false;
//autrement on recupere l'etudiant
for(Etudiant e: g.getPointPoint().getEtudiants()){
if(e.getId()==rs.getInt(3)){
exist=true;
g.addEtudiant(e);
break;
//On récupère les etudiants contenue du groupe
PreparedStatement pst;
//Si c'est la promo
pst= cnx.prepareStatement("SELECT Etudiant.nom, Etudiant.prenom, Etudiant.id FROM `CONTIENT` JOIN Etudiant on CONTIENT.idEt=Etudiant.id WHERE CONTIENT.idGroupe=? ORDER BY Etudiant.id ASC");
pst.setInt(1, g.getId());
ResultSet rs=pst.executeQuery();
//Pour tous les étudiants
while(rs.next()){
boolean exist=false;
//autrement on recupere l'etudiant
for(Etudiant e: g.getPointPoint().getEtudiants()){
if(e.getId()==rs.getInt(3)){
exist=true;
g.addEtudiant(e);
break;
}
}
if(exist==false){
g.addEtudiant(new EtudiantNP(rs.getString(1), rs.getString(2), rs.getInt(3)));
}
}
if(exist==false){
g.addEtudiant(new EtudiantNP(rs.getString(1), rs.getString(2), rs.getInt(3)));
}
}
rs.close();
pst.close();
rs.close();
pst.close();
}catch(SQLException e){
if(this.erreurCO())
this.addBDEtudiant(g, cnx);

View File

@@ -12,7 +12,7 @@ public class ChangementNP implements Changement {
//auto-incrément des changements
private static int nextId=0;
private String raison;
private int id;
private Groupe a,b;
private Etudiant e;
@@ -21,7 +21,18 @@ public class ChangementNP implements Changement {
Objects.requireNonNull(a,"On ne peut pas créer un changement avec un groupe à quitter null");
Objects.requireNonNull(b,"On ne peut pas créer un changement avec un groupe à rejoindre null");
Objects.requireNonNull(e,"On ne peut pas créer un changement concernant un étudiant null");
this.raison=null;
this.id=++this.nextId;
this.a=a;
this.b=b;
this.e=e;
}
public ChangementNP(Groupe a, Etudiant e, Groupe b, String raison){
Objects.requireNonNull(a,"On ne peut pas créer un changement avec un groupe à quitter null");
Objects.requireNonNull(b,"On ne peut pas créer un changement avec un groupe à rejoindre null");
Objects.requireNonNull(e,"On ne peut pas créer un changement concernant un étudiant null");
this.raison=raison;
this.id=++this.nextId;
this.a=a;
this.b=b;
@@ -41,6 +52,20 @@ public class ChangementNP implements Changement {
this.nextId=this.id;
}
}
public ChangementNP(Groupe a, Etudiant e, Groupe b, int id, String raison){
Objects.requireNonNull(a,"On ne peut pas créer un changement avec un groupe à quitter null");
Objects.requireNonNull(b,"On ne peut pas créer un changement avec un groupe à rejoindre null");
Objects.requireNonNull(e,"On ne peut pas créer un changement concernant un étudiant null");
this.raison=raison;
this.id=id;
this.a=a;
this.b=b;
this.e=e;
if(this.id>this.nextId){
this.nextId=this.id;
}
}
/**
* permet de récupérer l'identifiant du changement (référence interne sans intérêt irl).
@@ -73,4 +98,9 @@ public class ChangementNP implements Changement {
return this.e;
}
@Override
public String getRaison() {
return this.raison;
}
}