This commit is contained in:
AnnZhimol 2023-05-18 19:38:05 +04:00
commit 7b269fb7ec
20 changed files with 263 additions and 70 deletions

View File

@ -554,5 +554,73 @@ namespace HostrelHeadwaiterApp.Controllers
});
Response.Redirect("ListConferenceBookings");
}
/*--------------------Reports------------------------*/
[HttpGet]
public IActionResult ListDinnerRoomToFile()
{
if (APIClient.Headwaiter == null)
{
return Redirect("~/Home/Enter");
}
return View(APIClient.GetRequest<List<DinnerViewModel>>($"api/main/getdinnerlist?headwaiterId={APIClient.Headwaiter.Id}"));
}
[HttpPost]
public void ListDinnerRoomToFile(int[] Ids, string type)
{
if (APIClient.Headwaiter == null)
{
throw new Exception("Вы как суда попали? Суда вход только авторизованным");
}
if (Ids.Length <= 0)
{
throw new Exception("Количество должно быть больше 0");
}
if (string.IsNullOrEmpty(type))
{
throw new Exception("Неверный тип отчета");
}
List<int> res = new List<int>();
foreach (var item in Ids)
{
res.Add(item);
}
if (type == "docx")
{
APIClient.PostRequest("api/report/createheadwaiterreporttowordfile", new ReportHeadwaiterBindingModel
{
Ids = res,
FileName = "E:\\ReportsCourseWork\\wordfile.docx"
});
Response.Redirect("GetWordFile");
}
else
{
APIClient.PostRequest("api/report/createheadwaiterreporttoexcelfile", new ReportHeadwaiterBindingModel
{
Ids = res,
FileName = "E:\\ReportsCourseWork\\excelfile.xlsx"
});
Response.Redirect("GetExcelFile");
}
}
[HttpGet]
public IActionResult GetWordFile()
{
return new PhysicalFileResult("E:\\ReportsCourseWork\\wordfile.docx", "application/vnd.openxmlformats-officedocument.wordprocessingml.document");
}
public IActionResult GetExcelFile()
{
return new PhysicalFileResult("E:\\ReportsCourseWork\\excelfile.xlsx", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
}
}
}

View File

@ -8,10 +8,12 @@
<ItemGroup>
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
<PackageReference Include="PdfSharp.MigraDoc.Standard" Version="1.51.15" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\HotelContracts\HotelContracts.csproj" />
<ProjectReference Include="..\HotelDataModels\HotelDataModels.csproj" />
</ItemGroup>
</Project>

View File

@ -0,0 +1,73 @@
@using HotelContracts.ViewModels
@model List<DinnerViewModel>
@{
ViewData["Title"] = "ListDinnerRoomToFile";
}
<div class="text-center">
<div class="title">
<h2>Создание отчета по обедам</h2>
</div>
</div>
<div class="text-center">
<form method="post">
<div class="file-format">
<label class="form-label">Выберите формат файла:</label>
<div class="form-check">
<input class="form-check-input" type="radio" name="type" value="docx" id="docx">
<label class="form-check-label" for="docx">Word-файл</label>
</div>
<div class="form-check">
<input class="form-check-input" type="radio" name="type" value="xlsx" id="xlsx" checked>
<label class="form-check-label" for="xlsx">Excel-файл</label>
</div>
</div>
<div class="table">
<table class="table table-hover">
<thead class="thead-light">
<tr>
<th scope="col"></th>
<th scope="col">Обед</th>
<th scope="col">Цена</th>
</tr>
</thead>
<tbody>
@foreach (var item in Model)
{
<tr>
<td>
<div class="form-check">
<input class="form-check-input" type="checkbox" name="Ids[]" value="@item.Id" id="@item.Id">
</div>
</td>
<td>@Html.DisplayFor(modelItem => item.DinnerName)</td>
<td>@Html.DisplayFor(modelItem => item.DinnerPrice)</td>
</tr>
}
</tbody>
</table>
</div>
<br>
<div class="d-flex justify-content-center">
<button type="submit" class="btn btn-block btn-outline-dark w-100">Создать</button>
</div>
</form>
</div>
<style>
.title {
margin-top: 10px;
margin-bottom: 30px;
}
.file-format {
margin-bottom: 30px;
}
.table {
margin-bottom: 30px;
}
</style>

View File

@ -37,6 +37,8 @@
<a class="nav-link " asp-area="" asp-controller="Home" asp-action="Enter">Аутентификация </a>
<a class="nav-link " asp-area="" asp-controller="Home" asp-action="ListDinnerRoomToFile">Отчет (word/excel) </a>
</div>
</div>
</div>

View File

@ -8,6 +8,7 @@ using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
namespace HotelBusinessLogic.BusinessLogics
@ -140,6 +141,11 @@ namespace HotelBusinessLogic.BusinessLogics
throw new ArgumentNullException("Нет номера телефона метродотеля", nameof(model.HeadwaiterNumber));
}
if (model.HeadwaiterEmail.Length > _loginMaxLength || !Regex.IsMatch(model.HeadwaiterEmail, @"([a-zA-Z0-9]+@[a-zA-Z0-9]+\.[a-zA-Z0-9]+)"))
{
throw new Exception($"В качестве логина должна быть указана почта и иметь длинну не более {_loginMaxLength} символов");
}
if (string.IsNullOrEmpty(model.HeadwaiterEmail))
{
throw new ArgumentNullException("Нет почты метродотеля", nameof(model.HeadwaiterEmail));
@ -150,21 +156,17 @@ namespace HotelBusinessLogic.BusinessLogics
throw new ArgumentNullException("Нет пароля метродотеля", nameof(model.HeadwaiterPassword));
}
if (model.HeadwaiterPassword.Length < _passwordMinLength)
if (model.HeadwaiterPassword.Length > _passwordMaxLength || model.HeadwaiterPassword.Length < _passwordMinLength
|| !Regex.IsMatch(model.HeadwaiterPassword, @"^((\w+\d+\W+)|(\w+\W+\d+)|(\d+\w+\W+)|(\d+\W+\w+)|(\W+\w+\d+)|(\W+\d+\w+))[\w\d\W]*$"))
{
throw new ArgumentNullException("Пароль слишком короткий", nameof(model.HeadwaiterPassword));
}
if (model.HeadwaiterPassword.Length > _passwordMaxLength)
{
throw new ArgumentNullException("Пароль слишком длинный", nameof(model.HeadwaiterPassword));
throw new Exception($"Пароль длиной от {_passwordMinLength} до {_passwordMaxLength} должен состоять из цифр, букв и небуквенных символов");
}
_logger.LogInformation("Headwaiter. HeadwaiterFIO: {HeadwaiterFIO}. HeadwaiterLogin: {HeadwaiterLogin}. Id: {Id}", model.HeadwaiterFIO, model.HeadwaiterLogin, model.Id);
var element = _headwaiterStorage.GetElement(new HeadwaiterSearchModel
{
HeadwaiterLogin = model.HeadwaiterLogin
HeadwaiterEmail = model.HeadwaiterEmail
});
if (element != null && element.Id != model.Id)

View File

@ -17,45 +17,48 @@ namespace HotelBusinessLogic.BusinessLogics
{
private readonly IRoomStorage _roomStorage;
private readonly IDinnerStorage _dinnerStorage;
private readonly IMealPlanStorage _mealPlansStorage;
private readonly IConferenceBookingStorage _conferenceBookingStorage;
private readonly AbstractSaveToExcelHeadwaiter _saveToExcel;
private readonly AbstractSaveToWordHeadwaitre _saveToWord;
private readonly AbstractSaveToPdfHeadwaiter _saveToPdf;
public ReportLogicHeadwaiter(IRoomStorage roomStorage, IDinnerStorage dinnerStorage, IMealPlanStorage mealPlansStorage, IConferenceBookingStorage conferenceBookingStorage, AbstractSaveToExcelHeadwaiter saveToExcel, AbstractSaveToWordHeadwaitre saveToWord, AbstractSaveToPdfHeadwaiter saveToPdf)
public ReportLogicHeadwaiter(IRoomStorage roomStorage, IDinnerStorage dinnerStorage, IConferenceBookingStorage conferenceBookingStorage, AbstractSaveToExcelHeadwaiter saveToExcel, AbstractSaveToWordHeadwaitre saveToWord, AbstractSaveToPdfHeadwaiter saveToPdf)
{
_roomStorage = roomStorage;
_dinnerStorage = dinnerStorage;
_mealPlansStorage = mealPlansStorage;
_conferenceBookingStorage = conferenceBookingStorage;
_saveToExcel = saveToExcel;
_saveToWord = saveToWord;
_saveToPdf = saveToPdf;
}
public List<ReportMealPlanDinnerViewModel> GetMealPlanDinner()
public List<ReportDinnerRoomViewModel> GetDinnerRoom(List<int> Ids)
{
var mealPlans = _mealPlansStorage.GetFullList();
var dinners = _dinnerStorage.GetFullList();
if (Ids == null)
{
return new List<ReportDinnerRoomViewModel>();
}
var rooms = _roomStorage.GetFullList();
var list = new List<ReportMealPlanDinnerViewModel>();
List<DinnerViewModel> dinners = new List<DinnerViewModel>();
foreach (var memId in Ids)
{
var res = _dinnerStorage.GetElement(new DinnerSearchModel { Id = memId });
if (res != null)
{
dinners.Add(res);
}
}
var list = new List<ReportDinnerRoomViewModel>();
foreach (var dinner in dinners)
{
var record = new ReportMealPlanDinnerViewModel
var record = new ReportDinnerRoomViewModel
{
DinnerName = dinner.DinnerName,
MealPlans = new List<Tuple<string, double>>()
Rooms = new List<Tuple<string, double>>()
};
foreach (var room in rooms)
{
if (room.RoomDinners.ContainsKey(dinner.Id))
{
foreach (var mealPlan in mealPlans)
{
if (mealPlan.MealPlanRooms.ContainsKey(room.Id))
{
record.MealPlans.Add(new Tuple<string, double>(mealPlan.MealPlanName, mealPlan.MealPlanPrice));
}
}
record.Rooms.Add(new Tuple<string, double>(room.RoomName, room.RoomPrice));
}
}
list.Add(record);
@ -63,26 +66,34 @@ namespace HotelBusinessLogic.BusinessLogics
return list;
}
public List<ReportConferenceBindingRoomsViewModel> GetConferenceBindingRooms(ReportHeadwaiterBindingModel model)
public List<ReportDinnersViewModel> GetDinners(ReportHeadwaiterBindingModel model)
{
var listAll = new List<ReportConferenceBindingRoomsViewModel>();
var listAll = new List<ReportDinnersViewModel>();
var listConferenceBinding = _conferenceBookingStorage.GetFilteredList(new ConferenceBookingSearchModel
var listСonferences = _roomStorage.GetFilteredList(new RoomSearchModel
{
HeadwaiterId = model.HeadwaiterId,
DateFrom = model.DateFrom,
DateTo = model.DateTo
RoomName = model.RoomName,
});
var listRooms = _roomStorage.GetFilteredList(new RoomSearchModel());
foreach (var room in listRooms)
foreach (var room in listСonferences)
{
listAll.Add(new ReportConferenceBindingRoomsViewModel
foreach (var c in room.RoomDinners)
{
RoomName = room.RoomName,
RoomPrice = room.RoomPrice,
RoomFrame = room.RoomFrame
listAll.Add(new ReportDinnersViewModel
{
RoomName = room.RoomName,
DinnerName = c.Value.DinnerName
});
}
}
var listConferenceBookings = _conferenceBookingStorage.GetFilteredList(new ConferenceBookingSearchModel());
foreach (var conferenceBooking in listConferenceBookings)
{
listAll.Add(new ReportDinnersViewModel
{
NameHall = conferenceBooking.NameHall
});
}
@ -90,35 +101,33 @@ namespace HotelBusinessLogic.BusinessLogics
return listAll;
}
public void SaveMealPlanDinnerToExcelFile(ReportHeadwaiterBindingModel model)
public void SaveDinnerRoomToExcelFile(ReportHeadwaiterBindingModel model)
{
_saveToExcel.CreateReport(new ExcelInfoHeadwaiter
{
FileName = model.FileName,
Title = "Список участников",
MealPlanDinner = GetMealPlanDinner()
Title = "Список номеров",
DinnerRooms = GetDinnerRoom(model.Ids)
});
}
public void SaveMealPlanDinnerToWordFile(ReportHeadwaiterBindingModel model)
public void SaveDinnerRoomToWordFile(ReportHeadwaiterBindingModel model)
{
_saveToWord.CreateDoc(new WordInfoHeadwaiter
{
FileName = model.FileName,
Title = "Список участников",
MealPlanDinner = GetMealPlanDinner()
Title = "Список номеров",
DinnerRooms = GetDinnerRoom(model.Ids)
});
}
public void SaveConferenceBindingRoomsToPdfFile(ReportHeadwaiterBindingModel model)
public void SaveDinnersToPdfFile(ReportHeadwaiterBindingModel model)
{
_saveToPdf.CreateDoc(new PdfInfoHeadwaiter
{
FileName = model.FileName,
Title = "Список участников",
DateFrom = model.DateFrom!.Value,
DateTo = model.DateTo!.Value,
ConferenceBindingRooms = GetConferenceBindingRooms(model)
Title = "Список обедов",
Dinners = GetDinners(model)
});
}
}

View File

@ -30,7 +30,7 @@ namespace HotelBusinessLogic.OfficePackage
uint rowIndex = 2;
foreach (var mc in info.MealPlanDinner)
foreach (var mc in info.DinnerRooms)
{
InsertCellInWorksheet(new ExcelCellParameters
{
@ -42,7 +42,7 @@ namespace HotelBusinessLogic.OfficePackage
rowIndex++;
foreach (var mealPlan in mc.MealPlans)
foreach (var mealPlan in mc.Rooms)
{
InsertCellInWorksheet(new ExcelCellParameters
{

View File

@ -32,7 +32,7 @@ namespace HotelBusinessLogic.OfficePackage
Style = "NormalTitle",
ParagraphAlignment = PdfParagraphAlignmentType.Center
});
foreach (var conferenceBindingRooms in info.ConferenceBindingRooms)
foreach (var conferenceBindingRooms in info.Dinners)
{
CreateRow(new PdfRowParameters
{
@ -43,7 +43,7 @@ namespace HotelBusinessLogic.OfficePackage
}
CreateParagraph(new PdfParagraph
{
Text = $"Итого: {info.ConferenceBindingRooms.Sum(x => x.RoomPrice)}\t",
Text = $"Итого: {info.Dinners.Sum(x => x.RoomPrice)}\t",
Style = "Normal",
ParagraphAlignment = PdfParagraphAlignmentType.Rigth
});

View File

@ -24,12 +24,12 @@ namespace HotelBusinessLogic.OfficePackage
}
});
foreach (var mc in info.MealPlanDinner)
foreach (var mc in info.DinnerRooms)
{
CreateParagraph(new WordParagraph
{
Texts = new List<(string, WordTextProperties)>
{ (mc.DinnerName+" - ", new WordTextProperties { Size = "24", Bold=true})},
{ (mc.DinnerName, new WordTextProperties { Size = "24", Bold=true})},
TextProperties = new WordTextProperties
{
Size = "24",
@ -37,7 +37,7 @@ namespace HotelBusinessLogic.OfficePackage
}
});
foreach (var mealPlan in mc.MealPlans)
foreach (var mealPlan in mc.Rooms)
{
CreateParagraph(new WordParagraph
{

View File

@ -11,7 +11,7 @@ namespace HotelBusinessLogic.OfficePackage.HelperModels
{
public string FileName { get; set; } = string.Empty;
public string Title { get; set; } = string.Empty;
public List<ReportMealPlanDinnerViewModel> MealPlanDinner
public List<ReportDinnerRoomViewModel> DinnerRooms
{
get;
set;

View File

@ -13,6 +13,6 @@ namespace HotelBusinessLogic.OfficePackage.HelperModels
public string Title { get; set; } = string.Empty;
public DateTime DateFrom { get; set; }
public DateTime DateTo { get; set; }
public List<ReportConferenceBindingRoomsViewModel> ConferenceBindingRooms { get; set; } = new();
public List<ReportDinnersViewModel> Dinners { get; set; } = new();
}
}

View File

@ -11,6 +11,6 @@ namespace HotelBusinessLogic.OfficePackage.HelperModels
{
public string FileName { get; set; } = string.Empty;
public string Title { get; set; } = string.Empty;
public List<ReportMealPlanDinnerViewModel> MealPlanDinner { get; set; } = new();
public List<ReportDinnerRoomViewModel> DinnerRooms { get; set; } = new();
}
}

View File

@ -11,7 +11,7 @@ using System.Threading.Tasks;
namespace HotelBusinessLogic.OfficePackage.Implements
{
internal class SaveToPdfHeadwaiter : AbstractSaveToPdfHeadwaiter
public class SaveToPdfHeadwaiter : AbstractSaveToPdfHeadwaiter
{
private Document? _document;
private Section? _section;

View File

@ -9,8 +9,8 @@ namespace HotelContracts.BindingModels
public class ReportHeadwaiterBindingModel
{
public string FileName { get; set; } = string.Empty;
public DateTime? DateFrom { get; set; }
public DateTime? DateTo { get; set; }
public string RoomName { get; set; } = string.Empty;
public List<int>? Ids { get; set; }
public int HeadwaiterId { get; set; }
}
}

View File

@ -10,10 +10,10 @@ namespace HotelContracts.BusinessLogicsContracts
{
public interface IReportHeadwaiterLogic
{
List<ReportMealPlanDinnerViewModel> GetMealPlanDinner();
List<ReportConferenceBindingRoomsViewModel> GetConferenceBindingRooms(ReportHeadwaiterBindingModel model);
void SaveMealPlanDinnerToWordFile(ReportHeadwaiterBindingModel model);
void SaveMealPlanDinnerToExcelFile(ReportHeadwaiterBindingModel model);
void SaveConferenceBindingRoomsToPdfFile(ReportHeadwaiterBindingModel model);
List<ReportDinnerRoomViewModel> GetDinnerRoom(List<int> Ids);
List<ReportDinnersViewModel> GetDinners(ReportHeadwaiterBindingModel model);
void SaveDinnerRoomToWordFile(ReportHeadwaiterBindingModel model);
void SaveDinnerRoomToExcelFile(ReportHeadwaiterBindingModel model);
void SaveDinnersToPdfFile(ReportHeadwaiterBindingModel model);
}
}

View File

@ -6,10 +6,10 @@ using System.Threading.Tasks;
namespace HotelContracts.ViewModels
{
public class ReportMealPlanDinnerViewModel
public class ReportDinnerRoomViewModel
{
public string DinnerName { get; set; } = string.Empty;
public List<Tuple<string, double>> MealPlans { get; set; } = new();
public List<Tuple<string, double>> Rooms { get; set; } = new();
}
}

View File

@ -6,10 +6,12 @@ using System.Threading.Tasks;
namespace HotelContracts.ViewModels
{
public class ReportConferenceBindingRoomsViewModel
public class ReportDinnersViewModel
{
public int Id { get; set; }
public string RoomName { get; set; } = string.Empty;
public string NameHall { get; set; } = string.Empty;
public string DinnerName { get; set; } = string.Empty;
public double RoomPrice { get; set; }
public string RoomFrame { get; set; } = string.Empty;

View File

@ -9,7 +9,7 @@ namespace HotelDataBaseImplement
{
if (optionsBuilder.IsConfigured == false)
{
optionsBuilder.UseSqlServer(@"Data Source=DESKTOP-VG5USAH\SQLEXPRESS;Initial Catalog=HotelDataBaseFull;Integrated Security=True;MultipleActiveResultSets=True;;TrustServerCertificate=True");
optionsBuilder.UseSqlServer(@"Data Source=DESKTOP-V0ON61E\SQLEXPRESS;Initial Catalog=HotelDataBaseFu;Integrated Security=True;MultipleActiveResultSets=True;;TrustServerCertificate=True");
}
base.OnConfiguring(optionsBuilder);
}

View File

@ -11,10 +11,12 @@ namespace HotelRestApi.Controllers
{
private readonly ILogger _logger;
private readonly IReportOrganiserLogic _reportOrganiserLogic;
public ReportController(ILogger<ReportController> logger, IReportOrganiserLogic reportOrganiserLogic)
private readonly IReportHeadwaiterLogic _reportHeadwaiterLogic;
public ReportController(ILogger<ReportController> logger, IReportOrganiserLogic reportOrganiserLogic, IReportHeadwaiterLogic reportHeadwaiterLogic)
{
_logger = logger;
_reportOrganiserLogic = reportOrganiserLogic;
_reportHeadwaiterLogic = reportHeadwaiterLogic;
}
[HttpPost]
@ -64,5 +66,33 @@ namespace HotelRestApi.Controllers
throw;
}
}
[HttpPost]
public void CreateHeadwaiterReportToWordFile(ReportHeadwaiterBindingModel model)
{
try
{
_reportHeadwaiterLogic.SaveDinnerRoomToWordFile(model);
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка создания отчета");
throw;
}
}
[HttpPost]
public void CreateHeadwaiterReportToExcelFile(ReportHeadwaiterBindingModel model)
{
try
{
_reportHeadwaiterLogic.SaveDinnerRoomToExcelFile(model);
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка создания отчета");
throw;
}
}
}
}

View File

@ -24,11 +24,16 @@ builder.Services.AddTransient<IMealPlanLogic, MealPlanLogic>();
builder.Services.AddTransient<IMemberLogic, MemberLogic>();
builder.Services.AddTransient<IConferenceLogic, ConferenceLogic>();
builder.Services.AddTransient<IReportOrganiserLogic, ReportLogicOrganiser>();
builder.Services.AddTransient<IReportHeadwaiterLogic, ReportLogicHeadwaiter>();
builder.Services.AddTransient<AbstractSaveToExcelOrganiser, SaveToExcelOrganiser>();
builder.Services.AddTransient<AbstractSaveToWordOrganiser, SaveToWordOrganiser>();
builder.Services.AddTransient<AbstractSaveToPdfOrganiser, SaveToPdfOrganiser>();
builder.Services.AddTransient<AbstractSaveToExcelHeadwaiter, SaveToExcelHeadwaiter>();
builder.Services.AddTransient<AbstractSaveToWordHeadwaitre, SaveToWordHeadwaiter>();
builder.Services.AddTransient<AbstractSaveToPdfHeadwaiter, SaveToPdfHeadwaiter>();
builder.Services.AddTransient<IHeadwaiterStorage, HeadwaiterStorage>();
builder.Services.AddTransient<IDinnerStorage, DinnerStorage>();
builder.Services.AddTransient<IRoomStorage, RoomStorage>();