PIbd21_Makarov_DV_FlowerShop/FlowerShop/FlowerShopBusinessLogic/OfficePackage/AbstractSaveToExcel.cs

80 lines
2.8 KiB
C#
Raw Normal View History

2024-04-04 00:39:31 +04:00
using DocumentFormat.OpenXml.Office2016.Drawing.ChartDrawing;
using FlowerShopBusinessLogic.OfficePackage.HelperEnums;
using FlowerShopBusinessLogic.OfficePackage.HelperModels;
namespace FlowerShopBusinessLogic.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;
2024-04-04 00:39:31 +04:00
foreach (var fc in info.FlowerComponents)
{
InsertCellInWorksheet(new ExcelCellParameters
{
ColumnName = "A",
RowIndex = rowIndex,
2024-04-04 00:39:31 +04:00
Text = fc.FlowerName,
StyleInfo = ExcelStyleInfoType.Text
});
rowIndex++;
2024-04-04 00:39:31 +04:00
foreach (var (Flower, Count) in fc.Components)
{
InsertCellInWorksheet(new ExcelCellParameters
{
ColumnName = "B",
RowIndex = rowIndex,
2024-04-04 00:39:31 +04:00
Text = Flower,
StyleInfo = ExcelStyleInfoType.TextWithBorder
});
2024-04-04 00:39:31 +04:00
InsertCellInWorksheet(new ExcelCellParameters
{
ColumnName = "C",
RowIndex = rowIndex,
2024-04-04 00:39:31 +04:00
Text = Count.ToString(),
StyleInfo = ExcelStyleInfoType.TextWithBorder
});
2024-04-04 00:39:31 +04:00
rowIndex++;
}
InsertCellInWorksheet(new ExcelCellParameters
{
ColumnName = "A",
RowIndex = rowIndex,
Text = "Итого",
StyleInfo = ExcelStyleInfoType.Text
});
InsertCellInWorksheet(new ExcelCellParameters
{
ColumnName = "C",
RowIndex = rowIndex,
2024-04-04 00:39:31 +04:00
Text = fc.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);
}
}