самый стандартный пдф документ который работает

This commit is contained in:
the 2024-06-24 19:26:39 +04:00
parent c716bda901
commit 489be1deb8
5 changed files with 51 additions and 1 deletions

View File

@ -16,6 +16,7 @@
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="8.0.1" />
<PackageReference Include="PdfSharp.MigraDoc.Standard" Version="1.51.15" />
<PackageReference Include="System.IdentityModel.Tokens.Jwt" Version="7.6.0" />
<PackageReference Include="System.Text.Encoding.CodePages" Version="8.0.0" />
</ItemGroup>
<ItemGroup>

View File

@ -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
{

View File

@ -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;
}
}

View File

@ -22,13 +22,15 @@ namespace WinFormsApp
private readonly ISupplyLogic _supplyLogic;
private readonly IProductLogic _productLogic;
private readonly ISupplierLogic _supplierLogic;
public FormMain(ILogger<FormMain> logger, ISupplierLogic supplierLogic, ISupplyLogic supplyLogic, IProductLogic productLogic)
private readonly IReportLogic _reportLogic;
public FormMain(ILogger<FormMain> 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);
}
}
}
}
}

View File

@ -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<ISupplierLogic, SupplierLogic>();
services.AddTransient<IProductLogic, ProductLogic>();
services.AddTransient<IMediaFileLogic, MediaFileLogic>();
services.AddTransient<IReportLogic, ReportLogic>();
services.AddTransient<AbstractSaveToPdf, SaveToPdf>();