From d87458a10a38ad222d08f43031ecabfcf4e49d94 Mon Sep 17 00:00:00 2001 From: ekallin Date: Sun, 24 Mar 2024 00:59:51 +0400 Subject: [PATCH] =?UTF-8?q?=D0=BB=D0=BE=D0=B3=D0=B8=D0=BA=D0=B0=20=D0=BE?= =?UTF-8?q?=D1=82=D1=87=D0=B5=D1=82=D0=B0=20=D0=B8=20=D0=BF=D0=BE=D0=BC?= =?UTF-8?q?=D0=B5=D0=BD=D1=8F=D0=BB=D0=B0=20=D0=BB=D0=BE=D0=B3=D0=B8=D0=BA?= =?UTF-8?q?=D1=83=20=D0=B2=20=D0=BA=D0=BB=D0=B0=D1=81=D1=81=D0=B5=20Order?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../OfficePackage/AbstractSaveToWord.cs | 53 ++++++++ SushiBarBusinessLogic/Reportlogic.cs | 126 ++++++++++++++++++ .../SushiBarBusinessLogic.csproj | 2 + .../BusinessLogicsContracts/IReportLogic.cs | 4 +- .../SearchModel/OrderSearchModel.cs | 3 + .../ReportSushiComponentViewModel.cs | 2 +- 6 files changed, 187 insertions(+), 3 deletions(-) create mode 100644 SushiBarBusinessLogic/OfficePackage/AbstractSaveToWord.cs create mode 100644 SushiBarBusinessLogic/Reportlogic.cs diff --git a/SushiBarBusinessLogic/OfficePackage/AbstractSaveToWord.cs b/SushiBarBusinessLogic/OfficePackage/AbstractSaveToWord.cs new file mode 100644 index 0000000..1b9f497 --- /dev/null +++ b/SushiBarBusinessLogic/OfficePackage/AbstractSaveToWord.cs @@ -0,0 +1,53 @@ +using SushiBarBusinessLogic.OfficePackage.HelperEnums; +using SushiBarBusinessLogic.OfficePackage.HelperModels; + +namespace SushiBarBusinessLogic.OfficePackage +{ + public abstract class AbstractSaveToWord + { + public void CreateDoc(WordInfo info) + { + CreateWord(info); + CreateParagraph(new WordParagraph + { + Texts = new List<(string, WordTextProperties)> { (info.Title, new WordTextProperties { Bold = true, Size = "24", }) }, + TextProperties = new WordTextProperties + { + Size = "24", + JustificationType = WordJustificationType.Center + } + }); + foreach (var component in info.Components) + { + CreateParagraph(new WordParagraph + { + Texts = new List<(string, WordTextProperties)> { + (component.ComponentName, new WordTextProperties { Size = "24", }) + }, + TextProperties = new WordTextProperties + { + Size = "24", + JustificationType = WordJustificationType.Both + } + }); + } + SaveWord(info); + } + /// + /// Создание doc-файла + /// + /// + protected abstract void CreateWord(WordInfo info); + /// + /// Создание абзаца с текстом + /// + /// + /// + protected abstract void CreateParagraph(WordParagraph paragraph); + /// + /// Сохранение файла + /// + /// + protected abstract void SaveWord(WordInfo info); + } +} \ No newline at end of file diff --git a/SushiBarBusinessLogic/Reportlogic.cs b/SushiBarBusinessLogic/Reportlogic.cs new file mode 100644 index 0000000..906d783 --- /dev/null +++ b/SushiBarBusinessLogic/Reportlogic.cs @@ -0,0 +1,126 @@ +using SushiBarBusinessLogic.OfficePackage.HelperModels; +using SushiBarBusinessLogic.OfficePackage; +using SushiBarContracts.BindingModel; +using SushiBarContracts.BusinessLogicsContracts; +using SushiBarContracts.SearchModel; +using SushiBarContracts.StoragesContracts; +using SushiBarContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace SushiBarBusinessLogic +{ + public class ReportLogic : IReportLogic + { + private readonly IComponentStorage _componentStorage; + private readonly ISushiStorage _sushiStorage; + private readonly IOrderStorage _orderStorage; + private readonly AbstractSaveToExcel _saveToExcel; + private readonly AbstractSaveToWord _saveToWord; + private readonly AbstractSaveToPdf _saveToPdf; + public ReportLogic(ISushiStorage sushiStorage, IComponentStorage componentStorage, + IOrderStorage orderStorage, AbstractSaveToExcel saveToExcel, + AbstractSaveToWord saveToWord, AbstractSaveToPdf saveToPdf) + { + _sushiStorage = sushiStorage; + _componentStorage = componentStorage; + _orderStorage = orderStorage; + _saveToExcel = saveToExcel; + _saveToWord = saveToWord; + _saveToPdf = saveToPdf; + } + /// + /// Получение списка компонент с указанием, в каких изделиях используются + /// + /// + public List GetSushiComponent() + { + var components = _componentStorage.GetFullList(); + var sushis = _sushiStorage.GetFullList(); + var list = new List(); + foreach (var component in components) + { + var record = new ReportSushisComponentViewModel + { + ComponentName = component.ComponentName, + Sushis = new List<(string, int)>(), + TotalCount = 0 + }; + foreach (var sushi in sushis) + { + if (sushi.SushiComponents.ContainsKey(component.Id)) + { + record.Sushis.Add((sushi.SushiName, sushi.SushiComponents[component.Id].Item2)); + record.TotalCount += + sushi.SushiComponents[component.Id].Item2; + } + } + list.Add(record); + } + return list; + } + /// + /// Получение списка заказов за определенный период + /// + /// + /// + public List GetOrders(ReportBindingModel model) + { + return _orderStorage.GetFilteredList(new OrderSearchModel + { + DateFrom = model.DateFrom, + DateTo = model.DateTo + }).Select(x => new ReportOrdersViewModel + { + Id = x.Id, + DateCreate = x.DateCreate, + SushiName = x.SushiName, + Sum = x.Sum + }).ToList(); + } + /// + /// Сохранение компонент в файл-Word + /// + /// + public void SaveComponentsToWordFile(ReportBindingModel model) + { + _saveToWord.CreateDoc(new WordInfo + { + FileName = model.FileName, + Title = "Список компонент", + Components = _componentStorage.GetFullList() + }); + } + /// + /// Сохранение компонент с указаеним продуктов в файл-Excel + /// + /// + public void SaveSushiComponentToExcelFile(ReportBindingModel model) + { + _saveToExcel.CreateReport(new ExcelInfo + { + FileName = model.FileName, + Title = "Список компонент", + SushiComponents = GetSushiComponent() + }); + } + /// + /// Сохранение заказов в файл-Pdf + /// + /// + public void SaveOrdersToPdfFile(ReportBindingModel model) + { + _saveToPdf.CreateDoc(new PdfInfo + { + FileName = model.FileName, + Title = "Список заказов", + DateFrom = model.DateFrom!.Value, + DateTo = model.DateTo!.Value, + Orders = GetOrders(model) + }); + } + } +} diff --git a/SushiBarBusinessLogic/SushiBarBusinessLogic.csproj b/SushiBarBusinessLogic/SushiBarBusinessLogic.csproj index 033d6c7..f0dcddc 100644 --- a/SushiBarBusinessLogic/SushiBarBusinessLogic.csproj +++ b/SushiBarBusinessLogic/SushiBarBusinessLogic.csproj @@ -7,11 +7,13 @@ + + diff --git a/SushiBarContracts/BusinessLogicsContracts/IReportLogic.cs b/SushiBarContracts/BusinessLogicsContracts/IReportLogic.cs index c0114c3..e1e3ef0 100644 --- a/SushiBarContracts/BusinessLogicsContracts/IReportLogic.cs +++ b/SushiBarContracts/BusinessLogicsContracts/IReportLogic.cs @@ -9,7 +9,7 @@ namespace SushiBarContracts.BusinessLogicsContracts /// Получение списка компонент с указанием, в каких изделиях используются /// /// - List GetProductComponent(); + List GetSushiComponent(); /// /// Получение списка заказов за определенный период /// @@ -25,7 +25,7 @@ namespace SushiBarContracts.BusinessLogicsContracts /// Сохранение компонент с указаеним продуктов в файл-Excel /// /// - void SaveSushisComponentToExcelFile(ReportBindingModel model); + void SaveSushiComponentToExcelFile(ReportBindingModel model); /// /// Сохранение заказов в файл-Pdf /// diff --git a/SushiBarContracts/SearchModel/OrderSearchModel.cs b/SushiBarContracts/SearchModel/OrderSearchModel.cs index 4223941..ea1a7ad 100644 --- a/SushiBarContracts/SearchModel/OrderSearchModel.cs +++ b/SushiBarContracts/SearchModel/OrderSearchModel.cs @@ -9,5 +9,8 @@ namespace SushiBarContracts.SearchModel public class OrderSearchModel { public int? Id { get; set; } + public DateTime? DateFrom { get; set; } + public DateTime? DateTo { get; set; } + } } diff --git a/SushiBarContracts/ViewModels/ReportSushiComponentViewModel.cs b/SushiBarContracts/ViewModels/ReportSushiComponentViewModel.cs index b43a7b3..3df6329 100644 --- a/SushiBarContracts/ViewModels/ReportSushiComponentViewModel.cs +++ b/SushiBarContracts/ViewModels/ReportSushiComponentViewModel.cs @@ -4,7 +4,7 @@ { public string ComponentName { get; set; } = string.Empty; public int TotalCount { get; set; } - public List> Sushis { get; set; } = new(); + public List<(string Sushi, int Count)> Sushis { get; set; } = new(); } }