PIbd-22_Smirnov_A.A._Securi.../SecuritySystem/SecuritySystemBusinessLogiс/BusinessLogic/ReportLogic.cs
2024-05-08 00:49:35 +04:00

121 lines
4.3 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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<ReportSecureSensorViewModel> GetSecureSensor()
{
var Secures = _SecureStorage.GetFullList();
var list = new List<ReportSecureSensorViewModel>();
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<ReportOrdersViewModel> 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)
});
}
}
}