115 lines
4.9 KiB
C#
115 lines
4.9 KiB
C#
|
using System;
|
|||
|
using System.Collections.Generic;
|
|||
|
using System.Data;
|
|||
|
using System.Data.SqlClient;
|
|||
|
using System.Linq;
|
|||
|
using System.Text;
|
|||
|
using System.Threading.Tasks;
|
|||
|
using GestionDeCommerceInfoClasseBDDNCouches;
|
|||
|
|
|||
|
namespace GestionDeCommerceInfoClasseBDDNCouches.DataLayer
|
|||
|
{
|
|||
|
public class BDDAccesPanier : BDDAccesBase
|
|||
|
{
|
|||
|
public BDDAccesPanier(string schConn) : base(schConn)
|
|||
|
{
|
|||
|
}
|
|||
|
public List<Panier.LSTArticle> listeArticlePanier(int panierId)
|
|||
|
{
|
|||
|
CommandSQL.Parameters.Clear();
|
|||
|
List<Panier.LSTArticle> lstARt = new List<Panier.LSTArticle>();
|
|||
|
CommandSQL.CommandType = System.Data.CommandType.StoredProcedure;
|
|||
|
CommandSQL.CommandText = "ListArticlePanier";
|
|||
|
CommandSQL.Parameters.AddWithValue("@ID", panierId);
|
|||
|
CommandSQL.Connection.Open();
|
|||
|
SqlDataReader data = CommandSQL.ExecuteReader();
|
|||
|
while (data.Read())
|
|||
|
{
|
|||
|
lstARt.Add(new Panier.LSTArticle(new BDDAccesArticle(base.SCHConnBDD).LireArticle(int.Parse(data["ArticleID"].ToString())),
|
|||
|
int.Parse(data["ID"].ToString()),
|
|||
|
int.Parse(data["Quantite"].ToString()),
|
|||
|
float.Parse(data["PrixHTVA"].ToString())));
|
|||
|
|
|||
|
|
|||
|
}
|
|||
|
CommandSQL.Connection.Close();
|
|||
|
|
|||
|
return lstARt;
|
|||
|
}
|
|||
|
public Panier LirePanier(int id)
|
|||
|
{
|
|||
|
Panier pret;
|
|||
|
|
|||
|
CommandSQL.CommandType = System.Data.CommandType.StoredProcedure;
|
|||
|
CommandSQL.CommandText = "LirePanier";
|
|||
|
CommandSQL.Parameters.AddWithValue("@ID", id);
|
|||
|
CommandSQL.Connection.Open();
|
|||
|
SqlDataReader data = CommandSQL.ExecuteReader();
|
|||
|
|
|||
|
if (data.Read())
|
|||
|
{
|
|||
|
pret = new Panier(int.Parse(data["ID"].ToString()),
|
|||
|
new BDDAccesUtilisateur(base.SCHConnBDD).LireUtilisateur(int.Parse(data["UserId"].ToString())),
|
|||
|
data["Nom"].ToString(),
|
|||
|
(Panier.Type_E)int.Parse(data["Type"].ToString()),
|
|||
|
(Panier.Status_E)int.Parse(data["Status"].ToString()),
|
|||
|
DateTime.Parse(data["DateAchat"].ToString()),
|
|||
|
listeArticlePanier(id));
|
|||
|
CommandSQL.Connection.Close();
|
|||
|
return pret;
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
CommandSQL.Connection.Close();
|
|||
|
return null;
|
|||
|
}
|
|||
|
}
|
|||
|
public void SuprimerArticlePanier(int id)
|
|||
|
{
|
|||
|
CommandSQL.Parameters.Clear();
|
|||
|
CommandSQL.CommandType = System.Data.CommandType.StoredProcedure;
|
|||
|
CommandSQL.CommandText = "SuprimerArticlePanier";
|
|||
|
CommandSQL.Parameters.AddWithValue("@ID", id);
|
|||
|
CommandSQL.Connection.Open();
|
|||
|
SqlDataReader data = CommandSQL.ExecuteReader();
|
|||
|
CommandSQL.Connection.Close();
|
|||
|
}
|
|||
|
public int AjouterArticlePanier(Panier.LSTArticle lstart, int idPanier)
|
|||
|
{
|
|||
|
CommandSQL.CommandType = System.Data.CommandType.StoredProcedure;
|
|||
|
CommandSQL.CommandText = "AjoutArticleDansPanier";
|
|||
|
CommandSQL.Parameters.Clear();
|
|||
|
CommandSQL.Parameters.Add("ID", SqlDbType.Int);
|
|||
|
Direction("ID", ParameterDirection.Output);
|
|||
|
CommandSQL.Parameters.AddWithValue("@IDArt", lstart.article.Designation);
|
|||
|
CommandSQL.Parameters.AddWithValue("@IDPanier", idPanier);
|
|||
|
CommandSQL.Parameters.AddWithValue("@Quantite", lstart.quantitee);
|
|||
|
CommandSQL.Parameters.AddWithValue("@PrixHTVA", lstart.prixHTVAPC);
|
|||
|
CommandSQL.Connection.Open();
|
|||
|
SqlDataReader data = CommandSQL.ExecuteReader();
|
|||
|
int a = int.Parse(CommandSQL.Parameters["ID"].Value.ToString());
|
|||
|
lstart.id = a;
|
|||
|
CommandSQL.Connection.Close();
|
|||
|
return a;
|
|||
|
}
|
|||
|
public int CreerPanier(Panier panier)
|
|||
|
{
|
|||
|
CommandSQL.CommandType = System.Data.CommandType.StoredProcedure;
|
|||
|
CommandSQL.CommandText = "AjoutArticleDansPanier";
|
|||
|
CommandSQL.Parameters.Clear();
|
|||
|
CommandSQL.Parameters.Add("ID", SqlDbType.Int);
|
|||
|
Direction("ID", ParameterDirection.Output);
|
|||
|
CommandSQL.Parameters.AddWithValue("@UserID", panier.user.ID);
|
|||
|
CommandSQL.Parameters.AddWithValue("@Nom", panier.nomPanier);
|
|||
|
CommandSQL.Parameters.AddWithValue("@type", (int)panier.type);
|
|||
|
CommandSQL.Connection.Open();
|
|||
|
SqlDataReader data = CommandSQL.ExecuteReader();
|
|||
|
int a = int.Parse(CommandSQL.Parameters["ID"].Value.ToString());
|
|||
|
panier.idPanier = a;
|
|||
|
CommandSQL.Connection.Close();
|
|||
|
return a;
|
|||
|
}
|
|||
|
|
|||
|
}
|
|||
|
}
|