aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSergey Chebotar <s.chebotar@gmail.com>2023-05-27 08:19:10 +0300
committerSergey Chebotar <s.chebotar@gmail.com>2023-05-27 08:19:10 +0300
commitf58dec38a4cc1a8ea0b3d9208e2bc8f73d77add5 (patch)
tree8b99a652df8bbb9e676b2a5c948f9819993c9f7b
parent9c3c65a4f8cef25dbf2f9a940f6ae16a22d26ef6 (diff)
Fix wrong article found on replaced lookup
-rw-r--r--RhSolutions.AddIn/Services/ExcelWriter.cs49
1 files changed, 30 insertions, 19 deletions
diff --git a/RhSolutions.AddIn/Services/ExcelWriter.cs b/RhSolutions.AddIn/Services/ExcelWriter.cs
index 8267627..99018b0 100644
--- a/RhSolutions.AddIn/Services/ExcelWriter.cs
+++ b/RhSolutions.AddIn/Services/ExcelWriter.cs
@@ -3,7 +3,6 @@ using System.Runtime.Versioning;
using RhSolutions.Tools;
#endif
-
using System.Text.RegularExpressions;
namespace RhSolutions.Services;
@@ -112,7 +111,7 @@ public class ExcelWriter : IWriter, IDisposable
Range worksheetCells = _worksheet.Cells;
Range skuColumn = _skuCell.EntireColumn;
- int? row = GetPositionRow(skuColumn, positionAmount.Key.ProductSku.ToString(), positionAmount.Key.ProductLines.FirstOrDefault());
+ int? row = GetPositionRow(skuColumn, positionAmount.Key.ProductSku, positionAmount.Key.ProductLines.FirstOrDefault());
if (row != null)
{
@@ -128,7 +127,7 @@ public class ExcelWriter : IWriter, IDisposable
if (_oldSkuCell != null)
{
- row = GetPositionRow(_oldSkuCell.EntireColumn, positionAmount.Key.ProductSku.ToString(), positionAmount.Key.ProductLines.FirstOrDefault());
+ row = GetPositionRow(_oldSkuCell.EntireColumn, positionAmount.Key.ProductSku, positionAmount.Key.ProductLines.FirstOrDefault());
if (row != null)
{
@@ -149,8 +148,7 @@ public class ExcelWriter : IWriter, IDisposable
}
}
- string sku = positionAmount.Key.ProductSku.Article;
- row = GetPositionRow(skuColumn, sku, positionAmount.Key.ProductLines.FirstOrDefault());
+ row = GetPositionRow(skuColumn, positionAmount.Key.ProductSku, positionAmount.Key.ProductLines.FirstOrDefault(), true);
if (row != null)
{
@@ -212,10 +210,12 @@ public class ExcelWriter : IWriter, IDisposable
}
}
- private int? GetPositionRow(Range range, string sku, string group)
+ private int? GetPositionRow(Range range, ProductSku sku, string productLine, bool justArticle = false)
{
- Range found = range.Find(sku);
+ string lookupString = justArticle ? sku.Article : sku.ToString();
+ Range found = range.Find(lookupString);
string foundGroupValue;
+ string foundSkuValue;
if (found == null)
{
@@ -224,25 +224,36 @@ public class ExcelWriter : IWriter, IDisposable
int firstFoundRow = found.Row;
- if (string.IsNullOrEmpty(group))
- {
- return found.Row;
- }
-
while (true)
{
+ foundSkuValue = _worksheet.Cells[found.Row, range.Column].Value2.ToString();
foundGroupValue = _worksheet.Cells[found.Row, _programLineCell.Column].Value2.ToString();
- if (group.Equals(foundGroupValue))
+ if (ProductSku.TryParse(foundSkuValue, out var skus))
{
- return found.Row;
- }
-
- found = range.FindNext(found);
+ if (skus.Any(s => s.Article == sku.Article) &&
+ (string.IsNullOrEmpty(productLine) || productLine.Equals(foundGroupValue)) )
+ {
+ return found.Row;
+ }
+ else
+ {
+ found = range.FindNext(found);
- if (found.Row == firstFoundRow)
+ if (found.Row == firstFoundRow)
+ {
+ return null;
+ }
+ }
+ }
+ else
{
- return null;
+ found = range.FindNext(found);
+
+ if (found.Row == firstFoundRow)
+ {
+ return null;
+ }
}
}
}