127 lines
4.8 KiB
C#
127 lines
4.8 KiB
C#
using PrecastConcretePlantBusinessLogic.OfficePackage;
|
||
using PrecastConcretePlantBusinessLogic.OfficePackage.HelperModels;
|
||
using PrecastConcretePlantContracts.BindingModels;
|
||
using PrecastConcretePlantContracts.BusinessLogicsContracts;
|
||
using PrecastConcretePlantContracts.SearchModels;
|
||
using PrecastConcretePlantContracts.StoragesContract;
|
||
using PrecastConcretePlantContracts.ViewModels;
|
||
using System;
|
||
using System.Collections.Generic;
|
||
using System.Linq;
|
||
using System.Text;
|
||
using System.Threading.Tasks;
|
||
|
||
namespace PrecastConcretePlantBusinessLogic.BusinessLogic
|
||
{
|
||
public class ReportLogic : IReportLogic
|
||
{
|
||
private readonly IComponentStorage _componentStorage;
|
||
|
||
private readonly IReinforcedStorage _reinforcedStorage;
|
||
|
||
private readonly IOrderStorage _orderStorage;
|
||
|
||
private readonly AbstractSaveToExcel _saveToExcel;
|
||
|
||
private readonly AbstractSaveToWord _saveToWord;
|
||
|
||
private readonly AbstractSaveToPdf _saveToPdf;
|
||
|
||
public ReportLogic(IReinforcedStorage ReinforcedStorage, IComponentStorage componentStorage, IOrderStorage orderStorage,
|
||
AbstractSaveToExcel saveToExcel, AbstractSaveToWord saveToWord, AbstractSaveToPdf saveToPdf)
|
||
{
|
||
_reinforcedStorage = ReinforcedStorage;
|
||
_componentStorage = componentStorage;
|
||
_orderStorage = orderStorage;
|
||
|
||
_saveToExcel = saveToExcel;
|
||
_saveToWord = saveToWord;
|
||
_saveToPdf = saveToPdf;
|
||
}
|
||
|
||
/// <summary>
|
||
/// Получение списка компонент с указанием, в каких изделиях используются
|
||
/// </summary>
|
||
/// <returns></returns>
|
||
public List<ReportReinforcedComponentViewModel> GetReinforcedComponent()
|
||
{
|
||
var reinforceds = _reinforcedStorage.GetFullList();
|
||
var list = new List<ReportReinforcedComponentViewModel>();
|
||
foreach (var reinforced in reinforceds)
|
||
{
|
||
var record = new ReportReinforcedComponentViewModel
|
||
{
|
||
ReinforcedName = reinforced.ReinforcedName,
|
||
Components = reinforced.ReinforcedComponents.Values.Select(x => Tuple.Create(x.Item1.ComponentName, x.Item2)).ToList(),
|
||
TotalCount = reinforced.ReinforcedComponents.Values.Select(x => x.Item2).Sum(),
|
||
};
|
||
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,
|
||
ReinforcedName = x.ReinforcedName,
|
||
OrderStatus = Convert.ToString(x.Status) ?? string.Empty,
|
||
Sum = x.Sum
|
||
})
|
||
.ToList();
|
||
}
|
||
|
||
/// <summary>
|
||
/// Сохранение изделий в файл-Word
|
||
/// </summary>
|
||
/// <param name="model"></param>
|
||
public void SaveReinforcedsToWordFile(ReportBindingModel model)
|
||
{
|
||
_saveToWord.CreateDoc(new WordInfo
|
||
{
|
||
FileName = model.FileName,
|
||
Title = "Список изделий",
|
||
Reinforceds = _reinforcedStorage.GetFullList()
|
||
});
|
||
}
|
||
|
||
/// <summary>
|
||
/// Сохранение изделий с указаеним продуктов в файл-Excel
|
||
/// </summary>
|
||
/// <param name="model"></param>
|
||
public void SaveReinforcedComponentToExcelFile(ReportBindingModel model)
|
||
{
|
||
_saveToExcel.CreateReport(new ExcelInfo
|
||
{
|
||
FileName = model.FileName,
|
||
Title = "Список изделий",
|
||
ReinforcedComponents = GetReinforcedComponent()
|
||
});
|
||
}
|
||
|
||
/// <summary>
|
||
/// Сохранение заказов в файл-Pdf
|
||
/// </summary>
|
||
/// <param name="model"></param>
|
||
public void SaveOrdersToPdfFile(ReportBindingModel model)
|
||
{
|
||
_saveToPdf.CreateDoc(new PdfInfo
|
||
{
|
||
FileName = model.FileName,
|
||
Title = "Список заказов",
|
||
DateFrom = model.DateFrom!.Value,
|
||
DateTo = model.DateTo!.Value,
|
||
Orders = GetOrders(model)
|
||
});
|
||
}
|
||
}
|
||
}
|