Пдфка создаётся

This commit is contained in:
GokaPek 2024-10-31 00:02:20 +04:00
parent 005a281753
commit 5fdba2649f
5 changed files with 174 additions and 19 deletions

View File

@ -28,19 +28,34 @@
/// </summary>
private void InitializeComponent()
{
components = new System.ComponentModel.Container();
menuStrip1 = new MenuStrip();
createToolStripMenuItem = new ToolStripMenuItem();
updateToolStripMenuItem = new ToolStripMenuItem();
deleteToolStripMenuItem = new ToolStripMenuItem();
manufacturerToolStripMenuItem = new ToolStripMenuItem();
documentsToolStripMenuItem = new ToolStripMenuItem();
pdfImageToolStripMenuItem = new ToolStripMenuItem();
exelTableToolStripMenuItem = new ToolStripMenuItem();
wordGistToolStripMenuItem = new ToolStripMenuItem();
outputTableResults = new Library15Gerimovich.OutputTableResults();
pdfImg = new Library14Petrushin.PdfImg(components);
wordDiagramComponent = new Library15Gerimovich.WordDiagramComponent(components);
componentTable = new WinFormsLibrary1.ComponentTable(components);
saveFileDialog = new SaveFileDialog(); // Инициализация SaveFileDialog
// Настройка SaveFileDialog
saveFileDialog.Filter = "PDF Files (*.pdf)|*.pdf";
saveFileDialog.Title = "Save PDF Document";
saveFileDialog.FileName = "Products.pdf";
menuStrip1.SuspendLayout();
SuspendLayout();
//
// menuStrip1
//
menuStrip1.ImageScalingSize = new Size(20, 20);
menuStrip1.Items.AddRange(new ToolStripItem[] { createToolStripMenuItem, updateToolStripMenuItem, deleteToolStripMenuItem, manufacturerToolStripMenuItem });
menuStrip1.Items.AddRange(new ToolStripItem[] { createToolStripMenuItem, updateToolStripMenuItem, deleteToolStripMenuItem, manufacturerToolStripMenuItem, documentsToolStripMenuItem });
menuStrip1.Location = new Point(0, 0);
menuStrip1.Name = "menuStrip1";
menuStrip1.Size = new Size(480, 28);
@ -75,6 +90,34 @@
manufacturerToolStripMenuItem.Text = "Manufacturer";
manufacturerToolStripMenuItem.Click += manufacturersToolStripMenuItem_Click;
//
// documentsToolStripMenuItem
//
documentsToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { pdfImageToolStripMenuItem, exelTableToolStripMenuItem, wordGistToolStripMenuItem });
documentsToolStripMenuItem.Name = "documentsToolStripMenuItem";
documentsToolStripMenuItem.Size = new Size(98, 24);
documentsToolStripMenuItem.Text = "Documents";
//
// pdfImageToolStripMenuItem
//
pdfImageToolStripMenuItem.Name = "pdfImageToolStripMenuItem";
pdfImageToolStripMenuItem.Size = new Size(224, 26);
pdfImageToolStripMenuItem.Text = "Pdf Image";
pdfImageToolStripMenuItem.Click += createSimpleDocumentToolStripMenuItem_Click;
//
// exelTableToolStripMenuItem
//
exelTableToolStripMenuItem.Name = "exelTableToolStripMenuItem";
exelTableToolStripMenuItem.Size = new Size(224, 26);
exelTableToolStripMenuItem.Text = "Exel table";
exelTableToolStripMenuItem.Click += createCustomTableDocumentToolStripMenuItem_Click;
//
// wordGistToolStripMenuItem
//
wordGistToolStripMenuItem.Name = "wordGistToolStripMenuItem";
wordGistToolStripMenuItem.Size = new Size(224, 26);
wordGistToolStripMenuItem.Text = "Word gist";
wordGistToolStripMenuItem.Click += createChartDocumentToolStripMenuItem_Click;
//
// outputTableResults
//
outputTableResults.Location = new Point(12, 32);
@ -94,6 +137,7 @@
MainMenuStrip = menuStrip1;
Name = "MainForm";
Text = "Form1";
KeyDown += MainForm_KeyDown;
menuStrip1.ResumeLayout(false);
menuStrip1.PerformLayout();
ResumeLayout(false);
@ -108,5 +152,12 @@
private Library15Gerimovich.OutputTableResults outputTableResults;
private ToolStripMenuItem deleteToolStripMenuItem;
private ToolStripMenuItem manufacturerToolStripMenuItem;
private ToolStripMenuItem documentsToolStripMenuItem;
private ToolStripMenuItem pdfImageToolStripMenuItem;
private ToolStripMenuItem exelTableToolStripMenuItem;
private ToolStripMenuItem wordGistToolStripMenuItem;
private Library14Petrushin.PdfImg pdfImg;
private Library15Gerimovich.WordDiagramComponent wordDiagramComponent;
private WinFormsLibrary1.ComponentTable componentTable;
}
}

View File

@ -3,6 +3,7 @@ using Data.Repositories;
using View;
using System.Windows.Forms;
using Data.Models;
using Library14Petrushin;
namespace Laba3
{
@ -10,6 +11,7 @@ namespace Laba3
{
private readonly IProductRepository _productRepository;
private readonly IManufacturerRepository _manufacturerRepository;
private SaveFileDialog saveFileDialog;
public MainForm(IProductRepository productRepository, IManufacturerRepository manufacturerRepository)
{
@ -53,13 +55,18 @@ namespace Laba3
private void editToolStripMenuItem_Click(object sender, EventArgs e)
{
var selectedProductId = outputTableResults.GetSelectedObject<Product>().Id;
var selectedProduct = _productRepository.GetProductById(selectedProductId);
var productForm = new ProductForm(_productRepository, _manufacturerRepository, selectedProduct);
if (productForm.ShowDialog() == DialogResult.OK)
try
{
LoadProducts();
var selectedProductId = outputTableResults.GetSelectedObject<Product>().Id;
var selectedProduct = _productRepository.GetProductById(selectedProductId);
var productForm = new ProductForm(_productRepository, _manufacturerRepository, selectedProduct);
if (productForm.ShowDialog() == DialogResult.OK)
{
LoadProducts();
}
}
catch (Exception ex) {
MessageBox.Show(ex.ToString());
}
}
@ -78,5 +85,94 @@ namespace Laba3
var manufacturerForm = new ManufacturerForm(_manufacturerRepository);
manufacturerForm.ShowDialog();
}
private void createSimpleDocumentToolStripMenuItem_Click(object sender, EventArgs e)
{
// Получаем изображения из базы данных
var images = GetImagesFromDatabase();
if (images.Count > 0)
{
// Показываем диалоговое окно для выбора пути сохранения
if (saveFileDialog.ShowDialog() == DialogResult.OK)
{
// Создаем компонент PdfImg
var pdfImg = new Library14Petrushin.PdfImg();
// Путь для сохранения PDF-документа
string fileName = saveFileDialog.FileName;
// Заголовок документа
string documentTitle = "Product Images";
// Создаем PDF-документ
pdfImg.CreatePdfDocument(fileName, documentTitle, images);
}
}
else
{
MessageBox.Show("No images found in the database.");
}
}
private void createCustomTableDocumentToolStripMenuItem_Click(object sender, EventArgs e)
{
// Реализация создания документа с настраиваемой таблицей
}
private void createChartDocumentToolStripMenuItem_Click(object sender, EventArgs e)
{
// Реализация создания документа с диаграммой
}
private void MainForm_KeyDown(object sender, KeyEventArgs e)
{
if (e.Control)
{
switch (e.KeyCode)
{
case Keys.A:
addToolStripMenuItem_Click(null, EventArgs.Empty);
break;
case Keys.U:
editToolStripMenuItem_Click(null, EventArgs.Empty);
break;
case Keys.D:
deleteToolStripMenuItem_Click(null, EventArgs.Empty);
break;
case Keys.S:
createSimpleDocumentToolStripMenuItem_Click(null, EventArgs.Empty);
break;
case Keys.T:
createCustomTableDocumentToolStripMenuItem_Click(null, EventArgs.Empty);
break;
case Keys.C:
createChartDocumentToolStripMenuItem_Click(null, EventArgs.Empty);
break;
}
}
}
private List<ImageData> GetImagesFromDatabase()
{
var images = new List<ImageData>();
var products = _productRepository.GetAllProducts();
foreach (var product in products)
{
if (product.Image != null)
{
// Создаем временный файл для сохранения изображения
string tempFilePath = Path.GetTempFileName();
File.WriteAllBytes(tempFilePath, product.Image);
// Добавляем путь к временному файлу в список
images.Add(new ImageData { ImagePath = tempFilePath });
}
}
return images;
}
}
}

View File

@ -120,4 +120,13 @@
<metadata name="menuStrip1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>17, 17</value>
</metadata>
<metadata name="pdfImg.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>153, 17</value>
</metadata>
<metadata name="wordDiagramComponent.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>258, 17</value>
</metadata>
<metadata name="componentTable.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>484, 17</value>
</metadata>
</root>

View File

@ -105,7 +105,6 @@
Controls.Add(dtpDeliveryDate);
Name = "ProductForm";
Text = "ProductForm";
Load += ProductForm_Load;
((System.ComponentModel.ISupportInitialize)pbImage).EndInit();
ResumeLayout(false);
}

View File

@ -25,8 +25,18 @@ namespace Laba3
public ProductForm(IProductRepository productRepository, IManufacturerRepository manufacturerRepository, Product product = null)
{
InitializeComponent();
_productRepository = productRepository;
_manufacturerRepository = manufacturerRepository;
var manufacturers = _manufacturerRepository.GetAllManufacturers().Select(m => m.Name).ToList();
// cmbManufacturer.Data = manufacturers;
foreach (var manufacturer in manufacturers)
{
cmbManufacturer.AddItem(manufacturer);
}
_product = product;
_isNewProduct = product == null;
txtName.MinLength = MINL;
@ -36,7 +46,7 @@ namespace Laba3
if (!_isNewProduct)
{
txtName.InputValue = _product.Name;
cmbManufacturer.SelectedValue= _product.ManufacturerName;
cmbManufacturer.SelectedValue = _product.ManufacturerName;
dtpDeliveryDate.Date = _product.DeliveryDate;
if (_product.Image != null)
{
@ -99,15 +109,5 @@ namespace Laba3
DialogResult = DialogResult.OK;
Close();
}
private void ProductForm_Load(object sender, EventArgs e)
{
var manufacturers = _manufacturerRepository.GetAllManufacturers().Select(m => m.Name).ToList();
// cmbManufacturer.Data = manufacturers;
foreach (var manufacturer in manufacturers)
{
cmbManufacturer.AddItem(manufacturer);
}
}
}
}