From 48603bba797304cd0ed95fe54400a6f3be6a8743 Mon Sep 17 00:00:00 2001 From: VictoriaPresnyakova Date: Mon, 20 Mar 2023 14:13:00 +0400 Subject: [PATCH] names fixed --- .../BusinessLogics/ReportLogic.cs | 131 ++++++++++++++++++ .../OfficePackage/HelperModels/ExcelInfo.cs | 2 +- .../ReportJewelComponentViewModel.cs | 4 +- 3 files changed, 134 insertions(+), 3 deletions(-) create mode 100644 JewelryStoreBusinessLogic/BusinessLogics/ReportLogic.cs diff --git a/JewelryStoreBusinessLogic/BusinessLogics/ReportLogic.cs b/JewelryStoreBusinessLogic/BusinessLogics/ReportLogic.cs new file mode 100644 index 0000000..1b93b41 --- /dev/null +++ b/JewelryStoreBusinessLogic/BusinessLogics/ReportLogic.cs @@ -0,0 +1,131 @@ +using JewelryStoreBusinessLogic.OfficePackage; +using JewelryStoreBusinessLogic.OfficePackage.HelperModels; +using JewelryStoreContracts.BindingModels; +using JewelryStoreContracts.BusinessLogicsContracts; +using JewelryStoreContracts.SearchModels; +using JewelryStoreContracts.StoragesContracts; +using JewelryStoreContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace JewelryStoreBusinessLogic.BusinessLogics +{ + public class ReportLogic : IReportLogic + { + private readonly IComponentStorage _componentStorage; + private readonly IJewelStorage _jewelStorage; + private readonly IOrderStorage _orderStorage; + private readonly AbstractSaveToExcel _saveToExcel; + private readonly AbstractSaveToWord _saveToWord; + private readonly AbstractSaveToPdf _saveToPdf; + public ReportLogic(IJewelStorage jewelStorage, IComponentStorage + componentStorage, IOrderStorage orderStorage, + AbstractSaveToExcel saveToExcel, AbstractSaveToWord saveToWord, + AbstractSaveToPdf saveToPdf) + { + _jewelStorage = jewelStorage; + _componentStorage = componentStorage; + _orderStorage = orderStorage; + _saveToExcel = saveToExcel; + _saveToWord = saveToWord; + _saveToPdf = saveToPdf; + } + /// + /// Получение списка компонент с указанием, в каких изделиях используются + /// + /// + public List GetJewelComponent() + { + var components = _componentStorage.GetFullList(); + var jewels = _jewelStorage.GetFullList(); + var list = new List(); + foreach (var component in components) + { + var record = new ReportJewelComponentViewModel + { + ComponentName = component.ComponentName, + Jewels = new List>(), + TotalCount = 0 + }; + foreach (var jewel in jewels) + { + if (jewel.JewelComponents.ContainsKey(component.Id)) + { + record.Jewels.Add(new Tuple(jewel.JewelName, jewel.JewelComponents[component.Id].Item2)); + record.TotalCount += + jewel.JewelComponents[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, + JewelName = x.JewelName, + Sum = x.Sum + }) + .ToList(); + } + /// + /// Сохранение компонент в файл-Word + /// + /// + public void SaveComponentsToWordFile(ReportBindingModel model) + { + _saveToWord.CreateDoc(new WordInfo + { + FileName = model.FileName, + Title = "Список компонент", + Components = _componentStorage.GetFullList() + }); + } + /// + /// Сохранение компонент с указаеним продуктов в файл-Excel + /// + /// + public void SaveJewelComponentToExcelFile(ReportBindingModel model) + { + _saveToExcel.CreateReport(new ExcelInfo + { + FileName = model.FileName, + Title = "Список компонент", + JewelComponents = GetJewelComponent() + }); + } + /// Сохранение заказов в файл-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/JewelryStoreBusinessLogic/OfficePackage/HelperModels/ExcelInfo.cs b/JewelryStoreBusinessLogic/OfficePackage/HelperModels/ExcelInfo.cs index 4be5096..fb2d81b 100644 --- a/JewelryStoreBusinessLogic/OfficePackage/HelperModels/ExcelInfo.cs +++ b/JewelryStoreBusinessLogic/OfficePackage/HelperModels/ExcelInfo.cs @@ -11,7 +11,7 @@ namespace JewelryStoreBusinessLogic.OfficePackage.HelperModels { public string FileName { get; set; } = string.Empty; public string Title { get; set; } = string.Empty; - public List ProductJewels + public List JewelComponents { get; set; diff --git a/JewelryStoreContracts/ViewModels/ReportJewelComponentViewModel.cs b/JewelryStoreContracts/ViewModels/ReportJewelComponentViewModel.cs index 1f05466..cff6bef 100644 --- a/JewelryStoreContracts/ViewModels/ReportJewelComponentViewModel.cs +++ b/JewelryStoreContracts/ViewModels/ReportJewelComponentViewModel.cs @@ -8,8 +8,8 @@ namespace JewelryStoreContracts.ViewModels { public class ReportJewelComponentViewModel { - public string JewelName { get; set; } = string.Empty; + public string ComponentName { get; set; } = string.Empty; public int TotalCount { get; set; } - public List> Products { get; set; } = new(); + public List> Jewels { get; set; } = new(); } }