Edit sleeves tool

This commit is contained in:
Sergey Chebotar 2023-06-20 11:52:42 +03:00
parent b9cdad649a
commit 5153e951e4
2 changed files with 10 additions and 12 deletions

View File

@ -2,24 +2,21 @@
internal class SleevesTool : Tool
{
public SleevesTool(IServiceProvider provider) : base(provider)
private readonly ISleevesCaluculator _sleevesCaluculator;
public SleevesTool(ReaderFactory readerFactory, WriterFactory writerFactory, ISleevesCaluculator 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 = new List<(string, Dictionary<Product, double>)>()
{
(string.Empty, new Dictionary<Product, double>()
{
[new Product("11600011001")] = 10,
[new Product("11600021001")] = 10,
[new Product("11600031001")] = 10
})
};
_writer.WriteProducts(products);
var products = _reader.ReadProducts(new[] { worksheet });
var sleeves = _sleevesCaluculator.CalculateSleeves(products.Select(p => p.Item2).First());
_writer.WriteProducts(sleeves);
}
}

View File

@ -4,6 +4,7 @@ internal class ToolFactory
{
static ReaderFactory readerFactory = RhSolutionsAddIn.ServiceProvider.GetService<ReaderFactory>();
static WriterFactory writerFactory = RhSolutionsAddIn.ServiceProvider.GetService<WriterFactory>();
static ISleevesCaluculator sleevesCaluculator = RhSolutionsAddIn.ServiceProvider.GetService<ISleevesCaluculator>();
public Tool GetTool(string toolName)
{
@ -14,7 +15,7 @@ internal class ToolFactory
"merge" => new MergeTool(readerFactory, writerFactory),
"dxfexport" => new DxfTool(readerFactory, writerFactory),
"guess" => new GuessTool(readerFactory, writerFactory),
"fillsleeves" => new SleevesTool(RhSolutionsAddIn.ServiceProvider),
"fillsleeves" => new SleevesTool(readerFactory, writerFactory, sleevesCaluculator),
_ => throw new Exception($"Неизвестный инструмент {toolName}"),
};
return tool;