Compare commits

..

No commits in common. "2aae1805c5c94ed1a25ec107ec6f5f1c8982cbfd" and "4434da98be2bcad2ef0a4543dfd86f0ec04f3334" have entirely different histories.

7 changed files with 29 additions and 43 deletions

View File

@ -31,5 +31,5 @@ using System.Runtime.InteropServices;
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.8.2.0")]
[assembly: AssemblyFileVersion("1.8.2.0")]
[assembly: AssemblyVersion("1.8.1.0")]
[assembly: AssemblyFileVersion("1.8.1.0")]

View File

@ -3,6 +3,7 @@ using System.Runtime.Versioning;
using RhSolutions.Tools;
#endif
using System.Text.RegularExpressions;
namespace RhSolutions.Services;
@ -111,7 +112,7 @@ public class ExcelWriter : IWriter, IDisposable
Range worksheetCells = _worksheet.Cells;
Range skuColumn = _skuCell.EntireColumn;
int? row = GetPositionRow(skuColumn, positionAmount.Key.ProductSku, positionAmount.Key.ProductLines.FirstOrDefault());
int? row = GetPositionRow(skuColumn, positionAmount.Key.ProductSku.ToString(), positionAmount.Key.ProductLines.FirstOrDefault());
if (row != null)
{
@ -127,7 +128,7 @@ public class ExcelWriter : IWriter, IDisposable
if (_oldSkuCell != null)
{
row = GetPositionRow(_oldSkuCell.EntireColumn, positionAmount.Key.ProductSku, positionAmount.Key.ProductLines.FirstOrDefault());
row = GetPositionRow(_oldSkuCell.EntireColumn, positionAmount.Key.ProductSku.ToString(), positionAmount.Key.ProductLines.FirstOrDefault());
if (row != null)
{
@ -148,7 +149,8 @@ public class ExcelWriter : IWriter, IDisposable
}
}
row = GetPositionRow(skuColumn, positionAmount.Key.ProductSku, positionAmount.Key.ProductLines.FirstOrDefault(), true);
string sku = positionAmount.Key.ProductSku.Article;
row = GetPositionRow(skuColumn, sku, positionAmount.Key.ProductLines.FirstOrDefault());
if (row != null)
{
@ -210,12 +212,10 @@ public class ExcelWriter : IWriter, IDisposable
}
}
private int? GetPositionRow(Range range, ProductSku sku, string productLine, bool justArticle = false)
private int? GetPositionRow(Range range, string sku, string group)
{
string lookupString = justArticle ? sku.Article : sku.ToString();
Range found = range.Find(lookupString);
Range found = range.Find(sku);
string foundGroupValue;
string foundSkuValue;
if (found == null)
{
@ -224,36 +224,25 @@ 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 (ProductSku.TryParse(foundSkuValue, out var skus))
if (group.Equals(foundGroupValue))
{
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)
{
return null;
}
}
return found.Row;
}
else
{
found = range.FindNext(found);
if (found.Row == firstFoundRow)
{
return null;
}
found = range.FindNext(found);
if (found.Row == firstFoundRow)
{
return null;
}
}
}

View File

@ -79,13 +79,10 @@ public class CanWriteProducts : IDisposable
Assert.Equal("TestSpecificationReplaced", products.First().Item1);
Assert.Equal("TargetSpecificationReplaced", targetProducts.First().Item1);
var result = targetProducts.First().Item2.ToArray();
Assert.Contains("Молот Тора", result[0].Key.Name);
Assert.Contains("15555551555", result[0].Key.Name);
Assert.Equal(1, result[0].Value);
Assert.Contains("Нога Вирта", result[1].Key.Name);
Assert.Contains("17777771777", result[1].Key.Name);
Assert.Equal(1, result[1].Value);
Assert.Single(targetProducts.First().Item2);
var product = targetProducts.First().Item2.First().Key;
Assert.Contains("Молот Тора", product.Name);
Assert.Contains("15555551555", product.Name);
}
[ExcelFact(Workbook = @"..\..\..\TestWorkbooks\TestSpecificationNewVariant.xlsx")]
@ -101,10 +98,10 @@ public class CanWriteProducts : IDisposable
Assert.Equal("TestSpecificationNewVariant", products.First().Item1);
Assert.Equal("TargetSpecificationNewVariant", targetProducts.First().Item1);
var result = targetProducts.First().Item2.ToArray();
Assert.Contains("Молот Тора", result[0].Key.Name);
Assert.Contains("11201111555", result[0].Key.Name);
Assert.Equal(1, result[0].Value);
Assert.Single(targetProducts.First().Item2);
var product = targetProducts.First().Item2.First().Key;
Assert.Contains("Молот Тора", product.Name);
Assert.Contains("15555551555", product.Name);
}
public void Dispose()