Compare commits

..

5 Commits

Author SHA1 Message Date
Sergey Chebotar
2aae1805c5 Merge branch 'master' of https://gitea.cebotari.ru/chebser/RhSolutions-AddIn 2023-05-27 08:21:37 +03:00
Sergey Chebotar
cf472b66a4 Version 1.8.2.0 2023-05-27 08:20:39 +03:00
Sergey Chebotar
f58dec38a4 Fix wrong article found on replaced lookup 2023-05-27 08:19:10 +03:00
Sergey Chebotar
9c3c65a4f8 Fix write test 2023-05-27 08:17:36 +03:00
Sergey Chebotar
3e4a5e6563 Edit Replace and New Variant tests 2023-05-27 07:37:36 +03:00
7 changed files with 43 additions and 29 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 // You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below: // by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")] // [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.8.1.0")] [assembly: AssemblyVersion("1.8.2.0")]
[assembly: AssemblyFileVersion("1.8.1.0")] [assembly: AssemblyFileVersion("1.8.2.0")]

View File

@ -3,7 +3,6 @@ using System.Runtime.Versioning;
using RhSolutions.Tools; using RhSolutions.Tools;
#endif #endif
using System.Text.RegularExpressions; using System.Text.RegularExpressions;
namespace RhSolutions.Services; namespace RhSolutions.Services;
@ -112,7 +111,7 @@ public class ExcelWriter : IWriter, IDisposable
Range worksheetCells = _worksheet.Cells; Range worksheetCells = _worksheet.Cells;
Range skuColumn = _skuCell.EntireColumn; 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) if (row != null)
{ {
@ -128,7 +127,7 @@ public class ExcelWriter : IWriter, IDisposable
if (_oldSkuCell != null) 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) if (row != null)
{ {
@ -149,8 +148,7 @@ public class ExcelWriter : IWriter, IDisposable
} }
} }
string sku = positionAmount.Key.ProductSku.Article; row = GetPositionRow(skuColumn, positionAmount.Key.ProductSku, positionAmount.Key.ProductLines.FirstOrDefault(), true);
row = GetPositionRow(skuColumn, sku, positionAmount.Key.ProductLines.FirstOrDefault());
if (row != null) 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 foundGroupValue;
string foundSkuValue;
if (found == null) if (found == null)
{ {
@ -224,25 +224,36 @@ public class ExcelWriter : IWriter, IDisposable
int firstFoundRow = found.Row; int firstFoundRow = found.Row;
if (string.IsNullOrEmpty(group))
{
return found.Row;
}
while (true) while (true)
{ {
foundSkuValue = _worksheet.Cells[found.Row, range.Column].Value2.ToString();
foundGroupValue = _worksheet.Cells[found.Row, _programLineCell.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; 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;
}
}
} }
else
found = range.FindNext(found);
if (found.Row == firstFoundRow)
{ {
return null; found = range.FindNext(found);
if (found.Row == firstFoundRow)
{
return null;
}
} }
} }
} }

View File

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