197 lines
6.2 KiB
C#
197 lines
6.2 KiB
C#
using ElectronicsShopBusinessLogic.OfficePackage.HelperEnums;
|
||
using ElectronicsShopBusinessLogic.OfficePackage.HelperModels;
|
||
|
||
|
||
namespace ElectronicsShopBusinessLogic.OfficePackage
|
||
{
|
||
public abstract class AbstractSaveToExcelEmployee
|
||
{
|
||
public byte[]? CreateReport(ExcelInfoEmployee 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 product in info.ListProduct) {
|
||
InsertCellInWorksheet(new ExcelCellParameters {
|
||
ColumnName = "A",
|
||
RowIndex = rowIndex,
|
||
Text = product.ProductName,
|
||
StyleInfo = ExcelStyleInfoType.Text
|
||
});
|
||
rowIndex++;
|
||
foreach (var paymeant in product.Values) {
|
||
InsertCellInWorksheet(new ExcelCellParameters {
|
||
ColumnName = "B",
|
||
RowIndex = rowIndex,
|
||
Text = "Номер оплаты:",
|
||
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 = paymeant.PaymeantID.ToString(),
|
||
StyleInfo = ExcelStyleInfoType.TextWithBroder
|
||
});
|
||
|
||
|
||
InsertCellInWorksheet(new ExcelCellParameters {
|
||
ColumnName = "E",
|
||
RowIndex = rowIndex,
|
||
Text = "В количестве:",
|
||
StyleInfo = ExcelStyleInfoType.TextWithBroder,
|
||
|
||
});
|
||
|
||
InsertCellInWorksheet(new ExcelCellParameters {
|
||
ColumnName = "F",
|
||
RowIndex = rowIndex,
|
||
StyleInfo = ExcelStyleInfoType.TextWithBroder,
|
||
|
||
});
|
||
|
||
MergeCells(new ExcelMergeParameters {
|
||
CellFromName = $"E{rowIndex}",
|
||
CellToName = $"F{rowIndex}"
|
||
});
|
||
|
||
InsertCellInWorksheet(new ExcelCellParameters {
|
||
ColumnName = "G",
|
||
RowIndex = rowIndex,
|
||
Text = paymeant.ProducCount.ToString(),
|
||
StyleInfo = ExcelStyleInfoType.TextWithBroder
|
||
});
|
||
InsertCellInWorksheet(new ExcelCellParameters {
|
||
ColumnName = "H",
|
||
RowIndex = rowIndex,
|
||
Text = "Статус оплаты:",
|
||
StyleInfo = ExcelStyleInfoType.TextWithBroder
|
||
});
|
||
|
||
InsertCellInWorksheet(new ExcelCellParameters {
|
||
ColumnName = "I",
|
||
RowIndex = rowIndex,
|
||
StyleInfo = ExcelStyleInfoType.TextWithBroder,
|
||
|
||
});
|
||
|
||
MergeCells(new ExcelMergeParameters {
|
||
CellFromName = $"H{rowIndex}",
|
||
CellToName = $"I{rowIndex}"
|
||
});
|
||
|
||
InsertCellInWorksheet(new ExcelCellParameters {
|
||
ColumnName = "J",
|
||
RowIndex = rowIndex,
|
||
Text = paymeant.PaymeantStatus.ToString(),
|
||
StyleInfo = ExcelStyleInfoType.TextWithBroder
|
||
});
|
||
|
||
InsertCellInWorksheet(new ExcelCellParameters {
|
||
ColumnName = "k",
|
||
RowIndex = rowIndex,
|
||
StyleInfo = ExcelStyleInfoType.TextWithBroder
|
||
});
|
||
|
||
MergeCells(new ExcelMergeParameters {
|
||
CellFromName = $"J{rowIndex}",
|
||
CellToName = $"K{rowIndex}"
|
||
});
|
||
|
||
InsertCellInWorksheet(new ExcelCellParameters {
|
||
ColumnName = "L",
|
||
RowIndex = rowIndex,
|
||
Text = "Сумма:",
|
||
StyleInfo = ExcelStyleInfoType.TextWithBroder
|
||
});
|
||
|
||
InsertCellInWorksheet(new ExcelCellParameters {
|
||
ColumnName = "M",
|
||
RowIndex = rowIndex,
|
||
Text = paymeant.ProductSum.ToString(),
|
||
StyleInfo = ExcelStyleInfoType.TextWithBroder
|
||
});
|
||
|
||
InsertCellInWorksheet(new ExcelCellParameters {
|
||
ColumnName = "N",
|
||
RowIndex = rowIndex,
|
||
Text = "ID Клиента:",
|
||
StyleInfo = ExcelStyleInfoType.TextWithBroder
|
||
});
|
||
|
||
InsertCellInWorksheet(new ExcelCellParameters {
|
||
ColumnName = "O",
|
||
RowIndex = rowIndex,
|
||
StyleInfo = ExcelStyleInfoType.TextWithBroder
|
||
});
|
||
|
||
|
||
MergeCells(new ExcelMergeParameters {
|
||
CellFromName = $"N{rowIndex}",
|
||
CellToName = $"O{rowIndex}"
|
||
});
|
||
|
||
InsertCellInWorksheet(new ExcelCellParameters {
|
||
ColumnName = "P",
|
||
RowIndex = rowIndex,
|
||
Text = paymeant.ClientID.ToString(),
|
||
StyleInfo = ExcelStyleInfoType.TextWithBroder
|
||
});
|
||
rowIndex++;
|
||
}
|
||
InsertCellInWorksheet(new ExcelCellParameters {
|
||
ColumnName = "A",
|
||
RowIndex = rowIndex,
|
||
Text = "Итого:",
|
||
StyleInfo = ExcelStyleInfoType.Title
|
||
});
|
||
|
||
InsertCellInWorksheet(new ExcelCellParameters {
|
||
ColumnName = "C",
|
||
RowIndex = rowIndex,
|
||
Text = product.Total.ToString(),
|
||
StyleInfo = ExcelStyleInfoType.Title
|
||
});
|
||
rowIndex++;
|
||
}
|
||
|
||
var document = SaveExcel(info);
|
||
return document;
|
||
}
|
||
|
||
protected abstract void CreateExcel(ExcelInfoEmployee info);
|
||
|
||
protected abstract void InsertCellInWorksheet(ExcelCellParameters excelParams);
|
||
|
||
protected abstract void MergeCells(ExcelMergeParameters excelParams);
|
||
|
||
protected abstract byte[]? SaveExcel(ExcelInfoEmployee info);
|
||
}
|
||
}
|