2024-07-23 20:29:10 +04:00
|
|
|
|
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 {
|
2024-08-01 15:04:29 +04:00
|
|
|
|
Text = $"C {info.DateFrom.ToShortDateString()} по {info.DateTo.ToShortDateString()}",
|
2024-07-23 20:29:10 +04:00
|
|
|
|
Style = "Normal",
|
|
|
|
|
alignmentType = PdfParagraphAlignmentType.Right
|
|
|
|
|
});
|
|
|
|
|
|
2024-07-27 14:58:51 +04:00
|
|
|
|
List<int> PaymentsID = new List<int>();
|
|
|
|
|
foreach (var pr in info.Products) {
|
|
|
|
|
int id = pr.PaymentID;
|
|
|
|
|
if (PaymentsID.Contains(id) == false) {
|
|
|
|
|
PaymentsID.Add(id);
|
2024-07-27 14:34:30 +04:00
|
|
|
|
}
|
2024-07-27 14:58:51 +04:00
|
|
|
|
}
|
2024-07-27 14:34:30 +04:00
|
|
|
|
|
2024-07-27 14:58:51 +04:00
|
|
|
|
foreach (int id in PaymentsID) {
|
|
|
|
|
CreateParagraph(new PdfParagraph {
|
|
|
|
|
Text = $"Номер оплаты: {id}",
|
2024-07-23 20:29:10 +04:00
|
|
|
|
Style = "Normal",
|
|
|
|
|
alignmentType = PdfParagraphAlignmentType.Left,
|
|
|
|
|
});
|
2024-07-27 15:04:04 +04:00
|
|
|
|
CreateTable(new List<string> { "2cm", "4cm", "2cm", "4cm", "4cm" });
|
2024-07-27 14:34:30 +04:00
|
|
|
|
|
2024-07-27 14:58:51 +04:00
|
|
|
|
CreateRow(new PdfRowParameters {
|
|
|
|
|
Text = new List<string> { "Номер товара", "Товар", "Цена", "Количество", "Статья затрат" },
|
|
|
|
|
Style = "NormalTittle",
|
|
|
|
|
alignmentType = PdfParagraphAlignmentType.Center,
|
|
|
|
|
});
|
2024-07-23 20:29:10 +04:00
|
|
|
|
|
2024-07-27 14:58:51 +04:00
|
|
|
|
double sum = 0;
|
|
|
|
|
foreach (var products in info.Products) {
|
|
|
|
|
if (products.PaymentID == id) {
|
|
|
|
|
sum += products.Price * products.count;
|
|
|
|
|
CreateRow(new PdfRowParameters {
|
|
|
|
|
Text = new List<string> { products.ID.ToString(), products.ProductName.ToString(),
|
|
|
|
|
(products.Price * products.count).ToString(), products.count.ToString() ,products.CostItemName.ToString()},
|
|
|
|
|
Style = "Normal",
|
|
|
|
|
alignmentType = PdfParagraphAlignmentType.Left,
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
CreateParagraph(new PdfParagraph {
|
|
|
|
|
Text = $"Итого: {sum}\t",
|
|
|
|
|
Style = "Normal",
|
|
|
|
|
alignmentType = PdfParagraphAlignmentType.Right
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2024-07-23 20:29:10 +04:00
|
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
}
|