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 CanteenContracts.ViewModels; namespace CanteenBusinessLogic.OfficePackage { public abstract class AbstractSaveToPdf { public void CreateLunchDoc(PdfInfo info) { CreatePdf(info); CreateParagraph(new PdfParagraph { Text = info.Title, Style = "NormalTitle" }); CreateParagraph(new PdfParagraph { Text = $"с { info.DateAfter.ToShortDateString() } по { info.DateBefore.ToShortDateString() }", Style = "Normal" }); CreateTable(new List { "2cm", "2cm", "2cm", "5cm", "3cm", "3cm" }); CreateRow(new PdfRowParameters { Texts = new List { "Дата обеда", "Стоимость обеда", "Заказ", "Повар"}, Style = "NormalTitle", ParagraphAlignment = PdfParagraphAlignmentType.Center }); foreach (var lunch in info.Lunches) { CreateRow(new PdfRowParameters { Texts = new List { lunch.DateCreate.ToShortDateString(), lunch.Sum.ToString(), "", ""}, Style = "Normal", ParagraphAlignment = PdfParagraphAlignmentType.Left }); // Вывод заказов для каждого обеда foreach (var order in lunch.Orders) { CreateRow(new PdfRowParameters { Texts = new List { "", "", order.Id.ToString(), ""}, Style = "Normal", ParagraphAlignment = PdfParagraphAlignmentType.Left }); // Вывод поваров для каждого заказа foreach (var cook in order.OrderCooks) { CreateRow(new PdfRowParameters { Texts = new List { "", "", "", cook.Value.FIO }, Style = "Normal", ParagraphAlignment = PdfParagraphAlignmentType.Left }); } } } SavePdf(info); } public void CreateCookDoc(PdfInfo info) { CreatePdf(info); CreateParagraph(new PdfParagraph { Text = info.Title, Style = "NormalTitle" }); CreateParagraph(new PdfParagraph { Text = $"с {info.DateAfter.ToShortDateString()} по {info.DateBefore.ToShortDateString()}", Style = "Normal" }); CreateTable(new List { "2cm", "3cm", "2cm", "2cm", "2cm" }); CreateRow(new PdfRowParameters { Texts = new List { "Id повара", "ФИО повара", "Id обеда", "Дата начала обеда", "Дата окончания обеда" }, Style = "NormalTitle", ParagraphAlignment = PdfParagraphAlignmentType.Center }); foreach (var cook in info.Cooks) { CreateRow(new PdfRowParameters { Texts = new List { cook.CookId.ToString(), cook.FIO.ToString(), "", "", "" }, Style = "Normal", ParagraphAlignment = PdfParagraphAlignmentType.Left }); foreach (var lunch in cook.Lunches) { CreateRow(new PdfRowParameters { Texts = new List { "", "", lunch.Id.ToString(), lunch.DateCreate.ToShortDateString(), lunch.DateImplement?.ToShortDateString() }, Style = "Normal", ParagraphAlignment = PdfParagraphAlignmentType.Left }); } } SavePdf(info); } protected abstract void CreatePdf(PdfInfo info); protected abstract void CreateParagraph(PdfParagraph paragraph); protected abstract void CreateTable(List columns); protected abstract void CreateRow(PdfRowParameters rowParameters); protected abstract void SavePdf(PdfInfo info); } }