Эксель пашет

This commit is contained in:
Artyom_Yashin 2024-05-27 00:56:48 +04:00
parent 68cd7db894
commit 17c6486d7c
6 changed files with 86 additions and 133 deletions

View File

@ -88,53 +88,100 @@ namespace BankBusinessLogic.OfficePackage
MergeCells(new ExcelMergeParameters
{
CellFromName = "A1",
CellToName = "C1"
CellToName = "F1"
});
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
});
InsertCellInWorksheet(new ExcelCellParameters
{
ColumnName = "F",
RowIndex = 2,
Text = "Счет получателя",
StyleInfo = ExcelStyleInfoType.Title
});
uint rowIndex = 3;
foreach (var report in info.Transfers)
{
InsertCellInWorksheet(new ExcelCellParameters
{
ColumnName = "A",
RowIndex = rowIndex,
Text = "",
Text = report.CardNumber,
StyleInfo = ExcelStyleInfoType.Text
});
rowIndex++;
foreach (var transfer1 in transfer.Transfers)
foreach (var transfer in report.Transfers)
{
InsertCellInWorksheet(new ExcelCellParameters
{
ColumnName = "B",
RowIndex = rowIndex,
Text = "",
Text = transfer.Id.ToString(),
StyleInfo = ExcelStyleInfoType.TextWithBroder
});
InsertCellInWorksheet(new ExcelCellParameters
{
ColumnName = "C",
RowIndex = rowIndex,
Text = "",
StyleInfo =
ExcelStyleInfoType.TextWithBroder
Text = transfer.Sum.ToString(),
StyleInfo = ExcelStyleInfoType.TextWithBroder
});
InsertCellInWorksheet(new ExcelCellParameters
{
ColumnName = "D",
RowIndex = rowIndex,
Text = transfer.TransferTime.ToString(),
StyleInfo = ExcelStyleInfoType.TextWithBroder
});
InsertCellInWorksheet(new ExcelCellParameters
{
ColumnName = "E",
RowIndex = rowIndex,
Text = transfer.SenderAccountNumber,
StyleInfo = ExcelStyleInfoType.TextWithBroder
});
InsertCellInWorksheet(new ExcelCellParameters
{
ColumnName = "F",
RowIndex = rowIndex,
Text = transfer.RecipientAccountNumber,
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);
}

View File

@ -531,7 +531,7 @@ namespace BankClientApp.Controllers
case "excel":
APIClient.PostRequest($"api/report/savetransferstoexcel", new ReportBindingModel
{
FileName = "C:\\Users\\123\\Desktop\\excelfile.xls",
FileName = "C:\\Users\\123\\Desktop\\excelfile.xlsx",
SelectedCardIds = cards,
});
break;

View File

@ -18,110 +18,8 @@
</div>
</div>
<div class="text-center">
<h4 class="display-4">Перевод</h4>
</div>
<div class="row">
<div class="col-4">Сумма:</div>
<div class="col-8">
<input type="number" readonly name="transfersum" id="transfersum" />
</div>
</div>
<div class="row">
<div class="col-4">Номер счета отправителя:</div>
<div class="col-8">
<input type="text" readonly name="transfersender-number" id="transfersender-number" />
</div>
</div>
<div class="row">
<div class="col-4">Номер счета получателя:</div>
<div class="col-8">
<input type="text" readonly name="treansferrecipient-number" id="transferrecipient-number" />
</div>
</div>
<div class="row">
<div class="col-4">Дата:</div>
<div class="col-8">
<input type="datetime-local" readonly name="transferdate" id="transferdate" />
</div>
</div>
<div class="text-center">
<h4 class="display-4">Операция</h4>
</div>
<div class="row">
<div class="col-4">Сумма:</div>
<div class="col-8">
<input type="text" readonly name="operationsum" id="operationsum" />
</div>
</div>
<div class="row">
<div class="col-4">Отправитель:</div>
<div class="col-8">
<input type="text" readonly name="operationrecipient-number" id="operationrecipient-number" />
</div>
</div>
<div class="row">
<div class="col-4">Получатель:</div>
<div class="col-8">
<input type="text" readonly name="operationrecipient-number" id="operationrecipient-number" />
</div>
</div>
<div class="row">
<div class="col-4">Дата:</div>
<div class="col-8">
<input type="datetime-local" readonly name="operationdate" id="operationdate" />
</div>
</div>
<div class="row">
<div class="col-4"></div>
<div class="col-8"><input type="submit" value="Связать" class="btn btn-success" /></div>
</div>
</form>
@section Scripts
{
<script>
function checkTrensfer() {
var transfer = $('#transfer').val();
if (transfer) {
$.ajax({
method: "GET",
url: "/Home/GetTransfer",
data: { transferId: transfer },
success: function (result) {
$('#sum').val(result.Sum);
$('#transfersender-number').val(result.senderAccountNumber);
$('#transferrecipient-number').val(result.recipientAccountNumber);
$('#transferdate').val(result.transferTime);
}
});
};
}
function checkOperation() {
var operation = $('#operation').val();
if (operation) {
$.ajax({
method: "GET",
url: "/Home/GetOperation",
data: { operationId: operation },
success: function (result) {
$('#sum').val(result.Sum);
$('#operationsender-number').val(result.senderCardNumber);
$('#operationrecipient-number').val(result.recipientCardNumber);
$('#operationdate').val(result.operationTime);
}
});
};
}
checkTransfer();
checkOperation();
$('#transfer').on('change', function () {
checkTransfer();
});
$('#operation').on('change', function () {
checkOperation();
});
</script>
}
</form>

View File

@ -58,7 +58,7 @@ namespace BankDatabaseImplement.Implements
var transfer = context.Transfers.FirstOrDefault(x => x.OperationId == model.Id);
if (transfer != null)
{
return null;
throw new InvalidOperationException("Обновление невозможно");
}
if (operation == null)
{
@ -75,7 +75,7 @@ namespace BankDatabaseImplement.Implements
var transfer = context.Transfers.FirstOrDefault(x => x.OperationId == model.Id);
if (transfer != null)
{
return null;
throw new InvalidOperationException("Удаление невозможно");
}
if (operation != null)
{

View File

@ -99,7 +99,7 @@ namespace BankDatabaseImplement.Implements
.FirstOrDefault(rec => rec.Id == model.Id);
if (element?.Status != RequestStatus.Принята)
{
return null;
throw new InvalidOperationException("Заявка уже выполнена");
}
if (element != null)
{

View File

@ -49,9 +49,17 @@ namespace BankRestApi.Controllers
}
}
[HttpPost]
public void SaveTransfersToExcel(ReportBindingModel? model)
public void SaveTransfersToExcel(ReportBindingModel model)
{
try
{
_logic.SaveTransfersToExcelFile(model);
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка сохранения переводов в ворд");
throw;
}
}
}
}