diff --git a/BusinessLogic/BusinessLogic/BarcodeLogic.cs b/BusinessLogic/BusinessLogic/BarcodeLogic.cs index 660f594..375c9ca 100644 --- a/BusinessLogic/BusinessLogic/BarcodeLogic.cs +++ b/BusinessLogic/BusinessLogic/BarcodeLogic.cs @@ -10,10 +10,11 @@ namespace BusinessLogic.BusinessLogic { public class BarcodeLogic { - public GeneratedBarcode CreateBarcode(ProductBindingModel model) + public GeneratedBarcode CreateBarcode(ProductBindingModel model, bool save) { var barCode = IronBarCode.BarcodeWriter.CreateBarcode(model.Id.ToString(), BarcodeEncoding.Code128); - return barCode.SaveAsPng($"product{model.Id}.png"); + if (save) return barCode.SaveAsPng($"product{model.Id}.png"); + return barCode; } } } diff --git a/BusinessLogic/OfficePackage/AbstractSaveToPdf.cs b/BusinessLogic/OfficePackage/AbstractSaveToPdf.cs new file mode 100644 index 0000000..4be3403 --- /dev/null +++ b/BusinessLogic/OfficePackage/AbstractSaveToPdf.cs @@ -0,0 +1,77 @@ +using BusinessLogic.OfficePackage.HelperEnums; +using BusinessLogic.OfficePackage.HelperModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BusinessLogic.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 = $"с{info.DateFrom.ToShortDateString()} по {info.DateTo.ToShortDateString()}", + Style = "Normal", + ParagraphAlignment = PdfParagraphAlignmentType.Center + }); + CreateTable(new List { "2cm", "3cm", "6cm", "4cm" }); + CreateRow(new PdfRowParameters + { + Texts = new List { "Идентификатор", "Дата поставки", "Информация", "Статус" }, + 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() }, + Style = "Normal", + ParagraphAlignment = PdfParagraphAlignmentType.Left + }); + CreateParagraph(new PdfParagraph + { + Text = $"Итого: {info.Supply.Price}", + Style = "Normal", + ParagraphAlignment = PdfParagraphAlignmentType.Right + }); + 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 SavePdf(PdfInfo info); + } +} diff --git a/BusinessLogic/OfficePackage/HelperEnums/PdfParagraphAlignmentType.cs b/BusinessLogic/OfficePackage/HelperEnums/PdfParagraphAlignmentType.cs new file mode 100644 index 0000000..cb665c5 --- /dev/null +++ b/BusinessLogic/OfficePackage/HelperEnums/PdfParagraphAlignmentType.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BusinessLogic.OfficePackage.HelperEnums +{ + public enum PdfParagraphAlignmentType + { + Center, + Left, + Right + } +} diff --git a/BusinessLogic/OfficePackage/HelperModels/PdfInfo.cs b/BusinessLogic/OfficePackage/HelperModels/PdfInfo.cs new file mode 100644 index 0000000..2ef7778 --- /dev/null +++ b/BusinessLogic/OfficePackage/HelperModels/PdfInfo.cs @@ -0,0 +1,18 @@ +using Contracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BusinessLogic.OfficePackage.HelperModels +{ + public class PdfInfo + { + public string FileName { get; set; } = string.Empty; + public string Title { get; set; } = string.Empty; + public DateTime DateFrom { get; set; } + public DateTime DateTo { get; set; } + public SupplyViewModel Supply { get; set; } = new(); + } +} diff --git a/BusinessLogic/OfficePackage/HelperModels/PdfParagraph.cs b/BusinessLogic/OfficePackage/HelperModels/PdfParagraph.cs new file mode 100644 index 0000000..563d69b --- /dev/null +++ b/BusinessLogic/OfficePackage/HelperModels/PdfParagraph.cs @@ -0,0 +1,16 @@ +using BusinessLogic.OfficePackage.HelperEnums; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BusinessLogic.OfficePackage.HelperModels +{ + public class PdfParagraph + { + public string Text { get; set; } = string.Empty; + public string Style { get; set; } = string.Empty; + public PdfParagraphAlignmentType ParagraphAlignment { get; set; } + } +} diff --git a/BusinessLogic/OfficePackage/HelperModels/PdfRowParameters.cs b/BusinessLogic/OfficePackage/HelperModels/PdfRowParameters.cs new file mode 100644 index 0000000..6054e4f --- /dev/null +++ b/BusinessLogic/OfficePackage/HelperModels/PdfRowParameters.cs @@ -0,0 +1,16 @@ +using BusinessLogic.OfficePackage.HelperEnums; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BusinessLogic.OfficePackage.HelperModels +{ + public class PdfRowParameters + { + public List Texts { get; set; } = new(); + public string Style { get; set; } = string.Empty; + public PdfParagraphAlignmentType ParagraphAlignment { get; set; } + } +} diff --git a/WinFormsApp/FormProducts.cs b/WinFormsApp/FormProducts.cs index 2b931a1..a1ab921 100644 --- a/WinFormsApp/FormProducts.cs +++ b/WinFormsApp/FormProducts.cs @@ -100,6 +100,12 @@ namespace WinFormsApp IsBeingSold = checkBoxIsSold.Checked, }; var operationResult = _id.HasValue ? _productLogic.Update(model) : _productLogic.Create(model); + var lastProductCreated = _productLogic.ReadList(null).Last(); + _barcodeLogic.CreateBarcode(new ProductBindingModel() + { + Id = lastProductCreated.Id, + Name = lastProductCreated.Name, + }, true); _id = null; if (!operationResult) { @@ -196,7 +202,7 @@ namespace WinFormsApp { Id = (Guid)dataGridView.SelectedRows[0].Cells["Id"].Value, Name = Convert.ToString(dataGridView.SelectedRows[0].Cells["Name"].Value), - }); + }, true); pictureBox1.Image = barcode.Image; _barcode = BarcodeReader.Read($"product{barcode.Value}.png"); }