From db2fdf476350aedf07c82c28025427495c2855da Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=95=D0=BB=D0=B5=D0=BD=D0=B0=20=D0=91=D0=B0=D0=BA=D0=B0?= =?UTF-8?q?=D0=BB=D1=8C=D1=81=D0=BA=D0=B0=D1=8F?= Date: Wed, 29 May 2024 14:53:56 +0400 Subject: [PATCH] =?UTF-8?q?=D0=BD=D0=B0=D1=87=D0=B0=D0=BB=D0=B0=20=D0=BE?= =?UTF-8?q?=D1=82=D1=87=D0=B5=D1=82=20=D0=B4=D0=BB=D1=8F=20=D0=BF=D0=B4?= =?UTF-8?q?=D1=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../AbstractSaveToPdfCoursesByProcedure.cs | 75 ++++++++++++++ ...fProceduresByMedicamentsAndSymptomsInfo.cs | 15 +++ .../Implements/SaveToPdfCoursesByProcedure.cs | 98 +++++++++++++++++++ .../PolyclinicBusinessLogic.csproj | 1 + 4 files changed, 189 insertions(+) create mode 100644 Polyclinic/PolyclinicBusinessLogic/OfficePackage/AbstractSaveToPdfCoursesByProcedure.cs create mode 100644 Polyclinic/PolyclinicBusinessLogic/OfficePackage/HelperModels/PDF/PdfProceduresByMedicamentsAndSymptomsInfo.cs create mode 100644 Polyclinic/PolyclinicBusinessLogic/OfficePackage/Implements/SaveToPdfCoursesByProcedure.cs diff --git a/Polyclinic/PolyclinicBusinessLogic/OfficePackage/AbstractSaveToPdfCoursesByProcedure.cs b/Polyclinic/PolyclinicBusinessLogic/OfficePackage/AbstractSaveToPdfCoursesByProcedure.cs new file mode 100644 index 0000000..6660d16 --- /dev/null +++ b/Polyclinic/PolyclinicBusinessLogic/OfficePackage/AbstractSaveToPdfCoursesByProcedure.cs @@ -0,0 +1,75 @@ +using PolyclinicBusinessLogic.OfficePackage.HelperEnums; +using PolyclinicBusinessLogic.OfficePackage.HelperModels.PDF; + +namespace PolyclinicBusinessLogic.OfficePackage +{ + public abstract class AbstractSaveToPdfCoursesByProcedure + { + public void CreateDoc(PdfProceduresByMedicamentsAndSymptomsInfo 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 { "1cm", "3cm", "3cm", "4cm", "4cm", "4cm" }); + CreateRow(new PdfRowParameters + { + Texts = new List { "Номер", "Дата начала процедуры", "Дата окончания процедуры", "Процедура", "Лекарство", "Симптом" }, + Style = "NormalTitle", + ParagraphAlignment = PdfParagraphAlignmentType.Center + }); + foreach (var order in info.Orders) + { + CreateRow(new PdfRowParameters + { + Texts = new List { order.Id.ToString(), order.DateCreate.ToShortDateString(), order.Status.ToString(), order.SushiName, order.Sum.ToString() }, + Style = "Normal", + ParagraphAlignment = PdfParagraphAlignmentType.Left, + }); + } + CreateParagraph(new PdfParagraph + { + Text = $"Итого: {info.Orders.Sum(x => x.Sum)}\t", + Style = "Normal", + ParagraphAlignment = PdfParagraphAlignmentType.Rigth + }); + SavePdf(info); + } + /// + /// Создание doc-файла + /// + /// + protected abstract void CreatePdf(PdfProceduresByMedicamentsAndSymptomsInfo info); + /// + /// Создание параграфа с текстом + /// + /// + /// + protected abstract void CreateParagraph(PdfParagraph paragraph); + /// + /// Создание таблицы + /// + /// + /// + protected abstract void CreateTable(List columns); + /// + /// Создание и заполнение строки + /// + /// + protected abstract void CreateRow(PdfRowParameters rowParameters); + /// + /// Сохранение файла + /// + /// + protected abstract void SavePdf(PdfProceduresByMedicamentsAndSymptomsInfo info); + } +} diff --git a/Polyclinic/PolyclinicBusinessLogic/OfficePackage/HelperModels/PDF/PdfProceduresByMedicamentsAndSymptomsInfo.cs b/Polyclinic/PolyclinicBusinessLogic/OfficePackage/HelperModels/PDF/PdfProceduresByMedicamentsAndSymptomsInfo.cs new file mode 100644 index 0000000..1bfa644 --- /dev/null +++ b/Polyclinic/PolyclinicBusinessLogic/OfficePackage/HelperModels/PDF/PdfProceduresByMedicamentsAndSymptomsInfo.cs @@ -0,0 +1,15 @@ +using PolyclinicContracts.ViewModels; + +namespace PolyclinicBusinessLogic.OfficePackage.HelperModels.PDF +{ + public class PdfProceduresByMedicamentsAndSymptomsInfo + { + public string Title { get; set; } = string.Empty; + public string FileName { get; set; } = string.Empty; + public DateTime DateFrom { get; set; } + public DateTime DateTo { get; set; } + public List Procedures{ get; set; } = new(); + public List Medicaments { get; set; } = new(); + public List Symptoms { get; set; } = new(); + } +} diff --git a/Polyclinic/PolyclinicBusinessLogic/OfficePackage/Implements/SaveToPdfCoursesByProcedure.cs b/Polyclinic/PolyclinicBusinessLogic/OfficePackage/Implements/SaveToPdfCoursesByProcedure.cs new file mode 100644 index 0000000..44ac638 --- /dev/null +++ b/Polyclinic/PolyclinicBusinessLogic/OfficePackage/Implements/SaveToPdfCoursesByProcedure.cs @@ -0,0 +1,98 @@ +using MigraDoc.DocumentObjectModel; +using MigraDoc.DocumentObjectModel.Tables; +using MigraDoc.Rendering; +using PolyclinicBusinessLogic.OfficePackage.HelperEnums; +using PolyclinicBusinessLogic.OfficePackage.HelperModels.PDF; + +namespace PolyclinicBusinessLogic.OfficePackage.Implements +{ + public class SaveToPdfCoursesByProcedure : AbstractSaveToPdfCoursesByProcedure + { + private Document? _document; + private Section? _section; + private Table? _table; + private static ParagraphAlignment GetParagraphAlignment(PdfParagraphAlignmentType type) + { + return type switch + { + PdfParagraphAlignmentType.Center => ParagraphAlignment.Center, + PdfParagraphAlignmentType.Left => ParagraphAlignment.Left, + PdfParagraphAlignmentType.Rigth => ParagraphAlignment.Right, + _ => ParagraphAlignment.Justify, + }; + } + /// + /// Создание стилей для документа + /// + /// + private static void DefineStyles(Document document) + { + var style = document.Styles["Normal"]; + style.Font.Name = "Times New Roman"; + style.Font.Size = 14; + style = document.Styles.AddStyle("NormalTitle", "Normal"); + style.Font.Bold = true; + } + protected override void CreatePdf(PdfProceduresByMedicamentsAndSymptomsInfo info) + { + _document = new Document(); + DefineStyles(_document); + _section = _document.AddSection(); + } + protected override void CreateParagraph(PdfParagraph pdfParagraph) + { + if (_section == null) + { + return; + } + var paragraph = _section.AddParagraph(pdfParagraph.Text); + paragraph.Format.SpaceAfter = "1cm"; + paragraph.Format.Alignment = GetParagraphAlignment(pdfParagraph.ParagraphAlignment); + paragraph.Style = pdfParagraph.Style; + } + protected override void CreateTable(List columns) + { + if (_document == null) + { + return; + } + _table = _document.LastSection.AddTable(); + foreach (var elem in columns) + { + _table.AddColumn(elem); + } + } + protected override void CreateRow(PdfRowParameters rowParameters) + { + if (_table == null) + { + return; + } + var row = _table.AddRow(); + for (int i = 0; i < rowParameters.Texts.Count; ++i) + { + row.Cells[i].AddParagraph(rowParameters.Texts[i]); + if (!string.IsNullOrEmpty(rowParameters.Style)) + { + row.Cells[i].Style = rowParameters.Style; + } + Unit borderWidth = 0.5; + row.Cells[i].Borders.Left.Width = borderWidth; + row.Cells[i].Borders.Right.Width = borderWidth; + row.Cells[i].Borders.Top.Width = borderWidth; + row.Cells[i].Borders.Bottom.Width = borderWidth; + row.Cells[i].Format.Alignment = GetParagraphAlignment(rowParameters.ParagraphAlignment); + row.Cells[i].VerticalAlignment = VerticalAlignment.Center; + } + } + protected override void SavePdf(PdfProceduresByMedicamentsAndSymptomsInfo info) + { + var renderer = new PdfDocumentRenderer(true) + { + Document = _document + }; + renderer.RenderDocument(); + renderer.PdfDocument.Save(info.FileName); + } + } +} diff --git a/Polyclinic/PolyclinicBusinessLogic/PolyclinicBusinessLogic.csproj b/Polyclinic/PolyclinicBusinessLogic/PolyclinicBusinessLogic.csproj index ee32ea1..968b6ae 100644 --- a/Polyclinic/PolyclinicBusinessLogic/PolyclinicBusinessLogic.csproj +++ b/Polyclinic/PolyclinicBusinessLogic/PolyclinicBusinessLogic.csproj @@ -9,6 +9,7 @@ +