debut de la fin des changements, modif api et correction de bug
This commit is contained in:
@@ -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);
|
||||
|
Reference in New Issue
Block a user