public static Echantillon Get(Int32 Identifiant)
        {
            Echantillon echantillon = new Echantillon();

            //Connection
            SqlConnection connection = DataBase.Connection();

            //Requete
            String requete = select+" WHERE Identifiant = @Identifiant;";

            //Commande
            SqlCommand commande = new SqlCommand(requete, connection);

            //Parametres
            commande.Parameters.AddWithValue("Identifiant", Identifiant);

            //Execution
            try
            {
                connection.Open();

                SqlDataReader dataReader = commande.ExecuteReader();

                while (dataReader.Read())
                {
            echantillon.Identifiant  = dataReader.GetInt32(0);
            echantillon.NumLot       = dataReader.GetString(1);
            echantillon.DatePeinture = dataReader.GetDateTime(2);
            echantillon.ISconforme   = dataReader.GetInt16(3);
            echantillon.ID_Produit   = dataReader.GetInt32(4);
                }

                dataReader.Close();

            }
            catch (Exception)
            {
                echantillon = null;
            }
            finally
            {
                connection.Close();
            }
            return echantillon;
        }
 private void BaddE1_Click(object sender, EventArgs e)
 {
     if ( CBteinte.SelectedItem != null
       && TBnumLotE1.Text != null)
     {
         Echantillon E= new Echantillon();
         E.ID_Produit = Int32.Parse(LBproduit.SelectedValue.ToString());
         E.ISconforme = -2;
         E.NumLot = TBnumLotE1.Text;
         E.DatePeinture = DTPpeintureE1.Value;
         EchantillonDB.Insert(E);
         RefreshE1();
     }
 }
        public static Boolean Insert(Echantillon echantillon)
        {
            //Connection
            SqlConnection connection = DataBase.Connection();

            //Requete
            String requete = @"INSERT INTO Echantillon (" + champs + ") VALUES (@NumLot,@DatePeinture,@ISconforme,@ID_Produit);";

            //Commande
            SqlCommand commande = new SqlCommand(requete, connection);

            //Parametres
            commande.Parameters.AddWithValue("NumLot", echantillon.NumLot);
            commande.Parameters.AddWithValue("DatePeinture", echantillon.DatePeinture);
            commande.Parameters.AddWithValue("ISconforme", echantillon.ISconforme);
            commande.Parameters.AddWithValue("ID_Produit", echantillon.ID_Produit);
            //Execution
            try
            {
                connection.Open();
                commande.ExecuteNonQuery();
                return true;
            }
            catch (Exception)
            {
                return false;
            }
            finally
            {
                connection.Close();
            }
        }
        public static Boolean Update(Echantillon echantillon)
        {
            //Connection
            SqlConnection connection = DataBase.Connection();

            //Requete
            String requete = @"UPDATE Echantillon
                               SET NumLot=@NumLot,DatePeinture=@DatePeinture,ISconforme=@ISconforme,ID_Produit=@ID_Produit
                               WHERE Identifiant=@Identifiant ;";

            //Commande
            SqlCommand commande = new SqlCommand(requete, connection);

            //Parametres
            commande.Parameters.AddWithValue("Identifiant",echantillon.Identifiant);
            commande.Parameters.AddWithValue("NumLot", echantillon.NumLot);
            commande.Parameters.AddWithValue("DatePeinture", echantillon.DatePeinture);
            commande.Parameters.AddWithValue("ISconforme", echantillon.ISconforme);
            commande.Parameters.AddWithValue("ID_Produit", echantillon.ID_Produit);

            //Execution
            connection.Open();
            commande.ExecuteNonQuery();
            connection.Close();

            return true;
        }
        public static List<Echantillon> List(Int16 Conforme)
        {
            List<Echantillon> listeEchantillon = new List<Echantillon>();

            //Connection
            SqlConnection connection = DataBase.Connection();

            //Requete
            String requete = select+" WHERE ISconforme =@Conforme;";

            //Commande
            SqlCommand commande = new SqlCommand(requete, connection);

            //Parametres
            commande.Parameters.AddWithValue("Conforme", Conforme);

            //Execution
            connection.Open();

            SqlDataReader dataReader = commande.ExecuteReader();

            while (dataReader.Read())
            {
               Echantillon echantillon = new Echantillon();
               echantillon.Identifiant = dataReader.GetInt32(0);
               echantillon.NumLot = dataReader.GetString(1);
               echantillon.DatePeinture = dataReader.GetDateTime(2);
               echantillon.ISconforme = dataReader.GetInt16(3);
               echantillon.ID_Produit = dataReader.GetInt32(4);
               listeEchantillon.Add(echantillon);
            }

            dataReader.Close();
            connection.Close();

            return listeEchantillon;
        }
        public static List<Echantillon> List()
        {
            List<Echantillon> listeEchantillon = new List<Echantillon>();

            //Connection
            SqlConnection connection = DataBase.Connection();

            //Requete
            String requete = select + ";";

            //Commande
            SqlCommand commande = new SqlCommand(requete, connection);

            //Parametres

            //Execution
            try
            {
                connection.Open();

                SqlDataReader dataReader = commande.ExecuteReader();

                while (dataReader.Read())
                {
                Echantillon echantillon = new Echantillon();
                echantillon.Identifiant = dataReader.GetInt32(0);
                echantillon.NumLot = dataReader.GetString(1);
                echantillon.DatePeinture = dataReader.GetDateTime(2);
                echantillon.ISconforme = dataReader.GetInt16(3);
                echantillon.ID_Produit = dataReader.GetInt32(4);
                listeEchantillon.Add(echantillon);
                }

                dataReader.Close();

            }
            catch (Exception)
            {
                listeEchantillon = null;
            }
            finally
            {
                connection.Close();
            }
            return listeEchantillon;
        }