5 Commits

Author SHA1 Message Date
a16ae4b564 change some config 2024-11-17 20:26:00 +04:00
4bf092cdd0 change some configs 2024-11-17 19:42:43 +04:00
e5f79a8cf1 Create PluginsConvention 2024-11-17 19:39:01 +04:00
bcecbf9c77 create LibraryPlugin project 2024-11-17 17:50:34 +04:00
328b25c576 create LibraryUtils project 2024-11-17 16:57:14 +04:00
17 changed files with 446 additions and 72 deletions

View File

@@ -4,6 +4,7 @@
<TargetFramework>net6.0</TargetFramework> <TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings> <ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable> <Nullable>enable</Nullable>
<GeneratePackageOnBuild>True</GeneratePackageOnBuild>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>

View File

@@ -4,6 +4,7 @@
<TargetFramework>net6.0</TargetFramework> <TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings> <ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable> <Nullable>enable</Nullable>
<GeneratePackageOnBuild>True</GeneratePackageOnBuild>
</PropertyGroup> </PropertyGroup>
</Project> </Project>

View File

@@ -4,6 +4,7 @@
<TargetFramework>net6.0</TargetFramework> <TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings> <ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable> <Nullable>enable</Nullable>
<GeneratePackageOnBuild>True</GeneratePackageOnBuild>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>

View File

@@ -0,0 +1,13 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace LibraryPlugin.Helpers
{
public class PluginsConventionElement
{
public Guid Id { get; set; }
}
}

View File

@@ -0,0 +1,13 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace LibraryPlugin.Helpers
{
public class PluginsConventionSaveDocument
{
public string FileName { get; set; } = string.Empty;
}
}

View File

@@ -0,0 +1,23 @@
using LibraryPlugin.Helpers;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace LibraryPlugin
{
public interface IPluginsConvention
{
string PluginName { get; }
UserControl GetControl { get; }
PluginsConventionElement GetElement { get; }
Form GetForm(PluginsConventionElement element);
Form GetThesaurus();
bool DeleteElement(PluginsConventionElement element);
void ReloadData();
bool CreateSimpleDocument(PluginsConventionSaveDocument saveDocument);
bool CreateTableDocument(PluginsConventionSaveDocument saveDocument);
bool CreateChartDocument(PluginsConventionSaveDocument saveDocument);
}
}

View File

@@ -0,0 +1,22 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0-windows</TargetFramework>
<Nullable>enable</Nullable>
<UseWindowsForms>true</UseWindowsForms>
<ImplicitUsings>enable</ImplicitUsings>
<GeneratePackageOnBuild>True</GeneratePackageOnBuild>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="ComponentLibrary1" Version="1.0.0" />
<PackageReference Include="Library_var_4_lab_1" Version="1.0.1" />
<PackageReference Include="YunusovComponentsLibrary" Version="1.0.1" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\LibraryDatabase\LibraryDatabase.csproj" />
<ProjectReference Include="..\LibraryWinFormsApp\LibraryWinFormsApp.csproj" />
</ItemGroup>
</Project>

View File

@@ -0,0 +1,262 @@
using ComponentLibrary1.pdf_image;
using DocumentFormat.OpenXml.Drawing.Charts;
using Library_var_4_lab_1;
using LibraryContracts.StorageContracts;
using LibraryDatabase.Models;
using LibraryDatabase.Storages;
using LibraryDataModels.AbstractModels;
using LibraryDataModels.Dtos;
using LibraryDataModels.Views;
using LibraryPlugin.Helpers;
using LibraryWinFormsApp;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using YunusovComponentsLibrary;
using YunusovComponentsLibrary.OfficePackage.HelperModels;
using static LibraryUtils.ImageConverter.ImageConverter;
namespace LibraryPlugin
{
public class PluginsConvention : IPluginsConvention
{
private readonly IAuthorStorage _authorStorage = new AuthorStorage();
private readonly IBookStorage _bookStorage = new BookStorage();
private PdfImage pdfImage = new PdfImage();
private ConfigurableTable configurableTable = new ConfigurableTable();
private WordDiagram wordDiagram = new WordDiagram();
private ListOutputComponent bookTable = new ListOutputComponent();
#region interface getters
public string PluginName { get; } = "LibraryPlugin";
public UserControl GetControl
{
get
{
ReloadData();
return bookTable;
}
}
public PluginsConventionElement GetElement
{
get
{
var book = bookTable.GetSelectedObject<BookView>();
int? id = null;
if (book != null)
{
id = Convert.ToInt32(book.Id);
}
byte[] bytes = new byte[16];
if (!id.HasValue)
{
id = -1;
}
BitConverter.GetBytes(id.Value).CopyTo(bytes, 0);
return new()
{
Id = new Guid(bytes)
};
}
}
public Form GetForm(PluginsConventionElement element)
{
FormBook form = new FormBook(_bookStorage, _authorStorage);
int id = element?.Id.GetHashCode() ?? -1;
if ( id > 0)
{
form._id = id;
}
return form;
}
public Form GetThesaurus()
{
return new FormAuthors(_authorStorage);
}
#endregion
#region interface methods
public bool CreateSimpleDocument(PluginsConventionSaveDocument saveDocument)
{
try
{
string fileName = saveDocument.FileName;
if (string.IsNullOrWhiteSpace(fileName))
{
return false;
}
var _books = _bookStorage.GetFullList();
List<byte[]> selectedImages = new List<byte[]>();
foreach (var book in _books)
{
selectedImages.Add(StringToByteArray(book.BookCover));
}
var info = new PdfImageInfo
{
FileName = fileName,
Title = "Обложки",
Images = selectedImages,
};
pdfImage.CreatePdf(info);
MessageBox.Show("PDF успешно создан!", "Успех", MessageBoxButtons.OK, MessageBoxIcon.Information);
return true;
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
return false;
}
}
public bool CreateTableDocument(PluginsConventionSaveDocument saveDocument)
{
try
{
string fileName = saveDocument.FileName;
if (string.IsNullOrWhiteSpace(fileName))
{
return false;
}
List<TreeNode> headers = new List<TreeNode>
{
new TreeNode
{
Text = "Идентификатор",
Tag = "Id",
Name = "40",
},
new TreeNode("Книга", new TreeNode[]
{
new TreeNode
{
Text = "Название",
Tag = "Name",
Name = "40",
},
new TreeNode
{
Text = "Автор",
Tag = "Author",
Name = "40",
},
}),
new TreeNode
{
Text = "Дата",
Tag = "ReleaseDate",
Name = "40",
},
};
var _books = _bookStorage.GetFullList();
configurableTable.CreateTable(
fileName,
"Книги",
headers,
_books);
MessageBox.Show("Excell успешно создан!", "Успех", MessageBoxButtons.OK, MessageBoxIcon.Information);
return true;
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
return false;
}
}
public bool CreateChartDocument(PluginsConventionSaveDocument saveDocument)
{
try
{
string fileName = saveDocument.FileName;
if (string.IsNullOrWhiteSpace(fileName))
{
return false;
}
var _books = _bookStorage.GetFullList();
var authors = _authorStorage.GetFullList();
WordDiagramSeries series = new WordDiagramSeries();
series.SeriesName = "Авторы";
foreach (var author in authors)
{
double sum = 0.0;
foreach (var book in _books)
{
if (string.Equals(book.Author, author.Name))
{
sum++;
}
}
series.Data.Add(author.Name, sum);
}
wordDiagram.CreateDiagram(new WordDiagramInfo()
{
FileName = fileName,
Title = "Авторы",
ChartTitle = "Авторы",
Series = series,
});
MessageBox.Show("Word успешно создан!", "Успех", MessageBoxButtons.OK, MessageBoxIcon.Information);
return true;
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
return false;
}
}
public bool DeleteElement(PluginsConventionElement element)
{
try
{
int selectedRow = bookTable.SelectedRow;
if (selectedRow == -1)
{
throw new Exception("Выберите книгу для удаления");
}
if (MessageBox.Show("Удалить запись?", "Вопрос", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
{
int id = Convert.ToInt32(bookTable.Rows[selectedRow].Cells[0].Value);
_bookStorage.Delete(new BookDto()
{
Id = id
});
ReloadData();
}
return true;
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
return false;
}
}
public void ReloadData()
{
try
{
List<BookView> _books = _bookStorage.GetFullList();
List<ColumnInfo> parameters = new List<ColumnInfo>()
{
new ColumnInfo("", 0, false, "Id"),
new ColumnInfo("Название", 258, true, "Name"),
new ColumnInfo("", 0, false, "BookCover"),
new ColumnInfo("ФИО автора", 258, true, "Author"),
new ColumnInfo("Дата издания", 258, true, "ReleaseDate"),
};
bookTable.ConfigColumn(parameters);
if (_books == null)
{
return;
}
foreach (var book in _books)
{
bookTable.AddItem(book);
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
#endregion
}
}

View File

@@ -4,7 +4,7 @@ using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace LibraryWinFormsApp namespace LibraryUtils.FileChooser
{ {
public enum DocType public enum DocType
{ {

View File

@@ -0,0 +1,44 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace LibraryUtils.FileChooser
{
public class FileChooser
{
private static string GetFileExtension(DocType type)
{
switch (type)
{
case DocType.Excel:
return ".xlsx";
case DocType.Word:
return ".docx";
case DocType.Pdf:
return ".pdf";
default:
return "";
}
}
public static string GetFileFullName(DocType type)
{
string extension = GetFileExtension(type);
if (string.IsNullOrEmpty(extension))
{
throw new Exception("Invalid file extension");
}
using SaveFileDialog fileDialog = new SaveFileDialog
{
Filter = $"Файлы|*{extension}"
};
if (fileDialog.ShowDialog() == DialogResult.OK)
{
return fileDialog.FileName;
}
return "";
}
}
}

View File

@@ -0,0 +1,33 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace LibraryUtils.ImageConverter
{
public class ImageConverter
{
public static Image StringToImage(string bytes)
{
byte[] arrayimg = Convert.FromBase64String(bytes);
Image imageStr = Image.FromStream(new MemoryStream(arrayimg));
return imageStr;
}
public static string ImageToString(Image image)
{
using (var ms = new MemoryStream())
{
image.Save(ms, image.RawFormat);
byte[] imageBytes = ms.ToArray();
string base64String = Convert.ToBase64String(imageBytes);
return base64String;
}
}
public static byte[] StringToByteArray(string bytes)
{
return Convert.FromBase64String(bytes);
}
}
}

View File

@@ -0,0 +1,11 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0-windows</TargetFramework>
<Nullable>enable</Nullable>
<UseWindowsForms>true</UseWindowsForms>
<ImplicitUsings>enable</ImplicitUsings>
<GeneratePackageOnBuild>True</GeneratePackageOnBuild>
</PropertyGroup>
</Project>

View File

@@ -11,6 +11,10 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "LibraryDataModels", "Librar
EndProject EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "LibraryDatabase", "LibraryDatabase\LibraryDatabase.csproj", "{4F0EC406-67F6-49C1-97C8-F553455780FB}" Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "LibraryDatabase", "LibraryDatabase\LibraryDatabase.csproj", "{4F0EC406-67F6-49C1-97C8-F553455780FB}"
EndProject EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LibraryUtils", "LibraryUtils\LibraryUtils.csproj", "{C2309DD0-4F3E-42C5-9727-793219E25E09}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LibraryPlugin", "LibraryPlugin\LibraryPlugin.csproj", "{43977511-4067-4355-91E7-3C45F2685248}"
EndProject
Global Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU Debug|Any CPU = Debug|Any CPU
@@ -33,6 +37,14 @@ Global
{4F0EC406-67F6-49C1-97C8-F553455780FB}.Debug|Any CPU.Build.0 = Debug|Any CPU {4F0EC406-67F6-49C1-97C8-F553455780FB}.Debug|Any CPU.Build.0 = Debug|Any CPU
{4F0EC406-67F6-49C1-97C8-F553455780FB}.Release|Any CPU.ActiveCfg = Release|Any CPU {4F0EC406-67F6-49C1-97C8-F553455780FB}.Release|Any CPU.ActiveCfg = Release|Any CPU
{4F0EC406-67F6-49C1-97C8-F553455780FB}.Release|Any CPU.Build.0 = Release|Any CPU {4F0EC406-67F6-49C1-97C8-F553455780FB}.Release|Any CPU.Build.0 = Release|Any CPU
{C2309DD0-4F3E-42C5-9727-793219E25E09}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{C2309DD0-4F3E-42C5-9727-793219E25E09}.Debug|Any CPU.Build.0 = Debug|Any CPU
{C2309DD0-4F3E-42C5-9727-793219E25E09}.Release|Any CPU.ActiveCfg = Release|Any CPU
{C2309DD0-4F3E-42C5-9727-793219E25E09}.Release|Any CPU.Build.0 = Release|Any CPU
{43977511-4067-4355-91E7-3C45F2685248}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{43977511-4067-4355-91E7-3C45F2685248}.Debug|Any CPU.Build.0 = Debug|Any CPU
{43977511-4067-4355-91E7-3C45F2685248}.Release|Any CPU.ActiveCfg = Release|Any CPU
{43977511-4067-4355-91E7-3C45F2685248}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection EndGlobalSection
GlobalSection(SolutionProperties) = preSolution GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE HideSolutionNode = FALSE

View File

@@ -15,6 +15,7 @@ using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using System.Windows.Controls.Primitives; using System.Windows.Controls.Primitives;
using System.Windows.Forms; using System.Windows.Forms;
using static LibraryUtils.ImageConverter.ImageConverter;
namespace LibraryWinFormsApp namespace LibraryWinFormsApp
{ {
@@ -25,7 +26,6 @@ namespace LibraryWinFormsApp
private BookView? _book = null; private BookView? _book = null;
private IBookStorage _bookStorage; private IBookStorage _bookStorage;
private IAuthorStorage _authorStorage; private IAuthorStorage _authorStorage;
private ImageConverter _imageConverter = new ImageConverter();
public FormBook(IBookStorage bookStorage, IAuthorStorage authorStorage) public FormBook(IBookStorage bookStorage, IAuthorStorage authorStorage)
{ {
InitializeComponent(); InitializeComponent();
@@ -65,7 +65,7 @@ namespace LibraryWinFormsApp
authorField.SelectedItem = _book.Author; authorField.SelectedItem = _book.Author;
try try
{ {
pictureBox.Image = _imageConverter.StringToImage(_cover); pictureBox.Image = StringToImage(_cover);
} }
catch catch
{ {
@@ -168,7 +168,7 @@ namespace LibraryWinFormsApp
{ {
var image_new = new Bitmap(dialog.FileName); var image_new = new Bitmap(dialog.FileName);
pictureBox.Image = image_new; pictureBox.Image = image_new;
_cover = _imageConverter.ImageToString(image_new); _cover = ImageToString(image_new);
} }
dialog.Dispose(); dialog.Dispose();

View File

@@ -5,6 +5,9 @@ using LibraryDataModels.Views;
using System.Windows.Forms; using System.Windows.Forms;
using YunusovComponentsLibrary; using YunusovComponentsLibrary;
using YunusovComponentsLibrary.OfficePackage.HelperModels; using YunusovComponentsLibrary.OfficePackage.HelperModels;
using LibraryUtils.FileChooser;
using static LibraryUtils.FileChooser.FileChooser;
using static LibraryUtils.ImageConverter.ImageConverter;
namespace LibraryWinFormsApp namespace LibraryWinFormsApp
{ {
@@ -13,7 +16,6 @@ namespace LibraryWinFormsApp
private IBookStorage _bookStorage; private IBookStorage _bookStorage;
private IAuthorStorage _authorStorage; private IAuthorStorage _authorStorage;
private List<BookView> _books = new List<BookView>(); private List<BookView> _books = new List<BookView>();
private ImageConverter _converter = new ImageConverter();
public FormBooks(IBookStorage bookStorage, IAuthorStorage authorStorage) public FormBooks(IBookStorage bookStorage, IAuthorStorage authorStorage)
{ {
InitializeComponent(); InitializeComponent();
@@ -219,39 +221,6 @@ namespace LibraryWinFormsApp
} }
} }
private string GetFileExtension(DocType type)
{
switch (type)
{
case DocType.Excel:
return ".xlsx";
case DocType.Word:
return ".docx";
case DocType.Pdf:
return ".pdf";
default:
return "";
}
}
private string GetFileFullName(DocType type)
{
string extension = GetFileExtension(type);
if (string.IsNullOrEmpty(extension))
{
throw new Exception("Invalid file extension");
}
using SaveFileDialog fileDialog = new SaveFileDialog
{
Filter = $"<22><><EFBFBD><EFBFBD><EFBFBD>|*{extension}"
};
if (fileDialog.ShowDialog() == DialogResult.OK)
{
return fileDialog.FileName;
}
return "";
}
private void CreatePdf() private void CreatePdf()
{ {
string fileName = GetFileFullName(DocType.Pdf); string fileName = GetFileFullName(DocType.Pdf);
@@ -263,7 +232,7 @@ namespace LibraryWinFormsApp
List<byte[]> selectedImages = new List<byte[]>(); List<byte[]> selectedImages = new List<byte[]>();
foreach (var book in _books) foreach (var book in _books)
{ {
selectedImages.Add(_converter.StringToByteArray(book.BookCover)); selectedImages.Add(StringToByteArray(book.BookCover));
} }
var info = new PdfImageInfo var info = new PdfImageInfo
{ {

View File

@@ -1,33 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace LibraryWinFormsApp
{
internal class ImageConverter
{
public Image StringToImage(string bytes)
{
byte[] arrayimg = Convert.FromBase64String(bytes);
Image imageStr = Image.FromStream(new MemoryStream(arrayimg));
return imageStr;
}
public string ImageToString(Image image)
{
using (var ms = new MemoryStream())
{
image.Save(ms, image.RawFormat);
byte[] imageBytes = ms.ToArray();
string base64String = Convert.ToBase64String(imageBytes);
return base64String;
}
}
public byte[] StringToByteArray(string bytes)
{
return Convert.FromBase64String(bytes);
}
}
}

View File

@@ -6,6 +6,7 @@
<Nullable>enable</Nullable> <Nullable>enable</Nullable>
<UseWindowsForms>true</UseWindowsForms> <UseWindowsForms>true</UseWindowsForms>
<ImplicitUsings>enable</ImplicitUsings> <ImplicitUsings>enable</ImplicitUsings>
<GeneratePackageOnBuild>True</GeneratePackageOnBuild>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
@@ -17,6 +18,7 @@
<ItemGroup> <ItemGroup>
<ProjectReference Include="..\LibraryDatabase\LibraryDatabase.csproj" /> <ProjectReference Include="..\LibraryDatabase\LibraryDatabase.csproj" />
<ProjectReference Include="..\LibraryUtils\LibraryUtils.csproj" />
</ItemGroup> </ItemGroup>
</Project> </Project>