111 lines
		
	
	
		
			3.6 KiB
		
	
	
	
		
			C#
		
	
	
	
	
	
			
		
		
	
	
			111 lines
		
	
	
		
			3.6 KiB
		
	
	
	
		
			C#
		
	
	
	
	
	
| #region Ressources extérieures
 | |
| using System;
 | |
| using System.Collections.Generic;
 | |
| using System.Text;
 | |
| using System.Data;
 | |
| using System.Data.SqlClient;
 | |
| using System.Data.SqlTypes;
 | |
| using Projet_GestionCommerceInfo.Classes;
 | |
| #endregion
 | |
| 
 | |
| namespace Projet_GestionCommerceInfo.Acces
 | |
| {
 | |
|  /// <summary>
 | |
|  /// Couche d'accès aux données (Data Access Layer)
 | |
|  /// </summary>
 | |
|  public class A_Article : ADBase
 | |
|  {
 | |
|   #region Constructeurs
 | |
|   public A_Article(string sChaineConnexion)
 | |
|   	: base(sChaineConnexion)
 | |
|   { }
 | |
|   #endregion
 | |
|   public int Ajouter(string Designation, int Stock, bool Visible, bool Actif, decimal? PrixHTVA)
 | |
|   {
 | |
|    CreerCommande("AjouterArticle");
 | |
|    int res = 0;
 | |
|    Commande.Parameters.Add("ID", SqlDbType.Int);
 | |
|    Direction("ID", ParameterDirection.Output);
 | |
|    Commande.Parameters.AddWithValue("@Designation", Designation);
 | |
|    Commande.Parameters.AddWithValue("@Stock", Stock);
 | |
|    Commande.Parameters.AddWithValue("@Visible", Visible);
 | |
|    Commande.Parameters.AddWithValue("@Actif", Actif);
 | |
|    if(PrixHTVA == null) Commande.Parameters.AddWithValue("@PrixHTVA", Convert.DBNull);
 | |
|    else Commande.Parameters.AddWithValue("@PrixHTVA", PrixHTVA);
 | |
|    Commande.Connection.Open();
 | |
|    Commande.ExecuteNonQuery();
 | |
|    res = int.Parse(LireParametre("ID"));
 | |
|    Commande.Connection.Close();
 | |
|    return res;
 | |
|   }
 | |
|   public int Modifier(int ID, string Designation, int Stock, bool Visible, bool Actif, decimal? PrixHTVA)
 | |
|   {
 | |
|    CreerCommande("ModifierArticle");
 | |
|    int res = 0;
 | |
|    Commande.Parameters.AddWithValue("@ID", ID);
 | |
|    Commande.Parameters.AddWithValue("@Designation", Designation);
 | |
|    Commande.Parameters.AddWithValue("@Stock", Stock);
 | |
|    Commande.Parameters.AddWithValue("@Visible", Visible);
 | |
|    Commande.Parameters.AddWithValue("@Actif", Actif);
 | |
|    if(PrixHTVA == null) Commande.Parameters.AddWithValue("@PrixHTVA", Convert.DBNull);
 | |
|    else Commande.Parameters.AddWithValue("@PrixHTVA", PrixHTVA);
 | |
|    Commande.Connection.Open();
 | |
|    Commande.ExecuteNonQuery();
 | |
|    Commande.Connection.Close();
 | |
|    return res;
 | |
|   }
 | |
|   public List<C_Article> Lire(string Index)
 | |
|   {
 | |
|    CreerCommande("SelectionnerArticle");
 | |
|    Commande.Parameters.AddWithValue("@Index", Index);
 | |
|    Commande.Connection.Open();
 | |
|    SqlDataReader dr = Commande.ExecuteReader();
 | |
|    List<C_Article> res = new List<C_Article>();
 | |
|    while (dr.Read())
 | |
|    {
 | |
|     C_Article tmp = new C_Article();
 | |
|     tmp.ID = int.Parse(dr["ID"].ToString());
 | |
|     tmp.Designation = dr["Designation"].ToString();
 | |
|     tmp.Stock = int.Parse(dr["Stock"].ToString());
 | |
|     tmp.Visible = bool.Parse(dr["Visible"].ToString());
 | |
|     tmp.Actif = bool.Parse(dr["Actif"].ToString());
 | |
|    if(dr["PrixHTVA"] != DBNull.Value) tmp.PrixHTVA = decimal.Parse(dr["PrixHTVA"].ToString());
 | |
|     res.Add(tmp);
 | |
| 			}
 | |
| 			dr.Close();
 | |
| 			Commande.Connection.Close();
 | |
| 			return res;
 | |
| 		}
 | |
|   public C_Article Lire_ID(int ID)
 | |
|   {
 | |
|    CreerCommande("SelectionnerArticle_ID");
 | |
|    Commande.Parameters.AddWithValue("@ID", ID);
 | |
|    Commande.Connection.Open();
 | |
|    SqlDataReader dr = Commande.ExecuteReader();
 | |
|    C_Article res = new C_Article();
 | |
|    while (dr.Read())
 | |
|    {
 | |
|     res.ID = int.Parse(dr["ID"].ToString());
 | |
|     res.Designation = dr["Designation"].ToString();
 | |
|     res.Stock = int.Parse(dr["Stock"].ToString());
 | |
|     res.Visible = bool.Parse(dr["Visible"].ToString());
 | |
|     res.Actif = bool.Parse(dr["Actif"].ToString());
 | |
|    if(dr["PrixHTVA"] != DBNull.Value) res.PrixHTVA = decimal.Parse(dr["PrixHTVA"].ToString());
 | |
|    }
 | |
| 			dr.Close();
 | |
| 			Commande.Connection.Close();
 | |
| 			return res;
 | |
| 		}
 | |
|   public int Supprimer(int ID)
 | |
|   {
 | |
|    CreerCommande("SupprimerArticle");
 | |
|    int res = 0;
 | |
|    Commande.Parameters.AddWithValue("@ID", ID);
 | |
|    Commande.Connection.Open();
 | |
|    res = Commande.ExecuteNonQuery();
 | |
| 			Commande.Connection.Close();
 | |
| 			return res;
 | |
| 		}
 | |
|  }
 | |
| }
 |