suite changement et correction bug
This commit is contained in:
@@ -29,6 +29,16 @@ public class AbstractChangementFactoryNP implements AbstractChangementFactory {
|
||||
this.fenetre=fenetre;
|
||||
this.brain=new HashMap<Integer,Changement>();
|
||||
}
|
||||
|
||||
public AbstractChangementFactoryNP(AbstractGroupeFactory agf, JFrame fenetre, Set<Changement> liste){
|
||||
Objects.requireNonNull(agf,"On ne peut pas créer une usine à changement dont l'usine à groupe parternaire est null");
|
||||
this.agf=agf;
|
||||
this.fenetre=fenetre;
|
||||
this.brain=new HashMap<Integer,Changement>();
|
||||
for(Changement ch:liste){
|
||||
this.brain.put(ch.getId(), ch);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
@@ -85,9 +95,22 @@ public class AbstractChangementFactoryNP implements AbstractChangementFactory {
|
||||
*/
|
||||
public void deleteChangement(Changement c){
|
||||
Objects.requireNonNull(c,"On ne peut pas demander la suppression d'un changement qui est null");
|
||||
|
||||
this.brain.remove(Integer.valueOf(c.getId()));
|
||||
|
||||
Connection cnx=this.cnx();
|
||||
try{
|
||||
PreparedStatement pst=cnx.prepareStatement("DELETE FROM `Changement` where `id`=?");
|
||||
pst.setInt(1, c.getId());
|
||||
pst.executeUpdate();
|
||||
pst.close();
|
||||
}catch(SQLException er){
|
||||
System.out.println(er.toString());
|
||||
if(this.erreurSQL()){
|
||||
this.deleteChangement(c);
|
||||
}else{
|
||||
return;
|
||||
}
|
||||
}
|
||||
this.close(cnx);
|
||||
this.brain.remove(c.getId());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -109,13 +132,25 @@ public class AbstractChangementFactoryNP implements AbstractChangementFactory {
|
||||
this.brain.put(Integer.valueOf(c.getId()),c);
|
||||
Connection cnx=this.cnx();
|
||||
try{
|
||||
PreparedStatement pst=cnx.prepareStatement("INSERT INTO `Changement` (`idGroupeA`, `idGroupeB`, `idEtudiant`) VALUES (?, ?, ?);");
|
||||
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());
|
||||
pst.executeUpdate();
|
||||
pst.close();
|
||||
if(!pst.executeQuery().next()){
|
||||
pst.close();
|
||||
pst=cnx.prepareStatement("INSERT INTO `Changement` (`idGroupeA`, `idGroupeB`, `idEtudiant`, `id`) VALUES (?, ?, ?, ?);");
|
||||
pst.setInt(1, A.getId());
|
||||
pst.setInt(2, B.getId());
|
||||
pst.setInt(3, e.getId());
|
||||
pst.setInt(4, c.getId());
|
||||
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);
|
||||
}else{
|
||||
|
||||
Reference in New Issue
Block a user