112 lines
4.2 KiB
C#
112 lines
4.2 KiB
C#
|
using PlumbingRepairBusinessLogic.OfficePackage.HelperModels;
|
|||
|
using PlumbingRepairBusinessLogic.OfficePackage;
|
|||
|
using PlumbingRepairContracts.BindingModels;
|
|||
|
using PlumbingRepairContracts.BusinessLogicsContracts;
|
|||
|
using PlumbingRepairContracts.SearchModels;
|
|||
|
using PlumbingRepairContracts.StoragesContracts;
|
|||
|
using PlumbingRepairContracts.ViewModels;
|
|||
|
using System;
|
|||
|
using System.Collections.Generic;
|
|||
|
using System.Linq;
|
|||
|
using System.Text;
|
|||
|
using System.Threading.Tasks;
|
|||
|
|
|||
|
namespace PlumbingRepairBusinessLogic.BusinessLogics
|
|||
|
{
|
|||
|
public class ReportLogic : IReportLogic
|
|||
|
{
|
|||
|
private readonly IComponentStorage _componentStorage;
|
|||
|
private readonly IWorkStorage _workStorage;
|
|||
|
private readonly IOrderStorage _orderStorage;
|
|||
|
private readonly AbstractSaveToExcel _saveToExcel;
|
|||
|
private readonly AbstractSaveToWord _saveToWord;
|
|||
|
private readonly AbstractSaveToPdf _saveToPdf;
|
|||
|
public ReportLogic (IWorkStorage workStorage, IComponentStorage
|
|||
|
componentStorage, IOrderStorage orderStorage,
|
|||
|
AbstractSaveToExcel saveToExcel, AbstractSaveToWord saveToWord,
|
|||
|
AbstractSaveToPdf saveToPdf)
|
|||
|
{
|
|||
|
_workStorage = workStorage;
|
|||
|
_componentStorage = componentStorage;
|
|||
|
_orderStorage = orderStorage;
|
|||
|
_saveToExcel = saveToExcel;
|
|||
|
_saveToWord = saveToWord;
|
|||
|
_saveToPdf = saveToPdf;
|
|||
|
}
|
|||
|
public List<ReportWorkComponentViewModel> GetProductComponent()
|
|||
|
{
|
|||
|
var components = _componentStorage.GetFullList();
|
|||
|
var products = _workStorage.GetFullList();
|
|||
|
var list = new List<ReportWorkComponentViewModel>();
|
|||
|
foreach (var component in components)
|
|||
|
{
|
|||
|
var record = new ReportWorkComponentViewModel
|
|||
|
{
|
|||
|
ComponentName = component.ComponentName,
|
|||
|
Works = new List<Tuple<string, int>>(),
|
|||
|
TotalCount = 0
|
|||
|
};
|
|||
|
foreach (var product in products)
|
|||
|
{
|
|||
|
if (product.WorkComponents.ContainsKey(component.Id))
|
|||
|
{
|
|||
|
record.Works.Add(new Tuple<string,
|
|||
|
int>(product.WorkName, product.WorkComponents[component.Id].Item2));
|
|||
|
record.TotalCount +=
|
|||
|
product.WorkComponents[component.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,
|
|||
|
WorkName = x.WorkName,
|
|||
|
Sum = x.Sum
|
|||
|
})
|
|||
|
.ToList();
|
|||
|
}
|
|||
|
public void SaveComponentsToWordFile(ReportBindingModel model)
|
|||
|
{
|
|||
|
_saveToWord.CreateDoc(new WordInfo
|
|||
|
{
|
|||
|
FileName = model.FileName,
|
|||
|
Title = "Список компонент",
|
|||
|
Components = _componentStorage.GetFullList()
|
|||
|
});
|
|||
|
}
|
|||
|
public void SaveProductComponentToExcelFile(ReportBindingModel model)
|
|||
|
{
|
|||
|
_saveToExcel.CreateReport(new ExcelInfo
|
|||
|
{
|
|||
|
FileName = model.FileName,
|
|||
|
Title = "Список компонент",
|
|||
|
WorkComponents = GetProductComponent()
|
|||
|
});
|
|||
|
}
|
|||
|
public void SaveOrdersToPdfFile(ReportBindingModel model)
|
|||
|
{
|
|||
|
_saveToPdf.CreateDoc(new PdfInfo
|
|||
|
{
|
|||
|
FileName = model.FileName,
|
|||
|
Title = "Список заказов",
|
|||
|
DateFrom = model.DateFrom!.Value,
|
|||
|
DateTo = model.DateTo!.Value,
|
|||
|
Orders = GetOrders(model)
|
|||
|
});
|
|||
|
}
|
|||
|
|
|||
|
}
|
|||
|
}
|