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;