예제 #1
0
        public override void Parse()
        {
            Income.Products = new List<Product>();
            CategoryService categoryService = new CategoryService();
            int addedCount = 0;
            int skippedCount = 0;
            bool skipCategoryPrinted = false;
            int usedRangeRows = ActiveWorksheet.UsedRange.Rows.Count;

            for (int i = FirstRow; i < usedRangeRows; i++)
            {
                if (i == 344)
                {

                }
                string quantityString = GetCellValue(i, QuantityColumn);
                int level = (int)GetOutlineLevel(i);

                // признак категории
                if (string.IsNullOrEmpty(quantityString) || level == 2)
                {
                    categoryService.LastResult = CategoryService.CategoryChoiсeResult.Undefined;
                    UpdateCategories(GetCellValue(i, 1), level);
                    skipCategoryPrinted = false;
                    continue;
                }

                string price = GetCellValue(i, PriceColumn);

                OnSetProgressBarValue(CalcProgressBarValue(i, usedRangeRows));
                OnPrintStatus($"Обработка позиции {i} из {usedRangeRows}");

                string originalName = _categoriesStack.Peek().CleanName;
                //CleanCategoriesStack(GetOutlineLevel(i));
                string articul = GetCellValue(i, NameColumn).Trim();

                if (string.IsNullOrEmpty(articul) ||
                    string.IsNullOrEmpty(originalName) ||
                    string.IsNullOrEmpty(price))
                {
                    OnPrintMessage($"Строка {i} пропущена. Одно из значений в строке нулевое");
                    skippedCount++;
                    continue;
                }

                if (categoryService.LastResult == CategoryService.CategoryChoiсeResult.Undefined)
                    categoryService.ParseCategory(_categoriesStack.ToList(), originalName);

                if (categoryService.LastResult == CategoryService.CategoryChoiсeResult.Ignore)
                {
                    skippedCount++;
                    if (skipCategoryPrinted == false)
                    {
                        OnPrintMessage($"Категорию '{GetCategoriesTree()}' пропускаем");
                        skipCategoryPrinted = true;
                    }
                    continue;
                }

                Brand brand = GetBrand(originalName);

                var remains = new List<Remain>();

                if (!string.IsNullOrEmpty(quantityString))
                {
                    int quantity = 0;
                    int.TryParse(quantityString, out quantity);
                    if (quantity < 0)
                        quantity = 0;
                    remains.Add(new Remain() {Quantity = quantity, Size = GetCellValue(i, SizeColumn), Price = price});
                    // сбор всех размеров
                    int nextLevel = (int)GetOutlineLevel(i+1);
                    while (nextLevel == level)
                    {
                        i++;

                        price = GetCellValue(i, PriceColumn);
                        if (!string.IsNullOrEmpty(price))
                        {
                            quantityString = GetCellValue(i, QuantityColumn);
                            remains.Add(new Remain()
                            {
                                Quantity = quantity,
                                Size = GetCellValue(i, SizeColumn),
                                Price = price
                            });
                            int.TryParse(quantityString, out quantity);
                            if (quantity < 0)
                                quantity = 0;
                        }
                        nextLevel = (int)GetOutlineLevel(i + 1);
                    }
                }

                Product newProduct = new Product
                {
                    Categories = categoryService.ChosenCategoryString,
                    Articul = articul,
                    Name = originalName,
                    Brand = brand?.Name,
                    Price = price,
                    Remains = remains
                };
                Income.Products.Add(newProduct);
                addedCount++;
            }
            OnPrintMessage($"Обработано успешно: {addedCount}; Пропущено: {skippedCount}");
        }
예제 #2
0
        public override void Parse()
        {
            // test category fill
            Income.Products = new List<Product>();
            var
                onlyLeaves =
                    CatalogDictionary.Instance.AllCategoriesList.Where(cat => cat.Categories.Count == 0).ToList();
            onlyLeaves.ForEach(cat =>
            {
                Income.Products.Add(new Product
                {
                    Articul = "test_" + System.Guid.NewGuid().ToString().Substring(0, 8),
                    Brand = "",
                    Categories = cat.PluginExportString,
                    Name = "test name",
                    Price = "0",
                    Remains = new List<Remain>()
                });
            });
            //return;

            Income.Products = new List<Product>();
            CategoryService categoryService = new CategoryService();
            int addedCount = 0;
            int skippedCount = 0;
            bool skipCategoryPrinted = false;
            int usedRangeRows = ActiveWorksheet.UsedRange.Rows.Count;

            for (int i = FirstRow; i < usedRangeRows; i++)
            {
                if (GetCellColor(i, 1) == Color.FromArgb(242, 241, 217))
                {
                    categoryService.LastResult = CategoryService.CategoryChoiсeResult.Undefined;
                    UpdateCategories(GetCellValue(i, 1));
                    skipCategoryPrinted = false;
                    continue;
                }

                OnSetProgressBarValue(CalcProgressBarValue(i, usedRangeRows));
                OnPrintStatus($"Обработка позиции {i} из {usedRangeRows}");

                string originalName = GetCellValue(i, NameColumn);
                string price = GetCellValue(i, 10);

                if (string.IsNullOrEmpty(originalName))
                {
                    skippedCount ++;
                    continue;
                }

                if (categoryService.LastResult == CategoryService.CategoryChoiсeResult.Undefined)
                    categoryService.ParseCategory(_categoriesStack.ToList(), "");

                if (categoryService.LastResult == CategoryService.CategoryChoiсeResult.Ignore)
                {
                    skippedCount++;
                    if (skipCategoryPrinted == false)
                    {
                        OnPrintMessage($"Категорию '{GetCategoriesTree()}' пропускаем");
                        skipCategoryPrinted = true;
                    }
                    continue;
                }

                Brand brand = GetBrand(originalName);
                if (brand == null)
                {
                    skippedCount++;
                    continue;
                }

                string articulValue = GetArticul(originalName, brand);

                string nameValue = GetName(originalName, brand);

                var remains = GetRemains(i,
                    GetCategoriesTree().ToUpper().Contains("ОБУВЬ") ||
                    (brand.Name == "Asics" && nameValue.Contains("Стелька анатомическая")), price);

                Product newProduct = new Product
                {
                    Categories = categoryService.ChosenCategoryString,
                    Articul = articulValue,
                    Name = nameValue,
                    Brand = brand?.Name,
                    Price = price,
                    //PriceWithSale = priceWithSale,
                    Remains = remains
                };
                Income.Products.Add(newProduct);
                addedCount++;
            }
            OnPrintMessage($"Обработано успешно: {addedCount}; Пропущено: {skippedCount}");
        }