2023-05-19 23:32:09 +04:00
using BankYouBankruptBusinessLogic.OfficePackage.HelperEnums ;
using BankYouBankruptBusinessLogic.OfficePackage.HelperModels ;
using BankYouBankruptDataModels.Enums ;
using System ;
using System.Collections.Generic ;
using System.Linq ;
using System.Text ;
using System.Threading.Tasks ;
namespace BankYouBankruptBusinessLogic.OfficePackage
{
public abstract class AbstractSaveToWord
{
//метод создания документа
public void CreateDoc ( WordInfo info , OfficeOperationEnum operationEnum )
{
if ( operationEnum = = OfficeOperationEnum . М е ж д у _cче та ми )
{
CreateMoneyTransferWord ( info ) ;
}
if ( operationEnum = = OfficeOperationEnum . П о п о л н е н и е _ка р т )
{
CreateCreditingWord ( info ) ;
}
if ( operationEnum = = OfficeOperationEnum . Cнятие _с _ка р ты )
{
CreateDebitingWord ( info ) ;
}
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 . DateOperation . ToString ( ) , new WordTextProperties { Size = "20" } ) ,
} ;
rowList . Add ( cellList ) ;
CreateTable ( new WordParagraph
{
RowTexts = rowList ,
TextProperties = new WordTextProperties
{
Size = "24" ,
JustificationType = WordJustificationType . Center
}
} ) ;
}
2023-05-20 11:55:07 +04:00
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
}
} ) ;
2023-05-19 23:32:09 +04:00
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 . DateClose = = null ? "В обработке" : crediting . DateClose . ToString ( ) , new WordTextProperties { Size = "24" } )
} ;
rowList . Add ( cellList ) ;
CreateTable ( new WordParagraph
{
RowTexts = rowList ,
TextProperties = new WordTextProperties
{
Size = "24" ,
JustificationType = WordJustificationType . Center
}
} ) ;
}
2023-05-20 11:55:07 +04:00
//формирование списка поступления по каждой карте
var dict = new Dictionary < string , int > ( ) ;
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
}
} ) ;
}
2023-05-19 23:32:09 +04:00
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 . DateClose = = null ? "В обработке" : crediting . DateClose . ToString ( ) , new WordTextProperties { Size = "24" } )
} ;
rowList . Add ( cellList ) ;
CreateTable ( new WordParagraph
{
RowTexts = rowList ,
TextProperties = new WordTextProperties
{
Size = "24" ,
JustificationType = WordJustificationType . Center
}
} ) ;
}
2023-05-20 11:55:07 +04:00
//формирование списка поступления по каждой карте
var dict = new Dictionary < string , int > ( ) ;
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
}
} ) ;
}
2023-05-19 23:32:09 +04:00
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 . DateOpen . 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 ) ;
}
}