ExcelWriterBase Refactoring
This commit is contained in:
parent
7b8cab3e9e
commit
f89a3eb765
@ -9,12 +9,14 @@ namespace RhSolutions.Services
|
||||
protected ResultBar _resultBar;
|
||||
protected ProgressBar _progressBar;
|
||||
|
||||
protected Worksheet _worksheet;
|
||||
protected Range _amountCell;
|
||||
protected Range _nameCell;
|
||||
protected Range _oldSkuCell;
|
||||
protected Range _programLineCell;
|
||||
protected Range _skuCell;
|
||||
protected Worksheet _worksheet;
|
||||
|
||||
protected bool _appendValues = true;
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
@ -50,7 +52,7 @@ namespace RhSolutions.Services
|
||||
{
|
||||
foreach (var kvp in products.First().Item2)
|
||||
{
|
||||
FillPositionAmountToColumns(kvp, _amountCell.Column);
|
||||
FillAmounts(kvp, _amountCell.Column);
|
||||
_progressBar.Update();
|
||||
}
|
||||
FilterByAmount();
|
||||
@ -71,7 +73,7 @@ namespace RhSolutions.Services
|
||||
|
||||
foreach (var kvp in product.Item2)
|
||||
{
|
||||
FillPositionAmountToColumns(kvp, _amountCell.Column - 1, _amountCell.Column);
|
||||
FillAmounts(kvp, _amountCell.Column - 1, _amountCell.Column);
|
||||
_progressBar.Update();
|
||||
}
|
||||
}
|
||||
@ -81,14 +83,14 @@ namespace RhSolutions.Services
|
||||
}
|
||||
}
|
||||
|
||||
private void FillMissing(KeyValuePair<Product, double> positionAmount, params int[] columns)
|
||||
private void WriteOutMissing(KeyValuePair<Product, double> productAmount, params int[] columns)
|
||||
{
|
||||
Range worksheetCells = _worksheet.Cells;
|
||||
Range worksheetRows = _worksheet.Rows;
|
||||
int skuColumn = _skuCell.Column;
|
||||
int groupColumn = _programLineCell.Column;
|
||||
int nameColumn = _nameCell.Column;
|
||||
Product product = positionAmount.Key;
|
||||
Product product = productAmount.Key;
|
||||
|
||||
int row = worksheetCells[worksheetRows.Count, skuColumn]
|
||||
.End[XlDirection.xlUp]
|
||||
@ -115,75 +117,73 @@ namespace RhSolutions.Services
|
||||
foreach (int column in columns)
|
||||
{
|
||||
Range cell = worksheetCells[row, column];
|
||||
cell.AddValue(positionAmount.Value);
|
||||
cell.AddValue(productAmount.Value);
|
||||
}
|
||||
}
|
||||
|
||||
private void FillPositionAmountToColumns(KeyValuePair<Product, double> positionAmount, params int[] columns)
|
||||
{
|
||||
Range worksheetCells = _worksheet.Cells;
|
||||
Range skuColumn = _skuCell.EntireColumn;
|
||||
|
||||
int? row = GetPositionRow(skuColumn, positionAmount.Key.ProductSku, positionAmount.Key.ProductLines.FirstOrDefault());
|
||||
|
||||
if (row != null)
|
||||
private void FillCells(double amount, int row, int[] columns)
|
||||
{
|
||||
foreach (int column in columns)
|
||||
{
|
||||
Range cell = worksheetCells[row, column];
|
||||
cell.AddValue(positionAmount.Value);
|
||||
Range cell = _worksheet.Cells[row, column];
|
||||
if (_appendValues)
|
||||
{
|
||||
cell.AddValue(amount);
|
||||
}
|
||||
else
|
||||
{
|
||||
cell.Value2 = amount;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void FillAmounts(KeyValuePair<Product, double> positionAmount, params int[] columns)
|
||||
{
|
||||
Range range = _skuCell.EntireColumn;
|
||||
ProductSku sku = positionAmount.Key.ProductSku;
|
||||
string productLine = positionAmount.Key.ProductLines.FirstOrDefault();
|
||||
|
||||
int? row = GetPositionRow(range, sku, productLine);
|
||||
|
||||
if (row != null)
|
||||
{
|
||||
FillCells(positionAmount.Value, row.Value, columns);
|
||||
_resultBar.IncrementSuccess();
|
||||
return;
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
if (_oldSkuCell != null)
|
||||
{
|
||||
row = GetPositionRow(_oldSkuCell.EntireColumn, positionAmount.Key.ProductSku, positionAmount.Key.ProductLines.FirstOrDefault());
|
||||
range = _oldSkuCell.EntireColumn;
|
||||
row = GetPositionRow(range, sku, productLine);
|
||||
}
|
||||
|
||||
if (row == null)
|
||||
{
|
||||
range = _skuCell.EntireColumn;
|
||||
row = GetPositionRow(range, sku, productLine, true);
|
||||
}
|
||||
|
||||
if (row != null)
|
||||
{
|
||||
Range nameCell = worksheetCells[row, _nameCell.Column];
|
||||
Range nameCell = _worksheet.Cells[row, _nameCell.Column];
|
||||
if (!Regex.IsMatch(nameCell.Value2, @"арт. \d{11}"))
|
||||
{
|
||||
nameCell.AddValue($"(замена арт. {positionAmount.Key.ProductSku})");
|
||||
}
|
||||
|
||||
foreach (int column in columns)
|
||||
{
|
||||
Range cell = worksheetCells[row, column];
|
||||
cell.AddValue(positionAmount.Value);
|
||||
nameCell.AddValue($"(замена арт. {sku})");
|
||||
}
|
||||
|
||||
FillCells(positionAmount.Value, row.Value, columns);
|
||||
_resultBar.IncrementReplaced();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
row = GetPositionRow(skuColumn, positionAmount.Key.ProductSku, positionAmount.Key.ProductLines.FirstOrDefault(), true);
|
||||
|
||||
if (row != null)
|
||||
else
|
||||
{
|
||||
Range nameCell = worksheetCells[row, _nameCell.Column];
|
||||
if (!Regex.IsMatch(nameCell.Value2, @"арт. \d{11}"))
|
||||
{
|
||||
nameCell.AddValue($"(замена арт. {positionAmount.Key.ProductSku})");
|
||||
}
|
||||
|
||||
foreach (int column in columns)
|
||||
{
|
||||
Range cell = worksheetCells[row, column];
|
||||
cell.AddValue(positionAmount.Value);
|
||||
}
|
||||
|
||||
_resultBar.IncrementReplaced();
|
||||
return;
|
||||
}
|
||||
|
||||
FillMissing(positionAmount, columns);
|
||||
WriteOutMissing(positionAmount, columns);
|
||||
_resultBar.IncrementNotFound();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void FilterByAmount()
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user