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)
{
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,13 +85,12 @@ namespace RehauSku.PriceListTools
}
ResultBar.IncrementReplaced();
return;
}
}
else
{
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)
{
@ -101,15 +101,12 @@ namespace RehauSku.PriceListTools
}
ResultBar.IncrementReplaced();
return;
}
else
{
FillMissing(positionAmount, columns);
ResultBar.IncrementNotFound();
}
}
}
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 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)
{
foundCell = TargetFile.skuCell.EntireColumn.FindNext(foundCell);
if (foundCell == null) return row;
foundGroupValue = TargetFile.Sheet.Cells[found.Row, TargetFile.groupCell.Column].Value2.ToString();
foundGroupValue = TargetFile.Sheet.Cells[foundCell.Row, TargetFile.groupCell.Column].Value2.ToString();
if (group.Equals(foundGroupValue)) return foundCell.Row;
if (string.IsNullOrEmpty(group) || group.Equals(foundGroupValue))
{
return found.Row;
}
found = range.FindNext(found);
if (found.Row == firstFoundRow)
{
return null;
}
}
}