From ca575bef2dae6bb50b87f3dc46e24b60d5bc222d Mon Sep 17 00:00:00 2001 From: Sergey Chebotar Date: Fri, 28 Jan 2022 15:21:58 +0300 Subject: [PATCH] Move FillPosition logic to separate method --- src/PriceListTools/PriceListTool.cs | 77 +++++++++++++++-------------- 1 file changed, 41 insertions(+), 36 deletions(-) diff --git a/src/PriceListTools/PriceListTool.cs b/src/PriceListTools/PriceListTool.cs index 9aebd25..a80010b 100644 --- a/src/PriceListTools/PriceListTool.cs +++ b/src/PriceListTools/PriceListTool.cs @@ -38,42 +38,7 @@ namespace RehauSku.PriceListTools foreach (var kvp in dictionary) { - Range foundCell = TargetFile.skuCell.EntireColumn.Find(kvp.Key.Sku); - if (foundCell == null) - { - missing.Add(kvp); - continue; - } - - string foundCellGroup = groupColumn[foundCell.Row, 1].ToString(); - - while (foundCell != null && foundCellGroup != kvp.Key.Group) - { - foundCell = TargetFile.skuCell.EntireColumn.FindNext(foundCell); - foundCellGroup = groupColumn[foundCell.Row, 1].ToString(); - } - - if (foundCell == null) - { - missing.Add(kvp); - } - - else - { - foreach (var column in columns) - { - Range sumCell = TargetFile.Sheet.Cells[foundCell.Row, column]; - if (sumCell.Value2 == null) - { - sumCell.Value2 = kvp.Value; - } - - else - { - sumCell.Value2 += kvp.Value; - } - } - } + FillPosition(kvp, columns, ref missing, ref groupColumn); } if (missing.Count > 0) @@ -86,6 +51,46 @@ namespace RehauSku.PriceListTools } } + protected private void FillPosition(KeyValuePair kvp, int[] columns, ref List> missing, ref object[,] groupColumn) + { + Range foundCell = TargetFile.skuCell.EntireColumn.Find(kvp.Key.Sku); + if (foundCell == null) + { + missing.Add(kvp); + return; + } + + string foundCellGroup = groupColumn[foundCell.Row, 1].ToString(); + + while (foundCell != null && foundCellGroup != kvp.Key.Group) + { + foundCell = TargetFile.skuCell.EntireColumn.FindNext(foundCell); + foundCellGroup = groupColumn[foundCell.Row, 1].ToString(); + } + + if (foundCell == null) + { + missing.Add(kvp); + } + + else + { + foreach (var column in columns) + { + Range sumCell = TargetFile.Sheet.Cells[foundCell.Row, column]; + if (sumCell.Value2 == null) + { + sumCell.Value2 = kvp.Value; + } + + else + { + sumCell.Value2 += kvp.Value; + } + } + } + } + protected private void FilterByAmount() { AutoFilter filter = TargetFile.Sheet.AutoFilter;