partially done reports

This commit is contained in:
Denis 2023-06-14 22:47:30 +04:00
parent 3e15c7b642
commit 8708d8b6d0
28 changed files with 435 additions and 80 deletions

View File

@ -6,6 +6,8 @@ using CanteenContracts.SearchModel;
using CanteenContracts.StoragesContracts; using CanteenContracts.StoragesContracts;
using CanteenContracts.View; using CanteenContracts.View;
using CanteenContracts.ViewModels; using CanteenContracts.ViewModels;
using DocumentFormat.OpenXml.Bibliography;
using System.Linq;
namespace CanteenBusinessLogic.BusinessLogics namespace CanteenBusinessLogic.BusinessLogics
{ {
@ -35,12 +37,11 @@ namespace CanteenBusinessLogic.BusinessLogics
{ {
var list = new List<ReportLunchesPCView>(); var list = new List<ReportLunchesPCView>();
// Получаем список обедов (сущность 1) за указанный период и для указанного посетителя
var lunches = lunchStorage.GetFilteredList(new LunchSearchModel var lunches = lunchStorage.GetFilteredList(new LunchSearchModel
{ {
DateFrom = (DateTime)model.DateAfter, DateFrom = (DateTime)model.DateAfter,
DateTo = model.DateBefore, DateTo = model.DateBefore,
VisitorId = model.VisitorId VisitorId = model.UserId
}); });
foreach (var lunch in lunches) foreach (var lunch in lunches)
@ -53,16 +54,13 @@ namespace CanteenBusinessLogic.BusinessLogics
Cooks = new List<CookViewModel>() Cooks = new List<CookViewModel>()
}; };
// Получаем связанные заказы (сущность 2) для текущего обеда
var orders = lunch.LunchOrders.Keys.ToList(); var orders = lunch.LunchOrders.Keys.ToList();
foreach (var orderId in orders) foreach (var orderId in orders)
{ {
// Получаем заказы (сущность 2) и добавляем их в список Orders
var order = orderStorage.GetElement(new OrderSearchModel { Id = orderId }); var order = orderStorage.GetElement(new OrderSearchModel { Id = orderId });
record.Orders.Add(order); record.Orders.Add(order);
} }
// Получаем связанных поваров (сущность 4) для текущих продуктов обеда
var lunchProducts = lunch.LunchProducts.Keys.ToList(); var lunchProducts = lunch.LunchProducts.Keys.ToList();
foreach (var productId in lunchProducts) foreach (var productId in lunchProducts)
{ {
@ -71,7 +69,6 @@ namespace CanteenBusinessLogic.BusinessLogics
foreach (var cookId in productCooks) foreach (var cookId in productCooks)
{ {
// Получаем поваров (сущность 4) и добавляем их в список Cooks
var cook = cookStorage.GetElement(new CookSearchModel { Id = cookId }); var cook = cookStorage.GetElement(new CookSearchModel { Id = cookId });
record.Cooks.Add(cook); record.Cooks.Add(cook);
} }
@ -95,24 +92,77 @@ namespace CanteenBusinessLogic.BusinessLogics
Lunches = GetLunchesPCView(model) Lunches = GetLunchesPCView(model)
}); });
} }
public List<CookViewModel> GetCooksByLanches(ReportBindingModel model) public List<ReportCookView> GetCooksByLanches(ReportBindingModel model)
{ {
var list = new List<CookViewModel>(); var list = new List<ReportCookView>();
var listCookIds = new List<int>();
foreach (var lunch in model.lunches) var lunches = lunchStorage.GetFilteredList(new LunchSearchModel
{ {
var lunchProducts = lunch.LunchProducts.Keys.ToList().Select(rec => productStorage.GetElement(new ProductSearchModel { Id = rec })); DateFrom = (DateTime)model.DateAfter,
foreach (var elem in lunchProducts) DateTo = model.DateBefore,
VisitorId = model.UserId
});
foreach (var lunch in lunches)
{ {
listCookIds.AddRange(elem.ProductCooks.Keys.ToList()); var record = new ReportCookView
{
Lunch = lunch,
Cooks = new List<CookViewModel>()
};
var lunchProducts = lunch.LunchProducts.Keys.ToList();
foreach (var productId in lunchProducts)
{
var product = productStorage.GetElement(new ProductSearchModel { Id = productId });
var productCooks = product.ProductCooks.Keys.ToList();
foreach (var cookId in productCooks)
{
if (record.Cooks.Where(cook => cook.Id == cookId).ToList().Count == 0)
{
var cook = cookStorage.GetElement(new CookSearchModel { Id = cookId });
record.Cooks.Add(cook);
} }
} }
list = listCookIds.Distinct().ToList().Select(rec => cookStorage.GetElement(new CookSearchModel { Id = rec })).ToList(); }
list.Add(record);
}
return list;
}
private List<ReportOrderView> GetOrdersByProducts(ReportBindingModel model)
{
var list = new List<ReportOrderView>();
var products = productStorage.GetFilteredList(new ProductSearchModel
{
ManagerId = model.UserId
});
foreach (var product in products)
{
var record = new ReportOrderView
{
Product = product,
Orders = new List<OrderViewModel>()
};
var productCook = product.ProductCooks.Keys.ToList();
foreach (var cookId in productCook)
{
var orders = orderStorage.GetOrderCooksList(new OrderSearchModel { CookId = cookId });
orders.ForEach(x =>
{
if (record.Orders.Find(y => y.Id == x.Id) == null) record.Orders.Add(x);
});
}
list.Add(record);
}
return list; return list;
} }
public void saveCooksToExcel(ReportBindingModel model) public void saveCooksToExcel(ReportBindingModel model)
{ {
saveToExcel.CreateReport(new ExcelInfo() saveToExcel.CreateCooksReport(new ExcelInfo()
{ {
FileName = model.FileName, FileName = model.FileName,
Title = "Список поваров:", Title = "Список поваров:",
@ -121,12 +171,30 @@ namespace CanteenBusinessLogic.BusinessLogics
} }
public void saveCooksToWord(ReportBindingModel model) public void saveCooksToWord(ReportBindingModel model)
{ {
saveToWord.CreateDoc(new WordInfo() saveToWord.CreateCooksDoc(new WordInfo()
{ {
FileName = model.FileName, FileName = model.FileName,
Title = "Список поваров", Title = "Список поваров",
Cooks = GetCooksByLanches(model) Cooks = GetCooksByLanches(model)
}); });
} }
public void saveOrdersToExcel(ReportBindingModel model)
{
saveToExcel.CreateOrdersReport(new ExcelInfo()
{
FileName = model.FileName,
Title = "Список заказов:",
Orders = GetOrdersByProducts(model)
});
}
public void saveOrdersToWord(ReportBindingModel model)
{
saveToWord.CreateOrdersDoc(new WordInfo()
{
FileName = model.FileName,
Title = "Список заказов",
Orders = GetOrdersByProducts(model)
});
}
} }
} }

View File

@ -5,12 +5,13 @@ using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using CanteenBusinessLogic.OfficePackage.HelperEnums; using CanteenBusinessLogic.OfficePackage.HelperEnums;
using CanteenBusinessLogic.OfficePackage.HelperModels; using CanteenBusinessLogic.OfficePackage.HelperModels;
using DocumentFormat.OpenXml.EMMA;
namespace CanteenBusinessLogic.OfficePackage namespace CanteenBusinessLogic.OfficePackage
{ {
public abstract class AbstractSaveToExcel public abstract class AbstractSaveToExcel
{ {
public void CreateReport(ExcelInfo info) public void CreateCooksReport(ExcelInfo info)
{ {
CreateExcel(info); CreateExcel(info);
InsertCellInWorksheet(new ExcelCellParameters InsertCellInWorksheet(new ExcelCellParameters
@ -26,13 +27,30 @@ namespace CanteenBusinessLogic.OfficePackage
CellToName = "C1" CellToName = "C1"
}); });
uint rowIndex = 2; uint rowIndex = 2;
foreach (var pc in info.Cooks)
foreach (var reportCookView in info.Cooks)
{ {
InsertCellInWorksheet(new ExcelCellParameters InsertCellInWorksheet(new ExcelCellParameters
{ {
ColumnName = "A", ColumnName = "A",
RowIndex = rowIndex, RowIndex = rowIndex,
Text = pc.FIO, Text = $"Обед: {reportCookView.Lunch.LunchName}, {reportCookView.Lunch.DateCreate}",
StyleInfo = ExcelStyleInfoType.TextWithBroder
});
MergeCells(new ExcelMergeParameters
{
CellFromName = "A" + rowIndex,
CellToName = "E" + rowIndex
});
rowIndex++;
foreach (var cook in reportCookView.Cooks)
{
InsertCellInWorksheet(new ExcelCellParameters
{
ColumnName = "A",
RowIndex = rowIndex,
Text = cook.FIO,
StyleInfo = ExcelStyleInfoType.TextWithBroder StyleInfo = ExcelStyleInfoType.TextWithBroder
}); });
InsertCellInWorksheet(new ExcelCellParameters InsertCellInWorksheet(new ExcelCellParameters
@ -56,6 +74,73 @@ namespace CanteenBusinessLogic.OfficePackage
}); });
rowIndex++; rowIndex++;
} }
}
SaveExcel(info);
}
public void CreateOrdersReport(ExcelInfo 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 orderView in info.Orders)
{
InsertCellInWorksheet(new ExcelCellParameters
{
ColumnName = "A",
RowIndex = rowIndex,
Text = $"Продукт: {orderView.Product.ProductName}, {orderView.Product.Price}",
StyleInfo = ExcelStyleInfoType.TextWithBroder
});
MergeCells(new ExcelMergeParameters
{
CellFromName = "A" + rowIndex,
CellToName = "E" + rowIndex
});
rowIndex++;
foreach (var order in orderView.Orders)
{
InsertCellInWorksheet(new ExcelCellParameters
{
ColumnName = "A",
RowIndex = rowIndex,
Text = $"Id: {order.Id}",
StyleInfo = ExcelStyleInfoType.TextWithBroder
});
InsertCellInWorksheet(new ExcelCellParameters
{
ColumnName = "B",
RowIndex = rowIndex,
Text = "",
StyleInfo = ExcelStyleInfoType.TextWithBroder
});
InsertCellInWorksheet(new ExcelCellParameters
{
ColumnName = "C",
RowIndex = rowIndex,
Text = "",
StyleInfo = ExcelStyleInfoType.TextWithBroder
});
MergeCells(new ExcelMergeParameters
{
CellFromName = "A" + rowIndex,
CellToName = "C" + rowIndex
});
rowIndex++;
}
}
SaveExcel(info); SaveExcel(info);
} }
protected abstract void CreateExcel(ExcelInfo info); protected abstract void CreateExcel(ExcelInfo info);

View File

@ -10,7 +10,7 @@ namespace CanteenBusinessLogic.OfficePackage
{ {
public abstract class AbstractSaveToWord public abstract class AbstractSaveToWord
{ {
public void CreateDoc(WordInfo info) public void CreateCooksDoc(WordInfo info)
{ {
CreateWord(info); CreateWord(info);
CreateParagraph(new WordParagraph CreateParagraph(new WordParagraph
@ -22,12 +22,46 @@ namespace CanteenBusinessLogic.OfficePackage
JustificationType = WordJustificationType.Center JustificationType = WordJustificationType.Center
} }
}); });
foreach (var component in info.Cooks)
foreach (var reportCookView in info.Cooks)
{ {
CreateParagraph(new WordParagraph CreateParagraph(new WordParagraph
{ {
Texts = new List<(string, WordTextProperties)> {("Повар: ", new WordTextProperties {Bold = true, Size = "24"}), Texts = new List<(string, WordTextProperties)>
(component.FIO, new WordTextProperties {Bold = false, Size = "24"})}, {
("Обед: ", new WordTextProperties { Bold = true, Size = "24" }),
(reportCookView.Lunch.LunchName, new WordTextProperties { Bold = false, Size = "24" }),
(" Дата создания: ", new WordTextProperties { Bold = true, Size = "24" }),
(reportCookView.Lunch.DateCreate.ToString(), new WordTextProperties { Bold = false, Size = "24" })
},
TextProperties = new WordTextProperties
{
Size = "24",
JustificationType = WordJustificationType.Both
}
});
CreateParagraph(new WordParagraph
{
Texts = new List<(string, WordTextProperties)>
{
("Повара: ", new WordTextProperties { Bold = true, Size = "24" })
},
TextProperties = new WordTextProperties
{
Size = "24",
JustificationType = WordJustificationType.Both
}
});
foreach (var cook in reportCookView.Cooks)
{
CreateParagraph(new WordParagraph
{
Texts = new List<(string, WordTextProperties)>
{
(cook.FIO, new WordTextProperties { Bold = false, Size = "24" })
},
TextProperties = new WordTextProperties TextProperties = new WordTextProperties
{ {
Size = "24", Size = "24",
@ -35,11 +69,18 @@ namespace CanteenBusinessLogic.OfficePackage
} }
}); });
} }
SaveWord(info);
} }
SaveWord(info);
}
protected abstract void CreateWord(WordInfo info); protected abstract void CreateWord(WordInfo info);
protected abstract void CreateParagraph(WordParagraph paragraph); protected abstract void CreateParagraph(WordParagraph paragraph);
protected abstract void SaveWord(WordInfo info); protected abstract void SaveWord(WordInfo info);
internal void CreateOrdersDoc(WordInfo wordInfo)
{
throw new NotImplementedException();
}
} }
} }

View File

@ -12,6 +12,7 @@ namespace CanteenBusinessLogic.OfficePackage.HelperModels
{ {
public string FileName { get; set; } public string FileName { get; set; }
public string Title { get; set; } public string Title { get; set; }
public List<CookViewModel> Cooks { get; set; } public List<ReportCookView> Cooks { get; set; }
public List<ReportOrderView> Orders { get; set; }
} }
} }

View File

@ -12,6 +12,7 @@ namespace CanteenBusinessLogic.OfficePackage.HelperModels
{ {
public string FileName { get; set; } public string FileName { get; set; }
public string Title { get; set; } public string Title { get; set; }
public List<CookViewModel> Cooks { get; set; } public List<ReportCookView> Cooks { get; set; }
public List<ReportOrderView> Orders { get; set; }
} }
} }

View File

@ -13,6 +13,7 @@ namespace CanteenContracts.BindingModels
public DateTime? DateAfter { get; set; } public DateTime? DateAfter { get; set; }
public DateTime? DateBefore { get; set; } public DateTime? DateBefore { get; set; }
public List<LunchViewModel>? lunches { get; set; } public List<LunchViewModel>? lunches { get; set; }
public int VisitorId { get; set; } public List<OrderViewModel>? orders { get; set; }
public int UserId { get; set; }
} }
} }

View File

@ -11,10 +11,12 @@ namespace CanteenContracts.BusinessLogicsContracts
{ {
public interface IReportLogic public interface IReportLogic
{ {
List<CookViewModel> GetCooksByLanches(ReportBindingModel model); public List<ReportCookView> GetCooksByLanches(ReportBindingModel model);
List<ReportLunchesPCView> GetLunchesPCView(ReportBindingModel model); List<ReportLunchesPCView> GetLunchesPCView(ReportBindingModel model);
void saveLunchesToPdfFile(ReportBindingModel model); void saveLunchesToPdfFile(ReportBindingModel model);
void saveCooksToWord(ReportBindingModel model); void saveCooksToWord(ReportBindingModel model);
void saveCooksToExcel(ReportBindingModel model); void saveCooksToExcel(ReportBindingModel model);
public void saveOrdersToExcel(ReportBindingModel model);
public void saveOrdersToWord(ReportBindingModel model);
} }
} }

View File

@ -11,5 +11,6 @@ namespace CanteenContracts.SearchModel
public int? Id { get; set; } public int? Id { get; set; }
public string? FIO { get; set; } public string? FIO { get; set; }
public int? ManagerId { get; set; } public int? ManagerId { get; set; }
public int? OrderId { get; set; }
} }
} }

View File

@ -10,6 +10,7 @@ namespace CanteenContracts.SearchModel
{ {
public int? Id { get; set; } public int? Id { get; set; }
public int? VisitorId { get; set; } public int? VisitorId { get; set; }
public int? CookId { get; set; }
} }
} }

View File

@ -16,7 +16,7 @@ namespace CanteenContracts.StoragesContracts
List<OrderViewModel> GetFullList(); List<OrderViewModel> GetFullList();
List<OrderViewModel> GetFilteredList(OrderSearchModel model); List<OrderViewModel> GetFilteredList(OrderSearchModel model);
OrderViewModel? GetElement(OrderSearchModel model); OrderViewModel? GetElement(OrderSearchModel model);
OrderCookViewModel? GetOrderCookElement(OrderCookSearchModel model); List<OrderViewModel>? GetOrderCooksList(OrderSearchModel model);
OrderViewModel? Insert(OrderBindingModel model); OrderViewModel? Insert(OrderBindingModel model);
OrderViewModel? Update(OrderBindingModel model); OrderViewModel? Update(OrderBindingModel model);
OrderViewModel? Delete(OrderBindingModel model); OrderViewModel? Delete(OrderBindingModel model);

View File

@ -0,0 +1,15 @@
using CanteenContracts.View;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace CanteenContracts.ViewModels
{
public class ReportCookView
{
public LunchViewModel Lunch { get; set; }
public List<CookViewModel> Cooks { get; set; }
}
}

View File

@ -0,0 +1,15 @@
using CanteenContracts.View;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace CanteenContracts.ViewModels
{
public class ReportOrderView
{
public List<OrderViewModel> Orders { get; set; }
public ProductViewModel Product { get; set; }
}
}

View File

@ -11,7 +11,7 @@ namespace CanteenDatabaseImplement
{ {
if (optionsBuilder.IsConfigured == false) if (optionsBuilder.IsConfigured == false)
{ {
optionsBuilder.UseSqlServer(@"Data Source=DESKTOP-A68O3K0;Initial Catalog=CanteenDataBase;Integrated Security=True;MultipleActiveResultSets=True;;TrustServerCertificate=True"); optionsBuilder.UseSqlServer(@"Data Source=DESKTOP-23CS6SP\SQLEXPRESS;Initial Catalog=CanteenDataBase;Integrated Security=True;MultipleActiveResultSets=True;;TrustServerCertificate=True");
} }
base.OnConfiguring(optionsBuilder); base.OnConfiguring(optionsBuilder);
} }

View File

@ -4,6 +4,7 @@ using CanteenContracts.StoragesContracts;
using CanteenContracts.View; using CanteenContracts.View;
using CanteenDatabaseImplement.Models; using CanteenDatabaseImplement.Models;
using CanteenDataModels.Models; using CanteenDataModels.Models;
using FluentNHibernate.Conventions;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
@ -25,16 +26,30 @@ namespace CanteenDatabaseImplement.Implements
using var context = new CanteenDatabase(); using var context = new CanteenDatabase();
return context.Cooks.FirstOrDefault(x => model.Id.HasValue && x.Id == model.Id)?.GetViewModel; return context.Cooks
.Include(x => x.Products)
.ThenInclude(x => x.Product)
.FirstOrDefault(x => model.Id.HasValue && x.Id == model.Id)?.GetViewModel;
} }
public List<CookViewModel> GetFilteredList(CookSearchModel model) public List<CookViewModel> GetFilteredList(CookSearchModel model)
{ {
if (!model.Id.HasValue && !model.OrderId.HasValue)
{
return new();
}
using var context = new CanteenDatabase(); using var context = new CanteenDatabase();
return context.Cooks return context.Cooks
.Include(x => x.Manager) .Include(x => x.Manager)
.Where(x => (model.Id.HasValue && x.Id == model.Id) || (model.ManagerId.HasValue && model.ManagerId == x.ManagerId)) .Include(x => x.Products)
.ThenInclude(x => x.Product)
.Include(x => x.Orders)
.ThenInclude(x => x.Order)
.Where(x =>
(model.Id.HasValue && x.Id == model.Id) ||
(model.ManagerId.HasValue && model.ManagerId == x.ManagerId) ||
(model.OrderId.HasValue && x.Orders.Find(x => x.CookId == model.OrderId) != null))
.Select(x => x.GetViewModel) .Select(x => x.GetViewModel)
.ToList(); .ToList();
} }

View File

@ -5,6 +5,7 @@ using CanteenContracts.StoragesContracts;
using CanteenContracts.View; using CanteenContracts.View;
using CanteenContracts.ViewModels; using CanteenContracts.ViewModels;
using CanteenDatabaseImplement.Models; using CanteenDatabaseImplement.Models;
using DocumentFormat.OpenXml.Office2019.Drawing.Model3D;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
@ -16,17 +17,17 @@ namespace CanteenDatabaseImplement.Implements
{ {
public class OrderStorage : IOrderStorage public class OrderStorage : IOrderStorage
{ {
public OrderCookViewModel? GetOrderCookElement(OrderCookSearchModel model) public List<OrderViewModel>? GetOrderCooksList(OrderSearchModel model)
{ {
if (!model.Id.HasValue && (!model.OrderId.HasValue || !model.CookId.HasValue)) if (!model.CookId.HasValue)
{ {
return null; return null;
} }
using var context = new CanteenDatabase(); using var context = new CanteenDatabase();
return context.OrderCook var orders = context.Orders.Include(x => x.Cooks).ThenInclude(x => x.Cook).Select(x => x.GetViewModel).ToList();
.FirstOrDefault(x => x.OrderId == model.OrderId && x.CookId == model.CookId)?.GetViewModel; return orders.Where(x => x.OrderCooks.ContainsKey((int)model.CookId)).ToList();
} }
public OrderViewModel? GetElement(OrderSearchModel model) public OrderViewModel? GetElement(OrderSearchModel model)
@ -61,7 +62,10 @@ namespace CanteenDatabaseImplement.Implements
.ThenInclude(x => x.Cook) .ThenInclude(x => x.Cook)
.Include(x => x.Tablewares) .Include(x => x.Tablewares)
.ThenInclude(x => x.Tableware) .ThenInclude(x => x.Tableware)
.Where(x => (model.Id.HasValue && x.Id == model.Id) || (model.VisitorId.HasValue && model.VisitorId == x.VisitorId)).Select(x => x.GetViewModel).ToList(); .Where(x =>
(model.Id.HasValue && x.Id == model.Id) ||
(model.VisitorId.HasValue && model.VisitorId == x.VisitorId))
.Select(x => x.GetViewModel).ToList();
} }
public List<OrderViewModel> GetFullList() public List<OrderViewModel> GetFullList()

View File

@ -52,11 +52,11 @@ namespace CanteenDatabaseImplement.Implements
} }
using var context = new CanteenDatabase(); using var context = new CanteenDatabase();
return context.Products return context.Products
.Include(x => x.Cooks) .Include(x => x.Cooks)
.ThenInclude(x => x.Cook) .ThenInclude(x => x.Cook)
.Where(x => ((model.Id.HasValue && x.Id == model.Id) || (model.ManagerId.HasValue && model.ManagerId == x.ManagerId))) .Where(x => (model.Id.HasValue && x.Id == model.Id) ||
(model.ManagerId.HasValue && model.ManagerId == x.ManagerId))
.Select(x => x.GetViewModel).ToList(); .Select(x => x.GetViewModel).ToList();
} }

View File

@ -58,7 +58,7 @@ namespace CanteenDatabaseImplement.Models
Id = Id, Id = Id,
ManagerId = ManagerId, ManagerId = ManagerId,
FIO = FIO, FIO = FIO,
Position = Position Position = Position,
}; };
} }
} }

View File

@ -474,5 +474,40 @@ namespace CanteenManagerApp.Controllers
ViewBag.Model = APIClient.GetRequest<List<GraphicViewModel>>($"api/main/GetGraphic"); ViewBag.Model = APIClient.GetRequest<List<GraphicViewModel>>($"api/main/GetGraphic");
return View(); return View();
} }
[HttpGet]
public IActionResult Report()
{
return View(new ReportBindingModel());
}
[HttpPost]
public void ReportPdf(ReportBindingModel model)
{
model.UserId = APIClient.Manager.Id;
APIClient.PostRequest("api/main/SaveLunchesToPDF", model);
Response.Redirect("Index");
}
[HttpPost]
public void ReportXsl(ReportBindingModel model)
{
model.UserId = APIClient.Manager.Id;
APIClient.PostRequest("api/main/SaveOrdersToXSL", model);
Response.Redirect("Index");
}
[HttpPost]
public void ReportWord(ReportBindingModel model)
{
model.UserId = APIClient.Manager.Id;
APIClient.PostRequest("api/main/SaveOrdersToWORD", model);
Response.Redirect("Index");
}
[HttpPost]
public void ReportEmail(ReportBindingModel model)
{
APIClient.PostRequest("api/main/SaveEMAIL", model);
Response.Redirect("Index");
}
} }
} }

View File

@ -0,0 +1,31 @@
@using CanteenContracts.BindingModels;
@model ReportBindingModel
@{
ViewBag.Title = "Report";
}
<h2>Generate Report</h2>
@using (Html.BeginForm("Report", "Home", FormMethod.Post))
{
<div>
@Html.LabelFor(m => m.FileName)
@Html.TextBoxFor(m => m.FileName)
</div>
<div>
@Html.LabelFor(m => m.DateAfter)
@Html.TextBoxFor(m => m.DateAfter, new { type = "date" })
</div>
<div>
@Html.LabelFor(m => m.DateBefore)
@Html.TextBoxFor(m => m.DateBefore, new { type = "date" })
</div>
<button type="submit" formaction="@Url.Action("ReportPdf", "Home")">Сохранить в pfd</button>
<button type="submit" formaction="@Url.Action("ReportEmail", "Home")">Отправить по почте</button>
<button type="submit" formaction="@Url.Action("ReportXsl", "Home")">Сохранить в excel</button>
<button type="submit" formaction="@Url.Action("ReportWord", "Home")">Сохранить в word</button>
}

View File

@ -34,6 +34,9 @@
<li class="nav-item"> <li class="nav-item">
<a class="nav-link text-dark" asp-area="" asp-controller="Home" asp-action="Register">Регистрация</a> <a class="nav-link text-dark" asp-area="" asp-controller="Home" asp-action="Register">Регистрация</a>
</li> </li>
<li class="nav-item">
<a class="nav-link text-dark" asp-area="" asp-controller="Home" asp-action="Report">Отчеты</a>
</li>
<li class="nav-item"> <li class="nav-item">
<a class="nav-link text-dark" asp-area="" asp-controller="Home" asp-action="Graphic">Графики</a> <a class="nav-link text-dark" asp-area="" asp-controller="Home" asp-action="Graphic">Графики</a>
</li> </li>

View File

@ -37,7 +37,7 @@ namespace CanteenRestApi.Controllers
} }
[HttpPost] [HttpPost]
public void SavePDF(ReportBindingModel model) public void SaveLunchesToPDF(ReportBindingModel model)
{ {
try try
{ {
@ -46,8 +46,8 @@ namespace CanteenRestApi.Controllers
DateAfter = model.DateAfter, DateAfter = model.DateAfter,
DateBefore = model.DateBefore, DateBefore = model.DateBefore,
FileName = model.FileName, FileName = model.FileName,
VisitorId = model.VisitorId, UserId = model.UserId,
lunches = _lunch.ReadList(new LunchSearchModel { VisitorId = model.VisitorId}), lunches = _lunch.ReadList(new LunchSearchModel { VisitorId = model.UserId}),
}); });
} }
catch (Exception ex) catch (Exception ex)
@ -58,7 +58,7 @@ namespace CanteenRestApi.Controllers
} }
[HttpPost] [HttpPost]
public IActionResult SaveXSL(ReportBindingModel model) public void SaveCooksToXSL(ReportBindingModel model)
{ {
try try
{ {
@ -70,12 +70,9 @@ namespace CanteenRestApi.Controllers
DateAfter = model.DateAfter, DateAfter = model.DateAfter,
DateBefore = model.DateBefore, DateBefore = model.DateBefore,
FileName = excelFilePath, FileName = excelFilePath,
VisitorId = model.VisitorId, UserId = model.UserId,
lunches = _lunch.ReadList(new LunchSearchModel { VisitorId = model.VisitorId }), lunches = _lunch.ReadList(new LunchSearchModel { VisitorId = model.UserId }),
}); });
byte[] fileBytes = System.IO.File.ReadAllBytes(excelFilePath);
return File(fileBytes, "application/octet-stream", excelFileName);
} }
catch (Exception ex) catch (Exception ex)
{ {
@ -85,7 +82,7 @@ namespace CanteenRestApi.Controllers
} }
[HttpPost] [HttpPost]
public void SaveWORD(ReportBindingModel model) public void SaveCooksToWORD(ReportBindingModel model)
{ {
try try
{ {
@ -94,8 +91,47 @@ namespace CanteenRestApi.Controllers
DateAfter = model.DateAfter, DateAfter = model.DateAfter,
DateBefore = model.DateBefore, DateBefore = model.DateBefore,
FileName = model.FileName, FileName = model.FileName,
VisitorId = model.VisitorId, UserId = model.UserId,
lunches = _lunch.ReadList(new LunchSearchModel { VisitorId = model.VisitorId }), lunches = _lunch.ReadList(new LunchSearchModel { VisitorId = model.UserId }),
});
}
catch (Exception ex)
{
_logger.LogError(ex, "Error during loading list of bouquets");
throw;
}
}
[HttpPost]
public void SaveOrdersToXSL(ReportBindingModel model)
{
try
{
_reportLogic.saveOrdersToExcel(new ReportBindingModel()
{
FileName = $"{model.FileName}.xlsx",
UserId = model.UserId,
orders = _order.ReadList(new OrderSearchModel { VisitorId = model.UserId }),
});
}
catch (Exception ex)
{
_logger.LogError(ex, "Error during loading list of bouquets");
throw;
}
}
[HttpPost]
public void SaveOrderToWORD(ReportBindingModel model)
{
try
{
_reportLogic.saveOrdersToWord(new ReportBindingModel()
{
FileName = $"{model.FileName}.docx",
UserId = model.UserId,
lunches = _lunch.ReadList(new LunchSearchModel { VisitorId = model.UserId }),
}); });
} }
catch (Exception ex) catch (Exception ex)

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -507,31 +507,31 @@ namespace CanteenVisitorApp.Controllers
[HttpPost] [HttpPost]
public void ReportPdf(ReportBindingModel model) public void ReportPdf(ReportBindingModel model)
{ {
model.VisitorId = APIClient.Visitor.Id; model.UserId = APIClient.Visitor.Id;
APIClient.PostRequest("api/main/SavePDF", model); APIClient.PostRequest("api/main/SaveLunchesToPDF", model);
Response.Redirect("Index"); Response.Redirect("Index");
} }
[HttpPost] [HttpPost]
public void ReportXsl(ReportBindingModel model) public void ReportXsl(ReportBindingModel model)
{ {
model.VisitorId = APIClient.Visitor.Id; model.UserId = APIClient.Visitor.Id;
APIClient.PostRequest("api/main/SaveXSL", model); APIClient.PostRequest("api/main/SaveCooksToXSL", model);
Response.Redirect("Index"); Response.Redirect("Index");
} }
[HttpPost] [HttpPost]
public void ReportWord(ReportBindingModel model) public void ReportWord(ReportBindingModel model)
{ {
model.VisitorId = APIClient.Visitor.Id; model.UserId = APIClient.Visitor.Id;
APIClient.PostRequest("api/main/SaveWORD", model); APIClient.PostRequest("api/main/SaveCooksToWORD", model);
Response.Redirect("Index"); Response.Redirect("Index");
} }
[HttpPost] [HttpPost]
public void ReportEmail(ReportBindingModel model) public void ReportEmail(ReportBindingModel model)
{ {
APIClient.PostRequest("api/main/SaveEMAIL", model); APIClient.PostRequest("api/main/SaveCooksToEMAIL", model);
Response.Redirect("Index"); Response.Redirect("Index");
} }
} }