diff --git a/Polyclinic/PolyclinicBusinessLogic/BusinessLogics/ImplementerReportLogic.cs b/Polyclinic/PolyclinicBusinessLogic/BusinessLogics/ImplementerReportLogic.cs index 5535cff..e626841 100644 --- a/Polyclinic/PolyclinicBusinessLogic/BusinessLogics/ImplementerReportLogic.cs +++ b/Polyclinic/PolyclinicBusinessLogic/BusinessLogics/ImplementerReportLogic.cs @@ -100,6 +100,7 @@ namespace PolyclinicBusinessLogic.BusinessLogics DateFrom = reportModel.DateStart, DateTo = reportModel.DateEnd, FileName = reportInfo.FileName, + PeriodString = reportInfo.GetPeriodString(), Report = reportModel }); } diff --git a/Polyclinic/PolyclinicBusinessLogic/OfficePackage/AbstractImplementerReports/AbstractReportDiagnosesByPeriodSaveToPdf.cs b/Polyclinic/PolyclinicBusinessLogic/OfficePackage/AbstractImplementerReports/AbstractReportDiagnosesByPeriodSaveToPdf.cs index 3b21310..fb7835c 100644 --- a/Polyclinic/PolyclinicBusinessLogic/OfficePackage/AbstractImplementerReports/AbstractReportDiagnosesByPeriodSaveToPdf.cs +++ b/Polyclinic/PolyclinicBusinessLogic/OfficePackage/AbstractImplementerReports/AbstractReportDiagnosesByPeriodSaveToPdf.cs @@ -17,14 +17,14 @@ namespace PolyclinicBusinessLogic.OfficePackage.AbstractImplementerReports }); CreateParagraph(new PdfParagraph { - Text = $"с {(info.DateFrom == null ? "-" : info.DateFrom?.ToShortDateString())} по {(info.DateTo == null ? "-" : info.DateTo?.ToShortDateString())}", + Text = info.PeriodString, Style = "Normal", ParagraphAlignment = PdfParagraphAlignmentType.Center }); - CreateTable(new List { "1cm", "4cm", "3cm", "3cm", "4cm", "4cm" }); + CreateTable(new List { "3cm", "3cm", "3cm", "4cm", "5cm" }); CreateRow(new PdfRowParameters { - Texts = new List { "#", "Название", "Начало", "Конец", "Симптомы", "Курсы" }, + Texts = new List { "Название", "Начало", "Конец", "Симптомы", "Курсы" }, Style = "NormalTitle", ParagraphAlignment = PdfParagraphAlignmentType.Center }); @@ -35,7 +35,6 @@ namespace PolyclinicBusinessLogic.OfficePackage.AbstractImplementerReports { Texts = new List { - diagnose.Id.ToString(), diagnose.Name, diagnose.DateStartDiagnose.ToShortDateString(), diagnose.DateStopDiagnose?.ToShortDateString() ?? string.Empty, @@ -57,7 +56,6 @@ namespace PolyclinicBusinessLogic.OfficePackage.AbstractImplementerReports "", "", "", - "", symptom?.Name ?? string.Empty, (course == null ? string.Empty : $"#{course.Id} {course.Comment}") }, diff --git a/Polyclinic/PolyclinicBusinessLogic/OfficePackage/HelperModels/PDF/PdfDiagnosesByPeriodInfo.cs b/Polyclinic/PolyclinicBusinessLogic/OfficePackage/HelperModels/PDF/PdfDiagnosesByPeriodInfo.cs index a69be76..ac6ed04 100644 --- a/Polyclinic/PolyclinicBusinessLogic/OfficePackage/HelperModels/PDF/PdfDiagnosesByPeriodInfo.cs +++ b/Polyclinic/PolyclinicBusinessLogic/OfficePackage/HelperModels/PDF/PdfDiagnosesByPeriodInfo.cs @@ -6,6 +6,7 @@ namespace PolyclinicBusinessLogic.OfficePackage.HelperModels.PDF { public string Title { get; set; } = string.Empty; public string FileName { get; set; } = string.Empty; + public string PeriodString { get; set; } = string.Empty; public DateTime? DateFrom { get; set; } public DateTime? DateTo { get; set; } public ReportDiagnosesByPeriodViewModel Report { get; set; } = new(); diff --git a/Polyclinic/PolyclinicContracts/BindingModels/ReportBindingModel.cs b/Polyclinic/PolyclinicContracts/BindingModels/ReportBindingModel.cs index 6a75230..a7a65f7 100644 --- a/Polyclinic/PolyclinicContracts/BindingModels/ReportBindingModel.cs +++ b/Polyclinic/PolyclinicContracts/BindingModels/ReportBindingModel.cs @@ -1,9 +1,33 @@ -namespace PolyclinicContracts.BindingModels +using static System.Net.Mime.MediaTypeNames; +using System.Reflection; + +namespace PolyclinicContracts.BindingModels { public class ReportBindingModel { public string? FileName { get; set; } public DateTime? DateFrom { get; set; } public DateTime? DateTo { get; set; } + public string GetPeriodString() + { + string txt = ""; + if (DateFrom == null && DateTo == null) + { + txt = "за все время"; + } + else if (DateFrom == null) + { + txt = $"по {DateTo?.ToShortDateString()}"; + } + else if (DateTo == null) + { + txt = $"с {DateFrom?.ToShortDateString()}"; + } + else + { + txt = $"с {DateFrom?.ToShortDateString()} по {DateTo?.ToShortDateString()}"; + } + return txt; + } } } diff --git a/Polyclinic/PolyclinicWebAppImplementer/Controllers/ReportsController.cs b/Polyclinic/PolyclinicWebAppImplementer/Controllers/ReportsController.cs index b43b8de..0e67941 100644 --- a/Polyclinic/PolyclinicWebAppImplementer/Controllers/ReportsController.cs +++ b/Polyclinic/PolyclinicWebAppImplementer/Controllers/ReportsController.cs @@ -1,4 +1,5 @@ using Microsoft.AspNetCore.Mvc; +using PolyclinicBusinessLogic.BusinessLogics; using PolyclinicBusinessLogic.OfficePackage.HelperEnums; using PolyclinicContracts.BindingModels; using PolyclinicContracts.BusinessLogicsContracts; @@ -12,11 +13,13 @@ namespace PolyclinicWebAppImplementer.Controllers { private readonly IImplementerReportLogic _reportLogic; private readonly IDiagnoseLogic _diagnoseLogic; + private readonly SendMailLogic _sendMailLogic; - public ReportsController(IImplementerReportLogic reportLogic, IDiagnoseLogic diagnoseLogic) + public ReportsController(IImplementerReportLogic reportLogic, IDiagnoseLogic diagnoseLogic, SendMailLogic sendMailLogic) { _reportLogic = reportLogic; _diagnoseLogic = diagnoseLogic; + _sendMailLogic = sendMailLogic; } [HttpGet] @@ -54,7 +57,26 @@ namespace PolyclinicWebAppImplementer.Controllers var filePath = Path.Combine(Directory.GetCurrentDirectory(), fileName); byte[] fileBytes = System.IO.File.ReadAllBytes(filePath); - return File(fileBytes, "application/pdf", fileName); + if (System.IO.File.Exists(filePath)) + { + try + { + string txt = reportInfo.GetPeriodString(); + var userEmail = currentUser.Email; + _sendMailLogic.SendEmail(userEmail, $"Здравствуйте, {currentUser.FIO}! В приложении отчет по болезням {txt} от {DateTime.Now.ToString()}", filePath); + + model.Message = $"Отчет в формате .pdf был отправлен на почту {currentUser.Email}"; + return View(model); + } + catch (Exception) + { + model.Error = $"Произошла ошибка при отправке отчета"; + } + } + else + { + model.Error = "Произошла ошибка при генерации отчета"; + } } return View(model); } @@ -102,7 +124,7 @@ namespace PolyclinicWebAppImplementer.Controllers var filePath = Path.Combine(Directory.GetCurrentDirectory(), reportInfo.FileName); byte[] fileBytes = System.IO.File.ReadAllBytes(filePath); string mimeType = model.ReportType == ReportType.Word ? "application/vnd.openxmlformats-officedocument.wordprocessingml.document" : "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"; - + return File(fileBytes, mimeType, reportInfo.FileName); } } diff --git a/Polyclinic/PolyclinicWebAppImplementer/Models/DiagnosesByPeriodFormModel.cs b/Polyclinic/PolyclinicWebAppImplementer/Models/DiagnosesByPeriodFormModel.cs index 820e09f..41d5df8 100644 --- a/Polyclinic/PolyclinicWebAppImplementer/Models/DiagnosesByPeriodFormModel.cs +++ b/Polyclinic/PolyclinicWebAppImplementer/Models/DiagnosesByPeriodFormModel.cs @@ -12,5 +12,7 @@ namespace PolyclinicWebAppImplementer.Models public DateTime? DateEnd { get; set; } public ReportType ReportType { get; set; } public ReportDiagnosesByPeriodViewModel? Report { get; set; } + public string? Error { get; set; } + public string? Message { get; set; } } } diff --git a/Polyclinic/PolyclinicWebAppImplementer/Program.cs b/Polyclinic/PolyclinicWebAppImplementer/Program.cs index 89fe6c8..b267cac 100644 --- a/Polyclinic/PolyclinicWebAppImplementer/Program.cs +++ b/Polyclinic/PolyclinicWebAppImplementer/Program.cs @@ -32,6 +32,8 @@ builder.Services.AddTransient(); builder.Services.AddTransient(); builder.Services.AddTransient(); +builder.Services.AddTransient(); + builder.Services.AddTransient(); builder.Services.AddTransient(); builder.Services.AddTransient(); diff --git a/Polyclinic/PolyclinicWebAppImplementer/Views/Reports/DiagnosesByPeriod.cshtml b/Polyclinic/PolyclinicWebAppImplementer/Views/Reports/DiagnosesByPeriod.cshtml index 5bb209b..24b9e10 100644 --- a/Polyclinic/PolyclinicWebAppImplementer/Views/Reports/DiagnosesByPeriod.cshtml +++ b/Polyclinic/PolyclinicWebAppImplementer/Views/Reports/DiagnosesByPeriod.cshtml @@ -4,6 +4,18 @@ ViewBag.SelectedSiteMenuItem = SiteMenuItems.DiagnosesReport; }
+ @if (Model.Error != null) + { + + } + @if (Model.Message != null) + { + + }
diff --git a/Polyclinic/PolyclinicWebAppImplementer/appsettings.json b/Polyclinic/PolyclinicWebAppImplementer/appsettings.json index 10f68b8..46bcebe 100644 --- a/Polyclinic/PolyclinicWebAppImplementer/appsettings.json +++ b/Polyclinic/PolyclinicWebAppImplementer/appsettings.json @@ -5,5 +5,12 @@ "Microsoft.AspNetCore": "Warning" } }, - "AllowedHosts": "*" + "AllowedHosts": "*", + "Smtp": { + "Host": "smtp.beget.com", + "Port": "2525", + "Username": "polyclinic@ekallin.ru", + "Password": "tlmu50*zAwN1", + "EnableSsl": "false" + } }