2024-07-09 19:40:24 +04:00
|
|
|
|
using DocumentFormat.OpenXml.Packaging;
|
|
|
|
|
using ElectronicsShopBusinessLogic.OfficePackage.HelperEnums;
|
2024-05-30 16:07:54 +04:00
|
|
|
|
using ElectronicsShopBusinessLogic.OfficePackage.HelperModels;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
namespace ElectronicsShopBusinessLogic.OfficePackage
|
|
|
|
|
{
|
2024-05-31 19:49:56 +04:00
|
|
|
|
public abstract class AbstractSaveToExcelClient
|
2024-05-30 16:07:54 +04:00
|
|
|
|
{
|
2024-07-10 18:32:46 +04:00
|
|
|
|
public byte[]? CreateReport(ExcelInfoClient info) {
|
2024-05-30 16:07:54 +04:00
|
|
|
|
CreateExcel(info);
|
|
|
|
|
|
2024-07-02 17:28:23 +04:00
|
|
|
|
InsertCellInWorksheet(new ExcelCellParameters {
|
2024-05-30 16:07:54 +04:00
|
|
|
|
ColumnName = "A",
|
|
|
|
|
RowIndex = 1,
|
|
|
|
|
Text = info.Title,
|
|
|
|
|
StyleInfo = ExcelStyleInfoType.Title
|
|
|
|
|
});
|
|
|
|
|
|
2024-07-02 17:28:23 +04:00
|
|
|
|
MergeCells(new ExcelMergeParameters {
|
2024-05-30 16:07:54 +04:00
|
|
|
|
CellFromName = "A1",
|
|
|
|
|
CellToName = "C1"
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
uint rowIndex = 2;
|
2024-07-02 17:28:23 +04:00
|
|
|
|
foreach (var pp in info.PaymeantProducts) {
|
|
|
|
|
InsertCellInWorksheet(new ExcelCellParameters {
|
2024-05-30 16:07:54 +04:00
|
|
|
|
ColumnName = "A",
|
|
|
|
|
RowIndex = rowIndex,
|
2024-07-02 17:28:23 +04:00
|
|
|
|
Text = pp.PaymeantID.ToString(),
|
2024-05-30 16:07:54 +04:00
|
|
|
|
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-05-30 16:07:54 +04:00
|
|
|
|
|
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
|
|
|
|
});
|
2024-05-30 16:07:54 +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-05-30 16:07:54 +04:00
|
|
|
|
|
2024-07-02 17:28:23 +04:00
|
|
|
|
// Создание excel-файла
|
2024-05-31 19:49:56 +04:00
|
|
|
|
protected abstract void CreateExcel(ExcelInfoClient info);
|
2024-05-30 16:07:54 +04:00
|
|
|
|
|
2024-07-02 17:28:23 +04:00
|
|
|
|
// Добавляем новую ячейку в лист
|
2024-05-30 16:07:54 +04:00
|
|
|
|
protected abstract void InsertCellInWorksheet(ExcelCellParameters excelParams);
|
|
|
|
|
|
2024-07-02 17:28:23 +04:00
|
|
|
|
// Объединение ячеек
|
2024-05-30 16:07:54 +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);
|
2024-05-30 16:07:54 +04:00
|
|
|
|
}
|
|
|
|
|
}
|