This commit is contained in:
devil_1nc 2024-06-25 15:51:01 +04:00
commit 882a46ba3b
5 changed files with 44 additions and 38 deletions

View File

@ -180,8 +180,27 @@ namespace WinFormsApp
var src = $"supplyreport{dataGridView.SelectedRows[0].Cells["Id"].Value}.pdf"; var src = $"supplyreport{dataGridView.SelectedRows[0].Cells["Id"].Value}.pdf";
if (!File.Exists(src)) if (!File.Exists(src))
{ {
MessageBox.Show("Отчёт о поставке не был найден. Сначала сформируйте отчёт по выбранной поставке.", "Ошибка"); var result = MessageBox.Show("Отчёт о поставке не был найден. Сформировать?", "", MessageBoxButtons.YesNo);
return; 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); form.src = System.IO.Path.GetFullPath(src);
if (form.ShowDialog() == DialogResult.OK) if (form.ShowDialog() == DialogResult.OK)

View File

@ -28,26 +28,14 @@
/// </summary> /// </summary>
private void InitializeComponent() private void InitializeComponent()
{ {
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(FormPreviewPDF));
axAcropdf = new AxAcroPDFLib.AxAcroPDF();
panel1 = new Panel(); panel1 = new Panel();
buttonCancel = new Button(); buttonCancel = new Button();
buttonPrint = new Button(); buttonPrint = new Button();
((System.ComponentModel.ISupportInitialize)axAcropdf).BeginInit(); pictureBox = new PictureBox();
panel1.SuspendLayout(); panel1.SuspendLayout();
((System.ComponentModel.ISupportInitialize)pictureBox).BeginInit();
SuspendLayout(); 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
// //
panel1.Controls.Add(buttonCancel); panel1.Controls.Add(buttonCancel);
@ -80,26 +68,34 @@
buttonPrint.UseVisualStyleBackColor = true; buttonPrint.UseVisualStyleBackColor = true;
buttonPrint.Click += buttonPrint_Click; 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 // FormPreviewPDF
// //
AutoScaleDimensions = new SizeF(7F, 15F); AutoScaleDimensions = new SizeF(7F, 15F);
AutoScaleMode = AutoScaleMode.Font; AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(478, 576); ClientSize = new Size(478, 576);
Controls.Add(pictureBox);
Controls.Add(panel1); Controls.Add(panel1);
Controls.Add(axAcropdf);
Name = "FormPreviewPDF"; Name = "FormPreviewPDF";
Text = "FormPreviewPDF"; Text = "FormPreviewPDF";
Load += FormPreviewPDF_Load; Load += FormPreviewPDF_Load;
((System.ComponentModel.ISupportInitialize)axAcropdf).EndInit();
panel1.ResumeLayout(false); panel1.ResumeLayout(false);
((System.ComponentModel.ISupportInitialize)pictureBox).EndInit();
ResumeLayout(false); ResumeLayout(false);
} }
#endregion #endregion
private AxAcroPDFLib.AxAcroPDF axAcropdf;
private Panel panel1; private Panel panel1;
private Button buttonCancel; private Button buttonCancel;
private Button buttonPrint; private Button buttonPrint;
private PictureBox pictureBox;
} }
} }

View File

@ -1,4 +1,6 @@
using System; using Spire.Pdf;
using Spire.Pdf.Graphics;
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.ComponentModel; using System.ComponentModel;
using System.Data; using System.Data;
@ -26,10 +28,11 @@ namespace WinFormsApp
private void FormPreviewPDF_Load(object sender, EventArgs e) private void FormPreviewPDF_Load(object sender, EventArgs e)
{ {
axAcropdf.src = src; var doc = new PdfDocument();
axAcropdf.LoadFile(src); doc.LoadFromFile(src);
axAcropdf.setView("Fit"); Image image = doc.SaveAsImage(0, PdfImageType.Bitmap, 500, 1000);
axAcropdf.Show(); pictureBox.Image = image;
pictureBox.SizeMode = PictureBoxSizeMode.Zoom;
} }
private void buttonCancel_Click(object sender, EventArgs e) private void buttonCancel_Click(object sender, EventArgs e)
@ -37,10 +40,5 @@ namespace WinFormsApp
DialogResult = DialogResult.Cancel; DialogResult = DialogResult.Cancel;
Close(); Close();
} }
private void axAcropdf_Enter(object sender, EventArgs e)
{
}
} }
} }

View File

@ -117,12 +117,4 @@
<resheader name="writer"> <resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value> <value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader> </resheader>
<data name="axAcropdf.OcxState" mimetype="application/x-microsoft.net.object.binary.base64">
<value>
AAEAAAD/////AQAAAAAAAAAMAgAAAEZTeXN0ZW0uV2luZG93cy5Gb3JtcywgQ3VsdHVyZT1uZXV0cmFs
LCBQdWJsaWNLZXlUb2tlbj1iNzdhNWM1NjE5MzRlMDg5BQEAAAAhU3lzdGVtLldpbmRvd3MuRm9ybXMu
QXhIb3N0K1N0YXRlAQAAAAREYXRhBwICAAAACQMAAAAPAwAAACEAAAACAQAAAAEAAAAAAAAAAAAAAAAM
AAAAAA4AANgTAADYEwAACw==
</value>
</data>
</root> </root>

View File

@ -35,6 +35,7 @@
</PackageReference> </PackageReference>
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="8.0.0" /> <PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="8.0.0" />
<PackageReference Include="NLog.Extensions.Logging" Version="5.3.11" /> <PackageReference Include="NLog.Extensions.Logging" Version="5.3.11" />
<PackageReference Include="Spire.PDF" Version="10.6.7" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>