все
This commit is contained in:
parent
c07422e040
commit
9e6be7f23c
@ -1,4 +1,5 @@
|
||||
using HospitalContracts.BindingModels;
|
||||
using HospitalBusinessLogic.MailWorker;
|
||||
using HospitalContracts.BindingModels;
|
||||
using HospitalContracts.BusinessLogicsContracts;
|
||||
using HospitalContracts.SearchModels;
|
||||
using HospitalContracts.StoragesContracts;
|
||||
@ -17,10 +18,14 @@ namespace HospitalBusinessLogic.BusinessLogics
|
||||
{
|
||||
private readonly ILogger _logger;
|
||||
private readonly IRecipesStorage _recipesStorage;
|
||||
public RecipesLogic(ILogger<RecipesLogic> logger, IRecipesStorage recipesStorage)
|
||||
private readonly AbstractMailWorker _mailWorker;
|
||||
private readonly IClientLogic _clientLogic;
|
||||
public RecipesLogic(ILogger<RecipesLogic> logger, IRecipesStorage recipesStorage, AbstractMailWorker mailWorker, IClientLogic clientLogic)
|
||||
{
|
||||
_logger = logger;
|
||||
_recipesStorage = recipesStorage;
|
||||
_mailWorker = mailWorker;
|
||||
_clientLogic = clientLogic;
|
||||
}
|
||||
|
||||
public bool AddProcedures(RecipesSearchModel model, IProceduresModel procedure)
|
||||
@ -60,11 +65,13 @@ namespace HospitalBusinessLogic.BusinessLogics
|
||||
public bool Create(RecipesBindingModel model)
|
||||
{
|
||||
CheckModel(model);
|
||||
if (_recipesStorage.Insert(model) == null)
|
||||
{
|
||||
var result = _recipesStorage.Insert(model);
|
||||
|
||||
if (result == null) {
|
||||
_logger.LogWarning("Insert operation failed");
|
||||
return false;
|
||||
}
|
||||
SendRecipeMessage(result.ClientId, $"Поликлиника \"Вы больны\", Рецепт №{result.Id}", $"Рецепт №{result.Id} созданный {result.Date} с дозировкой {result.Dose} и способом применения {result.ModeOfApplication} добавлен");
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -145,5 +152,24 @@ namespace HospitalBusinessLogic.BusinessLogics
|
||||
}
|
||||
_logger.LogInformation("Recipes.RecipesId:{Id}.Dose:{ Dose}.ModeOfApplication:{ ModeOfApplication}. MedicineId: { MedicineId}", model.Id, model.Dose, model.ModeOfApplication, model.SymptomsId);
|
||||
}
|
||||
|
||||
private bool SendRecipeMessage(int clientId, string subject, string text)
|
||||
{
|
||||
var client = _clientLogic.ReadElement(new() { Id = clientId });
|
||||
|
||||
if (client == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
_mailWorker.MailSendAsync(new()
|
||||
{
|
||||
MailAddress = client.Email,
|
||||
Subject = subject,
|
||||
Text = text
|
||||
});
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -66,54 +66,27 @@ namespace HospitalBusinessLogic.BusinessLogics
|
||||
return list;
|
||||
}
|
||||
|
||||
//public List<ReportMembersViewModel> GetMembers(ReportBindingModel model)
|
||||
//{
|
||||
// var listAll = new List<ReportMembersViewModel>();
|
||||
|
||||
// var listСonferences = _conferenceStorage.GetFilteredList(new ConferenceSearchModel
|
||||
// {
|
||||
// OrganiserId = model.OrganiserId,
|
||||
// DateFrom = model.DateFrom,
|
||||
// DateTo = model.DateTo
|
||||
// });
|
||||
|
||||
// foreach (var conference in listСonferences)
|
||||
// {
|
||||
// foreach (var m in conference.ConferenceMembers.Values)
|
||||
// {
|
||||
// listAll.Add(new ReportMembersViewModel
|
||||
// {
|
||||
// StartDate = conference.StartDate,
|
||||
// ConferenceName = conference.ConferenceName,
|
||||
// MemberFIO = m.MemberFIO
|
||||
// });
|
||||
// }
|
||||
// }
|
||||
|
||||
// var listMealPlans = _mealPlanStorage.GetFilteredList(new MealPlanSearchModel
|
||||
// {
|
||||
// OrganiserId = model.OrganiserId,
|
||||
// });
|
||||
|
||||
// foreach (var mealPlan in listMealPlans)
|
||||
// {
|
||||
// foreach (var mp in mealPlan.MealPlanMembers.Values)
|
||||
// {
|
||||
// listAll.Add(new ReportMembersViewModel
|
||||
// {
|
||||
// MemberFIO = mp.MemberFIO,
|
||||
// MealPlanName = mealPlan.MealPlanName,
|
||||
// MealPlanPrice = mealPlan.MealPlanPrice
|
||||
// });
|
||||
// }
|
||||
// }
|
||||
|
||||
// return listAll;
|
||||
//}
|
||||
|
||||
public List<ReportMedicinesViewModel> GetRecipeMedicine(ReportBindingModel model)
|
||||
public List<ReportRecipesViewModel> GetRecipes(ReportBindingModel model)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
var listAll = new List<ReportRecipesViewModel>();
|
||||
|
||||
var listRecipes = _recipeStorage.GetFilteredList(new RecipesSearchModel
|
||||
{
|
||||
ClientId = model.ClientId,
|
||||
DateFrom = model.DateFrom,
|
||||
DateTo = model.DateTo
|
||||
});
|
||||
|
||||
foreach (var recipe in listRecipes)
|
||||
{
|
||||
listAll.Add(new ReportRecipesViewModel
|
||||
{
|
||||
Date = recipe.Date,
|
||||
Dose = recipe.Dose,
|
||||
ModeofApplication = recipe.ModeOfApplication
|
||||
});
|
||||
}
|
||||
return listAll;
|
||||
}
|
||||
|
||||
public void SaveMedicinesToExcelFile(ReportBindingModel model)
|
||||
@ -136,30 +109,25 @@ namespace HospitalBusinessLogic.BusinessLogics
|
||||
});
|
||||
}
|
||||
|
||||
//public void SaveMembersToPdfFile(ReportBindingModel model)
|
||||
//{
|
||||
// if (model.DateFrom == null)
|
||||
// {
|
||||
// throw new ArgumentException("Дата начала не задана");
|
||||
// }
|
||||
|
||||
// if (model.DateTo == null)
|
||||
// {
|
||||
// throw new ArgumentException("Дата окончания не задана");
|
||||
// }
|
||||
// _saveToPdf.CreateDoc(new PdfInfoOrganiser
|
||||
// {
|
||||
// FileName = model.FileName,
|
||||
// Title = "Список участников",
|
||||
// DateFrom = model.DateFrom!.Value,
|
||||
// DateTo = model.DateTo!.Value,
|
||||
// Members = GetMembers(model)
|
||||
// });
|
||||
//}
|
||||
|
||||
public void SaveOrdersToPdfFile(ReportBindingModel model)
|
||||
public void SaveRecipesToPdfFile(ReportBindingModel model)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
if (model.DateFrom == null)
|
||||
{
|
||||
throw new ArgumentException("Дата начала не задана");
|
||||
}
|
||||
|
||||
if (model.DateTo == null)
|
||||
{
|
||||
throw new ArgumentException("Дата окончания не задана");
|
||||
}
|
||||
_saveToPdf.CreateDoc(new PdfInfo
|
||||
{
|
||||
FileName = model.FileName,
|
||||
Title = "Список рецептов",
|
||||
DateFrom = model.DateFrom!.Value,
|
||||
DateTo = model.DateTo!.Value,
|
||||
Recipes = GetRecipes(model)
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,64 @@
|
||||
using HospitalContracts.BindingModels;
|
||||
using HospitalContracts.BusinessLogicsContracts;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace HospitalBusinessLogic.MailWorker
|
||||
{
|
||||
public abstract class AbstractMailWorker
|
||||
{
|
||||
protected string _mailLogin = string.Empty;
|
||||
protected string _mailPassword = string.Empty;
|
||||
protected string _smtpClientHost = string.Empty;
|
||||
protected int _smtpClientPort;
|
||||
protected string _popHost = string.Empty;
|
||||
protected int _popPort;
|
||||
private readonly IClientLogic _clientLogic;
|
||||
private readonly ILogger _logger;
|
||||
|
||||
public AbstractMailWorker(ILogger<AbstractMailWorker> logger, IClientLogic clientLogic)
|
||||
{
|
||||
_logger = logger;
|
||||
_clientLogic = clientLogic;
|
||||
}
|
||||
|
||||
public void MailConfig(MailConfigBindingModel config)
|
||||
{
|
||||
_mailLogin = config.MailLogin;
|
||||
_mailPassword = config.MailPassword;
|
||||
_smtpClientHost = config.SmtpClientHost;
|
||||
_smtpClientPort = config.SmtpClientPort;
|
||||
_popHost = config.PopHost;
|
||||
_popPort = config.PopPort;
|
||||
_logger.LogDebug("Config: {login}, {password}, {clientHost}, {clientPOrt}, {popHost}, {popPort}", _mailLogin, _mailPassword, _smtpClientHost, _smtpClientPort, _popHost, _popPort);
|
||||
}
|
||||
|
||||
public async void MailSendAsync(MailSendInfoBindingModel info)
|
||||
{
|
||||
if (string.IsNullOrEmpty(_mailLogin) || string.IsNullOrEmpty(_mailPassword))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (string.IsNullOrEmpty(_smtpClientHost) || _smtpClientPort == 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (string.IsNullOrEmpty(info.MailAddress) || string.IsNullOrEmpty(info.Subject) || string.IsNullOrEmpty(info.Text))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
_logger.LogDebug("Send Mail: {To}, {Subject}", info.MailAddress, info.Subject);
|
||||
|
||||
await SendMailAsync(info);
|
||||
}
|
||||
|
||||
protected abstract Task SendMailAsync(MailSendInfoBindingModel info);
|
||||
}
|
||||
}
|
50
Hospital/HospitalBusinessLogic/MailWorker/MailKitWorker.cs
Normal file
50
Hospital/HospitalBusinessLogic/MailWorker/MailKitWorker.cs
Normal file
@ -0,0 +1,50 @@
|
||||
using Microsoft.Extensions.Logging;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Net.Mail;
|
||||
using System.Net.Mime;
|
||||
using System.Net;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using HospitalContracts.BusinessLogicsContracts;
|
||||
using HospitalContracts.BindingModels;
|
||||
|
||||
namespace HospitalBusinessLogic.MailWorker
|
||||
{
|
||||
public class MailKitWorker : AbstractMailWorker
|
||||
{
|
||||
public MailKitWorker(ILogger<MailKitWorker> logger, IClientLogic clientLogic) : base(logger, clientLogic) { }
|
||||
|
||||
protected override async Task SendMailAsync(MailSendInfoBindingModel info)
|
||||
{
|
||||
using var objMailMessage = new MailMessage();
|
||||
using var objSmtpClient = new SmtpClient(_smtpClientHost, _smtpClientPort);
|
||||
|
||||
try
|
||||
{
|
||||
objMailMessage.From = new MailAddress(_mailLogin);
|
||||
objMailMessage.To.Add(new MailAddress(info.MailAddress));
|
||||
objMailMessage.Subject = info.Subject;
|
||||
objMailMessage.Body = info.Text;
|
||||
objMailMessage.SubjectEncoding = Encoding.UTF8;
|
||||
objMailMessage.BodyEncoding = Encoding.UTF8;
|
||||
Attachment attachment = new Attachment("E:\\ReportsCourseWork\\pdffile.pdf", new ContentType(MediaTypeNames.Application.Pdf));
|
||||
objMailMessage.Attachments.Add(attachment);
|
||||
|
||||
objSmtpClient.UseDefaultCredentials = false;
|
||||
objSmtpClient.EnableSsl = true;
|
||||
objSmtpClient.DeliveryMethod = SmtpDeliveryMethod.Network;
|
||||
objSmtpClient.Credentials = new NetworkCredential(_mailLogin, _mailPassword);
|
||||
|
||||
await Task.Run(() => objSmtpClient.Send(objMailMessage));
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
@ -25,19 +25,19 @@ namespace HospitalBusinessLogic.OfficePackage
|
||||
Style = "Normal",
|
||||
ParagraphAlignment = PdfParagraphAlignmentType.Center
|
||||
});
|
||||
CreateTable(new List<string> { "2cm", "6cm"});
|
||||
CreateTable(new List<string> { "6cm", "3cm", "6cm"});
|
||||
CreateRow(new PdfRowParameters
|
||||
{
|
||||
Texts = new List<string> { "Номер", "Дата создания рецепта" },
|
||||
Texts = new List<string> { "Дата создания рецепта", "Доза", "Способ применения"},
|
||||
Style = "NormalTitle",
|
||||
ParagraphAlignment = PdfParagraphAlignmentType.Center
|
||||
});
|
||||
foreach (var recipe in info.RecipeMedicine)
|
||||
foreach (var recipe in info.Recipes)
|
||||
{
|
||||
CreateRow(new PdfRowParameters
|
||||
{
|
||||
Texts = new List<string> { recipe.Id.ToString(),
|
||||
recipe.DateCreate.ToShortDateString() },
|
||||
Texts = new List<string> {
|
||||
recipe.Date.ToShortDateString(), recipe.Dose, recipe.ModeofApplication },
|
||||
Style = "Normal",
|
||||
ParagraphAlignment = PdfParagraphAlignmentType.Left
|
||||
});
|
||||
|
@ -13,6 +13,6 @@ namespace HospitalBusinessLogic.OfficePackage.HelperModels
|
||||
public string Title { get; set; } = string.Empty;
|
||||
public DateTime DateFrom { get; set; }
|
||||
public DateTime DateTo { get; set; }
|
||||
public List<ReportMedicinesViewModel> RecipeMedicine { get; set; } = new();
|
||||
public List<ReportRecipesViewModel> Recipes { get; set; } = new();
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,6 @@
|
||||
using HospitalClientApp.Models;
|
||||
using HospitalContracts.BindingModels;
|
||||
using HospitalContracts.BusinessLogicsContracts;
|
||||
using HospitalContracts.SearchModels;
|
||||
using HospitalContracts.ViewModels;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
@ -14,10 +15,13 @@ namespace HospitalClientApp.Controllers
|
||||
public class HomeController : Controller
|
||||
{
|
||||
private readonly ILogger<HomeController> _logger;
|
||||
private readonly IReportLogic _report;
|
||||
|
||||
public HomeController(ILogger<HomeController> logger)
|
||||
|
||||
public HomeController(ILogger<HomeController> logger, IReportLogic report) //IReportLogic report
|
||||
{
|
||||
_logger = logger;
|
||||
_report = report;
|
||||
}
|
||||
|
||||
public IActionResult Index()
|
||||
@ -173,6 +177,94 @@ namespace HospitalClientApp.Controllers
|
||||
{
|
||||
return new PhysicalFileResult("E:\\ReportsCourseWork\\excelfile.xlsx", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public IActionResult ReportPdf()
|
||||
{
|
||||
if (APIClient.Client == null)
|
||||
{
|
||||
return Redirect("~/Home/Enter");
|
||||
}
|
||||
return View("ReportPdf");
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public void ReportPdf(DateTime dateFrom, DateTime dateTo, string clientEmail)
|
||||
{
|
||||
if (APIClient.Client == null)
|
||||
{
|
||||
throw new Exception("Вы как суда попали? Суда вход только авторизованным");
|
||||
}
|
||||
if (string.IsNullOrEmpty(clientEmail))
|
||||
{
|
||||
throw new Exception("Email пуст");
|
||||
}
|
||||
APIClient.PostRequest("api/report/CreateReportToPdfFile", new ReportBindingModel
|
||||
{
|
||||
DateFrom = dateFrom,
|
||||
DateTo = dateTo,
|
||||
ClientId = APIClient.Client.Id
|
||||
});
|
||||
APIClient.PostRequest("api/report/SendPdfToMail", new MailSendInfoBindingModel
|
||||
{
|
||||
MailAddress = clientEmail,
|
||||
Subject = "Отчет по рецептам (pdf)",
|
||||
Text = "Отчет по рецептам с " + dateFrom.ToShortDateString() + " до " + dateTo.ToShortDateString()
|
||||
});
|
||||
Response.Redirect("ReportPdf");
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public string GetRecipesReport(DateTime dateFrom, DateTime dateTo)
|
||||
{
|
||||
if (APIClient.Client == null)
|
||||
{
|
||||
throw new Exception("Вы как суда попали? Суда вход только авторизованным");
|
||||
}
|
||||
List<ReportRecipesViewModel> result;
|
||||
try
|
||||
{
|
||||
result = _report.GetRecipes(new ReportBindingModel
|
||||
{
|
||||
ClientId = APIClient.Client.Id,
|
||||
DateFrom = dateFrom,
|
||||
DateTo = dateTo
|
||||
});
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка создания отчета");
|
||||
throw;
|
||||
}
|
||||
|
||||
string table = "";
|
||||
table += $"<h2>Предварительный отчет</h2>";
|
||||
table += $"<table class=\"table table-bordered table-striped\"/>";
|
||||
table += "<thead class=\"u-custom-color-1 u-table-header u-table-header-1\">";
|
||||
table += "<tr style=\"height: 31px\">";
|
||||
table += $"<th class=\"u-border-1 u-border-grey-50 u-table-cell\">Дата создания</th>";
|
||||
table += $"<th class=\"u-border-1 u-border-grey-50 u-table-cell\">Дозировка</th>";
|
||||
table += $"<th class=\"u-border-1 u-border-grey-50 u-table-cell\">Способ применения</th>";
|
||||
table += "</tr>";
|
||||
table += "</thead>";
|
||||
foreach (var report in result)
|
||||
{
|
||||
bool IsDate = true;
|
||||
if (report.Date.ToShortDateString() == "01.01.0001")
|
||||
{
|
||||
IsDate = false;
|
||||
}
|
||||
table += "<tbody class=\"u-table-body\">";
|
||||
table += "<tr style=\"height: 75px\">";
|
||||
table += $"<td class=\"u-border-1 u-border-grey-40 u-border-no-left u-border-no-right u-table-cell\">{(IsDate is true ? report.Date.ToShortDateString() : string.Empty)}</td>";
|
||||
table += $"<td class=\"u-border-1 u-border-grey-40 u-border-no-left u-border-no-right u-table-cell\">{report.Dose}</td>";
|
||||
table += $"<td class=\"u-border-1 u-border-grey-40 u-border-no-left u-border-no-right u-table-cell\">{report.ModeofApplication}</td>";
|
||||
table += "</tr>";
|
||||
table += "</tbody>";
|
||||
}
|
||||
table += "</table>";
|
||||
return table;
|
||||
}
|
||||
/// <summary>
|
||||
/// ПРОЦЕДУРЫ
|
||||
/// </summary>
|
||||
|
@ -12,6 +12,8 @@
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\HospitalContracts\HospitalContracts.csproj" />
|
||||
<ProjectReference Include="..\..\HospitalDataBaseImplements\HospitalDataBaseImplements.csproj" />
|
||||
<ProjectReference Include="..\HospitalBusinessLogic\HospitalBusinessLogic.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
@ -1,6 +1,19 @@
|
||||
using HospitalBusinessLogic.BusinessLogics;
|
||||
using HospitalBusinessLogic.OfficePackage;
|
||||
using HospitalBusinessLogic.OfficePackage.Implements;
|
||||
using HospitalClientApp;
|
||||
using HospitalContracts.BusinessLogicsContracts;
|
||||
using HospitalContracts.StoragesContracts;
|
||||
using HospitalDataBaseImplements.Implements;
|
||||
|
||||
var builder = WebApplication.CreateBuilder(args);
|
||||
builder.Services.AddTransient<IReportLogic, ReportLogic>();
|
||||
builder.Services.AddTransient<IKurseStorage, KurseStorage>();
|
||||
builder.Services.AddTransient<IMedicinesStorage, MedicinesStorage>();
|
||||
builder.Services.AddTransient<IRecipesStorage, RecipesStorage>();
|
||||
builder.Services.AddTransient<AbstractSaveToExcel, SaveToExcel>();
|
||||
builder.Services.AddTransient<AbstractSaveToPdf, SaveToPdf>();
|
||||
builder.Services.AddTransient<AbstractSaveToWord, SaveToWord>();
|
||||
// Add services to the container.
|
||||
builder.Services.AddControllersWithViews();
|
||||
var app = builder.Build();
|
||||
|
78
Hospital/HospitalClientApp/Views/Home/ReportPdf.cshtml
Normal file
78
Hospital/HospitalClientApp/Views/Home/ReportPdf.cshtml
Normal file
@ -0,0 +1,78 @@
|
||||
@using HospitalContracts.ViewModels
|
||||
|
||||
@{
|
||||
ViewData["Title"] = "ReportPdf";
|
||||
}
|
||||
|
||||
<div class="text-center">
|
||||
<h2> Отчет по рецептам за период </h2>
|
||||
</div>
|
||||
|
||||
<div class="text-center">
|
||||
@{
|
||||
<form method="post">
|
||||
<div class="row">
|
||||
<div class="col-4">Начало периода:</div>
|
||||
<div class="col-8">
|
||||
<input type="datetime-local"
|
||||
placeholder="Выберите дату начала периода"
|
||||
id="dateFrom" name="dateFrom" />
|
||||
</div>
|
||||
</div>
|
||||
<br/>
|
||||
<div class="row">
|
||||
<div class="col-4">Окончание:</div>
|
||||
<div class="col-8">
|
||||
<input type="datetime-local"
|
||||
placeholder="Выберите дату окончания периода"
|
||||
id="dateTo" name="dateTo" />
|
||||
</div>
|
||||
</div>
|
||||
<br/>
|
||||
<div class="row">
|
||||
<div class="col-4">Введите почту:</div>
|
||||
<div class="col-8">
|
||||
<input type="email"
|
||||
placeholder="Введите вашу почту"
|
||||
name="clientEmail" />
|
||||
</div>
|
||||
</div>
|
||||
<br/>
|
||||
<div>
|
||||
<div class="col-8"></div>
|
||||
<div class="col-2"><input type="submit" style="width: 100%" class="btn btn-success" value="Отправить на почту" /></div>
|
||||
</div>
|
||||
<br/>
|
||||
<div class="mt-3" id="report">
|
||||
</div>
|
||||
</form>
|
||||
<br></br>
|
||||
<div>
|
||||
<div class="col-8"></div>
|
||||
<div class="col-2"><button type="button" class="btn btn-success" style="width: 100%" id="demonstrate">Продемонстрировать</button></div>
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
|
||||
@section Scripts {
|
||||
<script>
|
||||
function check() {
|
||||
var dateFrom = $('#dateFrom').val();
|
||||
var dateTo = $('#dateTo').val();
|
||||
if (dateFrom && dateTo) {
|
||||
$.ajax({
|
||||
method: "GET",
|
||||
url: "/Home/GetRecipesReport",
|
||||
data: { dateFrom: dateFrom, dateTo: dateTo },
|
||||
success: function (result) {
|
||||
if (result != null) {
|
||||
$('#report').html(result);
|
||||
}
|
||||
}
|
||||
});
|
||||
};
|
||||
}
|
||||
check();
|
||||
$('#demonstrate').on('click', (e) => check());
|
||||
</script>
|
||||
}
|
@ -71,7 +71,7 @@
|
||||
</div>
|
||||
<div class="u-align-center u-form-group u-form-submit u-label-top" style="padding-bottom: 120px">
|
||||
<div class="col-8"></div>
|
||||
<div class="col-4"><input type="submit" value="Создать файл" ></div>
|
||||
<div class="col-4"><input type="submit" class="btn btn-success" value="Создать файл"></div>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
|
@ -28,16 +28,7 @@
|
||||
placeholder="Тип процедуры"
|
||||
name="type" />
|
||||
</div>
|
||||
<div class="row">
|
||||
<p class="text-center"><strong>Лекарства</strong></p>
|
||||
<table id="medicinesTable" class="table table-bordered table-striped">
|
||||
<tr>
|
||||
<th>Название</th>
|
||||
</tr>
|
||||
<tbody class="u-table-body" id="table-elements">
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
|
||||
<div class="row">
|
||||
<div class="col-8"></div>
|
||||
<div class="col-4"><input type="submit" class="btn btn-success" value="Сохранить" /></div>
|
||||
|
@ -33,17 +33,7 @@
|
||||
<label class="lable">Симптомы</label>
|
||||
<select id="symptoms" name="symptoms" class="form-control" asp-items="@(new SelectList(@ViewBag.Symptomses,"Id", "SymptomName"))"></select>
|
||||
</div>
|
||||
<div class="row">
|
||||
<p class="text-center"><strong>Процедуры</strong></p>
|
||||
<table id="proceduresTable" class="table table-bordered table-striped">
|
||||
<tr>
|
||||
<th>Название</th>
|
||||
<th>Тип</th>
|
||||
</tr>
|
||||
<tbody class="u-table-body" id="table-elements">
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
|
||||
<div class="row">
|
||||
<div class="col-8"></div>
|
||||
<div class="col-4"><input type="submit" value="Сохранить" class="btn btn-success" /></div>
|
||||
|
@ -61,7 +61,7 @@
|
||||
</li>
|
||||
<li>
|
||||
<a class="dropdown-item"
|
||||
asp-area="dropdown-item" asp-controller="Home" asp-action="ListMemberConferenceToFile">Список лекарств (pdf)</a>
|
||||
asp-area="dropdown-item" asp-controller="Home" asp-action="ReportPdf">Список рецептов (pdf)</a>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
|
@ -1,4 +1,5 @@
|
||||
using HospitalContracts.BindingModels;
|
||||
using HospitalBusinessLogic.MailWorker;
|
||||
using HospitalContracts.BindingModels;
|
||||
using HospitalContracts.BusinessLogicsContracts;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
@ -10,47 +11,47 @@ namespace HospitalRestApi.Controllers
|
||||
{
|
||||
private readonly ILogger _logger;
|
||||
private readonly IReportLogic _reportLogic;
|
||||
//private readonly AbstractMailWorker _mailWorker;
|
||||
public ReportController(ILogger<ReportController> logger, IReportLogic reportLogic)
|
||||
private readonly AbstractMailWorker _mailWorker;
|
||||
public ReportController(ILogger<ReportController> logger, IReportLogic reportLogic, AbstractMailWorker mailWorker)
|
||||
{
|
||||
_logger = logger;
|
||||
_reportLogic = reportLogic;
|
||||
//_mailWorker = mailWorker;
|
||||
_mailWorker = mailWorker;
|
||||
}
|
||||
|
||||
//[HttpPost]
|
||||
//public void CreateReportToPdfFile(ReportBindingModel model)
|
||||
//{
|
||||
// try
|
||||
// {
|
||||
// _reportLogic.SaveMedicinesToPdfFile(new ReportBindingModel
|
||||
// {
|
||||
// DateFrom = model.DateFrom,
|
||||
// DateTo = model.DateTo,
|
||||
// OrganiserId = model.OrganiserId,
|
||||
// FileName = "C:\\ReportsCourseWork\\pdffile.pdf",
|
||||
// });
|
||||
// }
|
||||
// catch (Exception ex)
|
||||
// {
|
||||
// _logger.LogError(ex, "Ошибка создания отчета");
|
||||
// throw;
|
||||
// }
|
||||
//}
|
||||
[HttpPost]
|
||||
public void CreateReportToPdfFile(ReportBindingModel model)
|
||||
{
|
||||
try
|
||||
{
|
||||
_reportLogic.SaveRecipesToPdfFile(new ReportBindingModel
|
||||
{
|
||||
DateFrom = model.DateFrom,
|
||||
DateTo = model.DateTo,
|
||||
ClientId = model.ClientId,
|
||||
FileName = "E:\\ReportsCourseWork\\pdffile.pdf",
|
||||
});
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка создания отчета");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
//[HttpPost]
|
||||
//public void SendPdfToMail(MailSendInfoBindingModel model)
|
||||
//{
|
||||
// try
|
||||
// {
|
||||
// _mailWorker.MailSendAsync(model);
|
||||
// }
|
||||
// catch (Exception ex)
|
||||
// {
|
||||
// _logger.LogError(ex, "Ошибка отправки письма");
|
||||
// throw;
|
||||
// }
|
||||
//}
|
||||
[HttpPost]
|
||||
public void SendPdfToMail(MailSendInfoBindingModel model)
|
||||
{
|
||||
try
|
||||
{
|
||||
_mailWorker.MailSendAsync(model);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка отправки письма");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public void CreateReportToWordFile(ReportBindingModel model)
|
||||
|
@ -1,6 +1,8 @@
|
||||
using HospitalBusinessLogic.BusinessLogics;
|
||||
using HospitalBusinessLogic.MailWorker;
|
||||
using HospitalBusinessLogic.OfficePackage;
|
||||
using HospitalBusinessLogic.OfficePackage.Implements;
|
||||
using HospitalContracts.BindingModels;
|
||||
using HospitalContracts.BusinessLogicsContracts;
|
||||
using HospitalContracts.StoragesContracts;
|
||||
using HospitalDataBaseImplements;
|
||||
@ -35,6 +37,8 @@ builder.Services.AddTransient<AbstractSaveToExcel, SaveToExcel>();
|
||||
builder.Services.AddTransient<AbstractSaveToWord, SaveToWord>();
|
||||
builder.Services.AddTransient<AbstractSaveToPdf, SaveToPdf>();
|
||||
|
||||
builder.Services.AddSingleton<AbstractMailWorker, MailKitWorker>();
|
||||
|
||||
builder.Services.AddControllers();
|
||||
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
|
||||
builder.Services.AddEndpointsApiExplorer();
|
||||
@ -53,6 +57,18 @@ var app = builder.Build();
|
||||
LoaderFromXML.LoadSymptoms();
|
||||
LoaderFromXML.LoadKurses();
|
||||
|
||||
var mailSender = app.Services.GetService<AbstractMailWorker>();
|
||||
|
||||
mailSender?.MailConfig(new MailConfigBindingModel
|
||||
{
|
||||
MailLogin = builder.Configuration?.GetSection("MailLogin")?.Value?.ToString() ?? string.Empty,
|
||||
MailPassword = builder.Configuration?.GetSection("MailPassword")?.Value?.ToString() ?? string.Empty,
|
||||
SmtpClientHost = builder.Configuration?.GetSection("SmtpClientHost")?.Value?.ToString() ?? string.Empty,
|
||||
SmtpClientPort = Convert.ToInt32(builder.Configuration?.GetSection("SmtpClientPort")?.Value?.ToString()),
|
||||
PopHost = builder.Configuration?.GetSection("PopHost")?.Value?.ToString() ?? string.Empty,
|
||||
PopPort = Convert.ToInt32(builder.Configuration?.GetSection("PopPort")?.Value?.ToString())
|
||||
});
|
||||
|
||||
// Configure the HTTP request pipeline.
|
||||
if (app.Environment.IsDevelopment())
|
||||
{
|
||||
|
@ -5,5 +5,12 @@
|
||||
"Microsoft.AspNetCore": "Warning"
|
||||
}
|
||||
},
|
||||
"AllowedHosts": "*"
|
||||
"AllowedHosts": "*",
|
||||
|
||||
"SmtpClientHost": "smtp.gmail.com",
|
||||
"SmtpClientPort": "587",
|
||||
"PopHost": "pop.gmail.com",
|
||||
"PopPort": "995",
|
||||
"MailLogin": "rea22works@gmail.com",
|
||||
"MailPassword": "paww pnyu fpho bgts"
|
||||
}
|
||||
|
18
HospitalContracts/BindingModels/MailConfigBindingModel.cs
Normal file
18
HospitalContracts/BindingModels/MailConfigBindingModel.cs
Normal file
@ -0,0 +1,18 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace HospitalContracts.BindingModels
|
||||
{
|
||||
public class MailConfigBindingModel
|
||||
{
|
||||
public string MailLogin { get; set; } = string.Empty;
|
||||
public string MailPassword { get; set; } = string.Empty;
|
||||
public string SmtpClientHost { get; set; } = string.Empty;
|
||||
public int SmtpClientPort { get; set; }
|
||||
public string PopHost { get; set; } = string.Empty;
|
||||
public int PopPort { get; set; }
|
||||
}
|
||||
}
|
15
HospitalContracts/BindingModels/MailSendInfoBindingModel.cs
Normal file
15
HospitalContracts/BindingModels/MailSendInfoBindingModel.cs
Normal file
@ -0,0 +1,15 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace HospitalContracts.BindingModels
|
||||
{
|
||||
public class MailSendInfoBindingModel
|
||||
{
|
||||
public string MailAddress { get; set; } = string.Empty;
|
||||
public string Subject { get; set; } = string.Empty;
|
||||
public string Text { get; set; } = string.Empty;
|
||||
}
|
||||
}
|
@ -20,7 +20,7 @@ namespace HospitalContracts.BusinessLogicsContracts
|
||||
/// </summary>
|
||||
/// <param name="model"></param>
|
||||
/// <returns></returns>
|
||||
List<ReportMedicinesViewModel> GetRecipeMedicine(ReportBindingModel model);
|
||||
List<ReportRecipesViewModel> GetRecipes(ReportBindingModel model);
|
||||
/// <summary>
|
||||
/// Сохранение компонент в файл-Word
|
||||
/// </summary>
|
||||
@ -35,6 +35,6 @@ namespace HospitalContracts.BusinessLogicsContracts
|
||||
/// Сохранение заказов в файл-Pdf
|
||||
/// </summary>
|
||||
/// <param name="model"></param>
|
||||
void SaveOrdersToPdfFile(ReportBindingModel model);
|
||||
void SaveRecipesToPdfFile(ReportBindingModel model);
|
||||
}
|
||||
}
|
||||
|
@ -6,10 +6,11 @@ using System.Threading.Tasks;
|
||||
|
||||
namespace HospitalContracts.ViewModels
|
||||
{
|
||||
public class ReportMedicinesViewModel
|
||||
public class ReportRecipesViewModel
|
||||
{
|
||||
public int Id { get; set; }
|
||||
public DateTime DateCreate { get; set; }
|
||||
public string MedicinesName { get; set; } = string.Empty;
|
||||
public DateTime Date { get; set; }
|
||||
public string Dose { get; set; } = string.Empty;
|
||||
public string ModeofApplication { get; set; } = string.Empty;
|
||||
}
|
||||
}
|
@ -47,12 +47,28 @@ namespace HospitalDataBaseImplements.Implements
|
||||
//НУЖЕН ТУТ ЕЩЕ ОДИН ТУ ЛИСТ???
|
||||
public List<RecipesViewModel> GetFilteredList(RecipesSearchModel model)
|
||||
{
|
||||
if (!model.DateFrom.HasValue && !model.DateTo.HasValue && !model.ClientId.HasValue)
|
||||
{
|
||||
return new();
|
||||
}
|
||||
if (model is null)
|
||||
{
|
||||
return new();
|
||||
}
|
||||
using var context = new HospitalDatabase();
|
||||
|
||||
if (model.DateFrom.HasValue)
|
||||
{
|
||||
return context.Recipes.
|
||||
Include(x => x.Procedures).
|
||||
ThenInclude(x => x.Procedure)
|
||||
.Include(x => x.Symptoms)
|
||||
.Include(x => x.Client)
|
||||
.Where(x => x.Date >= model.DateFrom && x.Date <= model.DateTo && x.ClientId == model.ClientId)
|
||||
.Where(x => x.ClientId == model.ClientId).ToList()
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
else{
|
||||
return context.Recipes.
|
||||
Include(x => x.Procedures).
|
||||
ThenInclude(x => x.Procedure)
|
||||
@ -61,6 +77,7 @@ namespace HospitalDataBaseImplements.Implements
|
||||
.Where(x => x.ClientId == model.ClientId).ToList()
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
}
|
||||
|
||||
public List<RecipesViewModel> GetFullList()
|
||||
|
Loading…
Reference in New Issue
Block a user