PIbd-21_BatylkinaAO_MusoevD.../Canteen/CanteenBusinessLogic/OfficePackage/AbstractSaveToExcel.cs

152 lines
5.5 KiB
C#
Raw Normal View History

2023-05-20 12:11:48 +04:00
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using CanteenBusinessLogic.OfficePackage.HelperEnums;
using CanteenBusinessLogic.OfficePackage.HelperModels;
2023-06-14 22:47:30 +04:00
using DocumentFormat.OpenXml.EMMA;
2023-05-20 12:11:48 +04:00
namespace CanteenBusinessLogic.OfficePackage
{
public abstract class AbstractSaveToExcel
{
2023-06-14 22:47:30 +04:00
public void CreateCooksReport(ExcelInfo info)
2023-05-20 12:11:48 +04:00
{
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;
2023-06-14 22:47:30 +04:00
foreach (var reportCookView in info.Cooks)
2023-05-20 12:11:48 +04:00
{
InsertCellInWorksheet(new ExcelCellParameters
{
ColumnName = "A",
RowIndex = rowIndex,
2023-06-14 22:47:30 +04:00
Text = $"Обед: {reportCookView.Lunch.LunchName}, {reportCookView.Lunch.DateCreate}",
2023-05-20 12:11:48 +04:00
StyleInfo = ExcelStyleInfoType.TextWithBroder
});
2023-06-14 22:47:30 +04:00
MergeCells(new ExcelMergeParameters
2023-05-20 12:11:48 +04:00
{
2023-06-14 22:47:30 +04:00
CellFromName = "A" + rowIndex,
CellToName = "E" + rowIndex
2023-05-20 12:11:48 +04:00
});
2023-06-14 22:47:30 +04:00
rowIndex++;
foreach (var cook in reportCookView.Cooks)
{
InsertCellInWorksheet(new ExcelCellParameters
{
ColumnName = "A",
RowIndex = rowIndex,
Text = cook.FIO,
StyleInfo = ExcelStyleInfoType.TextWithBroder
});
InsertCellInWorksheet(new ExcelCellParameters
{
ColumnName = "B",
RowIndex = rowIndex,
Text = "",
StyleInfo = ExcelStyleInfoType.TextWithBroder
});
InsertCellInWorksheet(new ExcelCellParameters
{
ColumnName = "C",
RowIndex = rowIndex,
Text = "",
StyleInfo = ExcelStyleInfoType.TextWithBroder
});
MergeCells(new ExcelMergeParameters
{
CellFromName = "A" + rowIndex,
CellToName = "C" + rowIndex
});
rowIndex++;
}
}
SaveExcel(info);
}
public void CreateOrdersReport(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 orderView in info.Orders)
{
2023-05-20 12:11:48 +04:00
InsertCellInWorksheet(new ExcelCellParameters
{
2023-06-14 22:47:30 +04:00
ColumnName = "A",
2023-05-20 12:11:48 +04:00
RowIndex = rowIndex,
2023-06-19 09:12:18 +04:00
Text = $"Продукт: Id: {orderView.Product.Id}. {orderView.Product.ProductName}, {orderView.Product.Price}",
2023-05-20 12:11:48 +04:00
StyleInfo = ExcelStyleInfoType.TextWithBroder
});
MergeCells(new ExcelMergeParameters
{
CellFromName = "A" + rowIndex,
2023-06-14 22:47:30 +04:00
CellToName = "E" + rowIndex
2023-05-20 12:11:48 +04:00
});
rowIndex++;
2023-06-14 22:47:30 +04:00
foreach (var order in orderView.Orders)
{
InsertCellInWorksheet(new ExcelCellParameters
{
ColumnName = "A",
RowIndex = rowIndex,
Text = $"Id: {order.Id}",
StyleInfo = ExcelStyleInfoType.TextWithBroder
});
InsertCellInWorksheet(new ExcelCellParameters
{
ColumnName = "B",
RowIndex = rowIndex,
Text = "",
StyleInfo = ExcelStyleInfoType.TextWithBroder
});
InsertCellInWorksheet(new ExcelCellParameters
{
ColumnName = "C",
RowIndex = rowIndex,
Text = "",
StyleInfo = ExcelStyleInfoType.TextWithBroder
});
MergeCells(new ExcelMergeParameters
{
CellFromName = "A" + rowIndex,
CellToName = "C" + rowIndex
});
rowIndex++;
}
2023-05-20 12:11:48 +04:00
}
SaveExcel(info);
}
protected abstract void CreateExcel(ExcelInfo info);
protected abstract void InsertCellInWorksheet(ExcelCellParameters excelParams);
protected abstract void MergeCells(ExcelMergeParameters excelParams);
protected abstract void SaveExcel(ExcelInfo info);
}
}