Compare commits
4 Commits
7fd139a234
...
a9aa1f30c5
Author | SHA1 | Date | |
---|---|---|---|
|
a9aa1f30c5 | ||
|
7f8455d868 | ||
|
9d2f386a74 | ||
|
9840e0fb24 |
@ -14,7 +14,7 @@ public class GuessReader : IReader
|
||||
|
||||
public Dictionary<Product, double> ReadProducts(Range range)
|
||||
{
|
||||
_progressBar = new("Ищу колонки со значениями", range.Columns.Count);
|
||||
_progressBar = new("Поиск возможных пар артикул-количество...", range.Columns.Count);
|
||||
int? productColumnIndex = null;
|
||||
List<int> amountColumnIndeces = new();
|
||||
|
||||
@ -74,7 +74,7 @@ public class GuessReader : IReader
|
||||
private bool IsProductColumn(Range column)
|
||||
{
|
||||
int successCounter = 0;
|
||||
object[,] cells = column.Value2;
|
||||
var cells = column.Value2;
|
||||
|
||||
if (cells == null)
|
||||
{
|
||||
@ -82,8 +82,8 @@ public class GuessReader : IReader
|
||||
}
|
||||
|
||||
for (int row = 1; row < column.Rows.Count + 1; row++)
|
||||
{
|
||||
object currentCell = cells[row, 1];
|
||||
{
|
||||
object currentCell = column.Rows.Count == 1 ? cells : cells[row, 1];
|
||||
if (currentCell == null)
|
||||
{
|
||||
continue;
|
||||
@ -106,7 +106,7 @@ public class GuessReader : IReader
|
||||
private bool IsAmountColumn(Range column)
|
||||
{
|
||||
int successCounter = 0;
|
||||
object[,] cells = column.Value2;
|
||||
var cells = column.Value2;
|
||||
|
||||
if (cells == null)
|
||||
{
|
||||
@ -115,7 +115,7 @@ public class GuessReader : IReader
|
||||
|
||||
for (int row = 1; row < column.Rows.Count + 1; row++)
|
||||
{
|
||||
object currentCell = cells[row, 1];
|
||||
object currentCell = column.Rows.Count == 1 ? cells : cells[row, 1];
|
||||
if (currentCell == null)
|
||||
{
|
||||
continue;
|
||||
@ -143,23 +143,28 @@ public class GuessReader : IReader
|
||||
return false;
|
||||
}
|
||||
|
||||
successCounter++;
|
||||
if (++successCounter > 5)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return successCounter > 1;
|
||||
return successCounter > 0;
|
||||
}
|
||||
|
||||
private Dictionary<Product, double> GetDictionaryFromColumns(Range productColumn, Range amountColumn)
|
||||
{
|
||||
Dictionary<Product, double> result = new();
|
||||
_progressBar = new("Заполняю словарь значений...", productColumn.Rows.Count);
|
||||
|
||||
for (int row = 1; row < productColumn.Rows.Count + 1; row++)
|
||||
{
|
||||
object[,] amountCells = amountColumn.Value2;
|
||||
object currentAmountCell = amountCells[row, 1];
|
||||
_progressBar.Update();
|
||||
var amountCells = amountColumn.Value2;
|
||||
object currentAmountCell = productColumn.Rows.Count == 1 ? amountCells : amountCells[row, 1];
|
||||
|
||||
object[,] productCells = productColumn.Value2;
|
||||
object currentProductCell = productCells[row, 1];
|
||||
var productCells = productColumn.Value2;
|
||||
object currentProductCell = productColumn.Rows.Count == 1 ? productCells : productCells[row, 1];
|
||||
|
||||
double amountValue = 0.0;
|
||||
|
||||
|
@ -18,7 +18,7 @@ public class CanDoGuess : IDisposable
|
||||
}
|
||||
|
||||
[ExcelFact(Workbook = @"..\..\..\TestWorkbooks\TestSpecificationGuess.xlsx")]
|
||||
public void CanWrite()
|
||||
public void CanWriteMultiplyRows()
|
||||
{
|
||||
Worksheet sourceSheet = Util.Workbook.Worksheets[1];
|
||||
RhSolutionsAddIn.Configuration.SetPriceListPath(Path.GetFullPath(@"..\..\..\TestWorkbooks\TargetSpecificationGuess.xlsx"));
|
||||
@ -34,6 +34,23 @@ public class CanDoGuess : IDisposable
|
||||
Assert.Equal(products.First().Item2.Values.Sum(), targetProducts.First().Item2.Values.Sum());
|
||||
}
|
||||
|
||||
[ExcelFact(Workbook = @"..\..\..\TestWorkbooks\TestSpecificationGuessOneRow.xlsx")]
|
||||
public void CanWriteOneRow()
|
||||
{
|
||||
Worksheet sourceSheet = Util.Workbook.Worksheets[1];
|
||||
RhSolutionsAddIn.Configuration.SetPriceListPath(Path.GetFullPath(@"..\..\..\TestWorkbooks\TargetSpecificationGuessOneRow.xlsx"));
|
||||
var products = _reader.ReadProducts(new[] { sourceSheet });
|
||||
var _writer = new ExcelWriter(Util.Application, RhSolutionsAddIn.Configuration);
|
||||
_writer.WriteProducts(products);
|
||||
Worksheet targetSheet = Util.Application.ActiveWindow.ActiveSheet;
|
||||
var targetProducts = _reader.ReadProducts(new[] { targetSheet });
|
||||
|
||||
Assert.Equal("TestSpecificationGuessOneRow", products.First().Item1);
|
||||
Assert.Equal("TargetSpecificationGuessOneRow", targetProducts.First().Item1);
|
||||
Assert.Equal(products.First().Item2.Count(), targetProducts.First().Item2.Count());
|
||||
Assert.Equal(products.First().Item2.Values.Sum(), targetProducts.First().Item2.Values.Sum());
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
_addIn.AutoClose();
|
||||
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user