487 lines
12 KiB
C#
487 lines
12 KiB
C#
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 AbstractSaveToExcel
|
||
{
|
||
//Создание отчета. Описание методов ниже
|
||
public void CreateReport(ExcelInfo info, ExcelOperationEnum operationEnum)
|
||
{
|
||
if(operationEnum == ExcelOperationEnum.Между_cчетами)
|
||
{
|
||
CreateMoneyTransferExcel(info);
|
||
}
|
||
|
||
if (operationEnum == ExcelOperationEnum.Пополнение_карт)
|
||
{
|
||
CreateCreditingExcel(info);
|
||
}
|
||
|
||
if (operationEnum == ExcelOperationEnum.Cнятие_с_карты)
|
||
{
|
||
CreateDebitingExcel(info);
|
||
}
|
||
|
||
if (operationEnum == ExcelOperationEnum.Для_кассира)
|
||
{
|
||
CreateCashierExcel(info);
|
||
}
|
||
}
|
||
|
||
private void CreateMoneyTransferExcel(ExcelInfo info)
|
||
{
|
||
CreateExcel(info);
|
||
|
||
//вставляет заголовок
|
||
InsertCellInWorksheet(new ExcelCellParameters
|
||
{
|
||
ColumnName = "A",
|
||
RowIndex = 1,
|
||
Text = info.Title,
|
||
StyleInfo = ExcelStyleInfoType.Title
|
||
});
|
||
|
||
//соединяет 3 ячейки для заголовка
|
||
MergeCells(new ExcelMergeParameters
|
||
{
|
||
CellFromName = "A1",
|
||
CellToName = "C1"
|
||
});
|
||
|
||
//номер строчки в докуметне
|
||
uint rowIndex = 2;
|
||
|
||
foreach (var mt in info.MoneyTransfer)
|
||
{
|
||
//вставляет номер перевода
|
||
InsertCellInWorksheet(new ExcelCellParameters
|
||
{
|
||
ColumnName = "A",
|
||
RowIndex = rowIndex,
|
||
Text = "Перевод №" + mt.Id,
|
||
StyleInfo = ExcelStyleInfoType.Text
|
||
});
|
||
|
||
rowIndex++;
|
||
|
||
//строчка с номером счёта отправителя
|
||
InsertCellInWorksheet(new ExcelCellParameters
|
||
{
|
||
ColumnName = "B",
|
||
RowIndex = rowIndex,
|
||
Text = "Номер счёта отправителя: ",
|
||
StyleInfo = ExcelStyleInfoType.TextWithBorder
|
||
});
|
||
|
||
//вставка номера отправителя
|
||
InsertCellInWorksheet(new ExcelCellParameters
|
||
{
|
||
ColumnName = "C",
|
||
RowIndex = rowIndex,
|
||
Text = mt.AccountSenderNumber,
|
||
StyleInfo = ExcelStyleInfoType.TextWithBorder
|
||
});
|
||
|
||
rowIndex++;
|
||
|
||
//строчка с номером счёта получателя
|
||
InsertCellInWorksheet(new ExcelCellParameters
|
||
{
|
||
ColumnName = "B",
|
||
RowIndex = rowIndex,
|
||
Text = "Номер счёта получателя: ",
|
||
StyleInfo = ExcelStyleInfoType.TextWithBorder
|
||
});
|
||
|
||
//вставка номера отправителя
|
||
InsertCellInWorksheet(new ExcelCellParameters
|
||
{
|
||
ColumnName = "C",
|
||
RowIndex = rowIndex,
|
||
Text = mt.AccountPayeeNumber,
|
||
StyleInfo = ExcelStyleInfoType.TextWithBorder
|
||
});
|
||
|
||
rowIndex++;
|
||
|
||
//Вставляет слово "Сумма перевода"
|
||
InsertCellInWorksheet(new ExcelCellParameters
|
||
{
|
||
ColumnName = "A",
|
||
RowIndex = rowIndex,
|
||
Text = "Сумма перевода: ",
|
||
StyleInfo = ExcelStyleInfoType.Text
|
||
});
|
||
|
||
//подсчитывает общее кол-во заготовок в изделии
|
||
InsertCellInWorksheet(new ExcelCellParameters
|
||
{
|
||
ColumnName = "C",
|
||
RowIndex = rowIndex,
|
||
Text = mt.Sum.ToString(),
|
||
StyleInfo = ExcelStyleInfoType.Text
|
||
});
|
||
|
||
rowIndex++;
|
||
}
|
||
|
||
rowIndex++;
|
||
|
||
InsertCellInWorksheet(new ExcelCellParameters
|
||
{
|
||
ColumnName = "A",
|
||
RowIndex = rowIndex,
|
||
Text = "Суммарный объём переводов: ",
|
||
StyleInfo = ExcelStyleInfoType.Text
|
||
});
|
||
|
||
MergeCells(new ExcelMergeParameters
|
||
{
|
||
CellFromName = "A" + rowIndex.ToString(),
|
||
CellToName = "B" + rowIndex.ToString()
|
||
});
|
||
|
||
InsertCellInWorksheet(new ExcelCellParameters
|
||
{
|
||
ColumnName = "C",
|
||
RowIndex = rowIndex,
|
||
Text = info.MoneyTransfer.Sum(x => x.Sum).ToString(),
|
||
StyleInfo = ExcelStyleInfoType.Text
|
||
});
|
||
|
||
SaveExcel(info);
|
||
}
|
||
|
||
private void CreateCreditingExcel(ExcelInfo info)
|
||
{
|
||
CreateExcel(info);
|
||
|
||
//вставляет заголовок
|
||
InsertCellInWorksheet(new ExcelCellParameters
|
||
{
|
||
ColumnName = "A",
|
||
RowIndex = 1,
|
||
Text = info.Title,
|
||
StyleInfo = ExcelStyleInfoType.Title
|
||
});
|
||
|
||
//соединяет 3 ячейки для заголовка
|
||
MergeCells(new ExcelMergeParameters
|
||
{
|
||
CellFromName = "A1",
|
||
CellToName = "E2"
|
||
});
|
||
|
||
//номер строчки в докуметне
|
||
uint rowIndex = 3;
|
||
|
||
foreach (var cr in info.Crediting)
|
||
{
|
||
//вставляет номер перевода
|
||
InsertCellInWorksheet(new ExcelCellParameters
|
||
{
|
||
ColumnName = "A",
|
||
RowIndex = rowIndex,
|
||
Text = "Пополнение №" + cr.Id,
|
||
StyleInfo = ExcelStyleInfoType.Text
|
||
});
|
||
|
||
rowIndex++;
|
||
|
||
//строчка с номером счёта отправителя
|
||
InsertCellInWorksheet(new ExcelCellParameters
|
||
{
|
||
ColumnName = "B",
|
||
RowIndex = rowIndex,
|
||
Text = "Номер карты: ",
|
||
StyleInfo = ExcelStyleInfoType.TextWithBorder
|
||
});
|
||
|
||
//вставка номера отправителя
|
||
InsertCellInWorksheet(new ExcelCellParameters
|
||
{
|
||
ColumnName = "C",
|
||
RowIndex = rowIndex,
|
||
Text = cr.CardNumber,
|
||
StyleInfo = ExcelStyleInfoType.TextWithBorder
|
||
});
|
||
|
||
rowIndex++;
|
||
|
||
//строчка с номером счёта получателя
|
||
InsertCellInWorksheet(new ExcelCellParameters
|
||
{
|
||
ColumnName = "B",
|
||
RowIndex = rowIndex,
|
||
Text = "Сумма пополнения: ",
|
||
StyleInfo = ExcelStyleInfoType.TextWithBorder
|
||
});
|
||
|
||
//вставка номера отправителя
|
||
InsertCellInWorksheet(new ExcelCellParameters
|
||
{
|
||
ColumnName = "C",
|
||
RowIndex = rowIndex,
|
||
Text = cr.Sum.ToString(),
|
||
StyleInfo = ExcelStyleInfoType.TextWithBorder
|
||
});
|
||
|
||
rowIndex++;
|
||
}
|
||
|
||
rowIndex++;
|
||
|
||
InsertCellInWorksheet(new ExcelCellParameters
|
||
{
|
||
ColumnName = "A",
|
||
RowIndex = rowIndex,
|
||
Text = "Суммарный объём пополнений: ",
|
||
StyleInfo = ExcelStyleInfoType.Text
|
||
});
|
||
|
||
MergeCells(new ExcelMergeParameters
|
||
{
|
||
CellFromName = "A" + rowIndex.ToString(),
|
||
CellToName = "B" + rowIndex.ToString()
|
||
});
|
||
|
||
InsertCellInWorksheet(new ExcelCellParameters
|
||
{
|
||
ColumnName = "C",
|
||
RowIndex = rowIndex,
|
||
Text = info.Crediting.Sum(x => x.Sum).ToString(),
|
||
StyleInfo = ExcelStyleInfoType.Text
|
||
});
|
||
|
||
SaveExcel(info);
|
||
}
|
||
|
||
private void CreateDebitingExcel(ExcelInfo info)
|
||
{
|
||
CreateExcel(info);
|
||
|
||
//вставляет заголовок
|
||
InsertCellInWorksheet(new ExcelCellParameters
|
||
{
|
||
ColumnName = "A",
|
||
RowIndex = 1,
|
||
Text = info.Title,
|
||
StyleInfo = ExcelStyleInfoType.Title
|
||
});
|
||
|
||
//соединяет 3 ячейки для заголовка
|
||
MergeCells(new ExcelMergeParameters
|
||
{
|
||
CellFromName = "A1",
|
||
CellToName = "E2"
|
||
});
|
||
|
||
//номер строчки в докуметне
|
||
uint rowIndex = 3;
|
||
|
||
foreach (var cr in info.Debiting)
|
||
{
|
||
//вставляет номер перевода
|
||
InsertCellInWorksheet(new ExcelCellParameters
|
||
{
|
||
ColumnName = "A",
|
||
RowIndex = rowIndex,
|
||
Text = "Снятие №" + cr.Id,
|
||
StyleInfo = ExcelStyleInfoType.Text
|
||
});
|
||
|
||
rowIndex++;
|
||
|
||
//строчка с номером счёта отправителя
|
||
InsertCellInWorksheet(new ExcelCellParameters
|
||
{
|
||
ColumnName = "B",
|
||
RowIndex = rowIndex,
|
||
Text = "Номер карты: ",
|
||
StyleInfo = ExcelStyleInfoType.TextWithBorder
|
||
});
|
||
|
||
//вставка номера отправителя
|
||
InsertCellInWorksheet(new ExcelCellParameters
|
||
{
|
||
ColumnName = "C",
|
||
RowIndex = rowIndex,
|
||
Text = cr.CardNumber,
|
||
StyleInfo = ExcelStyleInfoType.TextWithBorder
|
||
});
|
||
|
||
rowIndex++;
|
||
|
||
//строчка с номером счёта получателя
|
||
InsertCellInWorksheet(new ExcelCellParameters
|
||
{
|
||
ColumnName = "B",
|
||
RowIndex = rowIndex,
|
||
Text = "Сумма снятия: ",
|
||
StyleInfo = ExcelStyleInfoType.TextWithBorder
|
||
});
|
||
|
||
//вставка номера отправителя
|
||
InsertCellInWorksheet(new ExcelCellParameters
|
||
{
|
||
ColumnName = "C",
|
||
RowIndex = rowIndex,
|
||
Text = cr.Sum.ToString(),
|
||
StyleInfo = ExcelStyleInfoType.TextWithBorder
|
||
});
|
||
|
||
rowIndex++;
|
||
}
|
||
|
||
rowIndex++;
|
||
|
||
InsertCellInWorksheet(new ExcelCellParameters
|
||
{
|
||
ColumnName = "A",
|
||
RowIndex = rowIndex,
|
||
Text = "Суммарный объём снятий: ",
|
||
StyleInfo = ExcelStyleInfoType.Text
|
||
});
|
||
|
||
MergeCells(new ExcelMergeParameters
|
||
{
|
||
CellFromName = "A" + rowIndex.ToString(),
|
||
CellToName = "B" + rowIndex.ToString()
|
||
});
|
||
|
||
InsertCellInWorksheet(new ExcelCellParameters
|
||
{
|
||
ColumnName = "C",
|
||
RowIndex = rowIndex,
|
||
Text = info.Debiting.Sum(x => x.Sum).ToString(),
|
||
StyleInfo = ExcelStyleInfoType.Text
|
||
});
|
||
|
||
SaveExcel(info);
|
||
}
|
||
|
||
private void CreateCashierExcel(ExcelInfo info)
|
||
{
|
||
CreateExcel(info);
|
||
|
||
//вставляет заголовок
|
||
InsertCellInWorksheet(new ExcelCellParameters
|
||
{
|
||
ColumnName = "A",
|
||
RowIndex = 1,
|
||
Text = info.Title,
|
||
StyleInfo = ExcelStyleInfoType.Title
|
||
});
|
||
|
||
//соединяет 3 ячейки для заголовка
|
||
MergeCells(new ExcelMergeParameters
|
||
{
|
||
CellFromName = "A1",
|
||
CellToName = "E2"
|
||
});
|
||
|
||
//номер строчки в докуметне
|
||
uint rowIndex = 3;
|
||
|
||
foreach (var cr in info.Debiting)
|
||
{
|
||
//вставляет номер перевода
|
||
InsertCellInWorksheet(new ExcelCellParameters
|
||
{
|
||
ColumnName = "A",
|
||
RowIndex = rowIndex,
|
||
Text = "Снятие №" + cr.Id,
|
||
StyleInfo = ExcelStyleInfoType.Text
|
||
});
|
||
|
||
rowIndex++;
|
||
|
||
//строчка с номером счёта отправителя
|
||
InsertCellInWorksheet(new ExcelCellParameters
|
||
{
|
||
ColumnName = "B",
|
||
RowIndex = rowIndex,
|
||
Text = "Номер карты: ",
|
||
StyleInfo = ExcelStyleInfoType.TextWithBorder
|
||
});
|
||
|
||
//вставка номера отправителя
|
||
InsertCellInWorksheet(new ExcelCellParameters
|
||
{
|
||
ColumnName = "C",
|
||
RowIndex = rowIndex,
|
||
Text = cr.CardNumber,
|
||
StyleInfo = ExcelStyleInfoType.TextWithBorder
|
||
});
|
||
|
||
rowIndex++;
|
||
|
||
//строчка с номером счёта получателя
|
||
InsertCellInWorksheet(new ExcelCellParameters
|
||
{
|
||
ColumnName = "B",
|
||
RowIndex = rowIndex,
|
||
Text = "Сумма снятия: ",
|
||
StyleInfo = ExcelStyleInfoType.TextWithBorder
|
||
});
|
||
|
||
//вставка номера отправителя
|
||
InsertCellInWorksheet(new ExcelCellParameters
|
||
{
|
||
ColumnName = "C",
|
||
RowIndex = rowIndex,
|
||
Text = cr.Sum.ToString(),
|
||
StyleInfo = ExcelStyleInfoType.TextWithBorder
|
||
});
|
||
|
||
rowIndex++;
|
||
}
|
||
|
||
rowIndex++;
|
||
|
||
InsertCellInWorksheet(new ExcelCellParameters
|
||
{
|
||
ColumnName = "A",
|
||
RowIndex = rowIndex,
|
||
Text = "Суммарный объём снятий: ",
|
||
StyleInfo = ExcelStyleInfoType.Text
|
||
});
|
||
|
||
MergeCells(new ExcelMergeParameters
|
||
{
|
||
CellFromName = "A" + rowIndex.ToString(),
|
||
CellToName = "B" + rowIndex.ToString()
|
||
});
|
||
|
||
InsertCellInWorksheet(new ExcelCellParameters
|
||
{
|
||
ColumnName = "C",
|
||
RowIndex = rowIndex,
|
||
Text = info.Crediting.Sum(x => x.Sum).ToString(),
|
||
StyleInfo = ExcelStyleInfoType.Text
|
||
});
|
||
|
||
SaveExcel(info);
|
||
}
|
||
|
||
//Создание 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);
|
||
}
|
||
}
|