示例#1
0
 public void Exec(Int32 ArticleSend)
 {
     try
     {
         Model.Local.ArticleRepository ArticleRepository = new Model.Local.ArticleRepository();
         Model.Local.Article           Article           = ArticleRepository.ReadArticle(ArticleSend);
         // If the catalog is sync with Prestashop
         if (Article.Catalog.Pre_Id != null || Article.Catalog.Pre_Id != 0)
         {
             Model.Prestashop.PsProductRepository ProductRepository = new Model.Prestashop.PsProductRepository();
             Model.Prestashop.PsProduct           Product           = new Model.Prestashop.PsProduct();
             // If the Article have a connection with Prestashop
             if (Article.Pre_Id != null)
             {
                 if (ProductRepository.ExistId(Convert.ToUInt32(Article.Pre_Id.Value)))
                 {
                     this.ExecLocalToDistant(Article);
                 }
             }
         }
     }
     catch (Exception ex)
     {
         Core.Error.SendMailError(ex.ToString());
     }
 }
示例#2
0
        public void Exec(Int32 ArticleSend)
        {
            try
            {
                Model.Local.ArticleRepository        ArticleRepository = new Model.Local.ArticleRepository();
                Model.Local.Article                  Article           = ArticleRepository.ReadArticle(ArticleSend);
                Model.Prestashop.PsProductRepository ProductRepository = new Model.Prestashop.PsProductRepository();
                Model.Prestashop.PsProduct           Product           = new Model.Prestashop.PsProduct();
                // If the Article have a connection with Prestashop
                if (Article.Pre_Id != null)
                {
                    //Article.Art_Date = Article.Art_Date.AddMilliseconds(-Article.Art_Date.Millisecond);
                    if (ProductRepository.ExistId(Convert.ToUInt32(Article.Pre_Id.Value)))
                    {
                        Product = ProductRepository.ReadId(Convert.ToUInt32(Article.Pre_Id.Value));

                        Model.Sage.F_ARTICLERepository F_ARTICLERepository = new Model.Sage.F_ARTICLERepository();
                        if (F_ARTICLERepository.ExistArticle(Article.Sag_Id))
                        {
                            SynchronisationArticle.ExecFeature(Article);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Core.Error.SendMailError(ex.ToString());
            }
        }
示例#3
0
        public void Exec(Int32 ArticleSend)
        {
            try
            {
                Model.Local.ArticleRepository ArticleRepository = new Model.Local.ArticleRepository();
                Model.Local.Article           Article           = ArticleRepository.ReadArticle(ArticleSend);

                // If the catalog is sync with Prestashop
                //if (Article.Catalog.Pre_Id != null || Article.Catalog.Pre_Id != 0)
                {
                    Model.Prestashop.PsProductRepository ProductRepository = new Model.Prestashop.PsProductRepository();
                    Boolean isProduct = false;
                    // If the Article have a connection with Prestashop
                    if (Article.Pre_Id != null &&
                        ProductRepository.ExistId(Convert.ToUInt32(Article.Pre_Id.Value)))
                    {
                        Model.Prestashop.PsProduct Product = ProductRepository.ReadId(Convert.ToUInt32(Article.Pre_Id.Value));
                        isProduct = true;
                        if (Product.DateUpd.Ticks > Article.Art_Date.Ticks)
                        {
                            this.ExecDistantToLocal(Product, Article, ArticleRepository);
                        }
                        else if (Product.DateUpd.Ticks < Article.Art_Date.Ticks)
                        {
                            this.ExecLocalToDistant(Article, Product, ArticleRepository, ProductRepository, isProduct);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Core.Error.SendMailError(ex.ToString());
            }
        }
        private void ReadRedirection(Model.Local.Article Article)
        {
            try
            {
                Model.Local.ArticleRepository ArticleRepository = new Model.Local.ArticleRepository();
                Article = ArticleRepository.ReadArticle(Article.Art_Id);
                Model.Prestashop.DataClassesPrestashop      DBPrestashop = new Model.Prestashop.DataClassesPrestashop(new MySqlConnection(Properties.Settings.Default.PRESTASHOPConnectionString));
                List <Model.Prestashop.Product_Redirection> list         = DBPrestashop.ExecuteQuery <Model.Prestashop.Product_Redirection>
                                                                               ("select redirect_type, " +
                                        #if (PRESTASHOP_VERSION_172)
                                                                               "id_type_redirected " +
                                        #else
                                                                               "id_product_redirected " +
                                        #endif
                                                                               " from ps_product_shop where id_product = " + Article.Pre_Id + " and id_shop = " + Core.Global.CurrentShop.IDShop + " ").ToList();

                if (list != null && list.Count == 1)
                {
                    Model.Prestashop.Product_Redirection values = list.FirstOrDefault();
                    Article.Art_RedirectType = values.redirect_type;
                                        #if (PRESTASHOP_VERSION_172)
                    Article.Art_RedirectProduct = (ArticleRepository.ExistPre_Id((int)values.id_type_redirected)) ? ArticleRepository.ReadPre_Id((int)values.id_type_redirected).Art_Id : 0;
                                        #else
                    Article.Art_RedirectProduct = (ArticleRepository.ExistPre_Id((int)values.id_product_redirected)) ? ArticleRepository.ReadPre_Id((int)values.id_product_redirected).Art_Id : 0;
                                        #endif
                    ArticleRepository.Save();
                }
            }
            catch (Exception ex)
            {
                Core.Error.SendMailError(ex.ToString());
            }
        }
        public void Exec(Int32 ArticleSend)
        {
            try
            {
                Model.Local.ArticleRepository ArticleRepository = new Model.Local.ArticleRepository();
                Model.Local.Article           Article           = ArticleRepository.ReadArticle(ArticleSend);

                Model.Sage.F_ARTICLERepository F_ARTICLERepository = new Model.Sage.F_ARTICLERepository();
                Model.Sage.F_ARTICLE           F_ARTICLE           = new Model.Sage.F_ARTICLE();
                F_ARTICLE = F_ARTICLERepository.ReadArticle(Article.Sag_Id);

                Core.ImportSage.ImportArticle ImportArticle = new ImportSage.ImportArticle();
                ImportArticle.ImportCatalogueInfoLibre(F_ARTICLE, Article);

                //Model.Local.CatalogRepository CatalogRepository = new Model.Local.CatalogRepository();

                //Model.Local.InformationLibreArticleRepository InformationLibreArticleRepository = new Model.Local.InformationLibreArticleRepository();
                //Model.Local.InformationLibreArticle InformationLibreArticleCatalogueParent = new Model.Local.InformationLibreArticle();

                //Model.Local.Catalog Parent;

                //foreach (Model.Local.InformationLibreArticle InformationLibreArticle in InformationLibreArticleRepository.List())
                //{
                //    CatalogRepository = new Model.Local.CatalogRepository();

                //    if (InformationLibreArticle.Inf_Catalogue == 2)
                //    {
                //        if (CatalogRepository.ExistParent(InformationLibreArticle.Inf_Parent, InformationLibreArticle.Inf_Catalogue))
                //        {
                //            CreateCatalogueInfoLibre(InformationLibreArticle, F_ARTICLE, Article, InformationLibreArticle.Inf_Catalogue + 1, CatalogRepository.ReadParent(InformationLibreArticle.Inf_Parent, InformationLibreArticle.Inf_Catalogue).Cat_Id);
                //        }
                //    }
                //    else
                //    {
                //        if (InformationLibreArticleRepository.ExistInfoLibreLevel(InformationLibreArticle.Inf_Parent, 2))
                //        {
                //            InformationLibreArticleCatalogueParent = InformationLibreArticleRepository.ReadInfoLibre(InformationLibreArticle.Inf_Parent, (int)InformationLibreArticle.Inf_Catalogue - 1);
                //            if (CatalogRepository.ExistName(F_ARTICLERepository.ReadArticleInformationLibreText(InformationLibreArticleCatalogueParent.Sag_InfoLibreArticle, F_ARTICLE.AR_Ref)))
                //            {
                //                Parent = CatalogRepository.ReadParent(F_ARTICLERepository.ReadArticleInformationLibreText(InformationLibreArticleCatalogueParent.Sag_InfoLibreArticle, F_ARTICLE.AR_Ref), 2);

                //                if (Parent != null)
                //                {
                //                    CreateCatalogueInfoLibre(InformationLibreArticle, F_ARTICLE, Article, 3, Parent.Cat_Id);
                //                }
                //            }
                //        }
                //    }
                //}
            }
            catch (Exception ex)
            {
                Core.Error.SendMailError(ex.ToString());
            }
        }
        public Boolean Exec(String PathDoc, Int32 ArticleSend, String Name, String Description, int?cbMarqSageMedia)
        {
            Boolean result            = false;
            Int32   IdArticleDocument = 0;

            try
            {
                Model.Local.AttachmentRepository AttachmentRepository = new Model.Local.AttachmentRepository();
                Model.Local.Attachment           Attachment           = new Model.Local.Attachment();

                Model.Local.ArticleRepository ArticleRepository = new Model.Local.ArticleRepository();
                Model.Local.Article           Article           = ArticleRepository.ReadArticle(ArticleSend);

                Attachment.Att_File = Core.Global.GetRandomHexNumber(40).ToLower();

                String[] ArrayFileName = PathDoc.Split('\\');
                Attachment.Att_FileName = ArrayFileName[ArrayFileName.Length - 1];
                if (AttachmentRepository.ExistFileArticle(Attachment.Att_FileName, ArticleSend) == false)
                {
                    string name = (!string.IsNullOrWhiteSpace(Name)) ? Name : Attachment.Att_FileName;
                    Attachment.Att_Name = (name.Length > 32) ? name.Substring(0, 32) : name;
                    string description = (!string.IsNullOrWhiteSpace(Description)) ? Description : name;
                    Attachment.Att_Description = description;

                    Attachment.Att_Mime = Attachment.GetMimeType(Attachment.Att_FileName);

                    Attachment.Art_Id = Article.Art_Id;
                    Attachment.Sag_Id = cbMarqSageMedia;
                    AttachmentRepository.Add(Attachment);
                    IdArticleDocument = Attachment.Att_Id;

                    this.CopyFile(Attachment, AttachmentRepository, Global.GetConfig().Folders.RootAttachment, PathDoc);

                    result = true;
                }
            }
            catch (Exception ex)
            {
                Core.Error.SendMailError(ex.ToString());
                if (ex.ToString().Contains("System.UnauthorizedAccessException") && IdArticleDocument != 0)
                {
                    Model.Local.AttachmentRepository AttachmentRepository = new Model.Local.AttachmentRepository();
                    AttachmentRepository.Delete(AttachmentRepository.ReadAttachment(IdArticleDocument));
                }
            }
            return(result);
        }
示例#7
0
        public void Exec(Int32 ArticleSend)
        {
            try
            {
                Model.Local.ArticleRepository ArticleRepository = new Model.Local.ArticleRepository();
                if (ArticleRepository.ExistArticle(ArticleSend))
                {
                    Model.Local.Article            Article             = ArticleRepository.ReadArticle(ArticleSend);
                    Model.Sage.F_ARTICLERepository F_ARTICLERepository = new Model.Sage.F_ARTICLERepository();

                    string AR_Ref = Article.Art_Ref;

                    // ajout gestion lecture des informations pour une composition
                    if (!F_ARTICLERepository.ExistReference(Article.Art_Ref) &&
                        Article.TypeArticle == Model.Local.Article.enum_TypeArticle.ArticleComposition &&
                        Article.CompositionArticle != null && Article.CompositionArticle.Count > 0)
                    {
                        int sag_id = (from Table in Article.CompositionArticle
                                      orderby Table.ComArt_Default descending
                                      select Table.ComArt_F_ARTICLE_SagId).FirstOrDefault();
                        Model.Sage.F_ARTICLE_Light light = F_ARTICLERepository.ReadLight(sag_id);
                        if (light != null && !string.IsNullOrWhiteSpace(light.AR_Ref))
                        {
                            AR_Ref = light.AR_Ref;
                        }
                    }

                    if (F_ARTICLERepository.ExistReference(AR_Ref))
                    {
                        if (ImportValues(Article, AR_Ref))
                        {
                            if (Core.Temp.UpdateDateActive)
                            {
                                Article.Art_Date = DateTime.Now;
                            }

                            ArticleRepository.Save();
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Core.Error.SendMailError(ex.ToString());
            }
        }
示例#8
0
        public void Exec(Int32 ArticleSend, out List <string> log_chrono, out uint pre_id)
        {
            log_chrono = new List <string>();
            pre_id     = 0;
            try
            {
                Model.Local.ArticleRepository ArticleRepository = new Model.Local.ArticleRepository();
                Model.Local.Article           Article           = ArticleRepository.ReadArticle(ArticleSend);

                DateTime start = DateTime.UtcNow;
                if (Core.Global.GetConfig().ChronoSynchroStockPriceActif)
                {
                    log_chrono.Add("----" + Article.Art_Ref + "----" + start.ToString("HH:mm:ss.fff", System.Globalization.CultureInfo.InvariantCulture));
                }

                Model.Prestashop.PsProductRepository ProductRepository = new Model.Prestashop.PsProductRepository();
                Model.Prestashop.PsProduct           Product           = new Model.Prestashop.PsProduct();
                // If the Article have a connection with Prestashop
                if (Article.Pre_Id != null)
                {
                    //Article.Art_Date = Article.Art_Date.AddMilliseconds(-Article.Art_Date.Millisecond);
                    if (ProductRepository.ExistId(Convert.ToUInt32(Article.Pre_Id.Value)))
                    {
                        Product = ProductRepository.ReadId(Convert.ToUInt32(Article.Pre_Id.Value));
                        List <string> log;
                        this.ExecLocalToDistant(Article, Product, ProductRepository, out log);
                        if (log != null && log.Count > 0)
                        {
                            log_chrono.AddRange(log);
                        }
                        pre_id = Product.IDProduct;
                    }
                }
                if (Core.Global.GetConfig().ChronoSynchroStockPriceActif)
                {
                    log_chrono.Add("----" + Article.Art_Ref + "----" + (DateTime.UtcNow - start).ToString());
                }
            }
            catch (Exception ex)
            {
                Core.Error.SendMailError(ex.ToString());
            }
        }
示例#9
0
 /// <summary>
 /// ExecArticle - Supprime toutes les images d'un article
 /// </summary>
 /// <param name="ArticleSend"></param>
 public void ExecArticle(Int32 ArticleSend, Boolean OnlyIfNotSourceExist, out List <string> log_out)
 {
     log_out = new List <string>();
     try
     {
         Model.Local.ArticleRepository ArticleRepository = new Model.Local.ArticleRepository();
         if (ArticleRepository.ExistArticle(ArticleSend))
         {
             Model.Local.ArticleImageRepository ArticleImageRepository = new Model.Local.ArticleImageRepository();
             List <Model.Local.ArticleImage>    List = ArticleImageRepository.ListArticle(ArticleSend);
             if (List != null)
             {
                 Model.Local.Article Article = ArticleRepository.ReadArticle(ArticleSend);
                 foreach (Model.Local.ArticleImage ArticleImage in List)
                 {
                     List <string> log = null;
                     if (OnlyIfNotSourceExist)
                     {
                         if (!System.IO.File.Exists(System.IO.Path.Combine(Core.Global.GetConfig().AutomaticImportFolderPicture, ArticleImage.ImaArt_SourceFile)))
                         {
                             Exec(ArticleImage, Article, out log);
                         }
                     }
                     else
                     {
                         Exec(ArticleImage, Article, out log);
                     }
                     if (log != null && log.Count > 0)
                     {
                         log_out.AddRange(log);
                     }
                 }
             }
         }
     }
     catch (Exception ex)
     {
         Core.Error.SendMailError(ex.ToString());
     }
 }
示例#10
0
 public void Exec(Int32 ArticleSend)
 {
     try
     {
         Model.Local.ArticleRepository        ArticleRepository = new Model.Local.ArticleRepository();
         Model.Local.Article                  Article           = ArticleRepository.ReadArticle(ArticleSend);
         Model.Prestashop.PsProductRepository ProductRepository = new Model.Prestashop.PsProductRepository();
         Model.Prestashop.PsProduct           Product           = new Model.Prestashop.PsProduct();
         // If the Article have a connection with Prestashop
         if (Article.Pre_Id != null)
         {
             //Article.Art_Date = Article.Art_Date.AddMilliseconds(-Article.Art_Date.Millisecond);
             if (ProductRepository.ExistId(Convert.ToUInt32(Article.Pre_Id.Value)))
             {
                 Product = ProductRepository.ReadId(Convert.ToUInt32(Article.Pre_Id.Value));
                 this.ExecLocalToDistant(Article, ArticleRepository, Product, ProductRepository);
             }
         }
     }
     catch (Exception ex)
     {
         Core.Error.SendMailError(ex.ToString());
     }
 }
示例#11
0
        private void ExecDistantToLocal(Model.Prestashop.PsProduct Product, Model.Local.Article Article, Model.Local.ArticleRepository ArticleRepository)
        {
            try
            {
                #region Recovery Data From CategoryProduct
                Model.Prestashop.PsCategoryProductRepository PsCategoryProductRepository = new Model.Prestashop.PsCategoryProductRepository();
                Model.Local.CatalogRepository         CatalogRepository        = new Model.Local.CatalogRepository();
                Model.Local.ArticleCatalogRepository  ArticleCatalogRepository = new Model.Local.ArticleCatalogRepository();
                Model.Prestashop.PsCategoryRepository PsCategoryRepository     = new Model.Prestashop.PsCategoryRepository();

                // filtrage des catalogues existants dans PC et PS
                List <Model.Local.CatalogLight> ListLocalCatalog = CatalogRepository.ListLight();
                List <uint> ListPrestashopCategory = PsCategoryRepository.ListIdOrderByLevelDepth(Core.Global.CurrentShop.IDShop, PsCategoryRepository.ReadId(Core.Global.CurrentShop.IDCategory).LevelDepth);
                ListLocalCatalog = ListLocalCatalog.Where(lc => ListPrestashopCategory.Count(pc => pc == (uint)lc.Pre_Id) > 0).ToList();

                // filtrage des associations PS par rapport aux catégories PS existantes en tant que catalogue PC
                List <Model.Prestashop.PsCategoryProduct> ListPsCategoryProduct = PsCategoryProductRepository.ListProduct(Product.IDProduct);
                ListPsCategoryProduct = ListPsCategoryProduct.Where(cp => ListLocalCatalog.Count(lc => lc.Pre_Id == cp.IDCategory) > 0).ToList();

                // filtrage des associations PC par rapport aux catégories ayant un ID PS
                List <Model.Local.ArticleCatalog> ListLocal = ArticleCatalogRepository.ListArticle(Article.Art_Id);
                ListLocal = ListLocal.Where(ac => ac.Catalog.Pre_Id != null).ToList();

                // tant que les associations en local contiennent des associations non présentes dans Prestashop
                if (Core.Global.GetConfig().DeleteCatalogProductAssociation)
                {
                    // suppression des occurences inexistantes dans PS
                    while (ListLocal.Count(ac => ListPsCategoryProduct.Count(cp => cp.IDCategory == ac.Catalog.Pre_Id) == 0) > 0)
                    {
                        Model.Local.ArticleCatalog target = ListLocal.FirstOrDefault(ac => ListPsCategoryProduct.Count(cp => cp.IDCategory == ac.Catalog.Pre_Id) == 0);
                        ArticleCatalogRepository.Delete(target);
                        ListLocal.Remove(target);
                    }
                    ;
                }

                // récupération catégorie principale si catalogue existant dans Prestaconnect
                if (Product.IDCategoryDefault != null && Product.IDCategoryDefault != 0 &&
                    ListLocalCatalog.Count(lc => lc.Pre_Id == (int)Product.IDCategoryDefault) > 0)
                {
                    ArticleRepository = new Model.Local.ArticleRepository();
                    Article           = ArticleRepository.ReadArticle(Article.Art_Id);

                    Article.Cat_Id = ListLocalCatalog.FirstOrDefault(lc => lc.Pre_Id == (int)Product.IDCategoryDefault).Cat_Id;
                    ArticleRepository.Save();

                    if (ListLocal.Count(ac => ac.Art_Id == Article.Art_Id && ac.Cat_Id == Article.Cat_Id) == 0)
                    {
                        ArticleCatalogRepository.Add(new Model.Local.ArticleCatalog()
                        {
                            Art_Id = Article.Art_Id,
                            Cat_Id = Article.Cat_Id
                        });
                    }
                }

                // filtre des associations Prestashop par rapport à celles déjà présentes dans Prestaconnect puis ajout
                ListLocal             = ArticleCatalogRepository.ListArticle(Article.Art_Id);
                ListLocal             = ListLocal.Where(ac => ac.Catalog.Pre_Id != null).ToList();
                ListPsCategoryProduct = ListPsCategoryProduct.Where(cp => ListLocal.Count(ac => ac.Catalog.Pre_Id == (Int32)cp.IDCategory) == 0).ToList();
                foreach (Model.Prestashop.PsCategoryProduct PsCategoryProduct in ListPsCategoryProduct)
                {
                    ArticleCatalogRepository.Add(new Model.Local.ArticleCatalog()
                    {
                        Art_Id = Article.Art_Id,
                        Cat_Id = ListLocalCatalog.FirstOrDefault(lc => lc.Pre_Id == (Int32)PsCategoryProduct.IDCategory).Cat_Id
                    });
                }
                #endregion
            }
            catch (Exception ex)
            {
                Core.Error.SendMailError(ex.ToString());
            }
        }
        public Boolean Exec(String PathImg, Int32 ArticleSend, int position, int Declination)
        {
            Boolean result         = false;
            Int32   IdArticleImage = 0;

            try
            {
                String extension = Path.GetExtension(PathImg);
                String FileName  = Path.GetFileName(PathImg);

                Model.Local.ArticleImageRepository ArticleImageRepository = new Model.Local.ArticleImageRepository();

                if (!ArticleImageRepository.ExistArticleFile(ArticleSend, FileName))
                {
                    Model.Local.ArticleRepository ArticleRepository = new Model.Local.ArticleRepository();
                    Model.Local.Article           Article           = ArticleRepository.ReadArticle(ArticleSend);
                    Model.Local.ArticleImage      ArticleImage      = new Model.Local.ArticleImage()
                    {
                        Art_Id            = Article.Art_Id,
                        ImaArt_Name       = Article.Art_Name,
                        ImaArt_Image      = "",
                        ImaArt_DateAdd    = DateTime.Now,
                        ImaArt_SourceFile = FileName
                    };
                    ArticleImage.ImaArt_Position = this.ReadNextPosition(Article, position);
                    ArticleImage.ImaArt_Default  = !(new Model.Local.ArticleImageRepository().ExistArticleDefault(Article.Art_Id, true));
                    ArticleImageRepository.Add(ArticleImage);
                    ArticleImage.ImaArt_Image = String.Format("{0}" + extension, ArticleImage.ImaArt_Id);
                    ArticleImageRepository.Save();
                    IdArticleImage = ArticleImage.ImaArt_Id;

                    string uri = PathImg.Replace("File:///", "").Replace("file:///", "").Replace("File://", "\\\\").Replace("file://", "\\\\").Replace("/", "\\");

                    System.IO.File.Copy(uri, ArticleImage.TempFileName);

                    Model.Prestashop.PsImageTypeRepository PsImageTypeRepository = new Model.Prestashop.PsImageTypeRepository();
                    List <Model.Prestashop.PsImageType>    ListPsImageType       = PsImageTypeRepository.ListProduct(1);

                    System.Drawing.Image img = System.Drawing.Image.FromFile(ArticleImage.TempFileName);

                    foreach (Model.Prestashop.PsImageType PsImageType in ListPsImageType)
                    {
                        Core.Img.resizeImage(img, Convert.ToInt32(PsImageType.Width), Convert.ToInt32(PsImageType.Height),
                                             ArticleImage.FileName(PsImageType.Name));
                    }

                    Core.Img.resizeImage(img, Core.Global.GetConfig().ConfigImageMiniatureWidth, Core.Global.GetConfig().ConfigImageMiniatureHeight,
                                         ArticleImage.SmallFileName);

                    img.Dispose();

                    // <JG> 28/10/2015 ajout attribution gamme/images
                    if (Declination != 0)
                    {
                        if (ArticleImage.Article.TypeArticle == Model.Local.Article.enum_TypeArticle.ArticleMonoGamme ||
                            ArticleImage.Article.TypeArticle == Model.Local.Article.enum_TypeArticle.ArticleMultiGammes)
                        {
                            Model.Local.AttributeArticleRepository AttributeArticleRepository = new Model.Local.AttributeArticleRepository();
                            if (AttributeArticleRepository.Exist(Declination))
                            {
                                Model.Local.AttributeArticleImageRepository AttributeArticleImageRepository = new Model.Local.AttributeArticleImageRepository();
                                if (!AttributeArticleImageRepository.ExistAttributeArticleImage(Declination, ArticleImage.ImaArt_Id))
                                {
                                    AttributeArticleImageRepository.Add(new Model.Local.AttributeArticleImage()
                                    {
                                        AttArt_Id = Declination,
                                        ImaArt_Id = ArticleImage.ImaArt_Id,
                                    });
                                }
                            }
                        }
                        else if (ArticleImage.Article.TypeArticle == Model.Local.Article.enum_TypeArticle.ArticleComposition)
                        {
                            Model.Local.CompositionArticleRepository CompositionArticleRepository = new Model.Local.CompositionArticleRepository();
                            if (CompositionArticleRepository.Exist(Declination))
                            {
                                Model.Local.CompositionArticleImageRepository CompositionArticleImageRepository = new Model.Local.CompositionArticleImageRepository();
                                if (!CompositionArticleImageRepository.ExistCompositionArticleImage(Declination, ArticleImage.ImaArt_Id))
                                {
                                    CompositionArticleImageRepository.Add(new Model.Local.CompositionArticleImage()
                                    {
                                        ComArt_Id = Declination,
                                        ImaArt_Id = ArticleImage.ImaArt_Id,
                                    });
                                }
                            }
                        }
                    }

                    result = true;
                }
                else if (Core.Global.GetConfig().ImportImageReplaceFiles)
                {
                    FileInfo importfile = new FileInfo(PathImg);
                    Model.Local.ArticleImage ArticleImage = ArticleImageRepository.ReadArticleFile(ArticleSend, FileName);
                    FileInfo existfile = new FileInfo(ArticleImage.TempFileName);
                    if ((ArticleImage.ImaArt_DateAdd == null || importfile.LastWriteTime > ArticleImage.ImaArt_DateAdd) ||
                        importfile.Length != existfile.Length)
                    {
                        try
                        {
                            // import nouveau fichier
                            string uri = PathImg.Replace("File:///", "").Replace("file:///", "").Replace("File://", "\\\\").Replace("file://", "\\\\").Replace("/", "\\");
                            System.IO.File.Copy(uri, ArticleImage.TempFileName, true);

                            Model.Prestashop.PsImageTypeRepository PsImageTypeRepository = new Model.Prestashop.PsImageTypeRepository();
                            List <Model.Prestashop.PsImageType>    ListPsImageType       = PsImageTypeRepository.ListProduct(1);

                            System.Drawing.Image img = System.Drawing.Image.FromFile(ArticleImage.TempFileName);

                            foreach (Model.Prestashop.PsImageType PsImageType in ListPsImageType)
                            {
                                Core.Img.resizeImage(img, Convert.ToInt32(PsImageType.Width), Convert.ToInt32(PsImageType.Height),
                                                     ArticleImage.FileName(PsImageType.Name));
                            }

                            Core.Img.resizeImage(img, Core.Global.GetConfig().ConfigImageMiniatureWidth, Core.Global.GetConfig().ConfigImageMiniatureHeight,
                                                 ArticleImage.SmallFileName);
                            Model.Prestashop.PsImageRepository PsImageRepository = new Model.Prestashop.PsImageRepository();

                            if (ArticleImage.Pre_Id != null && PsImageRepository.ExistImage((uint)ArticleImage.Pre_Id))
                            {
                                String FTP      = Core.Global.GetConfig().ConfigFTPIP;
                                String User     = Core.Global.GetConfig().ConfigFTPUser;
                                String Password = Core.Global.GetConfig().ConfigFTPPassword;

                                Model.Prestashop.PsImage PsImage = PsImageRepository.ReadImage((uint)ArticleImage.Pre_Id);

                                string ftpPath = "/img/p/";
                                switch (Core.Global.GetConfig().ConfigImageStorageMode)
                                {
                                case Core.Parametres.ImageStorageMode.old_system:
                                    #region old_system
                                    // no action on path
                                    break;
                                    #endregion

                                case Core.Parametres.ImageStorageMode.new_system:
                                default:
                                    #region new_system

                                    //System.Net.FtpWebRequest ftp_folder = null;

                                    foreach (char directory in PsImage.IDImage.ToString())
                                    {
                                        ftpPath += directory + "/";

                                        #region MyRegion
                                        try
                                        {
                                            System.Net.FtpWebRequest request = (System.Net.FtpWebRequest)System.Net.FtpWebRequest.Create(FTP + ftpPath);

                                            request.Credentials = new System.Net.NetworkCredential(User, Password);
                                            request.UsePassive  = true;
                                            request.UseBinary   = true;
                                            request.KeepAlive   = false;

                                            request.Method = System.Net.WebRequestMethods.Ftp.MakeDirectory;

                                            System.Net.FtpWebResponse makeDirectoryResponse = (System.Net.FtpWebResponse)request.GetResponse();
                                        }
                                        catch     //Exception ex
                                        {
                                            //System.Windows.MessageBox.Show(ex.ToString());
                                        }
                                        #endregion
                                    }
                                    break;
                                    #endregion
                                }

                                #region Upload des images
                                extension = ArticleImage.GetExtension;
                                if (System.IO.File.Exists(ArticleImage.TempFileName))
                                {
                                    string ftpfullpath = (Core.Global.GetConfig().ConfigImageStorageMode == Core.Parametres.ImageStorageMode.old_system)
                                        ? FTP + ftpPath + PsImage.IDProduct + "-" + PsImage.IDImage + ".jpg"
                                        : FTP + ftpPath + PsImage.IDImage + ".jpg";

                                    System.Net.FtpWebRequest ftp = (System.Net.FtpWebRequest)System.Net.FtpWebRequest.Create(ftpfullpath);
                                    ftp.Credentials = new System.Net.NetworkCredential(User, Password);
                                    //userid and password for the ftp server to given

                                    ftp.UseBinary  = true;
                                    ftp.UsePassive = true;
                                    ftp.EnableSsl  = Core.Global.GetConfig().ConfigFTPSSL;
                                    ftp.Method     = System.Net.WebRequestMethods.Ftp.UploadFile;
                                    System.IO.FileStream fs = System.IO.File.OpenRead(ArticleImage.TempFileName);
                                    byte[] buffer           = new byte[fs.Length];
                                    fs.Read(buffer, 0, buffer.Length);
                                    fs.Close();
                                    System.IO.Stream ftpstream = ftp.GetRequestStream();
                                    ftpstream.Write(buffer, 0, buffer.Length);
                                    ftpstream.Close();
                                    ftp.Abort();
                                }


                                foreach (Model.Prestashop.PsImageType PsImageType in ListPsImageType)
                                {
                                    String localfile = ArticleImage.FileName(PsImageType.Name);
                                    if (System.IO.File.Exists(localfile))
                                    {
                                        string ftpfullpath = (Core.Global.GetConfig().ConfigImageStorageMode == Core.Parametres.ImageStorageMode.old_system)
                                            ? FTP + ftpPath + PsImage.IDProduct + "-" + PsImage.IDImage + "-" + PsImageType.Name + ".jpg"
                                            : FTP + ftpPath + PsImage.IDImage + "-" + PsImageType.Name + ".jpg";

                                        System.Net.FtpWebRequest ftp = (System.Net.FtpWebRequest)System.Net.FtpWebRequest.Create(ftpfullpath);
                                        ftp.Credentials = new System.Net.NetworkCredential(User, Password);
                                        //userid and password for the ftp server to given

                                        ftp.UseBinary  = true;
                                        ftp.UsePassive = true;
                                        ftp.EnableSsl  = Core.Global.GetConfig().ConfigFTPSSL;
                                        ftp.Method     = System.Net.WebRequestMethods.Ftp.UploadFile;
                                        System.IO.FileStream fs = System.IO.File.OpenRead(localfile);
                                        byte[] buffer           = new byte[fs.Length];
                                        fs.Read(buffer, 0, buffer.Length);
                                        fs.Close();
                                        System.IO.Stream ftpstream = ftp.GetRequestStream();
                                        ftpstream.Write(buffer, 0, buffer.Length);
                                        ftpstream.Close();
                                        ftp.Abort();
                                    }
                                }
                                #endregion
                            }

                            ArticleImage.ImaArt_DateAdd = DateTime.Now;
                            ArticleImageRepository.Save();

                            // <JG> 28/10/2015 ajout attribution gamme/images
                            if (Declination != 0)
                            {
                                if (ArticleImage.Article.TypeArticle == Model.Local.Article.enum_TypeArticle.ArticleMonoGamme ||
                                    ArticleImage.Article.TypeArticle == Model.Local.Article.enum_TypeArticle.ArticleMultiGammes)
                                {
                                    Model.Local.AttributeArticleRepository AttributeArticleRepository = new Model.Local.AttributeArticleRepository();
                                    if (AttributeArticleRepository.Exist(Declination))
                                    {
                                        Model.Local.AttributeArticleImageRepository AttributeArticleImageRepository = new Model.Local.AttributeArticleImageRepository();
                                        if (!AttributeArticleImageRepository.ExistAttributeArticleImage(Declination, ArticleImage.ImaArt_Id))
                                        {
                                            AttributeArticleImageRepository.Add(new Model.Local.AttributeArticleImage()
                                            {
                                                AttArt_Id = Declination,
                                                ImaArt_Id = ArticleImage.ImaArt_Id,
                                            });
                                        }

                                        // réaffectation côté PrestaShop
                                        Model.Local.AttributeArticle AttributeArticle = AttributeArticleRepository.Read(Declination);
                                        if (AttributeArticle.Pre_Id != null &&
                                            AttributeArticle.Pre_Id != 0)
                                        {
                                            Model.Prestashop.PsProductAttributeImageRepository PsProductAttributeImageRepository = new Model.Prestashop.PsProductAttributeImageRepository();
                                            if (PsProductAttributeImageRepository.ExistProductAttributeImage((UInt32)AttributeArticle.Pre_Id, (UInt32)ArticleImage.Pre_Id) == false)
                                            {
                                                PsProductAttributeImageRepository.Add(new Model.Prestashop.PsProductAttributeImage()
                                                {
                                                    IDImage            = (UInt32)ArticleImage.Pre_Id,
                                                    IDProductAttribute = (UInt32)AttributeArticle.Pre_Id,
                                                });
                                            }
                                        }
                                    }
                                }
                                else if (ArticleImage.Article.TypeArticle == Model.Local.Article.enum_TypeArticle.ArticleComposition)
                                {
                                    Model.Local.CompositionArticleRepository CompositionArticleRepository = new Model.Local.CompositionArticleRepository();
                                    if (CompositionArticleRepository.Exist(Declination))
                                    {
                                        Model.Local.CompositionArticleImageRepository CompositionArticleImageRepository = new Model.Local.CompositionArticleImageRepository();
                                        if (!CompositionArticleImageRepository.ExistCompositionArticleImage(Declination, ArticleImage.ImaArt_Id))
                                        {
                                            CompositionArticleImageRepository.Add(new Model.Local.CompositionArticleImage()
                                            {
                                                ComArt_Id = Declination,
                                                ImaArt_Id = ArticleImage.ImaArt_Id,
                                            });
                                        }

                                        // réaffectation côté PrestaShop
                                        Model.Local.CompositionArticle CompositionArticle = CompositionArticleRepository.Read(Declination);
                                        if (CompositionArticle.Pre_Id != null &&
                                            CompositionArticle.Pre_Id != 0)
                                        {
                                            Model.Prestashop.PsProductAttributeImageRepository PsProductAttributeImageRepository = new Model.Prestashop.PsProductAttributeImageRepository();
                                            if (PsProductAttributeImageRepository.ExistProductAttributeImage((UInt32)CompositionArticle.Pre_Id, (UInt32)ArticleImage.Pre_Id) == false)
                                            {
                                                PsProductAttributeImageRepository.Add(new Model.Prestashop.PsProductAttributeImage()
                                                {
                                                    IDImage            = (UInt32)ArticleImage.Pre_Id,
                                                    IDProductAttribute = (UInt32)CompositionArticle.Pre_Id,
                                                });
                                            }
                                        }
                                    }
                                }
                            }

                            result = true;

                            logs.Add("II30- Remplacement de l'image " + ArticleImage.ImaArt_SourceFile + " en position " + ArticleImage.ImaArt_Position + " pour l'article " + ArticleImage.Article.Art_Ref);
                        }
                        catch (Exception ex)
                        {
                            Core.Error.SendMailError(ex.ToString());
                            logs.Add("II39- Erreur lors du remplacement de l'image " + ArticleImage.ImaArt_SourceFile + " en position " + ArticleImage.ImaArt_Position + " pour l'article " + ArticleImage.Article.Art_Ref);
                            logs.Add(ex.ToString());
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Core.Error.SendMailError(ex.ToString());
                if (ex.ToString().Contains("System.UnauthorizedAccessException") && IdArticleImage != 0)
                {
                    Model.Local.ArticleImageRepository ArticleImageRepository = new Model.Local.ArticleImageRepository();
                    ArticleImageRepository.Delete(ArticleImageRepository.ReadArticleImage(IdArticleImage));
                }
            }
            return(result);
        }