private void ExecDistantLocal(Model.Prestashop.PsCategory Category, Model.Local.Catalog Catalog, Model.Local.CatalogRepository CatalogRepository)
        {
            try
            {
                // Recovery Data From CatalogLang
                Model.Prestashop.PsCategoryLangRepository CategoryLangRepository = new Model.Prestashop.PsCategoryLangRepository();
                Model.Prestashop.PsCategoryLang           CategoryLang           = new Model.Prestashop.PsCategoryLang();
                if (CategoryLangRepository.ExistCategoryLang((Int32)Category.IDCategory, Core.Global.Lang, Global.CurrentShop.IDShop))
                {
                    CategoryLang                = CategoryLangRepository.ReadCategoryLang((Int32)Category.IDCategory, Core.Global.Lang, Global.CurrentShop.IDShop);
                    Catalog.Cat_Name            = CategoryLang.Name;
                    Catalog.Cat_Description     = CategoryLang.Description;
                    Catalog.Cat_MetaTitle       = CategoryLang.MetaTitle;
                    Catalog.Cat_MetaKeyword     = CategoryLang.MetaKeywords;
                    Catalog.Cat_MetaDescription = CategoryLang.MetaDescription;
                    Catalog.Cat_LinkRewrite     = CategoryLang.LinkRewrite;
                }

                bool find_parent = false;
                if (Category.IDParent != Core.Global.CurrentShop.IDCategory)
                {
                    if (!CatalogRepository.ExistPre_Id((int)Category.IDParent))
                    {
                        // todo import catalogue depuis prestashop
                        Core.ImportPrestashop.ImportCatalogue ImportCatalogue = new ImportPrestashop.ImportCatalogue();
                        ImportCatalogue.Exec((int)Category.IDParent);
                        find_parent = CatalogRepository.ExistPre_Id((int)Category.IDParent);
                    }
                    else
                    {
                        find_parent = true;
                    }
                    if (find_parent)
                    {
                        Catalog.Cat_Level = Category.LevelDepth;
                    }
                }
                else
                {
                    Catalog.Cat_Level = Category.LevelDepth;
                }

                //Catalog.Cat_Position = (Int32)Category.Position;
                Catalog.Cat_Active = Convert.ToBoolean(Category.Active);
                Catalog.Cat_Date   = (Category.DateUpd != null && Category.DateUpd > new DateTime(1753, 1, 2)) ? Category.DateUpd : DateTime.Now.Date;
                CatalogRepository.Save();

                int parent = (Category.IDParent != Core.Global.CurrentShop.IDCategory)
                    ? CatalogRepository.ReadPre_Id((int)Category.IDParent).Cat_Id
                    : 0;
                CatalogRepository.WriteParent(Catalog.Cat_Id, parent);
            }
            catch (Exception ex)
            {
                Core.Error.SendMailError(ex.ToString());
            }
        }
        //public void Exec(Int32 CategorySend)
        //{
        //    try
        //    {
        //        if (CategorySend != 1)
        //        {
        //            CatalogRepository CatalogRepository = new CatalogRepository();
        //            if (CatalogRepository.ExistPre_Id(CategorySend) == false)
        //            {
        //                PsCategoryLangRepository PsCategoryLangRepository = new PsCategoryLangRepository();
        //                if (PsCategoryLangRepository.ExistCategoryLang(CategorySend, Core.Global.Lang))
        //                {
        //                    PsCategoryRepository PsCategoryRepository = new PsCategoryRepository();
        //                    PsCategory PsCategory = PsCategoryRepository.ReadId(CategorySend);
        //                    PsCategoryLang PsCategoryLang = PsCategoryLangRepository.ReadCategoryLang(CategorySend, Core.Global.Lang);


        //                    F_CATALOGUERepository F_CATALOGUERepository = new F_CATALOGUERepository();
        //                    if (F_CATALOGUERepository.ExistIntituleNiveau(PsCategoryLang.Name, Convert.ToInt16(PsCategory.LevelDepth - 1)))
        //                    {
        //                        F_CATALOGUE F_CATALOGUE = F_CATALOGUERepository.ReadIntituleNiveau(PsCategoryLang.Name, Convert.ToInt16(PsCategory.LevelDepth - 1));
        //                        Catalog Catalog = new Catalog()
        //                        {
        //                            Cat_Name = PsCategoryLang.Name,
        //                            Cat_Description = PsCategoryLang.Description,
        //                            Cat_Level = PsCategory.LevelDepth,
        //                            Cat_MetaTitle = PsCategoryLang.MetaTitle,
        //                            Cat_MetaKeyword = PsCategoryLang.MetaKeywords,
        //                            Cat_Active = Convert.ToBoolean(PsCategory.Active),
        //                            Cat_MetaDescription = PsCategoryLang.MetaDescription,
        //                            Cat_LinkRewrite = PsCategoryLang.LinkRewrite,
        //                            Cat_Sync = true,
        //                            Cat_Date = PsCategory.DateUpd,
        //                            Sag_Id = F_CATALOGUE.cbMarq,
        //                            Pre_Id = Convert.ToInt32(PsCategory.IDCategory)
        //                        };

        //                        if (PsCategory.IDParent != 0 && PsCategory.IDParent != 1)
        //                        {
        //                            if (PsCategoryRepository.ExistId(Convert.ToInt32(PsCategory.IDParent)))
        //                            {
        //                                PsCategory PsCategoryParent = PsCategoryRepository.ReadId(Convert.ToInt32(PsCategory.IDParent));
        //                                if (CatalogRepository.ExistPre_Id(Convert.ToInt32(PsCategoryParent.IDCategory)))
        //                                {
        //                                    Catalog CatalogParent = CatalogRepository.ReadPre_Id(Convert.ToInt32(PsCategoryParent.IDCategory));
        //                                    Catalog.Cat_Parent = CatalogParent.Cat_Id;
        //                                }
        //                            }
        //                        }
        //                        CatalogRepository.Add(Catalog);
        //                    }
        //                }
        //            }
        //        }
        //    }
        //    catch (Exception ex)
        //    {
        //        Core.Error.SendMailError(ex.ToString());
        //    }
        //}


        //public void Exec(Int32 CategorySend)
        //{
        //    try
        //    {
        //        if (CategorySend != 1)
        //        {
        //            CatalogRepository catalogs = new CatalogRepository();

        //            //Vérifie si le catalogue PS est référence dans PC
        //            if (!catalogs.ExistPre_Id(CategorySend))
        //            {
        //                PsCategoryLangRepository langs = new PsCategoryLangRepository();

        //                //Vérifie que le catalogue existe bien dans la langue définit dans PC
        //                if (langs.ExistCategoryLang(CategorySend, Global.Lang,Global.CurrentShop.IDShop))
        //                {
        //                    PsCategoryRepository categories = new PsCategoryRepository();

        //                    //Récupération du catalogue dans PS
        //                    PsCategory category = categories.ReadId(CategorySend);
        //                    PsCategoryLang lang = langs.ReadCategoryLang(CategorySend, Global.Lang, Global.CurrentShop.IDShop);

        //                    //Récupération de tous les catalogues S suceptible de correspondre au catalogue PS
        //                    List<F_CATALOGUE> correspondances = new List<F_CATALOGUE>(
        //                        new F_CATALOGUERepository().ReadIntituleNiveau(lang.Name, Convert.ToInt16(category.LevelDepth - 1)));

        //                    if (correspondances.Count > 0)
        //                    {
        //                        PsCategory parentPrestashop = null;

        //                        //Récupération du parent dans PS
        //                        //Le catalogue 1 correspond à au noeud racine "Accueil" dans PS (il n'est ni utilisable, ni supprimable, ni exportable)
        //                        if (category.IDParent != 0 && category.IDParent != 1)
        //                            parentPrestashop = categories.ReadId(Convert.ToInt32(category.IDParent));

        //                        Catalog nouveauCatalogue = null;

        //                        if (correspondances.Count == 1)
        //                            nouveauCatalogue = GetCatalogue(category, lang, correspondances[0].cbMarq);
        //                        else if (correspondances.Count > 1)
        //                            foreach (var correspondanceSage in correspondances)
        //                                if (correspondanceSage.CL_NoParent.HasValue)
        //                                {
        //                                    //Récupération de la référence au parent de la correspondance en cours dans PC
        //                                    Catalog parentCorrespondance = catalogs.ReadSag_Id(correspondanceSage.CL_NoParent.Value);

        //                                    //Comparaison de l'ID de la réf PS du parent de la correspondance avec l'id du parent PS.
        //                                    if (parentCorrespondance != null)
        //                                        if (parentCorrespondance.Pre_Id == parentPrestashop.IDCategory)
        //                                        {
        //                                            nouveauCatalogue = GetCatalogue(category, lang, correspondanceSage.cbMarq);
        //                                            break;
        //                                        }
        //                                }

        //                        if (nouveauCatalogue != null && parentPrestashop != null)
        //                        {
        //                            //Si l'identifiant PS du parent existe dans PC
        //                            if (catalogs.ExistPre_Id(Convert.ToInt32(parentPrestashop.IDCategory)))
        //                                nouveauCatalogue.Cat_Parent = catalogs.ReadPre_Id(Convert.ToInt32(parentPrestashop.IDCategory)).Sag_Id;
        //                        }

        //                        catalogs.Add(nouveauCatalogue);
        //                    }
        //                }
        //            }
        //        }
        //    }
        //    catch (Exception ex)
        //    {
        //        Core.Error.SendMailError(ex.ToString());
        //    }
        //}


        public void Exec(Int32 CategorySend)
        {
            try
            {
                if (CategorySend != Core.Global.CurrentShop.IDCategory)
                {
                    Model.Local.CatalogRepository CatalogRepository = new Model.Local.CatalogRepository();

                    //Vérifie si le catalogue PS est référence dans PC
                    if (!CatalogRepository.ExistPre_Id(CategorySend))
                    {
                        Model.Prestashop.PsCategoryLangRepository PsCategoryLangRepository = new Model.Prestashop.PsCategoryLangRepository();

                        //Vérifie que le catalogue existe bien dans la langue définit dans PC
                        if (PsCategoryLangRepository.ExistCategoryLang(CategorySend, Global.Lang, Core.Global.CurrentShop.IDShop))
                        {
                            Model.Prestashop.PsCategoryRepository PsCategoryRepository = new Model.Prestashop.PsCategoryRepository();

                            //Récupération du catalogue dans PS
                            Model.Prestashop.PsCategory     PsCategory     = PsCategoryRepository.ReadId((UInt32)CategorySend);
                            Model.Prestashop.PsCategoryLang PsCategoryLang = PsCategoryLangRepository.ReadCategoryLang(CategorySend, Global.Lang, Core.Global.CurrentShop.IDShop);

                            Model.Prestashop.PsCategory parentPrestashop = null;

                            //Récupération du parent dans PS
                            //Le catalogue 1 correspond à au noeud racine "Accueil" dans PS (il n'est ni utilisable, ni supprimable, ni exportable)
                            if (PsCategory.IDParent != 0 && PsCategory.IDParent != 1 && PsCategory.IDParent != Core.Global.CurrentShop.IDShop)
                            {
                                parentPrestashop = PsCategoryRepository.ReadId(PsCategory.IDParent);
                            }

                            Model.Local.Catalog nouveauCatalogue = GetCatalogue(PsCategory, PsCategoryLang, 0);

                            if (nouveauCatalogue != null && parentPrestashop != null)
                            {
                                //Si l'identifiant PS du parent existe dans PC
                                if (CatalogRepository.ExistPre_Id(Convert.ToInt32(parentPrestashop.IDCategory)))
                                {
                                    nouveauCatalogue.Cat_Parent = CatalogRepository.ReadPre_Id(Convert.ToInt32(parentPrestashop.IDCategory)).Cat_Id;
                                }
                            }

                            CatalogRepository.Add(nouveauCatalogue);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Core.Error.SendMailError(ex.ToString());
            }
        }
        private Int32 ReadCatalog(uint?IdPsCategory)
        {
            Int32 Catalog = 0;

            try
            {
                Model.Local.CatalogRepository CatalogRepository = new Model.Local.CatalogRepository();
                if (IdPsCategory != null && CatalogRepository.ExistPre_Id((int)IdPsCategory))
                {
                    Catalog = CatalogRepository.ReadPre_Id((int)IdPsCategory).Cat_Id;
                }
            }
            catch (Exception ex)
            {
                Core.Error.SendMailError(ex.ToString());
            }
            return(Catalog);
        }