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)
|
||||
{
|
||||
int successCounter = 0;
|
||||
object[,] cells = column.Value2;
|
||||
|
||||
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++;
|
||||
}
|
||||
@ -84,6 +92,7 @@ public class GuessReader : IReader
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
double value = 0.0;
|
||||
|
||||
if (currentCell.GetType() == typeof(double))
|
||||
@ -115,26 +124,33 @@ public class GuessReader : IReader
|
||||
|
||||
for (int row = 1; row < productColumn.Rows.Count + 1; row++)
|
||||
{
|
||||
object[,] cells = amountColumn.Value2;
|
||||
object currentCell = cells[row, 1];
|
||||
object[,] amountCells = amountColumn.Value2;
|
||||
object currentAmountCell = amountCells[row, 1];
|
||||
|
||||
object[,] productCells = productColumn.Value2;
|
||||
object currentProductCell = productCells[row, 1];
|
||||
|
||||
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())
|
||||
{
|
||||
Name = "Распознанный артикул"
|
||||
};
|
||||
|
||||
if (currentCell.GetType() == typeof(double))
|
||||
if (currentAmountCell.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))
|
||||
{
|
||||
result[p] += amountValue;
|
||||
|
Loading…
Reference in New Issue
Block a user