169 lines
4.9 KiB
C#
169 lines
4.9 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"
|
||
});
|
||
|
||
InsertCellInWorksheet(new ExcelCellParameters {
|
||
ColumnName = "A",
|
||
RowIndex = 2,
|
||
Text = $"С {info.DateFrom.ToShortDateString()} по {info.DateTo.ToShortDateString()}",
|
||
StyleInfo = ExcelStyleInfoType.Title
|
||
});
|
||
|
||
MergeCells(new ExcelMergeParameters {
|
||
CellFromName = "A2",
|
||
CellToName = "K2"
|
||
});
|
||
|
||
uint rowIndex = 3;
|
||
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}"
|
||
});
|
||
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);
|
||
}
|
||
}
|