123 lines
4.2 KiB
C#
123 lines
4.2 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"
|
||
});
|
||
|
||
InsertCellInWorksheet(new ExcelCellParameters {
|
||
ColumnName = "A",
|
||
RowIndex = 2,
|
||
Text = $"С {info.DateFrom.ToShortDateString()} по {info.DateTo.ToShortDateString()}",
|
||
StyleInfo = ExcelStyleInfoType.Title
|
||
});
|
||
|
||
MergeCells(new ExcelMergeParameters {
|
||
CellFromName = "A2",
|
||
CellToName = "F2"
|
||
});
|
||
|
||
uint rowIndex = 3;
|
||
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, CostItem, Price) in pp.Products) {
|
||
InsertCellInWorksheet(new ExcelCellParameters {
|
||
ColumnName = "B",
|
||
RowIndex = rowIndex,
|
||
Text = Product,
|
||
StyleInfo = ExcelStyleInfoType.TextWithBroder
|
||
});
|
||
|
||
InsertCellInWorksheet(new ExcelCellParameters {
|
||
ColumnName = "C",
|
||
RowIndex = rowIndex,
|
||
StyleInfo = ExcelStyleInfoType.TextWithBroder
|
||
});
|
||
|
||
MergeCells(new ExcelMergeParameters {
|
||
CellFromName = $"B{rowIndex}",
|
||
CellToName = $"C{rowIndex}"
|
||
});
|
||
|
||
InsertCellInWorksheet(new ExcelCellParameters {
|
||
ColumnName = "D",
|
||
RowIndex = rowIndex,
|
||
Text = Count.ToString(),
|
||
StyleInfo = ExcelStyleInfoType.TextWithBroder
|
||
});
|
||
|
||
InsertCellInWorksheet(new ExcelCellParameters {
|
||
ColumnName = "E",
|
||
RowIndex = rowIndex,
|
||
Text = CostItem,
|
||
StyleInfo = ExcelStyleInfoType.TextWithBroder,
|
||
});
|
||
InsertCellInWorksheet(new ExcelCellParameters {
|
||
ColumnName = "F",
|
||
RowIndex = rowIndex,
|
||
Text = Price.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
|
||
});
|
||
InsertCellInWorksheet(new ExcelCellParameters {
|
||
ColumnName = "D",
|
||
RowIndex = rowIndex,
|
||
Text = pp.PaymeantPrice.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);
|
||
}
|
||
} |