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

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