From 41317cab7101f0f4fa438563373e1441b6ff3f70 Mon Sep 17 00:00:00 2001 From: Sergey Chebotar Date: Fri, 11 Feb 2022 21:59:07 +0300 Subject: [PATCH 1/9] Fix missing exact sku-group search and fill. --- src/PriceListTools/AbstractTool.cs | 73 +++++++++++++++--------------- 1 file changed, 36 insertions(+), 37 deletions(-) diff --git a/src/PriceListTools/AbstractTool.cs b/src/PriceListTools/AbstractTool.cs index d312315..68c5250 100644 --- a/src/PriceListTools/AbstractTool.cs +++ b/src/PriceListTools/AbstractTool.cs @@ -58,7 +58,7 @@ namespace RehauSku.PriceListTools protected private void FillPositionAmountToColumns(KeyValuePair positionAmount, params int[] columns) { - int? row = GetPositionRow(positionAmount.Key.Sku, positionAmount.Key.Group, TargetFile.skuCell.Column); + int? row = GetPositionRow(TargetFile.skuCell.EntireColumn, positionAmount.Key.Sku, positionAmount.Key.Group); if (row != null) { @@ -69,11 +69,12 @@ namespace RehauSku.PriceListTools } ResultBar.IncrementSuccess(); + return; } - else if (TargetFile.oldSkuCell != null) + if (TargetFile.oldSkuCell != null) { - row = GetPositionRow(positionAmount.Key.Sku, positionAmount.Key.Group, TargetFile.oldSkuCell.Column); + row = GetPositionRow(TargetFile.oldSkuCell.EntireColumn, positionAmount.Key.Sku, positionAmount.Key.Group); if (row != null) { @@ -84,31 +85,27 @@ namespace RehauSku.PriceListTools } ResultBar.IncrementReplaced(); + return; } } - else + string sku = positionAmount.Key.Sku.Substring(1, 6); + row = GetPositionRow(TargetFile.skuCell.EntireColumn, sku, positionAmount.Key.Group); + + if (row != null) { - string sku = positionAmount.Key.Sku.Substring(1, 6); - row = GetPositionRow(sku, positionAmount.Key.Group, TargetFile.skuCell.Column); - - if (row != null) + foreach (int column in columns) { - foreach (int column in columns) - { - Range cell = TargetFile.Sheet.Cells[row, column]; - cell.AddValue(positionAmount.Value); - } - - ResultBar.IncrementReplaced(); + Range cell = TargetFile.Sheet.Cells[row, column]; + cell.AddValue(positionAmount.Value); } - else - { - FillMissing(positionAmount, columns); - ResultBar.IncrementNotFound(); - } + ResultBar.IncrementReplaced(); + return; } + + FillMissing(positionAmount, columns); + ResultBar.IncrementNotFound(); } protected private void FillMissing(KeyValuePair positionAmount, params int[] columns) @@ -148,32 +145,34 @@ namespace RehauSku.PriceListTools } } - protected private int? GetPositionRow(string sku, string group, int column) + protected private int? GetPositionRow(Range range, string sku, string group) { - int? row = null; - Range foundCell = TargetFile.Sheet.Columns[column].Find(sku); + Range found = range.Find(sku); string foundGroupValue; - if (foundCell == null) return null; - - else + if (found == null) { - row = foundCell.Row; - foundGroupValue = TargetFile.Sheet.Cells[foundCell.Row, TargetFile.groupCell.Column].Value2.ToString(); + return null; } - if (string.IsNullOrEmpty(group) || group.Equals(foundGroupValue)) - return row; + int firstFoundRow = found.Row; - else - while (true) + while (true) + { + foundGroupValue = TargetFile.Sheet.Cells[found.Row, TargetFile.groupCell.Column].Value2.ToString(); + + if (string.IsNullOrEmpty(group) || group.Equals(foundGroupValue)) { - foundCell = TargetFile.skuCell.EntireColumn.FindNext(foundCell); - if (foundCell == null) return row; - - foundGroupValue = TargetFile.Sheet.Cells[foundCell.Row, TargetFile.groupCell.Column].Value2.ToString(); - if (group.Equals(foundGroupValue)) return foundCell.Row; + return found.Row; } + + found = range.FindNext(found); + + if (found.Row == firstFoundRow) + { + return null; + } + } } protected private void FilterByAmount() From 69865e96e3a1f128c9c25a32a445745aa8aa4fbf Mon Sep 17 00:00:00 2001 From: Sergey Chebotar Date: Sat, 12 Feb 2022 16:02:55 +0300 Subject: [PATCH 2/9] Create Tool Factory. Exception on empty selection in Export Tool. --- src/Interface/RibbonController.cs | 98 ++++++++++++------------------ src/PriceListTools/AbstractTool.cs | 31 +++------- src/PriceListTools/CombineTool.cs | 23 ++++++- src/PriceListTools/ConvertTool.cs | 21 ++----- src/PriceListTools/ExportTool.cs | 9 ++- src/PriceListTools/MergeTool.cs | 20 +++++- 6 files changed, 99 insertions(+), 103 deletions(-) diff --git a/src/Interface/RibbonController.cs b/src/Interface/RibbonController.cs index bc038d1..7a58c7c 100644 --- a/src/Interface/RibbonController.cs +++ b/src/Interface/RibbonController.cs @@ -20,11 +20,11 @@ namespace RehauSku.Interface -