Ejemplo n.º 1
0
        /// <summary>
        /// Trouve les doublons entre les données à importer et la base.
        /// </summary>
        /// <param name="ArticlesDtosRead">Les données à importer.</param>
        /// <param name="NewFamilies">Les doublons des familles.</param>
        /// <param name="NewBrands">Les doublons des marques.</param>
        /// <param name="NewSubFamilies">Les doublons des sous-familles.</param>
        /// <returns><c>true</c> si l'import est annulé, <c>false</c> sinon.</returns>
        private bool FindDuplicates(List <ArticlesDto> ArticlesDtosRead, Dictionary <string, Family> NewFamilies,
                                    Dictionary <string, Marques> NewBrands, Dictionary <string, SubFamily> NewSubFamilies)
        {
            var NameSakeErrorBuilder = new StringBuilder();
            int DuplicateFamilyCount = 0, DuplicateBrandCount = 0, DuplicateSubFamilyCount = 0;

            ImportProgress.Maximum = ArticlesDtosRead.Count * 2;
            StatusText.Text        = "Dédoublonnage...";
            ImportProgress.Value   = 0;
            foreach (var ArticlesDto in ArticlesDtosRead)
            {
                ImportProgress.Value += 1;

                var FamilyName = ArticlesDto.FamilyName;
                if (!NewFamilies.ContainsKey(FamilyName))
                {
                    var FamilyNameSake = FamilyDao.GetFamilleByName(FamilyName);
                    if (FamilyNameSake.Count > 0)
                    {
                        DuplicateFamilyCount += FamilyNameSake.Count;
                        NewFamilies.Add(FamilyName, FamilyNameSake[0]);
                    }
                }

                var BrandName = ArticlesDto.BrandName;
                if (!NewBrands.ContainsKey(BrandName))
                {
                    var BrandNameSake = BrandDao.GetBrandByName(BrandName);
                    if (BrandNameSake.Count > 0)
                    {
                        DuplicateBrandCount += BrandNameSake.Count;
                        NewBrands.Add(BrandName, BrandNameSake[0]);
                    }
                }

                var SubFamilyName = ArticlesDto.SubFamilyName;
                if (!NewSubFamilies.ContainsKey(SubFamilyName))
                {
                    var SubFamilyNameSake = SubFamilyDao.GetSubFamiliesByName(SubFamilyName);
                    if (SubFamilyNameSake.Count > 0)
                    {
                        DuplicateSubFamilyCount += SubFamilyNameSake.Count;
                        NewSubFamilies.Add(SubFamilyName, SubFamilyNameSake[0]);
                    }
                }
            }

            NameSakeErrorBuilder.AppendFormat("{0} doublons de familles ont été détéctés.\n", DuplicateFamilyCount);
            NameSakeErrorBuilder.AppendFormat("{0} doublons de sous-familles ont été détéctés.\n", DuplicateSubFamilyCount);
            NameSakeErrorBuilder.AppendFormat("{0} doublons de marques ont été détéctés.\n", DuplicateBrandCount);

            var Error = NameSakeErrorBuilder.ToString();

            if (DuplicateFamilyCount + DuplicateSubFamilyCount + DuplicateBrandCount > 0)
            {
                var Result = MessageBox.Show(
                    "Des doublons ont été détéctés : \n" + Error +
                    "Si vous continuez, les doublons ne seront pas importés",
                    "Doublons détéctés", MessageBoxButtons.OKCancel);
                if (Result == DialogResult.Cancel)
                {
                    StatusText.Text = "Import annulé.";
                    DialogResult    = DialogResult.Cancel;
                    return(true);
                }
            }
            return(false);
        }