CourseWorkElectronicsShop/ElectronicsShop/ElectronicsShopBusinessLogic/OfficePackage/AbstractSaveToExcelClient.cs

82 lines
2.9 KiB
C#
Raw Normal View History

2024-07-09 19:40:24 +04:00
using DocumentFormat.OpenXml.Packaging;
using ElectronicsShopBusinessLogic.OfficePackage.HelperEnums;
using ElectronicsShopBusinessLogic.OfficePackage.HelperModels;
namespace ElectronicsShopBusinessLogic.OfficePackage
{
public abstract class AbstractSaveToExcelClient
{
2024-07-10 18:32:46 +04:00
public byte[]? CreateReport(ExcelInfoClient info) {
CreateExcel(info);
2024-07-02 17:28:23 +04:00
InsertCellInWorksheet(new ExcelCellParameters {
ColumnName = "A",
RowIndex = 1,
Text = info.Title,
StyleInfo = ExcelStyleInfoType.Title
});
2024-07-02 17:28:23 +04:00
MergeCells(new ExcelMergeParameters {
CellFromName = "A1",
CellToName = "C1"
});
uint rowIndex = 2;
2024-07-02 17:28:23 +04:00
foreach (var pp in info.PaymeantProducts) {
InsertCellInWorksheet(new ExcelCellParameters {
ColumnName = "A",
RowIndex = rowIndex,
2024-07-02 17:28:23 +04:00
Text = pp.PaymeantID.ToString(),
StyleInfo = ExcelStyleInfoType.Text
});
rowIndex++;
2024-07-02 17:28:23 +04:00
foreach (var (Product, Count) in pp.Products) {
InsertCellInWorksheet(new ExcelCellParameters {
ColumnName = "B",
RowIndex = rowIndex,
Text = Product,
StyleInfo = ExcelStyleInfoType.TextWithBroder
});
2024-07-02 17:28:23 +04:00
InsertCellInWorksheet(new ExcelCellParameters {
ColumnName = "C",
RowIndex = rowIndex,
Text = Count.ToString(),
StyleInfo = ExcelStyleInfoType.TextWithBroder
});
rowIndex++;
}
InsertCellInWorksheet(new ExcelCellParameters {
ColumnName = "A",
2024-06-01 02:22:36 +04:00
RowIndex = rowIndex,
2024-07-02 17:28:23 +04:00
Text = "Итого",
StyleInfo = ExcelStyleInfoType.Title
2024-06-01 02:22:36 +04:00
});
2024-07-02 17:28:23 +04:00
InsertCellInWorksheet(new ExcelCellParameters {
2024-06-01 02:22:36 +04:00
ColumnName = "C",
RowIndex = rowIndex,
2024-07-02 17:28:23 +04:00
Text = pp.TotalCount.ToString(),
StyleInfo = ExcelStyleInfoType.Title
2024-06-01 02:22:36 +04:00
});
rowIndex++;
}
2024-07-09 19:40:24 +04:00
var documnet = SaveExcel(info);
return documnet;
2024-07-02 17:28:23 +04:00
}
2024-07-02 17:28:23 +04:00
// Создание excel-файла
protected abstract void CreateExcel(ExcelInfoClient info);
2024-07-02 17:28:23 +04:00
// Добавляем новую ячейку в лист
protected abstract void InsertCellInWorksheet(ExcelCellParameters excelParams);
2024-07-02 17:28:23 +04:00
// Объединение ячеек
protected abstract void MergeCells(ExcelMergeParameters excelParams);
2024-07-02 17:28:23 +04:00
// Сохранение файла
2024-07-10 18:32:46 +04:00
protected abstract byte[]? SaveExcel(ExcelInfoClient info);
}
}