GestionDeDommerceInformatiq.../GestionDeCommerceInfoClasse.../Panier.cs

151 lines
4.5 KiB
C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using GestionDeCommerceInfoClasseBDDNCouches.DataLayer;
namespace GestionDeCommerceInfoClasseBDDNCouches
{
public class Panier
{
public int idPanier;
public Utilisateur user;
public string nomPanier;
public Type_E type;
public Status_E status;
public DateTime dateAchat;
public List<LSTArticle> ArticleDansPanier;
public enum Type_E {Vente, Achat};
public enum Status_E
{
NULL = 0x00,
Commander = 0x01,
Envoyer = 0x02,
Recu = 0x03
};
public struct LSTArticle
{
public Article article;
public int quantitee;
public int id;
public float prixHTVAPC;
public float prixHTVATot
{
get
{
return prixHTVATot * quantitee;
}
}
public LSTArticle(Article art,int id, int quantitee)
{
this.article = art;
this.quantitee = quantitee;
prixHTVAPC = (float)article.PrixHTVA;
// prixHTVATot = prixHTVAPC * quantitee;
this.id = id;
}
public LSTArticle(Article article, int quantitee)
{
this.article = article;
this.quantitee = quantitee;
prixHTVAPC = (float)article.PrixHTVA;
//prixHTVATot = prixHTVAPC * quantitee;
this.id = -1;
}
public LSTArticle(Article article, int id, int quantitee, float prix)
{
this.article = article;
this.quantitee = quantitee;
prixHTVAPC = (float)article.PrixHTVA;
//prixHTVATot = prixHTVAPC * quantitee;
this.id = id;
}
public override string ToString()
{
return article.Designation;
}
public static implicit operator string(LSTArticle lSTArticle)
{
return lSTArticle.ToString();
}
}
public Panier()
{
ArticleDansPanier = new List<LSTArticle>();
}
public Panier(int id, Utilisateur user, string nomPanier, Type_E type, Status_E status, DateTime dateAchat, List<LSTArticle> lstart)
{
idPanier = id;
this.user = user;
this.nomPanier = nomPanier;
this.type = type;
this.status = status;
this.dateAchat = dateAchat;
ArticleDansPanier = lstart;
}
public Panier(Utilisateur user, string nomPanier, Type_E type, Status_E status, DateTime dateAchat)
{
this.user = user;
this.nomPanier = nomPanier;
this.type = type;
this.status = status;
this.dateAchat = dateAchat;
ArticleDansPanier = new List<LSTArticle>();
idPanier = -1;
}
public bool SuprimerArticlePanier(BDDAccesPanier bdd, LSTArticle article)
{
for(int i=0;ArticleDansPanier.Count()>i;i++)
{
if(ArticleDansPanier[i].id == article.id)
{
ArticleDansPanier.RemoveAt(i);
return true;
}
}
return false;
}
public LSTArticle ajoutArticle(BDDAccesPanier bdd, Article artcle, int quant)
{
LSTArticle lstart = new LSTArticle(artcle, quant);
bdd.AjouterArticlePanier(lstart, this.idPanier);
ArticleDansPanier.Add(lstart);
return lstart;
}
public LSTArticle? ajoutArticle(Article artcle, int quant)
{
if (idPanier < 0)
{
LSTArticle lstart = new LSTArticle(artcle, quant);
ArticleDansPanier.Add(lstart);
return lstart;
}
else
return null;
}
public void EnvoyerPanierBDD(BDDAccesPanier bdd)
{
if(idPanier < 0)
{
bdd.CreerPanier(this);
foreach(LSTArticle lstart in ArticleDansPanier)
{
bdd.AjouterArticlePanier(lstart, this.idPanier);
}
}
}
}
}