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 { "5cm", "6cm", "3cm", "3cm"}); CreateRow(new PdfRowParameters { Texts = new List { "Ученик", "Занятие", "Дата получения занятия", "Пополнение счета" }, 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 { 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 { "4cm", "5cm", "5cm", "3cm", }); CreateRow(new PdfRowParameters { Texts = new List { "Дата получения", "Занятие", "Требование", "Сумма требования" }, 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 { discipline.DateOfPassage.ToShortDateString(), discipline.Name, requirement.NameOfRequirement, requirement.Price.ToString(), }, Style = "Normal", ParagraphAlignment = PdfParagraphAlignmentType.Left }); } } SavePdf(info); } /// /// Создание doc-файла /// /// protected abstract void CreatePdf(PdfInfo info); /// /// Создание параграфа с текстом /// protected abstract void CreateParagraph(PdfParagraph paragraph); /// /// Создание таблицы /// protected abstract void CreateTable(List columns); /// /// Создание и заполнение строки /// /// protected abstract void CreateRow(PdfRowParameters rowParameters); /// /// Сохранение файла /// /// protected abstract void SavePdf(PdfInfo info); } }