public void Sync(Int32 ArticleSend)
        {
            this.Semaphore.WaitOne();

            try
            {
                Model.Local.ArticleRepository        ArticleRepository   = new Model.Local.ArticleRepository();
                Model.Local.Article                  Article             = ArticleRepository.ReadArticle(ArticleSend);
                Model.Prestashop.PsProductRepository PsProductRepository = new Model.Prestashop.PsProductRepository();
                if (Article.Pre_Id != null && !PsProductRepository.ExistId((uint)Article.Pre_Id))
                {
                    Article.Pre_Id     = null;
                    Article.Art_Active = this.Active;
                    ArticleRepository.Save();
                }
            }
            catch (Exception ex)
            {
                Core.Error.SendMailError(ex.ToString());
            }

            lock (this)
            {
                this.CurrentCount += 1;
            }
            this.ReportProgress(this.CurrentCount * 100 / this.ListCount);
            this.Semaphore.Release();
        }
        public TransfertPack()
        {
            this.InitializeComponent();
            Model.Local.ArticleRepository ArticleRepository = new Model.Local.ArticleRepository();
            List <Int32> ListArticle = ArticleRepository.ListIdSyncPack(true);

            // récupération des éléments du pack
            //foreach (Int32 ArticleSend in ListArticle)
            //{
            //    Model.Local.Article Article = ArticleRepository.ReadArticle(ArticleSend);
            //    if (Article.Art_Pack == true)
            //    {
            //        List<Int32> PackElements;
            //        SynchronisationArticle.ReadPackElements(ArticleRepository, Article, out PackElements);
            //        ListArticle.AddRange(PackElements);
            //    }
            //    ListArticle.Add(ArticleSend);
            //}

            this.ListCount = ListArticle.Count;

            Context = SynchronizationContext.Current;
            this.ParallelOptions.MaxDegreeOfParallelism = MaximumThreadCount;
            this.ReportProgress(0);
            Task.Factory.StartNew(() =>
            {
                Parallel.ForEach(ListArticle, this.ParallelOptions, Transfert);
            });
        }
Пример #3
0
        public void Sync(Int32 Article)
        {
            this.Semaphore.WaitOne();

            Model.Local.ArticleRepository ArticleRepository = new Model.Local.ArticleRepository();
            if (ArticleRepository.ExistArticle(Article))
            {
                Model.Local.Article            Item = ArticleRepository.ReadArticle(Article);
                Model.Sage.F_ARTICLERepository F_ARTICLERepository = new Model.Sage.F_ARTICLERepository();
                Model.Sage.F_ARTICLE           F_ARTICLE           = (F_ARTICLERepository.ExistArticle(Item.Sag_Id) ? F_ARTICLERepository.ReadArticle(Item.Sag_Id) : null);
                if (F_ARTICLE != null)
                {
                    if (Core.Global.GetConfig().ArticleImportConditionnementActif &&
                        F_ARTICLE.AR_Condition != null && F_ARTICLE.AR_Condition != 0)
                    {
                        Core.ImportSage.ImportArticle importarticle = new Core.ImportSage.ImportArticle();
                        if (importarticle.ExecConditioning(F_ARTICLE, Item))
                        {
                            Item.Art_Date = DateTime.Now;
                            ArticleRepository.Save();
                        }
                    }
                }
            }

            lock (this)
            {
                this.CurrentCount += 1;
            }
            this.ReportProgress(this.CurrentCount * 100 / this.ListCount);
            this.Semaphore.Release();
        }
Пример #4
0
        public SynchronisationArticle(List <Int32> ArticlesSend)
        {
            this.InitializeComponent();
            List <Int32> ListArticle = new List <Int32>();

            // récupération des éléments du pack
            Model.Local.ArticleRepository ArticleRepository = new Model.Local.ArticleRepository();
            foreach (Int32 ArticleSend in ArticlesSend)
            {
                Model.Local.Article Article = ArticleRepository.ReadArticle(ArticleSend);
                if (Article.Art_Pack == true)
                {
                    List <Int32> PackElements;
                    ReadPackElements(ArticleRepository, Article, out PackElements);
                    ListArticle.AddRange(PackElements);
                }
                ListArticle.Add(ArticleSend);
            }

            this.ListCount = ListArticle.Count;

            Core.Temp.LoadListesClients();

            Context = SynchronizationContext.Current;
            this.ParallelOptions.MaxDegreeOfParallelism = System.Environment.ProcessorCount;
            this.ReportProgress(0);
            Task.Factory.StartNew(() =>
            {
                Parallel.ForEach(ListArticle, this.ParallelOptions, Sync);
            });
        }
Пример #5
0
        public void ReportInfosSynchro(Int32 Article, Core.Temp._action_information_synchro action, string comment = null)
        {
            Context.Post(state =>
            {
                switch (action)
                {
                case PRESTACONNECT.Core.Temp._action_information_synchro.debut:
                    Model.Local.Article_Progress Article_Progress = new Model.Local.ArticleRepository().ReadArticleProgress(Article);
                    this.list_progress.Add(Article_Progress);
                    break;

                case PRESTACONNECT.Core.Temp._action_information_synchro.fin:
                    this.list_progress.Remove(list_progress.FirstOrDefault(p => p.Art_Id == Article));
                    break;

                case PRESTACONNECT.Core.Temp._action_information_synchro.refresh:
                    this.list_progress.FirstOrDefault(p => p.Art_Id == Article).Comment = comment;
                    break;

                default:
                    break;
                }
                listBoxProgress.ItemsSource = list_progress;
            }, null);
        }
Пример #6
0
 /// <summary>
 /// ReadPackElements
 /// </summary>
 /// <param name="ArticleRepository"></param>
 /// <param name="Article"></param>
 /// <param name="PackElements"></param>
 /// <remarks>Récupération des id des éléments du pack</remarks>
 internal static void ReadPackElements(Model.Local.ArticleRepository ArticleRepository, Model.Local.Article Article, out List <Int32> PackElements)
 {
     PackElements = new List <Int32>();
     Model.Sage.F_ARTICLERepository F_ARTICLERepository = new Model.Sage.F_ARTICLERepository();
     Model.Sage.F_ARTICLE           F_ARTICLE           = F_ARTICLERepository.ReadArticle(Article.Sag_Id);
     Model.Sage.F_ARTICLE           F_ARTICLENOMENCLAT;
     Model.Local.Article            ArticleNomenclat;
     foreach (Model.Sage.F_NOMENCLAT F_NOMENCLAT in new Model.Sage.F_NOMENCLATRepository().ListRef(F_ARTICLE.AR_Ref))
     {
         if (F_ARTICLERepository.ExistReference(F_NOMENCLAT.NO_RefDet))
         {
             F_ARTICLENOMENCLAT = F_ARTICLERepository.ReadReference(F_NOMENCLAT.NO_RefDet);
             if (ArticleRepository.ExistSag_Id(F_ARTICLENOMENCLAT.cbMarq) &&
                 F_ARTICLENOMENCLAT.AR_SuiviStock != (short)ABSTRACTION_SAGE.F_ARTICLE.Obj._Enum_AR_SuiviStock.Aucun)
             // pour ne pas prendre en compte les articles non suivi en stock
             {
                 ArticleNomenclat = ArticleRepository.ReadSag_Id(F_ARTICLENOMENCLAT.cbMarq);
                 if (ArticleNomenclat.Art_Sync == true ||
                     (ArticleNomenclat.Pre_Id != null && ArticleNomenclat.Pre_Id.Value != 0))
                 {
                     if (ArticleNomenclat.Art_Pack)
                     {
                         List <Int32> PackPackElements = new List <Int32>();
                         ReadPackElements(ArticleRepository, ArticleNomenclat, out PackPackElements);
                         PackElements.AddRange(PackPackElements);
                     }
                     PackElements.Add(ArticleNomenclat.Art_Id);
                 }
             }
         }
     }
 }
Пример #7
0
 private void ShowItem(int article)
 {
     PRESTACONNECT.Loading Loading = new PRESTACONNECT.Loading();
     Loading.Show();
     PRESTACONNECT.Article Article = new Article(new Model.Local.ArticleRepository().ReadArticle(article));
     Loading.Close();
     Article.ShowDialog();
     #region Refresh ligne article
     // rafraichissement des données affichées pour l'article par rapport à la base de données
     // sans perte du focus nécessaire à la continuité de saisie au clavier (accessibilité)
     Model.Local.Article temp = new Model.Local.ArticleRepository().ReadArticle(article);
     if (temp != null)
     {
         Model.Local.Article select = DataContext.SelectedCatalogItems.FirstOrDefault(a => a.Art_Id == article);
         select.Art_Name      = temp.Art_Name;
         select.Art_Ean13     = temp.Art_Ean13;
         select.Art_Sync      = temp.Art_Sync;
         select.Art_SyncPrice = temp.Art_SyncPrice;
         select.Art_Active    = temp.Art_Active;
         select.Art_Date      = temp.Art_Date;
         select.Art_Type      = temp.Art_Type;
         select.Pre_Id        = temp.Pre_Id;
         if (temp.prestashopProduct != null)
         {
             select.RefreshPrestashopProductData();
         }
         if (temp.TypeArticle == Model.Local.Article.enum_TypeArticle.ArticleComposition)
         {
             select.TypeArticle = Model.Local.Article.enum_TypeArticle.defaut;
             if (temp.CompositionArticle != null)
             {
                 List <int> list_composition = temp.CompositionArticle.Select(ca => ca.ComArt_F_ARTICLE_SagId).ToList();
                 foreach (Model.Local.Article composition in DataContext.SelectedCatalogItems.Where(a => list_composition.Contains(a.Sag_Id)))
                 {
                     Model.Local.Article temp_compo = new Model.Local.ArticleRepository().ReadArticle(composition.Art_Id);
                     composition.Art_Sync      = temp_compo.Art_Sync;
                     composition.Art_SyncPrice = temp_compo.Art_SyncPrice;
                     composition.Art_Active    = temp_compo.Art_Active;
                     composition.Art_Date      = temp_compo.Art_Date;
                 }
             }
         }
     }
     else
     {
         DataContext.LoadSelectedCatalogItems();
     }
     #endregion
 }
Пример #8
0
        public ImportSageArticleMedia(String DirDoc)
        {
            this.DirDoc = DirDoc;
            this.InitializeComponent();
            List <int> ListArticles = new Model.Local.ArticleRepository().ListId();

            this.ListCount = ListArticles.Count;
            Context        = SynchronizationContext.Current;
            this.ParallelOptions.MaxDegreeOfParallelism = MaximumThreadCount;
            this.ReportProgress(0);
            Task.Factory.StartNew(() =>
            {
                Parallel.ForEach(ListArticles, this.ParallelOptions, Sync);
            });
        }
Пример #9
0
        public void ControlURLRewriteArticle()
        {
            this.CurrentCount = 0;
            Model.Local.ArticleRepository ArticleRepository = new Model.Local.ArticleRepository();
            List <Int32> ListArticles = ArticleRepository.ListId();

            this.ListCount = ListArticles.Count;

            Context = SynchronizationContext.Current;
            this.ParallelOptions.MaxDegreeOfParallelism = System.Environment.ProcessorCount;
            this.ReportProgressArticle(0);
            Task.Factory.StartNew(() =>
            {
                Parallel.ForEach(ListArticles, this.ParallelOptions, ExecArticle);
            });
        }
        public ImportCompositionGammes()
        {
            this.InitializeComponent();
            Model.Local.ArticleRepository ArticleRepository = new Model.Local.ArticleRepository();
            List <Int32> ListLocal = ArticleRepository.ListIdTypeComposition();

            this.ListCount = ListLocal.Count;

            Context = SynchronizationContext.Current;
            this.ParallelOptions.MaxDegreeOfParallelism = MaximumThreadCount;
            this.ReportProgress(0);
            Task.Factory.StartNew(() =>
            {
                Parallel.ForEach(ListLocal, this.ParallelOptions, Sync);
            });
        }
Пример #11
0
        public SynchronisationArticle()
        {
            this.InitializeComponent();
            Model.Local.ArticleRepository ArticleRepository = new Model.Local.ArticleRepository();
            List <Int32> ListArticle = ArticleRepository.ListIdSyncOrderByPack(true);

            this.ListCount = ListArticle.Count;

            Core.Temp.LoadListesClients();

            Context = SynchronizationContext.Current;
            this.ParallelOptions.MaxDegreeOfParallelism = MaximumThreadCount;
            this.ReportProgress(0);
            Task.Factory.StartNew(() =>
            {
                Parallel.ForEach(ListArticle, this.ParallelOptions, Sync);
            });
        }
Пример #12
0
        public SuppressionImage(Boolean DeleteOnlyIfSourceNotExist)
        {
            this.InitializeComponent();

            DeleteOnlyNotSource = DeleteOnlyIfSourceNotExist;

            Model.Local.ArticleRepository ArticleRepository = new Model.Local.ArticleRepository();
            List <int> ListArticle = ArticleRepository.ListId();

            this.ListCount = ListArticle.Count;
            this.Context   = SynchronizationContext.Current;
            this.ParallelOptions.MaxDegreeOfParallelism = MaximumThreadCount;
            this.ReportProgress(0);
            Task.Factory.StartNew(() =>
            {
                Parallel.ForEach(ListArticle, this.ParallelOptions, Exec);
            });
        }
        public TransfertFeature(List <Int32> ListArticle = null)
        {
            this.InitializeComponent();
            if (ListArticle == null)
            {
                Model.Local.ArticleRepository ArticleRepository = new Model.Local.ArticleRepository();
                ListArticle = ArticleRepository.ListIdSync(true);
            }
            this.ListCount = ListArticle.Count;

            Context = SynchronizationContext.Current;
            this.ParallelOptions.MaxDegreeOfParallelism = MaximumThreadCount;
            this.ReportProgress(0);
            Task.Factory.StartNew(() =>
            {
                Parallel.ForEach(ListArticle, this.ParallelOptions, Transfert);
            });
        }
        public ControlArticle(Boolean Actif)
        {
            this.InitializeComponent();

            Model.Local.ArticleRepository ArticleRepository = new Model.Local.ArticleRepository();
            List <Int32> ListArticle = ArticleRepository.ListId();

            this.ListCount = ListArticle.Count;

            this.Active = Actif;

            Context = SynchronizationContext.Current;
            this.ParallelOptions.MaxDegreeOfParallelism = MaximumThreadCount;
            this.ReportProgress(0);
            Task.Factory.StartNew(() =>
            {
                Parallel.ForEach(ListArticle, this.ParallelOptions, Sync);
            });
        }
Пример #15
0
        public void ExecArticle(Int32 ArticleSend)
        {
            this.Semaphore.WaitOne();

            try
            {
                Model.Local.ArticleRepository ArticleRepository = new Model.Local.ArticleRepository();
                Model.Local.Article           Article           = ArticleRepository.ReadArticle(ArticleSend);
                string url = Core.Global.ReadLinkRewrite(Article.Art_LinkRewrite);
                if (url != Article.Art_LinkRewrite)
                {
                    Article.Art_LinkRewrite = url;
                    if (!this.RewritePrestaShop)
                    {
                        Article.Art_Date = DateTime.Now;
                    }
                    ArticleRepository.Save();

                    if (this.RewritePrestaShop && Article.Pre_Id != null)
                    {
                        Model.Prestashop.PsProductLangRepository PsProductLangRepository = new Model.Prestashop.PsProductLangRepository();
                        if (PsProductLangRepository.ExistProductLang(Article.Pre_Id.Value, Core.Global.Lang, Core.Global.CurrentShop.IDShop))
                        {
                            Model.Prestashop.PsProductLang PsProductLang = PsProductLangRepository.ReadProductLang(Article.Pre_Id.Value, Core.Global.Lang, Core.Global.CurrentShop.IDShop);
                            PsProductLang.LinkRewrite = url;
                            PsProductLangRepository.Save();
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Core.Error.SendMailError(ex.ToString());
            }

            lock (this)
            {
                this.CurrentCount += 1;
            }
            this.ReportProgressArticle(this.CurrentCount * 100 / this.ListCount);
            this.Semaphore.Release();
        }
Пример #16
0
        public void ReportInfosSynchro(Int32 Article, Core.Temp._action_information_synchro action)
        {
            Context.Post(state =>
            {
                string art_ref = new Model.Local.ArticleRepository().ReadArticleProgress(Article).Art_Ref;
                switch (action)
                {
                case PRESTACONNECT.Core.Temp._action_information_synchro.debut:
                    this.listBoxReference.Items.Add(art_ref);
                    break;

                case PRESTACONNECT.Core.Temp._action_information_synchro.fin:
                    this.listBoxReference.Items.Remove(art_ref);
                    break;

                default:
                    break;
                }
            }, null);
        }
        public ImportPrestashopArticle(bool forceImportProduct)
        {
            this.InitializeComponent();
            Model.Prestashop.PsProductRepository PsProductRepository = new Model.Prestashop.PsProductRepository();
            List <UInt32> ListPsProduct = PsProductRepository.ListId(Core.Global.CurrentShop.IDShop);

            if (!forceImportProduct)
            {
                Model.Local.ArticleRepository ArticleRepository = new Model.Local.ArticleRepository();
                List <Int32> listlocal = ArticleRepository.ListPrestashop();
                ListPsProduct = ListPsProduct.Where(ps => !listlocal.Contains((int)ps)).ToList();
            }

            this.ListCount = ListPsProduct.Count;
            this.Context   = SynchronizationContext.Current;
            this.ParallelOptions.MaxDegreeOfParallelism = MaximumThreadCount;
            this.ReportProgress(0);
            Task.Factory.StartNew(() =>
            {
                Parallel.ForEach(ListPsProduct, this.ParallelOptions, Sync);
            });
        }
Пример #18
0
        public TransfertArticleDocument(List <Int32> ListArticle = null)
        {
            this.InitializeComponent();
            if (ListArticle == null)
            {
                Model.Local.ArticleRepository ArticleRepository = new Model.Local.ArticleRepository();
                ListArticle = ArticleRepository.ListIdSync(true);
            }

            Model.Local.AttachmentRepository AttachmentRepository = new Model.Local.AttachmentRepository();
            List <int> listarticlewithdoctosync = AttachmentRepository.ListIDArticleNotSync();

            ListArticle = ListArticle.Where(a => listarticlewithdoctosync.Contains(a)).ToList();

            this.ListCount = ListArticle.Count;
            Context        = SynchronizationContext.Current;
            this.ParallelOptions.MaxDegreeOfParallelism = MaximumThreadCount;
            this.ReportProgress(0);
            Task.Factory.StartNew(() =>
            {
                Parallel.ForEach(ListArticle, this.ParallelOptions, Sync);
            });
        }
        public SynchronisationCatalogueInfoLibre()
        {
            this.InitializeComponent();
            this.worker.WorkerReportsProgress = true;

            // Insérez le code requis pour la création d’objet sous ce point.this.worker.WorkerReportsProgress = true;
            this.worker.DoWork += delegate(object s, DoWorkEventArgs args)
            {
                Model.Local.ArticleRepository ArticleRepository = new Model.Local.ArticleRepository();
                List <Int32> ListArticle = ArticleRepository.ListIdSync(true);

                foreach (Int32 Article in ListArticle)
                {
                    Core.Import.ImportCatalogueInfoLibre Sync = new Core.Import.ImportCatalogueInfoLibre();
                    Sync.Exec(Article);
                    lock (this)
                    {
                        this.CurrentCount += 1;
                    }
                    this.worker.ReportProgress((this.CurrentCount * 100 / ListArticle.Count));
                }
            };

            this.worker.ProgressChanged += delegate(object s, ProgressChangedEventArgs args)
            {
                this.ProgressBarStock.Value   = args.ProgressPercentage;
                this.LabelInformation.Content = "Informations : " + args.ProgressPercentage + " %";
            };

            this.worker.RunWorkerCompleted += delegate(object s, RunWorkerCompletedEventArgs args)
            {
                this.Close();
            };

            // Insérez le code requis pour la création d’objet sous ce point.
            this.worker.RunWorkerAsync();
        }
        private void LoadWorker_DoWork(object sender, DoWorkEventArgs e)
        {
            List <int> ArticleIds = new Model.Local.ArticleRepository().ListIdSync(true);

            if (ArticleIds != null)
            {
                Core.Transfert.TransfertArticleImage sync = new Core.Transfert.TransfertArticleImage();

                if (!Core.Global.GetConfig().ConfigImageSynchroPositionLegende)
                {
                    Model.Local.ArticleImageRepository ArticleImageRepository = new Model.Local.ArticleImageRepository();
                    List <int> listarticlewithimagetosync = ArticleImageRepository.ListIDArticleNotSync();
                    ArticleIds = ArticleIds.Where(a => listarticlewithimagetosync.Contains(a)).ToList();
                }

                int count = ArticleIds.Count;

                for (int i = 0; i < count; i++)
                {
                    sync.Exec(ArticleIds[i]);
                    LoadWorker.ReportProgress((((i + 1) * 100) / count));
                }
            }
        }
Пример #21
0
        public void Sync(Int32 ArticleSend)
        {
            this.Semaphore.WaitOne();

            ReportInfosSynchro(ArticleSend, Core.Temp._action_information_synchro.debut);

            List <string> log = new List <string>();

            try
            {
                Model.Local.ArticleRepository ArticleRepository = new Model.Local.ArticleRepository();

                Model.Prestashop.PsProductRepository PsProductRepository;
                Model.Prestashop.PsProduct           PsProduct;

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

                int sag_id = Article.Sag_Id;
                Model.Sage.F_ARTICLERepository F_ARTICLERepository = new Model.Sage.F_ARTICLERepository();
                if (!F_ARTICLERepository.ExistArticle(Article.Sag_Id) &&
                    Article.TypeArticle == Model.Local.Article.enum_TypeArticle.ArticleComposition &&
                    Article.CompositionArticle != null && Article.CompositionArticle.Count > 0)
                {
                    sag_id = (from Table in Article.CompositionArticle
                              orderby Table.ComArt_Default descending
                              select Table.ComArt_F_ARTICLE_SagId).FirstOrDefault();
                }

                Boolean check_attributes = ((Article.TypeArticle == Model.Local.Article.enum_TypeArticle.ArticleMonoGamme || Article.TypeArticle == Model.Local.Article.enum_TypeArticle.ArticleMultiGammes) &&
                                            Article.AttributeArticle != null && Article.AttributeArticle.Count > 0);

                Boolean check_composition = (Article.TypeArticle == Model.Local.Article.enum_TypeArticle.ArticleComposition &&
                                             Article.CompositionArticle != null && Article.CompositionArticle.Count > 0);

                if (F_ARTICLERepository.ExistArticle(sag_id))
                {
                    Model.Sage.F_ARTICLE F_ARTICLE = F_ARTICLERepository.ReadArticle(sag_id);

                    bool importsagefilterexclusion = Core.Tools.FiltreImportSage.ImportSageFilterExclude(F_ARTICLE);
                    // si on affiche pas les sommeil et que article en sommeil = True
                    // si on affiche pas les non publie et que article non publie = True
                    // si affiche sommeil ou non publie = False
                    if (Article.Art_Active && ((!Sommeil && F_ARTICLE.AR_Sommeil == 1) || (!NonPublie && F_ARTICLE.AR_Publie == 0) || importsagefilterexclusion))
                    {
                        Article.Art_Active = false;
                        if (Article.Pre_Id != null)
                        {
                            PsProductRepository = new Model.Prestashop.PsProductRepository();
                            if (PsProductRepository.ExistId((uint)Article.Pre_Id))
                            {
                                PsProduct        = PsProductRepository.ReadId((uint)Article.Pre_Id);
                                PsProduct.Active = 0;
                                PsProductRepository.Save();

                                //<JG> 23/01/2014 ajout modif sur PsProductShop
                                Model.Prestashop.PsProductShopRepository PsProductShopRepository = new Model.Prestashop.PsProductShopRepository();
                                if (PsProductShopRepository.ExistProductShop(PsProduct.IDProduct, Core.Global.CurrentShop.IDShop))
                                {
                                    Model.Prestashop.PsProductShop PsProductShop = PsProductShopRepository.ReadProductShop(PsProduct.IDProduct, Core.Global.CurrentShop.IDShop);
                                    PsProductShop.Active = PsProduct.Active;
                                    PsProductShopRepository.Save();
                                }
                            }
                        }
                        ArticleRepository.Save();

                        log.Add("SA10- Passage à l'état \"Inactif\" pour l'article [ " + Article.Art_Ref + " - " + Article.Art_Name + " ]" + (importsagefilterexclusion ? "(filtre d'exclusion)" : string.Empty));
                    }
                    else if (Article.Art_Active == false && ((F_ARTICLE.AR_Sommeil == 0 || Sommeil) && (F_ARTICLE.AR_Publie == 1 || NonPublie) && !importsagefilterexclusion))
                    {
                        Article.Art_Active = true;
                        if (Article.Pre_Id != null)
                        {
                            PsProductRepository = new Model.Prestashop.PsProductRepository();
                            if (PsProductRepository.ExistId((uint)Article.Pre_Id))
                            {
                                PsProduct        = PsProductRepository.ReadId((uint)Article.Pre_Id);
                                PsProduct.Active = 1;
                                PsProductRepository.Save();

                                //<JG> 23/01/2014 ajout modif sur PsProductShop
                                Model.Prestashop.PsProductShopRepository PsProductShopRepository = new Model.Prestashop.PsProductShopRepository();
                                if (PsProductShopRepository.ExistProductShop(PsProduct.IDProduct, Core.Global.CurrentShop.IDShop))
                                {
                                    Model.Prestashop.PsProductShop PsProductShop = PsProductShopRepository.ReadProductShop(PsProduct.IDProduct, Core.Global.CurrentShop.IDShop);
                                    PsProductShop.Active = PsProduct.Active;
                                    PsProductShopRepository.Save();
                                }
                            }
                        }
                        ArticleRepository.Save();

                        log.Add("SA11- Passage à l'état \"Actif\" pour l'article [ " + Article.Art_Ref + " - " + Article.Art_Name + " ]");
                    }

                    Boolean ExistAECAttributeStatut = Core.Global.ExistAECAttributeStatut();
                    // 09/12/2016 si le module de désactivation des gammes est installé
                    if (ExistAECAttributeStatut)
                    {
                        if (check_attributes)
                        {
                            Core.ImportSage.ImportArticle ImportArticle = new Core.ImportSage.ImportArticle();
                            bool onlyattributestatut = true;
                            // gestion statuts en local
                            ImportArticle.ExecAttribute(F_ARTICLE, Article, onlyattributestatut);

                            // gestion statuts dans PrestaShop
                            Model.Local.AttributeArticleRepository AttributeArticleRepository = new Model.Local.AttributeArticleRepository();
                            List <Model.Local.AttributeArticle>    ListAttributeArticle       = AttributeArticleRepository.ListArticle(Article.Art_Id);
                            int cpt = 0;
                            foreach (Model.Local.AttributeArticle AttributeArticle in ListAttributeArticle)
                            {
                                cpt++;
                                if (AttributeArticle.Pre_Id != null)
                                {
                                    string combination;
                                    if (CheckStatutProductAttribute((uint)AttributeArticle.Pre_Id, (sbyte)(AttributeArticle.AttArt_Active ? 1 : 0), out combination))
                                    {
                                        log.Add("SA51- " + "Référence : " + Article.Art_Ref + " / "
                                                + (AttributeArticle.AttArt_Active ? "Activation" : "Désactivation")
                                                + " déclinaison [" + combination + "] dans Prestashop ");
                                    }
                                }
                                ReportInfosSynchro(ArticleSend, Core.Temp._action_information_synchro.refresh, "Déclinaison : " + cpt + "/" + ListAttributeArticle.Count);
                            }
                        }
                        else if (check_composition)
                        {
                            List <Model.Sage.F_ARTICLE_Composition>  list_temp_filtre             = new List <Model.Sage.F_ARTICLE_Composition>();
                            Model.Local.CompositionArticleRepository CompositionArticleRepository = new Model.Local.CompositionArticleRepository();
                            List <Model.Local.CompositionArticle>    ListCompositionArticle       = CompositionArticleRepository.ListArticle(Article.Art_Id);
                            int cpt = 0;
                            foreach (Model.Local.CompositionArticle compo in ListCompositionArticle)
                            {
                                cpt++;
                                List <Model.Sage.F_ARTICLE_Composition> list_temp             = new List <Model.Sage.F_ARTICLE_Composition>();
                                Model.Sage.F_ARTICLE_Composition        F_ARTICLE_Composition = compo.F_ARTICLE_Composition;
                                list_temp.Add(F_ARTICLE_Composition);

                                list_temp = Core.Tools.FiltreImportSage.ImportSageFilter(list_temp);
                                bool filter_exclusion = (list_temp.Count == 0);

                                bool enable = compo.ComArt_Active;
                                if (compo.ComArt_F_ARTENUMREF_SagId == null && compo.ComArt_F_CONDITION_SagId == null)
                                {
                                    enable = ((F_ARTICLE_Composition.AR_Sommeil == 0 || Sommeil) && (F_ARTICLE_Composition.AR_Publie == 1 || NonPublie) && !filter_exclusion);
                                }
                                else if (compo.ComArt_F_ARTENUMREF_SagId != null)
                                {
                                    Model.Sage.F_ARTENUMREF F_ARTENUMREF = compo.EnumereF_ARTENUMREF;
                                                                        #if (SAGE_VERSION_16 || SAGE_VERSION_17)
                                    enable = ((F_ARTICLE_Composition.AR_Sommeil == 0 || Sommeil) && (F_ARTICLE_Composition.AR_Publie == 1 || NonPublie) && !filter_exclusion &&
                                              (Sommeil));
                                                                        #else
                                    enable = ((F_ARTICLE_Composition.AR_Sommeil == 0 || Sommeil) && (F_ARTICLE_Composition.AR_Publie == 1 || NonPublie) && !filter_exclusion &&
                                              ((F_ARTENUMREF.AE_Sommeil != null && F_ARTENUMREF.AE_Sommeil == 0) || Sommeil));
                                                                        #endif
                                }

                                if (enable != compo.ComArt_Active)
                                {
                                    // gestion statut local
                                    compo.ComArt_Active = enable;
                                    CompositionArticleRepository.Save();
                                }
                                // gestion statut PrestaShop
                                if (compo.Pre_Id != null)
                                {
                                    string combination;
                                    if (CheckStatutProductAttribute((uint)compo.Pre_Id, (sbyte)(compo.ComArt_Active ? 1 : 0), out combination))
                                    {
                                        log.Add("SA51- " + "Composition : " + Article.Art_Name + " / "
                                                + (compo.ComArt_Active ? "Activation" : "Désactivation")
                                                + " déclinaison [" + combination + "] dans Prestashop ");
                                    }
                                }
                                ReportInfosSynchro(ArticleSend, Core.Temp._action_information_synchro.refresh, "Déclinaison : " + cpt + "/" + ListCompositionArticle.Count);
                            }
                        }
                    }
                }
                else if (Article.Art_Active || Article.Art_Sync)
                {
                    Article.Art_Active = false;
                    Article.Art_Sync   = false;
                    if (Article.Pre_Id != null)
                    {
                        PsProductRepository = new Model.Prestashop.PsProductRepository();
                        if (PsProductRepository.ExistId((uint)Article.Pre_Id))
                        {
                            PsProduct        = PsProductRepository.ReadId((uint)Article.Pre_Id);
                            PsProduct.Active = 0;
                            PsProductRepository.Save();

                            //<JG> 23/01/2014 ajout modif sur PsProductShop
                            Model.Prestashop.PsProductShopRepository PsProductShopRepository = new Model.Prestashop.PsProductShopRepository();
                            if (PsProductShopRepository.ExistProductShop(PsProduct.IDProduct, Core.Global.CurrentShop.IDShop))
                            {
                                Model.Prestashop.PsProductShop PsProductShop = PsProductShopRepository.ReadProductShop(PsProduct.IDProduct, Core.Global.CurrentShop.IDShop);
                                PsProductShop.Active = PsProduct.Active;
                                PsProductShopRepository.Save();
                            }
                        }
                    }
                    ArticleRepository.Save();

                    log.Add("SA12- Article Sage introuvable désactivation complète de l'article [ " + Article.Art_Ref + " - " + Article.Art_Name + " ]");
                }
            }
            catch (Exception ex)
            {
                log.Add("SA01- Gestion statut article : " + ex.Message);
            }

            if (log.Count > 0)
            {
                log.Add(Core.Log.LogLineSeparator);
                lock (this.logs)
                    logs.AddRange(log);
            }

            lock (this)
            {
                this.CurrentCount += 1;
            }
            ReportInfosSynchro(ArticleSend, Core.Temp._action_information_synchro.fin);
            this.ReportProgress(this.CurrentCount * 100 / this.ListCount);
            this.Semaphore.Release();
        }
Пример #22
0
        public void Sync(int IdArticle)
        {
            this.Semaphore.WaitOne();

            try
            {
                Model.Sage.F_ARTICLEMEDIARepository F_ARTICLEMEDIARepository = new Model.Sage.F_ARTICLEMEDIARepository();
                Model.Local.ArticleRepository       ArticleRepository        = new Model.Local.ArticleRepository();
                Model.Local.Article Article = new Model.Local.Article();
                if (ArticleRepository.ExistArticle(IdArticle))
                {
                    Article = ArticleRepository.ReadArticle(IdArticle);

                    // <JG> 24/03/2015 ajout option suppression auto
                    if (Core.Global.GetConfig().ImportMediaAutoDeleteAttachment)
                    {
                        Model.Local.AttachmentRepository AttachmentRepository = new Model.Local.AttachmentRepository();
                        if (AttachmentRepository.ExistArticle(IdArticle))
                        {
                            List <Model.Local.Attachment> ListArticle = AttachmentRepository.ListArticle(IdArticle);
                            ListArticle = ListArticle.Where(at => at.Sag_Id != null).ToList();

                            foreach (Model.Local.Attachment Attachment in ListArticle)
                            {
                                if (!F_ARTICLEMEDIARepository.Exist(Attachment.Sag_Id.Value))
                                {
                                    if (System.IO.File.Exists(System.IO.Path.Combine(Core.Global.GetConfig().Folders.RootAttachment, Attachment.Att_File)))
                                    {
                                        File.Delete(System.IO.Path.Combine(Core.Global.GetConfig().Folders.RootAttachment, Attachment.Att_File));
                                    }

                                    if (Attachment.Pre_Id != null && Attachment.Pre_Id > 0)
                                    {
                                        // Suppression de l'occurence du document sur prestashop
                                        Model.Prestashop.PsAttachmentRepository        psAttachmentRepository        = new Model.Prestashop.PsAttachmentRepository();
                                        Model.Prestashop.PsAttachmentLangRepository    psAttachmentLangRepository    = new Model.Prestashop.PsAttachmentLangRepository();
                                        Model.Prestashop.PsProductAttachmentRepository psProductAttachmentRepository = new Model.Prestashop.PsProductAttachmentRepository();

                                        Model.Prestashop.PsAttachment psAttachment = psAttachmentRepository.ReadAttachment(Convert.ToUInt32(Attachment.Pre_Id.Value));

                                        string distant_file = string.Empty;
                                        if (psAttachment != null)
                                        {
                                            distant_file = psAttachment.File;
                                            psProductAttachmentRepository.Delete(psProductAttachmentRepository.ListAttachment(psAttachment.IDAttachment));
                                            psAttachmentLangRepository.Delete(psAttachmentLangRepository.ListAttachment(psAttachment.IDAttachment));
                                            psAttachmentRepository.Delete(psAttachment);
                                        }

                                        if (Core.Global.GetConfig().ConfigFTPActive)
                                        {
                                            String FTP      = Core.Global.GetConfig().ConfigFTPIP;
                                            String User     = Core.Global.GetConfig().ConfigFTPUser;
                                            String Password = Core.Global.GetConfig().ConfigFTPPassword;

                                            string ftpfullpath = FTP + "/download/" + distant_file;

                                            if (Core.Ftp.ExistFile(ftpfullpath, User, Password))
                                            {
                                                try
                                                {
                                                    System.Net.FtpWebRequest request = (System.Net.FtpWebRequest)System.Net.FtpWebRequest.Create(ftpfullpath);
                                                    request.Credentials = new System.Net.NetworkCredential(User, Password);
                                                    request.Method      = System.Net.WebRequestMethods.Ftp.DeleteFile;
                                                    request.UseBinary   = true;
                                                    request.UsePassive  = true;
                                                    request.KeepAlive   = false;

                                                    System.Net.FtpWebResponse response = (System.Net.FtpWebResponse)request.GetResponse();
                                                    response.Close();
                                                }
                                                catch (Exception ex) { Core.Error.SendMailError(ex.ToString()); }
                                            }
                                        }
                                    }

                                    AttachmentRepository.Delete(Attachment);
                                }
                            }
                        }
                    }

                    if (F_ARTICLEMEDIARepository.ExistReference(Article.Art_Ref))
                    {
                        foreach (Model.Sage.F_ARTICLEMEDIA F_ARTICLEMEDIA in F_ARTICLEMEDIARepository.ListReference(Article.Art_Ref))
                        {
                            String File = (System.IO.File.Exists(F_ARTICLEMEDIA.ME_Fichier))
                                        ? F_ARTICLEMEDIA.ME_Fichier
                                        : Path.Combine(DirDoc, F_ARTICLEMEDIA.ME_Fichier.Substring(2));
                            if (System.IO.File.Exists(File))
                            {
                                string extension = Path.GetExtension(File).ToLower();
                                string filename  = Path.GetFileNameWithoutExtension(File);
                                Model.Local.MediaAssignmentRuleRepository MediaAssignmentRuleRepository = new Model.Local.MediaAssignmentRuleRepository();
                                List <Model.Local.MediaAssignmentRule>    list = MediaAssignmentRuleRepository.List();
                                if (list.Count(r => filename.EndsWith(r.SuffixText)) > 0)
                                {
                                    foreach (Model.Local.MediaAssignmentRule mediarule in list.Where(r => filename.EndsWith(r.SuffixText)))
                                    {
                                        if (filename.EndsWith(mediarule.SuffixText))
                                        {
                                            switch (mediarule.Rule)
                                            {
                                            case (short)Core.Parametres.MediaRule.AsAttachment:
                                                Core.ImportSage.ImportArticleDocument Sync = new Core.ImportSage.ImportArticleDocument();
                                                Sync.Exec(File, Article.Art_Id, (!string.IsNullOrEmpty(mediarule.AssignName) ? mediarule.AssignName : F_ARTICLEMEDIA.ME_Commentaire), null, F_ARTICLEMEDIA.cbMarq);
                                                break;

                                            case (short)Core.Parametres.MediaRule.AsPicture:
                                                if (Core.Img.imageExtensions.Contains(extension))
                                                {
                                                    int position, AttributeArticle;
                                                    Core.Global.SearchReference(filename, out position, out AttributeArticle);
                                                    Core.ImportSage.ImportArticleImage ImportImage = new Core.ImportSage.ImportArticleImage();
                                                    ImportImage.Exec(File, Article.Art_Id, position, AttributeArticle);
                                                }
                                                break;
                                            }
                                        }
                                    }
                                }
                                else
                                {
                                    if (Core.Img.imageExtensions.Contains(extension))
                                    {
                                        if (Core.Global.GetConfig().ImportMediaIncludePictures)
                                        {
                                            int position, AttributeArticle;
                                            Core.Global.SearchReference(filename, out position, out AttributeArticle);
                                            Core.ImportSage.ImportArticleImage ImportImage = new Core.ImportSage.ImportArticleImage();
                                            ImportImage.Exec(File, Article.Art_Id, position, AttributeArticle);
                                        }
                                    }
                                    else
                                    {
                                        Core.ImportSage.ImportArticleDocument Sync = new Core.ImportSage.ImportArticleDocument();
                                        Sync.Exec(File, Article.Art_Id, F_ARTICLEMEDIA.ME_Commentaire, null, F_ARTICLEMEDIA.cbMarq);
                                    }
                                }
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Core.Error.SendMailError("[IM] " + ex.ToString());
            }
            lock (this)
            {
                this.CurrentCount += 1;
            }
            this.ReportProgress(this.CurrentCount * 100 / this.ListCount);
            this.Semaphore.Release();
        }
Пример #23
0
        private void LoadWorker_DoWork(object sender, DoWorkEventArgs e)
        {
            // parcours des données Sage
            if (Core.Global.GetConfig().ImportImageUseSageDatas)
            {
                Model.Sage.F_ARTICLERepository    F_ARTICLERepository = new Model.Sage.F_ARTICLERepository();
                List <Model.Sage.F_ARTICLE_Photo> ListPhoto           = F_ARTICLERepository.ListPhoto();

                Model.Local.ArticleRepository ArticleRepository = new Model.Local.ArticleRepository();
                List <int> ListSageLocal = ArticleRepository.ListSageId();

                ListPhoto = ListPhoto.Where(ap => ListSageLocal.Contains(ap.cbMarq)).ToList();

                ListCount    = ListPhoto.Count;
                CurrentCount = 0;

                foreach (Model.Sage.F_ARTICLE_Photo F_ARTICLE_Photo in ListPhoto)
                {
                    string file = null;
                    if (!string.IsNullOrWhiteSpace(F_ARTICLE_Photo.AC_Photo))
                    {
                        file = System.IO.Path.Combine(Core.Global.GetConfig().AutomaticImportFolderPicture, F_ARTICLE_Photo.AC_Photo);
                    }
                    else if (!string.IsNullOrWhiteSpace(F_ARTICLE_Photo.AR_Photo))
                    {
                        file = System.IO.Path.Combine(Core.Global.GetConfig().AutomaticImportFolderPicture, F_ARTICLE_Photo.AR_Photo);
                    }
                    if (file != null && System.IO.File.Exists(file))
                    {
                        Model.Local.Article Article = ArticleRepository.ReadSag_Id(F_ARTICLE_Photo.cbMarq);
                        String extension            = Path.GetExtension(file).ToLower();
                        if (Core.Img.imageExtensions.Contains(extension))
                        {
                            Core.ImportSage.ImportArticleImage import = new Core.ImportSage.ImportArticleImage();
                            import.Exec(file, Article.Art_Id);
                            if (import.logs != null && import.logs.Count > 0)
                            {
                                lock (this.Logs)
                                {
                                    Logs.AddRange(import.logs);
                                }
                            }
                            lock (this)
                            {
                                this.CurrentCount += 1;
                                LoadWorker.ReportProgress(this.CurrentCount * 100 / this.ListCount);
                            }
                        }
                    }
                }
            }
            // fonction par défaut = parcours dossier local ou réseau
            else
            {
                String[] Files = System.IO.Directory.GetFiles(this.DirImg);
                this.ListCount = Files.Length;

                foreach (string file in Files)
                {
                    exec(file);
                    lock (this)
                    {
                        this.CurrentCount += 1;
                        LoadWorker.ReportProgress(this.CurrentCount * 100 / this.ListCount);
                    }
                }
            }
        }
        public void Sync(Int32 id)
        {
            this.Semaphore.WaitOne();

            List <string> log = new List <string>();

            Model.Local.ArticleRepository ArticleRepository = new Model.Local.ArticleRepository();
            Model.Local.Article           ArticleCompo      = ArticleRepository.ReadArticle(id);
            if (ArticleCompo != null)
            {
                Model.Local.CompositionArticleRepository CompositionArticleRepository = new Model.Local.CompositionArticleRepository();
                List <Model.Local.CompositionArticle>    ListCompo = CompositionArticleRepository.ListArticle(ArticleCompo.Art_Id);
                if (ListCompo.Count > 0)
                {
                    Model.Local.CompositionArticle CompoDefaut = ListCompo.FirstOrDefault(c => c.ComArt_Default);
                    if (CompoDefaut == null || CompoDefaut.ComArt_Id == 0)
                    {
                        CompoDefaut = ListCompo.First();
                    }
                    // Si toutes les compos sont liées à la même réference Sage
                    // ET qu'elles sont toutes liées à une gamme ou un conditionnement
                    if (ListCompo.Count == ListCompo.Count(c => c.ComArt_F_ARTICLE_SagId == CompoDefaut.ComArt_F_ARTICLE_SagId &&
                                                           (c.ComArt_F_ARTENUMREF_SagId != null)))// ^ c.ComArt_F_CONDITION_SagId != null)))
                    {
                        // on récupère la liste des énumérés de l'article Sage
                        Model.Sage.F_ARTICLERepository          F_ARTICLERepository       = new Model.Sage.F_ARTICLERepository();
                        List <Model.Sage.F_ARTICLE_Composition> ListF_ARTICLE_Composition = F_ARTICLERepository.ListComposition(CompoDefaut.F_ARTICLE_Light.AR_Ref);
                        // si on n'affiche pas les données en sommeil alors on filtre les gammes
                        if (!Core.Global.GetConfig().ArticleEnSommeil)
                        {
                            ListF_ARTICLE_Composition = ListF_ARTICLE_Composition.Where(c => c.AE_Sommeil == 0).ToList();
                        }
                        ListF_ARTICLE_Composition = Core.Tools.FiltreImportSage.ImportSageFilter(ListF_ARTICLE_Composition);
                        // on filtre sur ceux déjà présents dans les compos
                        List <Int32?> listidsagecompo = new List <Int32?>();
                        if (CompoDefaut.ComArt_F_ARTENUMREF_SagId != null)
                        {
                            listidsagecompo           = ListCompo.Select(c => c.ComArt_F_ARTENUMREF_SagId).ToList();
                            ListF_ARTICLE_Composition = ListF_ARTICLE_Composition.Where(c => !listidsagecompo.Contains(c.F_ARTENUMREF_SagId) && !string.IsNullOrWhiteSpace(c.EnumereGamme1)).ToList();
                        }
                        //else if (CompoDefaut.ComArt_F_CONDITION_SagId != null)
                        //{
                        //    listidsagecompo = ListCompo.Select(c => c.ComArt_F_CONDITION_SagId).ToList();
                        //    ListF_ARTICLE_Composition = ListF_ARTICLE_Composition.Where(c => !listidsagecompo.Contains(c.F_CONDITION_SagId)).ToList();
                        //}

                        // si on a une déclinaison à créer
                        if (ListF_ARTICLE_Composition.Count > 0)
                        {
                            // on identifie le groupe d'attribut Prestashop
                            // fonctionne uniquement pour les articles mono-gamme
                            Model.Prestashop.PsAttributeGroupLangRepository PsAttributeGroupLangRepository = new Model.Prestashop.PsAttributeGroupLangRepository();
                            Model.Prestashop.PsAttributeGroupLang           PsAttributeGroupLang           = null;
                            if (ArticleCompo.CompositionArticleAttributeGroup != null && ArticleCompo.CompositionArticleAttributeGroup.Count == 1)
                            {
                                Model.Local.CompositionArticleAttributeGroup CAAG = ArticleCompo.CompositionArticleAttributeGroup.First();
                                if (PsAttributeGroupLangRepository.ExistAttributeGroupLang((uint)CAAG.Cag_AttributeGroup_PreId, Core.Global.Lang))
                                {
                                    PsAttributeGroupLang = PsAttributeGroupLangRepository.ReadAttributeGroupLang((uint)CAAG.Cag_AttributeGroup_PreId, Core.Global.Lang);
                                }
                            }

                            if (PsAttributeGroupLang != null)
                            {
                                foreach (Model.Sage.F_ARTICLE_Composition F_ARTICLE_Composition in ListF_ARTICLE_Composition)
                                {
                                    // création de la composition dans l'article Prestaconnect
                                    Model.Local.CompositionArticle CompositionArticle = new Model.Local.CompositionArticle()
                                    {
                                        ComArt_Active             = false,
                                        ComArt_ArtId              = ArticleCompo.Art_Id,
                                        ComArt_F_ARTICLE_SagId    = F_ARTICLE_Composition.cbMarq,
                                        ComArt_F_ARTENUMREF_SagId = F_ARTICLE_Composition.F_ARTENUMREF_SagId,
                                        ComArt_F_CONDITION_SagId  = F_ARTICLE_Composition.F_CONDITION_SagId,
                                        ComArt_Quantity           = 1,
                                        ComArt_Sync    = true,
                                        ComArt_Default = false,
                                        HasUpdated     = false,
                                    };
                                    CompositionArticleRepository.Add(CompositionArticle);
                                    log.Add("ICG10- Import auto déclinaison gamme [ " + CompoDefaut.F_ARTICLE_Light.AR_Ref + " / " + F_ARTICLE_Composition.EnumereGamme1 + " ] pour la composition : " + ArticleCompo.Art_Name + "");

                                    // création et affectation automatique des attributs
                                    Model.Prestashop.PsAttributeLang           PsAttributeLang           = null;
                                    Model.Prestashop.PsAttributeLangRepository PsAttributeLangRepository = new Model.Prestashop.PsAttributeLangRepository();

                                    lock (Core.Temp.ListAttributeGroupLocked)
                                    {
                                        // ajout de la gestion d'une liste de locked attribute group au moment de la création pour éviter les doublons //
                                        while (Core.Temp.ListAttributeGroupLocked.Contains(PsAttributeGroupLang.IDAttributeGroup))
                                        {
                                            System.Threading.Thread.Sleep(20);
                                        }

                                        Core.Temp.ListAttributeGroupLocked.Add(PsAttributeGroupLang.IDAttributeGroup);

                                        if (PsAttributeLangRepository.ExistAttributeLang(F_ARTICLE_Composition.EnumereGamme1.Trim(), Core.Global.Lang, PsAttributeGroupLang.IDAttributeGroup))
                                        {
                                            PsAttributeLang = PsAttributeLangRepository.ReadAttributeLang(F_ARTICLE_Composition.EnumereGamme1.Trim(), Core.Global.Lang, PsAttributeGroupLang.IDAttributeGroup);
                                        }
                                        else
                                        {
                                            Model.Prestashop.PsAttributeRepository PsAttributeRepository = new Model.Prestashop.PsAttributeRepository();
                                            Model.Prestashop.PsAttribute           PsAttribute           = new Model.Prestashop.PsAttribute()
                                            {
                                                IDAttributeGroup = PsAttributeGroupLang.IDAttributeGroup,
                                                Color            = string.Empty,
                                                Position         = PsAttributeRepository.NextPosition(),
                                            };
                                            PsAttributeRepository.Add(PsAttribute, Core.Global.CurrentShop.IDShop);

                                            foreach (Model.Prestashop.PsLang PsLang in new Model.Prestashop.PsLangRepository().ListActive(1, Core.Global.CurrentShop.IDShop))
                                            {
                                                if (!PsAttributeLangRepository.ExistAttributeLang(PsAttribute.IDAttribute, PsLang.IDLang))
                                                {
                                                    PsAttributeLangRepository.Add(new Model.Prestashop.PsAttributeLang()
                                                    {
                                                        IDAttribute = PsAttribute.IDAttribute,
                                                        IDLang      = PsLang.IDLang,
                                                        Name        = F_ARTICLE_Composition.EnumereGamme1.Trim(),
                                                    });
                                                }
                                            }

                                            PsAttributeLang = PsAttributeLangRepository.ReadAttributeLang(PsAttribute.IDAttribute, Core.Global.Lang);
                                        }

                                        Core.Temp.ListAttributeGroupLocked.Remove(PsAttributeGroupLang.IDAttributeGroup);
                                    }

                                    if (PsAttributeLang != null)
                                    {
                                        // affectation composition
                                        if (CompositionArticle.CompositionArticleAttribute.Count(ag => ag.Caa_AttributeGroup_PreId == (int)PsAttributeGroupLang.IDAttributeGroup) == 0)
                                        {
                                            CompositionArticle.CompositionArticleAttribute.Add(new Model.Local.CompositionArticleAttribute()
                                            {
                                                Caa_ComArtId             = CompositionArticle.ComArt_ArtId,
                                                Caa_AttributeGroup_PreId = (int)PsAttributeGroupLang.IDAttributeGroup,
                                                Caa_Attribute_PreId      = (int)PsAttributeLang.IDAttribute,
                                            });
                                        }
                                        else
                                        {
                                            Model.Local.CompositionArticleAttribute CompositionArticleAttribute = CompositionArticle.CompositionArticleAttribute.First(ag => ag.Caa_AttributeGroup_PreId == (int)PsAttributeGroupLang.IDAttributeGroup);
                                            CompositionArticleAttribute.Caa_Attribute_PreId = (int)PsAttributeLang.IDAttribute;
                                        }

                                        // si on a pu affecter l'attribut alors on active la déclinaison
                                        CompositionArticle.ComArt_Active = true;
                                    }

                                    CompositionArticleRepository.Save();

                                    // Marquage maj article compo
                                    ArticleCompo.Art_Date = DateTime.Now;
                                    ArticleRepository.Save();
                                }
                            }
                        }
                    }
                }
            }
            lock (Logs)
            {
                if (log != null && log.Count > 0)
                {
                    Logs.AddRange(log);
                }
                this.CurrentCount += 1;
            }
            this.ReportProgress(this.CurrentCount * 100 / this.ListCount);
            this.Semaphore.Release();
        }
        private void SearchArticle()
        {
            Model.Local.ArticleRepository ArticleRepository  = new Model.Local.ArticleRepository();
            List <Model.Local.Article>    ListArticleDisplay = new List <Model.Local.Article>();

            Model.Local.Catalog Catalog = this.DataGridCatalogue.SelectedItem as Model.Local.Catalog;
            if (Catalog != null && this.CheckBoxSearchOnlyCatalog.IsChecked == true)
            {
                this.ListArticle = ArticleRepository.ListCatalog(Catalog.Cat_Id);
                Model.Local.ArticleCatalogRepository ArticleCatalogRepository = new Model.Local.ArticleCatalogRepository();
                List <Model.Local.ArticleCatalog>    ListArticleCatalog       = ArticleCatalogRepository.ListCatalog(Catalog.Cat_Id);
                foreach (Model.Local.ArticleCatalog ArticleCatalog in ListArticleCatalog)
                {
                    Boolean Add = true;
                    foreach (Model.Local.Article Article in ListArticle)
                    {
                        if (Article.Art_Id == ArticleCatalog.Art_Id)
                        {
                            Add = false;
                            break;
                        }
                    }
                    if (Add == true)
                    {
                        this.ListArticle.Add(ArticleCatalog.Article);
                    }
                }
            }
            else
            {
                this.ListArticle = ArticleRepository.List();
            }

            Boolean isArticle;

            foreach (Model.Local.Article Article in this.ListArticle)
            {
                isArticle = true;
                if (this.TextBoxSearchArticleName.Text != "" && this.TextBoxSearchArticleName.Text.Replace("%", "") != "")
                {
                    if (this.TextBoxSearchArticleName.Text.Contains("%"))
                    {
                        if (Article.Art_Name.ToUpper().Contains(this.TextBoxSearchArticleName.Text.Replace("%", "").ToUpper()) == false)
                        {
                            isArticle = false;
                        }
                    }
                    else
                    {
                        if (Article.Art_Name.ToUpper().StartsWith(this.TextBoxSearchArticleName.Text.ToUpper()) == false)
                        {
                            isArticle = false;
                        }
                    }
                }
                if (this.TextBoxSearchArticleEan13.Text != "" && this.TextBoxSearchArticleEan13.Text.Replace("%", "") != "")
                {
                    if (Article.Art_Ean13 != null)
                    {
                        if (this.TextBoxSearchArticleEan13.Text.Contains("%"))
                        {
                            if (Article.Art_Ean13.ToUpper().Contains(this.TextBoxSearchArticleEan13.Text.Replace("%", "").ToUpper()) == false)
                            {
                                isArticle = false;
                            }
                        }
                        else
                        {
                            if (Article.Art_Ean13.ToUpper().StartsWith(this.TextBoxSearchArticleEan13.Text.ToUpper()) == false)
                            {
                                isArticle = false;
                            }
                        }
                    }
                    else
                    {
                        isArticle = false;
                    }
                }
                if (this.TextBoxSearchArticleRef.Text != "" && this.TextBoxSearchArticleRef.Text.Replace("%", "") != "")
                {
                    if (this.TextBoxSearchArticleRef.Text.Contains("%"))
                    {
                        if (Article.Art_Ref.ToUpper().Contains(this.TextBoxSearchArticleRef.Text.Replace("%", "").ToUpper()) == false)
                        {
                            isArticle = false;
                        }
                    }
                    else
                    {
                        if (Article.Art_Ref.ToUpper().StartsWith(this.TextBoxSearchArticleRef.Text.ToUpper()) == false)
                        {
                            isArticle = false;
                        }
                    }
                }

                if (Article.Art_Sync != this.CheckBoxSearchArticleSync.IsChecked)
                {
                    isArticle = false;
                }
                if (Article.Art_Active != this.CheckBoxSearchArticleActif.IsChecked)
                {
                    isArticle = false;
                }
                if (isArticle == true)
                {
                    ListArticleDisplay.Add(Article);
                }
            }
            this.DataGridArticle.ItemsSource = ListArticleDisplay;
        }
        public ReimportArticle(List <Int32> ListArticleSend)
        {
            this.InitializeComponent();
            List <Int32> ListArticle = ListArticleSend;

            if (Core.Global.GetConfig().ReimportUpdateAttribute || Core.Global.GetConfig().ReimportUpdateConditioning)
            {
                List <Model.Local.Article_Light> ListLocal = new Model.Local.ArticleRepository().ListLight();
                List <Int32> ListSagId = ListLocal.Where(l => ListArticleSend.Contains(l.Art_Id)).Select(l => l.Sag_Id).ToList();

                #region TODO TRANSFERT IN STATIC METHOD duplicate from importsagearticle.xaml.cs
                Model.Sage.F_ARTICLERepository    F_ARTICLERepository = new Model.Sage.F_ARTICLERepository();
                List <Model.Sage.F_ARTICLE_Light> ListF_ARTICLE       = F_ARTICLERepository.ListLight();

                ListF_ARTICLE = ListF_ARTICLE.AsParallel().Where(a => ListSagId.Contains(a.cbMarq)).AsParallel().ToList();

                ListF_ARTICLE = Core.Tools.FiltreImportSage.ImportSageFilter(ListF_ARTICLE);

                List <string> list_arref = ListF_ARTICLE.Select(a => a.AR_Ref).ToList();

                // ajout pré-import gammes / conditionnements
                // !!! traitement en parallèle déconseillé !!!
                // occurences d'énumérés pouvant se recouper entre les articles

                if (Core.Global.GetConfig().ReimportUpdateAttribute)
                {
                    List <short?> gammes = new List <short?>();
                    gammes.AddRange(ListF_ARTICLE.Where(a => a.AR_Gamme1 != null && a.AR_Gamme1 != 0).Select(a => a.AR_Gamme1).Distinct());
                    gammes.AddRange(ListF_ARTICLE.Where(a => a.AR_Gamme2 != null && a.AR_Gamme2 != 0).Select(a => a.AR_Gamme2).Distinct());

                    // import gammes
                    ImportSageGamme importsagegamme = new ImportSageGamme(gammes);
                    importsagegamme.ShowDialog();

                    // import énumérés de gammes
                    List <Model.Sage.F_ARTENUMREF> declinaisons = new Model.Sage.F_ARTENUMREFRepository().List().ToList();
                                        #if !(SAGE_VERSION_16 || SAGE_VERSION_17)
                    declinaisons = declinaisons.Where(d => d.AE_Sommeil == 0).ToList();
                                        #endif

                    declinaisons = Core.Tools.FiltreImportSage.ImportSageFilter(declinaisons);

                    List <Model.Sage.F_ARTGAMME> enumeres_gammes = new Model.Sage.F_ARTGAMMERepository().List();
                    List <int> localAttribute = new Model.Local.AttributeRepository().List().Select(a => a.Sag_Id).AsParallel().ToList();
                    enumeres_gammes = enumeres_gammes.AsParallel().Where(e => list_arref.Contains(e.AR_Ref) &&
                                                                         !localAttribute.Contains(e.cbMarq) &&
                                                                         declinaisons.Count(d => d.AG_No1 == e.AG_No || d.AG_No2 == e.AG_No) > 0).ToList();

                    enumeres_gammes = Core.Tools.FiltreImportSage.ImportSageFilter(enumeres_gammes);

                    ImportSageGammeEnumere importsagegammeenumere = new ImportSageGammeEnumere(enumeres_gammes);
                    importsagegammeenumere.ShowDialog();
                }

                // import conditionnements
                if (Core.Global.GetConfig().ReimportUpdateConditioning)
                {
                    if (Core.Global.GetConfig().ArticleImportConditionnementActif)
                    {
                        List <short?>             conditionnements          = ListF_ARTICLE.Where(a => a.AR_Condition != null && a.AR_Condition != 0).Select(a => a.AR_Condition).Distinct().ToList();
                        ImportSageConditionnement importsageconditionnement = new ImportSageConditionnement(conditionnements);
                        importsageconditionnement.ShowDialog();

                        List <Model.Sage.F_CONDITION> enumeres_conditionnement = new Model.Sage.F_CONDITIONRepository().List();
                        List <int> localConditioning = new Model.Local.ConditioningRepository().List().Select(c => c.Sag_Id).AsParallel().ToList();
                        enumeres_conditionnement = enumeres_conditionnement.AsParallel().Where(e => list_arref.Contains(e.AR_Ref) &&
                                                                                               !localConditioning.Contains(e.cbMarq)).ToList();

                        enumeres_conditionnement = Core.Tools.FiltreImportSage.ImportSageFilter(enumeres_conditionnement);

                        ImportSageConditionnementEnumere importsageconditionnementenumere = new ImportSageConditionnementEnumere(enumeres_conditionnement);
                        importsageconditionnementenumere.ShowDialog();
                    }
                }
                // fin
                #endregion
            }

            this.ListCount = ListArticle.Count;
            Context        = SynchronizationContext.Current;
            this.ParallelOptions.MaxDegreeOfParallelism = System.Environment.ProcessorCount;
            this.ReportProgress(0);
            Task.Factory.StartNew(() =>
            {
                Parallel.ForEach(ListArticle, this.ParallelOptions, Sync);
            });
        }