PIbd-22_Bazunov_A.I._SushiBar/SushiBar/SushiBarBusinessLogic/OfficePackage/AbstractSaveToExcel.cs

79 lines
2.8 KiB
C#
Raw Normal View History

2023-03-12 20:49:40 +04:00
using SushiBarBusinessLogic.OfficePackage.HelpersEnum;
using SushiBarBusinessLogic.OfficePackage.HelpersModels;
namespace SushiBarBusinessLogic.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"
});
2023-03-14 10:12:32 +04:00
2023-03-12 20:49:40 +04:00
uint rowIndex = 2;
2023-03-14 10:12:32 +04:00
foreach (var sushi in info.Sushi)
2023-03-12 20:49:40 +04:00
{
InsertCellInWorksheet(new ExcelCellParameters
{
ColumnName = "A",
RowIndex = rowIndex,
2023-03-14 10:12:32 +04:00
Text = sushi.SushiName,
2023-03-12 20:49:40 +04:00
StyleInfo = ExcelStyleInfoType.Text
});
rowIndex++;
2023-03-14 10:12:32 +04:00
foreach (var com in sushi.Components)
2023-03-12 20:49:40 +04:00
{
InsertCellInWorksheet(new ExcelCellParameters
{
ColumnName = "B",
RowIndex = rowIndex,
2023-03-14 10:12:32 +04:00
Text = com.Item1,
2023-03-12 20:49:40 +04:00
StyleInfo =
ExcelStyleInfoType.TextWithBroder
});
InsertCellInWorksheet(new ExcelCellParameters
{
ColumnName = "C",
RowIndex = rowIndex,
2023-03-14 10:12:32 +04:00
Text = com.Item2.ToString(),
2023-03-12 20:49:40 +04:00
StyleInfo =
ExcelStyleInfoType.TextWithBroder
});
rowIndex++;
}
InsertCellInWorksheet(new ExcelCellParameters
{
ColumnName = "A",
RowIndex = rowIndex,
2023-03-14 10:12:32 +04:00
Text = "Total",
2023-03-12 20:49:40 +04:00
StyleInfo = ExcelStyleInfoType.Text
});
InsertCellInWorksheet(new ExcelCellParameters
{
ColumnName = "C",
RowIndex = rowIndex,
2023-03-14 10:12:32 +04:00
Text = sushi.TotalCount.ToString(),
2023-03-12 20:49:40 +04:00
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);
}
}