ajout tous les étudiant et correction bug
This commit is contained in:
parent
4b6321d9b8
commit
5c4413a6fb
@ -14,6 +14,9 @@ public class ActionListenerNouveauEtu implements ActionListener{
|
||||
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
if(e.getActionCommand()=="tous"){
|
||||
this.pere.addAll();
|
||||
}else{
|
||||
JPanel myPanel = new JPanel();
|
||||
JTextField xField = new JTextField(20);
|
||||
JTextField yField = new JTextField(20);
|
||||
@ -28,5 +31,6 @@ public class ActionListenerNouveauEtu implements ActionListener{
|
||||
this.pere.addEtudiant(xField.getText(), yField.getText());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -145,7 +145,19 @@ public class ObservateurModifGroupe implements ActionListener{
|
||||
if(zField.getText().length()==0){
|
||||
JOptionPane.showMessageDialog(m.getFenetre(), "erreur entre un nom", "erreur", JOptionPane.ERROR_MESSAGE);
|
||||
}else{
|
||||
m.addPromo(min, max, zField.getText());
|
||||
if(min>max){
|
||||
JOptionPane.showMessageDialog(m.getFenetre(), "erreur min>max", "erreur", JOptionPane.ERROR_MESSAGE);
|
||||
}else{
|
||||
Set<Etudiant> ajout=new LinkedHashSet<>();
|
||||
JPanel pan=new FenetreSelectionEtu(null, ajout, false, this.m.getEtudiant());
|
||||
if(JOptionPane.showConfirmDialog(m.getFenetre(), new JScrollPane(pan), "Selectionner les étudiant a ajouter", JOptionPane.OK_CANCEL_OPTION) ==JOptionPane.YES_OPTION){
|
||||
if(min>ajout.size() || max<ajout.size()){
|
||||
JOptionPane.showMessageDialog(m.getFenetre(), "Il y a trop/pas assez d'etudiant pour le groupe", "erreur", JOptionPane.ERROR_MESSAGE);
|
||||
return;
|
||||
}
|
||||
m.addPromo(min, max, yField.getText(), ajout);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}catch(NumberFormatException er){
|
||||
|
@ -89,11 +89,15 @@ public class Model{
|
||||
* @param g le groupe a supprimer
|
||||
*/
|
||||
public void delete(Groupe g){
|
||||
//On ne peut pas supprimer la promo avec la factory
|
||||
//On ne peut pas supprimer la promo normallement
|
||||
if(g==this.promo.getPromotion()){
|
||||
if(JOptionPane.showConfirmDialog(this.fenetre, "Attention ête vous sûr de vouloir supprimer la promo", "Attention", JOptionPane.YES_NO_OPTION)==JOptionPane.YES_OPTION){
|
||||
this.promo=null;
|
||||
this.bd.suprGroupe(g);
|
||||
this.showGroupe(null);
|
||||
}else{
|
||||
return;
|
||||
}
|
||||
//JOptionPane.showMessageDialog(this.fenetre, "impossible de supprimer la promotion", "alerte", JOptionPane.ERROR_MESSAGE);
|
||||
}else{
|
||||
//autrement on récupere les groupe a supprimer par ordre avec une fonction recursive
|
||||
@ -159,7 +163,6 @@ public class Model{
|
||||
this.bd.createGroupe(creer);
|
||||
//on y ajoute les étudiant
|
||||
int n=0;
|
||||
int size=100/ajout.size()+1;
|
||||
for(Etudiant e:ajout){
|
||||
if(this.addEtudiant(creer, e)==false)
|
||||
n++;
|
||||
@ -190,14 +193,20 @@ public class Model{
|
||||
|
||||
|
||||
|
||||
public void addPromo(int min, int max, String name){
|
||||
public void addPromo(int min, int max, String name, Set<Etudiant> ajout){
|
||||
Chargement ch=new Chargement();
|
||||
this.promo=new AbstractGroupeFactoryNP(name, min, max);
|
||||
this.fenetre.setVisible(false);
|
||||
this.bd.saveGroupe(this.promo.getPromotion(), this.getTailleGroupe(this.promo.getPromotion()), ch);
|
||||
ch.addPourcent(20);
|
||||
int pourcent=85/ajout.size();
|
||||
for(Etudiant e:ajout){
|
||||
this.addEtudiant(this.promo.getPromotion(), e);
|
||||
ch.addPourcent(pourcent);
|
||||
}
|
||||
ch.dispose();
|
||||
this.fenetre.setVisible(true);
|
||||
this.showGroupe(this.bd.refreshALL(this.promo.getPromotion()));
|
||||
this.showGroupe(this.promo.getPromotion());
|
||||
}
|
||||
|
||||
/**
|
||||
@ -208,6 +217,7 @@ public class Model{
|
||||
*/
|
||||
public boolean addEtudiant(Groupe g, Etudiant e){
|
||||
//Si on a la place
|
||||
if(g!=g.getPointPoint())
|
||||
if(this.addEtuToParent(g.getPointPoint(), e)==false)
|
||||
return false;
|
||||
//On induqe a la BD de sauvegarder cette modification
|
||||
@ -225,13 +235,16 @@ public class Model{
|
||||
if(g.getMax()==g.getSize())
|
||||
return false;
|
||||
for(Etudiant et:g.getEtudiants()){
|
||||
if(et==e){
|
||||
if(et.getId()==e.getId()){
|
||||
return true;
|
||||
}
|
||||
}
|
||||
if(g.getPointPoint()!=g)
|
||||
if(this.addEtuToParent(g.getPointPoint(), e)==false){return false;}
|
||||
this.promo.addToGroupe(g, e);
|
||||
if(g.getPointPoint()!=g){
|
||||
if(this.addEtuToParent(g.getPointPoint(), e)==false){
|
||||
return false;
|
||||
}
|
||||
}
|
||||
this.bd.saveEtu(e, g);
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -267,12 +280,10 @@ public class Model{
|
||||
this.promo=null;
|
||||
}
|
||||
}catch(SQLException e){
|
||||
System.out.println("hooo");
|
||||
}
|
||||
rs.close();
|
||||
pst.close();
|
||||
}catch(SQLException e){
|
||||
System.out.println("erreur dans le resultat");
|
||||
}
|
||||
this.bd.close(cnx);
|
||||
return agf;
|
||||
|
@ -225,21 +225,6 @@ public class BD {
|
||||
pst.setInt(2, etudiant.getId());
|
||||
pst.setInt(1, g.getId());
|
||||
pst.executeUpdate();
|
||||
boolean la=false;
|
||||
while(g!=g.getPointPoint() || la==false){
|
||||
g=g.getPointPoint();
|
||||
for(Etudiant e:g.getEtudiants()){
|
||||
if(e==etudiant){
|
||||
la=true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(la==false){
|
||||
pst.setInt(2, etudiant.getId());
|
||||
pst.setInt(1, g.getId());
|
||||
pst.executeUpdate();
|
||||
}
|
||||
}
|
||||
}else{
|
||||
pst.close();
|
||||
pst=cnx.prepareStatement(
|
||||
@ -248,18 +233,6 @@ public class BD {
|
||||
pst.setString(2, etudiant.getNom());
|
||||
pst.setString(3, etudiant.getPrenom());
|
||||
pst.executeUpdate();
|
||||
pst.close();
|
||||
pst=cnx.prepareStatement(
|
||||
"INSERT INTO `CONTIENT` (`idGroupe`, `idEt`) VALUES (?, ?);");
|
||||
pst.setInt(2, etudiant.getId());
|
||||
pst.setInt(1, g.getId());
|
||||
pst.executeUpdate();
|
||||
while(g.getPointPoint()!=g){
|
||||
g=g.getPointPoint();
|
||||
pst.setInt(2, etudiant.getId());
|
||||
pst.setInt(1, g.getId());
|
||||
pst.executeUpdate();
|
||||
}
|
||||
}
|
||||
rs.close();
|
||||
pst.close();
|
||||
|
@ -6,11 +6,12 @@ import fr.iutfbleau.projetIHM2022FI2.Graphic.Controller.ActionListenerNouveauEtu
|
||||
import fr.iutfbleau.projetIHM2022FI2.Graphic.Controller.SelecteurEtudiant;
|
||||
import fr.iutfbleau.projetIHM2022FI2.MNP.EtudiantNP;
|
||||
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.Set;
|
||||
import java.awt.GridLayout;
|
||||
import java.awt.Color;
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JOptionPane;
|
||||
import javax.swing.JPanel;
|
||||
|
||||
@ -76,12 +77,34 @@ public class FenetreSelectionEtu extends JPanel{
|
||||
this.add(lab);
|
||||
index++;
|
||||
}
|
||||
if(etu.size()==0){
|
||||
this.add(new JLabel("Ce groupe possède tous les étudiants déja présent"));
|
||||
}
|
||||
JButton nouveau=new JButton("Nouveau +");
|
||||
nouveau.setBackground(Color.RED);
|
||||
nouveau.addActionListener(new ActionListenerNouveauEtu(this));
|
||||
JButton all=new JButton("tous");
|
||||
this.add(all);
|
||||
all.addActionListener(new ActionListenerNouveauEtu(this));
|
||||
this.add(nouveau);
|
||||
}
|
||||
|
||||
public void addAll(){
|
||||
if(this.getComponent(this.etu.size()).getBackground()==Color.GREEN){
|
||||
int i=0;
|
||||
for(Etudiant e:this.etu){
|
||||
this.getComponent(i).setBackground(this.getBackground());
|
||||
if(this.liste.contains(e))
|
||||
this.liste.remove(e);
|
||||
i++;
|
||||
}
|
||||
this.getComponent(this.etu.size()).setBackground(this.getBackground());
|
||||
}else{
|
||||
int i=0;
|
||||
for(Etudiant e:this.etu){
|
||||
this.getComponent(i).setBackground(Color.GREEN);
|
||||
this.liste.add(e);
|
||||
i++;
|
||||
}
|
||||
this.getComponent(this.etu.size()).setBackground(Color.GREEN);
|
||||
}
|
||||
this.repaint();
|
||||
}
|
||||
}
|
||||
|
@ -9,33 +9,19 @@ import javax.swing.JButton;
|
||||
import java.awt.*;
|
||||
|
||||
public class PanelEtudiant extends JPanel{
|
||||
private JLabel nom;
|
||||
private Etudiant e;
|
||||
private JButton renomer;
|
||||
private JButton supprimer;
|
||||
private JButton deplacer;
|
||||
public PanelEtudiant(Etudiant e){
|
||||
super(new GridBagLayout());
|
||||
this.nom=new JLabel(e.getNom()+" "+e.getPrenom()+" "+e.getId(), JLabel.LEFT);
|
||||
|
||||
this.renomer=new JButton("r");
|
||||
this.supprimer=new JButton("-");
|
||||
this.deplacer=new JButton("c");
|
||||
GridBagConstraints cbg=new GridBagConstraints();
|
||||
|
||||
cbg.gridy=0;
|
||||
cbg.anchor=GridBagConstraints.EAST;
|
||||
cbg.fill=GridBagConstraints.BOTH;
|
||||
|
||||
this.add(this.nom, cbg);
|
||||
|
||||
cbg.gridwidth=0;
|
||||
cbg.gridheight=0;
|
||||
cbg.anchor=GridBagConstraints.EAST;
|
||||
cbg.fill=GridBagConstraints.NONE;
|
||||
|
||||
this.add(this.renomer, cbg);
|
||||
this.add(this.supprimer, cbg);
|
||||
this.add(this.deplacer, cbg);
|
||||
super(new GridLayout(1,2,20,10));
|
||||
this.e=e;
|
||||
JLabel label=new JLabel(" "+e.getNom()+" "+e.getPrenom()+" "+e.getId(), JLabel.LEFT);
|
||||
this.supprimer=new JButton("supr");
|
||||
this.deplacer=new JButton("change");
|
||||
this.add(label);
|
||||
JPanel bouton=new JPanel(new GridLayout(1,2));
|
||||
bouton.add(this.supprimer);
|
||||
bouton.add(this.deplacer);
|
||||
this.add(bouton);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user