示例#1
0
        private void ExecLocalToDistant(Model.Local.Article Article, Model.Prestashop.PsProduct Product, Model.Local.ArticleRepository ArticleRepository, Model.Prestashop.PsProductRepository ProductRepository, Boolean isProduct)
        {
            try
            {
                if (isProduct)
                {
                    Model.Local.CatalogRepository CatalogRepository = new Model.Local.CatalogRepository();
                    Model.Local.Catalog           Catalog           = CatalogRepository.ReadId(Article.Cat_Id);

                    if (Catalog.Pre_Id != null && new Model.Prestashop.PsCategoryRepository().ExistId((int)Catalog.Pre_Id))
                    {
                        Product.IDCategoryDefault = Convert.ToUInt32(Catalog.Pre_Id);

                        ProductRepository.Save();

                        this.AssignCatalogProduct(Article, Product, ArticleRepository);

                        // <JG> 17/12/2012
                        this.ExecShopProduct(Product);
                    }
                }
            }
            catch (Exception ex)
            {
                Core.Error.SendMailError(ex.ToString());
            }
        }
        public void MoveCatalog()
        {
            if (MessageBox.Show("Valider le déplacement de :\n\""
                                + TargetCatalog.Cat_Name
                                + "\"\n vers :\n\""
                                + ((SelectedCatalog == null) ? "Racine boutique" : SelectedCatalog.Cat_Name) + "\"", "Déplacement catalogue", MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.Yes)
            {
                CatalogRepository.WriteParent(TargetCatalog.Cat_Id, ((SelectedCatalog == null) ? 0 : SelectedCatalog.Cat_Id));

                CatalogRepository       = new Model.Local.CatalogRepository();
                TargetCatalog           = CatalogRepository.ReadId(TargetCatalog.Cat_Id);
                TargetCatalog.Cat_Level = ((SelectedCatalog == null) ? 2 : SelectedCatalog.Cat_Level + 1);
                TargetCatalog.Cat_Date  = DateTime.Now;

                // <JG> 07/10/2016 ajout recalcul des niveaux sur les enfants
                ChangeLevelChilds(TargetCatalog);

                CatalogRepository.Save();
            }
        }
        public void Exec(Int32 CatalogSend)
        {
            try
            {
                Model.Local.CatalogRepository CatalogRepository = new Model.Local.CatalogRepository();
                Model.Local.Catalog           Catalog           = CatalogRepository.ReadId(CatalogSend);
                // if the catalog have a parent
                Boolean isSync   = false;
                uint    IdParent = 0;
                if (Catalog.Cat_Parent != 0)
                {
                    if (CatalogRepository.ExistId(Catalog.Cat_Parent))
                    {
                        Model.Local.Catalog CatalogParent = CatalogRepository.ReadId(Catalog.Cat_Parent);
                        if (CatalogParent.Pre_Id != null && CatalogParent.Pre_Id != 0)
                        {
                            IdParent = (uint)CatalogParent.Pre_Id.Value;
                            isSync   = true;
                        }
                    }
                }
                // default IdParent is defined on shop in Prestashop
                else
                {
                    isSync   = true;
                    IdParent = Global.CurrentShop.IDCategory;
                }


                if (isSync == true)
                {
                    Boolean isCategory = false;
                    Model.Prestashop.PsCategory           Category           = new Model.Prestashop.PsCategory();
                    Model.Prestashop.PsCategoryRepository CategoryRepository = new Model.Prestashop.PsCategoryRepository();
                    // If the Catalog have a connection with Prestashop
                    if (Catalog.Pre_Id != null)
                    {
                        Catalog.Cat_Date = Catalog.Cat_Date.AddMilliseconds(-Catalog.Cat_Date.Millisecond);
                        if (CategoryRepository.ExistId(Catalog.Pre_Id.Value))
                        {
                            Category   = CategoryRepository.ReadId((UInt32)Catalog.Pre_Id.Value);
                            isCategory = true;

                            if (Category.DateUpd.Ticks > Catalog.Cat_Date.Ticks)
                            {
                                this.ExecDistantLocal(Category, Catalog, CatalogRepository);
                            }
                            else if (Category.DateUpd.Ticks < Catalog.Cat_Date.Ticks)
                            {
                                this.ExecLocalDistant(Catalog, Category, CatalogRepository, CategoryRepository, isCategory, IdParent);
                            }
                            else
                            {
                                ExecGroupsLocalDistant(Category);
                            }
                        }
                    }
                    // We need to sync Catalog with Category
                    else
                    {
                        this.ExecLocalDistant(Catalog, Category, CatalogRepository, CategoryRepository, isCategory, IdParent);
                    }
                }
            }
            catch (Exception ex)
            {
                Core.Error.SendMailError(ex.ToString());
            }
        }