219 lines
7.9 KiB
C#
219 lines
7.9 KiB
C#
using AutomobilePlantBusinessLogic.OfficePackage;
|
||
using AutomobilePlantBusinessLogic.OfficePackage.HelperModels;
|
||
using AutomobilePlantContracts.BindingModels;
|
||
using AutomobilePlantContracts.BusinessLogicsContracts;
|
||
using AutomobilePlantContracts.SearchModel;
|
||
using AutomobilePlantContracts.StoragesContracts;
|
||
using AutomobilePlantContracts.ViewModel;
|
||
using System.Collections.Generic;
|
||
using System.Security.Cryptography.X509Certificates;
|
||
|
||
namespace AutomobilePlantBusinessLogic.BusinessLogics
|
||
{
|
||
public class ReportLogic : IReportLogic
|
||
{
|
||
private readonly IComponentStorage _componentStorage;
|
||
|
||
private readonly ICarStorage _carStorage;
|
||
|
||
private readonly IOrderStorage _orderStorage;
|
||
private readonly ICarShopStorage _carShopStorage;
|
||
|
||
private readonly AbstractSaveToExcel _saveToExcel;
|
||
|
||
private readonly AbstractSaveToWord _saveToWord;
|
||
|
||
private readonly AbstractSaveToPdf _saveToPdf;
|
||
|
||
private readonly AbstractShopToExcell _saveShopToExcel;
|
||
|
||
private readonly AbstractShopToWord _saveShopToWord;
|
||
|
||
private readonly AbstractOrdersCountToPDF _saveOrdersToPdf;
|
||
public ReportLogic(ICarStorage carStorage, IComponentStorage componentStorage, IOrderStorage orderStorage,
|
||
AbstractSaveToExcel saveToExcel, AbstractSaveToWord saveToWord, AbstractSaveToPdf saveToPdf,
|
||
ICarShopStorage carShopStorage, AbstractOrdersCountToPDF abstractOrdersCountToPDF, AbstractShopToExcell abstractShopToExcell,
|
||
AbstractShopToWord abstractShopToWord)
|
||
{
|
||
_carStorage = carStorage;
|
||
_componentStorage = componentStorage;
|
||
_orderStorage = orderStorage;
|
||
_carShopStorage = carShopStorage;
|
||
|
||
_saveToExcel = saveToExcel;
|
||
_saveToWord = saveToWord;
|
||
_saveToPdf = saveToPdf;
|
||
_saveShopToWord = abstractShopToWord;
|
||
_saveShopToExcel = abstractShopToExcell;
|
||
_saveOrdersToPdf = abstractOrdersCountToPDF;
|
||
}
|
||
|
||
/// <summary>
|
||
/// Получение списка компонент с указанием, в каких изделиях используются
|
||
/// </summary>
|
||
/// <returns></returns>
|
||
public List<ReportCarComponentViewModel> GetCarComponent()
|
||
{
|
||
var components = _componentStorage.GetFullList();
|
||
|
||
var cars = _carStorage.GetFullList();
|
||
|
||
var list = new List<ReportCarComponentViewModel>();
|
||
|
||
foreach (var car in cars)
|
||
{
|
||
var record = new ReportCarComponentViewModel
|
||
{
|
||
CarName = car.CarName,
|
||
Components = new List<(string, int)>(),
|
||
TotalCount = 0
|
||
};
|
||
foreach (var component in components)
|
||
{
|
||
if (car.CarComponents.ContainsKey(component.Id))
|
||
{
|
||
record.Components.Add(new (component.ComponentName, car.CarComponents[component.Id].Item2));
|
||
record.TotalCount += car.CarComponents[component.Id].Item2;
|
||
}
|
||
}
|
||
|
||
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,
|
||
CarName = x.CarName,
|
||
Status=x.Status.ToString(),
|
||
Sum = x.Sum
|
||
})
|
||
.ToList();
|
||
}
|
||
|
||
/// <summary>
|
||
/// Сохранение компонент в файл-Word
|
||
/// </summary>
|
||
/// <param name="model"></param>
|
||
public void SaveComponentsToWordFile(ReportBindingModel model)
|
||
{
|
||
_saveToWord.CreateDoc(new WordInfo
|
||
{
|
||
FileName = model.FileName,
|
||
Title = "Список компонент",
|
||
Components = _componentStorage.GetFullList()
|
||
});
|
||
}
|
||
|
||
/// <summary>
|
||
/// Сохранение компонент с указаеним продуктов в файл-Excel
|
||
/// </summary>
|
||
/// <param name="model"></param>
|
||
public void SaveCarComponentToExcelFile(ReportBindingModel model)
|
||
{
|
||
_saveToExcel.CreateReport(new ExcelInfo
|
||
{
|
||
FileName = model.FileName,
|
||
Title = "Список компонент",
|
||
CarComponents = GetCarComponent()
|
||
});
|
||
}
|
||
|
||
/// <summary>
|
||
/// Сохранение заказов в файл-Pdf
|
||
/// </summary>
|
||
/// <param name="model"></param>
|
||
public void SaveOrdersToPdfFile(ReportBindingModel model)
|
||
{
|
||
_saveToPdf.CreateDoc(new PdfInfo
|
||
{
|
||
FileName = model.FileName,
|
||
Title = "Список заказов",
|
||
DateFrom = DateTime.SpecifyKind(model.DateFrom!.Value, DateTimeKind.Utc),
|
||
DateTo = DateTime.SpecifyKind(model.DateTo!.Value, DateTimeKind.Utc),
|
||
Orders = GetOrders(model)
|
||
});
|
||
}
|
||
|
||
public List<ReportShopCarViewModel> GetShopCars()
|
||
{
|
||
var shops = _carShopStorage.GetFullList();
|
||
|
||
var cars = _carStorage.GetFullList();
|
||
|
||
var list = new List<ReportShopCarViewModel>();
|
||
|
||
foreach (var shop in shops)
|
||
{
|
||
var record = new ReportShopCarViewModel
|
||
{
|
||
ShopName = shop.ShopName,
|
||
Cars = new List<(string, int)>(),
|
||
TotalCount = 0
|
||
};
|
||
foreach (var car in cars)
|
||
{
|
||
if (shop.Cars.ContainsKey(car.Id))
|
||
{
|
||
record.Cars.Add(new(car.CarName, shop.Cars[car.Id].Item2));
|
||
record.TotalCount += shop.Cars[car.Id].Item2;
|
||
}
|
||
}
|
||
|
||
list.Add(record);
|
||
}
|
||
|
||
return list;
|
||
}
|
||
|
||
public List<ReportAllOrdersViewModel> GetOrdersAll()
|
||
{
|
||
var orders = _orderStorage.GetFullList().OrderBy(x => x.DateCreate).ToList();
|
||
var list = orders.GroupBy(x => x.DateCreate.Date)
|
||
.Select(g => new ReportAllOrdersViewModel { DateCreate=g.Key, Count = g.Count(), Sum = g.Sum(g=>g.Sum) })
|
||
.ToList();
|
||
return list;
|
||
}
|
||
|
||
public void SaveShopsToWordFile(ReportBindingModel model)
|
||
{
|
||
_saveShopToWord.CreateDoc(new ShopWordInfo
|
||
{
|
||
FileName = model.FileName,
|
||
Title = "Список магазинов",
|
||
Shops = _carShopStorage.GetFullList()
|
||
});
|
||
}
|
||
|
||
public void SaveShopCarsToExcelFile(ReportBindingModel model)
|
||
{
|
||
_saveShopToExcel.CreateReport(new ShopExcelInfo
|
||
{
|
||
FileName = model.FileName,
|
||
Title = "Список машин в магазинах",
|
||
ShopCars = GetShopCars()
|
||
});
|
||
}
|
||
|
||
public void SaveAllOrdersToPdfFile(ReportBindingModel model)
|
||
{
|
||
_saveOrdersToPdf.CreateDoc(new ShopPdfInfo
|
||
{
|
||
FileName = model.FileName,
|
||
Title = "Список заказов",
|
||
Orders = GetOrdersAll()
|
||
});
|
||
}
|
||
}
|
||
} |