/// <summary>
        /// Get sousfamille details with his name
        /// </summary>
        /// <param name="obj"></param>
        /// <returns></returns>
        public override SousFamille GetByName(SousFamille obj)
        {
            OpenConnection();

            // We have to compare the FamilleRef and the Sous Famille Name to fin it
            var Result = ExecuteSelect("SELECT * FROM " + TableName +
                                       " WHERE " + ValueName + " = '" + obj.Nom +
                                       "' ");


            SousFamille    ChildFamily = null;
            FamilleControl FCont       = new FamilleControl();


            if (Result.Read())
            {
                ChildFamily = new SousFamille(
                    Result.GetString(2),
                    obj.Famille,
                    Result.GetInt16(0));
            }
            else
            {
                ChildFamily = null;
            }
            CloseConnection();
            return(ChildFamily);
        }
        /// <summary>
        /// Return all element in the table sousFamille
        /// </summary>
        /// <returns></returns>
        public override HashSet <SousFamille> GetAll()
        {
            OpenConnection();
            HashSet <SousFamille> Liste = new HashSet <SousFamille>();
            var            Result       = ExecuteSelect("SELECT * FROM " + TableName + " ORDER BY Nom");
            FamilleControl FCont        = new FamilleControl();

            while (Result.Read())
            {
                SousFamille ChildFamily = new SousFamille(Result.GetString(2), FCont.FindByRef(Result.GetInt32(1)), Result.GetInt16(0));
                Liste.Add(ChildFamily);
            }
            CloseConnection();
            return(Liste);
        }
        /// <summary>
        /// Check If the famille exist, true if exist
        /// </summary>
        /// <param name="Family"></param>
        /// <returns></returns>
        public bool CheckFamille(Famille Family)
        {
            if (Family == null)
            {
                return(false);
            }
            FamilleControl FCont = new FamilleControl();

            if (FCont.FindByRef(Family.RefFamille) == null)
            {
                return(false);
            }
            else
            {
                return(true);
            }
        }
        /// <summary>
        /// Return the sousfamille object from the database with his ref
        /// </summary>
        /// <param name="Ref"></param>
        /// <returns></returns>
        public override SousFamille FindByRef(int Ref)
        {
            OpenConnection();
            var            Result      = ExecuteSelect("SELECT Nom,RefFamille,RefSousFamille FROM " + TableName + " WHERE " + RefName + " = " + Ref);
            SousFamille    ChildFamily = null;
            FamilleControl FCont       = new FamilleControl();

            if (Result.Read())
            {
                ChildFamily = new SousFamille(Result.GetString(0), FCont.FindByRef(Result.GetInt32(1)), Result.GetInt16(2));
            }
            else
            {
                ChildFamily = null;
            }
            CloseConnection();
            return(ChildFamily);
        }
示例#5
0
        /// <summary>
        /// Import the file in the database
        /// </summary>
        /// <param name="Path"></param>
        /// <returns></returns>
        public static bool ImportFile(String Path, ProgressBar Progress)
        {
            try
            {
                using (var reader = new StreamReader(Path, Encoding.Default))
                {
                    Console.WriteLine("We are importing this file " + Path);

                    ArticleControl     ACont  = new ArticleControl();
                    FamilleControl     FCont  = new FamilleControl();
                    SousFamilleControl SFCont = new SousFamilleControl();
                    MarqueControl      MCont  = new MarqueControl();

                    Progress.Maximum = reader.ReadLine().Count() - 1;// remove the first line

                    while (!reader.EndOfStream)
                    {
                        Progress.PerformStep();
                        Model.Marque      Mark    = new Model.Marque();
                        Model.Article     Artic   = new Model.Article();
                        Model.SousFamille SousFam = new Model.SousFamille();
                        Model.Famille     Fam     = new Model.Famille();

                        /*
                         * Parser
                         *
                         */
                        var Line = reader.ReadLine();
                        //Console.WriteLine(line);
                        string[] values = Line.Split(';');

                        /*
                         * Create a "Marque" in the Database and get the Id
                         */

                        Mark.Nom = values[MARQUE];

                        // the "Marque" object is not in the Database
                        if (!MCont.Exist(Mark))
                        {
                            // Create one
                            MCont.Insert(Mark);
                        }

                        // get it
                        Mark = MCont.GetByName(Mark);


                        /*
                         * Create a "Famille" in the Database and get the ID
                         */

                        Fam.Nom = values[FAMILLE];

                        if (!FCont.Exist(Fam))
                        {
                            FCont.Insert(Fam);
                        }

                        Fam = FCont.GetByName(Fam);


                        /*
                         * Create a "SousFamille" in the Database and get the ID
                         */
                        SousFam.Nom     = values[SOUSFAMILLE];
                        SousFam.Famille = Fam;
                        if (!SFCont.Exist(SousFam))
                        {
                            SFCont.Insert(SousFam);
                        }
                        SousFam = SFCont.GetByName(SousFam);

                        /*
                         * Create the "Article" and stock it in the database
                         */
                        Artic.RefArticle = values[REF];
                        Artic.PrixHT     = float.Parse(values[PRIXHT].Replace('.', ','));
                        //Console.WriteLine(Artic.PrixHT);
                        Artic.Description = values[DESCRIPTION];
                        Artic.Marque      = Mark;
                        Artic.SousFamille = SousFam;

                        // the Article object need to be update in the Database
                        if (ACont.Exist(Artic))
                        {
                            //Console.WriteLine("Update");
                            ACont.Update(Artic);
                        }
                        else
                        {
                            //Console.WriteLine("Insert");
                            ACont.Insert(Artic);
                        }
                    }
                    Progress.Value = Progress.Maximum;
                }
                return(true);
            }
            catch (Exception e)
            {
                Console.WriteLine(e.StackTrace);
                return(false);
            }
        }