CourseWorkElectronicsShop/ElectronicsShop/ElectronicsShopBusinessLogic/OfficePackage/AbstractSaveToPdfClient.cs

101 lines
4.1 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 ElectronicsShopBusinessLogic.OfficePackage.HelperEnums;
using ElectronicsShopBusinessLogic.OfficePackage.HelperModels;
using MigraDoc.DocumentObjectModel;
using PdfSharp.Pdf;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ElectronicsShopBusinessLogic.OfficePackage
{
public abstract class AbstractSaveToPdfClient {
public PdfDocument CreteDoc (PdfInfoClient info) {
CretePdf(info);
CreateParagraph(new PdfParagraph {
Text = info.Title,
Style = "NormalTitle",
alignmentType = PdfParagraphAlignmentType.Center,
});
CreateParagraph(new PdfParagraph {
Text = $"c {info.DateFrom.ToShortDateString()} по {info.DateTo.ToShortDateString()}",
Style = "Normal",
alignmentType = PdfParagraphAlignmentType.Right
});
CreateTable(new List<string> { "2cm", "6cm", "4cm", "6cm" });
//ТУТ КОСТЫЛЬ КАК взять номер заказа, в info его нема
CreateRow(new PdfRowParameters
{
Text = new List<string> {$"Заказ номер: Костыль " },
Style = "NormalTittle",
alignmentType = PdfParagraphAlignmentType.Center,
});
int StringsEnum = 0;
CreateRow(new PdfRowParameters
{
Text = new List<string> { "Номер", "Товар", "Цена", "Статья затрат" },
Style = "NormalTittle",
alignmentType = PdfParagraphAlignmentType.Center,
});
foreach (var products in info.Products)
{
if (products.ID == 1 && StringsEnum != 0)
{
// Криво считает сумму
CreateParagraph(new PdfParagraph
{
Text = $"Итого: {info.Products.Sum(x => x.Price)}\t",
Style = "Normal",
alignmentType = PdfParagraphAlignmentType.Right
});
CreateTable(new List<string> { "2cm", "6cm", "4cm", "6cm" });
//ТУТ КОСТЫЛЬ КАК взять номер заказа, в info его нема
CreateRow(new PdfRowParameters
{
Text = new List<string> { $"Заказ номер: Костыль " },
Style = "NormalTittle",
alignmentType = PdfParagraphAlignmentType.Center,
});
}
CreateRow(new PdfRowParameters
{
Text = new List<string> { products.ID.ToString(), products.ProductName.ToString(), products.Price.ToString(),
products.CostItemName.ToString()},
Style = "Normal",
alignmentType = PdfParagraphAlignmentType.Left,
});
StringsEnum++;
}
// Криво считает сумму
CreateParagraph(new PdfParagraph {
Text = $"Итого: {info.Products.Sum(x => x.Price)}\t",
Style = "Normal",
alignmentType = PdfParagraphAlignmentType.Right
});
var document = SavePdf(info);
return document;
}
// Создание doc-файла
protected abstract void CretePdf (PdfInfoClient info);
// Создание параграфа с текстом
protected abstract void CreateParagraph(PdfParagraph paragraph);
// Создание таблицы
protected abstract void CreateTable(List<string> columns);
// Создание и заполнение строки
protected abstract void CreateRow(PdfRowParameters rowParameters);
// Сохранение файла
protected abstract PdfDocument SavePdf(PdfInfoClient info);
}
}