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