136 lines
5.8 KiB
C#
136 lines
5.8 KiB
C#
|
using SchoolBusinessLogics.OfficePackage.HelperEnums;
|
|||
|
using SchoolBusinessLogics.OfficePackage.HelperModels;
|
|||
|
using SchoolContracts.ViewModels;
|
|||
|
|
|||
|
namespace SchoolBusinessLogics.OfficePackage
|
|||
|
{
|
|||
|
public abstract class AbstractSaveToPdf
|
|||
|
{
|
|||
|
public void CreateDocForAccounts(PdfInfo info)
|
|||
|
{
|
|||
|
CreatePdf(info);
|
|||
|
CreateParagraph(new PdfParagraph { Text = info.Title, Style = "NormalTitle", ParagraphAlignment = PdfParagraphAlignmentType.Center });
|
|||
|
CreateParagraph(new PdfParagraph {
|
|||
|
Text = $"с {info.DateFrom.ToShortDateString()} по {info.DateTo.ToShortDateString()}", Style = "Normal",
|
|||
|
ParagraphAlignment = PdfParagraphAlignmentType.Center });
|
|||
|
|
|||
|
CreateTable(new List<string> { "5cm", "6cm", "3cm", "3cm"});
|
|||
|
|
|||
|
CreateRow(new PdfRowParameters
|
|||
|
{
|
|||
|
Texts = new List<string> { "Ученик", "Занятие", "Дата получения занятия", "Пополнение счета" },
|
|||
|
Style = "NormalTitle",
|
|||
|
ParagraphAlignment = PdfParagraphAlignmentType.Center
|
|||
|
});
|
|||
|
var sumPaidPrice = 0.0;
|
|||
|
foreach (var pc in info.ReportObjects)
|
|||
|
{
|
|||
|
if (pc is not AccountViewModel account)
|
|||
|
{
|
|||
|
throw new ArgumentException($"Передан некорректный тип в отчет: " +
|
|||
|
$"ожидается Account; Получен объект типа: {pc.GetType()}", nameof(info));
|
|||
|
}
|
|||
|
|
|||
|
if (account.Student == null || account.ClientByDiscipline == null)
|
|||
|
{
|
|||
|
throw new ArgumentNullException(nameof(account), $"Получена модель счета c нулевыми полями");
|
|||
|
}
|
|||
|
sumPaidPrice += account.Price;
|
|||
|
CreateRow(new PdfRowParameters
|
|||
|
{
|
|||
|
Texts = new List<string>
|
|||
|
{
|
|||
|
account.Student.Name,
|
|||
|
account.Discipline?.Name ?? string.Empty,
|
|||
|
account.StudentByDiscipline.DateOfStudent.ToShortDateString(),
|
|||
|
account.Price.ToString(),
|
|||
|
},
|
|||
|
Style = "Normal",
|
|||
|
ParagraphAlignment = PdfParagraphAlignmentType.Left
|
|||
|
});
|
|||
|
}
|
|||
|
CreateParagraph(new PdfParagraph { Text = $"Итого оплачено : {sumPaidPrice}\t", Style = "Normal", ParagraphAlignment = PdfParagraphAlignmentType.Rigth });
|
|||
|
|
|||
|
SavePdf(info);
|
|||
|
}
|
|||
|
|
|||
|
public void CreateDocForDisciplines(PdfInfo info)
|
|||
|
{
|
|||
|
CreatePdf(info);
|
|||
|
CreateParagraph(new PdfParagraph { Text = info.Title, Style = "NormalTitle", ParagraphAlignment = PdfParagraphAlignmentType.Center });
|
|||
|
CreateParagraph(new PdfParagraph
|
|||
|
{
|
|||
|
Text = $"с {info.DateFrom.ToShortDateString()} по {info.DateTo.ToShortDateString()}",
|
|||
|
Style = "Normal",
|
|||
|
ParagraphAlignment = PdfParagraphAlignmentType.Center
|
|||
|
});
|
|||
|
|
|||
|
CreateTable(new List<string> { "4cm", "5cm", "5cm", "3cm", });
|
|||
|
|
|||
|
CreateRow(new PdfRowParameters
|
|||
|
{
|
|||
|
Texts = new List<string> { "Дата получения", "Занятие", "Требование", "Сумма требования" },
|
|||
|
Style = "NormalTitle",
|
|||
|
ParagraphAlignment = PdfParagraphAlignmentType.Center
|
|||
|
});
|
|||
|
foreach (var pc in info.ReportObjects)
|
|||
|
{
|
|||
|
if (pc is not DisciplineViewModel discipline)
|
|||
|
{
|
|||
|
throw new ArgumentException($"Передан некорректный тип в отчет: " +
|
|||
|
$"ожидается Discipline; Получен объект типа: {pc.GetType()}", nameof(info));
|
|||
|
}
|
|||
|
|
|||
|
if (discipline.RequirementViewModels == null)
|
|||
|
{
|
|||
|
throw new ArgumentNullException($"Получена модель требований c нулевыми полями");
|
|||
|
}
|
|||
|
foreach(var requirement in discipline.RequirementViewModels)
|
|||
|
{
|
|||
|
CreateRow(new PdfRowParameters
|
|||
|
{
|
|||
|
Texts = new List<string>
|
|||
|
{
|
|||
|
discipline.DateOfPassage.ToShortDateString(),
|
|||
|
discipline.Name,
|
|||
|
requirement.NameOfRequirement,
|
|||
|
requirement.Price.ToString(),
|
|||
|
},
|
|||
|
Style = "Normal",
|
|||
|
ParagraphAlignment = PdfParagraphAlignmentType.Left
|
|||
|
});
|
|||
|
}
|
|||
|
}
|
|||
|
SavePdf(info);
|
|||
|
}
|
|||
|
|
|||
|
/// <summary>
|
|||
|
/// Создание doc-файла
|
|||
|
/// </summary>
|
|||
|
/// <param name="info"></param>
|
|||
|
protected abstract void CreatePdf(PdfInfo info);
|
|||
|
|
|||
|
/// <summary>
|
|||
|
/// Создание параграфа с текстом
|
|||
|
/// </summary>
|
|||
|
protected abstract void CreateParagraph(PdfParagraph paragraph);
|
|||
|
|
|||
|
/// <summary>
|
|||
|
/// Создание таблицы
|
|||
|
/// </summary>
|
|||
|
protected abstract void CreateTable(List<string> columns);
|
|||
|
|
|||
|
/// <summary>
|
|||
|
/// Создание и заполнение строки
|
|||
|
/// </summary>
|
|||
|
/// <param name="rowParameters"></param>
|
|||
|
protected abstract void CreateRow(PdfRowParameters rowParameters);
|
|||
|
|
|||
|
/// <summary>
|
|||
|
/// Сохранение файла
|
|||
|
/// </summary>
|
|||
|
/// <param name="info"></param>
|
|||
|
protected abstract void SavePdf(PdfInfo info);
|
|||
|
}
|
|||
|
}
|