Pdf работает))))

This commit is contained in:
Artyom_Yashin 2024-05-27 04:16:18 +04:00
parent 6eda8d6237
commit 7672fd46c6
7 changed files with 385 additions and 61 deletions

View File

@ -28,7 +28,7 @@ namespace BankBusinessLogic.MailWorker
objMailMessage.Body = info.Text;
objMailMessage.SubjectEncoding = Encoding.UTF8;
objMailMessage.BodyEncoding = Encoding.UTF8;
Attachment attachment = new Attachment("C:\\Users\\pdffile.pdf", new ContentType(MediaTypeNames.Application.Pdf));
Attachment attachment = new Attachment("C:\\forpdf\\pdffile.pdf", new ContentType(MediaTypeNames.Application.Pdf));
objMailMessage.Attachments.Add(attachment);
objSmtpClient.UseDefaultCredentials = false;
objSmtpClient.EnableSsl = true;

View File

@ -52,6 +52,7 @@ namespace BankBusinessLogic.OfficePackage
public void CreateOperationsRequestsDoc(PdfInfo info)
{
CreatePdf(info);
//title
CreateParagraph(new PdfParagraph
{
Text = info.Title,
@ -64,28 +65,161 @@ namespace BankBusinessLogic.OfficePackage
Style = "Normal",
ParagraphAlignment = PdfParagraphAlignmentType.Center
});
//sender operations
CreateParagraph(new PdfParagraph
{
Text = "Операции на другие карты",
Style = "NormalTitle",
ParagraphAlignment = PdfParagraphAlignmentType.Left
});
CreateTable(new List<string> { "2cm", "3cm", "6cm", "3cm", "3cm" });
CreateRow(new PdfRowParameters
{
Texts = new List<string> { "Номер", "Дата заказа", "Компьютер", "Сумма", "Статус" },
Texts = new List<string> { "Номер карты", "Номер перевода", "Время перевода", "Сумма", "Карта получателя" },
Style = "NormalTitle",
ParagraphAlignment = PdfParagraphAlignmentType.Center
});
foreach (var entry in info.OperationsRequests)
foreach (var report in info.OperationsRequests)
{
CreateRow(new PdfRowParameters
{
Texts = new List<string> { entry.CardNumber.ToString(), },
Texts = new List<string> {
report.CardNumber.ToString(),
"",
"",
"",
"",
},
Style = "Normal",
ParagraphAlignment = PdfParagraphAlignmentType.Left
});
foreach (var senderOperation in report.SenderOperations)
{
CreateRow(new PdfRowParameters
{
Texts = new List<string>
{
"",
senderOperation.Id.ToString(),
senderOperation.OperationTime.ToString(),
senderOperation.Sum.ToString(),
senderOperation.RecipientCardNumber,
},
Style = "Normal",
ParagraphAlignment = PdfParagraphAlignmentType.Left
});
}
}
CreateParagraph(new PdfParagraph
{
Text = "",
Style = "Normal",
ParagraphAlignment =
PdfParagraphAlignmentType.Right
ParagraphAlignment = PdfParagraphAlignmentType.Right
});
//recipient operations
CreateParagraph(new PdfParagraph
{
Text = "Операции на другие карты",
Style = "NormalTitle",
ParagraphAlignment = PdfParagraphAlignmentType.Left
});
CreateTable(new List<string> { "2cm", "3cm", "6cm", "3cm", "3cm" });
CreateRow(new PdfRowParameters
{
Texts = new List<string> { "Номер карты", "Номер перевода", "Время перевода", "Сумма", "Карта отправителя" },
Style = "NormalTitle",
ParagraphAlignment = PdfParagraphAlignmentType.Center
});
foreach (var report in info.OperationsRequests)
{
CreateRow(new PdfRowParameters
{
Texts = new List<string> {
report.CardNumber.ToString(),
"",
"",
"",
"",
},
Style = "Normal",
ParagraphAlignment = PdfParagraphAlignmentType.Left
});
foreach (var recipientOperation in report.RecipientOperations)
{
CreateRow(new PdfRowParameters
{
Texts = new List<string>
{
"",
recipientOperation.Id.ToString(),
recipientOperation.OperationTime.ToString(),
recipientOperation.Sum.ToString(),
recipientOperation.SenderCardNumber,
},
Style = "Normal",
ParagraphAlignment = PdfParagraphAlignmentType.Left
});
}
}
CreateParagraph(new PdfParagraph
{
Text = "",
Style = "Normal",
ParagraphAlignment = PdfParagraphAlignmentType.Right
});
//requests
CreateParagraph(new PdfParagraph
{
Text = "Заявки",
Style = "NormalTitle",
ParagraphAlignment = PdfParagraphAlignmentType.Left
});
CreateTable(new List<string> { "2cm", "3cm", "6cm", "3cm", "3cm" });
CreateRow(new PdfRowParameters
{
Texts = new List<string> { "Номер карты", "Номер заявки", "Время создания", "Сумма", "Статус" },
Style = "NormalTitle",
ParagraphAlignment = PdfParagraphAlignmentType.Center
});
foreach (var report in info.OperationsRequests)
{
CreateRow(new PdfRowParameters
{
Texts = new List<string> {
report.CardNumber.ToString(),
"",
"",
"",
"",
},
Style = "Normal",
ParagraphAlignment = PdfParagraphAlignmentType.Left
});
foreach (var request in report.Requests)
{
CreateRow(new PdfRowParameters
{
Texts = new List<string>
{
"",
request.Id.ToString(),
request.RequestTime.ToString(),
request.Sum.ToString(),
request.Status.ToString(),
},
Style = "Normal",
ParagraphAlignment = PdfParagraphAlignmentType.Left
});
}
}
CreateParagraph(new PdfParagraph
{
Text = "",
Style = "Normal",
ParagraphAlignment = PdfParagraphAlignmentType.Right
});
SavePdf(info);
}

View File

@ -8,6 +8,7 @@ using DocumentFormat.OpenXml.Spreadsheet;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore.Metadata.Internal;
using System.Diagnostics;
using System.Globalization;
namespace BankClientApp.Controllers
{
@ -508,9 +509,9 @@ namespace BankClientApp.Controllers
{
throw new Exception("Вы как суда попали? Суда вход только авторизованным");
}
APIClient.PostRequest("api/report/sandoperationsrequeststoemail", new ReportBindingModel
APIClient.PostRequest("api/report/sendoperationsRequeststoemail", new ReportBindingModel
{
FileName = "C:\\Users\\pdffile.pdf",
FileName = "C:\\forpdf\\pdffile.pdf",
DateFrom = dateFrom,
DateTo = dateTo,
Email = APIClient.Client.Email
@ -519,6 +520,156 @@ namespace BankClientApp.Controllers
}
[HttpGet]
public string GetOperationsRequests(DateTime dateFrom, DateTime dateTo)
{
if (APIClient.Client == null)
{
throw new Exception("Вы как суда попали? Суда вход только авторизованным");
}
List<ReportOperationsRequestsViewModel>? result;
try
{
string dateFromS = dateFrom.ToString("s", CultureInfo.InvariantCulture);
string dateToS = dateTo.ToString("s", CultureInfo.InvariantCulture);
result = APIClient.GetRequest<List<ReportOperationsRequestsViewModel>?>($"api/report/getoperationsrequests?datefroms={dateFromS}&datetos={dateToS}");
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка создания отчета");
throw;
}
//title
string tables = "";
tables += "<h2 class=\"text-custom-color-1\">Отчет по картам</h2>";
tables += $"<div class=\"text-custom-color-1 text-center\">c {dateFrom.ToShortDateString()} по {dateTo.ToShortDateString()}</div>";
//sender operations
string senderOperationsTable = "";
senderOperationsTable += "<h2 class=\"text-custom-color-1\">Операции на счета</h2>";
senderOperationsTable += "<div class=\" table-responsive\">";
senderOperationsTable += "<table class=\"table table-striped table-bordered table-hover\">";
senderOperationsTable += "<thead class=\"table-dark\">";
senderOperationsTable += "<tr>";
senderOperationsTable += "<th scope=\"col\">Номер счета</th>";
senderOperationsTable += "<th scope=\"col\">Номер перевода</th>";
senderOperationsTable += "<th scope=\"col\">Время перевода</th>";
senderOperationsTable += "<th scope=\"col\">Сумма</th>";
senderOperationsTable += "<th scope=\"col\">Карта получателя</th>";
senderOperationsTable += "</tr>";
senderOperationsTable += "</thead>";
senderOperationsTable += "<tbody>";
foreach (var report in result)
{
senderOperationsTable += "<tr>";
senderOperationsTable += $"<td>{report.CardNumber}</td>";
senderOperationsTable += $"<td></td>";
senderOperationsTable += $"<td></td>";
senderOperationsTable += $"<td></td>";
senderOperationsTable += $"<td></td>";
senderOperationsTable += "</tr>";
foreach (var senderOperation in report.SenderOperations)
{
senderOperationsTable += "<tr>";
senderOperationsTable += $"<td></td>";
senderOperationsTable += $"<td>{senderOperation.Id}</td>";
senderOperationsTable += $"<td>{senderOperation.OperationTime}</td>";
senderOperationsTable += $"<td>{senderOperation.Sum}</td>";
senderOperationsTable += $"<td>{senderOperation.RecipientCardNumber}</td>";
senderOperationsTable += "</tr>";
}
}
senderOperationsTable += "</tbody>";
senderOperationsTable += "</table>";
senderOperationsTable += "</div>";
tables += senderOperationsTable;
//sender operations
string recipientOperationsTable = "";
recipientOperationsTable += "<h2 class=\"text-custom-color-1\">Операции со счетов</h2>";
recipientOperationsTable += "<div class=\" table-responsive\">";
recipientOperationsTable += "<table class=\"table table-striped table-bordered table-hover\">";
recipientOperationsTable += "<thead class=\"table-dark\">";
recipientOperationsTable += "<tr>";
recipientOperationsTable += "<th scope=\"col\">Номер счета</th>";
recipientOperationsTable += "<th scope=\"col\">Номер перевода</th>";
recipientOperationsTable += "<th scope=\"col\">Время перевода</th>";
recipientOperationsTable += "<th scope=\"col\">Сумма</th>";
recipientOperationsTable += "<th scope=\"col\">Карта получателя</th>";
recipientOperationsTable += "</tr>";
recipientOperationsTable += "</thead>";
recipientOperationsTable += "<tbody>";
foreach (var report in result)
{
recipientOperationsTable += "<tr>";
recipientOperationsTable += $"<td>{report.CardNumber}</td>";
recipientOperationsTable += $"<td></td>";
recipientOperationsTable += $"<td></td>";
recipientOperationsTable += $"<td></td>";
recipientOperationsTable += $"<td></td>";
recipientOperationsTable += "</tr>";
foreach (var recipientOperation in report.RecipientOperations)
{
recipientOperationsTable += "<tr>";
recipientOperationsTable += $"<td></td>";
recipientOperationsTable += $"<td>{recipientOperation.Id}</td>";
recipientOperationsTable += $"<td>{recipientOperation.OperationTime}</td>";
recipientOperationsTable += $"<td>{recipientOperation.Sum}</td>";
recipientOperationsTable += $"<td>{recipientOperation.SenderCardNumber}</td>";
recipientOperationsTable += "</tr>";
}
}
recipientOperationsTable += "</tbody>";
recipientOperationsTable += "</table>";
recipientOperationsTable += "</div>";
tables += recipientOperationsTable;
//requests
string requestsTable = "";
requestsTable += "<h2 class=\"text-custom-color-1\">Заявки</h2>";
requestsTable += "<div class=\" table-responsive\">";
requestsTable += "<table class=\"table table-striped table-bordered table-hover\">";
requestsTable += "<thead class=\"table-dark\">";
requestsTable += "<tr>";
requestsTable += "<th scope=\"col\">Номер счета</th>";
requestsTable += "<th scope=\"col\">Номер заявки</th>";
requestsTable += "<th scope=\"col\">Время создания</th>";
requestsTable += "<th scope=\"col\">Сумма</th>";
requestsTable += "<th scope=\"col\">Статус</th>";
requestsTable += "</tr>";
requestsTable += "</thead>";
requestsTable += "<tbody>";
foreach (var report in result)
{
requestsTable += "<tr>";
requestsTable += $"<td>{report.CardNumber}</td>";
requestsTable += $"<td></td>";
requestsTable += $"<td></td>";
requestsTable += $"<td></td>";
requestsTable += $"<td></td>";
requestsTable += "</tr>";
foreach (var request in report.Requests)
{
requestsTable += "<tr>";
requestsTable += $"<td></td>";
requestsTable += $"<td>{request.Id}</td>";
requestsTable += $"<td>{request.RequestTime}</td>";
requestsTable += $"<td>{request.Sum}</td>";
requestsTable += $"<td>{request.Status}</td>";
requestsTable += "</tr>";
}
}
requestsTable += "</tbody>";
requestsTable += "</table>";
requestsTable += "</div>";
tables += requestsTable;
return tables;
}
[HttpGet]
public IActionResult TransferListReport()
{

View File

@ -4,50 +4,53 @@
<div class="text-center">
<h3 class="display-4">Список карт с расшифровкой по операциям и заявкам за период</h3>
</div>
<div class="text-center">
@{
<div class="row mb-5">
<div class="col-4">Начальная дата:</div>
<div class="col-8">
<input type="date" id="dateFrom" name="dateFrom" class="form-control">
<div class="text-center" >
<form method="post">
@{
<div class="row mb-5">
<div class="col-4">Начальная дата:</div>
<div class="col-8">
<input type="date" id="dateFrom" name="dateFrom" class="form-control">
</div>
</div>
</div>
<div class="row mb-5">
<div class="col-4">Конечная дата:</div>
<div class="col-8">
<input type="date" id="dateTo" name="dateTo" class="form-control">
<div class="row mb-5">
<div class="col-4">Конечная дата:</div>
<div class="col-8">
<input type="date" id="dateTo" name="dateTo" class="form-control">
</div>
</div>
</div>
<div class="row">
<div class="col-8"></div>
<div class="col-4"><input type="submit" value="Создать отчет" class="btn btn-primary" /></div>
</div>
<div class="row">
<div class="col-8"></div>
<div class="col-4"><input type="submit" value="Отправить на почту" class="btn btn-primary" /></div>
</div>
<table class="table">
<thead>
<tr>
<th>
Номер
</th>
<th>
Дата
</th>
<th>
Карта
</th>
<th>
Операция
</th>
<th>
Заявка
</th>
</tr>
</thead>
<tbody>
</tbody>
</table>
}
</div>
<div class="row mb-2">
<div class="col-8"></div>
<div class="col-4"><input id="demonstrate" type="button" value="Создать отчет" class="btn btn-primary" /></div>
</div>
<div class="row">
<div class="col-8"></div>
<div class="col-4"><input type="submit" value="Отправить на почту" class="btn btn-primary" /></div>
</div>
<div id="report"></div>
}
</form>
</div>
@section Scripts {
<script>
function check() {
var dateFrom = $('#dateFrom').val();
var dateTo = $('#dateTo').val();
if (dateFrom && dateTo) {
$.ajax({
method: "GET",
url: "/Home/GetOperationsRequests",
data: { dateFrom: dateFrom, dateTo: dateTo },
success: function (result) {
if (result != null) {
$('#report').html(result);
}
}
});
};
}
check();
$('#demonstrate').on('click', (e) => check());
</script>
}

View File

@ -62,23 +62,30 @@ namespace BankDatabaseImplement.Implements
{
using var context = new BankDatabase();
return context.Cards
.Select(c => new ReportOperationsRequestsViewModel()
.Select(card => new ReportOperationsRequestsViewModel()
{
CardNumber = c.Number,
CardNumber = card.Number,
SenderOperations = context.Operations
.Where(x => x.OperationTime >= model.DateFrom && x.OperationTime <= model.DateTo && x.SenderCardId == c.Id)
.Include(x => x.RecipientCard)
.Where(x => x.OperationTime >= model.DateFrom && x.OperationTime <= model.DateTo && x.SenderCardId == card.Id)
.Select(t => t.GetViewModel)
.ToList(),
RecipientOperations = context.Operations
.Where(x => x.OperationTime >= model.DateFrom && x.OperationTime <= model.DateTo && x.RecipientCardId == c.Id)
.Include(x => x.SenderCard)
.Where(x => x.OperationTime >= model.DateFrom && x.OperationTime <= model.DateTo && x.RecipientCardId == card.Id)
.Select(t => t.GetViewModel)
.ToList(),
Requests = context.Requests
.Include(x => x.CardRequests)
.Where(x => x.Cards.Select(x => x.CardId).ToList().Contains(c.Id) && x.RequestTime >= model.DateFrom && x.RequestTime <= model.DateTo)
Requests = context.CardRequests
.Include(x => x.Request)
.ThenInclude(x => x.Cards)
.Where(x => x.CardId == card.Id)
.Select(x => x.Request)
.Where(x =>
x.RequestTime >= model.DateFrom &&
x.RequestTime <= model.DateTo)
.Select(r => r.GetViewModel)
.ToList(),
}).ToList();
}).ToList();
}
public CardViewModel? GetElement(CardSearchModel model)

View File

@ -1,6 +1,7 @@
using BankBusinessLogic.MailWorker;
using BankContracts.BindingModels;
using BankContracts.BusinessLogicsContracts;
using BankContracts.ViewModels;
using Microsoft.AspNetCore.Mvc;
namespace BankRestApi.Controllers
@ -111,5 +112,33 @@ namespace BankRestApi.Controllers
throw;
}
}
[HttpGet]
public List<ReportOperationsRequestsViewModel> GetOperationsRequests(string dateFromS, string dateToS)
{
try
{
DateTime dateFrom = DateTime.Parse(dateFromS);
DateTime dateTo = DateTime.Parse(dateToS);
var tmp = _logic.CreateReportOperationsRequests(new BankContracts.SearchModels.CardSearchModel
{
DateFrom = dateFrom,
DateTo = dateTo
});
foreach(var item in tmp)
{
foreach(var item2 in item.Requests)
{
item2.CardRequests = null;
}
}
return tmp;
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка получения для таблицы");
throw;
}
}
}
}

Binary file not shown.