Coursework_ComputerStore_Li.../ComputerStoreBusinessLogic/OfficePackage/AbstractSaveToPDF.cs

89 lines
3.7 KiB
C#

using ComputerStoreBusinessLogic.OfficePackage.HelperEnums;
using ComputerStoreBusinessLogic.OfficePackage.HelperModels;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ComputerStoreBusinessLogic.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 = $"from {info.DateFrom.ToShortDateString()} to {info.DateTo.ToShortDateString()}",
Style = "Normal",
ParagraphAlignment = PDFParagraphAlignmentType.Center
});
CreateTable(new List<string> { "6cm", "6cm", "3cm", "5cm"});
CreateRow(new PDFRowParameters
{
Texts = new List<string> { "PC's name", "Employee's username", "Total", "Components" },
Style = "NormalTitle",
ParagraphAlignment = PDFParagraphAlignmentType.Center
});
foreach (var pc in info.PCs)
{
CreateComplicatedRow(new PDFRowParameters
{
Texts = new List<string> { pc.PCName, pc.EmployeeUsername, pc.Price.ToString() },
Style = "Normal",
ParagraphAlignment = PDFParagraphAlignmentType.Left
},pc.Components);
}
CreateTable(new List<string> { "6cm", "6cm", "3cm", "5cm" });
CreateRow(new PDFRowParameters
{
Texts = new List<string> { "Product's name", "Employee's username", "Total", "Components" },
Style = "NormalTitle",
ParagraphAlignment = PDFParagraphAlignmentType.Center
});
foreach (var product in info.Products)
{
CreateComplicatedRow(new PDFRowParameters
{
Texts = new List<string> { product.ProductName, product.EmployeeUsername, product.Price.ToString() },
Style = "Normal",
ParagraphAlignment = PDFParagraphAlignmentType.Left
},product.Components);
}
CreateParagraph(new PDFParagraph
{
Text = $"Total by products: {info.Products.Sum(x => x.Price)} + {info.Products}\t",
Style = "Normal",
ParagraphAlignment = PDFParagraphAlignmentType.Right
});
CreateParagraph(new PDFParagraph
{
Text = $"Total by pcs: {info.PCs.Sum(x => x.Price)}\t",
Style = "Normal",
ParagraphAlignment = PDFParagraphAlignmentType.Right
});
CreateParagraph(new PDFParagraph
{
Text = $"Total: {info.PCs.Sum(x => x.Price)} + {info.Products.Sum(x => x.Price)}\t",
Style = "Normal",
ParagraphAlignment = PDFParagraphAlignmentType.Right
});
SavePDF(info);
}
protected abstract void SavePDF(PDFInfo info);
protected abstract void CreatePDF(PDFInfo info);
protected abstract void CreateParagraph(PDFParagraph PDFParagraph);
protected abstract void CreateTable(List<string> columns);
protected abstract void CreateRow(PDFRowParameters rowParameters);
protected abstract void CreateComplicatedRow(PDFRowParameters rowParameters, IEnumerable<(string,int)> components);
}
}