1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70
| using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections;
namespace GestionBar
{
class Commande
{
private List<Consommation> ListeConsommations;
private Consommation consommation;
public Commande()
{
ListeConsommations = new List<Consommation>();
}
public List<Consommation> listeConsommations
{
get { return ListeConsommations; }
}
private int IndexOf(Produit produit)
{
int index = -1;
for (int i = 0; i < ListeConsommations.Count; i++)
{
if (ListeConsommations[i].produitCommande == produit)
{
index = i;
break;
}
}
return index;
}
public void Add(Produit produit)
{
int index = this.IndexOf(produit);
if (index == -1)
{
consommation = new Consommation(produit, 1);
this.ListeConsommations.Add(consommation);
}
else
{
this.ListeConsommations[index].quantite++;
}
}
public void Remove(Produit produit)
{
int index = this.IndexOf(produit);
if (index != -1)
{
if (this.ListeConsommations[index].quantite == 1)
{
this.ListeConsommations.Remove(this.ListeConsommations[index]);
}
else
{
this.ListeConsommations[index].quantite--;
}
}
}
}
} |
Partager