From cfb15d1279f604cc7387e1e23680ba8a63c9f110 Mon Sep 17 00:00:00 2001 From: Sergey Chebotar Date: Mon, 31 Jan 2022 17:54:18 +0300 Subject: Fix Export Tool to use Price List Tool base methods --- src/PriceListTools/ExportTool.cs | 55 ++++++++-------------------------------- 1 file changed, 11 insertions(+), 44 deletions(-) (limited to 'src/PriceListTools/ExportTool.cs') 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); + } } } } -- cgit v1.2.3 From 7e5020ec253df1d0d32304ba72cdaa62937bb26b Mon Sep 17 00:00:00 2001 From: Sergey Chebotar Date: Tue, 1 Feb 2022 20:32:29 +0300 Subject: Refactoring, Not fount table formatting etc --- src/PriceListTools/ExportTool.cs | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) (limited to 'src/PriceListTools/ExportTool.cs') diff --git a/src/PriceListTools/ExportTool.cs b/src/PriceListTools/ExportTool.cs index 757d827..bfb3d8a 100644 --- a/src/PriceListTools/ExportTool.cs +++ b/src/PriceListTools/ExportTool.cs @@ -19,21 +19,24 @@ namespace RehauSku.PriceListTools throw new Exception("Неверный диапазон"); } } + public void FillTarget() { - ExcelApp.ScreenUpdating = false; GetSelected(); - FillColumnsWithDictionary(PositionAmount, TargetFile.amountCell.Column); + + foreach (var kvp in PositionAmount) + { + FillColumnsWithDictionary(kvp, TargetFile.amountCell.Column); + } + FilterByAmount(); - ExcelApp.ScreenUpdating = true; Forms.Dialog.SaveWorkbookAs(); } private void GetSelected() { - object[,] cells = Selection.Value2; - Dictionary SkuAmount = new Dictionary(); + object[,] cells = Selection.Value2; PositionAmount = new Dictionary(); int rowsCount = Selection.Rows.Count; @@ -72,21 +75,18 @@ namespace RehauSku.PriceListTools continue; } - if (SkuAmount.ContainsKey(sku)) + Position position = new Position(null, sku, null); + + if (PositionAmount.ContainsKey(position)) { - SkuAmount[sku] += amount.Value; + PositionAmount[position] += amount.Value; } else { - SkuAmount.Add(sku, amount.Value); + PositionAmount.Add(position, amount.Value); } } - - foreach (var kvp in SkuAmount) - { - PositionAmount.Add(new Position(null, kvp.Key, null), kvp.Value); - } } } } -- cgit v1.2.3