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 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections;
using System.ComponentModel;
namespace GestionBar
{
class Commande : INotifyPropertyChanged
{
private BindingList<Consommation> listeConsommations;
private Consommation consommation;
private decimal montantTotal;
public Commande()
{
listeConsommations = new BindingList<Consommation>();
montantTotal = 0;
}
public BindingList<Consommation> ListeConsommations
{
get { return listeConsommations; }
}
public decimal MontantTotal
{
get { return montantTotal; }
set { montantTotal = value; }
}
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;
}
private void TrierListe()
{
for (int i = 0; i < listeConsommations.Count; i++)
{
for (int j = 0; j < listeConsommations.Count; j++)
{
if (i != j)
{
if ((listeConsommations[i].ProduitCommande.Nom.CompareTo(listeConsommations[j].ProduitCommande.Nom)) < 0)
{
consommation = listeConsommations[i];
listeConsommations[i] = listeConsommations[j];
listeConsommations[j] = consommation;
}
}
}
}
}
public void Add(Produit Produit)
{
int index = this.IndexOf(Produit);
if (index == -1)
{
consommation = new Consommation(Produit, 1);
this.ListeConsommations.Add(consommation);
TrierListe();
//ListeConsommations = ListeConsommations.OrderBy(x => x.nomProduit).ToList()
//List<Consommation> ListeTriee = ListeConsommations.OrderBy(x => x.nomProduit).ToList();
//this.ListeConsommations = new BindingList<Consommation>(ListeTriee);
}
else
{
this.ListeConsommations[index].Quantite++;
}
this.OnPropertyChanged("ListeConsommations");
this.MontantTotal += Produit.Prix;
}
public bool 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--;
}
this.OnPropertyChanged("ListeConsommations");
this.MontantTotal -= produit.Prix;
return true;
}
else return false;
}
public event PropertyChangedEventHandler PropertyChanged;
public void OnPropertyChanged(string propertyName)
{
if (this.PropertyChanged != null)
{
this.PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
}
}
}
} |
Partager