modif supprimer dans commande

This commit is contained in:
famille Thevenot 2024-09-18 17:38:05 +02:00
parent 926b12ec55
commit 7136c719cc

View File

@ -1,120 +1,120 @@
/* /*
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template * Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
*/ */
package métiers; package métiers;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import java.util.Objects; import java.util.Objects;
/** /**
* *
* @author ilona * @author ilona
*/ */
public class Commande { public class Commande {
private int noCom, noVendeur; private int noCom, noVendeur;
private String dateCom; private String dateCom;
private final HashMap<Instrument, Integer> lesLignes = new HashMap<>(); private final HashMap<Instrument, Integer> lesLignes = new HashMap<>();
public Commande(int noCom, int noVendeur, String dateCom) { public Commande(int noCom, int noVendeur, String dateCom) {
this.noCom = noCom; this.noCom = noCom;
this.noVendeur = noVendeur; this.noVendeur = noVendeur;
this.dateCom = dateCom; this.dateCom = dateCom;
} }
/** /**
* Ajoute une quantité donnée d'un instrument à la commande * Ajoute une quantité donnée d'un instrument à la commande
* @param unInstrument instrument à ajouter * @param unInstrument instrument à ajouter
* @param qte quantité à ajouter * @param qte quantité à ajouter
* @return true si l'ajout est bon * @return true si l'ajout est bon
*/ */
public boolean ajouter(Instrument unInstrument, int qte){ public boolean ajouter(Instrument unInstrument, int qte){
boolean ajoutOK; boolean ajoutOK;
int qteDisponible = unInstrument.getQteStock(); int qteDisponible = unInstrument.getQteStock();
if (qteDisponible<qte){ if (qteDisponible<qte){
ajoutOK = false; ajoutOK = false;
}else { }else {
ajoutOK = true; ajoutOK = true;
lesLignes.put(unInstrument,qte); lesLignes.put(unInstrument,qte);
unInstrument.setQteStock(qteDisponible-qte); unInstrument.setQteStock(qteDisponible-qte);
} }
return ajoutOK; return ajoutOK;
} }
/** /**
* Supprimer un instrument de la commande * Supprimer un instrument de la commande
* @param unInstrument instrument à supprimer * @param unInstrument instrument à supprimer
* @return true si la suppression est effectuée * @return true si la suppression est effectuée
*/ */
public boolean supprimer(Instrument unInstrument){ public boolean supprimer(Instrument unInstrument){
//lesLignes.remove(unInstrument); //lesLignes.remove(unInstrument);
boolean suppOK; boolean suppOK;
if (lesLignes.containsValue(unInstrument) == true){ if (lesLignes.containsKey(unInstrument) == true){
suppOK = true; suppOK = true;
lesLignes.remove(unInstrument); lesLignes.remove(unInstrument);
} else { } else {
suppOK = false; suppOK = false;
} }
return suppOK; return suppOK;
} }
///////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////
public int getNoCom() { public int getNoCom() {
return noCom; return noCom;
} }
public int getNoVendeur() { public int getNoVendeur() {
return noVendeur; return noVendeur;
} }
public String getDateCom() { public String getDateCom() {
return dateCom; return dateCom;
} }
public HashMap<Instrument, Integer> getLesLignes() { public HashMap<Instrument, Integer> getLesLignes() {
return lesLignes; return lesLignes;
} }
public void setNoCom(int noCom) { public void setNoCom(int noCom) {
this.noCom = noCom; this.noCom = noCom;
} }
public void setNoVendeur(int noVendeur) { public void setNoVendeur(int noVendeur) {
this.noVendeur = noVendeur; this.noVendeur = noVendeur;
} }
public void setDateCom(String dateCom) { public void setDateCom(String dateCom) {
this.dateCom = dateCom; this.dateCom = dateCom;
} }
@Override @Override
public boolean equals(Object obj) { public boolean equals(Object obj) {
if (this == obj) { if (this == obj) {
return true; return true;
} }
if (obj == null) { if (obj == null) {
return false; return false;
} }
if (getClass() != obj.getClass()) { if (getClass() != obj.getClass()) {
return false; return false;
} }
final Commande other = (Commande) obj; final Commande other = (Commande) obj;
if (this.noCom != other.noCom) { if (this.noCom != other.noCom) {
return false; return false;
} }
if (this.noVendeur != other.noVendeur) { if (this.noVendeur != other.noVendeur) {
return false; return false;
} }
return Objects.equals(this.dateCom, other.dateCom); return Objects.equals(this.dateCom, other.dateCom);
} }
} }