Compare commits
19 Commits
50543ae697
...
5fbfd3732f
Author | SHA1 | Date | |
---|---|---|---|
|
5fbfd3732f | ||
|
9f4823378f | ||
|
6a5038246f | ||
|
c17771a5d3 | ||
|
101c1d4397 | ||
|
2224a98d32 | ||
|
0da818da3e | ||
|
5153e951e4 | ||
|
b9cdad649a | ||
|
2c44c5d2df | ||
|
a9d7ac710e | ||
|
a73cc46449 | ||
|
63a962f495 | ||
|
8c134644ba | ||
|
f570dd9a2d | ||
|
dc92388748 | ||
|
98bb135b62 | ||
|
f89a3eb765 | ||
|
7b8cab3e9e |
@ -25,13 +25,16 @@ public sealed class RhSolutionsAddIn : IExcelAddIn
|
|||||||
.AddSingleton<IAddInConfiguration, AddInConfiguration>()
|
.AddSingleton<IAddInConfiguration, AddInConfiguration>()
|
||||||
.AddSingleton<IDatabaseClient, DatabaseClient>()
|
.AddSingleton<IDatabaseClient, DatabaseClient>()
|
||||||
.AddSingleton<ICurrencyClient, CurrencyClient>()
|
.AddSingleton<ICurrencyClient, CurrencyClient>()
|
||||||
|
.AddSingleton<ISleevesCalculator, SleevesCalculator>()
|
||||||
.AddTransient<IFileDialog, FileDialog>();
|
.AddTransient<IFileDialog, FileDialog>();
|
||||||
|
|
||||||
Services.AddSingleton<WriterFactory>();
|
Services.AddSingleton<WriterFactory>();
|
||||||
Services.AddTransient<ExcelWriter>()
|
Services.AddTransient<NewPriceWriter>()
|
||||||
.AddTransient<IWriter, ExcelWriter>(s => s.GetService<ExcelWriter>());
|
.AddTransient<IWriter, NewPriceWriter>(s => s.GetService<NewPriceWriter>());
|
||||||
Services.AddTransient<DxfWriter>()
|
Services.AddTransient<DxfWriter>()
|
||||||
.AddTransient<IWriter, DxfWriter>(s => s.GetService<DxfWriter>());
|
.AddTransient<IWriter, DxfWriter>(s => s.GetService<DxfWriter>());
|
||||||
|
Services.AddTransient<CurrentPriceWriter>()
|
||||||
|
.AddTransient<IWriter, CurrentPriceWriter>(s => s.GetService<CurrentPriceWriter>());
|
||||||
|
|
||||||
Services.AddSingleton<ReaderFactory>();
|
Services.AddSingleton<ReaderFactory>();
|
||||||
Services.AddTransient<ExcelReader>()
|
Services.AddTransient<ExcelReader>()
|
||||||
|
@ -28,7 +28,8 @@ public class RibbonController : ExcelRibbon
|
|||||||
<button id='export' getEnabled='GetExportEnabled' label='Экспорт в новый файл' size='normal' imageMso='PivotExportToExcel' onAction='OnToolPressed'/>
|
<button id='export' getEnabled='GetExportEnabled' label='Экспорт в новый файл' size='normal' imageMso='PivotExportToExcel' onAction='OnToolPressed'/>
|
||||||
<button id='convert' getEnabled='GetConvertEnabled' label='Актуализировать' size='normal' imageMso='FileUpdate' onAction='OnToolPressed'/>
|
<button id='convert' getEnabled='GetConvertEnabled' label='Актуализировать' size='normal' imageMso='FileUpdate' onAction='OnToolPressed'/>
|
||||||
<button id='merge' label='Объединить' size='normal' imageMso='Copy' onAction='OnToolPressed'/>
|
<button id='merge' label='Объединить' size='normal' imageMso='Copy' onAction='OnToolPressed'/>
|
||||||
<button id='Guessexport' getEnabled='GetGuessEnabled' label='Найти и экспортировать' size='normal' imageMso='ControlWizards' onAction='OnToolPressed'/>
|
<button id='guess' getEnabled='GetGuessEnabled' label='Найти и экспортировать' size='normal' imageMso='ControlWizards' onAction='OnToolPressed'/>
|
||||||
|
<button id='fillsleeves' getEnabled='GetSleevesEnabled' label='Подобрать гильзы' size='normal' imageMso='CreateQueryFromWizard' onAction='OnToolPressed'/>
|
||||||
<button id='dxfexport' getEnabled='GetDxfEnabled' label='Экспортировать в DXF' size='normal' imageMso='ExportExcel' onAction='OnToolPressed'/>
|
<button id='dxfexport' getEnabled='GetDxfEnabled' label='Экспортировать в DXF' size='normal' imageMso='ExportExcel' onAction='OnToolPressed'/>
|
||||||
</group>
|
</group>
|
||||||
<group id='rausettings' getLabel='GetVersionLabel'>
|
<group id='rausettings' getLabel='GetVersionLabel'>
|
||||||
@ -84,6 +85,7 @@ public class RibbonController : ExcelRibbon
|
|||||||
|
|
||||||
public bool GetConvertEnabled(IRibbonControl control) => _workbookIsValid;
|
public bool GetConvertEnabled(IRibbonControl control) => _workbookIsValid;
|
||||||
public bool GetDxfEnabled(IRibbonControl control) => _workbookIsValid;
|
public bool GetDxfEnabled(IRibbonControl control) => _workbookIsValid;
|
||||||
|
public bool GetSleevesEnabled(IRibbonControl control) => _workbookIsValid;
|
||||||
public bool GetGuessEnabled(IRibbonControl control) => RhSolutionsAddIn.Excel.ActiveWorkbook != null && !_workbookIsValid;
|
public bool GetGuessEnabled(IRibbonControl control) => RhSolutionsAddIn.Excel.ActiveWorkbook != null && !_workbookIsValid;
|
||||||
|
|
||||||
public bool GetExportEnabled(IRibbonControl control)
|
public bool GetExportEnabled(IRibbonControl control)
|
||||||
|
@ -31,5 +31,5 @@ using System.Runtime.InteropServices;
|
|||||||
// You can specify all the values or you can default the Build and Revision Numbers
|
// You can specify all the values or you can default the Build and Revision Numbers
|
||||||
// by using the '*' as shown below:
|
// by using the '*' as shown below:
|
||||||
// [assembly: AssemblyVersion("1.0.*")]
|
// [assembly: AssemblyVersion("1.0.*")]
|
||||||
[assembly: AssemblyVersion("1.8.4.0")]
|
[assembly: AssemblyVersion("1.8.5.0")]
|
||||||
[assembly: AssemblyFileVersion("1.8.4.0")]
|
[assembly: AssemblyFileVersion("1.8.5.0")]
|
||||||
|
19
RhSolutions.AddIn/Services/CurrentPriceWriter.cs
Normal file
19
RhSolutions.AddIn/Services/CurrentPriceWriter.cs
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
#if !NET472
|
||||||
|
using System.Runtime.Versioning;
|
||||||
|
using RhSolutions.Tools;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
namespace RhSolutions.Services;
|
||||||
|
|
||||||
|
public class CurrentPriceWriter : ExcelWriterBase, IWriter, IDisposable
|
||||||
|
{
|
||||||
|
public CurrentPriceWriter(Application application, IAddInConfiguration configuration)
|
||||||
|
{
|
||||||
|
_application = application;
|
||||||
|
_resultBar = new();
|
||||||
|
_headers = configuration.GetPriceListHeaders();
|
||||||
|
_worksheet = _application.ActiveSheet;
|
||||||
|
_appendValues = false;
|
||||||
|
}
|
||||||
|
}
|
@ -1,275 +0,0 @@
|
|||||||
#if !NET472
|
|
||||||
using System.Runtime.Versioning;
|
|
||||||
using RhSolutions.Tools;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
using System.Text.RegularExpressions;
|
|
||||||
|
|
||||||
namespace RhSolutions.Services;
|
|
||||||
|
|
||||||
#if !NET472
|
|
||||||
[SupportedOSPlatform("windows")]
|
|
||||||
#endif
|
|
||||||
public class ExcelWriter : IWriter, IDisposable
|
|
||||||
{
|
|
||||||
private readonly Application _application;
|
|
||||||
private Worksheet _worksheet;
|
|
||||||
private readonly ResultBar _resultBar;
|
|
||||||
private readonly Dictionary<string, string> _headers;
|
|
||||||
private readonly string _pricelistPath;
|
|
||||||
private ProgressBar _progressBar;
|
|
||||||
|
|
||||||
private Range _amountCell,
|
|
||||||
_skuCell,
|
|
||||||
_programLineCell,
|
|
||||||
_nameCell,
|
|
||||||
_oldSkuCell;
|
|
||||||
|
|
||||||
public ExcelWriter(Application application, IAddInConfiguration configuration)
|
|
||||||
{
|
|
||||||
_application = application;
|
|
||||||
_pricelistPath = configuration.GetPriceListPath();
|
|
||||||
_resultBar = new();
|
|
||||||
_headers = configuration.GetPriceListHeaders();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void WriteProducts(Dictionary<Product, double> products)
|
|
||||||
{
|
|
||||||
WriteProducts(new[] { (string.Empty, products) });
|
|
||||||
}
|
|
||||||
|
|
||||||
public void WriteProducts(IEnumerable<(string, Dictionary<Product, double>)> products)
|
|
||||||
{
|
|
||||||
_worksheet = OpenNewPrice();
|
|
||||||
|
|
||||||
if (!_worksheet.IsValidSource())
|
|
||||||
{
|
|
||||||
_application.ActiveWorkbook.Close();
|
|
||||||
throw new ArgumentException(
|
|
||||||
$"Целевой файл {_application.ActiveWorkbook.Name} не является прайс-листом.");
|
|
||||||
}
|
|
||||||
|
|
||||||
_amountCell = _worksheet.Cells.Find(_headers["Amount"]);
|
|
||||||
_skuCell = _worksheet.Cells.Find(_headers["Sku"]);
|
|
||||||
_programLineCell = _worksheet.Cells.Find(_headers["ProductLine"]);
|
|
||||||
_nameCell = _worksheet.Cells.Find(_headers["Name"]);
|
|
||||||
_oldSkuCell = _worksheet.Cells.Find(_headers["OldSku"]);
|
|
||||||
|
|
||||||
_progressBar = new("Заполняю строки...", products
|
|
||||||
.Select(p => p.Item2)
|
|
||||||
.Sum(set => set.Count));
|
|
||||||
|
|
||||||
if (products.Count() == 1)
|
|
||||||
{
|
|
||||||
foreach (var kvp in products.First().Item2)
|
|
||||||
{
|
|
||||||
FillPositionAmountToColumns(kvp, _amountCell.Column);
|
|
||||||
_progressBar.Update();
|
|
||||||
}
|
|
||||||
FilterByAmount();
|
|
||||||
_resultBar.Update();
|
|
||||||
}
|
|
||||||
|
|
||||||
else
|
|
||||||
{
|
|
||||||
foreach (var product in products)
|
|
||||||
{
|
|
||||||
_worksheet.Columns[_amountCell.Column]
|
|
||||||
.EntireColumn
|
|
||||||
.Insert(XlInsertShiftDirection.xlShiftToRight, XlInsertFormatOrigin.xlFormatFromRightOrBelow);
|
|
||||||
|
|
||||||
Range newColumnHeader = _worksheet.Cells[_amountCell.Row, _amountCell.Column - 1];
|
|
||||||
newColumnHeader.Value2 = $"{product.Item1}";
|
|
||||||
newColumnHeader.WrapText = true;
|
|
||||||
|
|
||||||
foreach (var kvp in product.Item2)
|
|
||||||
{
|
|
||||||
FillPositionAmountToColumns(kvp, _amountCell.Column - 1, _amountCell.Column);
|
|
||||||
_progressBar.Update();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
FilterByAmount();
|
|
||||||
_resultBar.Update();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private Worksheet OpenNewPrice()
|
|
||||||
{
|
|
||||||
if (_application.Workbooks
|
|
||||||
.Cast<Workbook>()
|
|
||||||
.FirstOrDefault(w => w.FullName == _pricelistPath) != null)
|
|
||||||
{
|
|
||||||
throw new ArgumentException("Шаблонный файл редактируется в другом месте");
|
|
||||||
}
|
|
||||||
|
|
||||||
return _application.Workbooks.Open(_pricelistPath, null, true).ActiveSheet;
|
|
||||||
}
|
|
||||||
|
|
||||||
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)
|
|
||||||
{
|
|
||||||
foreach (int column in columns)
|
|
||||||
{
|
|
||||||
Range cell = worksheetCells[row, column];
|
|
||||||
cell.AddValue(positionAmount.Value);
|
|
||||||
}
|
|
||||||
|
|
||||||
_resultBar.IncrementSuccess();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (_oldSkuCell != null)
|
|
||||||
{
|
|
||||||
row = GetPositionRow(_oldSkuCell.EntireColumn, positionAmount.Key.ProductSku, positionAmount.Key.ProductLines.FirstOrDefault());
|
|
||||||
|
|
||||||
if (row != null)
|
|
||||||
{
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
row = GetPositionRow(skuColumn, positionAmount.Key.ProductSku, positionAmount.Key.ProductLines.FirstOrDefault(), true);
|
|
||||||
|
|
||||||
if (row != null)
|
|
||||||
{
|
|
||||||
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);
|
|
||||||
_resultBar.IncrementNotFound();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void FillMissing(KeyValuePair<Product, double> positionAmount, 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;
|
|
||||||
|
|
||||||
int row = worksheetCells[worksheetRows.Count, skuColumn]
|
|
||||||
.End[XlDirection.xlUp]
|
|
||||||
.Row + 1;
|
|
||||||
|
|
||||||
worksheetRows[row]
|
|
||||||
.EntireRow
|
|
||||||
.Insert(XlInsertShiftDirection.xlShiftDown, XlInsertFormatOrigin.xlFormatFromLeftOrAbove);
|
|
||||||
|
|
||||||
Range previous = worksheetRows[row - 1];
|
|
||||||
Range current = worksheetRows[row];
|
|
||||||
|
|
||||||
previous.Copy(current);
|
|
||||||
current.ClearContents();
|
|
||||||
|
|
||||||
worksheetCells[row, groupColumn].Value2 = product.ProductLines.FirstOrDefault() ?? string.Empty;
|
|
||||||
worksheetCells[row, nameColumn].Value2 = $"{product.Name} (не найден арт. {product.ProductSku})";
|
|
||||||
worksheetCells[row, skuColumn].Value2 = "???";
|
|
||||||
if (_oldSkuCell != null)
|
|
||||||
{
|
|
||||||
worksheetCells[row, _oldSkuCell.Column].Value2 = product.ProductSku;
|
|
||||||
}
|
|
||||||
|
|
||||||
foreach (int column in columns)
|
|
||||||
{
|
|
||||||
Range cell = worksheetCells[row, column];
|
|
||||||
cell.AddValue(positionAmount.Value);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private int? GetPositionRow(Range range, ProductSku sku, string productLine, bool justArticle = false)
|
|
||||||
{
|
|
||||||
string lookupString = justArticle ? sku.Article : sku.ToString();
|
|
||||||
Range found = range.Find(lookupString);
|
|
||||||
string foundGroupValue;
|
|
||||||
string foundSkuValue;
|
|
||||||
|
|
||||||
if (found == null)
|
|
||||||
{
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
int firstFoundRow = found.Row;
|
|
||||||
|
|
||||||
while (true)
|
|
||||||
{
|
|
||||||
foundSkuValue = _worksheet.Cells[found.Row, range.Column].Value2.ToString();
|
|
||||||
foundGroupValue = _worksheet.Cells[found.Row, _programLineCell.Column].Value2.ToString();
|
|
||||||
|
|
||||||
if (ProductSku.TryParse(foundSkuValue, out var skus))
|
|
||||||
{
|
|
||||||
if (skus.Any(s => s.Article == sku.Article) &&
|
|
||||||
(string.IsNullOrEmpty(productLine) || productLine.Equals(foundGroupValue)) )
|
|
||||||
{
|
|
||||||
return found.Row;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
found = range.FindNext(found);
|
|
||||||
|
|
||||||
if (found.Row == firstFoundRow)
|
|
||||||
{
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
found = range.FindNext(found);
|
|
||||||
|
|
||||||
if (found.Row == firstFoundRow)
|
|
||||||
{
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void FilterByAmount()
|
|
||||||
{
|
|
||||||
AutoFilter filter = _worksheet.AutoFilter;
|
|
||||||
int startColumn = filter.Range.Column;
|
|
||||||
|
|
||||||
filter.Range.AutoFilter(_amountCell.Column - startColumn + 1, "<>0", XlAutoFilterOperator.xlAnd, "<>");
|
|
||||||
_worksheet.Range["A1"].Activate();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void Dispose()
|
|
||||||
{
|
|
||||||
_progressBar?.Dispose();
|
|
||||||
_resultBar?.Dispose();
|
|
||||||
}
|
|
||||||
}
|
|
259
RhSolutions.AddIn/Services/ExcelWriterBase.cs
Normal file
259
RhSolutions.AddIn/Services/ExcelWriterBase.cs
Normal file
@ -0,0 +1,259 @@
|
|||||||
|
using System.Text.RegularExpressions;
|
||||||
|
|
||||||
|
namespace RhSolutions.Services
|
||||||
|
{
|
||||||
|
public abstract class ExcelWriterBase
|
||||||
|
{
|
||||||
|
protected Application _application;
|
||||||
|
protected Dictionary<string, string> _headers;
|
||||||
|
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 bool _appendValues = true;
|
||||||
|
|
||||||
|
public void Dispose()
|
||||||
|
{
|
||||||
|
_progressBar?.Dispose();
|
||||||
|
_resultBar?.Dispose();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void WriteProducts(Dictionary<Product, double> products)
|
||||||
|
{
|
||||||
|
WriteProducts(new[] { (string.Empty, products) });
|
||||||
|
}
|
||||||
|
|
||||||
|
public void WriteProducts(IEnumerable<(string, Dictionary<Product, double>)> products)
|
||||||
|
{
|
||||||
|
if (!_worksheet.IsValidSource())
|
||||||
|
{
|
||||||
|
_application.ActiveWorkbook.Close();
|
||||||
|
throw new ArgumentException(
|
||||||
|
$"Целевой файл {_application.ActiveWorkbook.Name} не является прайс-листом.");
|
||||||
|
}
|
||||||
|
|
||||||
|
ShowFilteredData();
|
||||||
|
|
||||||
|
_amountCell = _worksheet.Cells.Find(_headers["Amount"]);
|
||||||
|
_skuCell = _worksheet.Cells.Find(_headers["Sku"]);
|
||||||
|
_programLineCell = _worksheet.Cells.Find(_headers["ProductLine"]);
|
||||||
|
_nameCell = _worksheet.Cells.Find(_headers["Name"]);
|
||||||
|
_oldSkuCell = _worksheet.Cells.Find(_headers["OldSku"]);
|
||||||
|
|
||||||
|
_progressBar = new("Заполняю строки...", products
|
||||||
|
.Select(p => p.Item2)
|
||||||
|
.Sum(set => set.Count));
|
||||||
|
|
||||||
|
if (products.Count() == 1)
|
||||||
|
{
|
||||||
|
foreach (var kvp in products.First().Item2)
|
||||||
|
{
|
||||||
|
FillAmounts(kvp, _amountCell.Column);
|
||||||
|
_progressBar.Update();
|
||||||
|
}
|
||||||
|
FilterByAmount();
|
||||||
|
_resultBar.Update();
|
||||||
|
}
|
||||||
|
|
||||||
|
else
|
||||||
|
{
|
||||||
|
foreach (var product in products)
|
||||||
|
{
|
||||||
|
_worksheet.Columns[_amountCell.Column]
|
||||||
|
.EntireColumn
|
||||||
|
.Insert(XlInsertShiftDirection.xlShiftToRight, XlInsertFormatOrigin.xlFormatFromRightOrBelow);
|
||||||
|
|
||||||
|
Range newColumnHeader = _worksheet.Cells[_amountCell.Row, _amountCell.Column - 1];
|
||||||
|
newColumnHeader.Value2 = $"{product.Item1}";
|
||||||
|
newColumnHeader.WrapText = true;
|
||||||
|
|
||||||
|
foreach (var kvp in product.Item2)
|
||||||
|
{
|
||||||
|
FillAmounts(kvp, _amountCell.Column - 1, _amountCell.Column);
|
||||||
|
_progressBar.Update();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
FilterByAmount();
|
||||||
|
_resultBar.Update();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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 = productAmount.Key;
|
||||||
|
|
||||||
|
int row = worksheetCells[worksheetRows.Count, skuColumn]
|
||||||
|
.End[XlDirection.xlUp]
|
||||||
|
.Row + 1;
|
||||||
|
|
||||||
|
worksheetRows[row]
|
||||||
|
.EntireRow
|
||||||
|
.Insert(XlInsertShiftDirection.xlShiftDown, XlInsertFormatOrigin.xlFormatFromLeftOrAbove);
|
||||||
|
|
||||||
|
Range previous = worksheetRows[row - 1];
|
||||||
|
Range current = worksheetRows[row];
|
||||||
|
|
||||||
|
previous.Copy(current);
|
||||||
|
current.ClearContents();
|
||||||
|
|
||||||
|
worksheetCells[row, groupColumn].Value2 = product.ProductLines.FirstOrDefault() ?? string.Empty;
|
||||||
|
worksheetCells[row, nameColumn].Value2 = $"{product.Name} (не найден арт. {product.ProductSku})";
|
||||||
|
worksheetCells[row, skuColumn].Value2 = "???";
|
||||||
|
if (_oldSkuCell != null)
|
||||||
|
{
|
||||||
|
worksheetCells[row, _oldSkuCell.Column].Value2 = product.ProductSku;
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach (int column in columns)
|
||||||
|
{
|
||||||
|
Range cell = worksheetCells[row, column];
|
||||||
|
cell.AddValue(productAmount.Value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void FillCells(double amount, int row, int[] columns)
|
||||||
|
{
|
||||||
|
foreach (int column in columns)
|
||||||
|
{
|
||||||
|
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();
|
||||||
|
}
|
||||||
|
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (_oldSkuCell != null)
|
||||||
|
{
|
||||||
|
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 = _worksheet.Cells[row, _nameCell.Column];
|
||||||
|
if (!Regex.IsMatch(nameCell.Value2, @"арт. \d{11}"))
|
||||||
|
{
|
||||||
|
nameCell.AddValue($"(замена арт. {sku})");
|
||||||
|
}
|
||||||
|
|
||||||
|
FillCells(positionAmount.Value, row.Value, columns);
|
||||||
|
_resultBar.IncrementReplaced();
|
||||||
|
}
|
||||||
|
|
||||||
|
else
|
||||||
|
{
|
||||||
|
WriteOutMissing(positionAmount, columns);
|
||||||
|
_resultBar.IncrementNotFound();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void FilterByAmount()
|
||||||
|
{
|
||||||
|
if (_worksheet.AutoFilterMode)
|
||||||
|
{
|
||||||
|
AutoFilter filter = _worksheet.AutoFilter;
|
||||||
|
int startColumn = filter.Range.Column;
|
||||||
|
|
||||||
|
filter.Range.AutoFilter(_amountCell.Column - startColumn + 1, "<>0", XlAutoFilterOperator.xlAnd, "<>");
|
||||||
|
_worksheet.Range["A1"].Activate();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void ShowFilteredData()
|
||||||
|
{
|
||||||
|
if (_worksheet.AutoFilterMode)
|
||||||
|
{
|
||||||
|
AutoFilter filter = _worksheet.AutoFilter;
|
||||||
|
filter.ShowAllData();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private int? GetPositionRow(Range range, ProductSku sku, string productLine, bool justArticle = false)
|
||||||
|
{
|
||||||
|
string lookupString = justArticle ? sku.Article : sku.ToString();
|
||||||
|
Range found = range.Find(lookupString);
|
||||||
|
string foundGroupValue;
|
||||||
|
string foundSkuValue;
|
||||||
|
|
||||||
|
if (found == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
int firstFoundRow = found.Row;
|
||||||
|
|
||||||
|
while (true)
|
||||||
|
{
|
||||||
|
foundSkuValue = _worksheet.Cells[found.Row, range.Column].Value2.ToString();
|
||||||
|
foundGroupValue = _worksheet.Cells[found.Row, _programLineCell.Column].Value2.ToString();
|
||||||
|
|
||||||
|
if (ProductSku.TryParse(foundSkuValue, out var skus))
|
||||||
|
{
|
||||||
|
if (skus.Any(s => s.Article == sku.Article) &&
|
||||||
|
(string.IsNullOrEmpty(productLine) || productLine.Equals(foundGroupValue)))
|
||||||
|
{
|
||||||
|
return found.Row;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
found = range.FindNext(found);
|
||||||
|
|
||||||
|
if (found.Row == firstFoundRow)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
found = range.FindNext(found);
|
||||||
|
|
||||||
|
if (found.Row == firstFoundRow)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
6
RhSolutions.AddIn/Services/ISleevesCalculator.cs
Normal file
6
RhSolutions.AddIn/Services/ISleevesCalculator.cs
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
namespace RhSolutions.Services;
|
||||||
|
|
||||||
|
public interface ISleevesCalculator
|
||||||
|
{
|
||||||
|
public Dictionary<Product, double> CalculateSleeves(Dictionary<Product, double> products);
|
||||||
|
}
|
34
RhSolutions.AddIn/Services/NewPriceWriter.cs
Normal file
34
RhSolutions.AddIn/Services/NewPriceWriter.cs
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
#if !NET472
|
||||||
|
using System.Runtime.Versioning;
|
||||||
|
using RhSolutions.Tools;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
using System.Text.RegularExpressions;
|
||||||
|
|
||||||
|
namespace RhSolutions.Services;
|
||||||
|
|
||||||
|
#if !NET472
|
||||||
|
[SupportedOSPlatform("windows")]
|
||||||
|
#endif
|
||||||
|
public class NewPriceWriter : ExcelWriterBase, IWriter, IDisposable
|
||||||
|
{
|
||||||
|
public NewPriceWriter(Application application, IAddInConfiguration configuration)
|
||||||
|
{
|
||||||
|
_application = application;
|
||||||
|
_resultBar = new();
|
||||||
|
_headers = configuration.GetPriceListHeaders();
|
||||||
|
_worksheet = OpenNewPrice(configuration.GetPriceListPath());
|
||||||
|
}
|
||||||
|
|
||||||
|
private Worksheet OpenNewPrice(string pricelistPath)
|
||||||
|
{
|
||||||
|
if (_application.Workbooks
|
||||||
|
.Cast<Workbook>()
|
||||||
|
.FirstOrDefault(w => w.FullName == pricelistPath) != null)
|
||||||
|
{
|
||||||
|
throw new ArgumentException("Шаблонный файл редактируется в другом месте");
|
||||||
|
}
|
||||||
|
|
||||||
|
return _application.Workbooks.Open(pricelistPath, null, true).ActiveSheet;
|
||||||
|
}
|
||||||
|
}
|
63
RhSolutions.AddIn/Services/SleevesCalculator.cs
Normal file
63
RhSolutions.AddIn/Services/SleevesCalculator.cs
Normal file
@ -0,0 +1,63 @@
|
|||||||
|
using System.Text.RegularExpressions;
|
||||||
|
|
||||||
|
namespace RhSolutions.Services;
|
||||||
|
|
||||||
|
public class SleevesCalculator : ISleevesCalculator
|
||||||
|
{
|
||||||
|
private const string doublePattern =
|
||||||
|
@"((?i)равнопроходная|угольник 90|угольник 45|Т-образная|Комплект трубок(?i))(.+?(?<Sleeve>\b16\b|\b20\b|\b25\b|\b32\b|\b40\b|\b50\b|\b63\b))+";
|
||||||
|
private const string singlePattern =
|
||||||
|
@"((?i)муфта|тройник|переходник|угольник|штуцер|Г-образная|заглушка(?i))(.+?(?<Sleeve>\b16\b|\b20\b|\b25\b|\b32\b|\b40\b|\b50\b|\b63\b))+";
|
||||||
|
|
||||||
|
public Dictionary<Product, double> CalculateSleeves(Dictionary<Product, double> products)
|
||||||
|
{
|
||||||
|
Dictionary<string, double> result = new()
|
||||||
|
{
|
||||||
|
["16"] = 0,
|
||||||
|
["20"] = 0,
|
||||||
|
["25"] = 0,
|
||||||
|
["32"] = 0,
|
||||||
|
["40"] = 0,
|
||||||
|
["50"] = 0,
|
||||||
|
["63"] = 0,
|
||||||
|
};
|
||||||
|
var rautitanProducts = products.Where(kvp => kvp.Key.ProductLines.Contains("RAUTITAN"));
|
||||||
|
|
||||||
|
foreach (var kvp in rautitanProducts)
|
||||||
|
{
|
||||||
|
var doubleCollection = Regex.Matches(kvp.Key.Name, doublePattern);
|
||||||
|
if (doubleCollection.Count != 0)
|
||||||
|
{
|
||||||
|
CaptureCollection collection = doubleCollection[0].Groups["Sleeve"].Captures;
|
||||||
|
foreach (Capture sleeve in collection)
|
||||||
|
{
|
||||||
|
result[sleeve.Value] += kvp.Value * 2;
|
||||||
|
}
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
var singleCollection = Regex.Matches(kvp.Key.Name, singlePattern);
|
||||||
|
if (singleCollection.Count != 0)
|
||||||
|
{
|
||||||
|
CaptureCollection collection = singleCollection[0].Groups["Sleeve"].Captures;
|
||||||
|
foreach (Capture sleeve in collection)
|
||||||
|
{
|
||||||
|
result[sleeve.Value] += kvp.Value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return result
|
||||||
|
.ToDictionary(kvp =>
|
||||||
|
kvp.Key switch
|
||||||
|
{
|
||||||
|
"16" => new Product("11600011001"),
|
||||||
|
"20" => new Product("11600021001"),
|
||||||
|
"25" => new Product("11600031001"),
|
||||||
|
"32" => new Product("11600041001"),
|
||||||
|
"40" => new Product("11600051001"),
|
||||||
|
"50" => new Product("11397711002"),
|
||||||
|
"63" => new Product("11397811002"),
|
||||||
|
_ => throw new Exception($"Неизвестный диаметр {kvp.Key}")
|
||||||
|
}, kvp => kvp.Value);
|
||||||
|
}
|
||||||
|
}
|
@ -13,9 +13,10 @@ public class WriterFactory
|
|||||||
{
|
{
|
||||||
return writerName switch
|
return writerName switch
|
||||||
{
|
{
|
||||||
"Excel" => (IWriter)_serviceProvider.GetService(typeof(ExcelWriter)),
|
"NewPrice" => (IWriter)_serviceProvider.GetService(typeof(NewPriceWriter)),
|
||||||
|
"CurrentPrice" => (IWriter)_serviceProvider.GetService(typeof(CurrentPriceWriter)),
|
||||||
"Dxf" => (IWriter)_serviceProvider.GetService(typeof(DxfWriter)),
|
"Dxf" => (IWriter)_serviceProvider.GetService(typeof(DxfWriter)),
|
||||||
_ => throw new ArgumentException($"Незвестный интерфейс {nameof(IWriter)}: {writerName}")
|
_ => throw new ArgumentException($"Незвестный интерфейс {nameof(IWriter)}: {writerName}")
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -10,7 +10,7 @@ namespace RhSolutions.Tools;
|
|||||||
#endif
|
#endif
|
||||||
internal class ConvertTool : Tool
|
internal class ConvertTool : Tool
|
||||||
{
|
{
|
||||||
public ConvertTool(IServiceProvider provider) : base(provider)
|
public ConvertTool(ReaderFactory readerFactory, WriterFactory writerFactory) : base(readerFactory, writerFactory)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -19,7 +19,7 @@ internal class ConvertTool : Tool
|
|||||||
Application app = RhSolutionsAddIn.Excel.Application;
|
Application app = RhSolutionsAddIn.Excel.Application;
|
||||||
Worksheet worksheet = app.ActiveWorkbook.ActiveSheet;
|
Worksheet worksheet = app.ActiveWorkbook.ActiveSheet;
|
||||||
_reader = _readerFactory.GetReader("Excel");
|
_reader = _readerFactory.GetReader("Excel");
|
||||||
_writer = _writerFactory.GetWriter("Excel");
|
_writer = _writerFactory.GetWriter("NewPrice");
|
||||||
var products = _reader.ReadProducts(new[] { worksheet });
|
var products = _reader.ReadProducts(new[] { worksheet });
|
||||||
_writer.WriteProducts(products);
|
_writer.WriteProducts(products);
|
||||||
}
|
}
|
||||||
|
@ -9,7 +9,7 @@ namespace RhSolutions.Tools;
|
|||||||
#endif
|
#endif
|
||||||
internal class DxfTool : Tool
|
internal class DxfTool : Tool
|
||||||
{
|
{
|
||||||
public DxfTool(IServiceProvider provider) : base(provider)
|
public DxfTool(ReaderFactory readerFactory, WriterFactory writerFactory) : base(readerFactory, writerFactory)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -34,7 +34,8 @@ namespace RhSolutions.Tools
|
|||||||
RibbonController.UpdateWorkbookValidation();
|
RibbonController.UpdateWorkbookValidation();
|
||||||
RibbonController.RefreshControl("convert");
|
RibbonController.RefreshControl("convert");
|
||||||
RibbonController.RefreshControl("dxfexport");
|
RibbonController.RefreshControl("dxfexport");
|
||||||
RibbonController.RefreshControl("Guessexport");
|
RibbonController.RefreshControl("guess");
|
||||||
|
RibbonController.RefreshControl("fillsleeves");
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void RefreshExportButton(object sh, Range target)
|
private static void RefreshExportButton(object sh, Range target)
|
||||||
|
@ -9,7 +9,7 @@ namespace RhSolutions.Tools;
|
|||||||
#endif
|
#endif
|
||||||
internal class ExportTool : Tool
|
internal class ExportTool : Tool
|
||||||
{
|
{
|
||||||
public ExportTool(IServiceProvider provider) : base(provider)
|
public ExportTool(ReaderFactory readerFactory, WriterFactory writerFactory) : base(readerFactory, writerFactory)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -17,7 +17,7 @@ internal class ExportTool : Tool
|
|||||||
{
|
{
|
||||||
Application app = RhSolutionsAddIn.Excel.Application;
|
Application app = RhSolutionsAddIn.Excel.Application;
|
||||||
_reader = _readerFactory.GetReader("Excel");
|
_reader = _readerFactory.GetReader("Excel");
|
||||||
_writer = _writerFactory.GetWriter("Excel");
|
_writer = _writerFactory.GetWriter("NewPrice");
|
||||||
var products = _reader.ReadProducts(app.Selection);
|
var products = _reader.ReadProducts(app.Selection);
|
||||||
_writer.WriteProducts(products);
|
_writer.WriteProducts(products);
|
||||||
}
|
}
|
||||||
|
@ -6,7 +6,7 @@ namespace RhSolutions.Tools;
|
|||||||
|
|
||||||
internal class GuessTool : Tool
|
internal class GuessTool : Tool
|
||||||
{
|
{
|
||||||
public GuessTool(IServiceProvider provider) : base(provider)
|
public GuessTool(ReaderFactory readerFactory, WriterFactory writerFactory) : base(readerFactory, writerFactory)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -15,7 +15,7 @@ internal class GuessTool : Tool
|
|||||||
Application app = RhSolutionsAddIn.Excel.Application;
|
Application app = RhSolutionsAddIn.Excel.Application;
|
||||||
Worksheet worksheet = app.ActiveWorkbook.ActiveSheet;
|
Worksheet worksheet = app.ActiveWorkbook.ActiveSheet;
|
||||||
_reader = _readerFactory.GetReader("Guess");
|
_reader = _readerFactory.GetReader("Guess");
|
||||||
_writer = _writerFactory.GetWriter("Excel");
|
_writer = _writerFactory.GetWriter("NewPrice");
|
||||||
var products = _reader.ReadProducts(new[] { worksheet });
|
var products = _reader.ReadProducts(new[] { worksheet });
|
||||||
_writer.WriteProducts(products);
|
_writer.WriteProducts(products);
|
||||||
}
|
}
|
||||||
|
@ -9,7 +9,7 @@ namespace RhSolutions.Tools;
|
|||||||
#endif
|
#endif
|
||||||
internal class MergeTool : Tool
|
internal class MergeTool : Tool
|
||||||
{
|
{
|
||||||
public MergeTool(IServiceProvider provider) : base(provider)
|
public MergeTool(ReaderFactory readerFactory, WriterFactory writerFactory) : base(readerFactory, writerFactory)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -18,7 +18,7 @@ internal class MergeTool : Tool
|
|||||||
IFileDialog dialog = RhSolutionsAddIn.ServiceProvider.GetRequiredService<IFileDialog>();
|
IFileDialog dialog = RhSolutionsAddIn.ServiceProvider.GetRequiredService<IFileDialog>();
|
||||||
string[] files = dialog.GetFiles();
|
string[] files = dialog.GetFiles();
|
||||||
_reader = _readerFactory.GetReader("Excel");
|
_reader = _readerFactory.GetReader("Excel");
|
||||||
_writer = _writerFactory.GetWriter("Excel");
|
_writer = _writerFactory.GetWriter("NewPrice");
|
||||||
var products = _reader.ReadProducts(files);
|
var products = _reader.ReadProducts(files);
|
||||||
_writer.WriteProducts(products);
|
_writer.WriteProducts(products);
|
||||||
}
|
}
|
||||||
|
@ -7,7 +7,7 @@ namespace RhSolutions.Tools;
|
|||||||
#if !NET472
|
#if !NET472
|
||||||
[SupportedOSPlatform("windows")]
|
[SupportedOSPlatform("windows")]
|
||||||
#endif
|
#endif
|
||||||
internal class ProgressBar : StatusbarBase
|
public class ProgressBar : StatusbarBase
|
||||||
{
|
{
|
||||||
private double CurrentProgress { get; set; }
|
private double CurrentProgress { get; set; }
|
||||||
private readonly double TaskWeight;
|
private readonly double TaskWeight;
|
||||||
|
@ -8,7 +8,7 @@ namespace RhSolutions.Tools;
|
|||||||
#if !NET472
|
#if !NET472
|
||||||
[SupportedOSPlatform("windows")]
|
[SupportedOSPlatform("windows")]
|
||||||
#endif
|
#endif
|
||||||
internal class ResultBar : StatusbarBase
|
public class ResultBar : StatusbarBase
|
||||||
{
|
{
|
||||||
private int Success { get; set; }
|
private int Success { get; set; }
|
||||||
private int Replaced { get; set; }
|
private int Replaced { get; set; }
|
||||||
|
22
RhSolutions.AddIn/Tools/SleevesTool.cs
Normal file
22
RhSolutions.AddIn/Tools/SleevesTool.cs
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
namespace RhSolutions.Tools;
|
||||||
|
|
||||||
|
internal class SleevesTool : Tool
|
||||||
|
{
|
||||||
|
private readonly ISleevesCalculator _sleevesCaluculator;
|
||||||
|
|
||||||
|
public SleevesTool(ReaderFactory readerFactory, WriterFactory writerFactory, ISleevesCalculator sleevesCaluculator) : base(readerFactory, writerFactory)
|
||||||
|
{
|
||||||
|
_sleevesCaluculator = sleevesCaluculator;
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void Execute()
|
||||||
|
{
|
||||||
|
Application app = RhSolutionsAddIn.Excel.Application;
|
||||||
|
Worksheet worksheet = app.ActiveWorkbook.ActiveSheet;
|
||||||
|
_reader = _readerFactory.GetReader("Excel");
|
||||||
|
_writer = _writerFactory.GetWriter("CurrentPrice");
|
||||||
|
var products = _reader.ReadProducts(new[] { worksheet });
|
||||||
|
var sleeves = _sleevesCaluculator.CalculateSleeves(products.Select(p => p.Item2).First());
|
||||||
|
_writer.WriteProducts(sleeves);
|
||||||
|
}
|
||||||
|
}
|
@ -11,7 +11,7 @@ namespace RhSolutions.Tools;
|
|||||||
#if !NET472
|
#if !NET472
|
||||||
[SupportedOSPlatform("windows")]
|
[SupportedOSPlatform("windows")]
|
||||||
#endif
|
#endif
|
||||||
internal abstract class StatusbarBase : IDisposable
|
public abstract class StatusbarBase : IDisposable
|
||||||
{
|
{
|
||||||
protected Application Excel = RhSolutionsAddIn.Excel;
|
protected Application Excel = RhSolutionsAddIn.Excel;
|
||||||
|
|
||||||
|
@ -14,16 +14,16 @@ internal abstract class Tool : IDisposable
|
|||||||
protected IReader _reader;
|
protected IReader _reader;
|
||||||
protected IWriter _writer;
|
protected IWriter _writer;
|
||||||
|
|
||||||
public Tool(IServiceProvider provider)
|
public Tool(ReaderFactory readerFactory, WriterFactory writerFactory)
|
||||||
{
|
{
|
||||||
_readerFactory = provider.GetRequiredService<ReaderFactory>();
|
_readerFactory = readerFactory;
|
||||||
_writerFactory = provider.GetRequiredService<WriterFactory>();
|
_writerFactory = writerFactory;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Dispose()
|
public void Dispose()
|
||||||
{
|
{
|
||||||
_reader.Dispose();
|
_reader?.Dispose();
|
||||||
_writer.Dispose();
|
_writer?.Dispose();
|
||||||
}
|
}
|
||||||
|
|
||||||
public abstract void Execute();
|
public abstract void Execute();
|
||||||
|
@ -2,15 +2,20 @@
|
|||||||
|
|
||||||
internal class ToolFactory
|
internal class ToolFactory
|
||||||
{
|
{
|
||||||
|
static ReaderFactory readerFactory = RhSolutionsAddIn.ServiceProvider.GetService<ReaderFactory>();
|
||||||
|
static WriterFactory writerFactory = RhSolutionsAddIn.ServiceProvider.GetService<WriterFactory>();
|
||||||
|
static ISleevesCalculator sleevesCaluculator = RhSolutionsAddIn.ServiceProvider.GetService<ISleevesCalculator>();
|
||||||
|
|
||||||
public Tool GetTool(string toolName)
|
public Tool GetTool(string toolName)
|
||||||
{
|
{
|
||||||
Tool tool = toolName switch
|
Tool tool = toolName switch
|
||||||
{
|
{
|
||||||
"export" => new ExportTool(RhSolutionsAddIn.ServiceProvider),
|
"export" => new ExportTool(readerFactory, writerFactory),
|
||||||
"convert" => new ConvertTool(RhSolutionsAddIn.ServiceProvider),
|
"convert" => new ConvertTool(readerFactory, writerFactory),
|
||||||
"merge" => new MergeTool(RhSolutionsAddIn.ServiceProvider),
|
"merge" => new MergeTool(readerFactory, writerFactory),
|
||||||
"dxfexport" => new DxfTool(RhSolutionsAddIn.ServiceProvider),
|
"dxfexport" => new DxfTool(readerFactory, writerFactory),
|
||||||
"Guessexport" => new GuessTool(RhSolutionsAddIn.ServiceProvider),
|
"guess" => new GuessTool(readerFactory, writerFactory),
|
||||||
|
"fillsleeves" => new SleevesTool(readerFactory, writerFactory, sleevesCaluculator),
|
||||||
_ => throw new Exception($"Неизвестный инструмент {toolName}"),
|
_ => throw new Exception($"Неизвестный инструмент {toolName}"),
|
||||||
};
|
};
|
||||||
return tool;
|
return tool;
|
||||||
|
@ -25,7 +25,7 @@ public class CanDoGuess : IDisposable
|
|||||||
Worksheet sourceSheet = Util.Workbook.Worksheets[1];
|
Worksheet sourceSheet = Util.Workbook.Worksheets[1];
|
||||||
RhSolutionsAddIn.Configuration.SetPriceListPath(Path.GetFullPath(@"..\..\..\TestWorkbooks\TargetSpecificationGuess.xlsx"));
|
RhSolutionsAddIn.Configuration.SetPriceListPath(Path.GetFullPath(@"..\..\..\TestWorkbooks\TargetSpecificationGuess.xlsx"));
|
||||||
var products = _guessReader.ReadProducts(new[] { sourceSheet });
|
var products = _guessReader.ReadProducts(new[] { sourceSheet });
|
||||||
var _writer = new ExcelWriter(Util.Application, RhSolutionsAddIn.Configuration);
|
var _writer = new NewPriceWriter(Util.Application, RhSolutionsAddIn.Configuration);
|
||||||
_writer.WriteProducts(products);
|
_writer.WriteProducts(products);
|
||||||
Worksheet targetSheet = Util.Application.ActiveWindow.ActiveSheet;
|
Worksheet targetSheet = Util.Application.ActiveWindow.ActiveSheet;
|
||||||
var targetProducts = _reader.ReadProducts(new[] { targetSheet });
|
var targetProducts = _reader.ReadProducts(new[] { targetSheet });
|
||||||
@ -42,7 +42,7 @@ public class CanDoGuess : IDisposable
|
|||||||
Worksheet sourceSheet = Util.Workbook.Worksheets[1];
|
Worksheet sourceSheet = Util.Workbook.Worksheets[1];
|
||||||
RhSolutionsAddIn.Configuration.SetPriceListPath(Path.GetFullPath(@"..\..\..\TestWorkbooks\TargetSpecificationGuessOneRow.xlsx"));
|
RhSolutionsAddIn.Configuration.SetPriceListPath(Path.GetFullPath(@"..\..\..\TestWorkbooks\TargetSpecificationGuessOneRow.xlsx"));
|
||||||
var products = _guessReader.ReadProducts(new[] { sourceSheet });
|
var products = _guessReader.ReadProducts(new[] { sourceSheet });
|
||||||
var _writer = new ExcelWriter(Util.Application, RhSolutionsAddIn.Configuration);
|
var _writer = new NewPriceWriter(Util.Application, RhSolutionsAddIn.Configuration);
|
||||||
_writer.WriteProducts(products);
|
_writer.WriteProducts(products);
|
||||||
Worksheet targetSheet = Util.Application.ActiveWindow.ActiveSheet;
|
Worksheet targetSheet = Util.Application.ActiveWindow.ActiveSheet;
|
||||||
var targetProducts = _reader.ReadProducts(new[] { targetSheet });
|
var targetProducts = _reader.ReadProducts(new[] { targetSheet });
|
||||||
|
44
RhSolutions.Tests/CanFillSleeves.cs
Normal file
44
RhSolutions.Tests/CanFillSleeves.cs
Normal file
@ -0,0 +1,44 @@
|
|||||||
|
using RhSolutions.AddIn;
|
||||||
|
|
||||||
|
namespace RhSolutions.Tests;
|
||||||
|
|
||||||
|
[ExcelTestSettings(OutOfProcess = true)]
|
||||||
|
public class CanFillSleeves : IDisposable
|
||||||
|
{
|
||||||
|
private RhSolutionsAddIn _addIn;
|
||||||
|
private ISleevesCalculator _calculator;
|
||||||
|
private IReader _reader;
|
||||||
|
private IWriter _writer;
|
||||||
|
private Worksheet _worksheet;
|
||||||
|
|
||||||
|
public CanFillSleeves()
|
||||||
|
{
|
||||||
|
_addIn = new();
|
||||||
|
_addIn.AutoOpen();
|
||||||
|
_calculator = new SleevesCalculator();
|
||||||
|
_reader = new ExcelReader(Util.Application, RhSolutionsAddIn.Configuration);
|
||||||
|
_writer = new CurrentPriceWriter(Util.Application, RhSolutionsAddIn.Configuration);
|
||||||
|
_worksheet = Util.Workbook.Worksheets[1];
|
||||||
|
}
|
||||||
|
|
||||||
|
[ExcelFact(Workbook = @"..\..\..\TestWorkbooks\TestSpecificationSleeves.xlsx")]
|
||||||
|
public void CanCalculateSleeves()
|
||||||
|
{
|
||||||
|
var products = _reader.ReadProducts(new[] { _worksheet });
|
||||||
|
var sleeves = _calculator.CalculateSleeves(products.First().Item2);
|
||||||
|
_writer.WriteProducts(sleeves);
|
||||||
|
|
||||||
|
Assert.Equal(25, _worksheet.Range["E2"].Value);
|
||||||
|
Assert.Equal(15, _worksheet.Range["E3"].Value);
|
||||||
|
Assert.Equal(7, _worksheet.Range["E4"].Value);
|
||||||
|
Assert.Equal(8, _worksheet.Range["E5"].Value);
|
||||||
|
Assert.Equal(1, _worksheet.Range["E6"].Value);
|
||||||
|
Assert.Equal(3, _worksheet.Range["E7"].Value);
|
||||||
|
Assert.Equal(4, _worksheet.Range["E8"].Value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Dispose()
|
||||||
|
{
|
||||||
|
_addIn.AutoClose();
|
||||||
|
}
|
||||||
|
}
|
@ -23,7 +23,7 @@ public class CanWriteProducts : IDisposable
|
|||||||
Worksheet sourceSheet = Util.Workbook.Worksheets[1];
|
Worksheet sourceSheet = Util.Workbook.Worksheets[1];
|
||||||
RhSolutionsAddIn.Configuration.SetPriceListPath(Path.GetFullPath(@"..\..\..\TestWorkbooks\TargetSpecification.xlsx"));
|
RhSolutionsAddIn.Configuration.SetPriceListPath(Path.GetFullPath(@"..\..\..\TestWorkbooks\TargetSpecification.xlsx"));
|
||||||
var products = _reader.ReadProducts(new[] { sourceSheet });
|
var products = _reader.ReadProducts(new[] { sourceSheet });
|
||||||
var _writer = new ExcelWriter(Util.Application, RhSolutionsAddIn.Configuration);
|
var _writer = new NewPriceWriter(Util.Application, RhSolutionsAddIn.Configuration);
|
||||||
_writer.WriteProducts(products);
|
_writer.WriteProducts(products);
|
||||||
Worksheet targetSheet = Util.Application.ActiveWindow.ActiveSheet;
|
Worksheet targetSheet = Util.Application.ActiveWindow.ActiveSheet;
|
||||||
var targetProducts = _reader.ReadProducts(new[] { targetSheet });
|
var targetProducts = _reader.ReadProducts(new[] { targetSheet });
|
||||||
@ -40,7 +40,7 @@ public class CanWriteProducts : IDisposable
|
|||||||
Worksheet sourceSheet = Util.Workbook.Worksheets[1];
|
Worksheet sourceSheet = Util.Workbook.Worksheets[1];
|
||||||
RhSolutionsAddIn.Configuration.SetPriceListPath(Path.GetFullPath(@"..\..\..\TestWorkbooks\TargetSpecificationMultipleProductLines.xlsx"));
|
RhSolutionsAddIn.Configuration.SetPriceListPath(Path.GetFullPath(@"..\..\..\TestWorkbooks\TargetSpecificationMultipleProductLines.xlsx"));
|
||||||
var products = _reader.ReadProducts(new[] { sourceSheet });
|
var products = _reader.ReadProducts(new[] { sourceSheet });
|
||||||
var _writer = new ExcelWriter(Util.Application, RhSolutionsAddIn.Configuration);
|
var _writer = new NewPriceWriter(Util.Application, RhSolutionsAddIn.Configuration);
|
||||||
_writer.WriteProducts(products);
|
_writer.WriteProducts(products);
|
||||||
Worksheet targetSheet = Util.Application.ActiveWindow.ActiveSheet;
|
Worksheet targetSheet = Util.Application.ActiveWindow.ActiveSheet;
|
||||||
var targetProducts = _reader.ReadProducts(new[] { targetSheet });
|
var targetProducts = _reader.ReadProducts(new[] { targetSheet });
|
||||||
@ -57,7 +57,7 @@ public class CanWriteProducts : IDisposable
|
|||||||
Worksheet sourceSheet = Util.Workbook.Worksheets[1];
|
Worksheet sourceSheet = Util.Workbook.Worksheets[1];
|
||||||
RhSolutionsAddIn.Configuration.SetPriceListPath(Path.GetFullPath(@"..\..\..\TestWorkbooks\TargetSpecificationNotFound.xlsx"));
|
RhSolutionsAddIn.Configuration.SetPriceListPath(Path.GetFullPath(@"..\..\..\TestWorkbooks\TargetSpecificationNotFound.xlsx"));
|
||||||
var products = _reader.ReadProducts(new[] { sourceSheet });
|
var products = _reader.ReadProducts(new[] { sourceSheet });
|
||||||
var _writer = new ExcelWriter(Util.Application, RhSolutionsAddIn.Configuration);
|
var _writer = new NewPriceWriter(Util.Application, RhSolutionsAddIn.Configuration);
|
||||||
_writer.WriteProducts(products);
|
_writer.WriteProducts(products);
|
||||||
Worksheet targetSheet = Util.Application.ActiveWindow.ActiveSheet;
|
Worksheet targetSheet = Util.Application.ActiveWindow.ActiveSheet;
|
||||||
|
|
||||||
@ -72,7 +72,7 @@ public class CanWriteProducts : IDisposable
|
|||||||
Worksheet sourceSheet = Util.Workbook.Worksheets[1];
|
Worksheet sourceSheet = Util.Workbook.Worksheets[1];
|
||||||
RhSolutionsAddIn.Configuration.SetPriceListPath(Path.GetFullPath(@"..\..\..\TestWorkbooks\TargetSpecificationReplaced.xlsx"));
|
RhSolutionsAddIn.Configuration.SetPriceListPath(Path.GetFullPath(@"..\..\..\TestWorkbooks\TargetSpecificationReplaced.xlsx"));
|
||||||
var products = _reader.ReadProducts(new[] { sourceSheet });
|
var products = _reader.ReadProducts(new[] { sourceSheet });
|
||||||
var _writer = new ExcelWriter(Util.Application, RhSolutionsAddIn.Configuration);
|
var _writer = new NewPriceWriter(Util.Application, RhSolutionsAddIn.Configuration);
|
||||||
_writer.WriteProducts(products);
|
_writer.WriteProducts(products);
|
||||||
Worksheet targetSheet = Util.Application.ActiveWindow.ActiveSheet;
|
Worksheet targetSheet = Util.Application.ActiveWindow.ActiveSheet;
|
||||||
var targetProducts = _reader.ReadProducts(new[] { targetSheet });
|
var targetProducts = _reader.ReadProducts(new[] { targetSheet });
|
||||||
@ -94,7 +94,7 @@ public class CanWriteProducts : IDisposable
|
|||||||
Worksheet sourceSheet = Util.Workbook.Worksheets[1];
|
Worksheet sourceSheet = Util.Workbook.Worksheets[1];
|
||||||
RhSolutionsAddIn.Configuration.SetPriceListPath(Path.GetFullPath(@"..\..\..\TestWorkbooks\TargetSpecificationNewVariant.xlsx"));
|
RhSolutionsAddIn.Configuration.SetPriceListPath(Path.GetFullPath(@"..\..\..\TestWorkbooks\TargetSpecificationNewVariant.xlsx"));
|
||||||
var products = _reader.ReadProducts(new[] { sourceSheet });
|
var products = _reader.ReadProducts(new[] { sourceSheet });
|
||||||
var _writer = new ExcelWriter(Util.Application, RhSolutionsAddIn.Configuration);
|
var _writer = new NewPriceWriter(Util.Application, RhSolutionsAddIn.Configuration);
|
||||||
_writer.WriteProducts(products);
|
_writer.WriteProducts(products);
|
||||||
Worksheet targetSheet = Util.Application.ActiveWindow.ActiveSheet;
|
Worksheet targetSheet = Util.Application.ActiveWindow.ActiveSheet;
|
||||||
var targetProducts = _reader.ReadProducts(new[] { targetSheet });
|
var targetProducts = _reader.ReadProducts(new[] { targetSheet });
|
||||||
|
@ -23,7 +23,7 @@ public class RealPricelistTest : IDisposable
|
|||||||
Worksheet sourceSheet = Util.Workbook.Worksheets[1];
|
Worksheet sourceSheet = Util.Workbook.Worksheets[1];
|
||||||
RhSolutionsAddIn.Configuration.SetPriceListPath(Path.GetFullPath(@"..\..\..\TestWorkbooks\RealTargetSpecification.xlsx"));
|
RhSolutionsAddIn.Configuration.SetPriceListPath(Path.GetFullPath(@"..\..\..\TestWorkbooks\RealTargetSpecification.xlsx"));
|
||||||
var products = _reader.ReadProducts(new[] { sourceSheet });
|
var products = _reader.ReadProducts(new[] { sourceSheet });
|
||||||
var _writer = new ExcelWriter(Util.Application, RhSolutionsAddIn.Configuration);
|
var _writer = new NewPriceWriter(Util.Application, RhSolutionsAddIn.Configuration);
|
||||||
_writer.WriteProducts(products);
|
_writer.WriteProducts(products);
|
||||||
Worksheet targetSheet = Util.Application.ActiveWindow.ActiveSheet;
|
Worksheet targetSheet = Util.Application.ActiveWindow.ActiveSheet;
|
||||||
targetSheet.Range["A1"].Formula = "=SUM(H:H)";
|
targetSheet.Range["A1"].Formula = "=SUM(H:H)";
|
||||||
|
BIN
RhSolutions.Tests/TestWorkbooks/TestSpecificationSleeves.xlsx
Normal file
BIN
RhSolutions.Tests/TestWorkbooks/TestSpecificationSleeves.xlsx
Normal file
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user