Romanov_E.V._CourseWork_Vet.../VeterinaryClinicBusinessLogic/OfficePackage/AbstractSaveToExcel.cs

84 lines
2.9 KiB
C#
Raw Normal View History

2023-04-07 14:13:18 +04:00
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using VeterinaryClinicBusinessLogic.OfficePackage.HelperEnums;
using VeterinaryClinicBusinessLogic.OfficePackage.HelperModels;
namespace VeterinaryClinicBusinessLogic.OfficePackage
{
public abstract class AbstractSaveToExcel
{
public void CreateReport(ExcelInfo info)
{
CreateExcel(info);
InsertCellInWorksheet(new ExcelCellParameters
{
ColumnName = "A",
RowIndex = 1,
Text = info.Title,
StyleInfo = ExcelStyleInfoType.Title
});
MergeCells(new ExcelMergeParameters
{
CellFromName = "A1",
CellToName = "C1"
});
uint rowIndex = 2;
2023-04-07 14:47:26 +04:00
foreach (var pc in info.MedicineMedications)
2023-04-07 14:13:18 +04:00
{
InsertCellInWorksheet(new ExcelCellParameters
{
ColumnName = "A",
RowIndex = rowIndex,
2023-04-07 14:47:26 +04:00
Text = pc.MedicineName,
2023-04-07 14:13:18 +04:00
StyleInfo = ExcelStyleInfoType.Text
});
rowIndex++;
2023-04-07 14:47:26 +04:00
foreach (var Medicine in pc.Medications)
2023-04-07 14:13:18 +04:00
{
InsertCellInWorksheet(new ExcelCellParameters
{
ColumnName = "B",
RowIndex = rowIndex,
2023-04-07 14:47:26 +04:00
Text = Medicine.Item1,
2023-04-07 14:13:18 +04:00
StyleInfo =
ExcelStyleInfoType.TextWithBroder
});
InsertCellInWorksheet(new ExcelCellParameters
{
ColumnName = "C",
RowIndex = rowIndex,
2023-04-07 14:47:26 +04:00
Text = Medicine.Item2.ToString(),
2023-04-07 14:13:18 +04:00
StyleInfo =
ExcelStyleInfoType.TextWithBroder
});
rowIndex++;
}
InsertCellInWorksheet(new ExcelCellParameters
{
ColumnName = "A",
RowIndex = rowIndex,
Text = "Итого",
StyleInfo = ExcelStyleInfoType.Text
});
InsertCellInWorksheet(new ExcelCellParameters
{
ColumnName = "C",
RowIndex = rowIndex,
Text = pc.TotalCount.ToString(),
StyleInfo = ExcelStyleInfoType.Text
});
rowIndex++;
}
SaveExcel(info);
}
protected abstract void CreateExcel(ExcelInfo info);
protected abstract void InsertCellInWorksheet(ExcelCellParameters
excelParams);
protected abstract void MergeCells(ExcelMergeParameters excelParams);
protected abstract void SaveExcel(ExcelInfo info);
}
}