PIbd-22_Kamcharova_K.A_Reno.../RenovationWorkBusinessLogic/BusinessLogics/ReportLogic.cs

96 lines
3.5 KiB
C#
Raw Normal View History

2024-05-19 13:23:06 +04:00
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using RenovationWorkBusinessLogic.OfficePackage.HelperModels;
using RenovationWorkBusinessLogic.OfficePackage;
using RenovationWorkContracts.BindingModels;
using RenovationWorkContracts.BusinessLogicsContracts;
using RenovationWorkContracts.SearchModels;
using RenovationWorkContracts.StoragesContracts;
using RenovationWorkContracts.ViewModels;
namespace RenovationWorkBusinessLogic.BusinessLogics
{
public class ReportLogic : IReportLogic
{
private readonly IComponentStorage _componentStorage;
private readonly IRepairStorage _repairStorage;
private readonly IOrderStorage _orderStorage;
private readonly AbstractSaveToExcel _saveToExcel;
private readonly AbstractSaveToWord _saveToWord;
private readonly AbstractSaveToPdf _saveToPdf;
2024-05-25 21:23:11 +04:00
2024-05-19 13:23:06 +04:00
public ReportLogic(IRepairStorage repairStorage, IComponentStorage componentStorage, IOrderStorage orderStorage,
2024-05-25 21:23:11 +04:00
AbstractSaveToExcel saveToExcel, AbstractSaveToWord saveToWord, AbstractSaveToPdf saveToPdf)
2024-05-19 13:23:06 +04:00
{
_repairStorage = repairStorage;
_componentStorage = componentStorage;
_orderStorage = orderStorage;
2024-05-25 21:23:11 +04:00
2024-05-19 13:23:06 +04:00
_saveToExcel = saveToExcel;
_saveToWord = saveToWord;
_saveToPdf = saveToPdf;
}
public List<ReportRepairComponentViewModel> GetRepairComponent()
{
return _repairStorage.GetFullList().Select(x => new ReportRepairComponentViewModel
{
RepairName = x.RepairName,
Components = x.RepairComponents.Select(x => (x.Value.Item1.ComponentName, x.Value.Item2)).ToList(),
TotalCount = x.RepairComponents.Select(x => x.Value.Item2).Sum()
}).ToList();
}
2024-05-25 21:23:11 +04:00
2024-05-19 13:23:06 +04:00
public List<ReportOrdersViewModel> GetOrders(ReportBindingModel model)
{
return _orderStorage.GetFilteredList(new OrderSearchModel
2024-05-25 21:23:11 +04:00
{
2024-05-19 13:23:06 +04:00
DateFrom = model.DateFrom,
DateTo = model.DateTo
}).Select(x => new ReportOrdersViewModel
{
2024-05-25 21:23:11 +04:00
Id = x.Id,
DateCreate = x.DateCreate,
RepairName = x.RepairName,
Sum = x.Sum,
Status = x.Status.ToString()
2024-05-19 13:23:06 +04:00
}).ToList();
}
2024-05-25 21:23:11 +04:00
2024-05-19 13:23:06 +04:00
public void SaveRepairsToWordFile(ReportBindingModel model)
{
_saveToWord.CreateDoc(new WordInfo
{
FileName = model.FileName,
Title = "Список изделий",
Repairs = _repairStorage.GetFullList()
});
}
2024-05-25 21:23:11 +04:00
2024-05-19 13:23:06 +04:00
public void SaveRepairComponentToExcelFile(ReportBindingModel model)
{
_saveToExcel.CreateReport(new ExcelInfo
{
FileName = model.FileName,
Title = "Список компонент",
RepairComponents = GetRepairComponent()
});
}
2024-05-25 21:23:11 +04:00
2024-05-19 13:23:06 +04:00
public void SaveOrdersToPdfFile(ReportBindingModel model)
{
_saveToPdf.CreateDoc(new PdfInfo
{
FileName = model.FileName,
Title = "Список заказов",
DateFrom = model.DateFrom!.Value,
DateTo = model.DateTo!.Value,
Orders = GetOrders(model)
});
}
}
}