90 lines
2.8 KiB
C#
90 lines
2.8 KiB
C#
using GasStation.Repositories;
|
||
using Microsoft.Extensions.Logging;
|
||
|
||
namespace GasStation.Reports;
|
||
|
||
internal class DocReport
|
||
{
|
||
private readonly IGasmanRepository _gasmanRepository;
|
||
private readonly ISupplierRepository _supplierRepository;
|
||
private readonly IProductRepository _productRepository;
|
||
private readonly ILogger<DocReport> _logger;
|
||
|
||
public DocReport(IGasmanRepository gasmanRepository, ISupplierRepository supplierRepository,
|
||
IProductRepository productRepository, ILogger<DocReport> logger)
|
||
{
|
||
_gasmanRepository = gasmanRepository ??
|
||
throw new
|
||
ArgumentNullException(nameof(gasmanRepository));
|
||
_supplierRepository = supplierRepository ??
|
||
throw new ArgumentNullException(nameof(supplierRepository));
|
||
_productRepository = productRepository ??
|
||
throw new ArgumentNullException(nameof(productRepository));
|
||
_logger = logger ??
|
||
throw new ArgumentNullException(nameof(logger));
|
||
}
|
||
|
||
public bool CreateDoc(string filePath, bool includeGasmen, bool includeSuppliers, bool includeProducts)
|
||
{
|
||
try
|
||
{
|
||
var builder = new WordBuilder(filePath)
|
||
.AddHeader("Документ со справочниками");
|
||
if (includeGasmen)
|
||
{
|
||
builder.AddParagraph("Запрвщики")
|
||
.AddTable([2400, 2400, 2400],
|
||
GetGasmen());
|
||
}
|
||
if (includeSuppliers)
|
||
{
|
||
builder.AddParagraph("Поставщики")
|
||
.AddTable([2400], GetSuppliers());
|
||
}
|
||
if (includeProducts)
|
||
{
|
||
builder.AddParagraph("Товары")
|
||
.AddTable([2400, 2400], GetProducts());
|
||
}
|
||
builder.Build();
|
||
return true;
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
_logger.LogError(ex, "Ошибка при формировании документа");
|
||
return false;
|
||
}
|
||
}
|
||
|
||
private List<string[]> GetGasmen()
|
||
{
|
||
return [
|
||
["Имя работника", "Телефон", "Должность"],
|
||
.. _gasmanRepository
|
||
.ReadGasman()
|
||
.Select(x => new string[] { x.GasmanName, x.PhoneNumber, x.Post.ToString() }),
|
||
];
|
||
}
|
||
|
||
private List<string[]> GetSuppliers()
|
||
{
|
||
return [
|
||
["Название поставщика"],
|
||
.. _supplierRepository
|
||
.ReadSupplier()
|
||
.Select(x => new string[] { x.SupplierName }),
|
||
];
|
||
}
|
||
|
||
private List<string[]> GetProducts()
|
||
{
|
||
return [
|
||
["Стоимость товара", "Тип товара"],
|
||
.. _productRepository
|
||
.ReadProduct()
|
||
.Select(x => new string[] { x.ProductCost.ToString(), x.ProductType.ToString() }),
|
||
];
|
||
}
|
||
|
||
}
|