Lookup for amount untill last used row only
This commit is contained in:
parent
aa4c949270
commit
3ecfc82b7e
@ -1,4 +1,5 @@
|
||||
using System.IO;
|
||||
using Microsoft.Office.Interop.Excel;
|
||||
using System.IO;
|
||||
|
||||
namespace RhSolutions.Services;
|
||||
|
||||
@ -14,10 +15,12 @@ public class GuessReader : IReader
|
||||
|
||||
public Dictionary<Product, double> ReadProducts(Range range)
|
||||
{
|
||||
_progressBar = new("Ищу колонку с артикулами...", range.Columns.Count);
|
||||
int? productColumnIndex = null;
|
||||
|
||||
for (int column = 1; column < range.Columns.Count + 1; column++)
|
||||
{
|
||||
_progressBar.Update();
|
||||
if (IsProductColumn(range.Columns[column]))
|
||||
{
|
||||
productColumnIndex = column;
|
||||
@ -32,9 +35,11 @@ public class GuessReader : IReader
|
||||
|
||||
int? amountColumnIndex = null;
|
||||
int currentIndex = productColumnIndex.Value + 1;
|
||||
_progressBar = new("Ищу колонку с количеством...", range.Columns.Count);
|
||||
|
||||
while (currentIndex > 0)
|
||||
{
|
||||
_progressBar.Update();
|
||||
if (currentIndex > range.Columns.Count + 1)
|
||||
{
|
||||
currentIndex = productColumnIndex.Value - 1;
|
||||
@ -144,23 +149,22 @@ public class GuessReader : IReader
|
||||
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++)
|
||||
var lastRowIndex = amountColumn.Worksheet
|
||||
.Cells[amountColumn.Rows.Count, amountColumn.Column]
|
||||
.End[XlDirection.xlUp].Row;
|
||||
_progressBar = new("Заполняю словарь значений...", lastRowIndex);
|
||||
|
||||
for (int row = 1; row < lastRowIndex + 1; row++)
|
||||
{
|
||||
_progressBar.Update();
|
||||
var amountCells = amountColumn.Value2;
|
||||
object currentAmountCell = productColumn.Rows.Count == 1 ? amountCells : amountCells[row, 1];
|
||||
|
||||
double? amountValue = currentAmountCell as double?;
|
||||
if (amountValue == null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
var productCells = productColumn.Value2;
|
||||
object currentProductCell = productColumn.Rows.Count == 1 ? productCells : productCells[row, 1];
|
||||
if (currentProductCell == null)
|
||||
double? amountValue = currentAmountCell as double?;
|
||||
|
||||
if (amountValue == null || amountValue == 0 || currentProductCell == null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user