106 lines
4.7 KiB
C#
106 lines
4.7 KiB
C#
|
using Microsoft.Extensions.Logging;
|
|||
|
using ProjectOptika.Scripts.Repositories;
|
|||
|
|
|||
|
namespace ProjectOptika.Scripts.Reports
|
|||
|
{
|
|||
|
internal class DocReport
|
|||
|
{
|
|||
|
private readonly IAccessoriesRepository _accessoriesRepository;
|
|||
|
private readonly IClientRepositiory _clientRepositiory;
|
|||
|
private readonly IEmployeeRepository _employeeRepository;
|
|||
|
private readonly ISpecificationsRepository _specificationsRepository;
|
|||
|
private readonly ILogger<DocReport> _logger;
|
|||
|
public DocReport(IAccessoriesRepository accessoriesRepository, IClientRepositiory clientRepositiory, IEmployeeRepository employeeRepository, ISpecificationsRepository specificationsRepository,
|
|||
|
ILogger<DocReport> logger)
|
|||
|
{
|
|||
|
_accessoriesRepository = accessoriesRepository ??
|
|||
|
throw new ArgumentNullException(nameof(accessoriesRepository));
|
|||
|
|
|||
|
_clientRepositiory = clientRepositiory ??
|
|||
|
throw new ArgumentNullException(nameof(clientRepositiory));
|
|||
|
|
|||
|
_employeeRepository = employeeRepository ??
|
|||
|
throw new ArgumentNullException(nameof(employeeRepository));
|
|||
|
|
|||
|
_specificationsRepository = specificationsRepository ??
|
|||
|
throw new ArgumentNullException(nameof(specificationsRepository));
|
|||
|
|
|||
|
_logger = logger ??
|
|||
|
throw new ArgumentNullException(nameof(logger));
|
|||
|
}
|
|||
|
public bool CreateDoc(string filePath, bool includeAccessories, bool includeSpecification,
|
|||
|
bool includeEmployees, bool includeClients)
|
|||
|
{
|
|||
|
try
|
|||
|
{
|
|||
|
var builder = new WordBuilder(filePath).AddHeader("Документ со справочниками");
|
|||
|
if (includeAccessories)
|
|||
|
{
|
|||
|
builder.AddParagraph("Аксессуары")
|
|||
|
.AddTable([2400, 2400, 2400, 1200, 1200, 1200, 2400],
|
|||
|
GetAccessories());
|
|||
|
}
|
|||
|
if (includeSpecification)
|
|||
|
{
|
|||
|
builder.AddParagraph("Характеристики")
|
|||
|
.AddTable([1200, 1200, 2400, 1200, 1200, 2400], GetSpecification());
|
|||
|
}
|
|||
|
if (includeEmployees)
|
|||
|
{
|
|||
|
builder.AddParagraph("Сотрудники")
|
|||
|
.AddTable([2400, 2400, 2400, 2400], GetEmploeyees());
|
|||
|
}
|
|||
|
if (includeClients)
|
|||
|
{
|
|||
|
builder.AddParagraph("Клиент")
|
|||
|
.AddTable([2400, 2400, 2400, 2400, 2400], GetClients());
|
|||
|
}
|
|||
|
builder.Build();
|
|||
|
return true;
|
|||
|
}
|
|||
|
catch (Exception ex)
|
|||
|
{
|
|||
|
_logger.LogError(ex, "Ошибка при формировании документа");
|
|||
|
return false;
|
|||
|
}
|
|||
|
}
|
|||
|
private List<string[]> GetAccessories()
|
|||
|
{
|
|||
|
return [
|
|||
|
["Название", "Бренд", "Стоимость", "Наличие в магазине", "Наличие на складе", "Дата доставки", "Тип"],
|
|||
|
.. _accessoriesRepository.GetAccessories()
|
|||
|
.Select(x => new string[] { x.Name, x.Brand, x.Cost.ToString(), x.StockAvailability.ToString(), x.AvailabilityStore.ToString(), x.DeliveryDate.ToString(), x.CategoryName.ToString() }),
|
|||
|
];
|
|||
|
}
|
|||
|
private List<string[]> GetSpecification()
|
|||
|
{
|
|||
|
return [
|
|||
|
["ID аксессуара", "Материал", "Астигматизм", "Диоптрийность", "Страна изготовителя", "Время доставки"],
|
|||
|
.. _specificationsRepository
|
|||
|
.GetSpecifications()
|
|||
|
.Select(x => new string[] { x.AccessoriesID.ToString(), x.Material, x.Astigmatism, x.Dioptericity, x.OriginCountry, x.TimeProduction.ToString()}),
|
|||
|
];
|
|||
|
}
|
|||
|
private List<string[]> GetEmploeyees()
|
|||
|
{
|
|||
|
return [
|
|||
|
["Имя", "Отчество", "Фамилия", "Должность"],
|
|||
|
.. _employeeRepository
|
|||
|
.GetEmployees()
|
|||
|
.Select(x => new string[] { x.FirstName, x.SecondName, x.Surname, x.PositionEmployee.ToString() }),
|
|||
|
];
|
|||
|
}
|
|||
|
|
|||
|
private List<string[]> GetClients()
|
|||
|
{
|
|||
|
return [
|
|||
|
["Имя", "Отчество", "Фамилия", "Номер телефона", "Тип клиента"],
|
|||
|
.. _clientRepositiory
|
|||
|
.GetClients()
|
|||
|
.Select(x => new string[] { x.FirstName, x.SecondName, x.Surname, x.PhoneNumber, x.ClientType.ToString() }),
|
|||
|
];
|
|||
|
}
|
|||
|
|
|||
|
}
|
|||
|
}
|