Gismatullin.ISEbd-21.STO.Co.../ServiceStation/ServiceSourceBusinessLogic/OfficePackage/AbstractSaveToExcel.cs
2024-08-15 15:59:47 +04:00

126 lines
4.5 KiB
C#

using ServiceSourceBusinessLogic.OfficePackage.HelperEnums;
using ServiceSourceBusinessLogic.OfficePackage.HelperModels;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ServiceSourceBusinessLogic.OfficePackage
{
public abstract class AbstractSaveToExcel {
public byte[]? CreateReport(ExcelInfo 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 work_client in info.WorksClients) {
InsertCellInWorksheet(new ExcelCellParameters {
ColumnName = "A",
RowIndex = rowIndex,
Text = $"Номер работы: {work_client.WorkId}",
StyleInfo = ExcelStyleInfoType.Text
});
MergeCells(new ExcelMergeParameters {
CellFromName = $"A{rowIndex}",
CellToName = $"B{rowIndex}"
});
InsertCellInWorksheet(new ExcelCellParameters {
ColumnName = "C",
RowIndex = rowIndex,
Text = $"Дата работы: {work_client.Date}",
StyleInfo = ExcelStyleInfoType.Text
});
MergeCells(new ExcelMergeParameters {
CellFromName = $"C{rowIndex}",
CellToName = $"D{rowIndex}"
});
InsertCellInWorksheet(new ExcelCellParameters {
ColumnName = "E",
RowIndex = rowIndex,
Text = $"Стоимость: {work_client.Price}",
StyleInfo = ExcelStyleInfoType.Text
});
MergeCells(new ExcelMergeParameters {
CellFromName = $"E{rowIndex}",
CellToName = $"F{rowIndex}"
});
rowIndex++;
foreach (var (client_id, client_fio) in work_client._Clients) {
InsertCellInWorksheet(new ExcelCellParameters {
ColumnName = "B",
RowIndex = rowIndex,
Text = $"Номер клиента: {client_id}",
StyleInfo = ExcelStyleInfoType.TextWithBorder
});
MergeCells(new ExcelMergeParameters {
CellFromName = $"B{rowIndex}",
CellToName = $"C{rowIndex}"
});
InsertCellInWorksheet(new ExcelCellParameters {
ColumnName = "D",
RowIndex = rowIndex,
Text = $"ФИО клиента: {client_fio}",
StyleInfo = ExcelStyleInfoType.TextWithBorder
});
MergeCells(new ExcelMergeParameters {
CellFromName = $"D{rowIndex}",
CellToName = $"E{rowIndex}"
});
rowIndex++;
}
InsertCellInWorksheet(new ExcelCellParameters {
ColumnName = "A",
RowIndex = rowIndex,
Text = $"Итого: {work_client.TotalCount}",
StyleInfo = ExcelStyleInfoType.Title
});
MergeCells(new ExcelMergeParameters {
CellFromName = $"A{rowIndex}",
CellToName = $"B{rowIndex}"
});
rowIndex++;
}
var document = SaveExcel(info);
return document;
}
// Создание excel-файла
protected abstract void CreateExcel(ExcelInfo info);
// Добавляем новую ячейку в лист
protected abstract void InsertCellInWorksheet(ExcelCellParameters excelCellParameters);
// Объединение ячеек
protected abstract void MergeCells(ExcelMergeParameters mergeParameters);
// Сохранение файла
protected abstract byte[]? SaveExcel(ExcelInfo info);
}
}