From 5eaeef8528d0970645fa6d7095a7c2f45bf7b3d3 Mon Sep 17 00:00:00 2001 From: the Date: Tue, 25 Jun 2024 15:30:02 +0400 Subject: [PATCH 1/2] =?UTF-8?q?=D0=BD=D1=83=20=D0=B5=D0=B3=D0=BE=20=D0=BD?= =?UTF-8?q?=D0=B0=D1=85=D0=B5=D1=80=20=D1=8D=D1=82=D0=BE=D1=82=20=D0=B2?= =?UTF-8?q?=D0=B0=D1=88=20=D0=B0=D0=B4=D0=BE=D0=B1=20=D0=BA=D0=BE=D1=80?= =?UTF-8?q?=D0=BE=D1=87=D0=B5=20=D1=8F=20=D1=80=D0=B5=D1=88=D0=B8=D0=BB=20?= =?UTF-8?q?=D0=BF=D0=BE=20=D0=B4=D1=80=D1=83=D0=B3=D0=BE=D0=BC=D1=83=20?= =?UTF-8?q?=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/FormPreviewPDF.Designer.cs | 32 +++++++++++--------------- WinFormsApp/FormPreviewPDF.cs | 13 +++++++---- WinFormsApp/FormPreviewPDF.resx | 8 ------- WinFormsApp/WinFormsApp.csproj | 1 + 4 files changed, 23 insertions(+), 31 deletions(-) diff --git a/WinFormsApp/FormPreviewPDF.Designer.cs b/WinFormsApp/FormPreviewPDF.Designer.cs index cee0077..435f282 100644 --- a/WinFormsApp/FormPreviewPDF.Designer.cs +++ b/WinFormsApp/FormPreviewPDF.Designer.cs @@ -28,26 +28,14 @@ /// 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(); + pictureBox = new PictureBox(); panel1.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)pictureBox).BeginInit(); SuspendLayout(); // - // axAcropdf - // - 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 // panel1.Controls.Add(buttonCancel); @@ -80,26 +68,34 @@ buttonPrint.UseVisualStyleBackColor = true; buttonPrint.Click += buttonPrint_Click; // + // pictureBox + // + pictureBox.Dock = DockStyle.Fill; + pictureBox.Location = new Point(0, 0); + pictureBox.Name = "pictureBox"; + pictureBox.Size = new Size(478, 540); + pictureBox.TabIndex = 2; + pictureBox.TabStop = false; + // // FormPreviewPDF // AutoScaleDimensions = new SizeF(7F, 15F); AutoScaleMode = AutoScaleMode.Font; ClientSize = new Size(478, 576); + Controls.Add(pictureBox); Controls.Add(panel1); - Controls.Add(axAcropdf); Name = "FormPreviewPDF"; Text = "FormPreviewPDF"; Load += FormPreviewPDF_Load; - ((System.ComponentModel.ISupportInitialize)axAcropdf).EndInit(); panel1.ResumeLayout(false); + ((System.ComponentModel.ISupportInitialize)pictureBox).EndInit(); ResumeLayout(false); } #endregion - - private AxAcroPDFLib.AxAcroPDF axAcropdf; private Panel panel1; private Button buttonCancel; private Button buttonPrint; + private PictureBox pictureBox; } } \ No newline at end of file diff --git a/WinFormsApp/FormPreviewPDF.cs b/WinFormsApp/FormPreviewPDF.cs index 47a67ed..96daac5 100644 --- a/WinFormsApp/FormPreviewPDF.cs +++ b/WinFormsApp/FormPreviewPDF.cs @@ -1,4 +1,6 @@ -using System; +using Spire.Pdf; +using Spire.Pdf.Graphics; +using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; @@ -26,10 +28,11 @@ namespace WinFormsApp private void FormPreviewPDF_Load(object sender, EventArgs e) { - axAcropdf.src = src; - axAcropdf.LoadFile(src); - axAcropdf.setView("Fit"); - axAcropdf.Show(); + var doc = new PdfDocument(); + doc.LoadFromFile(src); + Image image = doc.SaveAsImage(0, PdfImageType.Bitmap, 500, 1000); + pictureBox.Image = image; + pictureBox.SizeMode = PictureBoxSizeMode.Zoom; } private void buttonCancel_Click(object sender, EventArgs e) diff --git a/WinFormsApp/FormPreviewPDF.resx b/WinFormsApp/FormPreviewPDF.resx index 24f9693..af32865 100644 --- a/WinFormsApp/FormPreviewPDF.resx +++ b/WinFormsApp/FormPreviewPDF.resx @@ -117,12 +117,4 @@ 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/WinFormsApp.csproj b/WinFormsApp/WinFormsApp.csproj index 7d85a86..42a15a7 100644 --- a/WinFormsApp/WinFormsApp.csproj +++ b/WinFormsApp/WinFormsApp.csproj @@ -35,6 +35,7 @@ + From 7776de448b90d88f6cf058af730692ddb1a78076 Mon Sep 17 00:00:00 2001 From: the Date: Tue, 25 Jun 2024 15:47:50 +0400 Subject: [PATCH 2/2] =?UTF-8?q?=D0=BF=D1=80=D0=BE=D0=BC=D0=BF=D1=82=20?= =?UTF-8?q?=D0=BE=20=D1=81=D0=BE=D0=B7=D0=B4=D0=B0=D0=BD=D0=B8=D0=B8=20?= =?UTF-8?q?=D0=BE=D1=82=D1=87=D1=91=D1=82=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- WinFormsApp/FormMain.cs | 23 +++++++++++++++++++++-- WinFormsApp/FormPreviewPDF.cs | 5 ----- 2 files changed, 21 insertions(+), 7 deletions(-) diff --git a/WinFormsApp/FormMain.cs b/WinFormsApp/FormMain.cs index 7ca4a5e..04fa1f1 100644 --- a/WinFormsApp/FormMain.cs +++ b/WinFormsApp/FormMain.cs @@ -180,8 +180,27 @@ namespace WinFormsApp var src = $"supplyreport{dataGridView.SelectedRows[0].Cells["Id"].Value}.pdf"; if (!File.Exists(src)) { - MessageBox.Show("Отчёт о поставке не был найден. Сначала сформируйте отчёт по выбранной поставке.", "Ошибка"); - return; + var result = MessageBox.Show("Отчёт о поставке не был найден. Сформировать?", "", MessageBoxButtons.YesNo); + if (result == DialogResult.Yes) + { + try + { + _reportLogic.SaveSuppliesToPdfFile(new ReportBindingModel + { + 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 + }); + _logger.LogInformation("Сохранение отчета о поставке"); + MessageBox.Show("Выполнено", "Успех", MessageBoxButtons.OK, MessageBoxIcon.Information); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка сохранения отчета о поставке"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + else return; } form.src = System.IO.Path.GetFullPath(src); if (form.ShowDialog() == DialogResult.OK) diff --git a/WinFormsApp/FormPreviewPDF.cs b/WinFormsApp/FormPreviewPDF.cs index 96daac5..ead3d5e 100644 --- a/WinFormsApp/FormPreviewPDF.cs +++ b/WinFormsApp/FormPreviewPDF.cs @@ -40,10 +40,5 @@ namespace WinFormsApp DialogResult = DialogResult.Cancel; Close(); } - - private void axAcropdf_Enter(object sender, EventArgs e) - { - - } } }