CourseWorkElectronicsShop/ElectronicsShop/ElectronicsShopBusinessLogic/OfficePackage/AbstractSaveToExcelClient.cs
Илья Федотов 1e4ea0c6d7 docx Report exp
2024-07-10 18:32:46 +04:00

82 lines
2.9 KiB
C#

using DocumentFormat.OpenXml.Packaging;
using ElectronicsShopBusinessLogic.OfficePackage.HelperEnums;
using ElectronicsShopBusinessLogic.OfficePackage.HelperModels;
namespace ElectronicsShopBusinessLogic.OfficePackage
{
public abstract class AbstractSaveToExcelClient
{
public byte[]? CreateReport(ExcelInfoClient 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;
foreach (var pp in info.PaymeantProducts) {
InsertCellInWorksheet(new ExcelCellParameters {
ColumnName = "A",
RowIndex = rowIndex,
Text = pp.PaymeantID.ToString(),
StyleInfo = ExcelStyleInfoType.Text
});
rowIndex++;
foreach (var (Product, Count) in pp.Products) {
InsertCellInWorksheet(new ExcelCellParameters {
ColumnName = "B",
RowIndex = rowIndex,
Text = Product,
StyleInfo = ExcelStyleInfoType.TextWithBroder
});
InsertCellInWorksheet(new ExcelCellParameters {
ColumnName = "C",
RowIndex = rowIndex,
Text = Count.ToString(),
StyleInfo = ExcelStyleInfoType.TextWithBroder
});
rowIndex++;
}
InsertCellInWorksheet(new ExcelCellParameters {
ColumnName = "A",
RowIndex = rowIndex,
Text = "Итого",
StyleInfo = ExcelStyleInfoType.Title
});
InsertCellInWorksheet(new ExcelCellParameters {
ColumnName = "C",
RowIndex = rowIndex,
Text = pp.TotalCount.ToString(),
StyleInfo = ExcelStyleInfoType.Title
});
rowIndex++;
}
var documnet = SaveExcel(info);
return documnet;
}
// Создание excel-файла
protected abstract void CreateExcel(ExcelInfoClient info);
// Добавляем новую ячейку в лист
protected abstract void InsertCellInWorksheet(ExcelCellParameters excelParams);
// Объединение ячеек
protected abstract void MergeCells(ExcelMergeParameters excelParams);
// Сохранение файла
protected abstract byte[]? SaveExcel(ExcelInfoClient info);
}
}