Оно работает........Сейчас я буду отправлять всеееееем письма.....(Реализована отправка отчета на почту, остался дизайн страницы)
This commit is contained in:
parent
105f89548f
commit
e58d4a1298
@ -92,6 +92,8 @@ namespace HotelBusinessLogic.BusinessLogics
|
||||
OrganiserId = model.OrganiserId,
|
||||
});
|
||||
|
||||
double sum = 0;
|
||||
|
||||
foreach (var mealPlan in listMealPlans)
|
||||
{
|
||||
foreach (var mp in mealPlan.MealPlanMembers.Values)
|
||||
@ -130,6 +132,15 @@ namespace HotelBusinessLogic.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,
|
||||
|
@ -9,6 +9,7 @@ using System.Security.Authentication;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using HotelContracts.BusinessLogicsContracts;
|
||||
using System.Net.Mime;
|
||||
|
||||
namespace HotelBusinessLogic.MailWorker
|
||||
{
|
||||
@ -29,6 +30,9 @@ namespace HotelBusinessLogic.MailWorker
|
||||
objMailMessage.Body = info.Text;
|
||||
objMailMessage.SubjectEncoding = Encoding.UTF8;
|
||||
objMailMessage.BodyEncoding = Encoding.UTF8;
|
||||
Attachment attachment = new Attachment("F:\\ReportsCourseWork\\pdffile.pdf", new ContentType(MediaTypeNames.Application.Pdf));
|
||||
objMailMessage.Attachments.Add(attachment);
|
||||
|
||||
objSmtpClient.UseDefaultCredentials = false;
|
||||
objSmtpClient.EnableSsl = true;
|
||||
objSmtpClient.DeliveryMethod = SmtpDeliveryMethod.Network;
|
||||
|
@ -4,7 +4,7 @@ namespace HotelBusinessLogic.OfficePackage.HelperModels
|
||||
{
|
||||
public class PdfInfoOrganiser
|
||||
{
|
||||
public string FileName { get; set; } = string.Empty;
|
||||
public string FileName { get; set; } = "F:\\ReportsCourseWork\\pdffile.pdf";
|
||||
public string Title { get; set; } = string.Empty;
|
||||
public DateTime DateFrom { get; set; }
|
||||
public DateTime DateTo { get; set; }
|
||||
|
@ -91,6 +91,7 @@ namespace HotelBusinessLogic.OfficePackage.Implements
|
||||
{
|
||||
Document = _document
|
||||
};
|
||||
System.Text.Encoding.RegisterProvider(System.Text.CodePagesEncodingProvider.Instance);
|
||||
renderer.RenderDocument();
|
||||
renderer.PdfDocument.Save(info.FileName);
|
||||
}
|
||||
|
@ -5,50 +5,26 @@ using HotelOrganiserApp.Models;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using System.Diagnostics;
|
||||
using System.Text;
|
||||
using System.Web.Helpers;
|
||||
using System.Reflection;
|
||||
using HotelBusinessLogic.BusinessLogics;
|
||||
using HotelContracts.BusinessLogicsContracts;
|
||||
|
||||
namespace HotelOrganiserApp.Controllers
|
||||
{
|
||||
public class HomeController : Controller
|
||||
{
|
||||
private readonly ILogger<HomeController> _logger;
|
||||
private readonly IReportOrganiserLogic _report;
|
||||
|
||||
public HomeController(ILogger<HomeController> logger)
|
||||
public HomeController(ILogger<HomeController> logger, IReportOrganiserLogic report)
|
||||
{
|
||||
_logger = logger;
|
||||
_report = report;
|
||||
}
|
||||
|
||||
/*--------------------Reports------------------------*/
|
||||
|
||||
[HttpGet]
|
||||
public IActionResult ListMembersToPdfFile()
|
||||
{
|
||||
if (APIClient.Organiser == null)
|
||||
{
|
||||
return Redirect("~/Home/Enter");
|
||||
}
|
||||
|
||||
return View();
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public void ListMembersToPdfFile(DateTime dateFrom, DateTime dateTo)
|
||||
{
|
||||
if (APIClient.Organiser == null)
|
||||
{
|
||||
throw new Exception("Не авторизованы");
|
||||
}
|
||||
|
||||
APIClient.PostRequest("api/Report/CreateReportToPdfFile", new ReportBindingModel()
|
||||
{
|
||||
DateFrom = dateFrom,
|
||||
DateTo = dateTo,
|
||||
OrganiserId=APIClient.Organiser.Id
|
||||
});
|
||||
|
||||
Response.Redirect("ListMembersToPdfFile");
|
||||
}
|
||||
|
||||
|
||||
[HttpGet]
|
||||
public IActionResult ListMemberConferenceToFile()
|
||||
{
|
||||
@ -109,12 +85,100 @@ namespace HotelOrganiserApp.Controllers
|
||||
{
|
||||
return new PhysicalFileResult("F:\\ReportsCourseWork\\wordfile.docx", "application/vnd.openxmlformats-officedocument.wordprocessingml.document");
|
||||
}
|
||||
|
||||
public IActionResult GetPdfFile()
|
||||
{
|
||||
return new PhysicalFileResult("F:\\ReportsCourseWork\\pdffile.pdf", "application/pdf");
|
||||
}
|
||||
public IActionResult GetExcelFile()
|
||||
{
|
||||
return new PhysicalFileResult("F:\\ReportsCourseWork\\excelfile.xlsx", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public IActionResult ListMembersToPdfFile()
|
||||
{
|
||||
if (APIClient.Organiser == null)
|
||||
{
|
||||
return Redirect("~/Home/Enter");
|
||||
}
|
||||
return View("ListMembersToPdfFile");
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public void ListMembersToPdfFile(DateTime dateFrom, DateTime dateTo, string organiserEmail)
|
||||
{
|
||||
if (APIClient.Organiser == null)
|
||||
{
|
||||
throw new Exception("Вы как суда попали? Суда вход только авторизованным");
|
||||
}
|
||||
if (string.IsNullOrEmpty(organiserEmail))
|
||||
{
|
||||
throw new Exception("Email пуст");
|
||||
}
|
||||
APIClient.PostRequest("api/report/CreateReportToPdfFile", new ReportBindingModel
|
||||
{
|
||||
DateFrom = dateFrom,
|
||||
DateTo = dateTo,
|
||||
OrganiserId = APIClient.Organiser.Id
|
||||
});
|
||||
APIClient.PostRequest("api/report/SendPdfToMail", new MailSendInfoBindingModel
|
||||
{
|
||||
MailAddress = organiserEmail,
|
||||
Subject = "Отчет по участникам (pdf)",
|
||||
Text = "Отчет по участникам с " + dateFrom.ToShortDateString() + " до " + dateTo.ToShortDateString()
|
||||
});
|
||||
Response.Redirect("ListMembersToPdfFile");
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public string GetMembersReport(DateTime dateFrom, DateTime dateTo)
|
||||
{
|
||||
if (APIClient.Organiser == null)
|
||||
{
|
||||
throw new Exception("Вы как суда попали? Суда вход только авторизованным");
|
||||
}
|
||||
List<ReportMembersViewModel> result;
|
||||
try
|
||||
{
|
||||
result = _report.GetMembers(new ReportBindingModel
|
||||
{
|
||||
OrganiserId = APIClient.Organiser.Id,
|
||||
DateFrom = dateFrom,
|
||||
DateTo = dateTo
|
||||
});
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка создания отчета");
|
||||
throw;
|
||||
}
|
||||
string table = "";
|
||||
foreach (var report in result)
|
||||
{
|
||||
table += $"<h2>{report.MemberFIO}</h2>";
|
||||
table += $"<table>";
|
||||
table += "<thead>";
|
||||
table += "<tr>";
|
||||
table += $"<th>Конференция</th>";
|
||||
table += $"<th>Дата начала конференции</th>";
|
||||
table += $"<th>План питания</th>";
|
||||
table += $"<th>Стоимость плана питания</th>";
|
||||
table += "</tr>";
|
||||
table += "</thead>";
|
||||
table += "<tbody>";
|
||||
table += "<tr>";
|
||||
table += $"<td>{report.ConferenceName}</td>";
|
||||
table += $"<td>{report.StartDate}</td>";
|
||||
table += $"<td>{report.MealPlanName}</td>";
|
||||
table += $"<td>{report.MealPlanPrice}</td>";
|
||||
table += "</tr>";
|
||||
table += "</tbody>";
|
||||
table += "</table>";
|
||||
}
|
||||
//table += $"<h3 style=\"align-self: self-start;\">Итого: {result.Item2}</h3>";
|
||||
return table;
|
||||
}
|
||||
|
||||
/*--------------------MealPlans------------------------*/
|
||||
|
||||
[HttpGet]
|
||||
|
@ -1,4 +1,4 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk.Web">
|
||||
<Project Sdk="Microsoft.NET.Sdk.Web">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net6.0</TargetFramework>
|
||||
@ -19,12 +19,15 @@
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.AspNet.WebPages" Version="3.2.9" />
|
||||
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
|
||||
<PackageReference Include="PdfSharp.MigraDoc.Standard" Version="1.51.15" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\HotelBusinessLogic\HotelBusinessLogic.csproj" />
|
||||
<ProjectReference Include="..\HotelContracts\HotelContracts.csproj" />
|
||||
<ProjectReference Include="..\HotelDataBaseImplement\HotelDataBaseImplement.csproj" />
|
||||
<ProjectReference Include="..\HotelDataModels\HotelDataModels.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
|
@ -3,7 +3,6 @@ namespace HotelOrganiserApp.Models
|
||||
public class ErrorViewModel
|
||||
{
|
||||
public string? RequestId { get; set; }
|
||||
|
||||
public bool ShowRequestId => !string.IsNullOrEmpty(RequestId);
|
||||
}
|
||||
}
|
@ -1,6 +1,20 @@
|
||||
using DocumentFormat.OpenXml.VariantTypes;
|
||||
using HotelBusinessLogic.BusinessLogics;
|
||||
using HotelBusinessLogic.OfficePackage;
|
||||
using HotelBusinessLogic.OfficePackage.Implements;
|
||||
using HotelContracts.BusinessLogicsContracts;
|
||||
using HotelContracts.StoragesContracts;
|
||||
using HotelDataBaseImplement.Implemets;
|
||||
using HotelOrganiserApp;
|
||||
|
||||
var builder = WebApplication.CreateBuilder(args);
|
||||
builder.Services.AddTransient<IReportOrganiserLogic, ReportLogicOrganiser>();
|
||||
builder.Services.AddTransient<IMemberStorage, MemberStorage>();
|
||||
builder.Services.AddTransient<IMealPlanStorage, MealPlanStorage>();
|
||||
builder.Services.AddTransient<IConferenceStorage, ConferenceStorage>();
|
||||
builder.Services.AddTransient<AbstractSaveToExcelOrganiser, SaveToExcelOrganiser>();
|
||||
builder.Services.AddTransient<AbstractSaveToPdfOrganiser, SaveToPdfOrganiser>();
|
||||
builder.Services.AddTransient<AbstractSaveToWordOrganiser, SaveToWordOrganiser>();
|
||||
|
||||
// Add services to the container.
|
||||
builder.Services.AddControllersWithViews();
|
||||
@ -9,12 +23,12 @@ var app = builder.Build();
|
||||
APIClient.Connect(builder.Configuration);
|
||||
|
||||
// Configure the HTTP request pipeline.
|
||||
if (!app.Environment.IsDevelopment())
|
||||
{
|
||||
//if (!app.Environment.IsDevelopment())
|
||||
//{
|
||||
app.UseExceptionHandler("/Home/Error");
|
||||
// The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
|
||||
app.UseHsts();
|
||||
}
|
||||
//}
|
||||
|
||||
app.UseHttpsRedirection();
|
||||
app.UseStaticFiles();
|
||||
|
@ -1,38 +1,60 @@
|
||||
@{
|
||||
ViewData["Title"] = "ListMembersToPdf";
|
||||
@using HotelContracts.ViewModels
|
||||
|
||||
@{
|
||||
ViewData["Title"] = "ListMembersToPdfFile";
|
||||
}
|
||||
|
||||
<head>
|
||||
<link rel="stylesheet" href="~/css/listmembers.css" asp-append-version="true" />
|
||||
</head>
|
||||
|
||||
<div class="text-center">
|
||||
<h2
|
||||
class="u-text u-text-custom-color-1 u-text-default u-text-1"
|
||||
>
|
||||
Создание отчета по участникам за период
|
||||
</h2>
|
||||
<h1 class="display-4">Отчет по участникам за период</h1>
|
||||
</div>
|
||||
|
||||
<form method="post">
|
||||
<div class="u-form-group u-form-name u-label-top">
|
||||
<label class="u-label u-text-custom-color-1 u-label-1">Дата начала периода:</label>
|
||||
<input
|
||||
type="datetime-local"
|
||||
placeholder="Выберите дату начала периода"
|
||||
id="dateFrom" name="dateFrom"
|
||||
class="u-input u-input-rectangle"/>
|
||||
</div>
|
||||
<div class="u-form-email u-form-group u-label-top">
|
||||
<label class="u-label u-text-custom-color-1 u-label-2">Дата конца периода:</label>
|
||||
<input
|
||||
type="datetime-local"
|
||||
placeholder="Выберите дату конца периода"
|
||||
id="dateTo" name="dateTo"
|
||||
class="u-input u-input-rectangle"/>
|
||||
</div>
|
||||
<div class="u-align-right u-form-group u-form-submit u-label-top">
|
||||
<div class="col-8"></div>
|
||||
<div class="col-4"><input type="submit" value="Сформировать отчёт" class="u-active-custom-color-6 u-border-none u-btn u-btn-submit u-button-style u-custom-color-1 u-hover-custom-color-2 u-btn-1" /></div>
|
||||
</div>
|
||||
</form>
|
||||
<div class="text-center">
|
||||
@{
|
||||
<form method="post">
|
||||
<div class="mt-3">
|
||||
<div class="form-check form-check-inline">
|
||||
<label class="form-check-label" for="dateFrom">
|
||||
От
|
||||
</label>
|
||||
<input type="datetime-local" id="dateFrom" name="dateFrom" />
|
||||
</div>
|
||||
<div class="form-check form-check-inline">
|
||||
<label class="form-check-label" for="dateTo">
|
||||
До
|
||||
</label>
|
||||
<input type="datetime-local" id="dateTo" name="dateTo" />
|
||||
</div>
|
||||
</div>
|
||||
<div class="mt-3">
|
||||
Ваш email
|
||||
<input type="text" name="organiserEmail" />
|
||||
<button class="btn btn-primary ms-3" type="submit">Отправить на почту</button>
|
||||
</div>
|
||||
<div class="mt-3" id="report" style="display: flex; flex-direction: column;">
|
||||
</div>
|
||||
</form>
|
||||
<button class="btn btn-primary" type="button" id="demonstrate">Продемонстрировать</button>
|
||||
}
|
||||
</div>
|
||||
|
||||
@section Scripts {
|
||||
<script>
|
||||
function check() {
|
||||
var dateFrom = $('#dateFrom').val();
|
||||
var dateTo = $('#dateTo').val();
|
||||
if (dateFrom && dateTo) {
|
||||
$.ajax({
|
||||
method: "GET",
|
||||
url: "/Home/GetMembersReport",
|
||||
data: { dateFrom: dateFrom, dateTo: dateTo },
|
||||
success: function (result) {
|
||||
if (result != null) {
|
||||
$('#report').html(result);
|
||||
}
|
||||
}
|
||||
});
|
||||
};
|
||||
}
|
||||
check();
|
||||
$('#demonstrate').on('click', (e) => check());
|
||||
</script>
|
||||
}
|
@ -2,6 +2,9 @@
|
||||
using HotelContracts.BusinessLogicsContracts;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using DocumentFormat.OpenXml.Presentation;
|
||||
using DocumentFormat.OpenXml.Spreadsheet;
|
||||
using HotelBusinessLogic.MailWorker;
|
||||
|
||||
namespace HotelRestApi.Controllers
|
||||
{
|
||||
@ -12,11 +15,13 @@ namespace HotelRestApi.Controllers
|
||||
private readonly ILogger _logger;
|
||||
private readonly IReportOrganiserLogic _reportOrganiserLogic;
|
||||
private readonly IReportHeadwaiterLogic _reportHeadwaiterLogic;
|
||||
public ReportController(ILogger<ReportController> logger, IReportOrganiserLogic reportOrganiserLogic, IReportHeadwaiterLogic reportHeadwaiterLogic)
|
||||
private readonly AbstractMailWorker _mailWorker;
|
||||
public ReportController(ILogger<ReportController> logger, AbstractMailWorker mailWorker, IReportOrganiserLogic reportOrganiserLogic, IReportHeadwaiterLogic reportHeadwaiterLogic)
|
||||
{
|
||||
_logger = logger;
|
||||
_reportOrganiserLogic = reportOrganiserLogic;
|
||||
_reportHeadwaiterLogic = reportHeadwaiterLogic;
|
||||
_mailWorker = mailWorker;
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
@ -26,10 +31,10 @@ namespace HotelRestApi.Controllers
|
||||
{
|
||||
_reportOrganiserLogic.SaveMembersToPdfFile(new ReportBindingModel
|
||||
{
|
||||
FileName="Отчет PDF.pdf",
|
||||
DateFrom = model.DateFrom,
|
||||
DateTo = model.DateTo,
|
||||
OrganiserId=model.OrganiserId,
|
||||
OrganiserId = model.OrganiserId,
|
||||
FileName = "F:\\ReportsCourseWork\\pdffile.pdf",
|
||||
});
|
||||
}
|
||||
catch (Exception ex)
|
||||
@ -39,6 +44,20 @@ namespace HotelRestApi.Controllers
|
||||
}
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public void SendPdfToMail(MailSendInfoBindingModel model)
|
||||
{
|
||||
try
|
||||
{
|
||||
_mailWorker.MailSendAsync(model);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка отправки письма");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public void CreateReportToWordFile(ReportBindingModel model)
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user