Initial commit
This commit is contained in:
		
							
								
								
									
										86
									
								
								Nouveau dossier/A_Base.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										86
									
								
								Nouveau dossier/A_Base.cs
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,86 @@
 | 
			
		||||
#region Ressources extérieures
 | 
			
		||||
using System;
 | 
			
		||||
using System.Collections.Generic;
 | 
			
		||||
using System.Text;
 | 
			
		||||
using System.Data;
 | 
			
		||||
using System.Data.SqlClient;
 | 
			
		||||
using System.Configuration;
 | 
			
		||||
#endregion
 | 
			
		||||
 | 
			
		||||
namespace Projet_BD_EXEMPLE.Acces
 | 
			
		||||
{
 | 
			
		||||
 public class ADBase
 | 
			
		||||
  {
 | 
			
		||||
  #region Données membres
 | 
			
		||||
  protected SqlCommand _commande;
 | 
			
		||||
  #endregion
 | 
			
		||||
  #region Constructeurs (étendus)
 | 
			
		||||
  /// <summary>
 | 
			
		||||
  /// Constructeur par défaut
 | 
			
		||||
  /// </summary>
 | 
			
		||||
  /// <remarks>La chaîne de connexion est récupérée en argument</remarks>
 | 
			
		||||
  public ADBase(string sChaineConnexion)
 | 
			
		||||
  {
 | 
			
		||||
   _commande = new SqlCommand();
 | 
			
		||||
   _commande.Connection = new SqlConnection(sChaineConnexion);
 | 
			
		||||
  }
 | 
			
		||||
  /// <summary>
 | 
			
		||||
  /// Méthode assignant une procédure stockée
 | 
			
		||||
  /// </summary>
 | 
			
		||||
  /// <param name="sCommande">Nom de la procédure stockée</param>
 | 
			
		||||
  public void CreerCommande(string sCommande)
 | 
			
		||||
  {
 | 
			
		||||
   _commande.CommandType = CommandType.StoredProcedure;
 | 
			
		||||
   _commande.CommandText = sCommande;
 | 
			
		||||
  }
 | 
			
		||||
  /// <summary>
 | 
			
		||||
  /// Méthode assignant une procédure stockée ET une chaîne de connexion
 | 
			
		||||
  /// </summary>
 | 
			
		||||
  /// <param name="sCommande">Nom de la procédure stockée</param>
 | 
			
		||||
  /// <param name="sConnexion">Chaîne de connexion à utiliser</param>
 | 
			
		||||
  public void CreerCommande(string sCommande, string sConnexion)
 | 
			
		||||
  {
 | 
			
		||||
   _commande.Connection = new SqlConnection(sConnexion);
 | 
			
		||||
   _commande.CommandType = CommandType.StoredProcedure;
 | 
			
		||||
   _commande.CommandText = sCommande;
 | 
			
		||||
  }
 | 
			
		||||
  /// <summary>
 | 
			
		||||
  /// Méthode assignant une procédure stockée et le type de requête
 | 
			
		||||
  /// </summary>
 | 
			
		||||
  /// <param name="sCommande">Nom de la procédure stockée</param>
 | 
			
		||||
  /// <param name="bTypeProcedures">Type de requête (Vrai=stockée, Faux=Texte)</param>
 | 
			
		||||
  public void CreerCommande(string sCommande, bool bTypeRequete)
 | 
			
		||||
  {
 | 
			
		||||
   if (bTypeRequete)	_commande.CommandType = CommandType.StoredProcedure;
 | 
			
		||||
   else	_commande.CommandType = CommandType.Text;
 | 
			
		||||
   _commande.CommandText = sCommande;
 | 
			
		||||
  }
 | 
			
		||||
  /// <summary>
 | 
			
		||||
  /// Méthode assignant une procédure stockée, une chaîne de connexion et le type de requête
 | 
			
		||||
  /// </summary>
 | 
			
		||||
  /// <param name="sCommande">Nom de la procédure stockée</param>
 | 
			
		||||
  /// <param name="sConnexion">Chaîne de connexion à utiliser</param>
 | 
			
		||||
  /// <param name="bTypeProcedures">Type de requête (Vrai=stockée, Faux=Texte)</param>
 | 
			
		||||
  public void CreerCommande(string sCommande, bool bTypeRequete, string sConnexion)
 | 
			
		||||
  {
 | 
			
		||||
   _commande.Connection = new SqlConnection(sConnexion);
 | 
			
		||||
   if (bTypeRequete)	_commande.CommandType = CommandType.StoredProcedure;
 | 
			
		||||
   else	_commande.CommandType = CommandType.Text;
 | 
			
		||||
   _commande.CommandText = sCommande;
 | 
			
		||||
  }
 | 
			
		||||
  #endregion
 | 
			
		||||
  #region Accesseurs
 | 
			
		||||
  public SqlCommand Commande
 | 
			
		||||
  {
 | 
			
		||||
   get { return _commande; }
 | 
			
		||||
   set { _commande = value; }
 | 
			
		||||
  }
 | 
			
		||||
  #endregion
 | 
			
		||||
  #region Utilitaires
 | 
			
		||||
  public void Direction(string sParam, ParameterDirection dParam)
 | 
			
		||||
  {	Commande.Parameters[sParam].Direction = dParam;	}
 | 
			
		||||
  public string LireParametre(string sParam)
 | 
			
		||||
  {	return Commande.Parameters[sParam].Value.ToString();	}
 | 
			
		||||
  #endregion
 | 
			
		||||
 }
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										104
									
								
								Nouveau dossier/A_Personne.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										104
									
								
								Nouveau dossier/A_Personne.cs
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,104 @@
 | 
			
		||||
#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_BD_EXEMPLE.Classes;
 | 
			
		||||
#endregion
 | 
			
		||||
 | 
			
		||||
namespace Projet_BD_EXEMPLE.Acces
 | 
			
		||||
{
 | 
			
		||||
 /// <summary>
 | 
			
		||||
 /// Couche d'accès aux données (Data Access Layer)
 | 
			
		||||
 /// </summary>
 | 
			
		||||
 public class A_Personne : ADBase
 | 
			
		||||
 {
 | 
			
		||||
  #region Constructeurs
 | 
			
		||||
  public A_Personne(string sChaineConnexion)
 | 
			
		||||
  	: base(sChaineConnexion)
 | 
			
		||||
  { }
 | 
			
		||||
  #endregion
 | 
			
		||||
  public int Ajouter(string NOM, string PRE, DateTime? NAI)
 | 
			
		||||
  {
 | 
			
		||||
   CreerCommande("AjouterPersonne");
 | 
			
		||||
   int res = 0;
 | 
			
		||||
   Commande.Parameters.Add("ID", SqlDbType.Int);
 | 
			
		||||
   Direction("ID", ParameterDirection.Output);
 | 
			
		||||
   Commande.Parameters.AddWithValue("@NOM", NOM);
 | 
			
		||||
   if(PRE == null) Commande.Parameters.AddWithValue("@PRE", Convert.DBNull);
 | 
			
		||||
   else Commande.Parameters.AddWithValue("@PRE", PRE);
 | 
			
		||||
   if(NAI == null) Commande.Parameters.AddWithValue("@NAI", Convert.DBNull);
 | 
			
		||||
   else Commande.Parameters.AddWithValue("@NAI", NAI);
 | 
			
		||||
   Commande.Connection.Open();
 | 
			
		||||
   Commande.ExecuteNonQuery();
 | 
			
		||||
   res = int.Parse(LireParametre("ID"));
 | 
			
		||||
   Commande.Connection.Close();
 | 
			
		||||
   return res;
 | 
			
		||||
  }
 | 
			
		||||
  public int Modifier(int ID, string NOM, string PRE, DateTime? NAI)
 | 
			
		||||
  {
 | 
			
		||||
   CreerCommande("ModifierPersonne");
 | 
			
		||||
   int res = 0;
 | 
			
		||||
   Commande.Parameters.AddWithValue("ID", SqlDbType.Int);
 | 
			
		||||
   Commande.Parameters.AddWithValue("@NOM", NOM);
 | 
			
		||||
   if(PRE == null) Commande.Parameters.AddWithValue("@PRE", Convert.DBNull);
 | 
			
		||||
   else Commande.Parameters.AddWithValue("@PRE", PRE);
 | 
			
		||||
   if(NAI == null) Commande.Parameters.AddWithValue("@NAI", Convert.DBNull);
 | 
			
		||||
   else Commande.Parameters.AddWithValue("@NAI", NAI);
 | 
			
		||||
   Commande.Connection.Open();
 | 
			
		||||
   Commande.ExecuteNonQuery();
 | 
			
		||||
   Commande.Connection.Close();
 | 
			
		||||
   return res;
 | 
			
		||||
  }
 | 
			
		||||
  public List<C_Personne> Lire(string Index)
 | 
			
		||||
  {
 | 
			
		||||
   CreerCommande("SelectionnerPersonne");
 | 
			
		||||
   Commande.Parameters.AddWithValue("@Index", Index);
 | 
			
		||||
   Commande.Connection.Open();
 | 
			
		||||
   SqlDataReader dr = Commande.ExecuteReader();
 | 
			
		||||
   List<C_Personne> res = new List<C_Personne>();
 | 
			
		||||
   while (dr.Read())
 | 
			
		||||
   {
 | 
			
		||||
    C_Personne tmp = new C_Personne();
 | 
			
		||||
    tmp.ID = int.Parse(dr["ID"].ToString());
 | 
			
		||||
    tmp.NOM = dr["NOM"].ToString();
 | 
			
		||||
    tmp.PRE = dr["PRE"].ToString();
 | 
			
		||||
   if(dr["NAI"] != DBNull.Value) tmp.NAI = DateTime.Parse(dr["NAI"].ToString());
 | 
			
		||||
    res.Add(tmp);
 | 
			
		||||
			}
 | 
			
		||||
			dr.Close();
 | 
			
		||||
			Commande.Connection.Close();
 | 
			
		||||
			return res;
 | 
			
		||||
		}
 | 
			
		||||
  public C_Personne Lire_ID(int ID)
 | 
			
		||||
  {
 | 
			
		||||
   CreerCommande("SelectionnerPersonne_ID");
 | 
			
		||||
   Commande.Parameters.AddWithValue("@ID", ID);
 | 
			
		||||
   Commande.Connection.Open();
 | 
			
		||||
   SqlDataReader dr = Commande.ExecuteReader();
 | 
			
		||||
   C_Personne res = new C_Personne();
 | 
			
		||||
   while (dr.Read())
 | 
			
		||||
   {
 | 
			
		||||
    res.ID = int.Parse(dr["ID"].ToString());
 | 
			
		||||
    res.NOM = dr["NOM"].ToString();
 | 
			
		||||
    res.PRE = dr["PRE"].ToString();
 | 
			
		||||
   if(dr["NAI"] != DBNull.Value) res.NAI = DateTime.Parse(dr["NAI"].ToString());
 | 
			
		||||
   }
 | 
			
		||||
			dr.Close();
 | 
			
		||||
			Commande.Connection.Close();
 | 
			
		||||
			return res;
 | 
			
		||||
		}
 | 
			
		||||
  public int Supprimer(int ID)
 | 
			
		||||
  {
 | 
			
		||||
   CreerCommande("SupprimerPersonne");
 | 
			
		||||
   int res = 0;
 | 
			
		||||
   Commande.Parameters.AddWithValue("@ID", ID);
 | 
			
		||||
   Commande.Connection.Open();
 | 
			
		||||
   res = Commande.ExecuteNonQuery();
 | 
			
		||||
			Commande.Connection.Close();
 | 
			
		||||
			return res;
 | 
			
		||||
		}
 | 
			
		||||
 }
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										58
									
								
								Nouveau dossier/C_Personne.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										58
									
								
								Nouveau dossier/C_Personne.cs
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,58 @@
 | 
			
		||||
#region Ressources extérieures
 | 
			
		||||
using System;
 | 
			
		||||
using System.Collections.Generic;
 | 
			
		||||
using System.Text;
 | 
			
		||||
#endregion
 | 
			
		||||
 | 
			
		||||
namespace Projet_BD_EXEMPLE.Classes
 | 
			
		||||
{
 | 
			
		||||
 /// <summary>
 | 
			
		||||
 /// Classe de définition des données
 | 
			
		||||
 /// </summary>
 | 
			
		||||
 public class C_Personne
 | 
			
		||||
 {
 | 
			
		||||
  #region Données membres
 | 
			
		||||
  private int _ID;
 | 
			
		||||
  private string _NOM;
 | 
			
		||||
  private string _PRE;
 | 
			
		||||
  private DateTime? _NAI;
 | 
			
		||||
  #endregion
 | 
			
		||||
  #region Constructeurs
 | 
			
		||||
  public C_Personne()
 | 
			
		||||
  { }
 | 
			
		||||
  public C_Personne(string NOM_, string PRE_, DateTime? NAI_)
 | 
			
		||||
  {
 | 
			
		||||
   NOM = NOM_;
 | 
			
		||||
   PRE = PRE_;
 | 
			
		||||
   NAI = NAI_;
 | 
			
		||||
  }
 | 
			
		||||
  public C_Personne(int ID_, string NOM_, string PRE_, DateTime? NAI_)
 | 
			
		||||
   : this(NOM_, PRE_, NAI_)
 | 
			
		||||
  {
 | 
			
		||||
   ID = ID_;
 | 
			
		||||
  }
 | 
			
		||||
  #endregion
 | 
			
		||||
  #region Accesseurs
 | 
			
		||||
  public int ID
 | 
			
		||||
  {
 | 
			
		||||
   get { return _ID; }
 | 
			
		||||
   set { _ID = value; }
 | 
			
		||||
  }
 | 
			
		||||
  public string NOM
 | 
			
		||||
  {
 | 
			
		||||
   get { return _NOM; }
 | 
			
		||||
   set { _NOM = value; }
 | 
			
		||||
  }
 | 
			
		||||
  public string PRE
 | 
			
		||||
  {
 | 
			
		||||
   get { return _PRE; }
 | 
			
		||||
   set { _PRE = value; }
 | 
			
		||||
  }
 | 
			
		||||
  public DateTime? NAI
 | 
			
		||||
  {
 | 
			
		||||
   get { return _NAI; }
 | 
			
		||||
   set { _NAI = value; }
 | 
			
		||||
  }
 | 
			
		||||
  #endregion
 | 
			
		||||
 }
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										28
									
								
								Nouveau dossier/G_Base.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										28
									
								
								Nouveau dossier/G_Base.cs
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,28 @@
 | 
			
		||||
#region Ressources extérieures
 | 
			
		||||
using System;
 | 
			
		||||
using System.Collections.Generic;
 | 
			
		||||
using System.Text;
 | 
			
		||||
#endregion
 | 
			
		||||
 | 
			
		||||
namespace Projet_BD_EXEMPLE.Gestion
 | 
			
		||||
{
 | 
			
		||||
 public class G_Base
 | 
			
		||||
  {
 | 
			
		||||
  #region Données membres
 | 
			
		||||
  string _ChaineConnexion;
 | 
			
		||||
  #endregion
 | 
			
		||||
  #region Constructeurs
 | 
			
		||||
  public G_Base()
 | 
			
		||||
  { ChaineConnexion = ""; }
 | 
			
		||||
  public G_Base(string sChaineConnexion)
 | 
			
		||||
  { ChaineConnexion = sChaineConnexion; }
 | 
			
		||||
  #endregion
 | 
			
		||||
  #region Accesseur
 | 
			
		||||
  public string ChaineConnexion
 | 
			
		||||
  {
 | 
			
		||||
   get {	return _ChaineConnexion;	}
 | 
			
		||||
   set	{	_ChaineConnexion = value;	}
 | 
			
		||||
  }
 | 
			
		||||
  #endregion
 | 
			
		||||
 }
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										35
									
								
								Nouveau dossier/G_Personne.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										35
									
								
								Nouveau dossier/G_Personne.cs
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,35 @@
 | 
			
		||||
#region Ressources extérieures
 | 
			
		||||
using System;
 | 
			
		||||
using System.Collections.Generic;
 | 
			
		||||
using System.Text;
 | 
			
		||||
using Projet_BD_EXEMPLE.Classes;
 | 
			
		||||
using Projet_BD_EXEMPLE.Acces;
 | 
			
		||||
#endregion
 | 
			
		||||
 | 
			
		||||
namespace Projet_BD_EXEMPLE.Gestion
 | 
			
		||||
{
 | 
			
		||||
 /// <summary>
 | 
			
		||||
 /// Couche intermédiaire de gestion (Business Layer)
 | 
			
		||||
 /// </summary>
 | 
			
		||||
 public class G_Personne : G_Base
 | 
			
		||||
 {
 | 
			
		||||
  #region Constructeurs
 | 
			
		||||
  public G_Personne()
 | 
			
		||||
   : base()
 | 
			
		||||
  { }
 | 
			
		||||
  public G_Personne(string sChaineConnexion)
 | 
			
		||||
   : base(sChaineConnexion)
 | 
			
		||||
  { }
 | 
			
		||||
  #endregion
 | 
			
		||||
  public int Ajouter(string NOM, string PRE, DateTime? NAI)
 | 
			
		||||
  { return new A_Personne(ChaineConnexion).Ajouter(NOM, PRE, NAI); }
 | 
			
		||||
  public int Modifier(int ID, string NOM, string PRE, DateTime? NAI)
 | 
			
		||||
  { return new A_Personne(ChaineConnexion).Modifier(ID, NOM, PRE, NAI); }
 | 
			
		||||
  public List<C_Personne> Lire(string Index)
 | 
			
		||||
  { return new A_Personne(ChaineConnexion).Lire(Index); }
 | 
			
		||||
  public C_Personne Lire_ID(int ID)
 | 
			
		||||
  { return new A_Personne(ChaineConnexion).Lire_ID(ID); }
 | 
			
		||||
  public int Supprimer(int ID)
 | 
			
		||||
  { return new A_Personne(ChaineConnexion).Supprimer(ID); }
 | 
			
		||||
 }
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										55
									
								
								Nouveau dossier/P_Personne.sql
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										55
									
								
								Nouveau dossier/P_Personne.sql
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,55 @@
 | 
			
		||||
use [G:\USERS\ADRIEN\NEXTCLOUD\ISET\2IS\2IS\POO\BD_PERSO.MDF]
 | 
			
		||||
go
 | 
			
		||||
CREATE PROCEDURE AjouterPersonne
 | 
			
		||||
 @ID int OUTPUT,
 | 
			
		||||
 @NOM varchar(25),
 | 
			
		||||
 @PRE varchar(25),
 | 
			
		||||
 @NAI datetime
 | 
			
		||||
AS
 | 
			
		||||
 INSERT INTO Personne(NOM,PRE,NAI)
 | 
			
		||||
  VALUES(@NOM,@PRE,@NAI)
 | 
			
		||||
 SET @ID=@@IDENTITY
 | 
			
		||||
RETURN
 | 
			
		||||
GO
 | 
			
		||||
CREATE PROCEDURE ModifierPersonne
 | 
			
		||||
 @ID int,
 | 
			
		||||
 @NOM varchar(25),
 | 
			
		||||
 @PRE varchar(25),
 | 
			
		||||
 @NAI datetime
 | 
			
		||||
AS
 | 
			
		||||
 IF(@ID IS NULL OR @ID=0)
 | 
			
		||||
  RAISERROR('Identifiant requis !',16,1)
 | 
			
		||||
 ELSE  UPDATE Personne
 | 
			
		||||
        SET NOM=@NOM,PRE=@PRE,NAI=@NAI
 | 
			
		||||
        WHERE ID=@ID
 | 
			
		||||
RETURN
 | 
			
		||||
GO
 | 
			
		||||
CREATE PROCEDURE SelectionnerPersonne
 | 
			
		||||
 @Index VARCHAR(10)
 | 
			
		||||
AS
 | 
			
		||||
 IF(@Index='NOM') SELECT * FROM Personne ORDER BY NOM
 | 
			
		||||
 ELSE IF(@Index='PRE') SELECT * FROM Personne ORDER BY PRE
 | 
			
		||||
 ELSE IF(@Index='NAI') SELECT * FROM Personne ORDER BY NAI
 | 
			
		||||
 ELSE SELECT * FROM Personne ORDER BY ID
 | 
			
		||||
RETURN
 | 
			
		||||
GO
 | 
			
		||||
CREATE PROCEDURE SelectionnerPersonne_ID
 | 
			
		||||
 @ID int
 | 
			
		||||
AS
 | 
			
		||||
 IF(@ID IS NULL)
 | 
			
		||||
  RAISERROR('Identifiant requis !',16,1)
 | 
			
		||||
 ELSE
 | 
			
		||||
  SELECT ID,NOM,PRE,NAI
 | 
			
		||||
  FROM Personne
 | 
			
		||||
  WHERE @ID=ID
 | 
			
		||||
RETURN
 | 
			
		||||
GO
 | 
			
		||||
CREATE PROCEDURE SupprimerPersonne
 | 
			
		||||
 @ID int
 | 
			
		||||
AS
 | 
			
		||||
 IF(@ID IS NULL)
 | 
			
		||||
  RAISERROR('Identifiant requis !',16,1)
 | 
			
		||||
 ELSE
 | 
			
		||||
  DELETE FROM Personne WHERE @ID=ID
 | 
			
		||||
RETURN
 | 
			
		||||
GO
 | 
			
		||||
		Reference in New Issue
	
	Block a user