using SecuritySystemBusinessLogic.OfficePackage; using SecuritySystemBusinessLogic.OfficePackage.HelperModels; using SecuritySystemContracts.BindingModels; using SecuritySystemContracts.BusinessLogicsContracts; using SecuritySystemContracts.SearchModels; using SecuritySystemContracts.StoragesContracts; using SecuritySystemContracts.ViewModels; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace SecuritySystemBusinessLogic.BusinessLogic { //Реализация бизнес-логики отчётов public class ReportLogic : IReportLogic { private readonly ISecureStorage _SecureStorage; private readonly IOrderStorage _orderStorage; private readonly AbstractSaveToExcel _saveToExcel; private readonly AbstractSaveToWord _saveToWord; private readonly AbstractSaveToPdf _saveToPdf; //инициализируем поля класса через контейнер public ReportLogic(ISecureStorage SecureStorage, IOrderStorage orderStorage, AbstractSaveToExcel saveToExcel, AbstractSaveToWord saveToWord, AbstractSaveToPdf saveToPdf) { _SecureStorage = SecureStorage; _orderStorage = orderStorage; _saveToExcel = saveToExcel; _saveToWord = saveToWord; _saveToPdf = saveToPdf; } //Получение списка компонент с указанием, в каких изделиях используются public List GetSecureSensor() { var Secures = _SecureStorage.GetFullList(); var list = new List(); foreach (var Secure in Secures) { var record = new ReportSecureSensorViewModel { SecureName = Secure.SecureName, Sensors = new List<(string, int)>(), TotalCount = 0 }; foreach (var Sensor in Secure.SecureSensors) { record.Sensors.Add(new(Sensor.Value.Item1.SensorName, Sensor.Value.Item2)); record.TotalCount += Sensor.Value.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, SecureName = x.SecureName, Sum = x.Sum, OrderStatus = x.Status.ToString() }) .ToList(); } //Сохранение мороженных в файл-Word public void SaveSecuresToWordFile(ReportBindingModel model) { _saveToWord.CreateDoc(new WordInfo { FileName = model.FileName, Title = "Список изделий", Secures = _SecureStorage.GetFullList() }); } //Сохранение заготовок с указаеним изделий в файл-Excel public void SaveSecureSensorToExcelFile(ReportBindingModel model) { _saveToExcel.CreateReport(new ExcelInfo { FileName = model.FileName, Title = "Список заготовок", SecureSensors = GetSecureSensor() }); } //Сохранение заказов в файл-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) }); } } }