diff --git a/Polyclinic/PolyclinicBusinessLogic/OfficePackage/AbstractSaveToPdfProcedures.cs b/Polyclinic/PolyclinicBusinessLogic/OfficePackage/AbstractSaveToPdfProcedures.cs index f0630f9..d4b3873 100644 --- a/Polyclinic/PolyclinicBusinessLogic/OfficePackage/AbstractSaveToPdfProcedures.cs +++ b/Polyclinic/PolyclinicBusinessLogic/OfficePackage/AbstractSaveToPdfProcedures.cs @@ -20,7 +20,7 @@ namespace PolyclinicBusinessLogic.OfficePackage Style = "Normal", ParagraphAlignment = PdfParagraphAlignmentType.Center }); - CreateTable(new List { "1cm", "3cm", "3cm", "4cm", "4cm", "4cm" }); + CreateTable(new List { "2cm", "3cm", "3cm", "4cm", "4cm", "4cm" }); CreateRow(new PdfRowParameters { Texts = new List { "Номер", "Период 'с'", "Период 'до'", "Процедура", "Лекарство", "Симптом" }, @@ -29,47 +29,48 @@ namespace PolyclinicBusinessLogic.OfficePackage }); foreach (var procedure in info.Procedures) { + // Добавление строки с основной информацией о процедуре + CreateRow(new PdfRowParameters + { + Texts = new List + { + procedure.Id.ToString(), + procedure.DateStartProcedure.ToShortTimeString(), + procedure.DateStopProcedure?.ToShortTimeString() ?? "нет даты окончания процедуры", + procedure.ProcedureName, + "", + "" + }, + Style = "Normal", + ParagraphAlignment = PdfParagraphAlignmentType.Left, + }); + foreach (var ms in procedure.MedicamentSymptom) { + // Добавление строки для каждого лекарства и симптома без дублирования названия процедуры CreateRow(new PdfRowParameters { - Texts = new List { procedure.Id.ToString(), procedure.DateStartProcedure.ToShortTimeString(), - procedure.DateStopProcedure?.ToShortTimeString() ?? "нет даты окончания процедуры", - procedure.ProcedureName, ms.medicamentName, ms.symptomName}, + Texts = new List + { + "", + "", + "", + "", + ms.medicamentName, + ms.symptomName + }, Style = "Normal", ParagraphAlignment = PdfParagraphAlignmentType.Left, }); } - } 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/Implements/SaveToPdfProcedures.cs b/Polyclinic/PolyclinicBusinessLogic/OfficePackage/Implements/SaveToPdfProcedures.cs index dbd07ba..836d54d 100644 --- a/Polyclinic/PolyclinicBusinessLogic/OfficePackage/Implements/SaveToPdfProcedures.cs +++ b/Polyclinic/PolyclinicBusinessLogic/OfficePackage/Implements/SaveToPdfProcedures.cs @@ -29,7 +29,7 @@ namespace PolyclinicBusinessLogic.OfficePackage.Implements { var style = document.Styles["Normal"]; style.Font.Name = "Times New Roman"; - style.Font.Size = 14; + style.Font.Size = 11; style = document.Styles.AddStyle("NormalTitle", "Normal"); style.Font.Bold = true; } @@ -57,6 +57,19 @@ namespace PolyclinicBusinessLogic.OfficePackage.Implements return; } _table = _document.LastSection.AddTable(); + // Получаем доступную ширину страницы, чтобы таблица не вылезала за края + var pageWidth = _document.DefaultPageSetup.PageWidth - _document.DefaultPageSetup.LeftMargin - _document.DefaultPageSetup.RightMargin; + var totalWidth = columns.Sum(col => Unit.FromCentimeter(double.Parse(col.Replace("cm", "")))); + + // Если ширина таблицы превышает доступную ширину страницы, уменьшаем ширину колонок пропорционально + if (totalWidth > pageWidth) + { + var scale = pageWidth / totalWidth; + for (int i = 0; i < columns.Count; i++) + { + columns[i] = $"{Unit.FromCentimeter(double.Parse(columns[i].Replace("cm", "")) * scale).Centimeter}cm"; + } + } foreach (var elem in columns) { _table.AddColumn(elem); diff --git a/Polyclinic/PolyclinicWebAppSuretor/Controllers/HomeController.cs b/Polyclinic/PolyclinicWebAppSuretor/Controllers/HomeController.cs index 1ae776e..57fe5fb 100644 --- a/Polyclinic/PolyclinicWebAppSuretor/Controllers/HomeController.cs +++ b/Polyclinic/PolyclinicWebAppSuretor/Controllers/HomeController.cs @@ -425,11 +425,9 @@ namespace PolyclinicWebAppSuretor.Controllers _suretorReportLogic.SaveProceduresToPdfFile(reportBindingModel); // - //var fileBytes = System.IO.File.ReadAllBytes(reportBindingModel.FileName); var fileName = "ProceduresReport.pdf"; var filePath = Path.Combine(Directory.GetCurrentDirectory(), fileName); byte[] fileBytes = System.IO.File.ReadAllBytes(filePath); - // return File(fileBytes, "application/pdf", fileName); }