diff --git a/BusinessLogic/BusinessLogic/ReportLogic.cs b/BusinessLogic/BusinessLogic/ReportLogic.cs index 652fb2f..619fefe 100644 --- a/BusinessLogic/BusinessLogic/ReportLogic.cs +++ b/BusinessLogic/BusinessLogic/ReportLogic.cs @@ -62,7 +62,7 @@ namespace BusinessLogic.BusinessLogic _saveToPdf.CreateDoc(new PdfInfo { FileName = model.FileName, - Title = "Отчёт о поставке", + Title = "Накладная", Date = model.Date!.Value, Supply = _supplyStorage.GetElement(new SupplySearchModel() { diff --git a/BusinessLogic/OfficePackage/AbstractSaveToPdf.cs b/BusinessLogic/OfficePackage/AbstractSaveToPdf.cs index b634b0e..8d7a2fc 100644 --- a/BusinessLogic/OfficePackage/AbstractSaveToPdf.cs +++ b/BusinessLogic/OfficePackage/AbstractSaveToPdf.cs @@ -11,30 +11,55 @@ namespace BusinessLogic.OfficePackage { public abstract class AbstractSaveToPdf { - public BarcodeLogic BarcodeLogic { get; set; } = new BarcodeLogic(); public void CreateDoc(PdfInfo info) { CreatePdf(info); CreateParagraph(new PdfParagraph { - Text = info.Title, + Text = $"{info.Title}\nОт {DateTime.UtcNow}", Style = "NormalTitle", ParagraphAlignment = PdfParagraphAlignmentType.Center }); - CreateTable(new List { "2cm", "3cm", "6cm", "4cm" }); + CreateParagraph(new PdfParagraph + { + Text = $"Поставщик: {info.Supply.SupplierName}\nДата создания поставки: {info.Supply.Date}\nСтатус: {info.Supply.Status}", + Style = "NormalTitle", + ParagraphAlignment = PdfParagraphAlignmentType.Right + }); + CreateTable(new List { "5cm", "10cm"}); CreateRow(new PdfRowParameters { - Texts = new List { "Идентификатор", "Дата поставки", "Информация", "Статус" }, + Texts = new List { "Id", "Информация" }, Style = "NormalTitle", ParagraphAlignment = PdfParagraphAlignmentType.Center }); CreateRow(new PdfRowParameters { - Texts = new List { info.Supply.Id.ToString(), info.Supply.Date.ToShortDateString(), info.Supply.Name, info.Supply.Status.ToString() }, + Texts = new List { info.Supply.Id.ToString(), info.Supply.Name, }, Style = "Normal", ParagraphAlignment = PdfParagraphAlignmentType.Left }); CreateParagraph(new PdfParagraph + { + Text = "Товары", + Style = "NormalTitle", + ParagraphAlignment = PdfParagraphAlignmentType.Center + }); + CreateTable(new List { "5cm", "5cm", "3cm", "2cm" }); + CreateRow(new PdfRowParameters + { + Texts = new List { "Id", "Название", "Цена", "Кол-во" }, + Style = "NormalTitle", + ParagraphAlignment = PdfParagraphAlignmentType.Center + }); + foreach (var product in info.Supply.Products.Values) + { + CreateRow(new PdfRowParameters + { + Texts = new List { product.Item1.Id.ToString(), product.Item1.Name, product.Item1.Price.ToString(), product.Item2.ToString() }, + }); + } + CreateParagraph(new PdfParagraph { Text = $"Итого: {info.Supply.Price}", Style = "Normal", @@ -42,32 +67,11 @@ namespace BusinessLogic.OfficePackage }); SavePdf(info); } - /// - /// Создание doc-файла - /// - /// protected abstract void CreatePdf(PdfInfo info); - /// - /// Создание параграфа с текстом - /// - /// - /// protected abstract void CreateParagraph(PdfParagraph paragraph); - /// - /// Создание таблицы - /// - /// - /// protected abstract void CreateTable(List columns); - /// - /// Создание и заполнение строки - /// - /// protected abstract void CreateRow(PdfRowParameters rowParameters); - /// - /// Сохранение файла - /// - /// + protected abstract void CreateImage(string path); protected abstract void SavePdf(PdfInfo info); } } diff --git a/BusinessLogic/OfficePackage/Implements/SaveToPdf.cs b/BusinessLogic/OfficePackage/Implements/SaveToPdf.cs index 049a98d..654366d 100644 --- a/BusinessLogic/OfficePackage/Implements/SaveToPdf.cs +++ b/BusinessLogic/OfficePackage/Implements/SaveToPdf.cs @@ -1,6 +1,7 @@ using BusinessLogic.OfficePackage.HelperEnums; using BusinessLogic.OfficePackage.HelperModels; using MigraDoc.DocumentObjectModel; +using MigraDoc.DocumentObjectModel.Shapes; using MigraDoc.DocumentObjectModel.Tables; using MigraDoc.Rendering; using System.Text; @@ -12,6 +13,7 @@ namespace BusinessLogic.OfficePackage.Implements private Document? _document; private Section? _section; private Table? _table; + private Image _image; private static ParagraphAlignment GetParagraphAlignment(PdfParagraphAlignmentType type) { @@ -49,8 +51,7 @@ namespace BusinessLogic.OfficePackage.Implements } var paragraph = _section.AddParagraph(pdfParagraph.Text); paragraph.Format.SpaceAfter = "1cm"; - paragraph.Format.Alignment = - GetParagraphAlignment(pdfParagraph.ParagraphAlignment); + paragraph.Format.Alignment = GetParagraphAlignment(pdfParagraph.ParagraphAlignment); paragraph.Style = pdfParagraph.Style; } protected override void CreateTable(List columns) @@ -89,6 +90,14 @@ namespace BusinessLogic.OfficePackage.Implements row.Cells[i].VerticalAlignment = VerticalAlignment.Center; } } + protected override void CreateImage(string path) + { + if (_document == null) + { + return; + } + _document.LastSection.AddImage(path); + } protected override void SavePdf(PdfInfo info) { var renderer = new PdfDocumentRenderer(true)