142 lines
3.7 KiB
C#
142 lines
3.7 KiB
C#
|
using DocumentFormat.OpenXml.Presentation;
|
|||
|
using HospitalBusinessLogics.OfficePackage.HelperEnums;
|
|||
|
using HospitalBusinessLogics.OfficePackage.HelperModels;
|
|||
|
using System;
|
|||
|
using System.Collections.Generic;
|
|||
|
using System.Linq;
|
|||
|
using System.Text;
|
|||
|
using System.Threading.Tasks;
|
|||
|
|
|||
|
namespace HospitalBusinessLogics.OfficePackage
|
|||
|
{
|
|||
|
/// <summary>
|
|||
|
/// Абстрактный класс для создания отчета Excel
|
|||
|
/// </summary>
|
|||
|
public abstract class AbstractSaveToExcel
|
|||
|
{
|
|||
|
/// <summary>
|
|||
|
/// Создать отчет Excel
|
|||
|
/// </summary>
|
|||
|
/// <param name="info"></param>
|
|||
|
public void CreateReport(ExcelInfo info)
|
|||
|
{
|
|||
|
// Создаем файл
|
|||
|
CreateExcel(info);
|
|||
|
|
|||
|
// Создаем заголовок таблицы
|
|||
|
// "Список процедур."
|
|||
|
InsertCellInWorksheet(new ExcelCellParameters
|
|||
|
{
|
|||
|
ColumnName = "A",
|
|||
|
RowIndex = 1,
|
|||
|
Text = info.Title,
|
|||
|
StyleInfo = ExcelStyleInfoType.Title
|
|||
|
});
|
|||
|
// Объединяем ячейки A1:D1 для заголовка таблицы
|
|||
|
MergeCells(new ExcelMergeParameters
|
|||
|
{
|
|||
|
CellFromName = "A1",
|
|||
|
CellToName = "D1"
|
|||
|
});
|
|||
|
|
|||
|
// Записываем основную информацию
|
|||
|
uint rowIndex = 2;
|
|||
|
foreach (var view in info.RecipeProcedures)
|
|||
|
{
|
|||
|
// "Рецепт:"
|
|||
|
InsertCellInWorksheet(new ExcelCellParameters
|
|||
|
{
|
|||
|
ColumnName = "A",
|
|||
|
RowIndex = rowIndex,
|
|||
|
Text = "Рецепт:",
|
|||
|
StyleInfo = ExcelStyleInfoType.SubtitleWithBorder
|
|||
|
});
|
|||
|
|
|||
|
// Номер рецепта "№X"
|
|||
|
InsertCellInWorksheet(new ExcelCellParameters
|
|||
|
{
|
|||
|
ColumnName = "B",
|
|||
|
RowIndex = rowIndex,
|
|||
|
Text = $"№{view.Recipe.Id}",
|
|||
|
StyleInfo = ExcelStyleInfoType.TextWithBorder
|
|||
|
});
|
|||
|
|
|||
|
// "Дата выписки:"
|
|||
|
InsertCellInWorksheet(new ExcelCellParameters
|
|||
|
{
|
|||
|
ColumnName = "C",
|
|||
|
RowIndex = rowIndex,
|
|||
|
Text = "Дата выписки:",
|
|||
|
StyleInfo = ExcelStyleInfoType.SubtitleWithBorder
|
|||
|
});
|
|||
|
|
|||
|
// Дата "XX.XX.XXXX"
|
|||
|
InsertCellInWorksheet(new ExcelCellParameters
|
|||
|
{
|
|||
|
ColumnName = "D",
|
|||
|
RowIndex = rowIndex,
|
|||
|
Text = $"{view.Recipe.IssueDate.ToShortDateString()}",
|
|||
|
StyleInfo = ExcelStyleInfoType.TextWithBorder
|
|||
|
});
|
|||
|
|
|||
|
rowIndex++;
|
|||
|
// "Процедуры:"
|
|||
|
InsertCellInWorksheet(new ExcelCellParameters
|
|||
|
{
|
|||
|
ColumnName = "A",
|
|||
|
RowIndex = rowIndex,
|
|||
|
Text = "Процедуры:",
|
|||
|
StyleInfo = ExcelStyleInfoType.Subtitle
|
|||
|
});
|
|||
|
|
|||
|
// Список процедур
|
|||
|
foreach (var procedure in view.Procedures)
|
|||
|
{
|
|||
|
// "Название процедуры"
|
|||
|
InsertCellInWorksheet(new ExcelCellParameters
|
|||
|
{
|
|||
|
ColumnName = "B",
|
|||
|
RowIndex = rowIndex,
|
|||
|
Text = $"{procedure.Name}",
|
|||
|
StyleInfo = ExcelStyleInfoType.Text
|
|||
|
});
|
|||
|
// Объединяем ячейки BX:DX для названия процедуры
|
|||
|
MergeCells(new ExcelMergeParameters
|
|||
|
{
|
|||
|
CellFromName = "B" + rowIndex,
|
|||
|
CellToName = "D" + rowIndex
|
|||
|
});
|
|||
|
|
|||
|
rowIndex++;
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
SaveExcel(info);
|
|||
|
}
|
|||
|
|
|||
|
/// <summary>
|
|||
|
/// Создать файл Excel
|
|||
|
/// </summary>
|
|||
|
/// <param name="info"></param>
|
|||
|
protected abstract void CreateExcel(ExcelInfo info);
|
|||
|
|
|||
|
/// <summary>
|
|||
|
/// Добавить новую ячейку в лист
|
|||
|
/// </summary>
|
|||
|
/// <param name="excelParams"></param>
|
|||
|
protected abstract void InsertCellInWorksheet(ExcelCellParameters excelParams);
|
|||
|
|
|||
|
/// <summary>
|
|||
|
/// Объединить ячейки
|
|||
|
/// </summary>
|
|||
|
/// <param name="excelParams"></param>
|
|||
|
protected abstract void MergeCells(ExcelMergeParameters excelParams);
|
|||
|
|
|||
|
/// <summary>
|
|||
|
/// Сохранить файл Excel
|
|||
|
/// </summary>
|
|||
|
/// <param name="info"></param>
|
|||
|
protected abstract void SaveExcel(ExcelInfo info);
|
|||
|
}
|
|||
|
}
|