This commit is contained in:
Artyom_Yashin 2024-05-27 00:56:59 +04:00
commit 60688b1147
6 changed files with 97 additions and 40 deletions

View File

@ -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);
}

View File

@ -44,10 +44,10 @@ namespace BankBusinessLogic.OfficePackage
var wordTable = new WordTable
{
Headers = new List<string> {
"Номер карты",
"Номер счёта",
"Номер заявки",
"Статус заявки",
"Сумма выдачи",
"Сумма заявки",
"Дата заявки"},
Columns = 5,
RowText = table

View File

@ -126,11 +126,24 @@ namespace BankDatabaseImplement.Implements
Withdrawal? withdrawal;
try
{
withdrawal = context.Withdrawals.FirstOrDefault(x => x.Id == withdrawalId);
withdrawal = context.Withdrawals.Include(x => x.Accounts).FirstOrDefault(x => x.Id == withdrawalId);
if (withdrawal == null)
throw new InvalidOperationException("Withdrawal was not found");
var request = context.Requests.FirstOrDefault(x => x.Id == requestId);
if (request == null)
throw new InvalidOperationException("Request was not found");
WithdrawalBindingModel model = new WithdrawalBindingModel
{
Id = withdrawal.Id,
WithdrawalAccounts = withdrawal.WithdrawalAccounts,
Sum = request.Sum,
};
MakeWithdrawal(context, model);
withdrawal.LinkToRequest(requestId);
context.SaveChanges();
if (!request.Execute())
throw new InvalidOperationException("Request was not executed");
withdrawal.UpdateAccounts(context, model);
context.SaveChanges();
}
catch
{
@ -144,16 +157,18 @@ namespace BankDatabaseImplement.Implements
public WithdrawalViewModel? Delete(WithdrawalBindingModel model)
{
using var context = new BankDatabase();
var element = context.Withdrawals
var withdrawal = context.Withdrawals
.Include(x => x.Request)
.Include(x => x.Accounts)
.ThenInclude(x => x.Account)
.FirstOrDefault(rec => rec.Id == model.Id);
if (element != null)
{
context.Withdrawals.Remove(element);
if (withdrawal != null)
{
if (withdrawal.RequestId != null)
throw new InvalidOperationException("Deletion was rejected: withdrawal was done");
context.Withdrawals.Remove(withdrawal);
context.SaveChanges();
return element.GetViewModel;
return withdrawal.GetViewModel;
}
return null;
}

View File

@ -88,6 +88,7 @@ namespace BankDatabaseImplement.Models
{
context.AccountWithdrawals.RemoveRange(WithdrawalAccounts.Where(rec => !model.WithdrawalAccounts.ContainsKey(rec.AccountId)));
context.SaveChanges();
WithdrawalAccounts = context.AccountWithdrawals.Where(rec => rec.WithdrawalId == model.Id).ToList();
foreach (var wa in WithdrawalAccounts)
{
wa.Sum = model.WithdrawalAccounts[wa.AccountId].Item2;

View File

@ -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:

View File

@ -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)
{