From 210e8756b7a4ed76e3771618fe2d30ecfc61a34b Mon Sep 17 00:00:00 2001 From: abazov73 <92822431+abazov73@users.noreply.github.com> Date: Sat, 20 May 2023 04:35:49 +0400 Subject: [PATCH] =?UTF-8?q?=D0=92=D1=8B=D0=B1=D0=BE=D1=80=20=D0=B4=D0=BB?= =?UTF-8?q?=D1=8F=20=D0=BE=D1=82=D1=87=D1=91=D1=82=D0=B0,=20=D1=81=D0=B2?= =?UTF-8?q?=D0=BE=D0=B5=20=D0=BD=D0=B0=D0=B7=D0=B2=D0=B0=D0=BD=D0=B8=D0=B5?= =?UTF-8?q?=20=D1=84=D0=B0=D0=B9=D0=BB=D0=BE=D0=B2=20=D0=BE=D1=82=D1=87?= =?UTF-8?q?=D1=91=D1=82=D0=BE=D0=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../OperatorApp/Controllers/HomeController.cs | 75 ++++++++++--------- Bank/OperatorApp/Views/Home/CreateDeal.cshtml | 2 +- .../Views/Home/PaymentsReport.cshtml | 5 +- .../Views/Home/TransfersReport.cshtml | 20 +++-- 4 files changed, 57 insertions(+), 45 deletions(-) diff --git a/Bank/OperatorApp/Controllers/HomeController.cs b/Bank/OperatorApp/Controllers/HomeController.cs index 62137ba..eba9f65 100644 --- a/Bank/OperatorApp/Controllers/HomeController.cs +++ b/Bank/OperatorApp/Controllers/HomeController.cs @@ -266,8 +266,10 @@ namespace OperatorApp.Controllers } [HttpPost] - public IActionResult PaymentsReport(List payments, string doctype) + public IActionResult PaymentsReport(List payments, string doctype, string filename) { + if (string.IsNullOrEmpty(filename)) filename = "report"; + filename = filename.Replace(".", string.Empty); List paymentBindings = new List(); foreach (int paymentId in payments) { @@ -283,13 +285,15 @@ namespace OperatorApp.Controllers } if (doctype.Equals("word")) { - MemoryStream list = _reportLogic.SavePaymentPurchaseToWord(new ReportBindingModel { FileName = "test" }, paymentBindings); - return File(list, "application/vnd.openxmlformats-officedocument.wordprocessingml.document", "testDoc.docx"); + if (!filename.EndsWith(".docx")) filename += ".docx"; + MemoryStream list = _reportLogic.SavePaymentPurchaseToWord(new ReportBindingModel { FileName = filename }, paymentBindings); + return File(list, "application/vnd.openxmlformats-officedocument.wordprocessingml.document", filename); } else { - MemoryStream list = _reportLogic.SavePaymentPurchaseToExcel(new ReportBindingModel { FileName = "test" }, paymentBindings); - return File(list, "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", "testExcel.xlsx"); + if (!filename.EndsWith(".xlsx")) filename += ".xlsx"; + MemoryStream list = _reportLogic.SavePaymentPurchaseToExcel(new ReportBindingModel { FileName = filename }, paymentBindings); + return File(list, "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", filename); } } @@ -304,44 +308,41 @@ namespace OperatorApp.Controllers return View(new ReportBindingModel()); } [HttpPost] - public void TransfersReport(DateTime dateFrom, DateTime dateTo) - { - if (APIClient.Operator == null) - { - Response.WriteAsync($""); - return; - } - MemoryStream report = _reportLogic.SaveTransferPurchaseToPDF(new ReportBindingModel { DateFrom = dateFrom, DateTo = dateTo }); - try - { - _mailWorker.MailSendAsync(new MailSendInfoBindingModel - { - Subject = "Отчёт о закупках", - Text = "Для оператора " + APIClient.Operator.LastName + APIClient.Operator.FirstName, - MailAddress = "", - FileName = "test.pdf", - Attachment = report - }); - Response.WriteAsync($""); - Redirect("/"); - } - catch (Exception ex) - { - Response.WriteAsync($""); - Response.Redirect("/"); - } - } - - public IActionResult ViewReport(DateTime dateFrom, DateTime dateTo) + public IActionResult TransfersReport(DateTime dateFrom, DateTime dateTo, string reptype, string email, string fileName) { if (APIClient.Operator == null) { Response.WriteAsync($""); return Redirect("/Home/Enter"); } - ViewBag.DateFrom = dateFrom.ToShortDateString(); - ViewBag.DateTo = dateTo.ToShortDateString(); - return View(_reportLogic.GetTransferPurchase(new ReportBindingModel { DateFrom=dateFrom, DateTo = dateTo })); + if (reptype.Equals("onForm")) + { + ViewBag.DateFrom = dateFrom.ToShortDateString(); + ViewBag.DateTo = dateTo.ToShortDateString(); + return View("ViewReport", _reportLogic.GetTransferPurchase(new ReportBindingModel { DateFrom = dateFrom, DateTo = dateTo })); + } + MemoryStream report = _reportLogic.SaveTransferPurchaseToPDF(new ReportBindingModel { DateFrom = dateFrom, DateTo = dateTo }); + try + { + if (string.IsNullOrEmpty(fileName)) fileName = "report"; + fileName = fileName.Replace(".", string.Empty); + if (!fileName.EndsWith(".pdf")) fileName += ".pdf"; + _mailWorker.MailSendAsync(new MailSendInfoBindingModel + { + Subject = "Отчёт о закупках", + Text = "Для оператора " + APIClient.Operator.LastName + APIClient.Operator.FirstName, + MailAddress = email, + FileName = fileName, + Attachment = report + }); + Response.WriteAsync($""); + return Redirect("/"); + } + catch (Exception ex) + { + Response.WriteAsync($""); + return Redirect("/"); + } } } } \ No newline at end of file diff --git a/Bank/OperatorApp/Views/Home/CreateDeal.cshtml b/Bank/OperatorApp/Views/Home/CreateDeal.cshtml index 4547f68..ce03c1a 100644 --- a/Bank/OperatorApp/Views/Home/CreateDeal.cshtml +++ b/Bank/OperatorApp/Views/Home/CreateDeal.cshtml @@ -7,7 +7,7 @@
ID клиента:
-
+
diff --git a/Bank/OperatorApp/Views/Home/PaymentsReport.cshtml b/Bank/OperatorApp/Views/Home/PaymentsReport.cshtml index c4bc90a..305dd4c 100644 --- a/Bank/OperatorApp/Views/Home/PaymentsReport.cshtml +++ b/Bank/OperatorApp/Views/Home/PaymentsReport.cshtml @@ -14,12 +14,15 @@
Word
@Html.RadioButton("doctype", "word", true) -
Excel
@Html.RadioButton("doctype", "excel")
+
+
Имя файла (необязательно):
+
+
diff --git a/Bank/OperatorApp/Views/Home/TransfersReport.cshtml b/Bank/OperatorApp/Views/Home/TransfersReport.cshtml index db33f83..d33c0ea 100644 --- a/Bank/OperatorApp/Views/Home/TransfersReport.cshtml +++ b/Bank/OperatorApp/Views/Home/TransfersReport.cshtml @@ -7,7 +7,7 @@

Создание списка

- +
C:
@@ -21,13 +21,21 @@

Вывести на:

-
-
На почту (.pdf)
- @Html.RadioButton("reptype", "pdf", true) +
+
На форму
+ @Html.RadioButton("reptype", "onForm", true) +
+
+
На почту (.pdf)
+ @Html.RadioButton("reptype", "pdf")
-
На форму
- @Html.RadioButton("reptype", "onForm") +
email:
+
+
+
+
Имя файла (необязательно):
+