2023-05-18 18:01:28 +04:00
|
|
|
|
using DocumentFormat.OpenXml.EMMA;
|
|
|
|
|
using HardwareShopBusinessLogic.OfficePackage.HelperEnums;
|
2023-05-18 17:21:54 +04:00
|
|
|
|
using HardwareShopBusinessLogic.OfficePackage.HelperModels;
|
2023-05-18 18:01:28 +04:00
|
|
|
|
using MigraDoc.Rendering;
|
2023-05-18 17:21:54 +04:00
|
|
|
|
|
|
|
|
|
namespace HardwareShopBusinessLogic.OfficePackage
|
|
|
|
|
{
|
|
|
|
|
public abstract class AbstractSaveToPdf
|
|
|
|
|
{
|
2023-05-18 18:01:28 +04:00
|
|
|
|
public byte[] GetEquipmentReportFile(PdfInfo info)
|
|
|
|
|
{
|
|
|
|
|
CreatePdf(info);
|
2023-05-18 17:21:54 +04:00
|
|
|
|
|
2023-05-18 18:01:28 +04:00
|
|
|
|
CreateParagraph(new PdfParagraph
|
|
|
|
|
{
|
|
|
|
|
Text = info.Title,
|
|
|
|
|
Style = "NormalTitle",
|
|
|
|
|
ParagraphAlignment = PdfParagraphAlignmentType.Center
|
|
|
|
|
});
|
2023-05-18 17:21:54 +04:00
|
|
|
|
|
2023-05-18 18:01:28 +04:00
|
|
|
|
CreateParagraph(new PdfParagraph
|
|
|
|
|
{
|
|
|
|
|
Text = $"за период с {info.DateFrom.ToShortDateString()} " +
|
|
|
|
|
$"по {info.DateTo.ToShortDateString()}",
|
|
|
|
|
Style = "Normal",
|
|
|
|
|
ParagraphAlignment = PdfParagraphAlignmentType.Center
|
|
|
|
|
});
|
2023-05-18 17:21:54 +04:00
|
|
|
|
|
2023-05-18 18:01:28 +04:00
|
|
|
|
CreateTable(new List<string> { "5cm", "5cm", "5cm" });
|
2023-05-18 17:21:54 +04:00
|
|
|
|
|
2023-05-18 18:01:28 +04:00
|
|
|
|
CreateRow(new PdfRowParameters
|
|
|
|
|
{
|
|
|
|
|
Texts = new List<string> { "Комплектация", "Автомобили", "Работы" },
|
|
|
|
|
Style = "NormalTitle",
|
|
|
|
|
ParagraphAlignment = PdfParagraphAlignmentType.Center
|
|
|
|
|
});
|
2023-05-18 17:21:54 +04:00
|
|
|
|
|
2023-05-18 18:01:28 +04:00
|
|
|
|
foreach (var record in info.ReportPurchases)
|
|
|
|
|
{
|
|
|
|
|
List<string> comments = record.Comments;
|
|
|
|
|
List<string> components = record.Components;
|
|
|
|
|
int recordHeight = Math.Max(comments.Count + 1, components.Count + 1);
|
|
|
|
|
for (int i = 0; i < recordHeight; i++)
|
|
|
|
|
{
|
|
|
|
|
List<string> cellsData = new() { "", "", "", "", "" };
|
|
|
|
|
if (i == 0)
|
|
|
|
|
{
|
|
|
|
|
cellsData[0] = record.Id.ToString();
|
|
|
|
|
cellsData[1] = record.PurchaseDate.ToShortDateString();
|
|
|
|
|
cellsData[2] = record.PurchaseSum.ToString("0.00") + " р.";
|
|
|
|
|
CreateRow(new PdfRowParameters
|
|
|
|
|
{
|
|
|
|
|
Texts = cellsData,
|
|
|
|
|
Style = "Normal",
|
|
|
|
|
ParagraphAlignment = PdfParagraphAlignmentType.Left
|
|
|
|
|
});
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
int k = i - 1;
|
|
|
|
|
if (k < comments.Count)
|
|
|
|
|
{
|
|
|
|
|
cellsData[3] = comments[k];
|
|
|
|
|
}
|
|
|
|
|
if (k < components.Count)
|
|
|
|
|
{
|
|
|
|
|
cellsData[4] = components[k];
|
|
|
|
|
}
|
|
|
|
|
CreateRow(new PdfRowParameters
|
|
|
|
|
{
|
|
|
|
|
Texts = cellsData,
|
|
|
|
|
Style = "Normal",
|
|
|
|
|
ParagraphAlignment = PdfParagraphAlignmentType.Left
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-05-18 17:21:54 +04:00
|
|
|
|
|
2023-05-18 18:01:28 +04:00
|
|
|
|
return GetFile(info);
|
|
|
|
|
}
|
2023-05-18 17:21:54 +04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Создание doc-файла
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="info"></param>
|
|
|
|
|
protected abstract void CreatePdf(PdfInfo info);
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Создание параграфа с текстом
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="title"></param>
|
|
|
|
|
/// <param name="style"></param>
|
|
|
|
|
protected abstract void CreateParagraph(PdfParagraph paragraph);
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Создание таблицы
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="title"></param>
|
|
|
|
|
/// <param name="style"></param>
|
|
|
|
|
protected abstract void CreateTable(List<string> columns);
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Создание и заполнение строки
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="rowParameters"></param>
|
|
|
|
|
protected abstract void CreateRow(PdfRowParameters rowParameters);
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Сохранение файла
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="info"></param>
|
|
|
|
|
protected abstract void SavePdf(PdfInfo info);
|
2023-05-18 18:01:28 +04:00
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Сохранение отправляем файл
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="info"></param>
|
|
|
|
|
protected abstract byte[] GetFile(PdfInfo info);
|
2023-05-18 17:21:54 +04:00
|
|
|
|
}
|
|
|
|
|
}
|