113 lines
3.8 KiB
C#
113 lines
3.8 KiB
C#
|
using Microsoft.Extensions.Logging;
|
|||
|
using ProjectGSM.Repositories;
|
|||
|
|
|||
|
namespace ProjectGSM.Documents;
|
|||
|
|
|||
|
public class DocReport
|
|||
|
{
|
|||
|
private readonly IAdvocateRepository _advocateRepository;
|
|||
|
private readonly IClientRepository _clientRepository;
|
|||
|
private readonly ICourtRepository _courtRepository;
|
|||
|
private readonly ILogger<DocReport> _logger;
|
|||
|
|
|||
|
public DocReport(IAdvocateRepository advocateRepository, IClientRepository
|
|||
|
clientRepository,
|
|||
|
ICourtRepository courtRepository, ILogger<DocReport> logger)
|
|||
|
{
|
|||
|
_advocateRepository = advocateRepository ??
|
|||
|
throw new
|
|||
|
ArgumentNullException(nameof(advocateRepository));
|
|||
|
_clientRepository = clientRepository ??
|
|||
|
throw new ArgumentNullException(nameof(clientRepository));
|
|||
|
_courtRepository = courtRepository ??
|
|||
|
throw new ArgumentNullException(nameof(courtRepository));
|
|||
|
_logger = logger ??
|
|||
|
throw new ArgumentNullException(nameof(logger));
|
|||
|
}
|
|||
|
|
|||
|
public bool CreateDoc(string filePath, bool includeAdvocates, bool
|
|||
|
includeClients, bool includeCourts)
|
|||
|
{
|
|||
|
try
|
|||
|
{
|
|||
|
var builder = new WordBuilder(filePath)
|
|||
|
.AddHeader("Документ со справочниками");
|
|||
|
if (includeAdvocates)
|
|||
|
{
|
|||
|
builder.AddParagraph("Адвокаты")
|
|||
|
.AddTable([2400, 1200, 2400, 1200, 1200, 1200, 2400, 2400, 2400, 5000],
|
|||
|
GetAdvocates());
|
|||
|
}
|
|||
|
|
|||
|
if (includeClients)
|
|||
|
{
|
|||
|
builder.AddParagraph("Клиенты")
|
|||
|
.AddTable([2400, 2400, 2400, 2400, 2400, 2400], GetClients());
|
|||
|
}
|
|||
|
|
|||
|
if (includeCourts)
|
|||
|
{
|
|||
|
builder.AddParagraph("Суды")
|
|||
|
.AddTable([2400, 2400], GetCourts());
|
|||
|
}
|
|||
|
|
|||
|
builder.Build();
|
|||
|
return true;
|
|||
|
}
|
|||
|
catch (Exception ex)
|
|||
|
{
|
|||
|
_logger.LogError(ex, "Ошибка при формировании документа");
|
|||
|
return false;
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
private List<string[]> GetAdvocates()
|
|||
|
{
|
|||
|
return
|
|||
|
[
|
|||
|
[
|
|||
|
"ФИО", "Пол", "Дата рождения", "Опыт", "Кол-во завершенных дел", "Рейтинг", "E-mail", "Номер телефона",
|
|||
|
"Адрес", "Лицензии"
|
|||
|
],
|
|||
|
.. _advocateRepository
|
|||
|
.ReadAdvocates()
|
|||
|
.Select(x => new[]
|
|||
|
{
|
|||
|
x.Name,
|
|||
|
x.Sex ? "Мужчина" : "Женщина", x.DateOfBirth.ToShortDateString(), x.Experience.ToString(),
|
|||
|
x.CompletedTasks.ToString(), x.Rating.ToString(), x.Email, x.PhoneNumber, x.Address,
|
|||
|
x.LicenseType.ToString()
|
|||
|
}),
|
|||
|
];
|
|||
|
}
|
|||
|
|
|||
|
private List<string[]> GetClients()
|
|||
|
{
|
|||
|
return
|
|||
|
[
|
|||
|
["ФИО", "Пол", "Дата рождения", "E-mail", "Номер телефона", "Адрес"],
|
|||
|
.. _clientRepository
|
|||
|
.ReadClients()
|
|||
|
.Select(x => new[]
|
|||
|
{
|
|||
|
x.Name,
|
|||
|
x.Sex ? "Мужчина" : "Женщина", x.DateOfBirth.ToShortDateString(), x.Email, x.PhoneNumber, x.Address
|
|||
|
}),
|
|||
|
];
|
|||
|
}
|
|||
|
|
|||
|
private List<string[]> GetCourts()
|
|||
|
{
|
|||
|
return
|
|||
|
[
|
|||
|
["Название", "Адрес"],
|
|||
|
.. _courtRepository
|
|||
|
.ReadCourts()
|
|||
|
.Select(x => new[]
|
|||
|
{
|
|||
|
x.Name,
|
|||
|
x.Address
|
|||
|
}),
|
|||
|
];
|
|||
|
}
|
|||
|
}
|