From ebc61c5ef4b3b554242adef0e397fa1e9d7ef986 Mon Sep 17 00:00:00 2001 From: the Date: Mon, 24 Jun 2024 18:08:53 +0400 Subject: [PATCH 1/9] =?UTF-8?q?=D1=82=D0=B5=D0=BF=D0=B5=D1=80=D1=8C=20?= =?UTF-8?q?=D1=82=D0=BE=D1=87=D0=BD=D0=BE=20=D0=B0=D0=B2=D1=82=D0=BE=D0=B3?= =?UTF-8?q?=D0=B5=D0=BD=D0=B5=D1=80=D0=B0=D1=86=D0=B8=D1=8F=20=D1=88=D1=82?= =?UTF-8?q?=D1=80=D0=B8=D1=85=D0=BA=D0=BE=D0=B4=D0=B0=20=D0=BF=D1=80=D0=B8?= =?UTF-8?q?=20=D1=81=D0=BE=D0=B7=D0=B4=D0=B0=D0=BD=D0=B8=D0=B8=20=D0=BF?= =?UTF-8?q?=D1=80=D0=BE=D0=B4=D1=83=D0=BA=D1=82=D0=B0=20+=20=D0=BD=D0=B0?= =?UTF-8?q?=D1=87=D0=B0=D0=BB=D0=BE=20=D1=80=D0=B0=D0=B1=D0=BE=D1=82=D1=8B?= =?UTF-8?q?=20=D0=BD=D0=B0=D0=B4=20=D0=B4=D0=BE=D0=BA=D1=83=D0=BC=D0=B5?= =?UTF-8?q?=D0=BD=D1=82=D0=B0=D0=BC=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- BusinessLogic/BusinessLogic/BarcodeLogic.cs | 5 +- .../OfficePackage/AbstractSaveToPdf.cs | 77 +++++++++++++++++++ .../HelperEnums/PdfParagraphAlignmentType.cs | 15 ++++ .../OfficePackage/HelperModels/PdfInfo.cs | 18 +++++ .../HelperModels/PdfParagraph.cs | 16 ++++ .../HelperModels/PdfRowParameters.cs | 16 ++++ WinFormsApp/FormProducts.cs | 8 +- 7 files changed, 152 insertions(+), 3 deletions(-) create mode 100644 BusinessLogic/OfficePackage/AbstractSaveToPdf.cs create mode 100644 BusinessLogic/OfficePackage/HelperEnums/PdfParagraphAlignmentType.cs create mode 100644 BusinessLogic/OfficePackage/HelperModels/PdfInfo.cs create mode 100644 BusinessLogic/OfficePackage/HelperModels/PdfParagraph.cs create mode 100644 BusinessLogic/OfficePackage/HelperModels/PdfRowParameters.cs 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"); } From c716bda9017e328f214afd4f59973407558f2743 Mon Sep 17 00:00:00 2001 From: the Date: Mon, 24 Jun 2024 18:53:31 +0400 Subject: [PATCH 2/9] =?UTF-8?q?=D0=BA=D0=BE=D1=88=D0=BC=D0=B0=D1=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- BusinessLogic/BusinessLogic.csproj | 1 + BusinessLogic/BusinessLogic/ReportLogic.cs | 74 +++++++++++++ .../OfficePackage/AbstractSaveToPdf.cs | 10 +- .../OfficePackage/HelperModels/PdfInfo.cs | 3 +- .../OfficePackage/Implements/SaveToPdf.cs | 101 ++++++++++++++++++ Contracts/BindingModels/ReportBindingModel.cs | 15 +++ .../BusinessLogicContracts/IReportLogic.cs | 24 +++++ .../ReportSupplyProductViewModel.cs | 15 +++ Contracts/ViewModels/ReportSupplyViewModel.cs | 17 +++ WinFormsApp/Program.cs | 4 + 10 files changed, 255 insertions(+), 9 deletions(-) create mode 100644 BusinessLogic/BusinessLogic/ReportLogic.cs create mode 100644 BusinessLogic/OfficePackage/Implements/SaveToPdf.cs create mode 100644 Contracts/BindingModels/ReportBindingModel.cs create mode 100644 Contracts/BusinessLogicContracts/IReportLogic.cs create mode 100644 Contracts/ViewModels/ReportSupplyProductViewModel.cs create mode 100644 Contracts/ViewModels/ReportSupplyViewModel.cs diff --git a/BusinessLogic/BusinessLogic.csproj b/BusinessLogic/BusinessLogic.csproj index 832c28f..c4585ce 100644 --- a/BusinessLogic/BusinessLogic.csproj +++ b/BusinessLogic/BusinessLogic.csproj @@ -14,6 +14,7 @@ + diff --git a/BusinessLogic/BusinessLogic/ReportLogic.cs b/BusinessLogic/BusinessLogic/ReportLogic.cs new file mode 100644 index 0000000..652fb2f --- /dev/null +++ b/BusinessLogic/BusinessLogic/ReportLogic.cs @@ -0,0 +1,74 @@ +using BusinessLogic.OfficePackage.HelperModels; +using BusinessLogic.OfficePackage; +using Contracts.BindingModels; +using Contracts.BusinessLogicContracts; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Contracts.StorageContracts; +using Contracts.ViewModels; +using Contracts.SearchModels; + +namespace BusinessLogic.BusinessLogic +{ + public class ReportLogic : IReportLogic + { + private readonly IProductStorage _productStorage; + private readonly ISupplyStorage _supplyStorage; + private readonly AbstractSaveToPdf _saveToPdf; + public ReportLogic(IProductStorage productStorage, ISupplyStorage supplyStorage, AbstractSaveToPdf saveToPdf) + { + _productStorage = productStorage; + _supplyStorage = supplyStorage; + _saveToPdf = saveToPdf; + } + /// + /// Получение списка компонент с указанием, в каких изделиях используются + /// + /// + public List GetSupplyProduct() + { + var products = _productStorage.GetFullList(); + var supplies = _supplyStorage.GetFullList(); + var list = new List(); + foreach (var supply in supplies) + { + var record = new ReportSupplyProductViewModel + { + SupplyName = supply.Name, + Products = new List>(), + TotalCount = 0 + }; + foreach (var product in products) + { + if (supply.Products.ContainsKey(product.Id)) + { + record.Products.Add(new Tuple(product.Name, supply.Products[product.Id].Item2)); + record.TotalCount += supply.Products[product.Id].Item2; + } + } + list.Add(record); + } + return list; + } + /// + /// Сохранение заказов в файл-Pdf + /// + /// + public void SaveSuppliesToPdfFile(ReportBindingModel model) + { + _saveToPdf.CreateDoc(new PdfInfo + { + FileName = model.FileName, + Title = "Отчёт о поставке", + Date = model.Date!.Value, + Supply = _supplyStorage.GetElement(new SupplySearchModel() + { + Id = model.SupplyId, + }) + }); + } + } +} diff --git a/BusinessLogic/OfficePackage/AbstractSaveToPdf.cs b/BusinessLogic/OfficePackage/AbstractSaveToPdf.cs index 4be3403..b634b0e 100644 --- a/BusinessLogic/OfficePackage/AbstractSaveToPdf.cs +++ b/BusinessLogic/OfficePackage/AbstractSaveToPdf.cs @@ -1,4 +1,5 @@ -using BusinessLogic.OfficePackage.HelperEnums; +using BusinessLogic.BusinessLogic; +using BusinessLogic.OfficePackage.HelperEnums; using BusinessLogic.OfficePackage.HelperModels; using System; using System.Collections.Generic; @@ -10,6 +11,7 @@ namespace BusinessLogic.OfficePackage { public abstract class AbstractSaveToPdf { + public BarcodeLogic BarcodeLogic { get; set; } = new BarcodeLogic(); public void CreateDoc(PdfInfo info) { CreatePdf(info); @@ -19,12 +21,6 @@ namespace BusinessLogic.OfficePackage 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 { diff --git a/BusinessLogic/OfficePackage/HelperModels/PdfInfo.cs b/BusinessLogic/OfficePackage/HelperModels/PdfInfo.cs index 2ef7778..d283468 100644 --- a/BusinessLogic/OfficePackage/HelperModels/PdfInfo.cs +++ b/BusinessLogic/OfficePackage/HelperModels/PdfInfo.cs @@ -11,8 +11,7 @@ namespace BusinessLogic.OfficePackage.HelperModels { 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 DateTime Date { get; set; } public SupplyViewModel Supply { get; set; } = new(); } } diff --git a/BusinessLogic/OfficePackage/Implements/SaveToPdf.cs b/BusinessLogic/OfficePackage/Implements/SaveToPdf.cs new file mode 100644 index 0000000..ff2e318 --- /dev/null +++ b/BusinessLogic/OfficePackage/Implements/SaveToPdf.cs @@ -0,0 +1,101 @@ +using BusinessLogic.OfficePackage.HelperEnums; +using BusinessLogic.OfficePackage.HelperModels; +using MigraDoc.DocumentObjectModel; +using MigraDoc.DocumentObjectModel.Tables; +using MigraDoc.Rendering; + +namespace BusinessLogic.OfficePackage.Implements +{ + public class SaveToPdf : AbstractSaveToPdf + { + private Document? _document; + private Section? _section; + private Table? _table; + private static ParagraphAlignment + GetParagraphAlignment(PdfParagraphAlignmentType type) + { + return type switch + { + PdfParagraphAlignmentType.Center => ParagraphAlignment.Center, + PdfParagraphAlignmentType.Left => ParagraphAlignment.Left, + PdfParagraphAlignmentType.Right => ParagraphAlignment.Right, + _ => ParagraphAlignment.Justify, + }; + } + /// + /// Создание стилей для документа + /// + /// + private static void DefineStyles(Document document) + { + var style = document.Styles["Normal"]; + style.Font.Name = "Times New Roman"; + style.Font.Size = 14; + style = document.Styles.AddStyle("NormalTitle", "Normal"); + style.Font.Bold = true; + } + protected override void CreatePdf(PdfInfo info) + { + _document = new Document(); + DefineStyles(_document); + _section = _document.AddSection(); + } + protected override void CreateParagraph(PdfParagraph pdfParagraph) + { + if (_section == null) + { + return; + } + var paragraph = _section.AddParagraph(pdfParagraph.Text); + paragraph.Format.SpaceAfter = "1cm"; + paragraph.Format.Alignment = + GetParagraphAlignment(pdfParagraph.ParagraphAlignment); + paragraph.Style = pdfParagraph.Style; + } + protected override void CreateTable(List columns) + { + if (_document == null) + { + return; + } + _table = _document.LastSection.AddTable(); + foreach (var elem in columns) + { + _table.AddColumn(elem); + } + } + protected override void CreateRow(PdfRowParameters rowParameters) + { + if (_table == null) + { + return; + } + var row = _table.AddRow(); + for (int i = 0; i < rowParameters.Texts.Count; ++i) + { + row.Cells[i].AddParagraph(rowParameters.Texts[i]); + if (!string.IsNullOrEmpty(rowParameters.Style)) + { + row.Cells[i].Style = rowParameters.Style; + } + Unit borderWidth = 0.5; + row.Cells[i].Borders.Left.Width = borderWidth; + row.Cells[i].Borders.Right.Width = borderWidth; + row.Cells[i].Borders.Top.Width = borderWidth; + row.Cells[i].Borders.Bottom.Width = borderWidth; + row.Cells[i].Format.Alignment = + GetParagraphAlignment(rowParameters.ParagraphAlignment); + row.Cells[i].VerticalAlignment = VerticalAlignment.Center; + } + } + protected override void SavePdf(PdfInfo info) + { + var renderer = new PdfDocumentRenderer(true) + { + Document = _document + }; + renderer.RenderDocument(); + renderer.PdfDocument.Save(info.FileName); + } + } +} diff --git a/Contracts/BindingModels/ReportBindingModel.cs b/Contracts/BindingModels/ReportBindingModel.cs new file mode 100644 index 0000000..0a77572 --- /dev/null +++ b/Contracts/BindingModels/ReportBindingModel.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Contracts.BindingModels +{ + public class ReportBindingModel + { + public string FileName { get; set; } = string.Empty; + public DateTime? Date { get; set; } + public Guid SupplyId { get; set; } + } +} diff --git a/Contracts/BusinessLogicContracts/IReportLogic.cs b/Contracts/BusinessLogicContracts/IReportLogic.cs new file mode 100644 index 0000000..c0707be --- /dev/null +++ b/Contracts/BusinessLogicContracts/IReportLogic.cs @@ -0,0 +1,24 @@ +using Contracts.BindingModels; +using Contracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Contracts.BusinessLogicContracts +{ + public interface IReportLogic + { + /// + /// Получение списка компонент с указанием, в каких изделиях используются + /// + /// + List GetSupplyProduct(); + /// + /// Сохранение заказов в файл-Pdf + /// + /// + void SaveSuppliesToPdfFile(ReportBindingModel model); + } +} diff --git a/Contracts/ViewModels/ReportSupplyProductViewModel.cs b/Contracts/ViewModels/ReportSupplyProductViewModel.cs new file mode 100644 index 0000000..fcf1ba2 --- /dev/null +++ b/Contracts/ViewModels/ReportSupplyProductViewModel.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Contracts.ViewModels +{ + public class ReportSupplyProductViewModel + { + public string SupplyName { get; set; } = string.Empty; + public int TotalCount { get; set; } + public List> Products { get; set; } = new(); + } +} diff --git a/Contracts/ViewModels/ReportSupplyViewModel.cs b/Contracts/ViewModels/ReportSupplyViewModel.cs new file mode 100644 index 0000000..b85c166 --- /dev/null +++ b/Contracts/ViewModels/ReportSupplyViewModel.cs @@ -0,0 +1,17 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Contracts.ViewModels +{ + public class ReportSupplyViewModel + { + public int Id { get; set; } + public DateTime Date { get; set; } + public string Name { get; set; } = string.Empty; + public double Price { get; set; } + public String Status { get; set; } = string.Empty; + } +} diff --git a/WinFormsApp/Program.cs b/WinFormsApp/Program.cs index 2cf562f..d830c81 100644 --- a/WinFormsApp/Program.cs +++ b/WinFormsApp/Program.cs @@ -6,6 +6,8 @@ using Contracts.StorageContracts; using DatabaseImplement.Implements; using Contracts.BusinessLogicContracts; using BusinessLogic.BusinessLogic; +using BusinessLogic.OfficePackage.Implements; +using BusinessLogic.OfficePackage; namespace WinFormsApp { @@ -45,6 +47,8 @@ namespace WinFormsApp services.AddTransient(); services.AddTransient(); + services.AddTransient(); + services.AddTransient(); services.AddTransient(); services.AddTransient(); From 489be1deb862e49a92eca1ff28a43b5ed4a68daf Mon Sep 17 00:00:00 2001 From: the Date: Mon, 24 Jun 2024 19:26:39 +0400 Subject: [PATCH 3/9] =?UTF-8?q?=D1=81=D0=B0=D0=BC=D1=8B=D0=B9=20=D1=81?= =?UTF-8?q?=D1=82=D0=B0=D0=BD=D0=B4=D0=B0=D1=80=D1=82=D0=BD=D1=8B=D0=B9=20?= =?UTF-8?q?=D0=BF=D0=B4=D1=84=20=D0=B4=D0=BE=D0=BA=D1=83=D0=BC=D0=B5=D0=BD?= =?UTF-8?q?=D1=82=20=D0=BA=D0=BE=D1=82=D0=BE=D1=80=D1=8B=D0=B9=20=D1=80?= =?UTF-8?q?=D0=B0=D0=B1=D0=BE=D1=82=D0=B0=D0=B5=D1=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- BusinessLogic/BusinessLogic.csproj | 1 + .../OfficePackage/Implements/SaveToPdf.cs | 1 + WinFormsApp/FormMain.Designer.cs | 13 ++++++++ WinFormsApp/FormMain.cs | 33 ++++++++++++++++++- WinFormsApp/Program.cs | 4 +++ 5 files changed, 51 insertions(+), 1 deletion(-) diff --git a/BusinessLogic/BusinessLogic.csproj b/BusinessLogic/BusinessLogic.csproj index c4585ce..fed513d 100644 --- a/BusinessLogic/BusinessLogic.csproj +++ b/BusinessLogic/BusinessLogic.csproj @@ -16,6 +16,7 @@ + diff --git a/BusinessLogic/OfficePackage/Implements/SaveToPdf.cs b/BusinessLogic/OfficePackage/Implements/SaveToPdf.cs index ff2e318..049a98d 100644 --- a/BusinessLogic/OfficePackage/Implements/SaveToPdf.cs +++ b/BusinessLogic/OfficePackage/Implements/SaveToPdf.cs @@ -3,6 +3,7 @@ using BusinessLogic.OfficePackage.HelperModels; using MigraDoc.DocumentObjectModel; using MigraDoc.DocumentObjectModel.Tables; using MigraDoc.Rendering; +using System.Text; namespace BusinessLogic.OfficePackage.Implements { diff --git a/WinFormsApp/FormMain.Designer.cs b/WinFormsApp/FormMain.Designer.cs index 1567d57..37987cd 100644 --- a/WinFormsApp/FormMain.Designer.cs +++ b/WinFormsApp/FormMain.Designer.cs @@ -35,6 +35,7 @@ поставщикиToolStripMenuItem = new ToolStripMenuItem(); buttonSupplyStatusArriving = new Button(); buttonSupplyStatusCompleted = new Button(); + buttonCreateReport = new Button(); ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); menuStrip1.SuspendLayout(); SuspendLayout(); @@ -101,11 +102,22 @@ buttonSupplyStatusCompleted.UseVisualStyleBackColor = true; buttonSupplyStatusCompleted.Click += buttonSupplyStatusCompleted_Click; // + // buttonCreateReport + // + buttonCreateReport.Location = new Point(707, 190); + buttonCreateReport.Name = "buttonCreateReport"; + buttonCreateReport.Size = new Size(154, 44); + buttonCreateReport.TabIndex = 5; + buttonCreateReport.Text = "Сформировать отчет о поставке"; + buttonCreateReport.UseVisualStyleBackColor = true; + buttonCreateReport.Click += buttonCreateReport_Click; + // // FormMain // AutoScaleDimensions = new SizeF(7F, 15F); AutoScaleMode = AutoScaleMode.Font; ClientSize = new Size(901, 384); + Controls.Add(buttonCreateReport); Controls.Add(buttonSupplyStatusCompleted); Controls.Add(buttonSupplyStatusArriving); Controls.Add(buttonCreateSupply); @@ -131,5 +143,6 @@ private ToolStripMenuItem поставщикиToolStripMenuItem; private Button buttonSupplyStatusArriving; private Button buttonSupplyStatusCompleted; + private Button buttonCreateReport; } } \ No newline at end of file diff --git a/WinFormsApp/FormMain.cs b/WinFormsApp/FormMain.cs index e9fa189..2da2aab 100644 --- a/WinFormsApp/FormMain.cs +++ b/WinFormsApp/FormMain.cs @@ -22,13 +22,15 @@ namespace WinFormsApp private readonly ISupplyLogic _supplyLogic; private readonly IProductLogic _productLogic; private readonly ISupplierLogic _supplierLogic; - public FormMain(ILogger logger, ISupplierLogic supplierLogic, ISupplyLogic supplyLogic, IProductLogic productLogic) + private readonly IReportLogic _reportLogic; + public FormMain(ILogger logger, ISupplierLogic supplierLogic, ISupplyLogic supplyLogic, IProductLogic productLogic, IReportLogic reportLogic) { InitializeComponent(); _supplierLogic = supplierLogic; _supplyLogic = supplyLogic; _productLogic = productLogic; _logger = logger; + _reportLogic = reportLogic; } private void FormMain_Load(object sender, EventArgs e) @@ -136,5 +138,34 @@ namespace WinFormsApp } } } + + private void buttonCreateReport_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count != 1) + { + MessageBox.Show("Выберите одну поставку для формирования отчета", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + using var dialog = new SaveFileDialog { Filter = "pdf|*.pdf" }; + if (dialog.ShowDialog() == DialogResult.OK) + { + try + { + _reportLogic.SaveSuppliesToPdfFile(new ReportBindingModel + { + FileName = dialog.FileName, + Date = (DateTime)dataGridView.SelectedRows[0].Cells["Date"].Value, + SupplyId = (Guid)dataGridView.SelectedRows[0].Cells["Id"].Value + }); + _logger.LogInformation("Сохранение отчета о поставке"); + MessageBox.Show("Выполнено", "Успех", MessageBoxButtons.OK, MessageBoxIcon.Information); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка сохранения отчета о поставке"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } } } diff --git a/WinFormsApp/Program.cs b/WinFormsApp/Program.cs index d830c81..3cd5083 100644 --- a/WinFormsApp/Program.cs +++ b/WinFormsApp/Program.cs @@ -8,6 +8,7 @@ using Contracts.BusinessLogicContracts; using BusinessLogic.BusinessLogic; using BusinessLogic.OfficePackage.Implements; using BusinessLogic.OfficePackage; +using System.Text; namespace WinFormsApp { @@ -21,6 +22,8 @@ namespace WinFormsApp [STAThread] static void Main() { + + Encoding.RegisterProvider(CodePagesEncodingProvider.Instance); // To customize application configuration such as set high DPI settings or default font, // see https://aka.ms/applicationconfiguration. ApplicationConfiguration.Initialize(); @@ -46,6 +49,7 @@ namespace WinFormsApp services.AddTransient(); services.AddTransient(); services.AddTransient(); + services.AddTransient(); services.AddTransient(); From 1fa7832bd7997bbbb8a7b16602fee155f97b24e6 Mon Sep 17 00:00:00 2001 From: the Date: Mon, 24 Jun 2024 20:57:48 +0400 Subject: [PATCH 4/9] =?UTF-8?q?=D0=BB=D0=BE=D0=B3=D0=B8=20(=D0=BD=D0=B0?= =?UTF-8?q?=D0=B4=D0=BE=20=D0=BD=D0=B5=20=D0=B7=D0=B0=D0=B1=D1=8B=D1=82?= =?UTF-8?q?=D1=8C=20=D1=81=D0=BA=D0=BE=D0=BF=D0=B8=D1=80=D0=BE=D0=B2=D0=B0?= =?UTF-8?q?=D1=82=D1=8C=20=D0=B2=20bin)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- WinFormsApp/nlog.config | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 WinFormsApp/nlog.config diff --git a/WinFormsApp/nlog.config b/WinFormsApp/nlog.config new file mode 100644 index 0000000..645d06b --- /dev/null +++ b/WinFormsApp/nlog.config @@ -0,0 +1,15 @@ + + + + + + + + + + \ No newline at end of file From 17403f4ce9e6eccab69fc5d803030e0fd31e3ad6 Mon Sep 17 00:00:00 2001 From: the Date: Mon, 24 Jun 2024 22:04:04 +0400 Subject: [PATCH 5/9] =?UTF-8?q?=D0=BF=D1=80=D0=B8=D0=BD=D1=82=D0=B5=D1=80?= =?UTF-8?q?=20=D0=BF=D1=80=D0=B8=D0=BD=D1=82=D0=B8=D1=82=20=D0=BF=D1=80?= =?UTF-8?q?=D0=B8=D0=BD=D1=82=D1=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- BusinessLogic/BusinessLogic.csproj | 1 + WinFormsApp/FormMain.Designer.cs | 32 ++++++++++++++++++++++++++++++ WinFormsApp/FormMain.cs | 12 +++++++++++ WinFormsApp/FormMain.resx | 30 ++++++++++++++++++++++++++++ 4 files changed, 75 insertions(+) diff --git a/BusinessLogic/BusinessLogic.csproj b/BusinessLogic/BusinessLogic.csproj index fed513d..f81d09f 100644 --- a/BusinessLogic/BusinessLogic.csproj +++ b/BusinessLogic/BusinessLogic.csproj @@ -13,6 +13,7 @@ + diff --git a/WinFormsApp/FormMain.Designer.cs b/WinFormsApp/FormMain.Designer.cs index 37987cd..60d391b 100644 --- a/WinFormsApp/FormMain.Designer.cs +++ b/WinFormsApp/FormMain.Designer.cs @@ -28,6 +28,7 @@ /// private void InitializeComponent() { + System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(FormMain)); dataGridView = new DataGridView(); buttonCreateSupply = new Button(); menuStrip1 = new MenuStrip(); @@ -36,6 +37,9 @@ buttonSupplyStatusArriving = new Button(); buttonSupplyStatusCompleted = new Button(); buttonCreateReport = new Button(); + buttonPrintReport = new Button(); + printPreviewDialog = new PrintPreviewDialog(); + printDialog = new PrintDialog(); ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); menuStrip1.SuspendLayout(); SuspendLayout(); @@ -112,11 +116,36 @@ buttonCreateReport.UseVisualStyleBackColor = true; buttonCreateReport.Click += buttonCreateReport_Click; // + // buttonPrintReport + // + buttonPrintReport.Location = new Point(707, 274); + buttonPrintReport.Name = "buttonPrintReport"; + buttonPrintReport.Size = new Size(154, 44); + buttonPrintReport.TabIndex = 6; + buttonPrintReport.Text = "Распечатать отчет"; + buttonPrintReport.UseVisualStyleBackColor = true; + buttonPrintReport.Click += buttonPrintReport_Click; + // + // printPreviewDialog + // + printPreviewDialog.AutoScrollMargin = new Size(0, 0); + printPreviewDialog.AutoScrollMinSize = new Size(0, 0); + printPreviewDialog.ClientSize = new Size(400, 300); + printPreviewDialog.Enabled = true; + printPreviewDialog.Icon = (Icon)resources.GetObject("printPreviewDialog.Icon"); + printPreviewDialog.Name = "printPreviewDialog"; + printPreviewDialog.Visible = false; + // + // printDialog + // + printDialog.UseEXDialog = true; + // // FormMain // AutoScaleDimensions = new SizeF(7F, 15F); AutoScaleMode = AutoScaleMode.Font; ClientSize = new Size(901, 384); + Controls.Add(buttonPrintReport); Controls.Add(buttonCreateReport); Controls.Add(buttonSupplyStatusCompleted); Controls.Add(buttonSupplyStatusArriving); @@ -144,5 +173,8 @@ private Button buttonSupplyStatusArriving; private Button buttonSupplyStatusCompleted; private Button buttonCreateReport; + private Button buttonPrintReport; + private PrintPreviewDialog printPreviewDialog; + private PrintDialog printDialog; } } \ No newline at end of file diff --git a/WinFormsApp/FormMain.cs b/WinFormsApp/FormMain.cs index 2da2aab..3608e2f 100644 --- a/WinFormsApp/FormMain.cs +++ b/WinFormsApp/FormMain.cs @@ -8,8 +8,11 @@ using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; +using System.Diagnostics; using System.Drawing; +using System.Drawing.Printing; using System.Linq; +using System.Reflection.Metadata; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; @@ -167,5 +170,14 @@ namespace WinFormsApp } } } + + private void buttonPrintReport_Click(object sender, EventArgs e) + { + var dialog = new OpenFileDialog(); + if (dialog.ShowDialog() == DialogResult.OK) + { + IronPrint.Printer.PrintAsync(dialog.FileName); + } + } } } diff --git a/WinFormsApp/FormMain.resx b/WinFormsApp/FormMain.resx index a0623c8..a85b19c 100644 --- a/WinFormsApp/FormMain.resx +++ b/WinFormsApp/FormMain.resx @@ -120,4 +120,34 @@ 17, 17 + + 132, 17 + + + + + AAABAAEAEBAAAAAAIAAoBAAAFgAAACgAAAAQAAAAIAAAAAEAIAAAAAAAAAQAAAAAAAAAAAAAAAAAAAAA + AAD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AP// + /wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AP// + /wD///8A////AP///wD///8A////AP///wD///8A////APb29v/29vb/9vb2//b29v/29vb/9vb2//b2 + 9v////8A////AP///wD///8A9vb2//b29v/29vb/9vb2//b29v/29vb/QkJC/0JCQv9CQkL/QkJC/0JC + Qv/29vb/////AP///wD///8A////APb29v9CQkL/QkJC/0JCQv9CQkL/9vb2/0JCQv9CQkL/QkJC/0JC + Qv9CQkL/9vb2/////wD///8A////AP///wD29vb/QkJC/0JCQv9CQkL/QkJC//b29v9CQkL/QkJC/0JC + Qv9CQkL/QkJC//b29v////8A////AP///wD///8A9vb2/0JCQv9CQkL/QkJC/0JCQv/29vb/9vb2//b2 + 9v/29vb/9vb2//b29v/29vb/9vb2//b29v////8A////APb29v9CQkL/QkJC/0JCQv9CQkL/9vb2/0JC + Qv9CQkL/QkJC/0JCQv9CQkL/QkJC/0JCQv/29vb/////AP///wD29vb/QkJC/0JCQv9CQkL/QkJC//b2 + 9v9CQkL/QkJC/0JCQv9CQkL/QkJC/0JCQv9CQkL/9vb2/////wD///8A9vb2/0JCQv9CQkL/QkJC/0JC + Qv/29vb/QkJC/0JCQv9CQkL/QkJC/0JCQv9CQkL/QkJC//b29v////8A////APb29v/29vb/9vb2//b2 + 9v/29vb/9vb2/0JCQv9CQkL/QkJC/0JCQv9CQkL/QkJC/0JCQv/29vb/////AP///wD///8A////AP// + /wD///8A////APb29v9CQkL/QkJC/0JCQv9CQkL/QkJC/0JCQv9CQkL/9vb2/////wD///8A////AP// + /wD///8A////AP///wD29vb/QkJC/0JCQv9CQkL/QkJC/0JCQv9CQkL/QkJC//b29v////8A////AP// + /wD///8A////AP///wD///8A9vb2/0JCQv9CQkL/QkJC/0JCQv9CQkL/QkJC/0JCQv/29vb/////AP// + /wD///8A////AP///wD///8A////APb29v/29vb/9vb2//b29v/29vb/9vb2//b29v/29vb/9vb2//// + /wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AP// + /wD///8A + + + + 286, 17 + \ No newline at end of file From a1575b150d761b7cf7335b3a186aff1c92febef6 Mon Sep 17 00:00:00 2001 From: the Date: Tue, 25 Jun 2024 09:00:46 +0400 Subject: [PATCH 6/9] =?UTF-8?q?=D0=B1=D0=BE=D0=BB=D0=B5=D0=B5=20=D0=BF?= =?UTF-8?q?=D1=80=D0=B8=D1=8F=D1=82=D0=BD=D1=8B=D0=B9=20=D0=BD=D0=B0=20?= =?UTF-8?q?=D0=B2=D0=B8=D0=B4=20=D0=B4=D0=BE=D0=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- BusinessLogic/BusinessLogic/ReportLogic.cs | 2 +- .../OfficePackage/AbstractSaveToPdf.cs | 58 ++++++++++--------- .../OfficePackage/Implements/SaveToPdf.cs | 13 ++++- 3 files changed, 43 insertions(+), 30 deletions(-) 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) From 57a28d9baf5ea8d17a5227e575cf4c6504bd011c Mon Sep 17 00:00:00 2001 From: the Date: Tue, 25 Jun 2024 13:14:23 +0400 Subject: [PATCH 7/9] =?UTF-8?q?=D0=94=D0=B0=D1=82=D1=8B=20=D0=B8=D0=B7?= =?UTF-8?q?=D0=BC=D0=B5=D0=BD=D0=B5=D0=BD=D0=B8=D1=8F=20=D0=BF=D0=BE=D1=81?= =?UTF-8?q?=D1=82=D0=B0=D0=B2=D0=BE=D0=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- BusinessLogic/BusinessLogic/SupplyLogic.cs | 8 + .../OfficePackage/AbstractSaveToPdf.cs | 5 +- Contracts/BindingModels/SupplyBindingModel.cs | 2 + Contracts/ViewModels/SupplyViewModel.cs | 2 + DataModels/Models/ISupply.cs | 2 + ...20240625085945_dates_migration.Designer.cs | 496 ++++++++++++++++++ .../20240625085945_dates_migration.cs | 60 +++ .../Migrations/DatabaseModelSnapshot.cs | 19 + DatabaseImplement/Models/Supply.cs | 8 + WinFormsApp/FormMain.Designer.cs | 15 +- WinFormsApp/FormMain.cs | 11 +- 11 files changed, 625 insertions(+), 3 deletions(-) create mode 100644 DatabaseImplement/Migrations/20240625085945_dates_migration.Designer.cs create mode 100644 DatabaseImplement/Migrations/20240625085945_dates_migration.cs diff --git a/BusinessLogic/BusinessLogic/SupplyLogic.cs b/BusinessLogic/BusinessLogic/SupplyLogic.cs index b246c0d..03df5ff 100644 --- a/BusinessLogic/BusinessLogic/SupplyLogic.cs +++ b/BusinessLogic/BusinessLogic/SupplyLogic.cs @@ -111,6 +111,14 @@ namespace BusinessLogic.BusinessLogic return false; } model.Status = newStatus; + if (newStatus == SupplyStatus.Arriving) + { + model.DateArriving = DateTime.UtcNow; + } + if (newStatus == SupplyStatus.Completed) + { + model.DateComplete = DateTime.UtcNow; + } if (_supplyStorage.Update(model) == null) { model.Status--; diff --git a/BusinessLogic/OfficePackage/AbstractSaveToPdf.cs b/BusinessLogic/OfficePackage/AbstractSaveToPdf.cs index 8d7a2fc..5b58544 100644 --- a/BusinessLogic/OfficePackage/AbstractSaveToPdf.cs +++ b/BusinessLogic/OfficePackage/AbstractSaveToPdf.cs @@ -3,6 +3,7 @@ using BusinessLogic.OfficePackage.HelperEnums; using BusinessLogic.OfficePackage.HelperModels; using System; using System.Collections.Generic; +using System.Configuration; using System.Linq; using System.Text; using System.Threading.Tasks; @@ -20,9 +21,11 @@ namespace BusinessLogic.OfficePackage Style = "NormalTitle", ParagraphAlignment = PdfParagraphAlignmentType.Center }); + string dateArriving = info.Supply.DateArriving.HasValue ? info.Supply.DateArriving.ToString() : "-"; + string dateComplete = info.Supply.DateComplete.HasValue ? info.Supply.DateComplete.ToString() : "-"; CreateParagraph(new PdfParagraph { - Text = $"Поставщик: {info.Supply.SupplierName}\nДата создания поставки: {info.Supply.Date}\nСтатус: {info.Supply.Status}", + Text = $"Поставщик: {info.Supply.SupplierName}\nДата создания поставки: {info.Supply.Date}\nДата отправления поставки: {dateArriving}\nДата получения поставки: {dateComplete}\nСтатус: {info.Supply.Status}", Style = "NormalTitle", ParagraphAlignment = PdfParagraphAlignmentType.Right }); diff --git a/Contracts/BindingModels/SupplyBindingModel.cs b/Contracts/BindingModels/SupplyBindingModel.cs index 44ba57c..61600d3 100644 --- a/Contracts/BindingModels/SupplyBindingModel.cs +++ b/Contracts/BindingModels/SupplyBindingModel.cs @@ -14,6 +14,8 @@ namespace Contracts.BindingModels public string Name { get; set; } = string.Empty; public Guid SupplierId { get; set; } public DateTime Date { get; set; } + public DateTime? DateArriving { get; set; } + public DateTime? DateComplete { get; set; } public double Price { get; set; } public SupplyStatus Status { get; set; } public Dictionary SupplyProducts { get; set; } = new(); diff --git a/Contracts/ViewModels/SupplyViewModel.cs b/Contracts/ViewModels/SupplyViewModel.cs index 08f7046..992a4a6 100644 --- a/Contracts/ViewModels/SupplyViewModel.cs +++ b/Contracts/ViewModels/SupplyViewModel.cs @@ -18,6 +18,8 @@ namespace Contracts.ViewModels public double Price { get; set; } public Dictionary Products { get; set; } = new(); public DateTime Date { get; set; } + public DateTime? DateArriving { get; set; } + public DateTime? DateComplete { get; set; } public SupplyStatus Status { get; set; } } } diff --git a/DataModels/Models/ISupply.cs b/DataModels/Models/ISupply.cs index fff5ab5..4dda0a7 100644 --- a/DataModels/Models/ISupply.cs +++ b/DataModels/Models/ISupply.cs @@ -13,6 +13,8 @@ namespace DataModels.Models double Price { get; } Guid SupplierId { get; } DateTime Date { get; } + DateTime? DateArriving { get; } + DateTime? DateComplete { get; } SupplyStatus Status { get; } Dictionary SupplyProducts { get; } } diff --git a/DatabaseImplement/Migrations/20240625085945_dates_migration.Designer.cs b/DatabaseImplement/Migrations/20240625085945_dates_migration.Designer.cs new file mode 100644 index 0000000..a814e7a --- /dev/null +++ b/DatabaseImplement/Migrations/20240625085945_dates_migration.Designer.cs @@ -0,0 +1,496 @@ +// +using System; +using DatabaseImplement; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; + +#nullable disable + +namespace DatabaseImplement.Migrations +{ + [DbContext(typeof(Database))] + [Migration("20240625085945_dates_migration")] + partial class dates_migration + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "8.0.6") + .HasAnnotation("Relational:MaxIdentifierLength", 63); + + NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder); + + modelBuilder.Entity("DatabaseImplement.Models.MediaFile", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("Location") + .IsRequired() + .HasColumnType("text"); + + b.Property("Name") + .IsRequired() + .HasColumnType("text"); + + b.Property("ProductId") + .HasColumnType("uuid"); + + b.HasKey("Id"); + + b.HasIndex("ProductId"); + + b.ToTable("MediaFiles"); + }); + + modelBuilder.Entity("DatabaseImplement.Models.Product", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("Amount") + .HasColumnType("integer"); + + b.Property("IsBeingSold") + .HasColumnType("boolean"); + + b.Property("Name") + .IsRequired() + .HasColumnType("text"); + + b.Property("Price") + .HasColumnType("double precision"); + + b.Property("Rate") + .HasColumnType("double precision"); + + b.HasKey("Id"); + + b.ToTable("Products"); + }); + + modelBuilder.Entity("DatabaseImplement.Models.Purchase", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("DatePurchase") + .HasColumnType("timestamp with time zone"); + + b.Property("Status") + .HasColumnType("integer"); + + b.Property("UserId") + .HasColumnType("uuid"); + + b.HasKey("Id"); + + b.HasIndex("UserId"); + + b.ToTable("Purchases"); + }); + + modelBuilder.Entity("DatabaseImplement.Models.PurchaseProducts", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("Count") + .HasColumnType("integer"); + + b.Property("ProductId") + .HasColumnType("uuid"); + + b.Property("PurchaseId") + .HasColumnType("uuid"); + + b.HasKey("Id"); + + b.HasIndex("ProductId"); + + b.HasIndex("PurchaseId"); + + b.ToTable("PurchaseProducts"); + }); + + modelBuilder.Entity("DatabaseImplement.Models.Role", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("Name") + .IsRequired() + .HasColumnType("text"); + + b.HasKey("Id"); + + b.ToTable("Roles"); + }); + + modelBuilder.Entity("DatabaseImplement.Models.Sell", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("DateSell") + .HasColumnType("timestamp with time zone"); + + b.Property("UserId") + .HasColumnType("uuid"); + + b.HasKey("Id"); + + b.HasIndex("UserId"); + + b.ToTable("Sells"); + }); + + modelBuilder.Entity("DatabaseImplement.Models.SellProducts", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("Count") + .HasColumnType("integer"); + + b.Property("ProductId") + .HasColumnType("uuid"); + + b.Property("SellId") + .HasColumnType("uuid"); + + b.HasKey("Id"); + + b.HasIndex("ProductId"); + + b.HasIndex("SellId"); + + b.ToTable("SellProducts"); + }); + + modelBuilder.Entity("DatabaseImplement.Models.Supplier", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("Deals") + .HasColumnType("integer"); + + b.Property("Name") + .IsRequired() + .HasColumnType("text"); + + b.HasKey("Id"); + + b.ToTable("Suppliers"); + }); + + modelBuilder.Entity("DatabaseImplement.Models.SupplierProduct", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("Count") + .HasColumnType("integer"); + + b.Property("ProductId") + .HasColumnType("uuid"); + + b.Property("SupplierId") + .HasColumnType("uuid"); + + b.HasKey("Id"); + + b.HasIndex("ProductId"); + + b.HasIndex("SupplierId"); + + b.ToTable("SupplierProducts"); + }); + + modelBuilder.Entity("DatabaseImplement.Models.Supply", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("Date") + .HasColumnType("timestamp with time zone"); + + b.Property("DateArriving") + .HasColumnType("timestamp with time zone"); + + b.Property("DateComplete") + .HasColumnType("timestamp with time zone"); + + b.Property("Name") + .IsRequired() + .HasColumnType("text"); + + b.Property("Price") + .HasColumnType("double precision"); + + b.Property("Status") + .HasColumnType("integer"); + + b.Property("SupplierId") + .HasColumnType("uuid"); + + b.HasKey("Id"); + + b.HasIndex("SupplierId"); + + b.ToTable("Supplies"); + }); + + modelBuilder.Entity("DatabaseImplement.Models.SupplyDoc", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("Name") + .IsRequired() + .HasColumnType("text"); + + b.Property("SupplyId") + .HasColumnType("uuid"); + + b.HasKey("Id"); + + b.ToTable("SupplyDocs"); + }); + + modelBuilder.Entity("DatabaseImplement.Models.SupplyProduct", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("Count") + .HasColumnType("integer"); + + b.Property("ProductId") + .HasColumnType("uuid"); + + b.Property("SupplyId") + .HasColumnType("uuid"); + + b.HasKey("Id"); + + b.HasIndex("ProductId"); + + b.HasIndex("SupplyId"); + + b.ToTable("SupplyProducts"); + }); + + modelBuilder.Entity("DatabaseImplement.Models.User", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("Birthday") + .HasColumnType("timestamp with time zone"); + + b.Property("Email") + .IsRequired() + .HasColumnType("text"); + + b.Property("FirstName") + .IsRequired() + .HasColumnType("text"); + + b.Property("OnlyImportantMails") + .HasColumnType("boolean"); + + b.Property("PasswordHash") + .IsRequired() + .HasColumnType("text"); + + b.Property("RoleId") + .HasColumnType("uuid"); + + b.Property("SecondName") + .IsRequired() + .HasColumnType("text"); + + b.HasKey("Id"); + + b.HasIndex("RoleId"); + + b.ToTable("Users"); + }); + + modelBuilder.Entity("DatabaseImplement.Models.MediaFile", b => + { + b.HasOne("DatabaseImplement.Models.Product", "Product") + .WithMany() + .HasForeignKey("ProductId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Product"); + }); + + modelBuilder.Entity("DatabaseImplement.Models.Purchase", b => + { + b.HasOne("DatabaseImplement.Models.User", "User") + .WithMany() + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("User"); + }); + + modelBuilder.Entity("DatabaseImplement.Models.PurchaseProducts", b => + { + b.HasOne("DatabaseImplement.Models.Product", "Product") + .WithMany("PurchaseProducts") + .HasForeignKey("ProductId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("DatabaseImplement.Models.Purchase", "Purchase") + .WithMany("Products") + .HasForeignKey("PurchaseId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Product"); + + b.Navigation("Purchase"); + }); + + modelBuilder.Entity("DatabaseImplement.Models.Sell", b => + { + b.HasOne("DatabaseImplement.Models.User", "User") + .WithMany() + .HasForeignKey("UserId"); + + b.Navigation("User"); + }); + + modelBuilder.Entity("DatabaseImplement.Models.SellProducts", b => + { + b.HasOne("DatabaseImplement.Models.Product", "Product") + .WithMany("SellProducts") + .HasForeignKey("ProductId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("DatabaseImplement.Models.Sell", "Sell") + .WithMany("Products") + .HasForeignKey("SellId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Product"); + + b.Navigation("Sell"); + }); + + modelBuilder.Entity("DatabaseImplement.Models.SupplierProduct", b => + { + b.HasOne("DatabaseImplement.Models.Product", "Product") + .WithMany() + .HasForeignKey("ProductId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("DatabaseImplement.Models.Supplier", "Supplier") + .WithMany("Products") + .HasForeignKey("SupplierId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Product"); + + b.Navigation("Supplier"); + }); + + modelBuilder.Entity("DatabaseImplement.Models.Supply", b => + { + b.HasOne("DatabaseImplement.Models.Supplier", "Supplier") + .WithMany() + .HasForeignKey("SupplierId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Supplier"); + }); + + modelBuilder.Entity("DatabaseImplement.Models.SupplyProduct", b => + { + b.HasOne("DatabaseImplement.Models.Product", "Product") + .WithMany() + .HasForeignKey("ProductId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("DatabaseImplement.Models.Supply", "Supply") + .WithMany("Products") + .HasForeignKey("SupplyId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Product"); + + b.Navigation("Supply"); + }); + + modelBuilder.Entity("DatabaseImplement.Models.User", b => + { + b.HasOne("DatabaseImplement.Models.Role", "Role") + .WithMany() + .HasForeignKey("RoleId"); + + b.Navigation("Role"); + }); + + modelBuilder.Entity("DatabaseImplement.Models.Product", b => + { + b.Navigation("PurchaseProducts"); + + b.Navigation("SellProducts"); + }); + + modelBuilder.Entity("DatabaseImplement.Models.Purchase", b => + { + b.Navigation("Products"); + }); + + modelBuilder.Entity("DatabaseImplement.Models.Sell", b => + { + b.Navigation("Products"); + }); + + modelBuilder.Entity("DatabaseImplement.Models.Supplier", b => + { + b.Navigation("Products"); + }); + + modelBuilder.Entity("DatabaseImplement.Models.Supply", b => + { + b.Navigation("Products"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/DatabaseImplement/Migrations/20240625085945_dates_migration.cs b/DatabaseImplement/Migrations/20240625085945_dates_migration.cs new file mode 100644 index 0000000..c228ce6 --- /dev/null +++ b/DatabaseImplement/Migrations/20240625085945_dates_migration.cs @@ -0,0 +1,60 @@ +using System; +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace DatabaseImplement.Migrations +{ + /// + public partial class dates_migration : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.AddColumn( + name: "DateArriving", + table: "Supplies", + type: "timestamp with time zone", + nullable: true); + + migrationBuilder.AddColumn( + name: "DateComplete", + table: "Supplies", + type: "timestamp with time zone", + nullable: true); + + migrationBuilder.CreateIndex( + name: "IX_MediaFiles_ProductId", + table: "MediaFiles", + column: "ProductId"); + + migrationBuilder.AddForeignKey( + name: "FK_MediaFiles_Products_ProductId", + table: "MediaFiles", + column: "ProductId", + principalTable: "Products", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropForeignKey( + name: "FK_MediaFiles_Products_ProductId", + table: "MediaFiles"); + + migrationBuilder.DropIndex( + name: "IX_MediaFiles_ProductId", + table: "MediaFiles"); + + migrationBuilder.DropColumn( + name: "DateArriving", + table: "Supplies"); + + migrationBuilder.DropColumn( + name: "DateComplete", + table: "Supplies"); + } + } +} diff --git a/DatabaseImplement/Migrations/DatabaseModelSnapshot.cs b/DatabaseImplement/Migrations/DatabaseModelSnapshot.cs index 1d1117b..013f054 100644 --- a/DatabaseImplement/Migrations/DatabaseModelSnapshot.cs +++ b/DatabaseImplement/Migrations/DatabaseModelSnapshot.cs @@ -41,6 +41,8 @@ namespace DatabaseImplement.Migrations b.HasKey("Id"); + b.HasIndex("ProductId"); + b.ToTable("MediaFiles"); }); @@ -226,6 +228,12 @@ namespace DatabaseImplement.Migrations b.Property("Date") .HasColumnType("timestamp with time zone"); + b.Property("DateArriving") + .HasColumnType("timestamp with time zone"); + + b.Property("DateComplete") + .HasColumnType("timestamp with time zone"); + b.Property("Name") .IsRequired() .HasColumnType("text"); @@ -326,6 +334,17 @@ namespace DatabaseImplement.Migrations b.ToTable("Users"); }); + modelBuilder.Entity("DatabaseImplement.Models.MediaFile", b => + { + b.HasOne("DatabaseImplement.Models.Product", "Product") + .WithMany() + .HasForeignKey("ProductId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Product"); + }); + modelBuilder.Entity("DatabaseImplement.Models.Purchase", b => { b.HasOne("DatabaseImplement.Models.User", "User") diff --git a/DatabaseImplement/Models/Supply.cs b/DatabaseImplement/Models/Supply.cs index 060d97c..2d65060 100644 --- a/DatabaseImplement/Models/Supply.cs +++ b/DatabaseImplement/Models/Supply.cs @@ -25,6 +25,8 @@ namespace DatabaseImplement.Models public Guid SupplierId { get; set; } [Required] public DateTime Date { get; set; } + public DateTime? DateArriving { get; private set; } + public DateTime? DateComplete { get; private set; } [Required] public SupplyStatus Status { get; set; } = SupplyStatus.Pending; private Dictionary? _supplyProducts = null; @@ -53,6 +55,8 @@ namespace DatabaseImplement.Models Name = model.Name, Price = model.Price, Date = model.Date, + DateArriving = model.DateArriving, + DateComplete = model.DateComplete, SupplierId = model.SupplierId, Products = model.SupplyProducts.Select(x => new SupplyProduct @@ -66,6 +70,8 @@ namespace DatabaseImplement.Models public void Update(SupplyBindingModel model) { Status = model.Status; + DateArriving = model.DateArriving; + DateComplete = model.DateComplete; } public SupplyViewModel GetViewModel { @@ -80,6 +86,8 @@ namespace DatabaseImplement.Models Products = SupplyProducts, SupplierId = SupplierId, Date = Date, + DateArriving = DateArriving, + DateComplete = DateComplete, Status = Status, SupplierName = Supplier.Name, }; diff --git a/WinFormsApp/FormMain.Designer.cs b/WinFormsApp/FormMain.Designer.cs index 60d391b..2f38434 100644 --- a/WinFormsApp/FormMain.Designer.cs +++ b/WinFormsApp/FormMain.Designer.cs @@ -40,6 +40,7 @@ buttonPrintReport = new Button(); printPreviewDialog = new PrintPreviewDialog(); printDialog = new PrintDialog(); + buttonRefresh = new Button(); ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); menuStrip1.SuspendLayout(); SuspendLayout(); @@ -118,7 +119,7 @@ // // buttonPrintReport // - buttonPrintReport.Location = new Point(707, 274); + buttonPrintReport.Location = new Point(707, 261); buttonPrintReport.Name = "buttonPrintReport"; buttonPrintReport.Size = new Size(154, 44); buttonPrintReport.TabIndex = 6; @@ -140,11 +141,22 @@ // printDialog.UseEXDialog = true; // + // buttonRefresh + // + buttonRefresh.Location = new Point(707, 325); + buttonRefresh.Name = "buttonRefresh"; + buttonRefresh.Size = new Size(154, 47); + buttonRefresh.TabIndex = 7; + buttonRefresh.Text = "Обновить"; + buttonRefresh.UseVisualStyleBackColor = true; + buttonRefresh.Click += buttonRefresh_Click; + // // FormMain // AutoScaleDimensions = new SizeF(7F, 15F); AutoScaleMode = AutoScaleMode.Font; ClientSize = new Size(901, 384); + Controls.Add(buttonRefresh); Controls.Add(buttonPrintReport); Controls.Add(buttonCreateReport); Controls.Add(buttonSupplyStatusCompleted); @@ -176,5 +188,6 @@ private Button buttonPrintReport; private PrintPreviewDialog printPreviewDialog; private PrintDialog printDialog; + private Button buttonRefresh; } } \ No newline at end of file diff --git a/WinFormsApp/FormMain.cs b/WinFormsApp/FormMain.cs index 3608e2f..da7e521 100644 --- a/WinFormsApp/FormMain.cs +++ b/WinFormsApp/FormMain.cs @@ -50,6 +50,8 @@ namespace WinFormsApp if (list != null) { dataGridView.DataSource = list; + dataGridView.Columns["SupplierId"].Visible = false; + dataGridView.Columns["Products"].Visible = false; } _logger.LogInformation("Загрузка поставок"); } @@ -125,7 +127,9 @@ namespace WinFormsApp var operationResult = _supplyLogic.StatusUpdate(new SupplyBindingModel { Id = id, - Status = (SupplyStatus)dataGridView.SelectedRows[0].Cells["Status"].Value + Status = (SupplyStatus)dataGridView.SelectedRows[0].Cells["Status"].Value, + DateArriving = (DateTime?)dataGridView.SelectedRows[0].Cells["DateArriving"].Value, + DateComplete = (DateTime?)dataGridView.SelectedRows[0].Cells["DateComplete"].Value, }, SupplyStatus.Completed); if (!operationResult) { @@ -179,5 +183,10 @@ namespace WinFormsApp IronPrint.Printer.PrintAsync(dialog.FileName); } } + + private void buttonRefresh_Click(object sender, EventArgs e) + { + LoadData(); + } } } From 424703e3971f816c87d22191b378d57aba131fe5 Mon Sep 17 00:00:00 2001 From: the Date: Tue, 25 Jun 2024 13:37:33 +0400 Subject: [PATCH 8/9] =?UTF-8?q?=D0=9F=D1=80=D0=B5=D0=B4=D0=B2=D0=B0=D1=80?= =?UTF-8?q?=D0=B8=D1=82=D0=B5=D0=BB=D1=8C=D0=BD=D1=8B=D0=B9=20=D0=BF=D1=80?= =?UTF-8?q?=D0=BE=D1=81=D0=BC=D0=BE=D1=82=D1=80=20=D0=BF=D0=B5=D1=87=D0=B0?= =?UTF-8?q?=D1=82=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- WinFormsApp/FormMain.cs | 10 +- WinFormsApp/FormPreviewPDF.Designer.cs | 103 ++++++++++++++++++++ WinFormsApp/FormPreviewPDF.cs | 32 +++++++ WinFormsApp/FormPreviewPDF.resx | 128 +++++++++++++++++++++++++ WinFormsApp/Program.cs | 1 + WinFormsApp/WinFormsApp.csproj | 20 ++++ 6 files changed, 293 insertions(+), 1 deletion(-) create mode 100644 WinFormsApp/FormPreviewPDF.Designer.cs create mode 100644 WinFormsApp/FormPreviewPDF.cs create mode 100644 WinFormsApp/FormPreviewPDF.resx diff --git a/WinFormsApp/FormMain.cs b/WinFormsApp/FormMain.cs index da7e521..fa4a804 100644 --- a/WinFormsApp/FormMain.cs +++ b/WinFormsApp/FormMain.cs @@ -180,7 +180,15 @@ namespace WinFormsApp var dialog = new OpenFileDialog(); if (dialog.ShowDialog() == DialogResult.OK) { - IronPrint.Printer.PrintAsync(dialog.FileName); + var service = Program.ServiceProvider?.GetService(typeof(FormPreviewPDF)); + if (service is FormPreviewPDF form) + { + form.src = dialog.FileName; + if (form.ShowDialog() == DialogResult.OK) + { + IronPrint.Printer.PrintAsync(dialog.FileName); + } + } } } diff --git a/WinFormsApp/FormPreviewPDF.Designer.cs b/WinFormsApp/FormPreviewPDF.Designer.cs new file mode 100644 index 0000000..74092aa --- /dev/null +++ b/WinFormsApp/FormPreviewPDF.Designer.cs @@ -0,0 +1,103 @@ +namespace WinFormsApp +{ + partial class FormPreviewPDF + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(FormPreviewPDF)); + axAcropdf = new AxAcroPDFLib.AxAcroPDF(); + panel1 = new Panel(); + buttonCancel = new Button(); + buttonPrint = new Button(); + ((System.ComponentModel.ISupportInitialize)axAcropdf).BeginInit(); + panel1.SuspendLayout(); + SuspendLayout(); + // + // axAcropdf + // + axAcropdf.Dock = DockStyle.Fill; + axAcropdf.Enabled = true; + axAcropdf.Location = new Point(0, 0); + axAcropdf.Name = "axAcropdf"; + axAcropdf.OcxState = (AxHost.State)resources.GetObject("axAcropdf.OcxState"); + axAcropdf.Size = new Size(478, 576); + axAcropdf.TabIndex = 0; + // + // panel1 + // + panel1.Controls.Add(buttonCancel); + panel1.Controls.Add(buttonPrint); + panel1.Dock = DockStyle.Bottom; + panel1.Location = new Point(0, 540); + panel1.Name = "panel1"; + panel1.Size = new Size(478, 36); + panel1.TabIndex = 1; + // + // buttonCancel + // + buttonCancel.Dock = DockStyle.Right; + buttonCancel.Location = new Point(262, 0); + buttonCancel.Name = "buttonCancel"; + buttonCancel.Size = new Size(108, 36); + buttonCancel.TabIndex = 1; + buttonCancel.Text = "Отмена"; + buttonCancel.UseVisualStyleBackColor = true; + // + // buttonPrint + // + buttonPrint.Dock = DockStyle.Right; + buttonPrint.Location = new Point(370, 0); + buttonPrint.Name = "buttonPrint"; + buttonPrint.Size = new Size(108, 36); + buttonPrint.TabIndex = 0; + buttonPrint.Text = "Распечатать"; + buttonPrint.UseVisualStyleBackColor = true; + buttonPrint.Click += buttonPrint_Click; + // + // FormPreviewPDF + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(478, 576); + Controls.Add(panel1); + Controls.Add(axAcropdf); + Name = "FormPreviewPDF"; + Text = "FormPreviewPDF"; + Load += FormPreviewPDF_Load; + ((System.ComponentModel.ISupportInitialize)axAcropdf).EndInit(); + panel1.ResumeLayout(false); + ResumeLayout(false); + } + + #endregion + + private AxAcroPDFLib.AxAcroPDF axAcropdf; + private Panel panel1; + private Button buttonCancel; + private Button buttonPrint; + } +} \ No newline at end of file diff --git a/WinFormsApp/FormPreviewPDF.cs b/WinFormsApp/FormPreviewPDF.cs new file mode 100644 index 0000000..888512b --- /dev/null +++ b/WinFormsApp/FormPreviewPDF.cs @@ -0,0 +1,32 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace WinFormsApp +{ + public partial class FormPreviewPDF : Form + { + public string src { get; set; } + public FormPreviewPDF() + { + InitializeComponent(); + } + + private void buttonPrint_Click(object sender, EventArgs e) + { + DialogResult = DialogResult.OK; + Close(); + } + + private void FormPreviewPDF_Load(object sender, EventArgs e) + { + axAcropdf.src = src; + } + } +} diff --git a/WinFormsApp/FormPreviewPDF.resx b/WinFormsApp/FormPreviewPDF.resx new file mode 100644 index 0000000..24f9693 --- /dev/null +++ b/WinFormsApp/FormPreviewPDF.resx @@ -0,0 +1,128 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + + AAEAAAD/////AQAAAAAAAAAMAgAAAEZTeXN0ZW0uV2luZG93cy5Gb3JtcywgQ3VsdHVyZT1uZXV0cmFs + LCBQdWJsaWNLZXlUb2tlbj1iNzdhNWM1NjE5MzRlMDg5BQEAAAAhU3lzdGVtLldpbmRvd3MuRm9ybXMu + QXhIb3N0K1N0YXRlAQAAAAREYXRhBwICAAAACQMAAAAPAwAAACEAAAACAQAAAAEAAAAAAAAAAAAAAAAM + AAAAAA4AANgTAADYEwAACw== + + + \ No newline at end of file diff --git a/WinFormsApp/Program.cs b/WinFormsApp/Program.cs index 3cd5083..18696a5 100644 --- a/WinFormsApp/Program.cs +++ b/WinFormsApp/Program.cs @@ -61,6 +61,7 @@ namespace WinFormsApp services.AddTransient(); services.AddTransient(); services.AddTransient(); + services.AddTransient(); } } diff --git a/WinFormsApp/WinFormsApp.csproj b/WinFormsApp/WinFormsApp.csproj index 4a12fd9..7d85a86 100644 --- a/WinFormsApp/WinFormsApp.csproj +++ b/WinFormsApp/WinFormsApp.csproj @@ -8,6 +8,26 @@ enable + + + tlbimp + 0 + 1 + 05bfd3f1-6319-4f30-b752-c7a22889bcc4 + 0 + false + true + + + aximp + 0 + 1 + 05bfd3f1-6319-4f30-b752-c7a22889bcc4 + 0 + false + + + all From 933a3bf3ea275e17fd77f69ed5891d4162feae86 Mon Sep 17 00:00:00 2001 From: the Date: Tue, 25 Jun 2024 14:27:20 +0400 Subject: [PATCH 9/9] =?UTF-8?q?=D0=BE=D0=BD=20=D0=B2=D0=BD=D0=B5=D0=B7?= =?UTF-8?q?=D0=B0=D0=BF=D0=BD=D0=BE=20=D0=BF=D0=B5=D1=80=D0=B5=D1=81=D1=82?= =?UTF-8?q?=D0=B0=D0=BB=20=D0=BE=D1=82=D0=BE=D0=B1=D1=80=D0=B0=D0=B6=D0=B0?= =?UTF-8?q?=D1=82=D1=8C=20=D0=BF=D0=B4=D1=84=20=D0=B4=D0=BE=D0=BA=D1=83?= =?UTF-8?q?=D0=BC=D0=B5=D0=BD=D1=82=20=D0=B8=20=D1=8F=20=D0=BD=D0=B5=20?= =?UTF-8?q?=D0=B7=D0=BD=D0=B0=D1=8E=20=D0=BF=D0=BE=D1=87=D0=B5=D0=BC=D1=83?= =?UTF-8?q?=20=D0=BD=D0=BE=20=D0=BA=D0=BE=D0=BC=D0=BC=D0=B8=D1=82=20=D0=BD?= =?UTF-8?q?=D0=B0=D0=B4=D0=BE=20=D1=81=D0=B4=D0=B5=D0=BB=D0=B0=D1=82=D1=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- WinFormsApp/FormMain.cs | 27 +++++++++++++------------- WinFormsApp/FormPreviewPDF.Designer.cs | 4 +++- WinFormsApp/FormPreviewPDF.cs | 14 +++++++++++++ 3 files changed, 30 insertions(+), 15 deletions(-) diff --git a/WinFormsApp/FormMain.cs b/WinFormsApp/FormMain.cs index fa4a804..7ca4a5e 100644 --- a/WinFormsApp/FormMain.cs +++ b/WinFormsApp/FormMain.cs @@ -153,14 +153,11 @@ namespace WinFormsApp MessageBox.Show("Выберите одну поставку для формирования отчета", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } - using var dialog = new SaveFileDialog { Filter = "pdf|*.pdf" }; - if (dialog.ShowDialog() == DialogResult.OK) - { try { _reportLogic.SaveSuppliesToPdfFile(new ReportBindingModel { - FileName = dialog.FileName, + FileName = $"supplyreport{dataGridView.SelectedRows[0].Cells["Id"].Value}.pdf", Date = (DateTime)dataGridView.SelectedRows[0].Cells["Date"].Value, SupplyId = (Guid)dataGridView.SelectedRows[0].Cells["Id"].Value }); @@ -172,22 +169,24 @@ namespace WinFormsApp _logger.LogError(ex, "Ошибка сохранения отчета о поставке"); MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); } - } } private void buttonPrintReport_Click(object sender, EventArgs e) { - var dialog = new OpenFileDialog(); - if (dialog.ShowDialog() == DialogResult.OK) + if (dataGridView.SelectedRows.Count != 1) return; + var service = Program.ServiceProvider?.GetService(typeof(FormPreviewPDF)); + if (service is FormPreviewPDF form) { - var service = Program.ServiceProvider?.GetService(typeof(FormPreviewPDF)); - if (service is FormPreviewPDF form) + var src = $"supplyreport{dataGridView.SelectedRows[0].Cells["Id"].Value}.pdf"; + if (!File.Exists(src)) { - form.src = dialog.FileName; - if (form.ShowDialog() == DialogResult.OK) - { - IronPrint.Printer.PrintAsync(dialog.FileName); - } + MessageBox.Show("Отчёт о поставке не был найден. Сначала сформируйте отчёт по выбранной поставке.", "Ошибка"); + return; + } + form.src = System.IO.Path.GetFullPath(src); + if (form.ShowDialog() == DialogResult.OK) + { + IronPrint.Printer.PrintAsync(src); } } } diff --git a/WinFormsApp/FormPreviewPDF.Designer.cs b/WinFormsApp/FormPreviewPDF.Designer.cs index 74092aa..cee0077 100644 --- a/WinFormsApp/FormPreviewPDF.Designer.cs +++ b/WinFormsApp/FormPreviewPDF.Designer.cs @@ -39,13 +39,14 @@ // // axAcropdf // - axAcropdf.Dock = DockStyle.Fill; + axAcropdf.Dock = DockStyle.Top; axAcropdf.Enabled = true; axAcropdf.Location = new Point(0, 0); axAcropdf.Name = "axAcropdf"; axAcropdf.OcxState = (AxHost.State)resources.GetObject("axAcropdf.OcxState"); axAcropdf.Size = new Size(478, 576); axAcropdf.TabIndex = 0; + axAcropdf.Enter += axAcropdf_Enter; // // panel1 // @@ -66,6 +67,7 @@ buttonCancel.TabIndex = 1; buttonCancel.Text = "Отмена"; buttonCancel.UseVisualStyleBackColor = true; + buttonCancel.Click += buttonCancel_Click; // // buttonPrint // diff --git a/WinFormsApp/FormPreviewPDF.cs b/WinFormsApp/FormPreviewPDF.cs index 888512b..47a67ed 100644 --- a/WinFormsApp/FormPreviewPDF.cs +++ b/WinFormsApp/FormPreviewPDF.cs @@ -27,6 +27,20 @@ namespace WinFormsApp private void FormPreviewPDF_Load(object sender, EventArgs e) { axAcropdf.src = src; + axAcropdf.LoadFile(src); + axAcropdf.setView("Fit"); + axAcropdf.Show(); + } + + private void buttonCancel_Click(object sender, EventArgs e) + { + DialogResult = DialogResult.Cancel; + Close(); + } + + private void axAcropdf_Enter(object sender, EventArgs e) + { + } } }