Exemplo n.º 1
0
        /// <summary>
        /// Find an article with the reference
        /// </summary>
        /// <param name="Ref"></param>
        /// <returns></returns>
        public Article FindByRef(string Ref)
        {
            OpenConnection();
            var Result = ExecuteSelect("SELECT * FROM " + TableName + " WHERE " + RefName + " = '" + Ref + "'");

            Article            Arti;
            SousFamilleControl SFCont = new SousFamilleControl();
            MarqueControl      MCont  = new MarqueControl();

            if (Result.Read())
            {
                Arti = new Article(
                    Result.GetString(0),
                    Result.GetString(1),
                    Result.GetFloat(4),
                    Result.GetInt16(5),
                    MCont.FindByRef(Result.GetInt16(3)),
                    SFCont.FindByRef(Result.GetInt16(2)));
            }
            else
            {
                Arti = null;
            }
            CloseConnection();
            return(Arti);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Check Article param except Reference, return true if its ok
        /// </summary>
        /// <param name="Arti"></param>
        /// <returns></returns>
        public bool CheckParam(Article Arti)
        {
            if (Arti == null ||
                Arti.SousFamille == null ||
                Arti.PrixHT < 0 ||
                Arti.Quantite < 0 ||
                Arti.Marque == null)
            {
                return(false);
            }
            MarqueControl      MCont  = new MarqueControl();
            SousFamilleControl SFCont = new SousFamilleControl();

            if (MCont.FindByRef(Arti.Marque.RefMarque) == null ||
                SFCont.FindByRef(Arti.SousFamille.RefSousFamille) == null)
            {
                return(false);
            }
            return(true);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Get all existant article
        /// </summary>
        /// <returns></returns>
        public override HashSet <Article> GetAll()
        {
            OpenConnection();
            HashSet <Article> Liste = new HashSet <Article>();
            var Result = ExecuteSelect("SELECT * FROM " + TableName);
            SousFamilleControl SFCont = new SousFamilleControl();
            MarqueControl      MCont  = new MarqueControl();

            while (Result.Read())
            {
                Article Arti = new Article(
                    Result.GetString(0),
                    Result.GetString(1),
                    Result.GetFloat(4),
                    Result.GetInt16(5),
                    MCont.FindByRef(Result.GetInt16(3)),
                    SFCont.FindByRef(Result.GetInt16(2)));
                Liste.Add(Arti);
            }
            CloseConnection();
            return(Liste);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Test the back end structurs
        /// </summary>
        static void test()
        {
            /// TESTS BDD - EXAMPLE ///


            //         /// MARQUES
            Control.MarqueControl MCont = new Control.MarqueControl();
            //         HashSet<Model.Marque> List = MCont.GetAll();
            //         if(List != null)    // Display all Marques
            //         {
            //             foreach (Model.Marque Brand in List)
            //             {
            //                 // Display all differents brands
            //                 Console.WriteLine(Brand.Nom);
            //             }
            //         }
            //         // Display Marque name with id = 1
            //         //Console.WriteLine("find name with id 1 : " + MCont.FindByRef(1).Nom);
            //         // Create a new marque in the model
            //         Model.Marque m = new Model.Marque("Kingston");
            //         // Insert this new marque into the DB
            //         MCont.Insert(m);
            //         // Update the marque in the model with the new attributed id
            //         m = MCont.FindByRef(MCont.GetMaxRef());
            //         Console.WriteLine("Insert : " + m.Nom);
            //         // Change the name in the model
            //         m.Nom = "QueenStone";
            //         // Update the name in the DB
            //         bool u = MCont.Update(m);
            //         Console.WriteLine("Update : " + MCont.FindByRef(MCont.GetMaxRef()).Nom);
            //         // Delete the marque
            //         bool r = MCont.Delete(m);

            //         /// FAMILLE
            FamilleControl FCont = new FamilleControl();
            //         HashSet<Famille> ListF = FCont.GetAll();
            //         if (ListF != null)    // Display all
            //         {
            //             foreach (Famille Fami in ListF)
            //             {
            //                 // Display all differents
            //                 Console.WriteLine(Fami.Nom);
            //             }
            //         }
            //         FCont.Insert(new Famille("Grande"));
            //         FCont.Insert(new Famille("Moyenne"));
            //         FCont.Insert(new Famille("Petite"));
            //         Console.WriteLine("max : " + FCont.GetMaxRef());
            //         ListF = FCont.GetAll();
            //         if (ListF != null)    // Display all
            //         {
            //             foreach (Famille Fami in ListF)
            //             {
            //                 // Display all differents
            //                 Console.WriteLine(Fami.RefFamille + " " + Fami.Nom);
            //                 Fami.Nom = "Changed";
            //                 FCont.Update(Fami);
            //                 Famille Fam2 = FCont.FindByRef(Fami.RefFamille);
            //                 Console.WriteLine(Fam2.RefFamille + " " + Fam2.Nom);
            //                 FCont.Delete(Fami);
            //             }
            //         }
            //         Console.WriteLine("max : " + FCont.GetMaxRef());

            //         /// SS-FAMILLE
            SousFamilleControl SFCont = new SousFamilleControl();
            //         Console.WriteLine("\nMax sous-famille : " + SFCont.GetMaxRef());
            //         Famille f = new Famille("La Ch-tite Famille");
            //         FCont.Insert(f);
            //         f = FCont.FindByRef(FCont.GetMaxRef());
            //         SousFamille sf = new SousFamille("Sous race 1", f);
            //         SousFamille sfb = new SousFamille("Sous race 2", f);
            //         r = SFCont.Insert(sf);
            //         r = SFCont.Insert(sfb);
            //         Console.WriteLine("Inserts\nMax sous-famille : " + SFCont.GetMaxRef());
            //         HashSet<SousFamille> ListSF = SFCont.GetAll();
            //         if (ListSF != null)    // Display all
            //         {
            //             foreach (SousFamille SFam in ListSF)
            //             {
            //                 // Display all differents
            //                 Console.WriteLine(SFam.RefSousFamille + " " + SFam.Nom);
            //                 SFam.Nom = "Changed";
            //                 SFCont.Update(SFam);
            //                 SousFamille SFam2 = SFCont.FindByRef(SFam.RefSousFamille);
            //                 Console.WriteLine(SFam2.RefSousFamille + " " + SFam2.Nom);

            //		// Test of the GetByName on a SF
            //		SousFamille SFMock = SFCont.GetByName(SFam);
            //		Console.WriteLine("test Get FullObject \n SFMock name = " + SFMock.Nom);
            //		SFam.Nom = "Not In the Database";
            //		SFMock = SFCont.GetByName(SFam);
            //		if (SFMock == null) Console.WriteLine("Done");
            //		SFCont.Delete(SFam);
            //             }
            //         }


            //FCont.Delete(f);
            //         Console.WriteLine("Deletes\nMax sous-famille : " + SFCont.GetMaxRef());

            //         /// ARTICLES
            ArticleControl ACont = new ArticleControl();

            //         // Create famille first
            //         Famille Fam = new Famille("Pere");
            //         FCont.Insert(Fam);
            //         Fam.RefFamille = FCont.GetMaxRef();
            //         // Then create SousFamilles
            //         SousFamille sf1 = new SousFamille("Fils",Fam);
            //         SousFamille sf2 = new SousFamille("Fille",Fam);
            //         SFCont.Insert(sf1);
            //         sf1.RefSousFamille = SFCont.GetMaxRef();
            //         SFCont.Insert(sf2);
            //         sf2.RefSousFamille = SFCont.GetMaxRef();
            //         //Create Marque
            //         Marque Mark = new Marque("Vroom");
            //         MCont.Insert(Mark);
            //         Mark.RefMarque = MCont.GetCountRef();
            //         Marque Mark2 = new Marque("Nitro");
            //         MCont.Insert(Mark2);
            //         Mark2.RefMarque = MCont.GetMaxRef();
            //         Console.WriteLine("\nArticle :\n" + MCont.GetCountRef() + " Marques / " + SFCont.GetCountRef() + " ssFamilles / " + FCont.GetCountRef() + " Familles");
            //         //Articles
            //         Article a1 = new Article("007","Secret Pen",88,2,Mark,sf1);
            //         ACont.Insert(a1);
            //         Article ac = new Article("008", "Secret copieur", 71, 12, Mark2, sf2);
            //         ACont.Insert(ac);
            //         HashSet<Article> Alist = ACont.GetAll();
            //         if(Alist != null)
            //         {
            //             foreach(Article Art in Alist)
            //             {
            //                 Console.WriteLine(Art.RefArticle + " " + Art.Description + " " + Art.Marque.Nom + " " + Art.SousFamille.Nom);
            //                 Art.Description = "Secret changed ";
            //                 Art.Marque = Mark2;
            //                 Art.SousFamille = sf2;
            //                 ACont.Update(Art);
            //                 Article Updated = ACont.FindByRef(Art.RefArticle);
            //                 Console.WriteLine(Updated.RefArticle + " " + Updated.Description + " " + Updated.Marque.Nom + " " + Updated.SousFamille.Nom);
            //                 ACont.Delete(Updated);
            //             }
            //         }


            ////Delete

            //ACont.Insert(a1);

            //ACont.Insert(ac);
            //Console.WriteLine(MCont.GetCountRef() + " Marques / " + SFCont.GetCountRef() + " ssFamilles / " + FCont.GetCountRef() + " Familles / " + ACont.GetCountRef() + " Articles ");
            //MCont.Delete(Mark);
            //         MCont.Delete(Mark2);
            //Console.WriteLine(MCont.GetCountRef() + " Marques / " + SFCont.GetCountRef() + " ssFamilles / " + FCont.GetCountRef() + " Familles / " + ACont.GetCountRef() + " Articles ");
            //FCont.Delete(Fam);
            //

            ////Delete

            //ACont.Insert(a1);

            //ACont.Insert(ac);
            //Console.WriteLine(MCont.GetCountRef() + " Marques / " + SFCont.GetCountRef() + " ssFamilles / " + FCont.GetCountRef() + " Familles / " + ACont.GetCountRef() + " Articles ");
            //MCont.Delete(Mark);
            //         MCont.Delete(Mark2);
            //Console.WriteLine(MCont.GetCountRef() + " Marques / " + SFCont.GetCountRef() + " ssFamilles / " + FCont.GetCountRef() + " Familles / " + ACont.GetCountRef() + " Articles ");
            //FCont.Delete(Fam);
            //         Console.WriteLine(MCont.GetCountRef() + " Marques / " + SFCont.GetCountRef() + " ssFamilles / " + FCont.GetCountRef() + " Familles / " + ACont.GetCountRef() + " Articles ");

            /*
             * Console.WriteLine(MCont.GetCountRef() + " Marques / " + SFCont.GetCountRef() + " ssFamilles / " + FCont.GetCountRef() + " Familles / " + ACont.GetCountRef() + " Articles ");
             * FileControl.ImportFile("C:\\Users\\Foxinow\\Desktop\\net\\.Net-Project\\Bacchus\\Bacchus\\Data_to_integrate.csv");
             * Console.WriteLine(MCont.GetCountRef() + " Marques / " + SFCont.GetCountRef() + " ssFamilles / " + FCont.GetCountRef() + " Familles / " + ACont.GetCountRef() + " Articles ");
             * FileControl.ExportFile(Environment.GetFolderPath(Environment.SpecialFolder.Desktop) + "\\toto.csv");
             * ACont.FlushTable();
             * MCont.FlushTable();
             * FCont.FlushTable();
             * Console.WriteLine(MCont.GetCountRef() + " Marques / " + SFCont.GetCountRef() + " ssFamilles / " + FCont.GetCountRef() + " Familles / " + ACont.GetCountRef() + " Articles ");
             */
            try
            {
                FileCheck.CheckFile("E:\\Bureau\\toto.csv");
                Console.WriteLine("Lefichier est bon");
            }
            catch (ExceptionFile Xceptio)
            {
                Console.WriteLine(Xceptio.FileErrorMsg);
            }
        }
Exemplo n.º 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);
            }
        }