Exemplo n.º 1
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);
                    }
                }
            }
        }