Stage 4: BussnessLogic(Добавление Абстрактных классов для Word, Excel, Pdf, добавление Reports и извлечение данных для отчётов), Contracts(редактирование Views), DatabaseImplement(редактирование подключения к базе данных)

This commit is contained in:
nikbel2004@outlook.com 2024-04-30 22:39:45 +04:00
parent db7fa7300b
commit 3aa3ecebb4
22 changed files with 477 additions and 18 deletions

View File

@ -8,6 +8,10 @@
<ItemGroup>
<PackageReference Include="DocumentFormat.OpenXml" Version="2.19.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="7.0.18">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.Extensions.Logging" Version="7.0.0" />
<PackageReference Include="PdfSharp.MigraDoc.Standard" Version="1.51.15" />
</ItemGroup>

View File

@ -0,0 +1,141 @@
using BankBusinessLogic.OfficePackage;
using BankBusinessLogic.OfficePackage.HelperModels;
using BankContracts.BindingModels.Reports;
using BankContracts.BusinessLogicsContracts.Reports;
using BankContracts.SearchModels.Cashier;
using BankContracts.SearchModels.Client;
using BankContracts.StoragesModels.Cashier;
using BankContracts.StoragesModels.Client;
using BankContracts.ViewModels.Client.ViewModels;
using BankContracts.ViewModels.Reports.Cashier;
using BankContracts.ViewModels.Reports;
using BankDatabaseImplement.Implements.ClientImplements;
using BankDataModels.Enums;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace BankBusinessLogic.BusinessLogic.Reports
{
public class ReportCashierLogic : IReportCashierLogic
{
private readonly IMoneyTransferStorage _moneyTransferStorage;
private readonly ICashWithdrawalStorage _cashWithdrawalStorage;
private readonly IDebitingStorage _debitingStorage;
private readonly IClientStorage _clientStorage;
private readonly ICardStorage _cardStorage;
private readonly AbstractSaveToExcel _saveToExcel;
private readonly AbstractSaveToWord _saveToWord;
private readonly AbstractSaveToPdf _saveToPdf;
// Конструктор
public ReportCashierLogic(IMoneyTransferStorage moneyTransferStorage, ICashWithdrawalStorage cashWithdrawalStorage,
IDebitingStorage debitingStorage, IClientStorage clientStorage, ICardStorage cardStorage,
AbstractSaveToExcel saveToExcel, AbstractSaveToWord saveToWord, AbstractSaveToPdf saveToPdf)
{
_moneyTransferStorage = moneyTransferStorage;
_cashWithdrawalStorage = cashWithdrawalStorage;
_debitingStorage = debitingStorage;
_clientStorage = clientStorage;
_cardStorage = cardStorage;
_saveToExcel = saveToExcel;
_saveToWord = saveToWord;
_saveToPdf = saveToPdf;
}
// Формирование списка переводов между счетами за период
public List<ReportCashierViewModel>? GetMoneyTransfers(ReportBindingModel model)
{
return _moneyTransferStorage.GetFilteredList(new MoneyTransferSearchModel { ClientId = model.ClientId, DateTransfer = model.DateTo })
.Select(x => new ReportCashierViewModel
{
OperationId = x.Id,
DateComplite = x.DateTransfer,
AccountSenderNumber = x.AccountPayeeNumber,
AccountPayeeNumber = x.AccountSenderNumber,
SumOperation = x.Sum
})
.ToList();
}
// Формирование списка выдачи наличных со счёта за период
public List<ReportCashierViewModel>? GetCashWithrawals(ReportBindingModel model)
{
return _cashWithdrawalStorage.GetFilteredList(new CashWithdrawalSearchModel { ClientId = model.ClientId, DateWithdrawal = model.DateTo })
.Select(x => new ReportCashierViewModel
{
OperationId = x.Id,
DebitingId = x.DebitingId,
AccountPayeeNumber = x.AccountNumber,
DateComplite = x.DateWithdrawal,
SumOperation = x.Sum
})
.ToList();
}
// Формирование списка выдачи наличных со счёта за период
public List<DebitingViewModel>? GetDebitings(ReportBindingModel model)
{
List<int> CardIdList = new();
var list = _cardStorage.GetFilteredList(new CardSearchModel
{
AccountId = model.AccountId
});
foreach (var index in list)
{
CardIdList.Add(index.Id);
}
List<DebitingViewModel> totalList = new();
foreach (var index in CardIdList)
{
var result = _debitingStorage.GetFilteredList(new DebitingSearchModel
{
CardId = index
});
totalList.AddRange(result);
}
return totalList;
}
// Формирование полного имени клиента для отчёта
public string GetFullName(ReportBindingModel model)
{
var client = _clientStorage.GetElement(new ClientSearchModel
{
Id = model.ClientId
});
return client.Surname + " " + client.Name + " " + client.Patronymic;
}
// Сохранение счетов в файл-Word
public void SaveAccountsToWordFile(ReportBindingModel model)
{
throw new NotImplementedException();
}
// Сохранение счетов в файл-Excel
public void SaveAccountsToExcelFile(ReportBindingModel model)
{
throw new NotImplementedException();
}
// Сохранение счетов в файл-Pdf
public ReportCashierViewModelForHTML SaveAccountsToPdfFile(ReportBindingModel model)
{
throw new NotImplementedException();
}
}
}

View File

@ -0,0 +1,163 @@
using BankBusinessLogic.OfficePackage;
using BankBusinessLogic.OfficePackage.HelperModels;
using BankContracts.BindingModels.Reports;
using BankContracts.BusinessLogicsContracts.Reports;
using BankContracts.SearchModels.Cashier;
using BankContracts.SearchModels.Client;
using BankContracts.StoragesModels.Cashier;
using BankContracts.StoragesModels.Client;
using BankContracts.ViewModels.Cashier.ViewModels;
using BankContracts.ViewModels.Client.ViewModels;
using BankContracts.ViewModels.Reports;
using BankContracts.ViewModels.Reports.Client;
using BankDataModels.Enums;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace BankBusinessLogic.BusinessLogic.Reports
{
public class ReportClientLogic : IReportClientLogic
{
private readonly IMoneyTransferStorage _moneyTransferStorage;
private readonly ICreditingStorage _creditingStorage;
private readonly IDebitingStorage _debitingStorage;
private readonly IClientStorage _clientStorage;
private readonly ICardStorage _cardStorage;
private readonly AbstractSaveToExcel _saveToExcel;
private readonly AbstractSaveToWord _saveToWord;
private readonly AbstractSaveToPdf _saveToPdf;
// Конструктор
public ReportClientLogic(IMoneyTransferStorage moneyTransferStorage,ICreditingStorage creditingStorage,
IDebitingStorage debitingStorage, IClientStorage clientStorage, ICardStorage cardStorage,
AbstractSaveToExcel saveToExcel, AbstractSaveToWord saveToWord, AbstractSaveToPdf saveToPdf)
{
_moneyTransferStorage = moneyTransferStorage;
_creditingStorage = creditingStorage;
_debitingStorage = debitingStorage;
_clientStorage = clientStorage;
_cardStorage = cardStorage;
_saveToExcel = saveToExcel;
_saveToWord = saveToWord;
_saveToPdf = saveToPdf;
}
public List<ReportClientViewModel>? GetCrediting(ReportBindingModel model)
{
return _creditingStorage.GetFilteredList(new CreditingSearchModel
{
DateCrediting = model.DateFrom,
}).Select(x => new ReportClientViewModel
{
OperationId = x.Id,
CardNumber = x.CardNumber,
SumOperation = x.Sum,
DateComplite = x.DateCredit
}).ToList();
}
public List<ReportClientViewModel>? GetDebiting(ReportBindingModel model)
{
return _debitingStorage.GetFilteredList(new DebitingSearchModel
{
DateDebit = model.DateFrom,
}).Select(x => new ReportClientViewModel
{
OperationId = x.Id,
CardNumber = x.CardNumber,
SumOperation = x.Sum,
DateComplite = x.DateDebit
}).ToList();
}
// Для Excel отчёта по переводам между счетов
public List<MoneyTransferViewModel>? GetMoneyTransfer(ReportBindingModel model)
{
// Список счетов по выбранным картам
List<int> accountId = new();
foreach (var index in model.CardList)
{
accountId.Add(_cardStorage.GetElement(new CardSearchModel { Id = index }).AccountId);
}
var list = accountId.ToHashSet().ToList();
List<MoneyTransferViewModel> totalList = new();
foreach (var index in list)
{
var result = _moneyTransferStorage.GetFilteredList(new MoneyTransferSearchModel
{
AccountSenderId = index,
AccountPayeeId = index
}).OrderBy(x => x.AccountSenderId).ToList();
totalList.AddRange(result);
}
return totalList;
}
// Для Excel отчёта по пополнениям карты
public List<CreditingViewModel> GetExcelCrediting(ReportBindingModel model)
{
List<CreditingViewModel> totalList = new();
foreach (var index in model.CardList)
{
var result = _creditingStorage.GetFilteredList(new CreditingSearchModel
{
CardId = index
});
totalList.AddRange(result);
}
return totalList;
}
// Для Excel отчёта по снятиям с карты
public List<DebitingViewModel> GetExcelDebiting(ReportBindingModel model)
{
List<DebitingViewModel> totalList = new();
foreach (var index in model.CardList)
{
var result = _debitingStorage.GetFilteredList(new DebitingSearchModel
{
CardId = index
});
totalList.AddRange(result);
}
return totalList;
}
// Сохранение в файл-Excel для клиентов
public void SaveToExcelFile(ReportBindingModel model, OfficeOperationEnum operationEnum)
{
throw new NotImplementedException();
}
// Сохранение в файл-Word для клиентов
public void SaveToWordFile(ReportBindingModel model, OfficeOperationEnum operationEnum)
{
throw new NotImplementedException();
}
// Сохранение в файл-Pdf для клиента
public ReportClientViewModelForHTML SaveClientReportToPdfFile(ReportBindingModel model)
{
throw new NotImplementedException();
}
}
}

View File

@ -11,6 +11,16 @@ namespace BankBusinessLogic.OfficePackage
{
public abstract class AbstractSaveToExcel
{
/// Создание excel-файла
protected abstract void CreateExcel(ExcelInfo info);
/// Добавляем новую ячейку в лист
protected abstract void InsertCellInWorksheet(ExcelCellParameters excelParams);
/// Объединение ячеек
protected abstract void MergeCells(ExcelMergeParameters excelParams);
/// Сохранение файла
protected abstract void SaveExcel(ExcelInfo info);
}
}

View File

@ -1,4 +1,5 @@
using System;
using BankBusinessLogic.OfficePackage.HelperModels;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
@ -8,5 +9,20 @@ namespace BankBusinessLogic.OfficePackage
{
public abstract class AbstractSaveToPdf
{
/// Создание pdf-файла
protected abstract void CreatePdf(PdfInfo info);
/// Создание параграфа с текстом
protected abstract void CreateParagraph(PdfParagraph paragraph);
/// Создание таблицы
protected abstract void CreateTable(List<string> columns);
/// Создание и заполнение строки
protected abstract void CreateRow(PdfRowParameters rowParameters);
/// Сохранение файла
protected abstract void SavePdf(PdfInfo info);
}
}

View File

@ -1,4 +1,5 @@
using System;
using BankBusinessLogic.OfficePackage.HelperModels;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
@ -8,5 +9,17 @@ namespace BankBusinessLogic.OfficePackage
{
public abstract class AbstractSaveToWord
{
/// Создание doc-файла
protected abstract void CreateWord(WordInfo info);
/// Создание абзаца с текстом
protected abstract void CreateParagraph(WordParagraph paragraph);
///Создание таблицы
protected abstract void CreateTable(WordParagraph paragraph);
/// Сохранение файла
protected abstract void SaveWord(WordInfo info);
}
}

View File

@ -26,4 +26,3 @@ namespace BankBusinessLogic.OfficePackage.HelperModels
public List<DebitingViewModel> Debiting { get; set; } = new();
}
}
}

View File

@ -1,4 +1,6 @@
using System;
using BankContracts.ViewModels.Reports.Cashier;
using BankContracts.ViewModels.Reports.Client;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
@ -32,7 +34,7 @@ namespace BankBusinessLogic.OfficePackage.HelperModels
// Перечень переводов со счёта на счёт
public List<ReportCashierViewModel> ReportMoneyTransfer { get; set; } = new();
// Перечень зачислений денежных средств на карту (т. е. на её счёт)
// Перечень зачислений денежных средств
public List<ReportCashierViewModel> ReportCashWithdrawal { get; set; } = new();
}
}

View File

@ -9,7 +9,7 @@ using System.Threading.Tasks;
namespace BankBusinessLogic.OfficePackage.HelperModels
{
// Общая информация по документу
internal class WordInfo
public class WordInfo
{
public string FileName { get; set; } = string.Empty;

View File

@ -1,4 +1,6 @@
using System;
using DocumentFormat.OpenXml.Packaging;
using DocumentFormat.OpenXml.Spreadsheet;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
@ -6,7 +8,14 @@ using System.Threading.Tasks;
namespace BankBusinessLogic.OfficePackage.Implements
{
// Реализация создания Excel-документа от абстрактного класса
public class SaveToExcel
{
private SpreadsheetDocument? _spreadsheetDocument;
private SharedStringTablePart? _shareStringPart;
private Worksheet? _worksheet;
}
}

View File

@ -1,4 +1,7 @@
using System;
using MigraDoc.DocumentObjectModel;
using MigraDoc.DocumentObjectModel.Tables;
using MigraDoc.Rendering;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
@ -6,7 +9,13 @@ using System.Threading.Tasks;
namespace BankBusinessLogic.OfficePackage.Implements
{
// Реализация создания Pdf-документа от абстрактного класса
public class SaveToPdf
{
private Document? _document;
private Section? _section;
private Table? _table;
}
}

View File

@ -1,4 +1,6 @@
using System;
using DocumentFormat.OpenXml.Packaging;
using DocumentFormat.OpenXml.Wordprocessing;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
@ -6,7 +8,12 @@ using System.Threading.Tasks;
namespace BankBusinessLogic.OfficePackage.Implements
{
// Реализация создания Word-документа от абстрактного класса
public class SaveToWord
{
private WordprocessingDocument? _wordDocument;
private Body? _docBody;
}
}

View File

@ -15,7 +15,6 @@
<Folder Include="ViewModels\Cashier\Reports\" />
<Folder Include="ViewModels\Client\Diagram\" />
<Folder Include="ViewModels\Client\Reports\" />
<Folder Include="ViewModels\Reports\" />
</ItemGroup>
</Project>

View File

@ -1,4 +1,6 @@
using BankContracts.BindingModels.Reports;
using BankContracts.ViewModels.Reports;
using BankContracts.ViewModels.Reports.Cashier;
using System;
using System.Collections.Generic;
using System.Linq;

View File

@ -1,4 +1,6 @@
using BankContracts.BindingModels.Reports;
using BankContracts.ViewModels.Reports;
using BankContracts.ViewModels.Reports.Client;
using BankDataModels.Enums;
using System;
using System.Collections.Generic;

View File

@ -18,12 +18,16 @@ namespace BankContracts.ViewModels.Cashier.ViewModels
public double Sum { get; set; }
// Для перевода между счетами
[DisplayName("Номер счёта отп.")]
public int? AccountSenderId { get; set; }
[DisplayName("Номер счёта получ.")]
[DisplayName("Номер счёта отправителя")]
public string AccountSenderNumber { get; set; } = string.Empty;
public int AccountPayeeId { get; set; }
[DisplayName("Номер счёта получателя")]
public string AccountPayeeNumber { get; set; } = string.Empty;
[DisplayName("Дата операции")]
public DateTime DateTransfer { get; set; } = DateTime.Now;

View File

@ -16,6 +16,7 @@ namespace BankContracts.ViewModels.Client.ViewModels
public int ClientId { get; set; }
public int CardId { get; set; }
[DisplayName("Номер карты")]
public string? CardNumber { get; set; }

View File

@ -0,0 +1,23 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace BankContracts.ViewModels.Reports.Cashier
{
public class ReportCashierViewModel
{
public int OperationId { get; set; }
public int DebitingId { get; set; }
public string AccountPayeeNumber { get; set; }
public string AccountSenderNumber { get; set; }
public double SumOperation { get; set; }
public DateTime DateComplite { get; set; }
}
}

View File

@ -0,0 +1,19 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace BankContracts.ViewModels.Reports.Client
{
public class ReportClientViewModel
{
public int OperationId { get; set; }
public string CardNumber { get; set; }
public double SumOperation { get; set; }
public DateTime? DateComplite { get; set; }
}
}

View File

@ -0,0 +1,18 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using BankContracts.ViewModels.Reports.Cashier;
namespace BankContracts.ViewModels.Reports
{
public class ReportCashierViewModelForHTML
{
// Список переводов со счёта на счёт
public List<ReportCashierViewModel> ReportMoneyTransfer { get; set; } = new();
// Список зачислений денежных средств на карту
public List<ReportCashierViewModel> ReportCashWithdrawal { get; set; } = new();
}
}

View File

@ -0,0 +1,18 @@
using BankContracts.ViewModels.Reports.Client;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace BankContracts.ViewModels.Reports
{
public class ReportClientViewModelForHTML
{
// Список операций пополнения за указанный период для вывода/сохранения в файл
public List<ReportClientViewModel> ReportCrediting { get; set; } = new();
// Список снятий за указанный период для вывода/сохранения в файл
public List<ReportClientViewModel> ReportDebiting { get; set; } = new();
}
}

View File

@ -15,7 +15,7 @@ namespace BankDatabaseImplement
{
if (optionsBuilder.IsConfigured == false)
{
optionsBuilder.UseSqlServer(@"Data Source= \SQLEXPRESS;Initial Catalog=BankDataBase;Integrated Security=True;MultipleActiveResultSets=True;;TrustServerCertificate=True");
optionsBuilder.UseSqlServer(@"Data Source= localhost\SQLEXPRESS;Initial Catalog=BankDataBase;Integrated Security=True;MultipleActiveResultSets=True;;TrustServerCertificate=True");
}
base.OnConfiguring(optionsBuilder);
}