/// <summary>
        /// Get one sub family by name or id
        /// </summary>
        /// <param name="Name"> The name of the sub family to get </param>
        /// <param name="Id"> The id of the sub family to get </param>
        /// <returns> The sub family searched </returns>
        public SousFamilles GetSousFamille(string Name = "", int Id = -1)
        {
            SousFamilles  SousFamille = new SousFamilles();
            SQLiteCommand Sql;

            if (Name.CompareTo("") != 0)
            {
                Sql = new SQLiteCommand("SELECT * FROM SousFamilles WHERE Nom = @name", Conn);
                Sql.Parameters.AddWithValue("@name", Name);
            }
            else
            {
                Sql = new SQLiteCommand("SELECT * FROM SousFamilles WHERE RefSousFamille = @idSousFamille", Conn);
                Sql.Parameters.AddWithValue("@idSousFamille", Id);
            }

            SQLiteDataReader Reader = Sql.ExecuteReader();

            if (Reader.Read())
            {
                SousFamille.ConvertDataReaderToSousFamilles(Reader);
                return(SousFamille);
            }
            else
            {
                return(null);
            }
        }
        /// <summary>
        /// Applies changes on the similar object stored on the DB with the object in parameter
        /// </summary>
        /// <param name="Obj">Object with the changes</param>
        /// <returns>Returns true if done, false else</returns>
        public override int ChangeElement(object Obj)
        {
            int Count;

            SousFamilles SubFamily      = (SousFamilles)(Obj);
            SousFamilles SubFamilyFound = Manager.GetSousFamille(Id: SubFamily.Id);

            if (SubFamilyFound != null)
            {
                if (Manager.GetSousFamille(SubFamily.Nom) == null) // Check if the sub family already exist or not
                {
                    Count = Manager.UpdateSousFamilles(SubFamily);
                    if (Count != 1)
                    {
                        throw new Exception("Une erreur liée à la base de données à empêcher la modification de la sous famille " + SubFamily.Nom);
                    }
                }
                else
                {
                    throw new Exception("La sous famille " + SubFamily.Nom + " existe déjà dans la base");
                }
            }
            else
            {
                throw new Exception("La sous famille " + SubFamily.Nom + " n'existe pas dans la base");
            }
            return(Count);
        }
Exemple #3
0
        /// <summary>
        /// Check if the sub family contains a mistake spelling
        /// </summary>
        /// <param name="Name"> The name of the sub family </param>
        /// <returns> The sub family fixed or null if no sub family have been found </returns>
        protected SousFamilles CheckSpellingSousFamilles(string Name)
        {
            int          BestDistance = 255, TempDistance;
            SousFamilles SousFamille = null;

            Dictionary <int, SousFamilles> ListSousFamille = DbManager.GetAllSousFamilles(); // Retrieve all SousFamille of the database

            foreach (KeyValuePair <int, SousFamilles> Entry in ListSousFamille)
            {
                TempDistance = DistanceLevenshtein(Name, Entry.Value.Nom); // Compute the distance

                if (TempDistance < BestDistance)
                {
                    BestDistance = TempDistance;
                    SousFamille  = Entry.Value;
                }
            }

            if (BestDistance <= 2) // Here we decide the degree of tolerance
            {
                return(SousFamille);
            }
            else
            {
                return(null);
            }
        }
Exemple #4
0
        /// <summary>
        /// Insert new subFamily to the database
        /// </summary>
        protected void NewSousFamille()
        {
            SousFamilles SousFamille = new SousFamilles();

            SousFamille.IdFamille = Article.IdFamille;
            SousFamille.Nom       = Node.SelectSingleNode("sousFamille").InnerText;
            Article.IdSousFamille = DbManager.InsertSousFamille(SousFamille); // Insert return the last id of the sousFamille added.
            UpdateListView(TypeMessage.Succès, SubjectMessage.Ajouter_sous_famille, "La sous famille " + SousFamille.Nom + " a été créée");
        }
        /// <summary>
        /// Adds a new element in the DB
        /// </summary>
        /// <param name="Obj">Object to add in the DB.</param>
        public override void AddElement(object Obj)
        {
            SousFamilles SubFamily      = (SousFamilles)Obj;
            SousFamilles SubFamilyFound = Manager.GetSousFamille(SubFamily.Nom);

            if (SubFamilyFound == null)
            {
                Manager.InsertSousFamille(SubFamily);
            }
            else
            {
                throw new Exception("La sous famille " + SubFamily.Nom + " existe déja dans la base");
            }
        }
        /// <summary>
        /// Get all sub family
        /// </summary>
        /// <returns>A dictionnary of the sub family</returns>
        public Dictionary <int, SousFamilles> GetAllSousFamilles()
        {
            Dictionary <int, SousFamilles> ListSousFamille = new Dictionary <int, SousFamilles>();
            SQLiteCommand    Sql    = new SQLiteCommand("SELECT * FROM SousFamilles", Conn);
            SQLiteDataReader Reader = Sql.ExecuteReader();

            while (Reader.Read())
            {
                SousFamilles SousFamille = new SousFamilles();
                SousFamille.ConvertDataReaderToSousFamilles(Reader);
                ListSousFamille.Add(SousFamille.Id, SousFamille);
            }

            return(ListSousFamille);
        }
Exemple #7
0
        /// <summary>
        /// Update value of the article
        /// </summary>
        private void UpdateArticle()
        {
            Article.Description = Node.SelectSingleNode("description").InnerText; // Update the description

            Familles Famille = DbManager.GetFamille(Node.SelectSingleNode("famille").InnerText);

            if (Famille == null)
            {
                NewFamille();
            }
            else
            {
                Article.IdFamille = Famille.Id; // Set the new id of the of famille
            }
            SousFamilles SousFamille = DbManager.GetSousFamille(Node.SelectSingleNode("sousFamille").InnerText);

            if (SousFamille == null)
            {
                NewSousFamille();
            }
            else
            {
                if (DbManager.ExistSousFamilleInFamille(SousFamille.Id, Article.IdFamille))
                {
                    Article.IdSousFamille = SousFamille.Id; // Set the new id of the sub family
                }
                else
                {
                    // Generate error because a sousFamille don't belong to twice family. (this sub family has already a family)
                    UpdateListView(TypeMessage.Erreur, SubjectMessage.Modifier_famille,
                                   "L'article " + Article.Reference + ". Sa famille n'a pas été mis à jour car sa sous famille ne correspond pas avec la nouvelle famille");
                }
            }

            Marques Marque = DbManager.GetMarque(Node.SelectSingleNode("marque").InnerText);

            if (Marque == null)
            {
                NewMarque();
            }
            else
            {
                Article.IdMarque = Marque.Id;                                             // Set the new id of the brand
            }
            Article.PrixHT = Convert.ToDouble(Node.SelectSingleNode("prixHT").InnerText); // Update prixHT

            DbManager.UpdateArticle(Article);                                             // Update information to the database
        }
        /// <summary>
        /// Get all sub families belonging to a family
        /// </summary>
        /// <param name="IdFamily"> The id of a family </param>
        /// <returns> The list of sub family belonging to a family </returns>
        public Dictionary <int, SousFamilles> GetAllSubFamiliesFromFamily(int IdFamily)
        {
            Dictionary <int, SousFamilles> ListSubFamily = new Dictionary <int, SousFamilles>();
            SQLiteCommand Sql = new SQLiteCommand("SELECT * FROM SousFamilles WHERE RefFamille = @idFamily", Conn);

            Sql.Parameters.AddWithValue("@idFamily", IdFamily);
            SQLiteDataReader Reader = Sql.ExecuteReader();

            while (Reader.Read())
            {
                SousFamilles SubFamily = new SousFamilles();
                SubFamily.ConvertDataReaderToSousFamilles(Reader);
                ListSubFamily.Add(SubFamily.Id, SubFamily);
            }
            return(ListSubFamily);
        }
        /// <summary>
        /// Set the new family to the database
        /// </summary>
        /// <param name="Subfamily"> The family to update </param>
        /// <returns>The number of line modified </returns>
        public int UpdateSousFamilles(SousFamilles Subfamily)
        {
            SQLiteCommand Sql = new SQLiteCommand("UPDATE SousFamilles SET Nom = @name, RefFamille = @idFamily WHERE RefSousFamille = @idSubFamily", Conn);

            Sql.Parameters.AddWithValue("@name", Subfamily.Nom);
            Sql.Parameters.AddWithValue("@idFamily", Subfamily.IdFamille);
            Sql.Parameters.AddWithValue("@idSubFamily", Subfamily.Id);

            try
            {
                return(Sql.ExecuteNonQuery());
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }
Exemple #10
0
        /// <summary>
        /// If not exist, check if spelling mistake, if not, create new one.
        /// </summary>
        /// <returns> True if everything is OK, false if the family does not match to the subfamily </returns>
        private bool TreatSousFamille()
        {
            bool FoundMistake = false;

            SousFamilles SousFamille = DbManager.GetSousFamille(Node.SelectSingleNode("sousFamille").InnerText); // Check if the sousFamille already exist

            if (SousFamille == null)                                                                             // If the sousFamille does not exist
            {
                SousFamille = CheckSpellingSousFamilles(Node.SelectSingleNode("sousFamille").InnerText);
                if (SousFamille == null)
                {
                    NewSousFamille();
                }
                else
                {
                    UpdateListView(TypeMessage.Avertissement, SubjectMessage.Erreur_orthographe,
                                   "La sous famille de l'article " + Article.Reference + " est \""
                                   + Node.SelectSingleNode("sousFamille").InnerText + "\". Elle a été remplacé par \"" + SousFamille.Nom + "\"");

                    Article.IdSousFamille = SousFamille.Id;

                    // Generate error when the sousFamille don't belong to the good famille
                    if (!DbManager.ExistSousFamilleInFamille(Article.IdSousFamille, Article.IdFamille))
                    {
                        UpdateListView(TypeMessage.Erreur, SubjectMessage.Mauvaise_information,
                                       "Impossible d'ajouter l'article " + Article.Reference + " car sa famille ne correspond pas à la bonne sous famille");

                        FoundMistake = true;
                    }
                    Node.SelectSingleNode("sousFamille").InnerText = SousFamille.Nom; // Change the text of the XML to correct the spelling mistake
                }
            }
            else
            {
                Article.IdSousFamille = SousFamille.Id;
                // Generate error when the sousFamille don't belong to the good famille
                if (!DbManager.ExistSousFamilleInFamille(Article.IdSousFamille, Article.IdFamille))
                {
                    UpdateListView(TypeMessage.Erreur, SubjectMessage.Mauvaise_information,
                                   "Impossible d'ajouter l'article " + Article.Reference + " car sa famille ne correspond pas à la bonne sous famille");

                    FoundMistake = true;
                }
            }
            return(FoundMistake);
        }
        /// <summary>
        /// Insert a new sub family to the database
        /// </summary>
        /// <param name="SousFamille"> The new sub family to add </param>
        /// <returns> Id of the new sub family added </returns>
        public int InsertSousFamille(SousFamilles SousFamille)
        {
            SQLiteCommand Sql = new SQLiteCommand(
                "INSERT INTO SousFamilles (RefSousFamille, RefFamille, Nom) VALUES((SELECT ifnull((SELECT RefSousFamille FROM SousFamilles ORDER BY RefSousFamille DESC LIMIT 1) + 1, 1)), @refFamille, @nom);", Conn);

            Sql.Parameters.AddWithValue("@refFamille", SousFamille.IdFamille);
            Sql.Parameters.AddWithValue("@nom", SousFamille.Nom);

            try
            {
                Sql.ExecuteNonQuery();
                return(Convert.ToInt32(Conn.LastInsertRowId));
            }
            catch (Exception Ex)
            {
                throw new Exception(Ex.Message);
            }
        }