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) + { + } } }