using DocumentFormat.OpenXml.Presentation;
using VeterinaryClinicBusinessLogics.OfficePackage.HelperEnums;
using VeterinaryClinicBusinessLogics.OfficePackage.HelperModels;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace VeterinaryClinicBusinessLogics.OfficePackage
{
///
/// Абстрактный класс для создания отчета Excel
///
public abstract class AbstractSaveToExcel
{
///
/// Создать отчет Excel
///
///
public void CreateReport(ExcelInfo info)
{
// Создаем файл
CreateExcel(info);
// Создаем заголовок таблицы
// "Список животных."
InsertCellInWorksheet(new ExcelCellParameters
{
ColumnName = "A",
RowIndex = 1,
Text = info.Title,
StyleInfo = ExcelStyleInfoType.Title
});
// Объединяем ячейки A1:H1 для заголовка таблицы
MergeCells(new ExcelMergeParameters
{
CellFromName = "A1",
CellToName = "H1"
});
// Записываем основную информацию
uint rowIndex = 2;
foreach (var view in info.AnimalServices)
{
// "Животное:"
InsertCellInWorksheet(new ExcelCellParameters
{
ColumnName = "A",
RowIndex = rowIndex,
Text = "Животное:",
StyleInfo = ExcelStyleInfoType.SubtitleWithBorder
});
// Номер животного "№X"
InsertCellInWorksheet(new ExcelCellParameters
{
ColumnName = "B",
RowIndex = rowIndex,
Text = $"№{view.Animal.Id}",
StyleInfo = ExcelStyleInfoType.TextWithBorder
});
// "Вид:"
InsertCellInWorksheet(new ExcelCellParameters
{
ColumnName = "C",
RowIndex = rowIndex,
Text = "Вид:",
StyleInfo = ExcelStyleInfoType.SubtitleWithBorder
});
InsertCellInWorksheet(new ExcelCellParameters
{
ColumnName = "D",
RowIndex = rowIndex,
Text = $"{view.Animal.Type}",
StyleInfo = ExcelStyleInfoType.TextWithBorder
});
// "Порода:"
InsertCellInWorksheet(new ExcelCellParameters
{
ColumnName = "E",
RowIndex = rowIndex,
Text = "Порода:",
StyleInfo = ExcelStyleInfoType.SubtitleWithBorder
});
InsertCellInWorksheet(new ExcelCellParameters
{
ColumnName = "F",
RowIndex = rowIndex,
Text = $"{view.Animal.Breed}",
StyleInfo = ExcelStyleInfoType.TextWithBorder
});
// "Возраст:"
InsertCellInWorksheet(new ExcelCellParameters
{
ColumnName = "G",
RowIndex = rowIndex,
Text = "Возраст:",
StyleInfo = ExcelStyleInfoType.SubtitleWithBorder
});
InsertCellInWorksheet(new ExcelCellParameters
{
ColumnName = "H",
RowIndex = rowIndex,
Text = $"{view.Animal.Age}",
StyleInfo = ExcelStyleInfoType.TextWithBorder
});
rowIndex++;
// "Услуги:"
InsertCellInWorksheet(new ExcelCellParameters
{
ColumnName = "A",
RowIndex = rowIndex,
Text = "Услуги:",
StyleInfo = ExcelStyleInfoType.Subtitle
});
MergeCells(new ExcelMergeParameters
{
CellFromName = "A" + rowIndex,
CellToName = "B" + rowIndex
});
// Список услуг
foreach (var service in view.Services)
{
// "Название услуги"
InsertCellInWorksheet(new ExcelCellParameters
{
ColumnName = "C",
RowIndex = rowIndex,
Text = $"{service.Name}",
StyleInfo = ExcelStyleInfoType.Text
});
MergeCells(new ExcelMergeParameters
{
CellFromName = "C" + rowIndex,
CellToName = "E" + rowIndex
});
// "Стоимость услуги"
InsertCellInWorksheet(new ExcelCellParameters
{
ColumnName = "F",
RowIndex = rowIndex,
Text = $"{service.Cost}",
StyleInfo = ExcelStyleInfoType.Text
});
MergeCells(new ExcelMergeParameters
{
CellFromName = "F" + rowIndex,
CellToName = "H" + rowIndex
});
rowIndex++;
}
}
SaveExcel(info);
}
///
/// Создать файл Excel
///
///
protected abstract void CreateExcel(ExcelInfo info);
///
/// Добавить новую ячейку в лист
///
///
protected abstract void InsertCellInWorksheet(ExcelCellParameters excelParams);
///
/// Объединить ячейки
///
///
protected abstract void MergeCells(ExcelMergeParameters excelParams);
///
/// Сохранить файл Excel
///
///
protected abstract void SaveExcel(ExcelInfo info);
}
}