97 lines
3.7 KiB
C#
Raw Normal View History

2023-03-12 20:49:40 +04:00
using SushiBarBusinessLogic.OfficePackage.HelpersEnum;
using SushiBarBusinessLogic.OfficePackage.HelpersModels;
namespace SushiBarBusinessLogic.OfficePackage
{
public abstract class AbstractSaveToPdf
{
public void CreateDoc(PdfInfo info)
{
CreatePdf(info);
CreateParagraph(new PdfParagraph
{
Text = info.Title,
Style = "NormalTitle",
ParagraphAlignment = PdfParagraphAlignmentType.Center
});
CreateParagraph(new PdfParagraph
{
Text = $"с{ info.DateFrom.ToShortDateString() } по { info.DateTo.ToShortDateString() }", Style= "Normal",
ParagraphAlignment = PdfParagraphAlignmentType.Center
});
2023-03-14 10:12:32 +04:00
CreateTable(new List<string> { "2cm", "3cm", "6cm", "2cm", "3cm" });
2023-03-12 20:49:40 +04:00
CreateRow(new PdfRowParameters
{
2023-03-14 10:12:32 +04:00
Texts = new List<string> { "Id", "Date", "Sushi", "Status", "Cost" },
2023-03-12 20:49:40 +04:00
Style = "NormalTitle",
ParagraphAlignment = PdfParagraphAlignmentType.Center
});
foreach (var order in info.Orders)
{
CreateRow(new PdfRowParameters
{
2023-03-14 10:12:32 +04:00
Texts = new List<string> {
order.Id.ToString(),
order.DateCreate.ToShortDateString(),
order.SushiName,
order.Status.ToString(),
order.Sum.ToString()
},
2023-03-12 20:49:40 +04:00
Style = "Normal",
ParagraphAlignment = PdfParagraphAlignmentType.Left
});
}
CreateParagraph(new PdfParagraph
{
2023-03-14 10:12:32 +04:00
Text = $"Total: {info.Orders.Sum(x=> x.Sum)}\t",
2023-03-12 20:49:40 +04:00
Style = "Normal",
ParagraphAlignment = PdfParagraphAlignmentType.Rigth
});
SavePdf(info);
}
2023-04-11 11:12:55 +04:00
public void CreateDocGroupedByDate(PdfInfo info)
{
CreatePdf(info);
CreateParagraph(new PdfParagraph
{
Text = info.Title,
Style = "NormalTitle",
ParagraphAlignment = PdfParagraphAlignmentType.Center
});
CreateTable(new List<string> { "4cm", "4cm", "4cm" });
CreateRow(new PdfRowParameters
{
Texts = new List<string> { "Date", "Count", "Sum" },
Style = "NormalTitle",
ParagraphAlignment = PdfParagraphAlignmentType.Center
});
foreach (var order in info.GroupOrders)
{
CreateRow(new PdfRowParameters
{
Texts = new List<string> {
order.OrderDate.ToShortDateString(),
order.Count.ToString(),
order.Sum.ToString()
},
Style = "Normal",
ParagraphAlignment = PdfParagraphAlignmentType.Left
});
}
CreateParagraph(new PdfParagraph
{
Text = $"Total: {info.GroupOrders.Sum(x=> x.Sum)}\t",
Style = "Normal",
ParagraphAlignment = PdfParagraphAlignmentType.Rigth
});
SavePdf(info);
}
2023-03-12 20:49:40 +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);
}
}