From 5153e951e4313739dd4fd106ce985c3f6c991837 Mon Sep 17 00:00:00 2001 From: Sergey Chebotar Date: Tue, 20 Jun 2023 11:52:42 +0300 Subject: [PATCH] Edit sleeves tool --- RhSolutions.AddIn/Tools/SleevesTool.cs | 19 ++++++++----------- RhSolutions.AddIn/Tools/ToolFactory.cs | 3 ++- 2 files changed, 10 insertions(+), 12 deletions(-) diff --git a/RhSolutions.AddIn/Tools/SleevesTool.cs b/RhSolutions.AddIn/Tools/SleevesTool.cs index 727baed..3981371 100644 --- a/RhSolutions.AddIn/Tools/SleevesTool.cs +++ b/RhSolutions.AddIn/Tools/SleevesTool.cs @@ -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)>() - { - (string.Empty, new Dictionary() - { - [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); } } diff --git a/RhSolutions.AddIn/Tools/ToolFactory.cs b/RhSolutions.AddIn/Tools/ToolFactory.cs index 09a6413..a330197 100644 --- a/RhSolutions.AddIn/Tools/ToolFactory.cs +++ b/RhSolutions.AddIn/Tools/ToolFactory.cs @@ -4,6 +4,7 @@ internal class ToolFactory { static ReaderFactory readerFactory = RhSolutionsAddIn.ServiceProvider.GetService(); static WriterFactory writerFactory = RhSolutionsAddIn.ServiceProvider.GetService(); + static ISleevesCaluculator sleevesCaluculator = RhSolutionsAddIn.ServiceProvider.GetService(); 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;