From 0c880443843428f483af8a1264b98cf4034e122a Mon Sep 17 00:00:00 2001 From: Zakharov_Rostislav Date: Mon, 27 May 2024 00:10:56 +0400 Subject: [PATCH] add excell report --- .../OfficePackage/AbstractSaveToExcel.cs | 84 +++++++++++++------ .../OfficePackage/AbstractSaveToWord.cs | 4 +- .../Controllers/HomeController.cs | 2 +- .../Controllers/ReportController.cs | 17 +++- 4 files changed, 74 insertions(+), 33 deletions(-) diff --git a/Bank/BankBusinessLogic/OfficePackage/AbstractSaveToExcel.cs b/Bank/BankBusinessLogic/OfficePackage/AbstractSaveToExcel.cs index 6726751..ed0a3b9 100644 --- a/Bank/BankBusinessLogic/OfficePackage/AbstractSaveToExcel.cs +++ b/Bank/BankBusinessLogic/OfficePackage/AbstractSaveToExcel.cs @@ -24,54 +24,86 @@ namespace BankBusinessLogic.OfficePackage MergeCells(new ExcelMergeParameters { CellFromName = "A1", - CellToName = "C1" + CellToName = "E1" }); - uint rowIndex = 2; - foreach (var transfer in info.Transfers) + InsertCellInWorksheet(new ExcelCellParameters + { + ColumnName = "A", + RowIndex = 2, + Text = "Номер счёта", + StyleInfo = ExcelStyleInfoType.Title + }); + InsertCellInWorksheet(new ExcelCellParameters + { + ColumnName = "B", + RowIndex = 2, + Text = "Номер заявки", + StyleInfo = ExcelStyleInfoType.Title + }); + InsertCellInWorksheet(new ExcelCellParameters + { + ColumnName = "C", + RowIndex = 2, + Text = "Статус заявки", + StyleInfo = ExcelStyleInfoType.Title + }); + InsertCellInWorksheet(new ExcelCellParameters + { + ColumnName = "D", + RowIndex = 2, + Text = "Сумма заявки", + StyleInfo = ExcelStyleInfoType.Title + }); + InsertCellInWorksheet(new ExcelCellParameters + { + ColumnName = "E", + RowIndex = 2, + Text = "Дата заявки", + StyleInfo = ExcelStyleInfoType.Title + }); + uint rowIndex = 3; + foreach (var report in info.Requests) { InsertCellInWorksheet(new ExcelCellParameters { ColumnName = "A", RowIndex = rowIndex, - Text = "", + Text = report.AccountNumber, StyleInfo = ExcelStyleInfoType.Text }); rowIndex++; - foreach (var component in transfer.Transfers) + foreach (var request in report.Requests) { InsertCellInWorksheet(new ExcelCellParameters { ColumnName = "B", RowIndex = rowIndex, - Text = "", - StyleInfo = - ExcelStyleInfoType.TextWithBroder + Text = request.Id.ToString(), + StyleInfo = ExcelStyleInfoType.TextWithBroder }); InsertCellInWorksheet(new ExcelCellParameters { ColumnName = "C", RowIndex = rowIndex, - Text = "", - StyleInfo = - ExcelStyleInfoType.TextWithBroder + Text = request.Status.ToString(), + StyleInfo = ExcelStyleInfoType.TextWithBroder + }); + InsertCellInWorksheet(new ExcelCellParameters + { + ColumnName = "D", + RowIndex = rowIndex, + Text = request.Sum.ToString(), + StyleInfo = ExcelStyleInfoType.TextWithBroder + }); + InsertCellInWorksheet(new ExcelCellParameters + { + ColumnName = "E", + RowIndex = rowIndex, + Text = request.RequestTime.ToString(), + StyleInfo = ExcelStyleInfoType.TextWithBroder }); rowIndex++; } - InsertCellInWorksheet(new ExcelCellParameters - { - ColumnName = "A", - RowIndex = rowIndex, - Text = "Итого", - StyleInfo = ExcelStyleInfoType.Text - }); - InsertCellInWorksheet(new ExcelCellParameters - { - ColumnName = "C", - RowIndex = rowIndex, - Text = "", - StyleInfo = ExcelStyleInfoType.Text - }); - rowIndex++; } SaveExcel(info); } diff --git a/Bank/BankBusinessLogic/OfficePackage/AbstractSaveToWord.cs b/Bank/BankBusinessLogic/OfficePackage/AbstractSaveToWord.cs index bc7ab60..87a6a33 100644 --- a/Bank/BankBusinessLogic/OfficePackage/AbstractSaveToWord.cs +++ b/Bank/BankBusinessLogic/OfficePackage/AbstractSaveToWord.cs @@ -44,10 +44,10 @@ namespace BankBusinessLogic.OfficePackage var wordTable = new WordTable { Headers = new List { - "Номер карты", + "Номер счёта", "Номер заявки", "Статус заявки", - "Сумма выдачи", + "Сумма заявки", "Дата заявки"}, Columns = 5, RowText = table diff --git a/Bank/BankManagersClientApp/Controllers/HomeController.cs b/Bank/BankManagersClientApp/Controllers/HomeController.cs index 9e627f3..b0fea54 100644 --- a/Bank/BankManagersClientApp/Controllers/HomeController.cs +++ b/Bank/BankManagersClientApp/Controllers/HomeController.cs @@ -494,7 +494,7 @@ namespace BankManagersClientApp.Controllers APIClient.PostRequest("/api/report/saverequeststoexcel", new ReportBindingModel { SelectedAccountIds = accounts, - FileName = "C:\\Users\\user\\Downloads\\RequestList.docx", + FileName = "C:\\Users\\user\\Downloads\\RequestList.xlsx", }); break; default: diff --git a/Bank/BankRestApi/Controllers/ReportController.cs b/Bank/BankRestApi/Controllers/ReportController.cs index 495a3e4..d2000a8 100644 --- a/Bank/BankRestApi/Controllers/ReportController.cs +++ b/Bank/BankRestApi/Controllers/ReportController.cs @@ -26,15 +26,24 @@ namespace BankRestApi.Controllers } catch (Exception ex) { - _logger.LogError(ex, "Ошибка сохранения переводов в ворд"); + _logger.LogError(ex, "Ошибка сохранения переводов в Word"); throw; } } [HttpPost] - public void SaveRequestsToExcel(ReportBindingModel? model) - { + public void SaveRequestsToExcel(ReportBindingModel model) + { + try + { + _logic.SaveRequestsToExcelFile(model); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка сохранения переводов в Excel"); + throw; + } - } + } [HttpPost] public void SaveTransfersToWord(ReportBindingModel model) {