Compare commits

...

2 Commits

Author SHA1 Message Date
a.puchkina
caaa65f204 pdf с картинками 2024-10-28 21:17:45 +04:00
a.puchkina
17c1521e2a ыть 2024-10-28 20:45:12 +04:00
13 changed files with 96 additions and 144 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=LibraryAppCOP;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

@ -29,9 +29,9 @@
private void InitializeComponent() private void InitializeComponent()
{ {
components = new System.ComponentModel.Container(); components = new System.ComponentModel.Container();
componentDocumentWithChartBarWord1 = new ComponentsLibraryNet60.DocumentWithChart.ComponentDocumentWithChartBarWord(components);
buttonChooseImage = new Button(); buttonChooseImage = new Button();
groupBox1 = new GroupBox(); groupBox1 = new GroupBox();
buttonBookDelete = new Button();
buttonAddAuthor = new Button(); buttonAddAuthor = new Button();
textBoxTitle = new TextBox(); textBoxTitle = new TextBox();
buttonBookAdd = new Button(); buttonBookAdd = new Button();
@ -43,9 +43,14 @@
label1 = new Label(); label1 = new Label();
groupBox2 = new GroupBox(); groupBox2 = new GroupBox();
controlDataTableCellBooks = new ControlsLibraryNet60.Data.ControlDataTableCell(); controlDataTableCellBooks = new ControlsLibraryNet60.Data.ControlDataTableCell();
buttonBookDelete = new Button(); pdfForImages = new COP_5.PdfForImages(components);
componentDocumentWithChartBarWord1 = new ComponentsLibraryNet60.DocumentWithChart.ComponentDocumentWithChartBarWord(components);
tableComponent1 = new FedComponentLib.NonVisualComponents.TableComponent(components);
buttonPdfCreate = new Button();
groupBox3 = new GroupBox();
groupBox1.SuspendLayout(); groupBox1.SuspendLayout();
groupBox2.SuspendLayout(); groupBox2.SuspendLayout();
groupBox3.SuspendLayout();
SuspendLayout(); SuspendLayout();
// //
// buttonChooseImage // buttonChooseImage
@ -81,6 +86,18 @@
groupBox1.TabStop = false; groupBox1.TabStop = false;
groupBox1.Text = "Загрузка книги"; groupBox1.Text = "Загрузка книги";
// //
// buttonBookDelete
//
buttonBookDelete.Anchor = AnchorStyles.None;
buttonBookDelete.BackColor = Color.LightCoral;
buttonBookDelete.Location = new Point(18, 405);
buttonBookDelete.Name = "buttonBookDelete";
buttonBookDelete.Size = new Size(231, 36);
buttonBookDelete.TabIndex = 26;
buttonBookDelete.Text = "Удалить книгу";
buttonBookDelete.UseVisualStyleBackColor = false;
buttonBookDelete.Click += buttonBookDelete_Click;
//
// buttonAddAuthor // buttonAddAuthor
// //
buttonAddAuthor.Anchor = AnchorStyles.None; buttonAddAuthor.Anchor = AnchorStyles.None;
@ -195,23 +212,32 @@
controlDataTableCellBooks.Size = new Size(517, 261); controlDataTableCellBooks.Size = new Size(517, 261);
controlDataTableCellBooks.TabIndex = 0; controlDataTableCellBooks.TabIndex = 0;
// //
// buttonBookDelete // buttonPdfCreate
// //
buttonBookDelete.Anchor = AnchorStyles.None; buttonPdfCreate.Location = new Point(20, 35);
buttonBookDelete.BackColor = Color.LightCoral; buttonPdfCreate.Name = "buttonPdfCreate";
buttonBookDelete.Location = new Point(18, 405); buttonPdfCreate.Size = new Size(132, 48);
buttonBookDelete.Name = "buttonBookDelete"; buttonPdfCreate.TabIndex = 20;
buttonBookDelete.Size = new Size(231, 36); buttonPdfCreate.Text = "Создать PDF с обложками";
buttonBookDelete.TabIndex = 26; buttonPdfCreate.UseVisualStyleBackColor = true;
buttonBookDelete.Text = "Удалить книгу"; buttonPdfCreate.Click += buttonPdfCreate_Click;
buttonBookDelete.UseVisualStyleBackColor = false; //
buttonBookDelete.Click += buttonBookDelete_Click; // groupBox3
//
groupBox3.Controls.Add(buttonPdfCreate);
groupBox3.Location = new Point(291, 304);
groupBox3.Name = "groupBox3";
groupBox3.Size = new Size(524, 173);
groupBox3.TabIndex = 21;
groupBox3.TabStop = false;
groupBox3.Text = "Формирование отчётов";
// //
// FormLibrary // FormLibrary
// //
AutoScaleDimensions = new SizeF(7F, 15F); AutoScaleDimensions = new SizeF(7F, 15F);
AutoScaleMode = AutoScaleMode.Font; AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(821, 489); ClientSize = new Size(821, 489);
Controls.Add(groupBox3);
Controls.Add(groupBox2); Controls.Add(groupBox2);
Controls.Add(groupBox1); Controls.Add(groupBox1);
Name = "FormLibrary"; Name = "FormLibrary";
@ -221,11 +247,11 @@
groupBox1.PerformLayout(); groupBox1.PerformLayout();
groupBox2.ResumeLayout(false); groupBox2.ResumeLayout(false);
groupBox2.PerformLayout(); groupBox2.PerformLayout();
groupBox3.ResumeLayout(false);
ResumeLayout(false); ResumeLayout(false);
} }
#endregion #endregion
private ComponentsLibraryNet60.DocumentWithChart.ComponentDocumentWithChartBarWord componentDocumentWithChartBarWord1;
private Button buttonChooseImage; private Button buttonChooseImage;
private GroupBox groupBox1; private GroupBox groupBox1;
private FedComponentLib.DateTextBox dateTextBoxDate; private FedComponentLib.DateTextBox dateTextBoxDate;
@ -240,5 +266,10 @@
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 pdfForImages;
private ComponentsLibraryNet60.DocumentWithChart.ComponentDocumentWithChartBarWord componentDocumentWithChartBarWord1;
private FedComponentLib.NonVisualComponents.TableComponent tableComponent1;
private Button buttonPdfCreate;
private GroupBox groupBox3;
} }
} }

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 = textBoxImage.Text, 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,13 @@
<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="pdfForImages.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>295, 17</value>
</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">
<value>17, 17</value> <value>17, 17</value>
</metadata> </metadata>
<metadata name="tableComponent1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>428, 17</value>
</metadata>
</root> </root>

View File

@ -1,75 +0,0 @@
// <auto-generated />
using LibraryAccountingApp_lab3.DatabaseImplement;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
#nullable disable
namespace LibraryAccountingApp_lab3.Migrations
{
[DbContext(typeof(LibraryDatabase))]
[Migration("20241028091634_imageFix")]
partial class imageFix
{
/// <inheritdoc />
protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder
.HasAnnotation("ProductVersion", "7.0.18")
.HasAnnotation("Relational:MaxIdentifierLength", 128);
SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder);
modelBuilder.Entity("LibraryAccountingApp_lab3.DatabaseImplement.Models.Author", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<string>("Name")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.HasKey("Id");
b.ToTable("Authors");
});
modelBuilder.Entity("LibraryAccountingApp_lab3.DatabaseImplement.Models.Book", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<string>("Author")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<string>("Date")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<string>("Image")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<string>("Title")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.HasKey("Id");
b.ToTable("Books");
});
#pragma warning restore 612, 618
}
}
}

View File

@ -1,34 +0,0 @@
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace LibraryAccountingApp_lab3.Migrations
{
/// <inheritdoc />
public partial class imageFix : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.AlterColumn<string>(
name: "Image",
table: "Books",
type: "nvarchar(max)",
nullable: false,
oldClrType: typeof(byte[]),
oldType: "varbinary(max)");
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.AlterColumn<byte[]>(
name: "Image",
table: "Books",
type: "varbinary(max)",
nullable: false,
oldClrType: typeof(string),
oldType: "nvarchar(max)");
}
}
}

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("20241015201338_InitialCreate")] [Migration("20241028164711_InitialCreate")]
partial class InitialCreate partial class InitialCreate
{ {
/// <inheritdoc /> /// <inheritdoc />

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()