From 7bb0a82ffbd5c5123bfdbff6ba29f463ab9d1b46 Mon Sep 17 00:00:00 2001 From: Sergey Chebotar Date: Thu, 27 Jan 2022 20:43:19 +0300 Subject: [PATCH] Add FillColumn method --- src/PriceListTools/CombineTool.cs | 35 +++++++--------------------- src/PriceListTools/ExportTool.cs | 8 ++++++- src/PriceListTools/MergeTool.cs | 7 +++++- src/PriceListTools/PriceListTool.cs | 36 ++++++++++++++--------------- 4 files changed, 39 insertions(+), 47 deletions(-) diff --git a/src/PriceListTools/CombineTool.cs b/src/PriceListTools/CombineTool.cs index f6eac8a..c634309 100644 --- a/src/PriceListTools/CombineTool.cs +++ b/src/PriceListTools/CombineTool.cs @@ -11,42 +11,23 @@ namespace RehauSku.PriceListTools public void FillTarget() { ExcelApp.ScreenUpdating = false; - FillAmountColumn(SourceFiles.Select(x => x.SkuAmount).ToArray()); - AddAndFillSourceColumns(); - FilterByAmount(); - ExcelApp.ScreenUpdating = true; - Forms.Dialog.SaveWorkbookAs(); - } - - private void AddAndFillSourceColumns() - { - foreach (var source in SourceFiles) + foreach (Source source in SourceFiles) { - if (source.SkuAmount.Count == 0) - continue; - TargetFile.Sheet.Columns[TargetFile.amountCell.Column] .EntireColumn .Insert(XlInsertShiftDirection.xlShiftToRight, XlInsertFormatOrigin.xlFormatFromRightOrBelow); TargetFile.Sheet.Cells[TargetFile.amountCell.Row, TargetFile.amountCell.Column - 1].Value2 = $"{source.Name}"; - foreach (var kvp in source.SkuAmount) - { - Range cell = TargetFile.Sheet.Columns[TargetFile.skuCell.Column].Find(kvp.Key); - - if (cell == null) - { - continue; - } - - else - { - TargetFile.Sheet.Cells[cell.Row, TargetFile.amountCell.Column - 1].Value2 = kvp.Value; - } - } + FillColumn(source.SkuAmount, TargetFile.amountCell.Column - 1); + FillColumn(source.SkuAmount, TargetFile.amountCell.Column); } + + FilterByAmount(); + ExcelApp.ScreenUpdating = true; + + Forms.Dialog.SaveWorkbookAs(); } } } diff --git a/src/PriceListTools/ExportTool.cs b/src/PriceListTools/ExportTool.cs index 10d66b4..fc9e42d 100644 --- a/src/PriceListTools/ExportTool.cs +++ b/src/PriceListTools/ExportTool.cs @@ -24,7 +24,7 @@ namespace RehauSku.PriceListTools { ExcelApp.ScreenUpdating = false; GetSelected(); - FillAmountColumn(new [] {SkuAmount}); + FillColumn(SkuAmount, TargetFile.amountCell.Column); FilterByAmount(); ExcelApp.ScreenUpdating = true; @@ -67,12 +67,18 @@ namespace RehauSku.PriceListTools } if (sku == null || amount == null) + { continue; + } if (SkuAmount.ContainsKey(sku)) + { SkuAmount[sku] += amount.Value; + } else + { SkuAmount.Add(sku, amount.Value); + } } } } diff --git a/src/PriceListTools/MergeTool.cs b/src/PriceListTools/MergeTool.cs index 20ace85..75804a0 100644 --- a/src/PriceListTools/MergeTool.cs +++ b/src/PriceListTools/MergeTool.cs @@ -10,7 +10,12 @@ namespace RehauSku.PriceListTools public void FillTarget() { ExcelApp.ScreenUpdating = false; - FillAmountColumn(SourceFiles.Select(x => x.SkuAmount).ToArray()); + + foreach (Source source in SourceFiles) + { + FillColumn(source.SkuAmount, TargetFile.amountCell.Column); + } + FilterByAmount(); ExcelApp.ScreenUpdating = true; diff --git a/src/PriceListTools/PriceListTool.cs b/src/PriceListTools/PriceListTool.cs index 09315a2..99eef17 100644 --- a/src/PriceListTools/PriceListTool.cs +++ b/src/PriceListTools/PriceListTool.cs @@ -31,37 +31,37 @@ namespace RehauSku.PriceListTools } } - protected private void FillAmountColumn(Dictionary[] dictionaries) + protected private void FillColumn(Dictionary dictionary, int column) { - foreach (var dictionary in dictionaries) + foreach (var kvp in dictionary) { - if (dictionary.Count == 0) - continue; + Range cell = TargetFile.Sheet.Columns[TargetFile.skuCell.Column].Find(kvp.Key); - foreach (var kvp in dictionary) + if (cell == null) { - Range cell = TargetFile.Sheet.Columns[TargetFile.skuCell.Column].Find(kvp.Key); + System.Windows.Forms.MessageBox.Show + ($"Артикул {kvp.Key} отсутствует в таблице заказов {RegistryUtil.PriceListPath}", + "Отсутствует позиция в конечной таблице заказов", + System.Windows.Forms.MessageBoxButtons.OK, + System.Windows.Forms.MessageBoxIcon.Information); + } - if (cell == null) + else + { + Range sumCell = TargetFile.Sheet.Cells[cell.Row, column]; + + if (sumCell.Value2 == null) { - System.Windows.Forms.MessageBox.Show - ($"Артикул {kvp.Key} отсутствует в таблице заказов {RegistryUtil.PriceListPath}", - "Отсутствует позиция в конечной таблице заказов", - System.Windows.Forms.MessageBoxButtons.OK, - System.Windows.Forms.MessageBoxIcon.Information); + sumCell.Value2 = kvp.Value; } else { - Range sumCell = TargetFile.Sheet.Cells[cell.Row, TargetFile.amountCell.Column]; - - if (sumCell.Value2 == null) - sumCell.Value2 = kvp.Value; - else - sumCell.Value2 += kvp.Value; + sumCell.Value2 += kvp.Value; } } } + } protected private void FilterByAmount()