CourseWorkElectronicsShop/ElectronicsShop/ElectronicsShopBusinessLogic/OfficePackage/AbstractSaveToExcelEmployee.cs

169 lines
4.9 KiB
C#
Raw Normal View History

using ElectronicsShopBusinessLogic.OfficePackage.HelperEnums;
using ElectronicsShopBusinessLogic.OfficePackage.HelperModels;
namespace ElectronicsShopBusinessLogic.OfficePackage
{
public abstract class AbstractSaveToExcelEmployee
{
2024-07-30 15:36:42 +04:00
public byte[]? CreateReport(ExcelInfoEmployee info)
{
CreateExcel(info);
InsertCellInWorksheet(new ExcelCellParameters
{
ColumnName = "A",
RowIndex = 1,
Text = info.Title,
StyleInfo = ExcelStyleInfoType.Title
});
2024-07-30 15:36:42 +04:00
MergeCells(new ExcelMergeParameters {
CellFromName = "A1",
CellToName = "C1"
});
2024-08-01 16:03:03 +04:00
InsertCellInWorksheet(new ExcelCellParameters {
ColumnName = "A",
RowIndex = 2,
Text = $"С {info.DateFrom.ToShortDateString()} по {info.DateTo.ToShortDateString()}",
StyleInfo = ExcelStyleInfoType.Title
});
MergeCells(new ExcelMergeParameters {
CellFromName = "A2",
CellToName = "H2"
});
uint rowIndex = 3;
2024-07-30 15:36:42 +04:00
foreach (var product in info.ListProduct) {
InsertCellInWorksheet(new ExcelCellParameters {
ColumnName = "A",
RowIndex = rowIndex,
2024-07-30 15:36:42 +04:00
Text = product.ProductName,
StyleInfo = ExcelStyleInfoType.Text
});
rowIndex++;
2024-07-30 15:36:42 +04:00
foreach (var paymeant in product.Values) {
InsertCellInWorksheet(new ExcelCellParameters {
ColumnName = "B",
RowIndex = rowIndex,
Text = "Номер оплаты:",
2024-08-01 16:03:03 +04:00
StyleInfo = ExcelStyleInfoType.TextWithBroder,
});
InsertCellInWorksheet(new ExcelCellParameters {
ColumnName = "c",
RowIndex = rowIndex,
StyleInfo = ExcelStyleInfoType.TextWithBroder,
});
MergeCells(new ExcelMergeParameters {
CellFromName = $"B{rowIndex}",
CellToName = $"C{rowIndex}"
2024-07-30 15:36:42 +04:00
});
2024-08-01 16:03:03 +04:00
2024-07-30 15:36:42 +04:00
InsertCellInWorksheet(new ExcelCellParameters {
2024-08-01 16:03:03 +04:00
ColumnName = "D",
2024-07-30 15:36:42 +04:00
RowIndex = rowIndex,
Text = paymeant.PaymeantID.ToString(),
StyleInfo = ExcelStyleInfoType.TextWithBroder
});
2024-08-01 16:03:03 +04:00
2024-07-30 15:36:42 +04:00
InsertCellInWorksheet(new ExcelCellParameters {
2024-08-01 16:03:03 +04:00
ColumnName = "E",
2024-07-30 15:36:42 +04:00
RowIndex = rowIndex,
Text = "В количестве:",
2024-08-01 16:03:03 +04:00
StyleInfo = ExcelStyleInfoType.TextWithBroder,
2024-07-30 15:36:42 +04:00
});
2024-08-01 16:03:03 +04:00
2024-07-30 15:36:42 +04:00
InsertCellInWorksheet(new ExcelCellParameters {
2024-08-01 16:03:03 +04:00
ColumnName = "F",
RowIndex = rowIndex,
StyleInfo = ExcelStyleInfoType.TextWithBroder,
});
MergeCells(new ExcelMergeParameters {
CellFromName = $"E{rowIndex}",
CellToName = $"F{rowIndex}"
});
InsertCellInWorksheet(new ExcelCellParameters {
ColumnName = "G",
2024-07-30 15:36:42 +04:00
RowIndex = rowIndex,
Text = paymeant.ProducCount.ToString(),
StyleInfo = ExcelStyleInfoType.TextWithBroder
});
InsertCellInWorksheet(new ExcelCellParameters {
2024-08-01 16:03:03 +04:00
ColumnName = "H",
2024-07-30 15:36:42 +04:00
RowIndex = rowIndex,
Text = "Статус оплаты:",
StyleInfo = ExcelStyleInfoType.TextWithBroder
});
2024-08-01 16:03:03 +04:00
2024-07-30 15:36:42 +04:00
InsertCellInWorksheet(new ExcelCellParameters {
2024-08-01 16:03:03 +04:00
ColumnName = "I",
RowIndex = rowIndex,
StyleInfo = ExcelStyleInfoType.TextWithBroder,
});
MergeCells(new ExcelMergeParameters {
CellFromName = $"H{rowIndex}",
CellToName = $"I{rowIndex}"
});
InsertCellInWorksheet(new ExcelCellParameters {
ColumnName = "J",
2024-07-30 15:36:42 +04:00
RowIndex = rowIndex,
Text = paymeant.PaymeantStatus.ToString(),
StyleInfo = ExcelStyleInfoType.TextWithBroder
});
2024-08-01 16:03:03 +04:00
InsertCellInWorksheet(new ExcelCellParameters {
ColumnName = "k",
RowIndex = rowIndex,
StyleInfo = ExcelStyleInfoType.TextWithBroder
});
MergeCells(new ExcelMergeParameters {
CellFromName = $"J{rowIndex}",
CellToName = $"K{rowIndex}"
});
2024-07-30 15:36:42 +04:00
rowIndex++;
}
InsertCellInWorksheet(new ExcelCellParameters {
ColumnName = "A",
RowIndex = rowIndex,
Text = "Итого:",
StyleInfo = ExcelStyleInfoType.Title
});
2024-07-30 15:36:42 +04:00
InsertCellInWorksheet(new ExcelCellParameters {
ColumnName = "C",
RowIndex = rowIndex,
Text = product.Total.ToString(),
StyleInfo = ExcelStyleInfoType.Title
});
rowIndex++;
}
2024-07-30 15:36:42 +04:00
var document = SaveExcel(info);
return document;
}
protected abstract void CreateExcel(ExcelInfoEmployee info);
protected abstract void InsertCellInWorksheet(ExcelCellParameters excelParams);
protected abstract void MergeCells(ExcelMergeParameters excelParams);
2024-07-30 15:36:42 +04:00
protected abstract byte[]? SaveExcel(ExcelInfoEmployee info);
}
}