Промежуточное сохранение.

This commit is contained in:
Programmist73 2023-05-18 21:57:14 +04:00
parent e535ffa3e1
commit e035f95f28
10 changed files with 199 additions and 12 deletions

View File

@ -0,0 +1,36 @@
using BankYouBankruptContracts.BusinessLogicsContracts;
using DocumentFormat.OpenXml.ExtendedProperties;
using Org.BouncyCastle.Asn1.Ocsp;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection.Metadata;
using System.Text;
using System.Threading.Tasks;
namespace BankYouBankruptBusinessLogic.BusinessLogics
{
public class ReportLoad : IReportLoad
{
public byte[] LoadFile(bool whoRequested)
{
string pdfFilePath;
//если пришло true, то загружаем отчёт клиента
if (whoRequested)
{
pdfFilePath = "C:\\Users\\Programmist73\\Desktop\\Практика\\2-й курс\\4-й семестр\\CourseWork_BankYouBankrupt\\BankYouBankrupt\\BankYouBankruptRestAPI\\Отчёт_поартам.pdf";
}
else
{
pdfFilePath = "C:\\Users\\Programmist73\\Desktop\\Практика\\2-й курс\\4-й семестр\\CourseWork_BankYouBankrupt\\BankYouBankrupt\\BankYouBankruptRestAPI\\Отчёт_по_счетам.pdf";
}
byte[] bytes = System.IO.File.ReadAllBytes(pdfFilePath);
System.IO.File.WriteAllBytes(pdfFilePath, bytes);
return bytes;
}
}
}

View File

@ -22,6 +22,7 @@ namespace BankYouBankruptСlientApp
public static T? GetRequest<T>(string requestUrl)
{
var response = _client.GetAsync(requestUrl);
var result = response.Result.Content.ReadAsStringAsync().Result;
if (response.Result.IsSuccessStatusCode)

View File

@ -8,6 +8,8 @@
<ItemGroup>
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
<PackageReference Include="PDFsharp" Version="1.50.5147" />
<PackageReference Include="Spire.PDF" Version="9.4.12" />
</ItemGroup>
<ItemGroup>

View File

@ -1,12 +1,17 @@

using BankYouBankruptClientApp.Models;
using BankYouBankruptClientApp.Models;
using BankYouBankruptContracts.BindingModels;
using BankYouBankruptContracts.ViewModels;
using BankYouBankruptDataModels.Enums;
using BankYouBankruptСlientApp;
using Microsoft.AspNetCore.Mvc;
using PdfSharp.Drawing;
using PdfSharp.Pdf;
using PdfSharp.Pdf.IO;
using System.Collections;
using System.Diagnostics;
using System.Reflection;
using System.Xml.Linq;
using static System.Net.Mime.MediaTypeNames;
namespace BankYouBankruptClientApp.Controllers
{
@ -214,6 +219,7 @@ namespace BankYouBankruptClientApp.Controllers
Id = x.Id,
FullName = x.ClientSurname + " " + x.Number.ToString()
}).ToList();
return View();
}
@ -253,7 +259,7 @@ namespace BankYouBankruptClientApp.Controllers
}
[HttpPost]
public void CreateReport(DateTime dateFrom, DateTime dateTo)
public IActionResult CreateReport(DateTime dateFrom, DateTime dateTo)
{
if (APIClient.Client == null)
{
@ -266,9 +272,67 @@ namespace BankYouBankruptClientApp.Controllers
DateTo = dateTo
});
Response.Redirect("CreditingList");
PdfLoadViewModel support = APIClient.GetRequest<PdfLoadViewModel>($"api/Report/LoadReport?whoRequested={bool.TrueString}");
/*PdfDocument doc = new PdfDocument();
doc.LoadFromBytes(support.bytes);
support.document = doc;*/
//return File(support.bytes, "application/pdf", "support.pdf")
/*/Create PDF Document
PdfDocument document = new PdfDocument();
//You will have to add Page in PDF Document
PdfPage page = document.AddPage();
//For drawing in PDF Page you will nedd XGraphics Object
XGraphics gfx = XGraphics.FromPdfPage(page);
//For Test you will have to define font to be used
XFont font = new XFont("Verdana", 20, XFontStyle.Bold);
//Finally use XGraphics & font object to draw text in PDF Page
gfx.DrawString("My First PDF Document", font, XBrushes.Black,
new XRect(0, 0, page.Width, page.Height), XStringFormats.Center);
//Specify file name of the PDF file
string filename = "FirstPDFDocument.pdf";
//Save PDF File
document.Save(filename);
//Load PDF File for viewing
Process.Start(filename);*/
/*MemoryStream stream = new MemoryStream(support.bytes);
PdfDocument document = PdfReader.Open(stream, PdfDocumentOpenMode.Import);
support.document = document.Save(stream, false);*/
//ViewBag.ReportFile = File(support.bytes, "application/pdf");
ViewBag.ReportFile = new FileContentResult(support.bytes, "application/pdf");
//ViewBag.ReportFile = System.IO.Path.GetDirectoryName(Assembly.GetEntryAssembly().Location).ToString();
return View();
}
/*[HttpPost]
public object LoadReport()
{
return null;
}*/
#endregion
[HttpGet]

View File

@ -21,7 +21,29 @@
<div class="row">
<div class="col-8"></div>
<div class="col-4">
<input type="submit" value="Сформировать отчёт" class="btn btn-primary" />
<input id="createReport" type="submit" value="Сформировать отчёт" class="btn btn-primary" />
</div>
</div>
<div class="row">
<h1>Просмотр отчёта в формате pdf</h1>
<object id="forPdf" data={@ViewBag.ReportFile.FileContents} type="application/pdf" width="100%" height="100%">
<p>Unable to display PDF file. <a href="/uploads/media/default/0001/01/540cb75550adf33f281f29132dddd14fded85bfc.pdf">Download</a> instead.</p>
</object>
</div>
</form>
<!-- подгрузка отчёта PDF в реальном времени -->
<!-- <script>
$('#createReport').on('click', function () {
load();
});
function load() {
byte[] bytes;
BinaryFormatter bf = new BinaryFormatter();
MemoryStream ms = new MemoryStream();
bf.Serialize(ms, fileContent);
bytes = ms.ToArray();
System.IO.File.WriteAllBytes("hello.pdf", bytes);
}
</script> -->

View File

@ -6,6 +6,11 @@
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="PdfSharp" Version="1.50.5147" />
<PackageReference Include="Spire.PDF" Version="9.4.12" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\BankYouBankruptDataModels\BankYouBankruptDataModels.csproj" />
</ItemGroup>

View File

@ -0,0 +1,13 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace BankYouBankruptContracts.BusinessLogicsContracts
{
public interface IReportLoad
{
byte[] LoadFile(bool whoRequested);
}
}

View File

@ -0,0 +1,17 @@
using PdfSharp.Pdf;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace BankYouBankruptContracts.ViewModels
{
//для возврата pdf на страницу
public class PdfLoadViewModel
{
public byte[] bytes { get; set; }
public PdfDocument document { get; set; }
}
}

View File

@ -4,7 +4,10 @@ using BankYouBankruptContracts.BusinessLogicsContracts;
using BankYouBankruptContracts.SearchModels;
using BankYouBankruptContracts.ViewModels;
using BankYouBankruptRestApi.Controllers;
using DocumentFormat.OpenXml.Office2016.Drawing.ChartDrawing;
using Microsoft.AspNetCore.Mvc;
using Org.BouncyCastle.Utilities;
using System.Net;
namespace BankYouBankruptRestAPI.Controllers
{
@ -21,12 +24,14 @@ namespace BankYouBankruptRestAPI.Controllers
private readonly IReportCashierLogic _reportCashierLogic;
private readonly IReportLoad _reportLoad;
public ReportController(ILogger<ReportController> logger, IReportClientLogic reportClientLogic, IReportCashierLogic reportCashierLogic)
public ReportController(ILogger<ReportController> logger, IReportClientLogic reportClientLogic, IReportCashierLogic reportCashierLogic, IReportLoad reportLoad)
{
_logger = logger;
_reportClientLogic = reportClientLogic;
_reportCashierLogic = reportCashierLogic;
_reportLoad = reportLoad;
}
//метод генерации отчёта за период по картам клиента
@ -37,7 +42,7 @@ namespace BankYouBankruptRestAPI.Controllers
{
_reportClientLogic.SaveClientReportToPdfFile(new ReportBindingModel
{
FileName = "Отчёт по картам за " + DateTime.Now.ToShortDateString() + ".pdf",
FileName = "Отчёт_поартам.pdf",
DateFrom = model.DateFrom,
DateTo = model.DateTo
});
@ -57,7 +62,7 @@ namespace BankYouBankruptRestAPI.Controllers
{
_reportCashierLogic.SaveAccountsToPdfFile(new ReportBindingModel
{
FileName = "Отчёт по счетам за " + DateTime.Now.ToShortDateString() + ".pdf",
FileName = "Отчёт_по_счетам.pdf",
ClientId = model.ClientId,
DateFrom = model.DateFrom,
DateTo = model.DateTo
@ -69,5 +74,23 @@ namespace BankYouBankruptRestAPI.Controllers
throw;
}
}
[HttpGet]
public PdfLoadViewModel LoadReport(bool whoRequested)
{
try
{
PdfLoadViewModel model = new PdfLoadViewModel();
model.bytes = _reportLoad.LoadFile(whoRequested);
return model;
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка входа в систему");
throw;
}
}
}
}

View File

@ -35,6 +35,10 @@ builder.Services.AddTransient<ICashWithdrawalLogic, CashWithdrawalLogic>();
builder.Services.AddTransient<IReportClientLogic, ReportClientLogic>();
builder.Services.AddTransient<IReportCashierLogic, ReportCashierLogic>();
//для отправки файла в приложение
builder.Services.AddTransient<IReportLoad, ReportLoad>();
builder.Services.AddTransient<IMessageInfoLogic, MessageInfoLogic>();
builder.Services.AddSingleton<AbstractMailWorker, MailKitWorker>();