Refactoring Guess Reader
This commit is contained in:
parent
a9aa1f30c5
commit
79eeb2a206
@ -1,4 +1,5 @@
|
||||
using System.IO;
|
||||
using Microsoft.Office.Interop.Excel;
|
||||
using System.IO;
|
||||
|
||||
namespace RhSolutions.Services;
|
||||
|
||||
@ -56,7 +57,6 @@ public class GuessReader : IReader
|
||||
if (amountColumnIndex == 0)
|
||||
{
|
||||
amountColumnIndex = amountColumnIndeces
|
||||
.OrderBy(i => i)
|
||||
.Where(i => i < productColumnIndex)
|
||||
.LastOrDefault();
|
||||
}
|
||||
@ -121,19 +121,9 @@ public class GuessReader : IReader
|
||||
continue;
|
||||
}
|
||||
|
||||
double value = 0.0;
|
||||
double? value = currentCell as double?;
|
||||
|
||||
if (currentCell.GetType() == typeof(double))
|
||||
{
|
||||
value = (double)currentCell;
|
||||
}
|
||||
|
||||
else if (currentCell.GetType() == typeof(string))
|
||||
{
|
||||
double.TryParse((string)currentCell, out value);
|
||||
}
|
||||
|
||||
if (value == 0)
|
||||
if (value == null || value == 0)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
@ -143,7 +133,7 @@ public class GuessReader : IReader
|
||||
return false;
|
||||
}
|
||||
|
||||
if (++successCounter > 5)
|
||||
if (++successCounter > 3)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
@ -163,37 +153,28 @@ public class GuessReader : IReader
|
||||
var amountCells = amountColumn.Value2;
|
||||
object currentAmountCell = productColumn.Rows.Count == 1 ? amountCells : amountCells[row, 1];
|
||||
|
||||
var productCells = productColumn.Value2;
|
||||
object currentProductCell = productColumn.Rows.Count == 1 ? productCells : productCells[row, 1];
|
||||
|
||||
double amountValue = 0.0;
|
||||
|
||||
if (currentAmountCell == null || currentProductCell == null)
|
||||
double? amountValue = currentAmountCell as double?;
|
||||
if (amountValue == null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
var productCells = productColumn.Value2;
|
||||
object currentProductCell = productColumn.Rows.Count == 1 ? productCells : productCells[row, 1];
|
||||
|
||||
if (ProductSku.TryParse(currentProductCell.ToString(), out IEnumerable<ProductSku> skus))
|
||||
{
|
||||
Product p = new(skus.First())
|
||||
{
|
||||
Name = "Распознанный артикул"
|
||||
};
|
||||
if (currentAmountCell.GetType() == typeof(double))
|
||||
{
|
||||
amountValue = (double)currentAmountCell;
|
||||
}
|
||||
else if (currentAmountCell.GetType() == typeof(string))
|
||||
{
|
||||
double.TryParse((string)currentAmountCell, out amountValue);
|
||||
}
|
||||
if (result.ContainsKey(p))
|
||||
{
|
||||
result[p] += amountValue;
|
||||
result[p] += amountValue.Value;
|
||||
}
|
||||
else
|
||||
{
|
||||
result.Add(p, amountValue);
|
||||
result.Add(p, amountValue.Value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user