Рабочие отчеты в Word\Excel, остался pdf на почту

This commit is contained in:
Алексей Тихоненков 2024-08-27 16:30:25 +04:00
parent 436bb27344
commit d80e620e9a
8 changed files with 80 additions and 64 deletions

View File

@ -49,23 +49,23 @@ namespace DiningRoomBusinessLogic.BusinessLogic
});
}
public void SaveReportToWordFile(ReportBindingModel Model, List<ComponentSearchModel> selectedComponents)
public void SaveReportToWordFile(ReportBindingModel Model)
{
_saveToWord.CreateDoc(new WordInfo
{
FileName = Model.FileName,
Title = "Список изделий",
ProductComponents = GetReportComponentsWithOrders(selectedComponents)
ProductComponents = GetReportComponentsWithOrders(Model.selectedComponents)
});
}
public void SaveReportToExcelFile(ReportBindingModel Model, List<ComponentSearchModel> selectedComponents)
public void SaveReportToExcelFile(ReportBindingModel Model)
{
_saveToExcel.CreateReport(new ExcelInfo
{
FileName = Model.FileName,
Title = "Список изделий",
ProductComponents = GetReportComponentsWithOrders(selectedComponents)
ProductComponents = GetReportComponentsWithOrders(Model.selectedComponents)
});
}
}

View File

@ -32,14 +32,6 @@ namespace DiningRoomBusinessLogic.OfficePackage
StyleInfo = ExcelStyleInfoType.Title
});
InsertCellInWorksheet(new ExcelCellParameters
{
ColumnName = "C",
RowIndex = 1,
Text = "Количество блюд в заказе",
StyleInfo = ExcelStyleInfoType.Title
});
uint rowIndex = 2;
// Группируем компоненты по названию
@ -71,14 +63,6 @@ namespace DiningRoomBusinessLogic.OfficePackage
StyleInfo = ExcelStyleInfoType.TextWithBroder
});
InsertCellInWorksheet(new ExcelCellParameters
{
ColumnName = "C",
RowIndex = rowIndex,
Text = item.ProductCount.ToString(),
StyleInfo = ExcelStyleInfoType.TextWithBroder
});
rowIndex++;
}

View File

@ -46,8 +46,7 @@ namespace DiningRoomBusinessLogic.OfficePackage
CreateParagraph(new WordParagraph
{
Texts = new List<(string, WordTextProperties)> {
("Количество блюд в заказе - "+Convert.ToInt32(product.ProductCount).ToString() + " ", new WordTextProperties { Size = "24" }),
("Название заказа - "+product.OrderName, new WordTextProperties { Size = "24"})
("Присутствует в заказе - "+product.OrderName, new WordTextProperties { Size = "24"})
},
TextProperties = new WordTextProperties
{

View File

@ -1,4 +1,5 @@
using System;
using DiningRoomContracts.SearchModels;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
@ -11,5 +12,7 @@ namespace DiningRoomContracts.BindingModels
public string FileName { get; set; } = string.Empty;
public DateTime? DateFrom { get; set; }
public DateTime? DateTo { get; set; }
}
public List<ComponentSearchModel>? selectedComponents { get; set; }
}
}

View File

@ -16,9 +16,9 @@ namespace DiningRoomContracts.BusinessLogicContracts
/// </summary>
List<ReportComponentByDateViewModel> GetReportComponentsByCardDate(ReportBindingModel Report);
void SaveReportToWordFile(ReportBindingModel Model, List<ComponentSearchModel> selectedComponents);
void SaveReportToWordFile(ReportBindingModel Model);
void SaveReportToExcelFile(ReportBindingModel Model, List<ComponentSearchModel> selectedComponents);
void SaveReportToExcelFile(ReportBindingModel Model);
void SaveComponentsToPdfFile(ReportBindingModel model);
}
}

View File

@ -4,7 +4,7 @@
{
public int? Id { get; set; }
public int? UserId { get; set; }
public string ComponentName { get; set; }
public string? ComponentName { get; set; }
public DateTime DateComponentCreate { get; set; }
}
}

View File

@ -1,4 +1,5 @@
using DiningRoomContracts.BindingModels;
using DiningRoomBusinessLogic.MailWorker;
using DiningRoomContracts.BindingModels;
using DiningRoomContracts.BusinessLogicContracts;
using DiningRoomContracts.SearchModels;
using DiningRoomContracts.ViewModels;
@ -19,7 +20,9 @@ namespace DiningRoomRestApi.Controllers
private readonly IProductLogic _product;
private readonly IComponentLogic _component;
private readonly IDrinkLogic _drink;
public MainController(ILogger<MainController> logger, ICardLogic card, IOrderLogic order, IProductLogic product, IComponentLogic component, IDrinkLogic drink)
private readonly IReportLogic _report;
private readonly AbstractMailWorker _mailWorker;
public MainController(ILogger<MainController> logger, ICardLogic card, IOrderLogic order, IProductLogic product, IComponentLogic component, IDrinkLogic drink, IReportLogic report, AbstractMailWorker mailWorker)
{
_logger = logger;
_card = card;
@ -27,7 +30,9 @@ namespace DiningRoomRestApi.Controllers
_product = product;
_component = component;
_drink = drink;
}
_report = report;
_mailWorker = mailWorker;
}
[HttpGet]
public List<CardViewModel>? GetCardList(int Id)
{
@ -413,5 +418,29 @@ namespace DiningRoomRestApi.Controllers
throw;
}
}
[HttpPost]
public void CreateComponentsWordFile(ReportBindingModel model)
{
try
{
_report.SaveReportToWordFile(model);
}
catch (Exception ex)
{
throw;
}
}
[HttpPost]
public void CreateComponentsExcelFile(ReportBindingModel model)
{
try
{
_report.SaveReportToExcelFile(model);
}
catch (Exception ex)
{
throw;
}
}
}
}

View File

@ -397,43 +397,44 @@ namespace DiningRoomUserApp.Controllers
return View();
}
//[HttpPost]
//public void ComponentOrderReport(List<int> components, string type)
//{
// if (APIClient.User == null)
// {
// throw new Exception("Вы как суда попали? Суда вход только авторизованным");
// }
[HttpPost]
public void ComponentOrderReport(List<int> components, string type)
{
if (APIClient.User == null)
{
throw new Exception("Вы как суда попали? Суда вход только авторизованным");
}
// if (components.Count <= 0)
// {
// throw new Exception("Количество должно быть больше 0");
// }
if (components.Count <= 0)
{
throw new Exception("Количество должно быть больше 0");
}
// if (string.IsNullOrEmpty(type))
// {
// throw new Exception("Неверный тип отчета");
// }
if (string.IsNullOrEmpty(type))
{
throw new Exception("Неверный тип отчета");
}
List<ComponentSearchModel> selComp = components.Select(id => new ComponentSearchModel { Id = id }).ToList();
// if (type == "docx")
// {
// APIClient.PostRequest("api/reportadministrator/createmealplanlistwordfile", new ReportComponentsBindingModel
// {
// Dinners = dinners,
// FileName = "C:\\wordfile.docx"
// });
// Response.Redirect("GetWordFile");
// }
// else
// {
// APIClient.PostRequest("api/reportadministrator/createmealplanlistexcelfile", new ReportComponentsBindingModel
// {
// Dinners = dinners,
// FileName = "C:\\exelfile.xlsx"
// });
// Response.Redirect("GetExcelFile");
// }
//}
if (type == "docx")
{
APIClient.PostRequest("api/main/createcomponentswordfile", (new ReportBindingModel
{
FileName = "C:\\wordfile.docx",
selectedComponents = selComp
}));
Response.Redirect("GetWordFile");
}
else
{
APIClient.PostRequest("api/main/createcomponentsexcelfile", (new ReportBindingModel
{
FileName = "C:\\exelfile.xlsx",
selectedComponents = selComp
}));
Response.Redirect("GetExcelFile");
}
}
[HttpGet]
public IActionResult GetWordFile()