client is done

This commit is contained in:
Илья Федотов 2024-08-08 16:12:26 +04:00
parent e3fda489a5
commit e9041926ab
8 changed files with 41 additions and 53 deletions

View File

@ -116,12 +116,7 @@ namespace ElectronicsShopBusinessLogic.BusinessLogic
} }
// Получение списка товаров с указанием, в какие оплаты товар входит // Получение списка товаров с указанием, в какие оплаты товар входит
public List<ReportPaymeantProductsViewModel> GetPaymeantProducts(ReportBindingModel model) { public List<ReportPaymeantProductsViewModel> GetPaymeantProducts(List<PaymeantViewModel> paymeants) {
var paymeants = _paymeantstorage.GetFillteredList(new PaymeantSearchModel {
ClientID = model.ClientID,
DateFrom = model.DateFrom,
DateTo = model.DateTo,
});
var list = new List<ReportPaymeantProductsViewModel>(); var list = new List<ReportPaymeantProductsViewModel>();
@ -150,14 +145,12 @@ namespace ElectronicsShopBusinessLogic.BusinessLogic
return list; return list;
} }
public byte[]? SavePaymeantToExcelFile(ReportBindingModel model) public byte[]? SavePaymeantToExcelFile(List<PaymeantViewModel> paymeants)
{ {
var document = _saveToExcel.CreateReport(new ExcelInfoClient var document = _saveToExcel.CreateReport(new ExcelInfoClient
{ {
Title = "Список оплат и товаров", Title = "Список оплат и товаров",
PaymeantProducts = GetPaymeantProducts(model), PaymeantProducts = GetPaymeantProducts(paymeants),
DateFrom = model.DateFrom,
DateTo = model.DateTo
}); });
return document; return document;
} }

View File

@ -22,26 +22,20 @@ namespace ElectronicsShopBusinessLogic.OfficePackage
CellToName = "C1" CellToName = "C1"
}); });
InsertCellInWorksheet(new ExcelCellParameters { uint rowIndex = 2;
ColumnName = "A",
RowIndex = 2,
Text = $"С {info.DateFrom.ToShortDateString()} по {info.DateTo.ToShortDateString()}",
StyleInfo = ExcelStyleInfoType.Title
});
MergeCells(new ExcelMergeParameters {
CellFromName = "A2",
CellToName = "F2"
});
uint rowIndex = 3;
foreach (var pp in info.PaymeantProducts) { foreach (var pp in info.PaymeantProducts) {
InsertCellInWorksheet(new ExcelCellParameters { InsertCellInWorksheet(new ExcelCellParameters {
ColumnName = "A", ColumnName = "A",
RowIndex = rowIndex, RowIndex = rowIndex,
Text = pp.PaymeantID.ToString(), Text = $"Номер оплаты: {pp.PaymeantID}",
StyleInfo = ExcelStyleInfoType.Text StyleInfo = ExcelStyleInfoType.Text
}); });
MergeCells(new ExcelMergeParameters {
CellFromName = $"A{rowIndex}",
CellToName = $"B{rowIndex}"
});
rowIndex++; rowIndex++;
foreach (var (Product, Count, CostItem, Price) in pp.Products) { foreach (var (Product, Count, CostItem, Price) in pp.Products) {
InsertCellInWorksheet(new ExcelCellParameters { InsertCellInWorksheet(new ExcelCellParameters {

View File

@ -24,14 +24,6 @@ namespace ElectronicsShopBusinessLogic.OfficePackage
} }
}); });
CreateParagraph(new WordParagraph {
Texts = new List<(string, WordTextProperties)> { ($"С {info.DateFrom.ToShortDateString()} по {info.DateTo.ToShortDateString()}",
new WordTextProperties { Bold = true, Size = "24", }) },
TextProperties = new WordTextProperties {
Size = "24",
JustificationType = WordJustificationType.Both
}
});
List<int> PaymentsID = new List<int>(); List<int> PaymentsID = new List<int>();
foreach (var pr in info.Products) foreach (var pr in info.Products)
{ {

View File

@ -13,7 +13,7 @@ namespace ElectronicsShopContracts.BusinessLogicContracts
public interface IReportClientLogic public interface IReportClientLogic
{ {
// получение списка товаров с указанием, в какие оплаты товар входит // получение списка товаров с указанием, в какие оплаты товар входит
List<ReportPaymeantProductsViewModel>? GetPaymeantProducts(ReportBindingModel model); List<ReportPaymeantProductsViewModel>? GetPaymeantProducts(List<PaymeantViewModel> paymeants);
// получения списка оплат // получения списка оплат
List<ReportPaymeantsViewModel>? GetPaymeants(ReportBindingModel model); List<ReportPaymeantsViewModel>? GetPaymeants(ReportBindingModel model);
@ -21,7 +21,7 @@ namespace ElectronicsShopContracts.BusinessLogicContracts
byte[]? SavePaymeantToWordFile(List<PaymeantViewModel> paymeants); byte[]? SavePaymeantToWordFile(List<PaymeantViewModel> paymeants);
// Сохранение отчета оплат с товарами в .excel // Сохранение отчета оплат с товарами в .excel
byte[]? SavePaymeantToExcelFile(ReportBindingModel model); byte[]? SavePaymeantToExcelFile(List<PaymeantViewModel> paymeants);
// Отчет оплаченных товаров в .pdf // Отчет оплаченных товаров в .pdf
PdfDocument SaveProductToPdfFile(ReportBindingModel model); PdfDocument SaveProductToPdfFile(ReportBindingModel model);

View File

@ -187,13 +187,19 @@ namespace ElectronicsShopRestAPI.Controllers {
} }
[HttpGet] [HttpGet]
public byte[]? CreateXlsxReport (int _clientID, string DateFrom, string DateTo) { public byte[]? CreateXlsxReport (string _ids) {
try { try {
var document = _reportLogic.SavePaymeantToExcelFile (new ReportBindingModel { List<PaymeantViewModel> _paymeants = new();
ClientID = _clientID,
DateFrom = DateTime.Parse(DateFrom), foreach (char i in _ids) {
DateTo = DateTime.Parse(DateTo) if (int.TryParse(i.ToString(), out int id)) {
}); var paymeant = _payLogic.ReadElement(new PaymeantSearchModel { ID = id }) ?? throw new Exception("Ошибка получения данных");
_paymeants.Add(paymeant);
}
}
var document = _reportLogic.SavePaymeantToExcelFile(_paymeants);
return document; return document;
} }
catch (Exception ex) { catch (Exception ex) {

View File

@ -324,15 +324,18 @@ namespace ElectronicsShopUserApp.Controllers {
} }
} }
if (string.IsNullOrEmpty(ids)) {
throw new Exception("Íåò âûáðàííûõ îïëàò");
}
(List<PaymeantViewModel>, string) tuple = (paymeantsFix, ids); (List<PaymeantViewModel>, string) tuple = (paymeantsFix, ids);
return View(tuple); return View(tuple);
} }
[HttpGet] [HttpGet]
public IActionResult CreateExcelReport(string DateFrom, string DateTo) { public IActionResult CreateExcelReport(string ids) {
var fileMemStream = APIClient.GetRequset<byte[]>($"api/Client/CreateXlsxReport?_clientID={APIClient.Client?.ID}&DateFrom={DateFrom}&" + var fileMemStream = APIClient.GetRequset<byte[]>($"api/Client/CreateXlsxReport?_ids={ids}");
$"DateTo={DateTo}");
if (fileMemStream == null) { if (fileMemStream == null) {
throw new Exception("Îøèáêà ñîçäàíèÿ îò÷åòà"); throw new Exception("Îøèáêà ñîçäàíèÿ îò÷åòà");

View File

@ -12,7 +12,7 @@
</div> </div>
<div class="text-end"> <div class="text-end">
<a class="btn btn-primary btn-sm" asp-action="CreateWordReport" asp-route-ids ="@Model.Item2" style="background-color:#335a95;">Экспорт отчета в .docx</a> <a class="btn btn-primary btn-sm" asp-action="CreateWordReport" asp-route-ids ="@Model.Item2" style="background-color:#335a95;">Экспорт отчета в .docx</a>
<a class="btn btn-primary btn-sm" asp-action="CreateExcelReport" style="background-color:#04713A;">Экспорт отчета в .xlsx</a> <a class="btn btn-primary btn-sm" asp-action="CreateExcelReport" asp-route-ids="@Model.Item2" style="background-color:#04713A;">Экспорт отчета в .xlsx</a>
</div> </div>
</h1> </h1>
</div> </div>

View File

@ -10,9 +10,9 @@
</head> </head>
<body> <body>
<header> <header>
<nav class="navbar navbar-expand-sm navbar-toggleable-sm navbar-light bg-white border-bottom box-shadow mb-3"> <nav class="navbar navbar-expand-sm navbar-toggleable-sm navbar-light border-bottom box-shadow mb-3" style="background-color:#1e2126">
<div class="container-fluid"> <div class="container-fluid">
<a class="navbar-brand" asp-area="" asp-controller="Home" asp-action="Index">Магазин электроники (Клиент)</a> <a class="navbar-brand" asp-area="" asp-controller="Home" asp-action="Index" style="color:whitesmoke">Магазин электроники (Клиент)</a>
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target=".navbar-collapse" aria-controls="navbarSupportedContent" <button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target=".navbar-collapse" aria-controls="navbarSupportedContent"
aria-expanded="false" aria-label="Toggle navigation"> aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span> <span class="navbar-toggler-icon"></span>
@ -20,22 +20,22 @@
<div class="navbar-collapse collapse d-sm-inline-flex flex-sm-row-reverse"> <div class="navbar-collapse collapse d-sm-inline-flex flex-sm-row-reverse">
<ul class="navbar-nav flex-grow-1"> <ul class="navbar-nav flex-grow-1">
<li class="nav-item"> <li class="nav-item">
<a class="nav-link text-dark" asp-area="" asp-controller="Home" asp-action="Index">Заказы</a> <a class="nav-link" asp-area="" asp-controller="Home" asp-action="Index" style="color:whitesmoke">Заказы</a>
</li> </li>
<li class="nav-item"> <li class="nav-item">
<a class="nav-link text-dark" asp-area="" asp-controller="Home" asp-action="Privacy">Личные данные</a> <a class="nav-link" asp-area="" asp-controller="Home" asp-action="Privacy" style="color:whitesmoke">Личные данные</a>
</li> </li>
<li class="nav-item"> <li class="nav-item">
<a class="nav-link text-dark" asp-area="" asp-controller="Home" asp-action="Enter">Вход</a> <a class="nav-link" asp-area="" asp-controller="Home" asp-action="Enter" style="color:whitesmoke">Вход</a>
</li> </li>
<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" asp-area="" asp-controller="Home" asp-action="Register" style="color:whitesmoke">Регистрация</a>
</li> </li>
<li class="nav-item"> <li class="nav-item">
<a class="nav-link text-dark" asp-area="" asp-controller="Home" asp-action="Orders">Корзины</a> <a class="nav-link" asp-area="" asp-controller="Home" asp-action="Orders" style="color:whitesmoke">Корзины</a>
</li> </li>
<li class="nav-item"> <li class="nav-item">
<a class="nav-link text-dark" asp-area="" asp-controller="Home" asp-action="Report">Отчёты</a> <a class="nav-link" asp-area="" asp-controller="Home" asp-action="Report" style="color:whitesmoke">Отчёты</a>
</li> </li>
</ul> </ul>
</div> </div>