100 lines
3.5 KiB
C#
100 lines
3.5 KiB
C#
|
using MotorPlantBusinessLogic.OfficePackage.HelperModels;
|
|||
|
using MotorPlantBusinessLogic.OfficePackage;
|
|||
|
using MotorPlantContracts.BindingModels;
|
|||
|
using MotorPlantContracts.BusinessLogicsContracts;
|
|||
|
using MotorPlantContracts.SearchModels;
|
|||
|
using MotorPlantContracts.StoragesContracts;
|
|||
|
using MotorPlantContracts.ViewModels;
|
|||
|
using System;
|
|||
|
using System.Collections.Generic;
|
|||
|
using System.Linq;
|
|||
|
using System.Text;
|
|||
|
using System.Threading.Tasks;
|
|||
|
|
|||
|
namespace MotorPlantBusinessLogic
|
|||
|
{
|
|||
|
public class ReportLogic : IReportLogic
|
|||
|
{
|
|||
|
private readonly IEngineStorage _EngineStorage;
|
|||
|
private readonly IOrderStorage _orderStorage;
|
|||
|
private readonly AbstractSaveToExcel _saveToExcel;
|
|||
|
private readonly AbstractSaveToWord _saveToWord;
|
|||
|
private readonly AbstractSaveToPdf _saveToPdf;
|
|||
|
public ReportLogic(IEngineStorage EngineStorage, IComponentStorage componentStorage, IOrderStorage orderStorage, AbstractSaveToExcel saveToExcel, AbstractSaveToWord saveToWord, AbstractSaveToPdf saveToPdf)
|
|||
|
{
|
|||
|
_EngineStorage = EngineStorage;
|
|||
|
_orderStorage = orderStorage;
|
|||
|
_saveToExcel = saveToExcel;
|
|||
|
_saveToWord = saveToWord;
|
|||
|
_saveToPdf = saveToPdf;
|
|||
|
}
|
|||
|
public List<ReportEngineComponentViewModel> GetEngineComponents()
|
|||
|
{
|
|||
|
var Engines = _EngineStorage.GetFullList();
|
|||
|
var list = new List<ReportEngineComponentViewModel>();
|
|||
|
foreach (var Engine in Engines)
|
|||
|
{
|
|||
|
var record = new ReportEngineComponentViewModel
|
|||
|
{
|
|||
|
EngineName = Engine.EngineName,
|
|||
|
Components = new List<(string Component, int Count)>(),
|
|||
|
TotalCount = 0
|
|||
|
};
|
|||
|
foreach (var component in Engine.EngineComponents)
|
|||
|
{
|
|||
|
record.Components.Add(new(component.Value.Item1.ComponentName, component.Value.Item2));
|
|||
|
record.TotalCount += component.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,
|
|||
|
EngineName = x.EngineName,
|
|||
|
Sum = x.Sum,
|
|||
|
Status = x.Status.ToString(),
|
|||
|
})
|
|||
|
.ToList();
|
|||
|
}
|
|||
|
public void SaveEnginesToWordFile(ReportBindingModel model)
|
|||
|
{
|
|||
|
_saveToWord.CreateDoc(new WordInfo
|
|||
|
{
|
|||
|
FileName = model.FileName,
|
|||
|
Title = "Список двигателей",
|
|||
|
Engines = _EngineStorage.GetFullList()
|
|||
|
});
|
|||
|
}
|
|||
|
public void SaveEngineComponentToExcelFile(ReportBindingModel model)
|
|||
|
{
|
|||
|
_saveToExcel.CreateReport(new ExcelInfo
|
|||
|
{
|
|||
|
FileName = model.FileName,
|
|||
|
Title = "Список компонентов",
|
|||
|
EngineComponents = GetEngineComponents()
|
|||
|
});
|
|||
|
}
|
|||
|
public void SaveOrdersToPdfFile(ReportBindingModel model)
|
|||
|
{
|
|||
|
_saveToPdf.CreateDoc(new PdfInfo
|
|||
|
{
|
|||
|
FileName = model.FileName,
|
|||
|
Title = "Список заказов",
|
|||
|
DateFrom = model.DateFrom!.Value,
|
|||
|
DateTo = model.DateTo!.Value,
|
|||
|
Orders = GetOrders(model)
|
|||
|
});
|
|||
|
}
|
|||
|
}
|
|||
|
}
|