pdf с картинками

This commit is contained in:
a.puchkina 2024-10-28 21:17:45 +04:00
parent 17c1521e2a
commit caaa65f204
11 changed files with 55 additions and 30 deletions

View File

@ -11,6 +11,6 @@ namespace LibraryAccountingApp_lab3.Contracts.BindingModels
public string Author { get; set; } public string Author { get; set; }
public string Date { get; set; } public string Date { get; set; }
public string Image { get; set; } public byte[] Image { get; set; }
} }
} }

View File

@ -14,6 +14,6 @@ namespace LibraryAccountingApp_lab3.Contracts.ViewModels
[DisplayName("Дата издания")] [DisplayName("Дата издания")]
public string Date { get; set; } public string Date { get; set; }
public string Image { get; set; } public byte[] Image { get; set; }
} }
} }

View File

@ -5,6 +5,6 @@
string Title { get; } string Title { get; }
string Author { get; } string Author { get; }
string Date { get; } string Date { get; }
string Image { get; } byte[] Image { get; }
} }
} }

View File

@ -9,7 +9,7 @@ namespace LibraryAccountingApp_lab3.DatabaseImplement
{ {
if (optionsBuilder.IsConfigured == false) if (optionsBuilder.IsConfigured == false)
{ {
optionsBuilder.UseSqlServer(@"Data Source=PC-Anna\SQLEXPRESS;Initial Catalog=LibraryAppCOP3;Integrated Security=True;MultipleActiveResultSets=True;;TrustServerCertificate=True"); optionsBuilder.UseSqlServer(@"Data Source=PC-Anna\SQLEXPRESS;Initial Catalog=LibraryAppCOP4;Integrated Security=True;MultipleActiveResultSets=True;;TrustServerCertificate=True");
//optionsBuilder.UseNpgsql("Host=localhost;Database=LibraryAppCOP;Username=postgres;Password=postgres"); //optionsBuilder.UseNpgsql("Host=localhost;Database=LibraryAppCOP;Username=postgres;Password=postgres");
} }
base.OnConfiguring(optionsBuilder); base.OnConfiguring(optionsBuilder);

View File

@ -16,6 +16,6 @@ namespace LibraryAccountingApp_lab3.DatabaseImplement.Models
public string Date { get; set; } public string Date { get; set; }
[Required] [Required]
public string Image { get; set; } public byte[] Image { get; set; }
} }
} }

View File

@ -43,7 +43,7 @@
label1 = new Label(); label1 = new Label();
groupBox2 = new GroupBox(); groupBox2 = new GroupBox();
controlDataTableCellBooks = new ControlsLibraryNet60.Data.ControlDataTableCell(); controlDataTableCellBooks = new ControlsLibraryNet60.Data.ControlDataTableCell();
pdfForImages1 = new COP_5.PdfForImages(components); pdfForImages = new COP_5.PdfForImages(components);
componentDocumentWithChartBarWord1 = new ComponentsLibraryNet60.DocumentWithChart.ComponentDocumentWithChartBarWord(components); componentDocumentWithChartBarWord1 = new ComponentsLibraryNet60.DocumentWithChart.ComponentDocumentWithChartBarWord(components);
tableComponent1 = new FedComponentLib.NonVisualComponents.TableComponent(components); tableComponent1 = new FedComponentLib.NonVisualComponents.TableComponent(components);
buttonPdfCreate = new Button(); buttonPdfCreate = new Button();
@ -214,12 +214,13 @@
// //
// buttonPdfCreate // buttonPdfCreate
// //
buttonPdfCreate.Location = new Point(46, 32); buttonPdfCreate.Location = new Point(20, 35);
buttonPdfCreate.Name = "buttonPdfCreate"; buttonPdfCreate.Name = "buttonPdfCreate";
buttonPdfCreate.Size = new Size(114, 48); buttonPdfCreate.Size = new Size(132, 48);
buttonPdfCreate.TabIndex = 20; buttonPdfCreate.TabIndex = 20;
buttonPdfCreate.Text = "Создать PDF с обложками"; buttonPdfCreate.Text = "Создать PDF с обложками";
buttonPdfCreate.UseVisualStyleBackColor = true; buttonPdfCreate.UseVisualStyleBackColor = true;
buttonPdfCreate.Click += buttonPdfCreate_Click;
// //
// groupBox3 // groupBox3
// //
@ -265,7 +266,7 @@
private ControlsLibraryNet60.Data.ControlDataTableCell controlDataTableCellBooks; private ControlsLibraryNet60.Data.ControlDataTableCell controlDataTableCellBooks;
private Button buttonAddAuthor; private Button buttonAddAuthor;
private Button buttonBookDelete; private Button buttonBookDelete;
private COP_5.PdfForImages pdfForImages1; private COP_5.PdfForImages pdfForImages;
private ComponentsLibraryNet60.DocumentWithChart.ComponentDocumentWithChartBarWord componentDocumentWithChartBarWord1; private ComponentsLibraryNet60.DocumentWithChart.ComponentDocumentWithChartBarWord componentDocumentWithChartBarWord1;
private FedComponentLib.NonVisualComponents.TableComponent tableComponent1; private FedComponentLib.NonVisualComponents.TableComponent tableComponent1;
private Button buttonPdfCreate; private Button buttonPdfCreate;

View File

@ -2,6 +2,7 @@ using ComponentsLibraryNet60.Heplers;
using ControlsLibraryNet60.Data; using ControlsLibraryNet60.Data;
using ControlsLibraryNet60.Models; using ControlsLibraryNet60.Models;
using COP_5; using COP_5;
using COP_5.PdfHelper;
using DocumentFormat.OpenXml.Office2010.Excel; using DocumentFormat.OpenXml.Office2010.Excel;
using FedComponentLib; using FedComponentLib;
using LibraryAccountingApp_lab3.Contracts.BindingModels; using LibraryAccountingApp_lab3.Contracts.BindingModels;
@ -17,11 +18,10 @@ namespace LibraryAccountingApp_lab3
public partial class FormLibrary : Form public partial class FormLibrary : Form
{ {
private byte[]? selectedImage = new byte[16]; private byte[]? selectedImage = new byte[16];
private int counterBooksIds = 0;
private int counterRows = 0;
private readonly IBookLogic _bookLogic; private readonly IBookLogic _bookLogic;
private readonly IAuthorLogic _authorLogic; private readonly IAuthorLogic _authorLogic;
public readonly IBookStorage _bookStorage; public readonly IBookStorage _bookStorage;
private List<byte[]> BooksImages = new List<byte[]>();
int rowIndex = 0; int rowIndex = 0;
private int? _id; private int? _id;
public int Id { set { _id = value; } } public int Id { set { _id = value; } }
@ -44,17 +44,6 @@ namespace LibraryAccountingApp_lab3
private void FillControlSelectedComboBoxSingle() private void FillControlSelectedComboBoxSingle()
{ {
//List<string> list = new List<string>() {
// "Äåíèåë Êèç",
// "Àëåêñàíäð Ïóøêèí",
// "Ô¸äîð Äîñòîåâñêèé",
// "Áîðèñ Àêóíèí",
// "Íèêîëàñ Ñïàðêñ"
//};
//for (int i = 0; i < list.Count; i++)
//{
// controlSelectedComboBoxSingleAuthor.AddElement(list[i]);
//}
controlSelectedComboBoxSingleAuthor.Clear(); controlSelectedComboBoxSingleAuthor.Clear();
try try
{ {
@ -167,9 +156,13 @@ namespace LibraryAccountingApp_lab3
Title = textBoxTitle.Text, Title = textBoxTitle.Text,
Author = controlSelectedComboBoxSingleAuthor.SelectedElement, Author = controlSelectedComboBoxSingleAuthor.SelectedElement,
Date = dateTextBoxDate.TextBoxValue, Date = dateTextBoxDate.TextBoxValue,
Image = selectedImage.ToString(), Image = selectedImage,
}); });
LoadDataInTable(); LoadDataInTable();
textBoxTitle.Clear();
controlSelectedComboBoxSingleAuthor.SelectedElement = null;
textBoxImage.Clear();
MessageBox.Show("Ñîõðàíåíèå ïðîøëî óñïåøíî", "Ñîîáùåíèå", MessageBoxButtons.OK, MessageBoxIcon.Information); MessageBox.Show("Ñîõðàíåíèå ïðîøëî óñïåøíî", "Ñîîáùåíèå", MessageBoxButtons.OK, MessageBoxIcon.Information);
DialogResult = DialogResult.OK; DialogResult = DialogResult.OK;
} }
@ -242,5 +235,36 @@ namespace LibraryAccountingApp_lab3
FillControlSelectedComboBoxSingle(); FillControlSelectedComboBoxSingle();
} }
private void buttonPdfCreate_Click(object sender, EventArgs e)
{
try
{
var list = _bookLogic.Read(null);
if (list != null)
{
BooksImages.Clear();
foreach (var book in list)
{
BooksImages.Add(book.Image);
}
}
var config = new ImagePdfInfo
{
FilePath = "D:\\ULSTU\\COP\\PdfWithImageBooks.pdf",
Header = "Äîêóìåíò ñ îáëîæêàìè êíèã",
Images = BooksImages
};
pdfForImages.CreatePdf(config);
MessageBox.Show("PDF óñïåøíî ñîçäàí!", "Óñïåõ", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
catch (Exception ex)
{
MessageBox.Show($"Îøèáêà çàãðóçêè äàííûõ: {ex.Message}");
}
}
} }
} }

View File

@ -117,7 +117,7 @@
<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>
<metadata name="pdfForImages1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"> <metadata name="pdfForImages.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>295, 17</value> <value>295, 17</value>
</metadata> </metadata>
<metadata name="componentDocumentWithChartBarWord1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"> <metadata name="componentDocumentWithChartBarWord1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">

View File

@ -11,7 +11,7 @@ using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
namespace LibraryAccountingApp_lab3.Migrations namespace LibraryAccountingApp_lab3.Migrations
{ {
[DbContext(typeof(LibraryDatabase))] [DbContext(typeof(LibraryDatabase))]
[Migration("20241028163659_InitialCreate")] [Migration("20241028164711_InitialCreate")]
partial class InitialCreate partial class InitialCreate
{ {
/// <inheritdoc /> /// <inheritdoc />
@ -57,9 +57,9 @@ namespace LibraryAccountingApp_lab3.Migrations
.IsRequired() .IsRequired()
.HasColumnType("nvarchar(max)"); .HasColumnType("nvarchar(max)");
b.Property<string>("Image") b.Property<byte[]>("Image")
.IsRequired() .IsRequired()
.HasColumnType("nvarchar(max)"); .HasColumnType("varbinary(max)");
b.Property<string>("Title") b.Property<string>("Title")
.IsRequired() .IsRequired()

View File

@ -32,7 +32,7 @@ namespace LibraryAccountingApp_lab3.Migrations
Title = table.Column<string>(type: "nvarchar(max)", nullable: false), Title = table.Column<string>(type: "nvarchar(max)", nullable: false),
Author = table.Column<string>(type: "nvarchar(max)", nullable: false), Author = table.Column<string>(type: "nvarchar(max)", nullable: false),
Date = table.Column<string>(type: "nvarchar(max)", nullable: false), Date = table.Column<string>(type: "nvarchar(max)", nullable: false),
Image = table.Column<string>(type: "nvarchar(max)", nullable: false) Image = table.Column<byte[]>(type: "varbinary(max)", nullable: false)
}, },
constraints: table => constraints: table =>
{ {

View File

@ -54,9 +54,9 @@ namespace LibraryAccountingApp_lab3.Migrations
.IsRequired() .IsRequired()
.HasColumnType("nvarchar(max)"); .HasColumnType("nvarchar(max)");
b.Property<string>("Image") b.Property<byte[]>("Image")
.IsRequired() .IsRequired()
.HasColumnType("nvarchar(max)"); .HasColumnType("varbinary(max)");
b.Property<string>("Title") b.Property<string>("Title")
.IsRequired() .IsRequired()