Fix missing exact sku-group search and fill.

This commit is contained in:
Sergey Chebotar 2022-02-11 21:59:07 +03:00
parent acaea67920
commit 41317cab71

View File

@ -58,7 +58,7 @@ namespace RehauSku.PriceListTools
protected private void FillPositionAmountToColumns(KeyValuePair<Position, double> positionAmount, params int[] columns) protected private void FillPositionAmountToColumns(KeyValuePair<Position, double> 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) if (row != null)
{ {
@ -69,11 +69,12 @@ namespace RehauSku.PriceListTools
} }
ResultBar.IncrementSuccess(); 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) if (row != null)
{ {
@ -84,13 +85,12 @@ namespace RehauSku.PriceListTools
} }
ResultBar.IncrementReplaced(); ResultBar.IncrementReplaced();
return;
} }
} }
else
{
string sku = positionAmount.Key.Sku.Substring(1, 6); string sku = positionAmount.Key.Sku.Substring(1, 6);
row = GetPositionRow(sku, positionAmount.Key.Group, TargetFile.skuCell.Column); row = GetPositionRow(TargetFile.skuCell.EntireColumn, sku, positionAmount.Key.Group);
if (row != null) if (row != null)
{ {
@ -101,15 +101,12 @@ namespace RehauSku.PriceListTools
} }
ResultBar.IncrementReplaced(); ResultBar.IncrementReplaced();
return;
} }
else
{
FillMissing(positionAmount, columns); FillMissing(positionAmount, columns);
ResultBar.IncrementNotFound(); ResultBar.IncrementNotFound();
} }
}
}
protected private void FillMissing(KeyValuePair<Position, double> positionAmount, params int[] columns) protected private void FillMissing(KeyValuePair<Position, double> positionAmount, params int[] columns)
{ {
@ -148,31 +145,33 @@ 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 found = range.Find(sku);
Range foundCell = TargetFile.Sheet.Columns[column].Find(sku);
string foundGroupValue; string foundGroupValue;
if (foundCell == null) return null; if (found == null)
else
{ {
row = foundCell.Row; return null;
foundGroupValue = TargetFile.Sheet.Cells[foundCell.Row, TargetFile.groupCell.Column].Value2.ToString();
} }
if (string.IsNullOrEmpty(group) || group.Equals(foundGroupValue)) int firstFoundRow = found.Row;
return row;
else
while (true) while (true)
{ {
foundCell = TargetFile.skuCell.EntireColumn.FindNext(foundCell); foundGroupValue = TargetFile.Sheet.Cells[found.Row, TargetFile.groupCell.Column].Value2.ToString();
if (foundCell == null) return row;
foundGroupValue = TargetFile.Sheet.Cells[foundCell.Row, TargetFile.groupCell.Column].Value2.ToString(); if (string.IsNullOrEmpty(group) || group.Equals(foundGroupValue))
if (group.Equals(foundGroupValue)) return foundCell.Row; {
return found.Row;
}
found = range.FindNext(found);
if (found.Row == firstFoundRow)
{
return null;
}
} }
} }