From fb97f13daaa4aae73c1fd685772949cf3a236a2c Mon Sep 17 00:00:00 2001 From: Programmist73 Date: Thu, 16 Mar 2023 16:40:30 +0400 Subject: [PATCH] =?UTF-8?q?=D0=A0=D0=B5=D0=B0=D0=BB=D0=B8=D0=B7=D0=B0?= =?UTF-8?q?=D1=86=D0=B8=D1=8F=20=D0=B1=D0=B8=D0=B7=D0=BD=D0=B5=D1=81=20?= =?UTF-8?q?=D0=BB=D0=BE=D0=B3=D0=B8=D0=BA=D0=B8=20=D0=BE=D1=82=D1=87=D1=91?= =?UTF-8?q?=D1=82=D0=BE=D0=B2.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../BusinessLogic/ReportLogic.cs | 126 ++++++++++++++++++ 1 file changed, 126 insertions(+) create mode 100644 BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BusinessLogic/ReportLogic.cs diff --git a/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BusinessLogic/ReportLogic.cs b/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BusinessLogic/ReportLogic.cs new file mode 100644 index 0000000..3087dbb --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BusinessLogic/ReportLogic.cs @@ -0,0 +1,126 @@ +using BlacksmithWorkshopBusinessLogic.OfficePackage; +using BlacksmithWorkshopBusinessLogic.OfficePackage.HelperModels; +using BlacksmithWorkshopContracts.BindingModels; +using BlacksmithWorkshopContracts.BusinessLogicsContracts; +using BlacksmithWorkshopContracts.SearchModels; +using BlacksmithWorkshopContracts.StoragesContracts; +using BlacksmithWorkshopContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BlacksmithWorkshopBusinessLogic.BusinessLogic +{ + //Реализация бизнес-логики отчётов + public class ReportLogic : IReportLogic + { + private readonly IWorkPieceStorage _workPieceStorage; + + private readonly IManufactureStorage _manufactureStorage; + + private readonly IOrderStorage _orderStorage; + + private readonly AbstractSaveToExcel _saveToExcel; + + private readonly AbstractSaveToWord _saveToWord; + + private readonly AbstractSaveToPdf _saveToPdf; + + //инициализируем поля класса через контейнер + public ReportLogic(IManufactureStorage manufactureStorage, IWorkPieceStorage + workPieceStorage, IOrderStorage orderStorage, AbstractSaveToExcel saveToExcel, + AbstractSaveToWord saveToWord, AbstractSaveToPdf saveToPdf) + { + _manufactureStorage = manufactureStorage; + _workPieceStorage = workPieceStorage; + _orderStorage = orderStorage; + _saveToExcel = saveToExcel; + _saveToWord = saveToWord; + _saveToPdf = saveToPdf; + } + + //Получение списка компонент с указанием, в каких изделиях используются + public List GetManufactureWorkPiece() + { + var workPieces = _workPieceStorage.GetFullList(); + var manufactures = _manufactureStorage.GetFullList(); + + var list = new List(); + + foreach (var workPiece in workPieces) + { + var record = new ReportManufactureWorkPieceViewModel + { + WorkPieceName = workPiece.WorkPieceName, + Manufactures = new List<(string, int)>(), + TotalCount = 0 + }; + + foreach (var manufacture in manufactures) + { + if (manufacture.ManufactureWorkPieces.ContainsKey(workPiece.Id)) + { + record.Manufactures.Add(new (manufacture.ManufactureName, manufacture.ManufactureWorkPieces[workPiece.Id].Item2)); + record.TotalCount += manufacture.ManufactureWorkPieces[workPiece.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, + ManufactureName = x.ManufactureName, + Sum = x.Sum + }) + .ToList(); + } + + //Сохранение заготовок в файл-Word + public void SaveWorkPiecesToWordFile(ReportBindingModel model) + { + _saveToWord.CreateDoc(new WordInfo + { + FileName = model.FileName, + Title = "Список заготовок", + WorkPieces = _workPieceStorage.GetFullList() + }); + + } + + //Сохранение заготовок с указаеним продуктов в файл-Excel + public void SaveManufactureWorkPieceToExcelFile(ReportBindingModel model) + { + _saveToExcel.CreateReport(new ExcelInfo + { + FileName = model.FileName, + Title = "Список заготовок", + ManufactureWorkPieces = GetManufactureWorkPiece() + }); + } + + //Сохранение заказов в файл-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) + }); + } + } +}