diff --git a/BusinessLogic/BusinessLogic.csproj b/BusinessLogic/BusinessLogic.csproj index c4585ce..fed513d 100644 --- a/BusinessLogic/BusinessLogic.csproj +++ b/BusinessLogic/BusinessLogic.csproj @@ -16,6 +16,7 @@ + diff --git a/BusinessLogic/OfficePackage/Implements/SaveToPdf.cs b/BusinessLogic/OfficePackage/Implements/SaveToPdf.cs index ff2e318..049a98d 100644 --- a/BusinessLogic/OfficePackage/Implements/SaveToPdf.cs +++ b/BusinessLogic/OfficePackage/Implements/SaveToPdf.cs @@ -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 { diff --git a/WinFormsApp/FormMain.Designer.cs b/WinFormsApp/FormMain.Designer.cs index 1567d57..37987cd 100644 --- a/WinFormsApp/FormMain.Designer.cs +++ b/WinFormsApp/FormMain.Designer.cs @@ -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; } } \ No newline at end of file diff --git a/WinFormsApp/FormMain.cs b/WinFormsApp/FormMain.cs index e9fa189..2da2aab 100644 --- a/WinFormsApp/FormMain.cs +++ b/WinFormsApp/FormMain.cs @@ -22,13 +22,15 @@ namespace WinFormsApp private readonly ISupplyLogic _supplyLogic; private readonly IProductLogic _productLogic; private readonly ISupplierLogic _supplierLogic; - public FormMain(ILogger logger, ISupplierLogic supplierLogic, ISupplyLogic supplyLogic, IProductLogic productLogic) + private readonly IReportLogic _reportLogic; + public FormMain(ILogger 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); + } + } + } } } diff --git a/WinFormsApp/Program.cs b/WinFormsApp/Program.cs index d830c81..3cd5083 100644 --- a/WinFormsApp/Program.cs +++ b/WinFormsApp/Program.cs @@ -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(); services.AddTransient(); services.AddTransient(); + services.AddTransient(); services.AddTransient();