почти готовы отчеты
This commit is contained in:
parent
95a732593a
commit
7158a74f27
@ -3,11 +3,13 @@ using HotelContracts.BindingModels;
|
||||
using HotelContracts.BusinessLogicsContracts;
|
||||
using HotelContracts.SearchModels;
|
||||
using HotelContracts.ViewModels;
|
||||
using HotelDataBaseImplement;
|
||||
using HotelDataBaseImplement.Models;
|
||||
using HotelDataModels.Models;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.AspNetCore.Mvc.Rendering;
|
||||
using System.Diagnostics;
|
||||
using System.Globalization;
|
||||
using System.Numerics;
|
||||
|
||||
namespace HotelAdministratorApp.Controllers
|
||||
@ -484,20 +486,175 @@ namespace HotelAdministratorApp.Controllers
|
||||
{
|
||||
throw new Exception("Вы как сюда попали? Сюда вход только авторизованным");
|
||||
}
|
||||
var roomElem = APIClient.GetRequest<RoomViewModel>($"api/main/getroombyid?roomId={room}");
|
||||
APIClient.PostRequest("api/main/updateroom", new RoomBindingModel
|
||||
using var context = new HotelDataBase();
|
||||
var roomElem = APIClient.GetRequest<RoomViewModel>($"api/main/getroombyid?roomId={room}");
|
||||
var dinners = _dinner.ReadList(new DinnerSearchModel { AdministratorId = APIClient.Administrator.Id });
|
||||
|
||||
APIClient.PostRequest("api/main/updateroom", new RoomBindingModel
|
||||
{
|
||||
Id = room,
|
||||
MealPlanId = mealplan,
|
||||
RoomNumber = roomElem.RoomNumber,
|
||||
DateCreate = roomElem.DateCreate,
|
||||
RoomPrice = roomElem.RoomPrice,
|
||||
/*RoomDinners = roomElemrs,*/
|
||||
AdministratorId = roomElem.AdministratorId,
|
||||
});
|
||||
Response.Redirect("Rooms");
|
||||
}
|
||||
[HttpGet]
|
||||
public IActionResult MealPlanDinnerReport()
|
||||
{
|
||||
if (APIClient.Administrator == null)
|
||||
{
|
||||
return Redirect("~/Home/Enter");
|
||||
}
|
||||
ViewBag.Dinners = APIClient.GetRequest<List<DinnerViewModel>>($"api/main/getdinnerlist?administratorid={APIClient.Administrator.Id}");
|
||||
return View();
|
||||
}
|
||||
|
||||
[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
|
||||
[HttpPost]
|
||||
public void MealPlanDinnerReport(List<int> dinners, string type)
|
||||
{
|
||||
if (APIClient.Administrator == null)
|
||||
{
|
||||
throw new Exception("Вы как суда попали? Суда вход только авторизованным");
|
||||
}
|
||||
|
||||
if (dinners.Count <= 0)
|
||||
{
|
||||
throw new Exception("Количество должно быть больше 0");
|
||||
}
|
||||
|
||||
if (string.IsNullOrEmpty(type))
|
||||
{
|
||||
throw new Exception("Неверный тип отчета");
|
||||
}
|
||||
|
||||
if (type == "docx")
|
||||
{
|
||||
APIClient.PostRequest("api/reportadministrator/createmealplanlistwordfile", new ReportMealPlanDinnerBindingModel
|
||||
{
|
||||
Dinners = dinners,
|
||||
FileName = "C:\\Users\\sshan\\OneDrive\\Desktop\\reports\\wordfile.docx"
|
||||
});
|
||||
Response.Redirect("GetWordFile");
|
||||
}
|
||||
else
|
||||
{
|
||||
APIClient.PostRequest("api/reportadministrator/createmealplanlistexcelfile", new ReportMealPlanDinnerBindingModel
|
||||
{
|
||||
Dinners = dinners,
|
||||
FileName = "C:\\Users\\sshan\\OneDrive\\Desktop\\reports\\exelfile.xlsx"
|
||||
});
|
||||
Response.Redirect("GetExcelFile");
|
||||
}
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public IActionResult GetWordFile()
|
||||
{
|
||||
return new PhysicalFileResult("C:\\Users\\sshan\\OneDrive\\Desktop\\reports\\wordfile.docx", "application/vnd.openxmlformats-officedocument.wordprocessingml.document");
|
||||
}
|
||||
|
||||
public IActionResult GetExcelFile()
|
||||
{
|
||||
return new PhysicalFileResult("C:\\Users\\sshan\\OneDrive\\Desktop\\reports\\exelfile.xlsx", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
|
||||
}
|
||||
[HttpGet]
|
||||
public IActionResult Report()
|
||||
{
|
||||
ViewBag.Report = new List<ReportRoomsConferenceBindingModel>();
|
||||
return View();
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public string GetDinnersReport(DateTime dateFrom, DateTime dateTo)
|
||||
{
|
||||
if (APIClient.Administrator == null)
|
||||
{
|
||||
throw new Exception("Вы как суда попали? Суда вход только авторизованным");
|
||||
}
|
||||
List<ReportRoomsConferencesViewModel> result;
|
||||
try
|
||||
{
|
||||
string dateFromS = dateFrom.ToString("s", CultureInfo.InvariantCulture);
|
||||
string dateToS = dateTo.ToString("s", CultureInfo.InvariantCulture);
|
||||
result = APIClient.GetRequest<List<ReportRoomsConferencesViewModel>>
|
||||
($"api/reportadministrator/getroomsconferencesreport?datefrom={dateFromS}&dateto={dateToS}&administratorid={APIClient.Administrator.Id}")!;
|
||||
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка создания отчета");
|
||||
throw;
|
||||
}
|
||||
string table = "";
|
||||
table += "<h2 class=\"text-custom-color-1\">Предварительный отчет</h2>";
|
||||
table += "<div class=\"table-responsive\">";
|
||||
table += "<table class=\"table table-striped table-bordered table-hover\">";
|
||||
table += "<thead class=\"table-dark\">";
|
||||
table += "<tr>";
|
||||
table += "<th scope=\"col\">Дата</th>";
|
||||
table += "<th scope=\"col\">Название обеда</th>";
|
||||
table += "<th scope=\"col\">Номер комнаты</th>";
|
||||
table += "<th scope=\"col\">Название конференции</th>";
|
||||
table += "</tr>";
|
||||
table += "</thead>";
|
||||
foreach (var dinner in result)
|
||||
{
|
||||
table += "<tbody>";
|
||||
table += "<tr>";
|
||||
table += $"<td></td>";
|
||||
table += $"<td>{dinner.DinnerName}</td>";
|
||||
table += $"<td></td>";
|
||||
table += $"<td></td>";
|
||||
table += "</tr>";
|
||||
foreach (var room in dinner.Rooms)
|
||||
{
|
||||
table += "<tr>";
|
||||
table += $"<td>{room.DateCreate}</td>";
|
||||
table += $"<td></td>";
|
||||
table += $"<td>{room.RoomNumber}</td>";
|
||||
table += $"<td></td>";
|
||||
table += "</tr>";
|
||||
}
|
||||
foreach (var conference in dinner.Conferences)
|
||||
{
|
||||
table += "<tr>";
|
||||
table += $"<td>{conference.StartDate}</td>";
|
||||
table += $"<td></td>";
|
||||
table += $"<td></td>";
|
||||
table += $"<td>{conference.ConferenceName}</td>";
|
||||
table += "</tr>";
|
||||
}
|
||||
table += "</tbody>";
|
||||
}
|
||||
table += "</table>";
|
||||
table += "</div>";
|
||||
return table;
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public void AddDinnerToFile(DateTime dateFrom, DateTime dateTo)
|
||||
{
|
||||
if (APIClient.Administrator == null)
|
||||
{
|
||||
throw new Exception("Вы как суда попали? Суда вход только авторизованным");
|
||||
}
|
||||
APIClient.PostRequest("api/reportadministrator/SendRoomsConferencesReportToEmail", new ReportRoomsConferenceBindingModel
|
||||
{
|
||||
FileName = "C:\\Users\\sshan\\OneDrive\\Desktop\\reports\\reportpdf.pdf",
|
||||
AdministratorId = APIClient.Administrator.Id,
|
||||
DateFrom = dateFrom,
|
||||
DateTo = dateTo,
|
||||
Email = APIClient.Administrator.AdministratorEmail,
|
||||
|
||||
});
|
||||
Response.Redirect("AddDinnerToFile");
|
||||
|
||||
}
|
||||
[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
|
||||
public IActionResult Error()
|
||||
{
|
||||
return View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier });
|
||||
|
@ -1,5 +1,7 @@
|
||||
using HotelAdministratorApp;
|
||||
using HotelBusinessLogic.BusinessLogic;
|
||||
using HotelBusinessLogic.OfficePackage;
|
||||
using HotelBusinessLogic.OfficePackage.Implements;
|
||||
using HotelContracts.BusinessLogicsContracts;
|
||||
using HotelContracts.StoragesContracts;
|
||||
using HotelDataBaseImplement.Implements;
|
||||
@ -11,6 +13,7 @@ builder.Services.AddTransient<IDinnerStorage, DinnerStorage>();
|
||||
builder.Services.AddTransient<IDinnerLogic, DinnerLogic>();
|
||||
builder.Services.AddTransient<IRoomStorage, RoomStorage>();
|
||||
builder.Services.AddTransient<IRoomLogic, RoomLogic>();
|
||||
builder.Services.AddTransient<AbstractSaveToPdfAdministrator, SaveToPdfAdministrator>();
|
||||
var app = builder.Build();
|
||||
APIClient.Connect(builder.Configuration);
|
||||
// Configure the HTTP request pipeline.
|
||||
|
@ -23,17 +23,37 @@
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-group mb-4">
|
||||
<label for="headwaiterEmail" class="form-label text-custom-color-1">Введите почту:</label>
|
||||
<input type="email" id="headwaiterEmail" name="headwaiterEmail" class="form-control" placeholder="Введите вашу почту">
|
||||
</div>
|
||||
<br>
|
||||
<div class="buttons-action-with-files">
|
||||
<div class="button">
|
||||
<button class="button-action">На почту</button>
|
||||
<button type ="submit" class="button-action">На почту</button>
|
||||
</div>
|
||||
<div class="button">
|
||||
<button class="button-action">Показать</button>
|
||||
<button type="button" id="demonstrate" class="button-action">Показать</button>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
<div id="report"></div>
|
||||
</form>
|
||||
|
||||
@section Scripts {
|
||||
<script>
|
||||
function check() {
|
||||
var dateFrom = $('#dateFrom').val();
|
||||
var dateTo = $('#dateTo').val();
|
||||
if (dateFrom && dateTo) {
|
||||
$.ajax({
|
||||
method: "GET",
|
||||
url: "/Home/GetDinnersReport",
|
||||
data: { dateFrom: dateFrom, dateTo: dateTo },
|
||||
success: function (result) {
|
||||
if (result != null) {
|
||||
$('#report').html(result);
|
||||
}
|
||||
}
|
||||
});
|
||||
};
|
||||
}
|
||||
check();
|
||||
$('#demonstrate').on('click', (e) => check());
|
||||
</script>
|
||||
}
|
@ -1,5 +1,6 @@
|
||||
@{
|
||||
ViewData["Title"] = "AddDinnerRoomToFiles";
|
||||
@using HotelContracts.ViewModels
|
||||
@{
|
||||
ViewData["Title"] = "MealPlanDinnerReport";
|
||||
}
|
||||
<head>
|
||||
<link rel="stylesheet" href="~/css/style.css" asp-append-version="true" />
|
||||
@ -11,33 +12,28 @@
|
||||
<div class="file-format">
|
||||
<label class="form-label">Формат файла:</label>
|
||||
<div class="radio-buttons">
|
||||
<input class="form-check-input" type="radio" name="type" id="docx">
|
||||
<input class="form-check-input" type="radio" name="type" value="docx" id="docx">
|
||||
<label class="label-word" for="docx">Word-файл</label>
|
||||
</div>
|
||||
<div class="form-check">
|
||||
<input class="form-check-input" type="radio" name="type" id="xlsx" checked>
|
||||
<input class="form-check-input" type="radio" name="type" value="xlsx" id="xlsx" checked>
|
||||
<label class="label-exel" for="xlsx">Excel-файл</label>
|
||||
</div>
|
||||
</div>
|
||||
<table class="table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>
|
||||
Название
|
||||
</th>
|
||||
<th>
|
||||
Калорийность
|
||||
</th>
|
||||
<th>
|
||||
Цена
|
||||
</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
</tbody>
|
||||
</table>
|
||||
<br>
|
||||
<div class="row">
|
||||
<div class="col-4">Обеды:</div>
|
||||
<div class="col-8">
|
||||
<select name="dinners" class="form-control" multiple size="5" id="dinners">
|
||||
@foreach (var service in ViewBag.Dinners)
|
||||
{
|
||||
<option value="@service.Id">@service.DinnerName</option>
|
||||
}
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
<br>
|
||||
<div class="buttons-create-file">
|
||||
<button class="button-action">Создать</button>
|
||||
<button type ="submit" class="button-action">Создать</button>
|
||||
</div>
|
||||
</form>
|
@ -59,7 +59,7 @@
|
||||
</a>
|
||||
<ul class="dropdown-menu" aria-labelledby="navbarDropdownMenuLink">
|
||||
<li class="nav-item">
|
||||
<a class="nav-link" asparea="" asp-controller="Home" asp-action="AddDinnerRoomToFiles">Отчет (word/excel)</a>
|
||||
<a class="nav-link" asparea="" asp-controller="Home" asp-action="MealPlanDinnerReport">Отчет (word/excel)</a>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a class="nav-link" asparea="" asp-controller="Home" asp-action="AddDinnerToFile">Отчет (pdf) </a>
|
||||
|
@ -0,0 +1,75 @@
|
||||
using HotelContracts.BindingModels;
|
||||
using HotelContracts.BusinessLogicsContracts;
|
||||
using HotelContracts.StoragesContracts;
|
||||
using HotelContracts.ViewModels;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using HotelBusinessLogic.OfficePackage;
|
||||
using HotelBusinessLogic.OfficePackage.HelperModels;
|
||||
|
||||
namespace HotelBusinessLogic.BusinessLogic
|
||||
{
|
||||
public class ReportLogicAdministrator : IReportAdministratorLogic
|
||||
{
|
||||
private readonly IDinnerStorage _dinnerStorage;
|
||||
private readonly AbstractSaveToExcelAdministrator _saveToExcel;
|
||||
private readonly AbstractSaveToWordAdministrator _saveToWord;
|
||||
private readonly AbstractSaveToPdfAdministrator _saveToPdf;
|
||||
|
||||
public ReportLogicAdministrator(IDinnerStorage dinnerStorage,
|
||||
AbstractSaveToExcelAdministrator saveToExcel, AbstractSaveToWordAdministrator saveToWord, AbstractSaveToPdfAdministrator saveToPdf)
|
||||
{
|
||||
_dinnerStorage = dinnerStorage;
|
||||
_saveToExcel = saveToExcel;
|
||||
_saveToWord = saveToWord;
|
||||
_saveToPdf = saveToPdf;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public void SaveMealPlansToExcelFile(ReportMealPlanDinnerBindingModel model)
|
||||
{
|
||||
_saveToExcel.CreateReport(new ExcelInfoAdministrator
|
||||
{
|
||||
FileName = model.FileName,
|
||||
Title = "Список покупок по медикаментам",
|
||||
MealPlanDinners = GetMealPlanDinners(model)
|
||||
});
|
||||
}
|
||||
|
||||
public void SaveMealPlansToWordFile(ReportMealPlanDinnerBindingModel model)
|
||||
{
|
||||
_saveToWord.CreateDoc(new WordInfoAdministrator
|
||||
{
|
||||
FileName = model.FileName,
|
||||
Title = "Список покупок по медикаментам",
|
||||
MealPlanDinners = GetMealPlanDinners(model)
|
||||
});
|
||||
}
|
||||
|
||||
public List<ReportMealPlansDinnersViewModel> GetMealPlanDinners(ReportMealPlanDinnerBindingModel model)
|
||||
{
|
||||
return _dinnerStorage.GetReportDinnerMealPlansList(new() { dinnersIds = model.Dinners });
|
||||
}
|
||||
public List<ReportRoomsConferencesViewModel> GetRoomsConferences(ReportRoomsConferenceBindingModel model)
|
||||
{
|
||||
return _dinnerStorage.GetReportRoomsConferences(new() { DateFrom = model.DateFrom, DateTo = model.DateTo, AdministratorId = model.AdministratorId });
|
||||
}
|
||||
|
||||
public void SaveDinnersToPdfFile(ReportRoomsConferenceBindingModel model)
|
||||
{
|
||||
_saveToPdf.CreateDoc(new PdfInfo
|
||||
{
|
||||
FileName = model.FileName,
|
||||
Title = "Список обедов",
|
||||
DateFrom = model.DateFrom!,
|
||||
DateTo = model.DateTo!,
|
||||
ReportRoomsConferences = GetRoomsConferences(model)
|
||||
});
|
||||
|
||||
}
|
||||
}
|
||||
}
|
@ -7,7 +7,9 @@
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="DocumentFormat.OpenXml" Version="3.0.2" />
|
||||
<PackageReference Include="Microsoft.Extensions.Logging" Version="7.0.0" />
|
||||
<PackageReference Include="PdfSharp.MigraDoc.Standard" Version="1.51.15" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
64
Hotel/HotelBusinessLogic/MailWorker/AbstractMailWorker.cs
Normal file
64
Hotel/HotelBusinessLogic/MailWorker/AbstractMailWorker.cs
Normal file
@ -0,0 +1,64 @@
|
||||
using HotelContracts.BindingModels;
|
||||
using HotelContracts.BusinessLogicsContracts;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace HotelBusinessLogic.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 IAdministratorLogic _administratorLogic;
|
||||
private readonly ILogger _logger;
|
||||
|
||||
public AbstractMailWorker(ILogger<AbstractMailWorker> logger, IAdministratorLogic administratorLogic)
|
||||
{
|
||||
_logger = logger;
|
||||
_administratorLogic = administratorLogic;
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
48
Hotel/HotelBusinessLogic/MailWorker/MailKitWorker.cs
Normal file
48
Hotel/HotelBusinessLogic/MailWorker/MailKitWorker.cs
Normal file
@ -0,0 +1,48 @@
|
||||
using HotelContracts.BindingModels;
|
||||
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 HotelContracts.BusinessLogicsContracts;
|
||||
|
||||
namespace HotelBusinessLogic.MailWorker
|
||||
{
|
||||
public class MailKitWorker : AbstractMailWorker
|
||||
{
|
||||
public MailKitWorker(ILogger<MailKitWorker> logger, IAdministratorLogic administratorLogic) : base(logger, administratorLogic) { }
|
||||
|
||||
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("C:\\Users\\sshan\\OneDrive\\Desktop\\reports\\reportpdf.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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,73 @@
|
||||
using HotelBusinessLogic.OfficePackage.HelperEnums;
|
||||
using HotelBusinessLogic.OfficePackage.HelperModels;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace HotelBusinessLogic.OfficePackage
|
||||
{
|
||||
public abstract class AbstractSaveToExcelAdministrator
|
||||
{
|
||||
public void CreateReport(ExcelInfoAdministrator info)
|
||||
{
|
||||
CreateExcel(info);
|
||||
|
||||
InsertCellInWorksheet(new ExcelCellParameters
|
||||
{
|
||||
ColumnName = "A",
|
||||
RowIndex = 1,
|
||||
Text = info.Title,
|
||||
StyleInfo = ExcelStyleInfoType.Title
|
||||
});
|
||||
|
||||
MergeCells(new ExcelMergeParameters
|
||||
{
|
||||
CellFromName = "A1",
|
||||
CellToName = "C1"
|
||||
});
|
||||
|
||||
uint rowIndex = 2;
|
||||
|
||||
foreach (var rec in info.MealPlanDinners)
|
||||
{
|
||||
InsertCellInWorksheet(new ExcelCellParameters
|
||||
{
|
||||
ColumnName = "A",
|
||||
RowIndex = rowIndex,
|
||||
Text = rec.DinnerName,
|
||||
StyleInfo = ExcelStyleInfoType.Text
|
||||
});
|
||||
|
||||
rowIndex++;
|
||||
|
||||
foreach (var dinner in rec.MealPlans)
|
||||
{
|
||||
InsertCellInWorksheet(new ExcelCellParameters
|
||||
{
|
||||
ColumnName = "B",
|
||||
RowIndex = rowIndex,
|
||||
Text = dinner.MealPlanName,
|
||||
StyleInfo = ExcelStyleInfoType.TextWithBroder
|
||||
});
|
||||
|
||||
rowIndex++;
|
||||
}
|
||||
|
||||
rowIndex++;
|
||||
}
|
||||
|
||||
SaveExcel(info);
|
||||
}
|
||||
|
||||
protected abstract void CreateExcel(ExcelInfoAdministrator info);
|
||||
|
||||
protected abstract void InsertCellInWorksheet(ExcelCellParameters excelParams);
|
||||
|
||||
protected abstract void MergeCells(ExcelMergeParameters excelParams);
|
||||
|
||||
protected abstract void SaveExcel(ExcelInfoAdministrator info);
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,72 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using HotelBusinessLogic.OfficePackage.HelperEnums;
|
||||
using HotelBusinessLogic.OfficePackage.HelperModels;
|
||||
|
||||
namespace HotelBusinessLogic.OfficePackage
|
||||
{
|
||||
public abstract class AbstractSaveToPdfAdministrator
|
||||
{
|
||||
public void CreateDoc(PdfInfo info)
|
||||
{
|
||||
CreatePdf(info);
|
||||
CreateParagraph(new PdfParagraph
|
||||
{
|
||||
Text = info.Title,
|
||||
Style =
|
||||
"NormalTitle",
|
||||
ParagraphAlignment = PdfParagraphAligmentType.Center
|
||||
});
|
||||
CreateParagraph(new PdfParagraph
|
||||
{
|
||||
Text = $"с {info.DateFrom.ToShortDateString()} по {info.DateTo.ToShortDateString()}",
|
||||
Style
|
||||
= "Normal",
|
||||
ParagraphAlignment = PdfParagraphAligmentType.Center
|
||||
});
|
||||
CreateTable(new List<string> { "4cm", "4cm", "4cm", "4cm" });
|
||||
CreateRow(new PdfRowParameters
|
||||
{
|
||||
Texts = new List<string> { "Дата", "Название обеда", "Комната", "Бронь" },
|
||||
Style = "NormalTitle",
|
||||
ParagraphAlignment = PdfParagraphAligmentType.Center
|
||||
});
|
||||
foreach (var dinner in info.ReportRoomsConferences)
|
||||
{
|
||||
CreateRow(new PdfRowParameters
|
||||
{
|
||||
Texts = new List<string> { "", dinner.DinnerName, "", "" },
|
||||
Style = "NormalTitle",
|
||||
ParagraphAlignment = PdfParagraphAligmentType.Center
|
||||
});
|
||||
foreach (var conference in dinner.Conferences)
|
||||
{
|
||||
CreateRow(new PdfRowParameters
|
||||
{
|
||||
Texts = new List<string> { conference.StartDate.ToString(), "", "", conference.ConferenceName },
|
||||
Style = "Normal",
|
||||
ParagraphAlignment = PdfParagraphAligmentType.Center
|
||||
});
|
||||
}
|
||||
foreach (var room in dinner.Rooms)
|
||||
{
|
||||
CreateRow(new PdfRowParameters
|
||||
{
|
||||
Texts = new List<string> { room.DateCreate.ToString(), "", room.RoomNumber.ToString(), "" },
|
||||
Style = "Normal",
|
||||
ParagraphAlignment = PdfParagraphAligmentType.Center
|
||||
});
|
||||
}
|
||||
}
|
||||
SavePdf(info);
|
||||
}
|
||||
protected abstract void CreatePdf(PdfInfo info);
|
||||
protected abstract void CreateParagraph(PdfParagraph paragraph);
|
||||
protected abstract void CreateTable(List<string> columns);
|
||||
protected abstract void CreateRow(PdfRowParameters rowParameters);
|
||||
protected abstract void SavePdf(PdfInfo info);
|
||||
}
|
||||
}
|
@ -0,0 +1,61 @@
|
||||
using HotelBusinessLogic.OfficePackage.HelperEnums;
|
||||
using HotelBusinessLogic.OfficePackage.HelperModels;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace HotelBusinessLogic.OfficePackage
|
||||
{
|
||||
public abstract class AbstractSaveToWordAdministrator
|
||||
{
|
||||
public void CreateDoc(WordInfoAdministrator info)
|
||||
{
|
||||
CreateWord(info);
|
||||
|
||||
CreateParagraph(new WordParagraph
|
||||
{
|
||||
Texts = new List<(string, WordTextProperties)> { (info.Title, new WordTextProperties { Bold = true, Size = "24", }) },
|
||||
TextProperties = new WordTextProperties
|
||||
{
|
||||
Size = "24",
|
||||
JustificationType = WordJustificationType.Center
|
||||
}
|
||||
});
|
||||
|
||||
foreach (var rec in info.MealPlanDinners)
|
||||
{
|
||||
CreateParagraph(new WordParagraph
|
||||
{
|
||||
Texts = new List<(string, WordTextProperties)>
|
||||
{ (rec.DinnerName, new WordTextProperties { Size = "24", Bold=true})},
|
||||
TextProperties = new WordTextProperties
|
||||
{
|
||||
Size = "24",
|
||||
JustificationType = WordJustificationType.Both
|
||||
}
|
||||
});
|
||||
|
||||
foreach (var dinner in rec.MealPlans)
|
||||
{
|
||||
CreateParagraph(new WordParagraph
|
||||
{
|
||||
Texts = new List<(string, WordTextProperties)>
|
||||
{ (dinner.MealPlanName, new WordTextProperties { Size = "20", Bold=false})},
|
||||
TextProperties = new WordTextProperties
|
||||
{
|
||||
Size = "24",
|
||||
JustificationType = WordJustificationType.Both
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
SaveWord(info);
|
||||
}
|
||||
|
||||
protected abstract void CreateWord(WordInfoAdministrator info);
|
||||
protected abstract void CreateParagraph(WordParagraph paragraph);
|
||||
protected abstract void SaveWord(WordInfoAdministrator info);
|
||||
}
|
||||
}
|
@ -0,0 +1,15 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace HotelBusinessLogic.OfficePackage.HelperEnums
|
||||
{
|
||||
public enum ExcelStyleInfoType
|
||||
{
|
||||
Title,
|
||||
Text,
|
||||
TextWithBroder
|
||||
}
|
||||
}
|
@ -0,0 +1,15 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace HotelBusinessLogic.OfficePackage.HelperEnums
|
||||
{
|
||||
public enum PdfParagraphAligmentType
|
||||
{
|
||||
Center,
|
||||
Left,
|
||||
Right
|
||||
}
|
||||
}
|
@ -0,0 +1,14 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace HotelBusinessLogic.OfficePackage.HelperEnums
|
||||
{
|
||||
public enum WordJustificationType
|
||||
{
|
||||
Center,
|
||||
Both
|
||||
}
|
||||
}
|
@ -0,0 +1,18 @@
|
||||
using HotelBusinessLogic.OfficePackage.HelperEnums;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace HotelBusinessLogic.OfficePackage.HelperModels
|
||||
{
|
||||
public class ExcelCellParameters
|
||||
{
|
||||
public string ColumnName { get; set; } = string.Empty;
|
||||
public uint RowIndex { get; set; }
|
||||
public string Text { get; set; } = string.Empty;
|
||||
public string CellReference => $"{ColumnName}{RowIndex}";
|
||||
public ExcelStyleInfoType StyleInfo { get; set; }
|
||||
}
|
||||
}
|
@ -0,0 +1,16 @@
|
||||
using HotelContracts.ViewModels;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace HotelBusinessLogic.OfficePackage.HelperModels
|
||||
{
|
||||
public class ExcelInfoAdministrator
|
||||
{
|
||||
public string FileName { get; set; } = string.Empty;
|
||||
public string Title { get; set; } = string.Empty;
|
||||
public List<ReportMealPlansDinnersViewModel> MealPlanDinners { get; set; } = new();
|
||||
}
|
||||
}
|
@ -0,0 +1,15 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace HotelBusinessLogic.OfficePackage.HelperModels
|
||||
{
|
||||
public class ExcelMergeParameters
|
||||
{
|
||||
public string CellFromName { get; set; } = string.Empty;
|
||||
public string CellToName { get; set; } = string.Empty;
|
||||
public string Merge => $"{CellFromName}:{CellToName}";
|
||||
}
|
||||
}
|
@ -0,0 +1,19 @@
|
||||
using HotelContracts.ViewModels;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace HotelBusinessLogic.OfficePackage.HelperModels
|
||||
{
|
||||
public class PdfInfo
|
||||
{
|
||||
public string FileName { get; set; } = string.Empty;
|
||||
public string Title { get; set; } = string.Empty;
|
||||
public DateTime DateFrom { get; set; }
|
||||
public DateTime DateTo { get; set; }
|
||||
public List<ReportRoomsConferencesViewModel> ReportRoomsConferences { get; set; } = new();
|
||||
/* public List<ReportVisitsDrugsViewModel> ReportVisitsDrugs { get; set; } = new();*/
|
||||
}
|
||||
}
|
@ -0,0 +1,17 @@
|
||||
using HotelBusinessLogic.OfficePackage.HelperEnums;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace HotelBusinessLogic.OfficePackage.HelperModels
|
||||
{
|
||||
public class PdfParagraph
|
||||
{
|
||||
public string Text { get; set; } = string.Empty;
|
||||
public string Style { get; set; } = string.Empty;
|
||||
public PdfParagraphAligmentType ParagraphAlignment { get; set; }
|
||||
|
||||
}
|
||||
}
|
@ -0,0 +1,16 @@
|
||||
using HotelBusinessLogic.OfficePackage.HelperEnums;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace HotelBusinessLogic.OfficePackage.HelperModels
|
||||
{
|
||||
public class PdfRowParameters
|
||||
{
|
||||
public List<string> Texts { get; set; } = new();
|
||||
public string Style { get; set; } = string.Empty;
|
||||
public PdfParagraphAligmentType ParagraphAlignment { get; set; }
|
||||
}
|
||||
}
|
@ -0,0 +1,16 @@
|
||||
using HotelContracts.ViewModels;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace HotelBusinessLogic.OfficePackage.HelperModels
|
||||
{
|
||||
public class WordInfoAdministrator
|
||||
{
|
||||
public string FileName { get; set; } = string.Empty;
|
||||
public string Title { get; set; } = string.Empty;
|
||||
public List<ReportMealPlansDinnersViewModel> MealPlanDinners { get; set; } = new();
|
||||
}
|
||||
}
|
@ -0,0 +1,14 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace HotelBusinessLogic.OfficePackage.HelperModels
|
||||
{
|
||||
public class WordParagraph
|
||||
{
|
||||
public List<(string, WordTextProperties)> Texts { get; set; } = new();
|
||||
public WordTextProperties? TextProperties { get; set; }
|
||||
}
|
||||
}
|
@ -0,0 +1,16 @@
|
||||
using HotelBusinessLogic.OfficePackage.HelperEnums;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace HotelBusinessLogic.OfficePackage.HelperModels
|
||||
{
|
||||
public class WordTextProperties
|
||||
{
|
||||
public string Size { get; set; } = string.Empty;
|
||||
public bool Bold { get; set; }
|
||||
public WordJustificationType JustificationType { get; set; }
|
||||
}
|
||||
}
|
@ -0,0 +1,333 @@
|
||||
using DocumentFormat.OpenXml.Office2010.Excel;
|
||||
using DocumentFormat.OpenXml.Office2013.Excel;
|
||||
using DocumentFormat.OpenXml.Packaging;
|
||||
using DocumentFormat.OpenXml.Spreadsheet;
|
||||
using DocumentFormat.OpenXml;
|
||||
using HotelBusinessLogic.OfficePackage.HelperEnums;
|
||||
using HotelBusinessLogic.OfficePackage.HelperModels;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace HotelBusinessLogic.OfficePackage.Implements
|
||||
{
|
||||
public class SaveToExcelAdministrator : AbstractSaveToExcelAdministrator
|
||||
{
|
||||
private SpreadsheetDocument? _spreadsheetDocument;
|
||||
private SharedStringTablePart? _shareStringPart;
|
||||
private Worksheet? _worksheet;
|
||||
|
||||
private static void CreateStyles(WorkbookPart workbookpart)
|
||||
{
|
||||
var sp = workbookpart.AddNewPart<WorkbookStylesPart>();
|
||||
sp.Stylesheet = new Stylesheet();
|
||||
|
||||
var fonts = new Fonts() { Count = 2U, KnownFonts = true };
|
||||
|
||||
var fontUsual = new Font();
|
||||
fontUsual.Append(new FontSize() { Val = 12D });
|
||||
fontUsual.Append(new DocumentFormat.OpenXml.Office2010.Excel.Color() { Theme = 1U });
|
||||
fontUsual.Append(new FontName() { Val = "Times New Roman" });
|
||||
fontUsual.Append(new FontFamilyNumbering() { Val = 2 });
|
||||
fontUsual.Append(new FontScheme() { Val = FontSchemeValues.Minor });
|
||||
|
||||
var fontTitle = new Font();
|
||||
fontTitle.Append(new Bold());
|
||||
fontTitle.Append(new FontSize() { Val = 14D });
|
||||
fontTitle.Append(new DocumentFormat.OpenXml.Office2010.Excel.Color() { Theme = 1U });
|
||||
fontTitle.Append(new FontName() { Val = "Times New Roman" });
|
||||
fontTitle.Append(new FontFamilyNumbering() { Val = 2 });
|
||||
fontTitle.Append(new FontScheme() { Val = FontSchemeValues.Minor });
|
||||
|
||||
fonts.Append(fontUsual);
|
||||
fonts.Append(fontTitle);
|
||||
|
||||
var fills = new Fills() { Count = 2U };
|
||||
|
||||
var fill1 = new Fill();
|
||||
fill1.Append(new PatternFill() { PatternType = PatternValues.None });
|
||||
|
||||
var fill2 = new Fill();
|
||||
fill2.Append(new PatternFill() { PatternType = PatternValues.Gray125 });
|
||||
|
||||
fills.Append(fill1);
|
||||
fills.Append(fill2);
|
||||
|
||||
var borders = new Borders() { Count = 2U };
|
||||
|
||||
var borderNoBorder = new Border();
|
||||
borderNoBorder.Append(new LeftBorder());
|
||||
borderNoBorder.Append(new RightBorder());
|
||||
borderNoBorder.Append(new TopBorder());
|
||||
borderNoBorder.Append(new BottomBorder());
|
||||
borderNoBorder.Append(new DiagonalBorder());
|
||||
|
||||
var borderThin = new Border();
|
||||
|
||||
var leftBorder = new LeftBorder() { Style = BorderStyleValues.Thin };
|
||||
leftBorder.Append(new DocumentFormat.OpenXml.Office2010.Excel.Color() { Indexed = 64U });
|
||||
|
||||
var rightBorder = new RightBorder() { Style = BorderStyleValues.Thin };
|
||||
rightBorder.Append(new DocumentFormat.OpenXml.Office2010.Excel.Color() { Indexed = 64U });
|
||||
|
||||
var topBorder = new TopBorder() { Style = BorderStyleValues.Thin };
|
||||
topBorder.Append(new DocumentFormat.OpenXml.Office2010.Excel.Color() { Indexed = 64U });
|
||||
|
||||
var bottomBorder = new BottomBorder() { Style = BorderStyleValues.Thin };
|
||||
bottomBorder.Append(new DocumentFormat.OpenXml.Office2010.Excel.Color() { Indexed = 64U });
|
||||
|
||||
borderThin.Append(leftBorder);
|
||||
borderThin.Append(rightBorder);
|
||||
borderThin.Append(topBorder);
|
||||
borderThin.Append(bottomBorder);
|
||||
borderThin.Append(new DiagonalBorder());
|
||||
|
||||
borders.Append(borderNoBorder);
|
||||
borders.Append(borderThin);
|
||||
|
||||
var cellStyleFormats = new CellStyleFormats()
|
||||
{
|
||||
Count = 1U
|
||||
};
|
||||
var cellFormatStyle = new CellFormat()
|
||||
{
|
||||
NumberFormatId = 0U,
|
||||
FontId = 0U,
|
||||
FillId = 0U,
|
||||
BorderId = 0U
|
||||
};
|
||||
|
||||
cellStyleFormats.Append(cellFormatStyle);
|
||||
|
||||
var cellFormats = new CellFormats()
|
||||
{
|
||||
Count = 3U
|
||||
};
|
||||
var cellFormatFont = new CellFormat()
|
||||
{
|
||||
NumberFormatId = 0U,
|
||||
FontId = 0U,
|
||||
FillId = 0U,
|
||||
BorderId = 0U,
|
||||
FormatId = 0U,
|
||||
ApplyFont = true
|
||||
};
|
||||
var cellFormatFontAndBorder = new CellFormat()
|
||||
{
|
||||
NumberFormatId = 0U,
|
||||
FontId = 0U,
|
||||
FillId = 0U,
|
||||
BorderId = 1U,
|
||||
FormatId = 0U,
|
||||
ApplyFont = true,
|
||||
ApplyBorder = true
|
||||
};
|
||||
var cellFormatTitle = new CellFormat()
|
||||
{
|
||||
NumberFormatId = 0U,
|
||||
FontId = 1U,
|
||||
FillId = 0U,
|
||||
BorderId = 0U,
|
||||
FormatId = 0U,
|
||||
Alignment = new Alignment()
|
||||
{
|
||||
Vertical = VerticalAlignmentValues.Center,
|
||||
WrapText = true,
|
||||
Horizontal = HorizontalAlignmentValues.Center
|
||||
},
|
||||
ApplyFont = true
|
||||
};
|
||||
cellFormats.Append(cellFormatFont);
|
||||
cellFormats.Append(cellFormatFontAndBorder);
|
||||
cellFormats.Append(cellFormatTitle);
|
||||
var cellStyles = new CellStyles() { Count = 1U };
|
||||
cellStyles.Append(new CellStyle()
|
||||
{
|
||||
Name = "Normal",
|
||||
FormatId = 0U,
|
||||
BuiltinId = 0U
|
||||
});
|
||||
var differentialFormats = new DocumentFormat.OpenXml.Office2013.Excel.DifferentialFormats()
|
||||
{
|
||||
Count = 0U
|
||||
};
|
||||
|
||||
var tableStyles = new TableStyles()
|
||||
{
|
||||
Count = 0U,
|
||||
DefaultTableStyle = "TableStyleMedium2",
|
||||
DefaultPivotStyle = "PivotStyleLight16"
|
||||
};
|
||||
var stylesheetExtensionList = new StylesheetExtensionList();
|
||||
var stylesheetExtension1 = new StylesheetExtension()
|
||||
{
|
||||
Uri = "{EB79DEF2-80B8-43e5-95BD-54CBDDF9020C}"
|
||||
};
|
||||
stylesheetExtension1.AddNamespaceDeclaration("x14", "http://schemas.microsoft.com/office/spreadsheetml/2009/9/main");
|
||||
stylesheetExtension1.Append(new SlicerStyles()
|
||||
{
|
||||
DefaultSlicerStyle = "SlicerStyleLight1"
|
||||
});
|
||||
var stylesheetExtension2 = new StylesheetExtension()
|
||||
{
|
||||
Uri = "{9260A510-F301-46a8-8635-F512D64BE5F5}"
|
||||
};
|
||||
stylesheetExtension2.AddNamespaceDeclaration("x15", "http://schemas.microsoft.com/office/spreadsheetml/2010/11/main");
|
||||
stylesheetExtension2.Append(new TimelineStyles()
|
||||
{
|
||||
DefaultTimelineStyle = "TimeSlicerStyleLight1"
|
||||
});
|
||||
|
||||
stylesheetExtensionList.Append(stylesheetExtension1);
|
||||
stylesheetExtensionList.Append(stylesheetExtension2);
|
||||
|
||||
sp.Stylesheet.Append(fonts);
|
||||
sp.Stylesheet.Append(fills);
|
||||
sp.Stylesheet.Append(borders);
|
||||
sp.Stylesheet.Append(cellStyleFormats);
|
||||
sp.Stylesheet.Append(cellFormats);
|
||||
sp.Stylesheet.Append(cellStyles);
|
||||
sp.Stylesheet.Append(differentialFormats);
|
||||
sp.Stylesheet.Append(tableStyles);
|
||||
sp.Stylesheet.Append(stylesheetExtensionList);
|
||||
}
|
||||
|
||||
private static uint GetStyleValue(ExcelStyleInfoType styleInfo)
|
||||
{
|
||||
return styleInfo switch
|
||||
{
|
||||
ExcelStyleInfoType.Title => 2U,
|
||||
ExcelStyleInfoType.TextWithBroder => 1U,
|
||||
ExcelStyleInfoType.Text => 0U,
|
||||
_ => 0U,
|
||||
};
|
||||
}
|
||||
|
||||
protected override void CreateExcel(ExcelInfoAdministrator info)
|
||||
{
|
||||
_spreadsheetDocument = SpreadsheetDocument.Create(info.FileName, SpreadsheetDocumentType.Workbook);
|
||||
var workbookpart = _spreadsheetDocument.AddWorkbookPart();
|
||||
workbookpart.Workbook = new Workbook();
|
||||
CreateStyles(workbookpart);
|
||||
_shareStringPart = _spreadsheetDocument.WorkbookPart!.GetPartsOfType<SharedStringTablePart>().Any() ? _spreadsheetDocument.WorkbookPart.GetPartsOfType<SharedStringTablePart>().First() : _spreadsheetDocument.WorkbookPart.AddNewPart<SharedStringTablePart>();
|
||||
|
||||
if (_shareStringPart.SharedStringTable == null)
|
||||
{
|
||||
_shareStringPart.SharedStringTable = new SharedStringTable();
|
||||
}
|
||||
|
||||
var worksheetPart = workbookpart.AddNewPart<WorksheetPart>();
|
||||
worksheetPart.Worksheet = new Worksheet(new SheetData());
|
||||
|
||||
var sheets = _spreadsheetDocument.WorkbookPart.Workbook.AppendChild(new Sheets());
|
||||
var sheet = new Sheet()
|
||||
{
|
||||
Id = _spreadsheetDocument.WorkbookPart.GetIdOfPart(worksheetPart),
|
||||
SheetId = 1,
|
||||
Name = "Лист"
|
||||
};
|
||||
sheets.Append(sheet);
|
||||
_worksheet = worksheetPart.Worksheet;
|
||||
}
|
||||
|
||||
protected override void InsertCellInWorksheet(ExcelCellParameters excelParams)
|
||||
{
|
||||
if (_worksheet == null || _shareStringPart == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var sheetData = _worksheet.GetFirstChild<SheetData>();
|
||||
|
||||
if (sheetData == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Row row;
|
||||
|
||||
if (sheetData.Elements<Row>().Where(r => r.RowIndex! == excelParams.RowIndex).Any())
|
||||
{
|
||||
row = sheetData.Elements<Row>().Where(r => r.RowIndex! == excelParams.RowIndex).First();
|
||||
}
|
||||
else
|
||||
{
|
||||
row = new Row() { RowIndex = excelParams.RowIndex };
|
||||
sheetData.Append(row);
|
||||
}
|
||||
|
||||
Cell cell;
|
||||
|
||||
if (row.Elements<Cell>().Where(c => c.CellReference!.Value == excelParams.CellReference).Any())
|
||||
{
|
||||
cell = row.Elements<Cell>().Where(c => c.CellReference!.Value == excelParams.CellReference).First();
|
||||
}
|
||||
else
|
||||
{
|
||||
Cell? refCell = null;
|
||||
foreach (Cell rowCell in row.Elements<Cell>())
|
||||
{
|
||||
if (string.Compare(rowCell.CellReference!.Value, excelParams.CellReference, true) > 0)
|
||||
{
|
||||
refCell = rowCell;
|
||||
break;
|
||||
}
|
||||
}
|
||||
var newCell = new Cell()
|
||||
{
|
||||
CellReference = excelParams.CellReference
|
||||
};
|
||||
row.InsertBefore(newCell, refCell);
|
||||
cell = newCell;
|
||||
}
|
||||
|
||||
_shareStringPart.SharedStringTable.AppendChild(new SharedStringItem(new Text(excelParams.Text)));
|
||||
_shareStringPart.SharedStringTable.Save();
|
||||
cell.CellValue = new CellValue((_shareStringPart.SharedStringTable.Elements<SharedStringItem>().Count() - 1).ToString());
|
||||
cell.DataType = new EnumValue<CellValues>(CellValues.SharedString);
|
||||
cell.StyleIndex = GetStyleValue(excelParams.StyleInfo);
|
||||
}
|
||||
|
||||
protected override void MergeCells(ExcelMergeParameters excelParams)
|
||||
{
|
||||
if (_worksheet == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
MergeCells mergeCells;
|
||||
if (_worksheet.Elements<MergeCells>().Any())
|
||||
{
|
||||
mergeCells = _worksheet.Elements<MergeCells>().First();
|
||||
}
|
||||
else
|
||||
{
|
||||
mergeCells = new MergeCells();
|
||||
if (_worksheet.Elements<CustomSheetView>().Any())
|
||||
{
|
||||
_worksheet.InsertAfter(mergeCells, _worksheet.Elements<CustomSheetView>().First());
|
||||
}
|
||||
else
|
||||
{
|
||||
_worksheet.InsertAfter(mergeCells, _worksheet.Elements<SheetData>().First());
|
||||
}
|
||||
}
|
||||
var mergeCell = new MergeCell()
|
||||
{
|
||||
Reference = new StringValue(excelParams.Merge)
|
||||
};
|
||||
mergeCells.Append(mergeCell);
|
||||
}
|
||||
|
||||
protected override void SaveExcel(ExcelInfoAdministrator info)
|
||||
{
|
||||
if (_spreadsheetDocument == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
_spreadsheetDocument.WorkbookPart!.Workbook.Save();
|
||||
_spreadsheetDocument.Dispose();
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,106 @@
|
||||
using HotelBusinessLogic.OfficePackage.HelperEnums;
|
||||
using HotelBusinessLogic.OfficePackage.HelperModels;
|
||||
using MigraDoc.DocumentObjectModel;
|
||||
using MigraDoc.DocumentObjectModel.Tables;
|
||||
using MigraDoc.Rendering;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace HotelBusinessLogic.OfficePackage.Implements
|
||||
{
|
||||
public class SaveToPdfAdministrator : AbstractSaveToPdfAdministrator
|
||||
{
|
||||
private Document? _document;
|
||||
private Section? _section;
|
||||
private Table? _table;
|
||||
private static ParagraphAlignment
|
||||
GetParagraphAlignment(PdfParagraphAligmentType type)
|
||||
{
|
||||
return type switch
|
||||
{
|
||||
PdfParagraphAligmentType.Center => ParagraphAlignment.Center,
|
||||
PdfParagraphAligmentType.Left => ParagraphAlignment.Left,
|
||||
PdfParagraphAligmentType.Right => ParagraphAlignment.Right,
|
||||
_ => ParagraphAlignment.Justify,
|
||||
};
|
||||
}
|
||||
/// <summary>
|
||||
/// Создание стилей для документа
|
||||
/// </summary>
|
||||
/// <param name="document"></param>
|
||||
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(PdfInfo 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<string> 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(PdfInfo info)
|
||||
{
|
||||
var renderer = new PdfDocumentRenderer(true)
|
||||
{
|
||||
Document = _document
|
||||
};
|
||||
renderer.RenderDocument();
|
||||
renderer.PdfDocument.Save(info.FileName);
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,117 @@
|
||||
using DocumentFormat.OpenXml.Packaging;
|
||||
using DocumentFormat.OpenXml.Wordprocessing;
|
||||
using DocumentFormat.OpenXml;
|
||||
using HotelBusinessLogic.OfficePackage.HelperEnums;
|
||||
using HotelBusinessLogic.OfficePackage.HelperModels;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace HotelBusinessLogic.OfficePackage.Implements
|
||||
{
|
||||
public class SaveToWordAdministrator : AbstractSaveToWordAdministrator
|
||||
{
|
||||
private WordprocessingDocument? _wordDocument;
|
||||
private Body? _docBody;
|
||||
// получение типов выравнивания
|
||||
private static JustificationValues GetJustificationValues(WordJustificationType type)
|
||||
{
|
||||
return type switch
|
||||
{
|
||||
WordJustificationType.Both => JustificationValues.Both,
|
||||
WordJustificationType.Center => JustificationValues.Center,
|
||||
_ => JustificationValues.Left,
|
||||
};
|
||||
}
|
||||
// настройки страницы
|
||||
private static SectionProperties CreateSectionProperties()
|
||||
{
|
||||
var properties = new SectionProperties();
|
||||
var pageSize = new PageSize
|
||||
{
|
||||
Orient = PageOrientationValues.Portrait
|
||||
};
|
||||
properties.AppendChild(pageSize);
|
||||
return properties;
|
||||
}
|
||||
// задание форматирования для абзаца
|
||||
private static ParagraphProperties? CreateParagraphProperties(WordTextProperties? paragraphProperties)
|
||||
{
|
||||
if (paragraphProperties == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
var properties = new ParagraphProperties();
|
||||
properties.AppendChild(new Justification()
|
||||
{
|
||||
Val =
|
||||
GetJustificationValues(paragraphProperties.JustificationType)
|
||||
});
|
||||
properties.AppendChild(new SpacingBetweenLines
|
||||
{
|
||||
LineRule = LineSpacingRuleValues.Auto
|
||||
});
|
||||
properties.AppendChild(new Indentation());
|
||||
var paragraphMarkRunProperties = new ParagraphMarkRunProperties();
|
||||
if (!string.IsNullOrEmpty(paragraphProperties.Size))
|
||||
{
|
||||
paragraphMarkRunProperties.AppendChild(new FontSize
|
||||
{
|
||||
Val =
|
||||
paragraphProperties.Size
|
||||
});
|
||||
}
|
||||
properties.AppendChild(paragraphMarkRunProperties);
|
||||
return properties;
|
||||
}
|
||||
protected override void CreateWord(WordInfoAdministrator info)
|
||||
{
|
||||
_wordDocument = WordprocessingDocument.Create(info.FileName,
|
||||
WordprocessingDocumentType.Document);
|
||||
MainDocumentPart mainPart = _wordDocument.AddMainDocumentPart();
|
||||
mainPart.Document = new Document();
|
||||
_docBody = mainPart.Document.AppendChild(new Body());
|
||||
}
|
||||
protected override void CreateParagraph(WordParagraph paragraph)
|
||||
{
|
||||
if (_docBody == null || paragraph == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
var docParagraph = new Paragraph();
|
||||
|
||||
docParagraph.AppendChild(CreateParagraphProperties(paragraph.TextProperties));
|
||||
foreach (var run in paragraph.Texts)
|
||||
{
|
||||
var docRun = new Run();
|
||||
var properties = new RunProperties();
|
||||
properties.AppendChild(new FontSize { Val = run.Item2.Size });
|
||||
if (run.Item2.Bold)
|
||||
{
|
||||
properties.AppendChild(new Bold());
|
||||
}
|
||||
docRun.AppendChild(properties);
|
||||
docRun.AppendChild(new Text
|
||||
{
|
||||
Text = run.Item1,
|
||||
Space =
|
||||
SpaceProcessingModeValues.Preserve
|
||||
});
|
||||
docParagraph.AppendChild(docRun);
|
||||
}
|
||||
_docBody.AppendChild(docParagraph);
|
||||
}
|
||||
protected override void SaveWord(WordInfoAdministrator info)
|
||||
{
|
||||
if (_docBody == null || _wordDocument == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
_docBody.AppendChild(CreateSectionProperties());
|
||||
_wordDocument.MainDocumentPart!.Document.Save();
|
||||
_wordDocument.Dispose();
|
||||
}
|
||||
}
|
||||
}
|
18
Hotel/HotelContracts/BindingModels/MailConfigBindingModel.cs
Normal file
18
Hotel/HotelContracts/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 HotelContracts.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; }
|
||||
}
|
||||
}
|
@ -0,0 +1,15 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace HotelContracts.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;
|
||||
}
|
||||
}
|
@ -0,0 +1,14 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace HotelContracts.BindingModels
|
||||
{
|
||||
public class ReportMealPlanDinnerBindingModel
|
||||
{
|
||||
public string FileName { get; set; } = string.Empty;
|
||||
public List<int> Dinners { get; set; } = new();
|
||||
}
|
||||
}
|
@ -0,0 +1,17 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace HotelContracts.BindingModels
|
||||
{
|
||||
public class ReportRoomsConferenceBindingModel
|
||||
{
|
||||
public string FileName { get; set; } = string.Empty;
|
||||
public DateTime DateFrom { get; set; }
|
||||
public DateTime DateTo { get; set; }
|
||||
public int? AdministratorId { get; set; }
|
||||
public string? Email { get; set; }
|
||||
}
|
||||
}
|
@ -0,0 +1,19 @@
|
||||
using HotelContracts.BindingModels;
|
||||
using HotelContracts.ViewModels;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace HotelContracts.BusinessLogicsContracts
|
||||
{
|
||||
public interface IReportAdministratorLogic
|
||||
{
|
||||
List<ReportRoomsConferencesViewModel> GetRoomsConferences(ReportRoomsConferenceBindingModel model);
|
||||
List<ReportMealPlansDinnersViewModel> GetMealPlanDinners(ReportMealPlanDinnerBindingModel model);
|
||||
void SaveMealPlansToWordFile(ReportMealPlanDinnerBindingModel model);
|
||||
void SaveMealPlansToExcelFile(ReportMealPlanDinnerBindingModel model);
|
||||
void SaveDinnersToPdfFile(ReportRoomsConferenceBindingModel model);
|
||||
}
|
||||
}
|
@ -0,0 +1,13 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace HotelContracts.SearchModels
|
||||
{
|
||||
public class ListMealPlansSearchModel
|
||||
{
|
||||
public List<int>? dinnersIds { get; set; }
|
||||
}
|
||||
}
|
@ -0,0 +1,16 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace HotelContracts.SearchModels
|
||||
{
|
||||
public class ReportRoomsConferencesSearchModel
|
||||
{
|
||||
public List<int>? dinnersIds { get; set; }
|
||||
public int? AdministratorId { get; set; }
|
||||
public DateTime? DateFrom { get; set; }
|
||||
public DateTime? DateTo { get; set; }
|
||||
}
|
||||
}
|
@ -22,5 +22,7 @@ namespace HotelContracts.StoragesContracts
|
||||
DinnerViewModel? Update(DinnerBindingModel model);
|
||||
|
||||
DinnerViewModel? Delete(DinnerBindingModel model);
|
||||
}
|
||||
List<ReportRoomsConferencesViewModel> GetReportRoomsConferences(ReportRoomsConferencesSearchModel model);
|
||||
List<ReportMealPlansDinnersViewModel> GetReportDinnerMealPlansList(ListMealPlansSearchModel model);
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,14 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace HotelContracts.ViewModels
|
||||
{
|
||||
public class ReportMealPlansDinnersViewModel
|
||||
{
|
||||
public string DinnerName { get; set; } = string.Empty;
|
||||
public List<MealPlanViewModel> MealPlans { get; set; } = new();
|
||||
}
|
||||
}
|
@ -0,0 +1,15 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace HotelContracts.ViewModels
|
||||
{
|
||||
public class ReportRoomsConferencesViewModel
|
||||
{
|
||||
public string DinnerName { get; set; } = string.Empty;
|
||||
public List<RoomViewModel> Rooms { get; set; }
|
||||
public List<ConferenceViewModel> Conferences { get; set; }
|
||||
}
|
||||
}
|
@ -129,5 +129,50 @@ namespace HotelDataBaseImplement.Implements
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
public List<ReportRoomsConferencesViewModel> GetReportRoomsConferences(ReportRoomsConferencesSearchModel model)
|
||||
{
|
||||
using var context = new HotelDataBase();
|
||||
return context.Dinners.Where(dinner => dinner.AdministratorId == model.AdministratorId)
|
||||
.Select(x => new ReportRoomsConferencesViewModel()
|
||||
{
|
||||
DinnerName = x.DinnerName,
|
||||
Rooms = context.Rooms
|
||||
.Where(room => room.DateCreate <= model.DateTo &&
|
||||
room.DateCreate >= model.DateFrom && room.Dinners.Any(m => m.DinnerId == x.Id) && room.AdministratorId == model.AdministratorId)
|
||||
.Select(room => room.GetViewModel)
|
||||
.ToList(),
|
||||
Conferences = context.ConferenceBookings
|
||||
.Include(conferencebooking => conferencebooking.Conference)
|
||||
.Where(conferencebooking => conferencebooking.Conference != null && conferencebooking.Conference.StartDate <= model.DateTo &&
|
||||
conferencebooking.Conference.StartDate >= model.DateFrom && conferencebooking.Dinners.Any(m => m.DinnerId == x.Id) && conferencebooking.AdministratorId == model.AdministratorId)
|
||||
.Select(conferencebooking => conferencebooking.Conference.GetViewModel)
|
||||
.ToList(),
|
||||
})
|
||||
.ToList();
|
||||
}
|
||||
|
||||
public List<ReportMealPlansDinnersViewModel> GetReportDinnerMealPlansList(ListMealPlansSearchModel model)
|
||||
{
|
||||
if (model.dinnersIds == null)
|
||||
{
|
||||
return new();
|
||||
}
|
||||
using var context = new HotelDataBase();
|
||||
return context.Dinners
|
||||
.Where(dinner => model.dinnersIds.Contains(dinner.Id))
|
||||
.Select(dinner => new ReportMealPlansDinnersViewModel
|
||||
{
|
||||
DinnerName = dinner.DinnerName,
|
||||
MealPlans = context.MealPlans
|
||||
.Include(mealplan => mealplan.Rooms)
|
||||
.ThenInclude(room => room.Dinners)
|
||||
.Where(mealplan => mealplan.Rooms
|
||||
.SelectMany(room => room.Dinners)
|
||||
.Any(rd => rd.DinnerId == dinner.Id))
|
||||
.Select(mealplan => mealplan.GetViewModel)
|
||||
.ToList()
|
||||
})
|
||||
.ToList();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
113
Hotel/HotelRestApi/Controllers/ReportAdministratorController.cs
Normal file
113
Hotel/HotelRestApi/Controllers/ReportAdministratorController.cs
Normal file
@ -0,0 +1,113 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using HotelBusinessLogic.BusinessLogic;
|
||||
using HotelBusinessLogic.MailWorker;
|
||||
using HotelContracts.BindingModels;
|
||||
using HotelContracts.BusinessLogicsContracts;
|
||||
using HotelContracts.ViewModels;
|
||||
using HotelDataBaseImplement.Models;
|
||||
|
||||
namespace HotelRestApi.Controllers
|
||||
{
|
||||
[Route("api/[controller]/[action]")]
|
||||
[ApiController]
|
||||
public class ReportAdministratorController : Controller
|
||||
{
|
||||
private readonly IReportAdministratorLogic _reportAdministrator;
|
||||
private readonly AbstractMailWorker _mailWorker;
|
||||
public ReportAdministratorController(IReportAdministratorLogic reportAdministrator, AbstractMailWorker mailWorker)
|
||||
{
|
||||
_reportAdministrator = reportAdministrator;
|
||||
_mailWorker = mailWorker;
|
||||
}
|
||||
[Microsoft.AspNetCore.Mvc.HttpGet]
|
||||
public IActionResult Index(IReportAdministratorLogic reportAdministrator)
|
||||
{
|
||||
return View();
|
||||
}
|
||||
/*[HttpPost]
|
||||
public void CreatePurchaseListWordFile(ReportPurchaseMedicationBindingModel model)
|
||||
{
|
||||
try
|
||||
{
|
||||
_reportAdministrator.SavePurchasesToWordFile(model);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
throw;
|
||||
}
|
||||
}
|
||||
[HttpPost]
|
||||
public void CreatePurchaseListExcelFile(ReportPurchaseMedicationBindingModel model)
|
||||
{
|
||||
try
|
||||
{
|
||||
_reportAdministrator.SavePurchasesToExcelFile(model);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
throw;
|
||||
}
|
||||
}*/
|
||||
[HttpGet]
|
||||
public List<ReportRoomsConferencesViewModel> GetRoomsConferencesReport(string dateFrom, string dateTo, int administratorId)
|
||||
{
|
||||
try
|
||||
{
|
||||
DateTime DateFrom = DateTime.Parse(dateFrom);
|
||||
DateTime DateTo = DateTime.Parse(dateTo);
|
||||
ReportRoomsConferenceBindingModel model = new();
|
||||
model.DateFrom = DateFrom;
|
||||
model.DateTo = DateTo;
|
||||
model.AdministratorId = administratorId;
|
||||
return _reportAdministrator.GetRoomsConferences(model);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public void SendRoomsConferencesReportToEmail(ReportRoomsConferenceBindingModel model)
|
||||
{
|
||||
try
|
||||
{
|
||||
_reportAdministrator.SaveDinnersToPdfFile(model);
|
||||
_mailWorker.MailSendAsync(new MailSendInfoBindingModel
|
||||
{
|
||||
MailAddress = model.Email!,
|
||||
Subject = "Отчет по обедам",
|
||||
Text = "Курсовая работа"
|
||||
});
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
throw;
|
||||
}
|
||||
}
|
||||
[HttpPost]
|
||||
public void CreateMealPlanListWordFile(ReportMealPlanDinnerBindingModel model)
|
||||
{
|
||||
try
|
||||
{
|
||||
_reportAdministrator.SaveMealPlansToWordFile(model);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
throw;
|
||||
}
|
||||
}
|
||||
[HttpPost]
|
||||
public void CreateMealPlanListExcelFile(ReportMealPlanDinnerBindingModel model)
|
||||
{
|
||||
try
|
||||
{
|
||||
_reportAdministrator.SaveMealPlansToExcelFile(model);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
throw;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -1,4 +1,8 @@
|
||||
using HotelBusinessLogic.BusinessLogic;
|
||||
using HotelBusinessLogic.MailWorker;
|
||||
using HotelBusinessLogic.OfficePackage;
|
||||
using HotelBusinessLogic.OfficePackage.Implements;
|
||||
using HotelContracts.BindingModels;
|
||||
using HotelContracts.BusinessLogicsContracts;
|
||||
using HotelContracts.StoragesContracts;
|
||||
using HotelDataBaseImplement.Implements;
|
||||
@ -26,6 +30,13 @@ builder.Services.AddTransient<IAdministratorLogic, AdministratorLogic>();
|
||||
builder.Services.AddTransient<IDinnerLogic, DinnerLogic>();
|
||||
builder.Services.AddTransient<IRoomLogic, RoomLogic>();
|
||||
builder.Services.AddTransient<IConferenceBookingLogic, ConferenceBookingLogic>();
|
||||
builder.Services.AddSingleton<AbstractMailWorker, MailKitWorker>();
|
||||
builder.Services.AddTransient<AbstractSaveToPdfAdministrator, SaveToPdfAdministrator>();
|
||||
builder.Services.AddTransient<IReportAdministratorLogic, ReportLogicAdministrator>();
|
||||
builder.Services.AddTransient<AbstractSaveToExcelAdministrator, SaveToExcelAdministrator>();
|
||||
builder.Services.AddTransient<AbstractSaveToWordAdministrator, SaveToWordAdministrator>();
|
||||
builder.Services.AddTransient<AbstractSaveToExcelAdministrator, SaveToExcelAdministrator>();
|
||||
builder.Services.AddTransient<AbstractSaveToWordAdministrator, SaveToWordAdministrator>();
|
||||
|
||||
builder.Services.AddControllers();
|
||||
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
|
||||
@ -40,6 +51,24 @@ builder.Services.AddSwaggerGen(c =>
|
||||
});
|
||||
|
||||
var app = builder.Build();
|
||||
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,11 @@
|
||||
"Microsoft.AspNetCore": "Warning"
|
||||
}
|
||||
},
|
||||
"AllowedHosts": "*"
|
||||
"AllowedHosts": "*",
|
||||
"SmtpClientHost": "smtp.gmail.com",
|
||||
"SmtpClientPort": "587",
|
||||
"PopHost": "pop.gmail.com",
|
||||
"PopPort": "995",
|
||||
"MailLogin": "shanyginalexandr228@gmail.com",
|
||||
"MailPassword": "h h q w s l p h d q o h h j t g"
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user