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

114 lines
4.6 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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<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);
}
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);
}
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);
}
}