2024-05-28 02:15:05 +04:00
using BankBusinessLogic.OfficePackage.HelperEnums ;
using BankBusinessLogic.OfficePackage.HelperModels ;
using BankDataModels.Enums ;
2024-04-30 22:39:45 +04:00
using System ;
2024-04-30 16:37:32 +04:00
using System.Collections.Generic ;
using System.Linq ;
using System.Text ;
using System.Threading.Tasks ;
namespace BankBusinessLogic.OfficePackage
{
2024-05-28 02:15:05 +04:00
public abstract class AbstractSaveToWord
{
//метод создания документа
public void CreateDoc ( WordInfo info , OfficeOperationEnum operationEnum )
{
if ( operationEnum = = OfficeOperationEnum . М е ж д у _cче та ми )
{
CreateMoneyTransferWord ( info ) ;
}
2024-04-30 22:39:45 +04:00
2024-05-28 02:15:05 +04:00
if ( operationEnum = = OfficeOperationEnum . П о п о л н е н и е _ка р т )
{
CreateCreditingWord ( info ) ;
}
2024-04-30 22:39:45 +04:00
2024-05-28 02:15:05 +04:00
if ( operationEnum = = OfficeOperationEnum . Cнятие _с _ка р ты )
{
CreateDebitingWord ( info ) ;
}
2024-04-30 22:39:45 +04:00
2024-05-28 02:15:05 +04:00
if ( operationEnum = = OfficeOperationEnum . Д л я _ка с с ир а )
{
CreateCashierWord ( info ) ;
}
}
private void CreateMoneyTransferWord ( WordInfo info )
{
CreateWord ( info ) ;
CreateParagraph ( new WordParagraph
{
Texts = new List < ( string , WordTextProperties ) > { ( info . Title , new WordTextProperties { Bold = true , Size = "24" } ) } ,
TextProperties = new WordTextProperties
{
Size = "24" ,
JustificationType = WordJustificationType . Center
}
} ) ;
foreach ( var transfer in info . MoneyTransfer )
{
List < List < ( string , WordTextProperties ) > > rowList = new ( )
{
new ( )
{
new ( "Номер счёта отправителя" , new WordTextProperties { Bold = true , Size = "20" } ) ,
new ( "Номер счёта получателя" , new WordTextProperties { Bold = true , Size = "20" } ) ,
new ( "Сумма операции" , new WordTextProperties { Bold = true , Size = "20" } ) ,
new ( "Дата перевода" , new WordTextProperties { Bold = true , Size = "20" } )
}
} ;
CreateParagraph ( new WordParagraph
{
Texts = new List < ( string , WordTextProperties ) > { ( "Перевод №" + transfer . Id . ToString ( ) , new WordTextProperties { Bold = true , Size = "24" } ) } ,
TextProperties = new WordTextProperties
{
Size = "24" ,
JustificationType = WordJustificationType . Center
}
} ) ;
List < ( string , WordTextProperties ) > cellList = new ( )
{
new ( transfer . AccountSenderNumber , new WordTextProperties { Size = "20" } ) ,
new ( transfer . AccountPayeeNumber , new WordTextProperties { Size = "20" } ) ,
new ( transfer . Sum . ToString ( ) , new WordTextProperties { Size = "20" } ) ,
new ( transfer . DateTransfer . ToString ( ) , new WordTextProperties { Size = "20" } ) ,
} ;
rowList . Add ( cellList ) ;
CreateTable ( new WordParagraph
{
RowTexts = rowList ,
TextProperties = new WordTextProperties
{
Size = "24" ,
JustificationType = WordJustificationType . Center
}
} ) ;
}
CreateParagraph ( new WordParagraph
{
Texts = new List < ( string , WordTextProperties ) > { ( "Суммарный объём переводов: " + info . MoneyTransfer . Sum ( x = > x . Sum ) . ToString ( ) ,
new WordTextProperties { Bold = true , Size = "24" } ) } ,
TextProperties = new WordTextProperties
{
Size = "24" ,
JustificationType = WordJustificationType . Both
}
} ) ;
SaveWord ( info ) ;
}
private void CreateCreditingWord ( WordInfo info )
{
CreateWord ( info ) ;
CreateParagraph ( new WordParagraph
{
Texts = new List < ( string , WordTextProperties ) > { ( info . Title , new WordTextProperties { Bold = true , Size = "24" } ) } ,
TextProperties = new WordTextProperties
{
Size = "24" ,
JustificationType = WordJustificationType . Center
}
} ) ;
foreach ( var crediting in info . Crediting )
{
List < List < ( string , WordTextProperties ) > > rowList = new ( )
{
new ( )
{
new ( "Номер карты" , new WordTextProperties { Bold = true , Size = "24" } ) ,
new ( "Сумма пополнения" , new WordTextProperties { Bold = true , Size = "24" } ) ,
new ( "Дата выполнения" , new WordTextProperties { Bold = true , Size = "24" } )
}
} ;
CreateParagraph ( new WordParagraph
{
Texts = new List < ( string , WordTextProperties ) > { ( "Пополнение №" + crediting . Id . ToString ( ) , new WordTextProperties { Bold = true , Size = "24" } ) } ,
TextProperties = new WordTextProperties
{
Size = "24" ,
JustificationType = WordJustificationType . Center
}
} ) ;
List < ( string , WordTextProperties ) > cellList = new ( )
{
new ( crediting . CardNumber , new WordTextProperties { Size = "24" } ) ,
new ( crediting . Sum . ToString ( ) , new WordTextProperties { Size = "24" } ) ,
new ( crediting . DateCredit = = null ? "В обработке" : crediting . DateCredit . ToString ( ) , new WordTextProperties { Size = "24" } )
} ;
rowList . Add ( cellList ) ;
CreateTable ( new WordParagraph
{
RowTexts = rowList ,
TextProperties = new WordTextProperties
{
Size = "24" ,
JustificationType = WordJustificationType . Center
}
} ) ;
}
//формирование списка поступления по каждой карте
var dict = new Dictionary < string , double > ( ) ;
foreach ( var elem in info . Crediting )
{
if ( dict . ContainsKey ( elem . CardNumber ) )
{
dict [ elem . CardNumber ] + = elem . Sum ;
}
else
{
dict [ elem . CardNumber ] = elem . Sum ;
}
}
foreach ( var elem in dict )
{
CreateParagraph ( new WordParagraph
{
Texts = new List < ( string , WordTextProperties ) > { ( "Суммарное пополнение на карту №" + elem . Key + ": " + elem . Value . ToString ( ) , new WordTextProperties { Bold = true , Size = "24" } ) } ,
TextProperties = new WordTextProperties
{
Size = "24" ,
JustificationType = WordJustificationType . Both
}
} ) ;
}
SaveWord ( info ) ;
}
private void CreateDebitingWord ( WordInfo info )
{
CreateWord ( info ) ;
CreateParagraph ( new WordParagraph
{
Texts = new List < ( string , WordTextProperties ) > { ( info . Title , new WordTextProperties { Bold = true , Size = "24" } ) } ,
TextProperties = new WordTextProperties
{
Size = "24" ,
JustificationType = WordJustificationType . Center
}
} ) ;
foreach ( var crediting in info . Debiting )
{
List < List < ( string , WordTextProperties ) > > rowList = new ( )
{
new ( )
{
new ( "Номер карты" , new WordTextProperties { Bold = true , Size = "24" } ) ,
new ( "Сумма снятия" , new WordTextProperties { Bold = true , Size = "24" } ) ,
new ( "Дата выполнения" , new WordTextProperties { Bold = true , Size = "24" } )
}
} ;
CreateParagraph ( new WordParagraph
{
Texts = new List < ( string , WordTextProperties ) > { ( "Снятие №" + crediting . Id . ToString ( ) , new WordTextProperties { Bold = true , Size = "24" } ) } ,
TextProperties = new WordTextProperties
{
Size = "24" ,
JustificationType = WordJustificationType . Center
}
} ) ;
List < ( string , WordTextProperties ) > cellList = new ( )
{
new ( crediting . CardNumber , new WordTextProperties { Size = "24" } ) ,
new ( crediting . Sum . ToString ( ) , new WordTextProperties { Size = "24" } ) ,
new ( crediting . DateDebit = = null ? "В обработке" : crediting . DateDebit . ToString ( ) , new WordTextProperties { Size = "24" } )
} ;
rowList . Add ( cellList ) ;
CreateTable ( new WordParagraph
{
RowTexts = rowList ,
TextProperties = new WordTextProperties
{
Size = "24" ,
JustificationType = WordJustificationType . Center
}
} ) ;
}
//формирование списка поступления по каждой карте
var dict = new Dictionary < string , double > ( ) ;
foreach ( var elem in info . Debiting )
{
if ( dict . ContainsKey ( elem . CardNumber ) )
{
dict [ elem . CardNumber ] + = elem . Sum ;
}
else
{
dict [ elem . CardNumber ] = elem . Sum ;
}
}
foreach ( var elem in dict )
{
CreateParagraph ( new WordParagraph
{
Texts = new List < ( string , WordTextProperties ) > { ( "Суммарное снятие с карты №" + elem . Key + ": " + elem . Value . ToString ( ) , new WordTextProperties { Bold = true , Size = "24" } ) } ,
TextProperties = new WordTextProperties
{
Size = "24" ,
JustificationType = WordJustificationType . Both
}
} ) ;
}
SaveWord ( info ) ;
}
private void CreateCashierWord ( WordInfo info )
{
CreateWord ( info ) ;
CreateParagraph ( new WordParagraph
{
Texts = new List < ( string , WordTextProperties ) > { ( info . Title , new WordTextProperties { Bold = true , Size = "24" } ) } ,
TextProperties = new WordTextProperties
{
Size = "24" ,
JustificationType = WordJustificationType . Center
}
} ) ;
foreach ( var crediting in info . Debiting )
{
List < List < ( string , WordTextProperties ) > > rowList = new ( )
{
new ( )
{
new ( "Сумма заявки" , new WordTextProperties { Bold = true , Size = "24" } ) ,
new ( "Дата открытия" , new WordTextProperties { Bold = true , Size = "24" } ) ,
new ( "Статус" , new WordTextProperties { Bold = true , Size = "24" } )
}
} ;
CreateParagraph ( new WordParagraph
{
Texts = new List < ( string , WordTextProperties ) > { ( "Заявка №" + crediting . Id . ToString ( ) , new WordTextProperties { Bold = true , Size = "24" } ) } ,
TextProperties = new WordTextProperties
{
Size = "24" ,
JustificationType = WordJustificationType . Center
}
} ) ;
List < ( string , WordTextProperties ) > cellList = new ( )
{
new ( crediting . Sum . ToString ( ) , new WordTextProperties { Size = "24" } ) ,
new ( crediting . DateDebit . ToString ( ) , new WordTextProperties { Size = "24" } ) ,
new ( crediting . Status . ToString ( ) , new WordTextProperties { Size = "24" } )
} ;
rowList . Add ( cellList ) ;
CreateTable ( new WordParagraph
{
RowTexts = rowList ,
TextProperties = new WordTextProperties
{
Size = "24" ,
JustificationType = WordJustificationType . Center
}
} ) ;
}
SaveWord ( info ) ;
}
/// Создание 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 ) ;
}
2024-04-30 16:37:32 +04:00
}