Example #1
0
        public static Appret Get(Int32 Identifiant)
        {
            Appret appret = new Appret();

            //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())
                {

                    appret.Identifiant = dataReader.GetInt32(0);
                    appret.Reference = dataReader.GetString(1);
                    appret.Min = dataReader.GetInt32(2);
                    appret.Norme = dataReader.GetInt32(3);
                    appret.Max = dataReader.GetInt32(4);
                }

                dataReader.Close();

            }
            catch (Exception)
            {
                appret = null;
            }
            finally
            {
                connection.Close();
            }
            return appret;
        }
Example #2
0
        public static Boolean Insert(Appret appret)
        {
            //Connection
            SqlConnection connection = DataBase.Connection();

            //Requete
            String requete = @"INSERT INTO Appret (" + champs + ") VALUES (@Reference,@Min,@Norme,@Max);";

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

            //Parametres
            commande.Parameters.AddWithValue("Reference", appret.Reference);
            commande.Parameters.AddWithValue("Min", appret.Min);
            commande.Parameters.AddWithValue("Norme", appret.Norme);
            commande.Parameters.AddWithValue("Max", appret.Max);

            //Execution
            try
            {
                connection.Open();
                commande.ExecuteNonQuery();
                return true;
            }
            catch (Exception)
            {
                return false;
            }
            finally
            {
                connection.Close();
            }
        }
Example #3
0
        public static Boolean Update(Appret appret)
        {
            //Connection
            SqlConnection connection = DataBase.Connection();

            //Requete
            String requete = @"UPDATE Appret
                               SET Reference=@Reference,Min=@Min,Norme=@Norme,Max=@Max
                               WHERE Identifiant=@Identifiant ;";

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

            //Parametres
            commande.Parameters.AddWithValue("Identifiant",appret.Identifiant);
            commande.Parameters.AddWithValue("Reference", appret.Reference);
            commande.Parameters.AddWithValue("Min", appret.Min);
            commande.Parameters.AddWithValue("Norme", appret.Norme);
            commande.Parameters.AddWithValue("Max", appret.Max);

            //Execution
            try
            {
                connection.Open();
                commande.ExecuteNonQuery();
                return true;
            }
            catch (Exception)
            {
                return false;
            }
            finally
            {
                connection.Close();
            }
        }
Example #4
0
        public static List<Appret> List()
        {
            List<Appret> listeAppret = new List<Appret>();

            //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())
                {
                    Appret appret = new Appret();
                    appret.Identifiant = dataReader.GetInt32(0);
                    appret.Reference = dataReader.GetString(1);
                    appret.Min = dataReader.GetInt32(2);
                    appret.Norme = dataReader.GetInt32(3);
                    appret.Max = dataReader.GetInt32(4);
                    listeAppret.Add(appret);
                }

                dataReader.Close();

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

            return listeAppret;
        }