using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using CanteenBusinessLogic.OfficePackage.HelperEnums; using CanteenBusinessLogic.OfficePackage.HelperModels; using DocumentFormat.OpenXml.EMMA; namespace CanteenBusinessLogic.OfficePackage { public abstract class AbstractSaveToExcel { public void CreateCooksReport(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 reportCookView in info.Cooks) { InsertCellInWorksheet(new ExcelCellParameters { ColumnName = "A", RowIndex = rowIndex, Text = $"Обед: {reportCookView.Lunch.LunchName}, {reportCookView.Lunch.DateCreate}", StyleInfo = ExcelStyleInfoType.TextWithBroder }); MergeCells(new ExcelMergeParameters { CellFromName = "A" + rowIndex, CellToName = "E" + rowIndex }); 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) { InsertCellInWorksheet(new ExcelCellParameters { ColumnName = "A", RowIndex = rowIndex, Text = $"Продукт: {orderView.Product.ProductName}, {orderView.Product.Price}", StyleInfo = ExcelStyleInfoType.TextWithBroder }); MergeCells(new ExcelMergeParameters { CellFromName = "A" + rowIndex, CellToName = "E" + rowIndex }); rowIndex++; 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++; } } 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); } }