Fix null reference
This commit is contained in:
parent
a56300a620
commit
c0c656c82c
@ -55,9 +55,17 @@ public class GuessReader : IReader
|
|||||||
private bool IsProductColumn(Range column)
|
private bool IsProductColumn(Range column)
|
||||||
{
|
{
|
||||||
int successCounter = 0;
|
int successCounter = 0;
|
||||||
|
object[,] cells = column.Value2;
|
||||||
|
|
||||||
for (int row = 1; row < column.Rows.Count + 1; row++)
|
for (int row = 1; row < column.Rows.Count + 1; row++)
|
||||||
{
|
{
|
||||||
if (ProductSku.TryParse(column.Cells[row, 1].Value2.ToString(), out IEnumerable<ProductSku> skus))
|
object currentCell = cells[row, 1];
|
||||||
|
if (currentCell == null)
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ProductSku.TryParse(currentCell.ToString(), out IEnumerable<ProductSku> skus))
|
||||||
{
|
{
|
||||||
successCounter++;
|
successCounter++;
|
||||||
}
|
}
|
||||||
@ -84,6 +92,7 @@ public class GuessReader : IReader
|
|||||||
{
|
{
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
double value = 0.0;
|
double value = 0.0;
|
||||||
|
|
||||||
if (currentCell.GetType() == typeof(double))
|
if (currentCell.GetType() == typeof(double))
|
||||||
@ -115,26 +124,33 @@ public class GuessReader : IReader
|
|||||||
|
|
||||||
for (int row = 1; row < productColumn.Rows.Count + 1; row++)
|
for (int row = 1; row < productColumn.Rows.Count + 1; row++)
|
||||||
{
|
{
|
||||||
object[,] cells = amountColumn.Value2;
|
object[,] amountCells = amountColumn.Value2;
|
||||||
object currentCell = cells[row, 1];
|
object currentAmountCell = amountCells[row, 1];
|
||||||
|
|
||||||
|
object[,] productCells = productColumn.Value2;
|
||||||
|
object currentProductCell = productCells[row, 1];
|
||||||
|
|
||||||
double amountValue = 0.0;
|
double amountValue = 0.0;
|
||||||
if (ProductSku.TryParse(productColumn.Cells[row, 1].Value2.ToString(), out IEnumerable<ProductSku> skus) &&
|
|
||||||
currentCell != null)
|
if (currentAmountCell == null || currentProductCell == null)
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ProductSku.TryParse(currentProductCell.ToString(), out IEnumerable<ProductSku> skus))
|
||||||
{
|
{
|
||||||
Product p = new(skus.First())
|
Product p = new(skus.First())
|
||||||
{
|
{
|
||||||
Name = "Распознанный артикул"
|
Name = "Распознанный артикул"
|
||||||
};
|
};
|
||||||
|
if (currentAmountCell.GetType() == typeof(double))
|
||||||
if (currentCell.GetType() == typeof(double))
|
|
||||||
{
|
{
|
||||||
amountValue = (double)currentCell;
|
amountValue = (double)currentAmountCell;
|
||||||
}
|
}
|
||||||
else if (currentCell.GetType() == typeof(string))
|
else if (currentAmountCell.GetType() == typeof(string))
|
||||||
{
|
{
|
||||||
double.TryParse((string)currentCell, out amountValue);
|
double.TryParse((string)currentAmountCell, out amountValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (result.ContainsKey(p))
|
if (result.ContainsKey(p))
|
||||||
{
|
{
|
||||||
result[p] += amountValue;
|
result[p] += amountValue;
|
||||||
|
Loading…
Reference in New Issue
Block a user