Eliseev E.E. LabWork04_Hard #9

Closed
ElEgEv wants to merge 43 commits from LabWork04_Hard into LabWork03_Hard
Showing only changes of commit fb97f13daa - Show all commits

View File

@ -0,0 +1,126 @@
using BlacksmithWorkshopBusinessLogic.OfficePackage;
using BlacksmithWorkshopBusinessLogic.OfficePackage.HelperModels;
using BlacksmithWorkshopContracts.BindingModels;
using BlacksmithWorkshopContracts.BusinessLogicsContracts;
using BlacksmithWorkshopContracts.SearchModels;
using BlacksmithWorkshopContracts.StoragesContracts;
using BlacksmithWorkshopContracts.ViewModels;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace BlacksmithWorkshopBusinessLogic.BusinessLogic
{
//Реализация бизнес-логики отчётов
public class ReportLogic : IReportLogic
{
private readonly IWorkPieceStorage _workPieceStorage;
private readonly IManufactureStorage _manufactureStorage;
private readonly IOrderStorage _orderStorage;
private readonly AbstractSaveToExcel _saveToExcel;
private readonly AbstractSaveToWord _saveToWord;
private readonly AbstractSaveToPdf _saveToPdf;
//инициализируем поля класса через контейнер
public ReportLogic(IManufactureStorage manufactureStorage, IWorkPieceStorage
workPieceStorage, IOrderStorage orderStorage, AbstractSaveToExcel saveToExcel,
AbstractSaveToWord saveToWord, AbstractSaveToPdf saveToPdf)
{
_manufactureStorage = manufactureStorage;
_workPieceStorage = workPieceStorage;
_orderStorage = orderStorage;
_saveToExcel = saveToExcel;
_saveToWord = saveToWord;
_saveToPdf = saveToPdf;
}
//Получение списка компонент с указанием, в каких изделиях используются
public List<ReportManufactureWorkPieceViewModel> GetManufactureWorkPiece()
{
var workPieces = _workPieceStorage.GetFullList();
var manufactures = _manufactureStorage.GetFullList();
var list = new List<ReportManufactureWorkPieceViewModel>();
foreach (var workPiece in workPieces)
{
var record = new ReportManufactureWorkPieceViewModel
{
WorkPieceName = workPiece.WorkPieceName,
Manufactures = new List<(string, int)>(),
TotalCount = 0
};
foreach (var manufacture in manufactures)
{
if (manufacture.ManufactureWorkPieces.ContainsKey(workPiece.Id))
{
record.Manufactures.Add(new (manufacture.ManufactureName, manufacture.ManufactureWorkPieces[workPiece.Id].Item2));
record.TotalCount += manufacture.ManufactureWorkPieces[workPiece.Id].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,
ManufactureName = x.ManufactureName,
Sum = x.Sum
})
.ToList();
}
//Сохранение заготовок в файл-Word
public void SaveWorkPiecesToWordFile(ReportBindingModel model)
{
_saveToWord.CreateDoc(new WordInfo
{
FileName = model.FileName,
Title = "Список заготовок",
WorkPieces = _workPieceStorage.GetFullList()
});
}
//Сохранение заготовок с указаеним продуктов в файл-Excel
public void SaveManufactureWorkPieceToExcelFile(ReportBindingModel model)
{
_saveToExcel.CreateReport(new ExcelInfo
{
FileName = model.FileName,
Title = "Список заготовок",
ManufactureWorkPieces = GetManufactureWorkPiece()
});
}
//Сохранение заказов в файл-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)
});
}
}
}