124 lines
4.5 KiB
C#
124 lines
4.5 KiB
C#
using HospitalBusinessLogic.OfficePackage.HelperEnums;
|
|
using HospitalBusinessLogic.OfficePackage.HelperModels;
|
|
|
|
namespace HospitalBusinessLogic.OfficePackage
|
|
{
|
|
public abstract class AbstractSaveToExcel
|
|
{
|
|
/// <summary>
|
|
/// Создание отчета
|
|
/// </summary>
|
|
/// <param name="info"></param>
|
|
public MemoryStream CreateReport(ExcelInfo info)
|
|
{
|
|
CreateExcel(info);
|
|
// название таблицы
|
|
InsertCellInWorksheet(new ExcelCellParameters
|
|
{
|
|
ColumnName = "A",
|
|
RowIndex = 1,
|
|
Text = info.Title,
|
|
StyleInfo = ExcelStyleInfoType.TextWithBroder
|
|
});
|
|
MergeCells(new ExcelMergeParameters
|
|
{
|
|
CellFromName = "A1",
|
|
CellToName = "E1"
|
|
});
|
|
// названия столбцов
|
|
char columnName = 'A';
|
|
foreach (var header in info.Headers)
|
|
{
|
|
InsertCellInWorksheet(new ExcelCellParameters
|
|
{
|
|
ColumnName = columnName.ToString(),
|
|
RowIndex = 2,
|
|
Text = header,
|
|
StyleInfo = ExcelStyleInfoType.TextWithBroder
|
|
});
|
|
columnName++;
|
|
}
|
|
|
|
|
|
uint rowIndex = 3;
|
|
foreach (var element in info.PatientsMedicines)
|
|
{
|
|
InsertCellInWorksheet(new ExcelCellParameters
|
|
{
|
|
ColumnName = "A",
|
|
RowIndex = rowIndex,
|
|
Text = element.MedicineName,
|
|
StyleInfo = ExcelStyleInfoType.Text
|
|
});
|
|
rowIndex++;
|
|
int patientNum = 1;
|
|
foreach (var patient in element.Patients)
|
|
{
|
|
InsertCellInWorksheet(new ExcelCellParameters
|
|
{
|
|
ColumnName = "A",
|
|
RowIndex = rowIndex,
|
|
Text = patientNum.ToString(),
|
|
StyleInfo = ExcelStyleInfoType.TextWithBroder
|
|
});
|
|
|
|
InsertCellInWorksheet(new ExcelCellParameters
|
|
{
|
|
ColumnName = "B",
|
|
RowIndex = rowIndex,
|
|
Text = patient.Item1,
|
|
StyleInfo =
|
|
ExcelStyleInfoType.TextWithBroder
|
|
});
|
|
|
|
InsertCellInWorksheet(new ExcelCellParameters
|
|
{
|
|
ColumnName = "C",
|
|
RowIndex = rowIndex,
|
|
Text = patient.Item2,
|
|
StyleInfo = ExcelStyleInfoType.TextWithBroder
|
|
});
|
|
InsertCellInWorksheet(new ExcelCellParameters
|
|
{
|
|
ColumnName = "D",
|
|
RowIndex = rowIndex,
|
|
Text = patient.Item3 != null ? patient.Item3 : "",
|
|
StyleInfo = ExcelStyleInfoType.TextWithBroder
|
|
});
|
|
InsertCellInWorksheet(new ExcelCellParameters
|
|
{
|
|
ColumnName = "E",
|
|
RowIndex = rowIndex,
|
|
Text = patient.Item4.ToString(),
|
|
StyleInfo = ExcelStyleInfoType.TextWithBroder
|
|
});
|
|
rowIndex++;
|
|
patientNum++;
|
|
}
|
|
rowIndex++;
|
|
}
|
|
return SaveExcel(info);
|
|
}
|
|
/// <summary>
|
|
/// Создание excel-файла
|
|
/// </summary>
|
|
/// <param name="info"></param>
|
|
protected abstract void CreateExcel(ExcelInfo info);
|
|
/// <summary>
|
|
/// Добавляем новую ячейку в лист
|
|
/// </summary>
|
|
/// <param name="cellParameters"></param>
|
|
protected abstract void InsertCellInWorksheet(ExcelCellParameters excelParams);
|
|
/// <summary>
|
|
/// Объединение ячеек
|
|
/// </summary>
|
|
/// <param name="mergeParameters"></param>
|
|
protected abstract void MergeCells(ExcelMergeParameters excelParams);
|
|
/// <summary>
|
|
/// Сохранение файла
|
|
/// </summary>
|
|
/// <param name="info"></param>
|
|
protected abstract MemoryStream SaveExcel(ExcelInfo info);
|
|
}
|
|
}
|