PIAPS_CW/BusinessLogic/OfficePackage/AbstractSaveToPdf.cs

81 lines
3.5 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 BusinessLogic.BusinessLogic;
using BusinessLogic.OfficePackage.HelperEnums;
using BusinessLogic.OfficePackage.HelperModels;
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace BusinessLogic.OfficePackage
{
public abstract class AbstractSaveToPdf
{
public void CreateDoc(PdfInfo info)
{
CreatePdf(info);
CreateParagraph(new PdfParagraph
{
Text = $"{info.Title}\nОт {DateTime.UtcNow}",
Style = "NormalTitle",
ParagraphAlignment = PdfParagraphAlignmentType.Center
});
string dateArriving = info.Supply.DateArriving.HasValue ? info.Supply.DateArriving.ToString() : "-";
string dateComplete = info.Supply.DateComplete.HasValue ? info.Supply.DateComplete.ToString() : "-";
CreateParagraph(new PdfParagraph
{
Text = $"Поставщик: {info.Supply.SupplierName}\nДата создания поставки: {info.Supply.Date}\nДата отправления поставки: {dateArriving}\nДата получения поставки: {dateComplete}\nСтатус: {info.Supply.Status}",
Style = "NormalTitle",
ParagraphAlignment = PdfParagraphAlignmentType.Right
});
CreateTable(new List<string> { "5cm", "10cm"});
CreateRow(new PdfRowParameters
{
Texts = new List<string> { "Id", "Информация" },
Style = "NormalTitle",
ParagraphAlignment = PdfParagraphAlignmentType.Center
});
CreateRow(new PdfRowParameters
{
Texts = new List<string> { info.Supply.Id.ToString(), info.Supply.Name, },
Style = "Normal",
ParagraphAlignment = PdfParagraphAlignmentType.Left
});
CreateParagraph(new PdfParagraph
{
Text = "Товары",
Style = "NormalTitle",
ParagraphAlignment = PdfParagraphAlignmentType.Center
});
CreateTable(new List<string> { "5cm", "5cm", "3cm", "2cm" });
CreateRow(new PdfRowParameters
{
Texts = new List<string> { "Id", "Название", "Цена", "Кол-во" },
Style = "NormalTitle",
ParagraphAlignment = PdfParagraphAlignmentType.Center
});
foreach (var product in info.Supply.Products.Values)
{
CreateRow(new PdfRowParameters
{
Texts = new List<string> { product.Item1.Id.ToString(), product.Item1.Name, product.Item1.Price.ToString(), product.Item2.ToString() },
});
}
CreateParagraph(new PdfParagraph
{
Text = $"Итого: {info.Supply.Price}",
Style = "Normal",
ParagraphAlignment = PdfParagraphAlignmentType.Right
});
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 CreateImage(string path);
protected abstract void SavePdf(PdfInfo info);
}
}