Example #1
0
        /// <summary>
        /// Renvoie la liste de tous les articles de la marque "Marque".
        /// </summary>
        /// <param name="Marque"></param>
        /// <returns></returns>
        public List <Article> GetArticlesWhereMarque(string Marque)
        {
            List <Article> ListeArticles = new List <Article>();

            DAOMarque daoMarque = new DAOMarque();
            int       RefMarque = daoMarque.GetRefMarque(Marque);

            string Cmd = "SELECT RefArticle FROM Articles WHERE RefMarque = " + RefMarque;

            using (SQLiteConnection Connection = new SQLiteConnection(DatabasePath))
            {
                Connection.Open();
                using (SQLiteCommand Command = new SQLiteCommand(Cmd, Connection))
                {
                    // On récupère la liste des RefArticle
                    using (SQLiteDataReader Reader = Command.ExecuteReader())
                    {
                        while (Reader.Read())
                        {
                            // Pour chaque RefArticle, on récupère l'article correspondant et on l'ajoute à la liste
                            Article NewArticle = GetArticle(Reader.GetString(0));
                            ListeArticles.Add(NewArticle);
                        }
                    }

                    return(ListeArticles);
                }
            }
        }
Example #2
0
        /// <summary>
        /// Met à jour un article déjà existant dans la base de données.
        /// </summary>
        /// <param name="ArticleUpdated">L'article à mettre à jour.</param>
        public int UpdateArticle(Article ArticleUpdated)
        {
            DAOMarque      daoMarque      = new DAOMarque();
            DAOFamille     daoFamille     = new DAOFamille();
            DAOSousFamille daoSousFamille = new DAOSousFamille();

            int RefMarque      = daoMarque.GetRefMarque(ArticleUpdated.Marque);
            int RefFamille     = daoFamille.GetRefFamille(ArticleUpdated.Famille);
            int RefSousFamille = daoSousFamille.GetRefSousFamille(RefFamille, ArticleUpdated.SousFamille);

            string Cmd = "UPDATE Articles " +
                         "SET Description = @Description, RefSousFamille = @RefSousFamille, RefMarque = @RefMarque, PrixHT = @PrixHT, Quantite = @Quantite " +
                         "WHERE RefArticle = @RefArticle;";

            using (SQLiteConnection Connection = new SQLiteConnection(DatabasePath))
            {
                Connection.Open();
                using (SQLiteCommand Command = new SQLiteCommand(Cmd, Connection))
                {
                    SQLiteParameter RefArticleParam = new SQLiteParameter("@RefArticle", DbType.String)
                    {
                        Value = ArticleUpdated.RefArticle
                    };
                    SQLiteParameter DescriptionParam = new SQLiteParameter("@Description", DbType.String)
                    {
                        Value = ArticleUpdated.Description
                    };
                    SQLiteParameter RefSousFamilleParam = new SQLiteParameter("@RefSousFamille", DbType.Int16)
                    {
                        Value = RefSousFamille
                    };
                    SQLiteParameter RefMarqueParam = new SQLiteParameter("@RefMarque", DbType.Int16)
                    {
                        Value = RefMarque
                    };
                    SQLiteParameter PrixHTParam = new SQLiteParameter("@PrixHT", DbType.Decimal)
                    {
                        Value = ArticleUpdated.PrixHT
                    };
                    SQLiteParameter QuantiteParam = new SQLiteParameter("@Quantite", DbType.Int16)
                    {
                        Value = ArticleUpdated.Quantite
                    };

                    Command.Parameters.Add(RefArticleParam);
                    Command.Parameters.Add(DescriptionParam);
                    Command.Parameters.Add(RefSousFamilleParam);
                    Command.Parameters.Add(RefMarqueParam);
                    Command.Parameters.Add(PrixHTParam);
                    Command.Parameters.Add(QuantiteParam);

                    return(Command.ExecuteNonQuery());
                }
            }
        }
Example #3
0
        /// <summary>
        /// Renvoie l'article correspondant à RefArticle, ou null si l'article n'a pas été trouvé.
        /// </summary>
        /// <param name="RefArticle">La référence de l'article à rechercher.</param>
        /// <returns>L'article rechercher.</returns>
        public Article GetArticle(string RefArticle)
        {
            string Cmd = "SELECT * FROM Articles WHERE RefArticle = '" + RefArticle + "'";

            using (SQLiteConnection Connection = new SQLiteConnection(DatabasePath))
            {
                Connection.Open();
                using (SQLiteCommand Command = new SQLiteCommand(Cmd, Connection))
                {
                    using (SQLiteDataReader Reader = Command.ExecuteReader())
                    {
                        if (Reader.Read())
                        {
                            DAOMarque      daoMarque      = new DAOMarque();
                            DAOFamille     daoFamille     = new DAOFamille();
                            DAOSousFamille daoSousFamille = new DAOSousFamille();

                            Article NewArticle = new Article
                            {
                                // Champs récupérables directement depuis la table SQL
                                RefArticle     = Reader.GetString(0),
                                Description    = Reader.GetString(1),
                                RefSousFamille = Reader.GetInt16(2),
                                RefMarque      = Reader.GetInt16(3),
                                PrixHT         = Reader.GetFloat(4),
                                Quantite       = Reader.GetInt16(5),

                                // Champs récupérables depuis d'autres tables
                                Marque      = daoMarque.GetNomMarque(Reader.GetInt16(3)),
                                RefFamille  = daoFamille.GetRefFamille(Reader.GetInt16(2)),
                                Famille     = daoFamille.GetNomFamille(daoFamille.GetRefFamille(Reader.GetInt16(2))),
                                SousFamille = daoSousFamille.GetNomSousFamille(Reader.GetInt16(2))
                            };

                            return(NewArticle);
                        }
                    }
                }
            }

            return(null);
        }
Example #4
0
        /// <summary>
        /// Ajoute un article à la base de données.
        /// </summary>
        /// <param name="article">L'article à ajouter</param>
        /// <returns></returns>
        public int AddArticle(Article article)
        {
            DAOMarque      daoMarque      = new DAOMarque();
            DAOFamille     daoFamille     = new DAOFamille();
            DAOSousFamille daoSousFamille = new DAOSousFamille();

            int RefMarque = daoMarque.GetRefMarque(article.Marque);

            if (RefMarque == -1)
            {
                RefMarque = daoMarque.AddMarque(article.Marque);
            }

            int RefFamille = daoFamille.GetRefFamille(article.Famille);

            if (RefFamille == -1)
            {
                RefFamille = daoFamille.AddFamille(article.Famille);
            }

            int RefSousFamille = daoSousFamille.GetRefSousFamille(RefFamille, article.SousFamille);

            if (RefSousFamille == -1)
            {
                RefSousFamille = daoSousFamille.AddSousFamille(RefFamille, article.SousFamille);
            }

            string Cmd = "INSERT INTO Articles (RefArticle, Description, RefSousFamille, RefMarque, PrixHT, Quantite) " +
                         "VALUES(@RefArticle, @Description, @RefSousFamille, @RefMarque, @PrixHT, @Quantite);";

            using (SQLiteConnection Connection = new SQLiteConnection(DatabasePath))
            {
                Connection.Open();
                using (SQLiteCommand Command = new SQLiteCommand(Cmd, Connection))
                {
                    SQLiteParameter RefArticleParam = new SQLiteParameter("@RefArticle", DbType.String)
                    {
                        Value = article.RefArticle
                    };
                    SQLiteParameter DescriptionParam = new SQLiteParameter("@Description", DbType.String)
                    {
                        Value = article.Description
                    };
                    SQLiteParameter RefSousFamilleParam = new SQLiteParameter("@RefSousFamille", DbType.Int16)
                    {
                        Value = RefSousFamille
                    };
                    SQLiteParameter RefMarqueParam = new SQLiteParameter("@RefMarque", DbType.Int16)
                    {
                        Value = RefMarque
                    };
                    SQLiteParameter PrixHTParam = new SQLiteParameter("@PrixHT", DbType.Decimal)
                    {
                        Value = article.PrixHT
                    };
                    SQLiteParameter QuantiteParam = new SQLiteParameter("@Quantite", DbType.Int16)
                    {
                        Value = article.Quantite
                    };

                    Command.Parameters.Add(RefArticleParam);
                    Command.Parameters.Add(DescriptionParam);
                    Command.Parameters.Add(RefSousFamilleParam);
                    Command.Parameters.Add(RefMarqueParam);
                    Command.Parameters.Add(PrixHTParam);
                    Command.Parameters.Add(QuantiteParam);

                    return(Command.ExecuteNonQuery());
                }
            }
        }