83 lines
3.0 KiB
C#
83 lines
3.0 KiB
C#
|
using Microsoft.Extensions.Logging;
|
|||
|
using ProjectFamilyBudget.Repositories;
|
|||
|
using System;
|
|||
|
using System.Collections.Generic;
|
|||
|
using System.Linq;
|
|||
|
using System.Text;
|
|||
|
using System.Threading.Tasks;
|
|||
|
|
|||
|
namespace ProjectFamilyBudget.Reports;
|
|||
|
|
|||
|
public class DocReport
|
|||
|
{
|
|||
|
private readonly IPeople _peopleRepository;
|
|||
|
private readonly IIncome _incomeRepository;
|
|||
|
private readonly IExpense _expenseRepository;
|
|||
|
private readonly ILogger<DocReport> _logger;
|
|||
|
|
|||
|
public DocReport(IPeople peopleRepository, IIncome incomeRepository, IExpense expenseRepository, ILogger<DocReport> logger)
|
|||
|
{
|
|||
|
_peopleRepository = peopleRepository ?? throw new ArgumentNullException(nameof(peopleRepository));
|
|||
|
_incomeRepository = incomeRepository ?? throw new ArgumentNullException(nameof(incomeRepository));
|
|||
|
_expenseRepository = expenseRepository ?? throw new ArgumentNullException(nameof(expenseRepository));
|
|||
|
_logger = logger ?? throw new ArgumentNullException(nameof(logger));
|
|||
|
}
|
|||
|
|
|||
|
public bool CreateDoc(string filePath, bool includePeoples, bool includeIncomes, bool includeExpenses)
|
|||
|
{
|
|||
|
try
|
|||
|
{
|
|||
|
var builder = new WordBuilder(filePath).AddHeader("Документ со справочниками");
|
|||
|
if (includePeoples)
|
|||
|
{
|
|||
|
builder.AddParagraph("Люди").AddTable([2400, 2400, 1200, 2400], GetPeoples());
|
|||
|
}
|
|||
|
if (includeIncomes)
|
|||
|
{
|
|||
|
builder.AddParagraph("Доходы").AddTable([2400, 2400, 2400], GetIncomes());
|
|||
|
}
|
|||
|
if (includeExpenses)
|
|||
|
{
|
|||
|
builder.AddParagraph("Расходы").AddTable([2400, 2400, 2400], GetExpenses());
|
|||
|
}
|
|||
|
builder.Build();
|
|||
|
return true;
|
|||
|
}
|
|||
|
catch (Exception ex)
|
|||
|
{
|
|||
|
_logger.LogError(ex, "Ошибка при формировании документа");
|
|||
|
return false;
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
private List<string[]> GetPeoples()
|
|||
|
{
|
|||
|
return [
|
|||
|
["Имя человека", "Фамилия человека", "Возраст", "Член семьи"],
|
|||
|
.. _peopleRepository
|
|||
|
.ReadPeople()
|
|||
|
.Select(x => new string[] { x.Name, x.LastName, x.Age.ToString(), x.MemberType.ToString() }),
|
|||
|
];
|
|||
|
}
|
|||
|
|
|||
|
private List<string[]> GetIncomes()
|
|||
|
{
|
|||
|
return [
|
|||
|
["Тип дохода", "Название", "Категория дохода"],
|
|||
|
.. _incomeRepository
|
|||
|
.ReadIncome()
|
|||
|
.Select(x => new string[] { x.IncomeType.ToString(), x.Name, x.IncomeCategory }),
|
|||
|
];
|
|||
|
}
|
|||
|
|
|||
|
private List<string[]> GetExpenses()
|
|||
|
{
|
|||
|
return [
|
|||
|
["Тип расхода", "Название", "Категория расхода"],
|
|||
|
.. _expenseRepository
|
|||
|
.ReadExpense()
|
|||
|
.Select(x => new string[] { x.ExpenseType.ToString(), x.Name, x.ExpenseCategory }),
|
|||
|
];
|
|||
|
}
|
|||
|
}
|