using SoftwareInstallationBusinessLogic.OfficePackage.HelperModels; using SoftwareInstallationBusinessLogic.OfficePackage; using SoftwareInstallationContracts.BindingModels; using SoftwareInstallationContracts.BusinessLogicsContracts; using SoftwareInstallationContracts.SearchModels; using SoftwareInstallationContracts.StoragesContracts; using SoftwareInstallationContracts.ViewModels; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace SoftwareInstallationBusinessLogic.BusinessLogics { public class ReportLogic : IReportLogic { private readonly IComponentStorage _componentStorage; private readonly IPackageStorage _PackageStorage; private readonly IOrderStorage _orderStorage; private readonly AbstractSaveToExcel _saveToExcel; private readonly AbstractSaveToWord _saveToWord; private readonly AbstractSaveToPdf _saveToPdf; public ReportLogic(IPackageStorage PackageStorage, IComponentStorage componentStorage, IOrderStorage orderStorage, AbstractSaveToExcel saveToExcel, AbstractSaveToWord saveToWord, AbstractSaveToPdf saveToPdf) { _PackageStorage = PackageStorage; _componentStorage = componentStorage; _orderStorage = orderStorage; _saveToExcel = saveToExcel; _saveToWord = saveToWord; _saveToPdf = saveToPdf; } public List GetSoftwareComponents() { var components = _componentStorage.GetFullList(); var Softwares = _PackageStorage.GetFullList(); var list = new List(); foreach (var Software in Softwares) { var record = new ReportPackageComponentViewModel { SoftwareName = Software.PackageName, Components = new List<(string Component, int Count)>(), TotalCount = 0 }; foreach (var component in components) { if (Software.PackageComponents.ContainsKey(component.Id)) { record.Components.Add(new(component.ComponentName, Software.PackageComponents[component.Id].Item2)); record.TotalCount += Software.PackageComponents[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, SoftwareName = x.PackageName, Sum = x.Sum, Status = x.Status.ToString(), }) .ToList(); } public void SaveSoftwaresToWordFile(ReportBindingModel model) { _saveToWord.CreateDoc(new WordInfo { FileName = model.FileName, Title = "Список ЖИ", Softwares = _PackageStorage.GetFullList() }); } public void SavePackageComponentToExcelFile(ReportBindingModel model) { _saveToExcel.CreateReport(new ExcelInfo { FileName = model.FileName, Title = "Список ЖИ", SoftwareComponents = GetSoftwareComponents() }); } public void SaveOrdersToPdfFile(ReportBindingModel model) { _saveToPdf.CreateDoc(new PdfInfo { FileName = model.FileName, Title = "Список заказов", DateFrom = model.DateFrom!.Value, DateTo = model.DateTo!.Value, Orders = GetOrders(model) }); } } }