diff --git a/LibraryWinFormsApp.sln b/LibraryWinFormsApp.sln index a43fded..548a3a8 100644 --- a/LibraryWinFormsApp.sln +++ b/LibraryWinFormsApp.sln @@ -5,12 +5,6 @@ VisualStudioVersion = 17.9.34723.18 MinimumVisualStudioVersion = 10.0.40219.1 Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "LibraryWinFormsApp", "LibraryWinFormsApp\LibraryWinFormsApp.csproj", "{E8BD6D99-6C63-42E4-8BBC-6FF8419C7C9E}" EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "LibraryContracts", "LibraryContracts\LibraryContracts.csproj", "{70D8ED64-2FC3-40DB-8C27-324439B590AA}" -EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "LibraryDataModels", "LibraryDataModels\LibraryDataModels.csproj", "{37477D2C-F5EB-418D-A9FA-135A71B430E1}" -EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "LibraryDatabase", "LibraryDatabase\LibraryDatabase.csproj", "{4F0EC406-67F6-49C1-97C8-F553455780FB}" -EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -21,18 +15,6 @@ Global {E8BD6D99-6C63-42E4-8BBC-6FF8419C7C9E}.Debug|Any CPU.Build.0 = Debug|Any CPU {E8BD6D99-6C63-42E4-8BBC-6FF8419C7C9E}.Release|Any CPU.ActiveCfg = Release|Any CPU {E8BD6D99-6C63-42E4-8BBC-6FF8419C7C9E}.Release|Any CPU.Build.0 = Release|Any CPU - {70D8ED64-2FC3-40DB-8C27-324439B590AA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {70D8ED64-2FC3-40DB-8C27-324439B590AA}.Debug|Any CPU.Build.0 = Debug|Any CPU - {70D8ED64-2FC3-40DB-8C27-324439B590AA}.Release|Any CPU.ActiveCfg = Release|Any CPU - {70D8ED64-2FC3-40DB-8C27-324439B590AA}.Release|Any CPU.Build.0 = Release|Any CPU - {37477D2C-F5EB-418D-A9FA-135A71B430E1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {37477D2C-F5EB-418D-A9FA-135A71B430E1}.Debug|Any CPU.Build.0 = Debug|Any CPU - {37477D2C-F5EB-418D-A9FA-135A71B430E1}.Release|Any CPU.ActiveCfg = Release|Any CPU - {37477D2C-F5EB-418D-A9FA-135A71B430E1}.Release|Any CPU.Build.0 = Release|Any CPU - {4F0EC406-67F6-49C1-97C8-F553455780FB}.Debug|Any CPU.ActiveCfg = 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.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/LibraryWinFormsApp/DocType.cs b/LibraryWinFormsApp/DocType.cs deleted file mode 100644 index 9282970..0000000 --- a/LibraryWinFormsApp/DocType.cs +++ /dev/null @@ -1,15 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace LibraryWinFormsApp -{ - public enum DocType - { - Excel, - Word, - Pdf - } -} diff --git a/LibraryWinFormsApp/FormAuthors.Designer.cs b/LibraryWinFormsApp/FormAuthors.Designer.cs deleted file mode 100644 index 461595f..0000000 --- a/LibraryWinFormsApp/FormAuthors.Designer.cs +++ /dev/null @@ -1,66 +0,0 @@ -namespace LibraryWinFormsApp -{ - partial class FormAuthors - { - /// - /// Required designer variable. - /// - private System.ComponentModel.IContainer components = null; - - /// - /// Clean up any resources being used. - /// - /// true if managed resources should be disposed; otherwise, false. - protected override void Dispose(bool disposing) - { - if (disposing && (components != null)) - { - components.Dispose(); - } - base.Dispose(disposing); - } - - #region Windows Form Designer generated code - - /// - /// Required method for Designer support - do not modify - /// the contents of this method with the code editor. - /// - private void InitializeComponent() - { - authorsTable = new DataGridView(); - ((System.ComponentModel.ISupportInitialize)authorsTable).BeginInit(); - SuspendLayout(); - // - // authorsTable - // - authorsTable.AllowUserToAddRows = false; - authorsTable.AllowUserToDeleteRows = false; - authorsTable.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; - authorsTable.Dock = DockStyle.Fill; - authorsTable.Location = new Point(0, 0); - authorsTable.Name = "authorsTable"; - authorsTable.RowTemplate.Height = 25; - authorsTable.Size = new Size(800, 450); - authorsTable.TabIndex = 0; - authorsTable.CellEndEdit += authorsTable_CellEndEdit; - authorsTable.KeyDown += authorsTable_KeyDown; - // - // FormAuthors - // - AutoScaleDimensions = new SizeF(7F, 15F); - AutoScaleMode = AutoScaleMode.Font; - ClientSize = new Size(800, 450); - Controls.Add(authorsTable); - Name = "FormAuthors"; - Text = "Авторы"; - Load += FormAuthors_Load; - ((System.ComponentModel.ISupportInitialize)authorsTable).EndInit(); - ResumeLayout(false); - } - - #endregion - - private DataGridView authorsTable; - } -} \ No newline at end of file diff --git a/LibraryWinFormsApp/FormAuthors.cs b/LibraryWinFormsApp/FormAuthors.cs deleted file mode 100644 index 207ca27..0000000 --- a/LibraryWinFormsApp/FormAuthors.cs +++ /dev/null @@ -1,113 +0,0 @@ -using LibraryContracts.StorageContracts; -using LibraryDataModels.Dtos; -using LibraryDataModels.Views; -using Microsoft.IdentityModel.Tokens; -using System; -using System.Collections.Generic; -using System.ComponentModel; -using System.Data; -using System.Drawing; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using System.Windows.Forms; - -namespace LibraryWinFormsApp -{ - public partial class FormAuthors : Form - { - private IAuthorStorage _authorStorage; - private List _authors; - public FormAuthors(IAuthorStorage authorStorage) - { - _authorStorage = authorStorage; - _authors = new List(); - InitializeComponent(); - } - - private void FormAuthors_Load(object sender, EventArgs e) - { - LoadData(); - } - - private void LoadData() - { - try - { - _authors = _authorStorage.GetFullList(); - if (_authors != null) - { - authorsTable.DataSource = _authors; - authorsTable.Columns[0].Visible = false; - authorsTable.Columns[1].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; - } - } - catch (Exception ex) - { - MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); - } - } - - private void authorsTable_CellEndEdit(object sender, DataGridViewCellEventArgs e) - { - var cellValue = (string)authorsTable.CurrentRow.Cells[1].EditedFormattedValue; - if (!string.IsNullOrEmpty(cellValue)) - { - var keyValue = Convert.ToInt32(authorsTable.CurrentRow.Cells[0].Value); - if (keyValue != -1) - { - _authorStorage.Update(new AuthorDto() - { - Id = keyValue, - Name = cellValue, - }); - } - else - { - _authorStorage.Insert(new AuthorDto() - { - Name = cellValue, - }); - } - } - else - { - MessageBox.Show("Введена пустая строка", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); - } - LoadData(); - } - - private void authorsTable_KeyDown(object sender, KeyEventArgs e) - { - if (e.KeyData == Keys.Insert) - { - if (authorsTable.Rows.Count == 0) - { - _authors.Add(new AuthorView()); - authorsTable.DataSource = new BindingList(_authors); - authorsTable.CurrentCell = authorsTable.Rows[0].Cells[1]; - return; - } - if (authorsTable.Rows[authorsTable.Rows.Count - 1].Cells[1].Value != null) - { - _authors.Add(new AuthorView()); - authorsTable.DataSource = new BindingList(_authors); - authorsTable.CurrentCell = authorsTable.Rows[authorsTable.Rows.Count - 1].Cells[1]; - return; - } - } - if (e.KeyData == Keys.Delete) - { - if (MessageBox.Show("Удалить выбранный элемент?", "Удаление", - MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) - { - _authorStorage.Delete(new AuthorDto() - { - Id = Convert.ToInt32(authorsTable.CurrentRow.Cells[0].Value), - }); - LoadData(); - } - } - } - } -} diff --git a/LibraryWinFormsApp/FormAuthors.resx b/LibraryWinFormsApp/FormAuthors.resx deleted file mode 100644 index af32865..0000000 --- a/LibraryWinFormsApp/FormAuthors.resx +++ /dev/null @@ -1,120 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - text/microsoft-resx - - - 2.0 - - - System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - \ No newline at end of file diff --git a/LibraryWinFormsApp/FormBook.Designer.cs b/LibraryWinFormsApp/FormBook.Designer.cs deleted file mode 100644 index 492e5d9..0000000 --- a/LibraryWinFormsApp/FormBook.Designer.cs +++ /dev/null @@ -1,180 +0,0 @@ -namespace LibraryWinFormsApp -{ - partial class FormBook - { - /// - /// Required designer variable. - /// - private System.ComponentModel.IContainer components = null; - - /// - /// Clean up any resources being used. - /// - /// true if managed resources should be disposed; otherwise, false. - protected override void Dispose(bool disposing) - { - if (disposing && (components != null)) - { - components.Dispose(); - } - base.Dispose(disposing); - } - - #region Windows Form Designer generated code - - /// - /// Required method for Designer support - do not modify - /// the contents of this method with the code editor. - /// - private void InitializeComponent() - { - releaseDateField = new Library_var_4_lab_1.DateInputBox(); - nameField = new TextBox(); - coverLabel = new Label(); - nameLabel = new Label(); - releaseDateLabel = new Label(); - authorLabel = new Label(); - authorField = new YunusovComponentsLibrary.SelectedComponent(); - saveButton = new Button(); - pictureBox = new PictureBox(); - changeCoverButton = new Button(); - ((System.ComponentModel.ISupportInitialize)pictureBox).BeginInit(); - SuspendLayout(); - // - // releaseDateField - // - releaseDateField.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left; - releaseDateField.Location = new Point(8, 67); - releaseDateField.Margin = new Padding(3, 2, 3, 2); - releaseDateField.Name = "releaseDateField"; - releaseDateField.Size = new Size(215, 61); - releaseDateField.TabIndex = 0; - // - // nameField - // - nameField.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left; - nameField.Location = new Point(8, 24); - nameField.Name = "nameField"; - nameField.Size = new Size(215, 23); - nameField.TabIndex = 1; - // - // coverLabel - // - coverLabel.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right; - coverLabel.AutoSize = true; - coverLabel.Location = new Point(229, 4); - coverLabel.Name = "coverLabel"; - coverLabel.Size = new Size(58, 15); - coverLabel.TabIndex = 3; - coverLabel.Text = "Обложка"; - // - // nameLabel - // - nameLabel.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left; - nameLabel.AutoSize = true; - nameLabel.Location = new Point(8, 4); - nameLabel.Name = "nameLabel"; - nameLabel.Size = new Size(59, 15); - nameLabel.TabIndex = 4; - nameLabel.Text = "Название"; - // - // releaseDateLabel - // - releaseDateLabel.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left; - releaseDateLabel.AutoSize = true; - releaseDateLabel.Location = new Point(8, 50); - releaseDateLabel.Name = "releaseDateLabel"; - releaseDateLabel.Size = new Size(79, 15); - releaseDateLabel.TabIndex = 5; - releaseDateLabel.Text = "Дата издания"; - // - // authorLabel - // - authorLabel.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left; - authorLabel.AutoSize = true; - authorLabel.Location = new Point(8, 97); - authorLabel.Name = "authorLabel"; - authorLabel.Size = new Size(40, 15); - authorLabel.TabIndex = 6; - authorLabel.Text = "Автор"; - // - // authorField - // - authorField.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left; - authorField.Location = new Point(8, 114); - authorField.Margin = new Padding(3, 2, 3, 2); - authorField.Name = "authorField"; - authorField.SelectedItem = ""; - authorField.Size = new Size(215, 208); - authorField.TabIndex = 7; - // - // saveButton - // - saveButton.Anchor = AnchorStyles.Bottom | AnchorStyles.Left; - saveButton.Location = new Point(8, 330); - saveButton.Name = "saveButton"; - saveButton.Size = new Size(215, 30); - saveButton.TabIndex = 8; - saveButton.Text = "Сохранить"; - saveButton.UseVisualStyleBackColor = true; - saveButton.Click += saveButton_Click; - // - // pictureBox - // - pictureBox.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right; - pictureBox.Location = new Point(229, 24); - pictureBox.Name = "pictureBox"; - pictureBox.Size = new Size(400, 276); - pictureBox.SizeMode = PictureBoxSizeMode.Zoom; - pictureBox.TabIndex = 9; - pictureBox.TabStop = false; - // - // changeCoverButton - // - changeCoverButton.Anchor = AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right; - changeCoverButton.Location = new Point(229, 330); - changeCoverButton.Name = "changeCoverButton"; - changeCoverButton.Size = new Size(402, 30); - changeCoverButton.TabIndex = 10; - changeCoverButton.Text = "Изменить обложку"; - changeCoverButton.UseVisualStyleBackColor = true; - changeCoverButton.Click += changeCoverButton_Click; - // - // FormBook - // - AutoScaleDimensions = new SizeF(7F, 15F); - AutoScaleMode = AutoScaleMode.Font; - ClientSize = new Size(639, 364); - Controls.Add(changeCoverButton); - Controls.Add(pictureBox); - Controls.Add(saveButton); - Controls.Add(authorField); - Controls.Add(authorLabel); - Controls.Add(releaseDateLabel); - Controls.Add(nameLabel); - Controls.Add(coverLabel); - Controls.Add(nameField); - Controls.Add(releaseDateField); - Name = "FormBook"; - Text = "Kнигa"; - FormClosing += FormBook_FormClosing; - Load += FormBook_Load; - ((System.ComponentModel.ISupportInitialize)pictureBox).EndInit(); - ResumeLayout(false); - PerformLayout(); - } - - #endregion - - private Library_var_4_lab_1.DateInputBox releaseDateField; - private TextBox nameField; - private Label coverLabel; - private Label nameLabel; - private Label releaseDateLabel; - private Label authorLabel; - private YunusovComponentsLibrary.SelectedComponent authorField; - private Button saveButton; - private PictureBox pictureBox; - private Button changeCoverButton; - } -} \ No newline at end of file diff --git a/LibraryWinFormsApp/FormBook.cs b/LibraryWinFormsApp/FormBook.cs deleted file mode 100644 index 241f677..0000000 --- a/LibraryWinFormsApp/FormBook.cs +++ /dev/null @@ -1,177 +0,0 @@ -using DocumentFormat.OpenXml.Office2010.Excel; -using Library_var_4_lab_1; -using LibraryContracts.StorageContracts; -using LibraryDatabase.Models; -using LibraryDatabase.Storages; -using LibraryDataModels.Dtos; -using LibraryDataModels.Views; -using System; -using System.Collections.Generic; -using System.ComponentModel; -using System.Data; -using System.Drawing; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using System.Windows.Controls.Primitives; -using System.Windows.Forms; - -namespace LibraryWinFormsApp -{ - public partial class FormBook : Form - { - public int _id { get; set; } = -1; - private string _cover { get; set; } = string.Empty; - private BookView? _book = null; - private IBookStorage _bookStorage; - private IAuthorStorage _authorStorage; - private ImageConverter _imageConverter = new ImageConverter(); - public FormBook(IBookStorage bookStorage, IAuthorStorage authorStorage) - { - InitializeComponent(); - _bookStorage = bookStorage; - _authorStorage = authorStorage; - } - - private void FormBook_Load(object sender, EventArgs e) - { - LoadData(); - } - - private void LoadData() - { - try - { - releaseDateField.Template = @"^([1-9]|[12][0-9]|3[01]) (января|февраля|марта|апреля|мая|июня|июля|августа|сентября|октября|ноября|декабря) [0-9]{4}$"; - var authors = _authorStorage.GetFullList(); - if (authors != null) - { - foreach (var author in authors) - { - authorField.Input(author.Name); - } - } - if (_id != -1) - { - _book = _bookStorage.GetElement(new BookDto() - { - Id = _id, - }); - if (_book != null) - { - _cover = _book.BookCover; - nameField.Text = _book.Name; - releaseDateField.Date = _book.ReleaseDate; - authorField.SelectedItem = _book.Author; - try - { - pictureBox.Image = _imageConverter.StringToImage(_cover); - } - catch - { - return; - } - } - } - } - catch (Exception ex) - { - MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); - } - } - - private void FormBook_FormClosing(object sender, FormClosingEventArgs e) - { - try - { - bool Changed = false; - if (_book == null) - { - if (!string.IsNullOrEmpty(_cover)) - Changed = true; - if (!string.IsNullOrEmpty(nameField.Text)) - Changed = true; - if (!string.IsNullOrEmpty(releaseDateField.Text)) - Changed = true; - if (!string.IsNullOrEmpty(authorField.Text)) - Changed = true; - } - else - { - if (_cover != _book.BookCover) - Changed = true; - if (nameField.Text != _book.Name) - Changed = true; - if (releaseDateField.Date != _book.ReleaseDate) - Changed = true; - if (authorField.SelectedItem != _book.Author) - Changed = true; - } - if (Changed) - { - DialogResult dialogResult = MessageBox.Show("Изменения не были сохранены. Всё равно выйти?", "Внимание!", MessageBoxButtons.YesNo); - if (dialogResult == DialogResult.No) - { - e.Cancel = true; - } - } - } - catch (Exception ex) - { - MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); - } - } - - private void saveButton_Click(object sender, EventArgs e) - { - try - { - if (string.IsNullOrEmpty(_cover)) - { - throw new Exception("Выберите обложку"); - } - var book = new BookDto() - { - Name = nameField.Text, - BookCover = _cover, - Author = authorField.SelectedItem, - ReleaseDate = releaseDateField.Date, - }; - if (_id != -1) - { - book.Id = _id; - _book = _bookStorage.Update(book); - } - else - { - _book = _bookStorage.Insert(book); - } - _id = _book?.Id ?? -1; - _cover = _book?.BookCover ?? string.Empty; - Close(); - } - catch (Exception ex) - { - MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); - } - } - - private void changeCoverButton_Click(object sender, EventArgs e) - { - - var dialog = new OpenFileDialog(); - - dialog.Title = "Выберите изображение"; - dialog.Filter = "Изображения|*.jpg;*.jpeg;*.png;*.bmp"; - - if (dialog.ShowDialog() == DialogResult.OK) - { - var image_new = new Bitmap(dialog.FileName); - pictureBox.Image = image_new; - _cover = _imageConverter.ImageToString(image_new); - } - - dialog.Dispose(); - } - } -} diff --git a/LibraryWinFormsApp/FormBooks.Designer.cs b/LibraryWinFormsApp/FormBooks.Designer.cs deleted file mode 100644 index 6919587..0000000 --- a/LibraryWinFormsApp/FormBooks.Designer.cs +++ /dev/null @@ -1,145 +0,0 @@ -namespace LibraryWinFormsApp -{ - partial class FormBooks - { - /// - /// Required designer variable. - /// - private System.ComponentModel.IContainer components = null; - - /// - /// Clean up any resources being used. - /// - /// true if managed resources should be disposed; otherwise, false. - protected override void Dispose(bool disposing) - { - if (disposing && (components != null)) - { - components.Dispose(); - } - base.Dispose(disposing); - } - - #region Windows Form Designer generated code - - /// - /// Required method for Designer support - do not modify - /// the contents of this method with the code editor. - /// - private void InitializeComponent() - { - components = new System.ComponentModel.Container(); - bookTable = new YunusovComponentsLibrary.ListOutputComponent(); - bookTableContextMenuStrip = new ContextMenuStrip(components); - changeAuthorsToolStripMenuItem = new ToolStripMenuItem(); - createBookToolStripMenuItem = new ToolStripMenuItem(); - updateBookToolStripMenuItem = new ToolStripMenuItem(); - deleteBookToolStripMenuItem = new ToolStripMenuItem(); - createPdfToolStripMenuItem = new ToolStripMenuItem(); - createExcellToolStripMenuItem = new ToolStripMenuItem(); - createWordToolStripMenuItem = new ToolStripMenuItem(); - pdfImage = new ComponentLibrary1.pdf_image.PdfImage(components); - configurableTable = new Library_var_4_lab_1.ConfigurableTable(components); - wordDiagram = new YunusovComponentsLibrary.WordDiagram(components); - bookTableContextMenuStrip.SuspendLayout(); - SuspendLayout(); - // - // bookTable - // - bookTable.AutoSize = true; - bookTable.ContextMenuStrip = bookTableContextMenuStrip; - bookTable.Dock = DockStyle.Fill; - bookTable.Location = new Point(0, 0); - bookTable.Margin = new Padding(3, 2, 3, 2); - bookTable.Name = "bookTable"; - bookTable.SelectedRow = -1; - bookTable.Size = new Size(827, 493); - bookTable.TabIndex = 0; - // - // bookTableContextMenuStrip - // - bookTableContextMenuStrip.Items.AddRange(new ToolStripItem[] { changeAuthorsToolStripMenuItem, createBookToolStripMenuItem, updateBookToolStripMenuItem, deleteBookToolStripMenuItem, createPdfToolStripMenuItem, createExcellToolStripMenuItem, createWordToolStripMenuItem }); - bookTableContextMenuStrip.Name = "bookTableContextMenuStrip"; - bookTableContextMenuStrip.Size = new Size(202, 158); - // - // changeAuthorsToolStripMenuItem - // - changeAuthorsToolStripMenuItem.Name = "changeAuthorsToolStripMenuItem"; - changeAuthorsToolStripMenuItem.Size = new Size(201, 22); - changeAuthorsToolStripMenuItem.Text = "Редактировать авторов"; - changeAuthorsToolStripMenuItem.Click += changeAuthorsToolStripMenuItem_Click; - // - // createBookToolStripMenuItem - // - createBookToolStripMenuItem.Name = "createBookToolStripMenuItem"; - createBookToolStripMenuItem.Size = new Size(201, 22); - createBookToolStripMenuItem.Text = "Добавить книгу"; - createBookToolStripMenuItem.Click += createBookToolStripMenuItem_Click; - // - // updateBookToolStripMenuItem - // - updateBookToolStripMenuItem.Name = "updateBookToolStripMenuItem"; - updateBookToolStripMenuItem.Size = new Size(201, 22); - updateBookToolStripMenuItem.Text = "Редактировать книгу"; - updateBookToolStripMenuItem.Click += updateBookToolStripMenuItem_Click; - // - // deleteBookToolStripMenuItem - // - deleteBookToolStripMenuItem.Name = "deleteBookToolStripMenuItem"; - deleteBookToolStripMenuItem.Size = new Size(201, 22); - deleteBookToolStripMenuItem.Text = "Удалить книгу"; - deleteBookToolStripMenuItem.Click += deleteBookToolStripMenuItem_Click; - // - // createPdfToolStripMenuItem - // - createPdfToolStripMenuItem.Name = "createPdfToolStripMenuItem"; - createPdfToolStripMenuItem.Size = new Size(201, 22); - createPdfToolStripMenuItem.Text = "Создать pdf"; - createPdfToolStripMenuItem.Click += createPdfToolStripMenuItem_Click; - // - // createExcellToolStripMenuItem - // - createExcellToolStripMenuItem.Name = "createExcellToolStripMenuItem"; - createExcellToolStripMenuItem.Size = new Size(201, 22); - createExcellToolStripMenuItem.Text = "Создать excell"; - createExcellToolStripMenuItem.Click += createExcellToolStripMenuItem_Click; - // - // createWordToolStripMenuItem - // - createWordToolStripMenuItem.Name = "createWordToolStripMenuItem"; - createWordToolStripMenuItem.Size = new Size(201, 22); - createWordToolStripMenuItem.Text = "Создать word"; - createWordToolStripMenuItem.Click += createWordToolStripMenuItem_Click; - // - // FormBooks - // - AutoScaleDimensions = new SizeF(7F, 15F); - AutoScaleMode = AutoScaleMode.Font; - ClientSize = new Size(827, 493); - Controls.Add(bookTable); - KeyPreview = true; - Name = "FormBooks"; - Text = "Книги"; - Load += FormBooks_Load; - KeyDown += booksTable_KeyDown; - bookTableContextMenuStrip.ResumeLayout(false); - ResumeLayout(false); - PerformLayout(); - } - - #endregion - - private YunusovComponentsLibrary.ListOutputComponent bookTable; - private ContextMenuStrip bookTableContextMenuStrip; - private ToolStripMenuItem changeAuthorsToolStripMenuItem; - private ToolStripMenuItem createBookToolStripMenuItem; - private ToolStripMenuItem updateBookToolStripMenuItem; - private ToolStripMenuItem deleteBookToolStripMenuItem; - private ToolStripMenuItem createPdfToolStripMenuItem; - private ToolStripMenuItem createExcellToolStripMenuItem; - private ToolStripMenuItem createWordToolStripMenuItem; - private ComponentLibrary1.pdf_image.PdfImage pdfImage; - private Library_var_4_lab_1.ConfigurableTable configurableTable; - private YunusovComponentsLibrary.WordDiagram wordDiagram; - } -} diff --git a/LibraryWinFormsApp/FormBooks.cs b/LibraryWinFormsApp/FormBooks.cs deleted file mode 100644 index 106a9ef..0000000 --- a/LibraryWinFormsApp/FormBooks.cs +++ /dev/null @@ -1,357 +0,0 @@ -using ComponentLibrary1.pdf_image; -using LibraryContracts.StorageContracts; -using LibraryDataModels.Dtos; -using LibraryDataModels.Views; -using System.Windows.Forms; -using YunusovComponentsLibrary; -using YunusovComponentsLibrary.OfficePackage.HelperModels; - -namespace LibraryWinFormsApp -{ - public partial class FormBooks : Form - { - private IBookStorage _bookStorage; - private IAuthorStorage _authorStorage; - private List _books = new List(); - private ImageConverter _converter = new ImageConverter(); - public FormBooks(IBookStorage bookStorage, IAuthorStorage authorStorage) - { - InitializeComponent(); - _bookStorage = bookStorage; - _authorStorage = authorStorage; - } - - #region event-handler-methods - private void FormBooks_Load(object sender, EventArgs e) - { - try - { - LoadData(); - } - catch (Exception ex) - { - MessageBox.Show(ex.Message, "", MessageBoxButtons.OK, MessageBoxIcon.Error); - } - } - - private void changeAuthorsToolStripMenuItem_Click(object sender, EventArgs e) - { - var service = Program.ServiceProvider?.GetService(typeof(FormAuthors)); - if (service is FormAuthors form) - { - form.ShowDialog(); - } - } - - private void createBookToolStripMenuItem_Click(object sender, EventArgs e) - { - try - { - CreateBook(); - } - catch (Exception ex) - { - MessageBox.Show(ex.Message, "", MessageBoxButtons.OK, MessageBoxIcon.Error); - } - } - - private void updateBookToolStripMenuItem_Click(object sender, EventArgs e) - { - try - { - UpdateBook(); - } - catch (Exception ex) - { - MessageBox.Show(ex.Message, "", MessageBoxButtons.OK, MessageBoxIcon.Error); - } - } - - private void deleteBookToolStripMenuItem_Click(object sender, EventArgs e) - { - try - { - DeleteBook(); - } - catch (Exception ex) - { - MessageBox.Show(ex.Message, "", MessageBoxButtons.OK, MessageBoxIcon.Error); - } - } - - private void createPdfToolStripMenuItem_Click(object sender, EventArgs e) - { - try - { - CreatePdf(); - } - catch (Exception ex) - { - MessageBox.Show(ex.Message, "", MessageBoxButtons.OK, MessageBoxIcon.Error); - } - } - - private void createExcellToolStripMenuItem_Click(object sender, EventArgs e) - { - try - { - CreateExcell(); - } - catch (Exception ex) - { - MessageBox.Show(ex.Message, "", MessageBoxButtons.OK, MessageBoxIcon.Error); - } - } - - private void createWordToolStripMenuItem_Click(object sender, EventArgs e) - { - try - { - CreateWord(); - } - catch (Exception ex) - { - MessageBox.Show(ex.Message, "", MessageBoxButtons.OK, MessageBoxIcon.Error); - } - } - - private void booksTable_KeyDown(object sender, KeyEventArgs e) - { - try - { - if (!e.Control) { return; } - switch (e.KeyCode) - { - case Keys.A: - CreateBook(); - break; - case Keys.U: - UpdateBook(); - break; - case Keys.D: - DeleteBook(); - break; - case Keys.S: - CreatePdf(); - break; - case Keys.T: - CreateExcell(); - break; - case Keys.C: - CreateWord(); - break; - } - } - catch (Exception ex) - { - MessageBox.Show(ex.Message, "", MessageBoxButtons.OK, MessageBoxIcon.Error); - } - } - #endregion - - private void LoadData() - { - _books = _bookStorage.GetFullList(); - List parameters = new List() - { - 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); - } - } - - private void CreateBook() - { - var service = Program.ServiceProvider?.GetService(typeof(FormBook)); - if (service is FormBook form) - { - form.ShowDialog(); - LoadData(); - } - } - - private void UpdateBook() - { - int selectedRow = bookTable.SelectedRow; - if (selectedRow == -1) - { - throw new Exception(" "); - } - else - { - int id = Convert.ToInt32(bookTable.Rows[selectedRow].Cells[0].Value); - var service = Program.ServiceProvider?.GetService(typeof(FormBook)); - if (service is FormBook form) - { - form._id = id; - form.ShowDialog(); - LoadData(); - } - } - } - - private void DeleteBook() - { - 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 - }); - LoadData(); - } - } - - 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 = $"|*{extension}" - }; - if (fileDialog.ShowDialog() == DialogResult.OK) - { - return fileDialog.FileName; - } - return ""; - } - - private void CreatePdf() - { - string fileName = GetFileFullName(DocType.Pdf); - if (string.IsNullOrWhiteSpace(fileName)) - { - return; - } - _books = _bookStorage.GetFullList(); - List selectedImages = new List(); - foreach (var book in _books) - { - selectedImages.Add(_converter.StringToByteArray(book.BookCover)); - } - var info = new PdfImageInfo - { - FileName = fileName, - Title = "", - Images = selectedImages, - }; - pdfImage.CreatePdf(info); - MessageBox.Show("PDF !", "", MessageBoxButtons.OK, MessageBoxIcon.Information); - } - - private void CreateExcell() - { - string fileName = GetFileFullName(DocType.Excel); - if (string.IsNullOrWhiteSpace(fileName)) - { - return; - } - List headers = new List - { - 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", - }, - }; - _books = _bookStorage.GetFullList(); - configurableTable.CreateTable( - fileName, - "", - headers, - _books); - MessageBox.Show("Excell !", "", MessageBoxButtons.OK, MessageBoxIcon.Information); - } - - private void CreateWord() - { - string fileName = GetFileFullName(DocType.Word); - if (string.IsNullOrWhiteSpace(fileName)) - { - return; - } - _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); - } - } -} diff --git a/LibraryWinFormsApp/FormBooks.resx b/LibraryWinFormsApp/FormBooks.resx deleted file mode 100644 index 035ed33..0000000 --- a/LibraryWinFormsApp/FormBooks.resx +++ /dev/null @@ -1,132 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - text/microsoft-resx - - - 2.0 - - - System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - 17, 17 - - - 222, 17 - - - 327, 17 - - - 475, 17 - - \ No newline at end of file diff --git a/LibraryWinFormsApp/FormMain.Designer.cs b/LibraryWinFormsApp/FormMain.Designer.cs new file mode 100644 index 0000000..63ac31d --- /dev/null +++ b/LibraryWinFormsApp/FormMain.Designer.cs @@ -0,0 +1,233 @@ +namespace LibraryWinFormsApp +{ + partial class FormMain + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.menuStrip = new System.Windows.Forms.MenuStrip(); + this.ControlsStripMenuItem = new + System.Windows.Forms.ToolStripMenuItem(); + this.ActionsToolStripMenuItem = new + System.Windows.Forms.ToolStripMenuItem(); + this.DocsToolStripMenuItem = new + System.Windows.Forms.ToolStripMenuItem(); + this.SimpleDocToolStripMenuItem = new + System.Windows.Forms.ToolStripMenuItem(); + this.TableDocToolStripMenuItem = new + System.Windows.Forms.ToolStripMenuItem(); + this.ChartDocToolStripMenuItem = new + System.Windows.Forms.ToolStripMenuItem(); + this.panelControl = new System.Windows.Forms.Panel(); + this.ThesaurusToolStripMenuItem = new + System.Windows.Forms.ToolStripMenuItem(); + this.AddElementToolStripMenuItem = new + System.Windows.Forms.ToolStripMenuItem(); + this.UpdElementToolStripMenuItem = new + System.Windows.Forms.ToolStripMenuItem(); + this.DelElementToolStripMenuItem = new + System.Windows.Forms.ToolStripMenuItem(); + this.menuStrip.SuspendLayout(); + this.SuspendLayout(); + // + // menuStrip + // + this.menuStrip.Items.AddRange(new + System.Windows.Forms.ToolStripItem[] { + this.ControlsStripMenuItem, + this.ActionsToolStripMenuItem, + this.DocsToolStripMenuItem}); + this.menuStrip.Location = new System.Drawing.Point(0, 0); + this.menuStrip.Name = "menuStrip"; + this.menuStrip.Size = new System.Drawing.Size(800, 24); + this.menuStrip.TabIndex = 0; + this.menuStrip.Text = "Меню"; + // + // ControlsStripMenuItem + // + this.ControlsStripMenuItem.Name = "ControlsStripMenuItem"; + this.ControlsStripMenuItem.Size = new System.Drawing.Size(94, + 20); + this.ControlsStripMenuItem.Text = "Компоненты"; + // + // ActionsToolStripMenuItem + // + this.ActionsToolStripMenuItem.DropDownItems.AddRange(new + System.Windows.Forms.ToolStripItem[] { + this.ThesaurusToolStripMenuItem, + this.AddElementToolStripMenuItem, + this.UpdElementToolStripMenuItem, + this.DelElementToolStripMenuItem}); + this.ActionsToolStripMenuItem.Name = + "ActionsToolStripMenuItem"; + this.ActionsToolStripMenuItem.Size = new + System.Drawing.Size(70, 20); + this.ActionsToolStripMenuItem.Text = "Действия"; + // + // DocsToolStripMenuItem + // + this.DocsToolStripMenuItem.DropDownItems.AddRange(new + System.Windows.Forms.ToolStripItem[] { + this.SimpleDocToolStripMenuItem, + this.TableDocToolStripMenuItem, + this.ChartDocToolStripMenuItem}); + this.DocsToolStripMenuItem.Name = "DocsToolStripMenuItem"; + this.DocsToolStripMenuItem.Size = new System.Drawing.Size(82, 20); + this.DocsToolStripMenuItem.Text = "Документы"; + // + // SimpleDocToolStripMenuItem + // + this.SimpleDocToolStripMenuItem.Name = "SimpleDocToolStripMenuItem"; + this.SimpleDocToolStripMenuItem.ShortcutKeys = + ((System.Windows.Forms.Keys)((System.Windows.Forms.Keys.Control | + System.Windows.Forms.Keys.S))); + this.SimpleDocToolStripMenuItem.Size = new + System.Drawing.Size(233, 22); + this.SimpleDocToolStripMenuItem.Text = "Простой документ"; + this.SimpleDocToolStripMenuItem.Click += new + System.EventHandler(this.SimpleDocToolStripMenuItem_Click); + // + // TableDocToolStripMenuItem + // + this.TableDocToolStripMenuItem.Name = + "TableDocToolStripMenuItem"; + this.TableDocToolStripMenuItem.ShortcutKeys = + ((System.Windows.Forms.Keys)((System.Windows.Forms.Keys.Control | + System.Windows.Forms.Keys.T))); + this.TableDocToolStripMenuItem.Size = new + System.Drawing.Size(233, 22); + this.TableDocToolStripMenuItem.Text = "Документ с таблицой"; + this.TableDocToolStripMenuItem.Click += new + System.EventHandler(this.TableDocToolStripMenuItem_Click); + // + // ChartDocToolStripMenuItem + // + this.ChartDocToolStripMenuItem.Name = + "ChartDocToolStripMenuItem"; + this.ChartDocToolStripMenuItem.ShortcutKeys = + ((System.Windows.Forms.Keys)((System.Windows.Forms.Keys.Control | + System.Windows.Forms.Keys.C))); + this.ChartDocToolStripMenuItem.Size = new + System.Drawing.Size(233, 22); + this.ChartDocToolStripMenuItem.Text = "Диаграмма"; + this.ChartDocToolStripMenuItem.Click += new + System.EventHandler(this.ChartDocToolStripMenuItem_Click); + // + // panelControl + // + this.panelControl.Dock = System.Windows.Forms.DockStyle.Fill; + this.panelControl.Location = new System.Drawing.Point(0, 24); + this.panelControl.Name = "panelControl"; + this.panelControl.Size = new System.Drawing.Size(800, 426); + this.panelControl.TabIndex = 1; + // + // ThesaurusToolStripMenuItem + // + this.ThesaurusToolStripMenuItem.Name = + "ThesaurusToolStripMenuItem"; + this.ThesaurusToolStripMenuItem.ShortcutKeys = + ((System.Windows.Forms.Keys)((System.Windows.Forms.Keys.Control | + System.Windows.Forms.Keys.I))); + this.ThesaurusToolStripMenuItem.Size = new + System.Drawing.Size(180, 22); + this.ThesaurusToolStripMenuItem.Text = "Справочник"; + this.ThesaurusToolStripMenuItem.Click += new + System.EventHandler(this.ThesaurusToolStripMenuItem_Click); + // + // AddElementToolStripMenuItem + // + this.AddElementToolStripMenuItem.Name = + "AddElementToolStripMenuItem"; + this.AddElementToolStripMenuItem.ShortcutKeys = + ((System.Windows.Forms.Keys)((System.Windows.Forms.Keys.Control | + System.Windows.Forms.Keys.A))); + this.AddElementToolStripMenuItem.Size = new + System.Drawing.Size(180, 22); + this.AddElementToolStripMenuItem.Text = "Добавить"; + this.AddElementToolStripMenuItem.Click += new + System.EventHandler(this.AddElementToolStripMenuItem_Click); + // + // UpdElementToolStripMenuItem + // + this.UpdElementToolStripMenuItem.Name = "UpdElementToolStripMenuItem"; + this.UpdElementToolStripMenuItem.ShortcutKeys = + ((System.Windows.Forms.Keys)((System.Windows.Forms.Keys.Control | + System.Windows.Forms.Keys.U))); + this.UpdElementToolStripMenuItem.Size = new + System.Drawing.Size(180, 22); + this.UpdElementToolStripMenuItem.Text = "Изменить"; + this.UpdElementToolStripMenuItem.Click += new + System.EventHandler(this.UpdElementToolStripMenuItem_Click); + // + // DelElementToolStripMenuItem + // + this.DelElementToolStripMenuItem.Name = + "DelElementToolStripMenuItem"; + this.DelElementToolStripMenuItem.ShortcutKeys = + ((System.Windows.Forms.Keys)((System.Windows.Forms.Keys.Control | + System.Windows.Forms.Keys.D))); + this.DelElementToolStripMenuItem.Size = new + System.Drawing.Size(180, 22); + this.DelElementToolStripMenuItem.Text = "Удалить"; + this.DelElementToolStripMenuItem.Click += new + System.EventHandler(this.DelElementToolStripMenuItem_Click); + // + // FormMain + // + this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(800, 450); + this.Controls.Add(this.panelControl); + this.Controls.Add(this.menuStrip); + this.MainMenuStrip = this.menuStrip; + this.Name = "FormMain"; + this.StartPosition = + System.Windows.Forms.FormStartPosition.CenterScreen; + this.Text = "Главная форма"; + this.WindowState = + System.Windows.Forms.FormWindowState.Maximized; + this.KeyDown += new + System.Windows.Forms.KeyEventHandler(this.FormMain_KeyDown); + this.menuStrip.ResumeLayout(false); + this.menuStrip.PerformLayout(); + this.ResumeLayout(false); + this.PerformLayout(); + } + #endregion + private System.Windows.Forms.MenuStrip menuStrip; + private System.Windows.Forms.ToolStripMenuItem ControlsStripMenuItem; + private System.Windows.Forms.ToolStripMenuItem DocsToolStripMenuItem; + private System.Windows.Forms.ToolStripMenuItem SimpleDocToolStripMenuItem; + private System.Windows.Forms.ToolStripMenuItem TableDocToolStripMenuItem; + private System.Windows.Forms.ToolStripMenuItem ChartDocToolStripMenuItem; + private System.Windows.Forms.Panel panelControl; + private System.Windows.Forms.ToolStripMenuItem ActionsToolStripMenuItem; + private System.Windows.Forms.ToolStripMenuItem ThesaurusToolStripMenuItem; + private System.Windows.Forms.ToolStripMenuItem AddElementToolStripMenuItem; + private System.Windows.Forms.ToolStripMenuItem UpdElementToolStripMenuItem; + private System.Windows.Forms.ToolStripMenuItem DelElementToolStripMenuItem; + } +} \ No newline at end of file diff --git a/LibraryWinFormsApp/FormMain.cs b/LibraryWinFormsApp/FormMain.cs new file mode 100644 index 0000000..2ee8b7a --- /dev/null +++ b/LibraryWinFormsApp/FormMain.cs @@ -0,0 +1,253 @@ +using NPOI.HPSF; +using Plugins; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Reflection; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace LibraryWinFormsApp +{ + public partial class FormMain : Form + { + private readonly Dictionary _plugins; + private string _selectedPlugin; + public FormMain() + { + InitializeComponent(); + _plugins = LoadPlugins(); + _selectedPlugin = string.Empty; + } + private Dictionary LoadPlugins() + { + Dictionary plugins = new(); + string currentDirectory = Directory + .GetParent(Environment.CurrentDirectory)! + .Parent! + .Parent! + .Parent! + .FullName + "\\plugin"; + string[] dllFiles = Directory.GetFiles(currentDirectory, "*.dll", SearchOption.AllDirectories); + foreach (string dllFile in dllFiles) + { + try + { + Assembly assembly = Assembly.LoadFrom(dllFile); + + Type[] types = assembly.GetTypes(); + + foreach (Type type in types) + { + if (typeof(IPluginsConvention).IsAssignableFrom(type) && !type.IsInterface) + { + var plugin = (IPluginsConvention)Activator.CreateInstance(type)!; + + plugins.Add(plugin.PluginName, plugin); + } + } + } + catch (Exception ex) + { + Console.WriteLine($"Не удалось загрузить плагин {dllFile}: {ex.Message}"); + } + } + foreach (var plugin in plugins) + { + CreateMenuItem(plugin.Value.PluginName); + } + return plugins; + } + private void CreateMenuItem(string pluginName) + { + ToolStripMenuItem menuItem = new ToolStripMenuItem(pluginName); + menuItem.Click += (object? sender, EventArgs a) => + { + _selectedPlugin = pluginName; + IPluginsConvention plugin = _plugins[pluginName]; + UserControl userControl = plugin.GetControl; + if (userControl != null) + { + panelControl.Controls.Clear(); + plugin.ReloadData(); + userControl.Dock = DockStyle.Fill; + panelControl.Controls.Add(userControl); + } + }; + ControlsStripMenuItem.DropDownItems.Add(menuItem); + } + private void FormMain_KeyDown(object sender, KeyEventArgs e) + { + if (string.IsNullOrEmpty(_selectedPlugin) || + !_plugins.ContainsKey(_selectedPlugin)) + { + return; + } + if (!e.Control) + { + return; + } + switch (e.KeyCode) + { + case Keys.I: + ShowThesaurus(); + break; + case Keys.A: + AddNewElement(); + break; + case Keys.U: + UpdateElement(); + break; + case Keys.D: + DeleteElement(); + break; + case Keys.S: + CreateSimpleDoc(); + break; + case Keys.T: + CreateTableDoc(); + break; + case Keys.C: + CreateChartDoc(); + break; + } + } + private void ShowThesaurus() + { + _plugins[_selectedPlugin].GetThesaurus()?.Show(); + } + private void AddNewElement() + { + var form = _plugins[_selectedPlugin].GetForm(null); + if (form != null && form.ShowDialog() == DialogResult.OK) + { + _plugins[_selectedPlugin].ReloadData(); + } + } + private void UpdateElement() + { + var element = _plugins[_selectedPlugin].GetElement; + if (element == null) + { + MessageBox.Show("Нет выбранного элемента", "Ошибка", + MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + var form = _plugins[_selectedPlugin].GetForm(element); + if (form != null && form.ShowDialog() == DialogResult.OK) + { + _plugins[_selectedPlugin].ReloadData(); + } + } + private void DeleteElement() + { + if (MessageBox.Show("Удалить выбранный элемент", "Удаление", + MessageBoxButtons.YesNo, + MessageBoxIcon.Question) != DialogResult.Yes) + { + return; + } + var element = _plugins[_selectedPlugin].GetElement; + if (element == null) + { + MessageBox.Show("Нет выбранного элемента", "Ошибка", + MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + + if (_plugins[_selectedPlugin].DeleteElement(element)) + { + _plugins[_selectedPlugin].ReloadData(); + } + } + private void CreateSimpleDoc() + { + SaveFileDialog saveFileDialog = new SaveFileDialog(); + saveFileDialog.Filter = "Word Documents (*.docx)|*.docx"; + saveFileDialog.Title = "Сохранить простой документ"; + if (saveFileDialog.ShowDialog() == DialogResult.OK) + { + if (_plugins[_selectedPlugin].CreateSimpleDocument( + new PluginsConventionSaveDocument() + { + FileName = saveFileDialog.FileName + })) + { + MessageBox.Show("Документ сохранен", "Создание" + + " документа", MessageBoxButtons.OK, MessageBoxIcon.Information); + } + else + { + MessageBox.Show("Ошибка при создании документа", + "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + + } + } + private void CreateTableDoc() + { + SaveFileDialog saveFileDialog = new SaveFileDialog(); + saveFileDialog.Filter = "PDF Files (*.pdf)|*.pdf"; + saveFileDialog.Title = "Сохранить таблицу"; + if (saveFileDialog.ShowDialog() == DialogResult.OK) + { + if (_plugins[_selectedPlugin].CreateTableDocument( + new PluginsConventionSaveDocument() + { + FileName = saveFileDialog.FileName + })) + { + MessageBox.Show("Документ сохранен", "Создание" + + " документа", MessageBoxButtons.OK, MessageBoxIcon.Information); + } + else + { + MessageBox.Show("Ошибка при создании документа", + "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + private void CreateChartDoc() + { + SaveFileDialog saveFileDialog = new SaveFileDialog(); + saveFileDialog.Filter = "Excel Files (*.xlsx)|*.xlsx"; + saveFileDialog.Title = "Сохранить диаграмму"; + if (saveFileDialog.ShowDialog() == DialogResult.OK) + { + if (_plugins[_selectedPlugin].CreateChartDocument( + new PluginsConventionSaveDocument() + { + FileName = saveFileDialog.FileName + })) + { + MessageBox.Show("Документ сохранен", "Создание" + + " документа", MessageBoxButtons.OK, MessageBoxIcon.Information); + } + else + { + MessageBox.Show("Ошибка при создании документа", + "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + + } + } + private void ThesaurusToolStripMenuItem_Click(object sender, + EventArgs e) => ShowThesaurus(); + private void AddElementToolStripMenuItem_Click(object sender, + EventArgs e) => AddNewElement(); + private void UpdElementToolStripMenuItem_Click(object sender, + EventArgs e) => UpdateElement(); + private void DelElementToolStripMenuItem_Click(object sender, + EventArgs e) => DeleteElement(); + private void SimpleDocToolStripMenuItem_Click(object sender, + EventArgs e) => CreateSimpleDoc(); + private void TableDocToolStripMenuItem_Click(object sender, EventArgs + e) => CreateTableDoc(); + private void ChartDocToolStripMenuItem_Click(object sender, EventArgs + e) => CreateChartDoc(); + } +} diff --git a/LibraryWinFormsApp/FormBook.resx b/LibraryWinFormsApp/FormMain.resx similarity index 93% rename from LibraryWinFormsApp/FormBook.resx rename to LibraryWinFormsApp/FormMain.resx index af32865..1af7de1 100644 --- a/LibraryWinFormsApp/FormBook.resx +++ b/LibraryWinFormsApp/FormMain.resx @@ -1,17 +1,17 @@  - diff --git a/LibraryWinFormsApp/ImageConverter.cs b/LibraryWinFormsApp/ImageConverter.cs deleted file mode 100644 index 4a32330..0000000 --- a/LibraryWinFormsApp/ImageConverter.cs +++ /dev/null @@ -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); - } - } -} diff --git a/LibraryWinFormsApp/LibraryWinFormsApp.csproj b/LibraryWinFormsApp/LibraryWinFormsApp.csproj index df4ec06..98d4bda 100644 --- a/LibraryWinFormsApp/LibraryWinFormsApp.csproj +++ b/LibraryWinFormsApp/LibraryWinFormsApp.csproj @@ -15,8 +15,4 @@ - - - - \ No newline at end of file diff --git a/LibraryWinFormsApp/Program.cs b/LibraryWinFormsApp/Program.cs index d7bb5b5..da06d54 100644 --- a/LibraryWinFormsApp/Program.cs +++ b/LibraryWinFormsApp/Program.cs @@ -1,36 +1,17 @@ -using System; -using LibraryContracts.StorageContracts; -using LibraryDatabase.Storages; -using Microsoft.Extensions.DependencyInjection; - namespace LibraryWinFormsApp { - internal static class Program - { - private static ServiceProvider? _serviceProvider; - public static ServiceProvider? ServiceProvider => _serviceProvider; - /// - /// The main entry point for the application. - /// - [STAThread] - static void Main() - { - // To customize application configuration such as set high DPI settings or default font, - // see https://aka.ms/applicationconfiguration. - ApplicationConfiguration.Initialize(); - var services = new ServiceCollection(); - ConfigureServices(services); - _serviceProvider = services.BuildServiceProvider(); - Application.Run(_serviceProvider.GetRequiredService()); - } - - private static void ConfigureServices(ServiceCollection services) - { - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - } - } + internal static class Program + { + /// + /// The main entry point for the application. + /// + [STAThread] + static void Main() + { + // To customize application configuration such as set high DPI settings or default font, + // see https://aka.ms/applicationconfiguration. + ApplicationConfiguration.Initialize(); + Application.Run(new FormMain()); + } + } } \ No newline at end of file