2023-04-18 15:02:12 +04:00
|
|
|
|
using SecuritySystemBusinessLogic.OfficePackage.HelperModels;
|
|
|
|
|
using SecuritySystemBusinessLogic.OfficePackage;
|
|
|
|
|
using SecuritySystemContracts.BindingModels;
|
|
|
|
|
using SecuritySystemContracts.BusinessLogicsContracts;
|
|
|
|
|
using SecuritySystemContracts.SearchModels;
|
|
|
|
|
using SecuritySystemContracts.StoragesContracts;
|
|
|
|
|
using SecuritySystemContracts.ViewModels;
|
|
|
|
|
|
|
|
|
|
namespace SecureCompanyBusinessLogic.BusinessLogics
|
|
|
|
|
{
|
|
|
|
|
public class ReportLogic : IReportLogic
|
|
|
|
|
{
|
|
|
|
|
private readonly IComponentStorage _componentStorage;
|
2023-05-01 14:00:18 +04:00
|
|
|
|
private readonly ISecureStorage _Securestorage;
|
2023-04-18 15:02:12 +04:00
|
|
|
|
private readonly IOrderStorage _orderStorage;
|
|
|
|
|
private readonly AbstractSaveToExcel _saveToExcel;
|
|
|
|
|
private readonly AbstractSaveToWord _saveToWord;
|
|
|
|
|
private readonly AbstractSaveToPdf _saveToPdf;
|
2023-05-01 14:00:18 +04:00
|
|
|
|
public ReportLogic(ISecureStorage Securestorage, IComponentStorage componentStorage, IOrderStorage orderStorage,
|
2023-04-18 15:02:12 +04:00
|
|
|
|
AbstractSaveToExcel saveToExcel, AbstractSaveToWord saveToWord, AbstractSaveToPdf saveToPdf)
|
|
|
|
|
{
|
2023-04-23 10:08:28 +04:00
|
|
|
|
_Securestorage = Securestorage;
|
2023-04-18 15:02:12 +04:00
|
|
|
|
_componentStorage = componentStorage;
|
|
|
|
|
_orderStorage = orderStorage;
|
|
|
|
|
_saveToExcel = saveToExcel;
|
|
|
|
|
_saveToWord = saveToWord;
|
|
|
|
|
_saveToPdf = saveToPdf;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Получение списка компонент с указанием, в каких изделиях используются
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public List<ReportSecureComponentViewModel> GetSecureComponent()
|
|
|
|
|
{
|
|
|
|
|
var components = _componentStorage.GetFullList();
|
2023-04-23 10:08:28 +04:00
|
|
|
|
var Secures = _Securestorage.GetFullList();
|
2023-04-18 15:02:12 +04:00
|
|
|
|
var list = new List<ReportSecureComponentViewModel>();
|
|
|
|
|
|
|
|
|
|
foreach (var Secure in Secures)
|
|
|
|
|
{
|
|
|
|
|
var record = new ReportSecureComponentViewModel
|
|
|
|
|
{
|
|
|
|
|
SecureName = Secure.SecureName,
|
|
|
|
|
Components = new List<(string, int)>(),
|
|
|
|
|
TotalCount = 0
|
|
|
|
|
};
|
|
|
|
|
foreach (var component in components)
|
|
|
|
|
{
|
|
|
|
|
if (Secure.SecureComponents.ContainsKey(component.Id))
|
|
|
|
|
{
|
|
|
|
|
record.Components.Add(new(component.ComponentName, Secure.SecureComponents[component.Id].Item2));
|
|
|
|
|
record.TotalCount += Secure.SecureComponents[component.Id].Item2;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
list.Add(record);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return list;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Получение списка заказов за определенный период
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="model"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
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,
|
|
|
|
|
Status = Convert.ToString(x.Status) ?? string.Empty,
|
|
|
|
|
})
|
|
|
|
|
.ToList();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Сохранение компонент в файл-Word
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="model"></param>
|
|
|
|
|
public void SaveComponentsToWordFile(ReportBindingModel model)
|
|
|
|
|
{
|
|
|
|
|
_saveToWord.CreateDoc(new WordInfo
|
|
|
|
|
{
|
|
|
|
|
FileName = model.FileName,
|
|
|
|
|
Title = "Список компонент",
|
2023-04-23 10:08:28 +04:00
|
|
|
|
Secures = _Securestorage.GetFullList()
|
2023-04-18 15:02:12 +04:00
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Сохранение компонент с указаеним продуктов в файл-Excel
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="model"></param>
|
|
|
|
|
public void SaveSecureComponentToExcelFile(ReportBindingModel model)
|
|
|
|
|
{
|
|
|
|
|
_saveToExcel.CreateReport(new ExcelInfo
|
|
|
|
|
{
|
|
|
|
|
FileName = model.FileName,
|
|
|
|
|
Title = "Список компонент",
|
|
|
|
|
SecureComponents = GetSecureComponent()
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Сохранение заказов в файл-Pdf
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="model"></param>
|
|
|
|
|
public void SaveOrdersToPdfFile(ReportBindingModel model)
|
|
|
|
|
{
|
|
|
|
|
_saveToPdf.CreateDoc(new PdfInfo
|
|
|
|
|
{
|
|
|
|
|
FileName = model.FileName,
|
|
|
|
|
Title = "Список заказов",
|
|
|
|
|
DateFrom = DateTime.SpecifyKind(model.DateFrom!.Value, DateTimeKind.Utc),
|
|
|
|
|
DateTo = DateTime.SpecifyKind(model.DateTo!.Value, DateTimeKind.Utc),
|
|
|
|
|
Orders = GetOrders(model)
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|