From 933a3bf3ea275e17fd77f69ed5891d4162feae86 Mon Sep 17 00:00:00 2001 From: the Date: Tue, 25 Jun 2024 14:27:20 +0400 Subject: [PATCH] =?UTF-8?q?=D0=BE=D0=BD=20=D0=B2=D0=BD=D0=B5=D0=B7=D0=B0?= =?UTF-8?q?=D0=BF=D0=BD=D0=BE=20=D0=BF=D0=B5=D1=80=D0=B5=D1=81=D1=82=D0=B0?= =?UTF-8?q?=D0=BB=20=D0=BE=D1=82=D0=BE=D0=B1=D1=80=D0=B0=D0=B6=D0=B0=D1=82?= =?UTF-8?q?=D1=8C=20=D0=BF=D0=B4=D1=84=20=D0=B4=D0=BE=D0=BA=D1=83=D0=BC?= =?UTF-8?q?=D0=B5=D0=BD=D1=82=20=D0=B8=20=D1=8F=20=D0=BD=D0=B5=20=D0=B7?= =?UTF-8?q?=D0=BD=D0=B0=D1=8E=20=D0=BF=D0=BE=D1=87=D0=B5=D0=BC=D1=83=20?= =?UTF-8?q?=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) + { + } } }