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 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("Дата издания")]
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 Author { get; }
string Date { get; }
string Image { get; }
byte[] Image { get; }
}
}

View File

@ -9,7 +9,7 @@ namespace LibraryAccountingApp_lab3.DatabaseImplement
{
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");
}
base.OnConfiguring(optionsBuilder);

View File

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

View File

@ -29,9 +29,9 @@
private void InitializeComponent()
{
components = new System.ComponentModel.Container();
componentDocumentWithChartBarWord1 = new ComponentsLibraryNet60.DocumentWithChart.ComponentDocumentWithChartBarWord(components);
buttonChooseImage = new Button();
groupBox1 = new GroupBox();
buttonBookDelete = new Button();
buttonAddAuthor = new Button();
textBoxTitle = new TextBox();
buttonBookAdd = new Button();
@ -43,9 +43,14 @@
label1 = new Label();
groupBox2 = new GroupBox();
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();
groupBox2.SuspendLayout();
groupBox3.SuspendLayout();
SuspendLayout();
//
// buttonChooseImage
@ -81,6 +86,18 @@
groupBox1.TabStop = false;
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.Anchor = AnchorStyles.None;
@ -195,23 +212,32 @@
controlDataTableCellBooks.Size = new Size(517, 261);
controlDataTableCellBooks.TabIndex = 0;
//
// buttonBookDelete
// buttonPdfCreate
//
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;
buttonPdfCreate.Location = new Point(20, 35);
buttonPdfCreate.Name = "buttonPdfCreate";
buttonPdfCreate.Size = new Size(132, 48);
buttonPdfCreate.TabIndex = 20;
buttonPdfCreate.Text = "Создать PDF с обложками";
buttonPdfCreate.UseVisualStyleBackColor = true;
buttonPdfCreate.Click += buttonPdfCreate_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
//
AutoScaleDimensions = new SizeF(7F, 15F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(821, 489);
Controls.Add(groupBox3);
Controls.Add(groupBox2);
Controls.Add(groupBox1);
Name = "FormLibrary";
@ -221,11 +247,11 @@
groupBox1.PerformLayout();
groupBox2.ResumeLayout(false);
groupBox2.PerformLayout();
groupBox3.ResumeLayout(false);
ResumeLayout(false);
}
#endregion
private ComponentsLibraryNet60.DocumentWithChart.ComponentDocumentWithChartBarWord componentDocumentWithChartBarWord1;
private Button buttonChooseImage;
private GroupBox groupBox1;
private FedComponentLib.DateTextBox dateTextBoxDate;
@ -240,5 +266,10 @@
private ControlsLibraryNet60.Data.ControlDataTableCell controlDataTableCellBooks;
private Button buttonAddAuthor;
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.Models;
using COP_5;
using COP_5.PdfHelper;
using DocumentFormat.OpenXml.Office2010.Excel;
using FedComponentLib;
using LibraryAccountingApp_lab3.Contracts.BindingModels;
@ -17,11 +18,10 @@ namespace LibraryAccountingApp_lab3
public partial class FormLibrary : Form
{
private byte[]? selectedImage = new byte[16];
private int counterBooksIds = 0;
private int counterRows = 0;
private readonly IBookLogic _bookLogic;
private readonly IAuthorLogic _authorLogic;
public readonly IBookStorage _bookStorage;
private List<byte[]> BooksImages = new List<byte[]>();
int rowIndex = 0;
private int? _id;
public int Id { set { _id = value; } }
@ -44,17 +44,6 @@ namespace LibraryAccountingApp_lab3
private void FillControlSelectedComboBoxSingle()
{
//List<string> list = new List<string>() {
// "Äåíèåë Êèç",
// "Àëåêñàíäð Ïóøêèí",
// "Ô¸äîð Äîñòîåâñêèé",
// "Áîðèñ Àêóíèí",
// "Íèêîëàñ Ñïàðêñ"
//};
//for (int i = 0; i < list.Count; i++)
//{
// controlSelectedComboBoxSingleAuthor.AddElement(list[i]);
//}
controlSelectedComboBoxSingleAuthor.Clear();
try
{
@ -167,9 +156,13 @@ namespace LibraryAccountingApp_lab3
Title = textBoxTitle.Text,
Author = controlSelectedComboBoxSingleAuthor.SelectedElement,
Date = dateTextBoxDate.TextBoxValue,
Image = textBoxImage.Text,
Image = selectedImage,
});
LoadDataInTable();
textBoxTitle.Clear();
controlSelectedComboBoxSingleAuthor.SelectedElement = null;
textBoxImage.Clear();
MessageBox.Show("Ñîõðàíåíèå ïðîøëî óñïåøíî", "Ñîîáùåíèå", MessageBoxButtons.OK, MessageBoxIcon.Information);
DialogResult = DialogResult.OK;
}
@ -242,5 +235,36 @@ namespace LibraryAccountingApp_lab3
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">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</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">
<value>17, 17</value>
</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>

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

View File

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