Exemplo n.º 1
0
        /// <summary>
        /// Enregistre les nouvelles données en bases.
        /// </summary>
        /// <param name="NewBrands">Les marques à enregistrer.</param>
        /// <param name="NewFamilies">Les familles à enregistrer.</param>
        /// <param name="NewSubFamilies">Les sous-familles à enregistrer.</param>
        /// <param name="NewArticles">Les articles à enregistrer.</param>
        /// <param name="ChosenNamesakeStrategy">La stratégie de dédoublonnage choisie.</param>
        /// <returns></returns>
        private async Task SaveImportedData(Dictionary <string, Marques> NewBrands,
                                            Dictionary <string, Family> NewFamilies, Dictionary <string, SubFamily> NewSubFamilies,
                                            Dictionary <string, Pair <Articles, Articles> > NewArticles, NamesakeStrategy ChosenNamesakeStrategy)
        {
            StatusText.Text = "Import des données...";

            ImportProgress.Value   = 0;
            ImportProgress.Maximum = NewBrands.Count;
            foreach (var Marques in NewBrands.Values)
            {
                ImportProgress.Value++;
                StatusText.Text = "Import des marques " + ImportProgress.Value + "/" + ImportProgress.Maximum;
                await Task.Run(() => BrandDao.Save(Marques));
            }

            ImportProgress.Value   = 0;
            ImportProgress.Maximum = NewFamilies.Count;
            foreach (var Familles in NewFamilies.Values)
            {
                ImportProgress.Value++;
                StatusText.Text = "Import des familles " + ImportProgress.Value + "/" + ImportProgress.Maximum;
                await Task.Run(() => FamilyDao.Save(Familles));
            }

            ImportProgress.Value   = 0;
            ImportProgress.Maximum = NewSubFamilies.Count;
            foreach (var SousFamille in NewSubFamilies.Values)
            {
                ImportProgress.Value++;
                StatusText.Text = "Import des sous-familles " + ImportProgress.Value + "/" + ImportProgress.Maximum;
                await Task.Run(() => SubFamilyDao.Save(SousFamille));
            }

            ImportProgress.Value   = 0;
            ImportProgress.Maximum = NewArticles.Count;
            foreach (var ArticlePair in NewArticles)
            {
                ImportProgress.Value++;
                StatusText.Text = "Import des articles " + ImportProgress.Value + "/" + ImportProgress.Maximum;
                //pas de doublons
                if (ArticlePair.Value.Second == null)
                {
                    await Task.Run(() => ArticleDao.Create(ArticlePair.Value.First));
                }
                else
                {
                    if (ChosenNamesakeStrategy == NamesakeStrategy.Replace)
                    {
                        await Task.Run(() => ArticleDao.Update(ArticlePair.Value.First));
                    }
                }
            }
        }