From cfb15d1279f604cc7387e1e23680ba8a63c9f110 Mon Sep 17 00:00:00 2001 From: Sergey Chebotar Date: Mon, 31 Jan 2022 17:54:18 +0300 Subject: [PATCH] Fix Export Tool to use Price List Tool base methods --- src/PriceListTools/ExportTool.cs | 55 ++++++----------------------- src/PriceListTools/Position.cs | 3 +- src/PriceListTools/PriceListTool.cs | 4 +++ 3 files changed, 16 insertions(+), 46 deletions(-) diff --git a/src/PriceListTools/ExportTool.cs b/src/PriceListTools/ExportTool.cs index 8bf274a..757d827 100644 --- a/src/PriceListTools/ExportTool.cs +++ b/src/PriceListTools/ExportTool.cs @@ -7,7 +7,7 @@ namespace RehauSku.PriceListTools { internal class ExportTool : PriceListTool { - private Dictionary SkuAmount { get; set; } + private Dictionary PositionAmount; private Range Selection; public void TryGetSelection() @@ -19,62 +19,23 @@ namespace RehauSku.PriceListTools throw new Exception("Неверный диапазон"); } } - public void FillTarget() { ExcelApp.ScreenUpdating = false; GetSelected(); - FillColumn(SkuAmount, TargetFile.amountCell.Column); + FillColumnsWithDictionary(PositionAmount, TargetFile.amountCell.Column); FilterByAmount(); ExcelApp.ScreenUpdating = true; Forms.Dialog.SaveWorkbookAs(); } - private void FillColumn(IEnumerable> dictionary, int column) - { - List> missing = new List>(); - - foreach (var kvp in dictionary) - { - Range cell = TargetFile.skuCell.EntireColumn.Find(kvp.Key); - - if (cell == null) - { - missing.Add(kvp); - } - - else - { - Range sumCell = TargetFile.Sheet.Cells[cell.Row, column]; - - if (sumCell.Value2 == null) - { - sumCell.Value2 = kvp.Value; - } - - else - { - sumCell.Value2 += kvp.Value; - } - } - } - - if (missing.Count > 0) - { - System.Windows.Forms.MessageBox.Show - ($"{missing.Count} артикулов отсутствует в таблице заказов {RegistryUtil.PriceListPath} Попробовать найти новый вариант?", - "Отсутствует позиция в конечной таблице заказов", - System.Windows.Forms.MessageBoxButtons.YesNo, - System.Windows.Forms.MessageBoxIcon.Information); - } - } - - private void GetSelected() { object[,] cells = Selection.Value2; - SkuAmount = new Dictionary(); + Dictionary SkuAmount = new Dictionary(); + PositionAmount = new Dictionary(); + int rowsCount = Selection.Rows.Count; for (int row = 1; row <= rowsCount; row++) @@ -115,11 +76,17 @@ namespace RehauSku.PriceListTools { SkuAmount[sku] += amount.Value; } + else { SkuAmount.Add(sku, amount.Value); } } + + foreach (var kvp in SkuAmount) + { + PositionAmount.Add(new Position(null, kvp.Key, null), kvp.Value); + } } } } diff --git a/src/PriceListTools/Position.cs b/src/PriceListTools/Position.cs index 471aa59..0863642 100644 --- a/src/PriceListTools/Position.cs +++ b/src/PriceListTools/Position.cs @@ -13,5 +13,4 @@ Name = name; } } -} - +} \ No newline at end of file diff --git a/src/PriceListTools/PriceListTool.cs b/src/PriceListTools/PriceListTool.cs index 09d4dac..f87aa16 100644 --- a/src/PriceListTools/PriceListTool.cs +++ b/src/PriceListTools/PriceListTool.cs @@ -89,6 +89,8 @@ namespace RehauSku.PriceListTools while (foundCell != null && foundCellGroup != positionAmount.Key.Group) { + if (positionAmount.Key.Group == null) break; + foundCell = TargetFile.skuCell.EntireColumn.FindNext(foundCell); foundCellGroup = TargetFile.Sheet.Cells[foundCell.Row, TargetFile.groupCell.Column].Value2.ToString(); } @@ -132,6 +134,8 @@ namespace RehauSku.PriceListTools while (foundCell != null && foundCellGroup != positionAmount.Key.Group) { + if (positionAmount.Key.Group == null) break; + foundCell = TargetFile.skuCell.EntireColumn.FindNext(foundCell); foundCellGroup = TargetFile.Sheet.Cells[foundCell.Row, TargetFile.groupCell.Column].Value2.ToString(); }