From 658881cb94ff6806f0e5a148f2e7736164a8ae74 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=98=D0=BB=D1=8C=D1=8F?= <Илья@WIN-RANNDDD> Date: Mon, 4 Nov 2024 23:43:51 +0400 Subject: [PATCH] lab4 ready --- COP/COP.sln | 22 +- COP/PluginsApp/FormMain.Designer.cs | 173 +++++++++++++ COP/PluginsApp/FormMain.cs | 243 ++++++++++++++++++ COP/PluginsApp/FormMain.resx | 123 +++++++++ COP/PluginsApp/PluginsApp.csproj | 19 ++ COP/PluginsApp/Program.cs | 17 ++ .../IPluginsConvention.cs | 66 +++++ .../PluginsConventionElement.cs | 7 + .../PluginsConventionLibrary.csproj | 10 + .../PluginsConventionSaveDocument.cs | 7 + COP/PortalAccountsView/PluginsConvention.cs | 211 +++++++++++++++ .../PluginsConventionAccount.cs | 15 ++ .../PortalAccountsView.csproj | 1 + 13 files changed, 909 insertions(+), 5 deletions(-) create mode 100644 COP/PluginsApp/FormMain.Designer.cs create mode 100644 COP/PluginsApp/FormMain.cs create mode 100644 COP/PluginsApp/FormMain.resx create mode 100644 COP/PluginsApp/PluginsApp.csproj create mode 100644 COP/PluginsApp/Program.cs create mode 100644 COP/PluginsConventionLibrary/IPluginsConvention.cs create mode 100644 COP/PluginsConventionLibrary/PluginsConventionElement.cs create mode 100644 COP/PluginsConventionLibrary/PluginsConventionLibrary.csproj create mode 100644 COP/PluginsConventionLibrary/PluginsConventionSaveDocument.cs create mode 100644 COP/PortalAccountsView/PluginsConvention.cs create mode 100644 COP/PortalAccountsView/PluginsConventionAccount.cs diff --git a/COP/COP.sln b/COP/COP.sln index f3baea6..c21fd07 100644 --- a/COP/COP.sln +++ b/COP/COP.sln @@ -7,15 +7,19 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "RodionovLibrary", "Rodionov EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "WinForms", "WinForms\WinForms.csproj", "{E160EBCF-4BD1-4049-ADD6-597332133952}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PortalAccountsContracts", "PortalAccountsContracts\PortalAccountsContracts.csproj", "{F18747FB-607B-42E4-AA8E-86A7E2FFBD28}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PortalAccountsContracts", "PortalAccountsContracts\PortalAccountsContracts.csproj", "{F18747FB-607B-42E4-AA8E-86A7E2FFBD28}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PortalAccountsDataModels", "PortalAccountsDataModels\PortalAccountsDataModels.csproj", "{4DFB6049-FCE4-42F3-B611-BAEE5156EA9C}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PortalAccountsDataModels", "PortalAccountsDataModels\PortalAccountsDataModels.csproj", "{4DFB6049-FCE4-42F3-B611-BAEE5156EA9C}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PortalAccountsBusinessLogic", "PortalAccountsBusinessLogic\PortalAccountsBusinessLogic.csproj", "{06D98752-0805-4CE4-AE5A-0EC14694D7D9}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PortalAccountsBusinessLogic", "PortalAccountsBusinessLogic\PortalAccountsBusinessLogic.csproj", "{06D98752-0805-4CE4-AE5A-0EC14694D7D9}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PortalAccountsDatabaseImplement", "PortalAccountsDatabaseImplement\PortalAccountsDatabaseImplement.csproj", "{0D3E5B70-5816-4AF6-AA94-95EA34EEC9FE}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PortalAccountsDatabaseImplement", "PortalAccountsDatabaseImplement\PortalAccountsDatabaseImplement.csproj", "{0D3E5B70-5816-4AF6-AA94-95EA34EEC9FE}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PortalAccountsView", "PortalAccountsView\PortalAccountsView.csproj", "{0304D12E-0F97-4C82-BB88-4E4784DEC81C}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PortalAccountsView", "PortalAccountsView\PortalAccountsView.csproj", "{0304D12E-0F97-4C82-BB88-4E4784DEC81C}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PluginsConventionLibrary", "PluginsConventionLibrary\PluginsConventionLibrary.csproj", "{6D5CA9C2-3975-43D4-8355-D06A5F38D1B6}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PluginsApp", "PluginsApp\PluginsApp.csproj", "{B4C12E16-5D35-4AB6-9DAA-DC4D545A8C5C}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -51,6 +55,14 @@ Global {0304D12E-0F97-4C82-BB88-4E4784DEC81C}.Debug|Any CPU.Build.0 = Debug|Any CPU {0304D12E-0F97-4C82-BB88-4E4784DEC81C}.Release|Any CPU.ActiveCfg = Release|Any CPU {0304D12E-0F97-4C82-BB88-4E4784DEC81C}.Release|Any CPU.Build.0 = Release|Any CPU + {6D5CA9C2-3975-43D4-8355-D06A5F38D1B6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {6D5CA9C2-3975-43D4-8355-D06A5F38D1B6}.Debug|Any CPU.Build.0 = Debug|Any CPU + {6D5CA9C2-3975-43D4-8355-D06A5F38D1B6}.Release|Any CPU.ActiveCfg = Release|Any CPU + {6D5CA9C2-3975-43D4-8355-D06A5F38D1B6}.Release|Any CPU.Build.0 = Release|Any CPU + {B4C12E16-5D35-4AB6-9DAA-DC4D545A8C5C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {B4C12E16-5D35-4AB6-9DAA-DC4D545A8C5C}.Debug|Any CPU.Build.0 = Debug|Any CPU + {B4C12E16-5D35-4AB6-9DAA-DC4D545A8C5C}.Release|Any CPU.ActiveCfg = Release|Any CPU + {B4C12E16-5D35-4AB6-9DAA-DC4D545A8C5C}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/COP/PluginsApp/FormMain.Designer.cs b/COP/PluginsApp/FormMain.Designer.cs new file mode 100644 index 0000000..5b45822 --- /dev/null +++ b/COP/PluginsApp/FormMain.Designer.cs @@ -0,0 +1,173 @@ +namespace PluginsApp +{ + 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() + { + menuStrip = new MenuStrip(); + ControlsStripMenuItem = new ToolStripMenuItem(); + ActionsToolStripMenuItem = new ToolStripMenuItem(); + ThesaurusToolStripMenuItem = new ToolStripMenuItem(); + AddElementToolStripMenuItem = new ToolStripMenuItem(); + UpdElementToolStripMenuItem = new ToolStripMenuItem(); + DelElementToolStripMenuItem = new ToolStripMenuItem(); + DocsToolStripMenuItem = new ToolStripMenuItem(); + SimpleDocToolStripMenuItem = new ToolStripMenuItem(); + TableDocToolStripMenuItem = new ToolStripMenuItem(); + ChartDocToolStripMenuItem = new ToolStripMenuItem(); + panelControl = new Panel(); + menuStrip.SuspendLayout(); + SuspendLayout(); + // + // menuStrip + // + menuStrip.Items.AddRange(new ToolStripItem[] { ControlsStripMenuItem, ActionsToolStripMenuItem, DocsToolStripMenuItem }); + menuStrip.Location = new Point(0, 0); + menuStrip.Name = "menuStrip"; + menuStrip.Size = new Size(800, 24); + menuStrip.TabIndex = 0; + menuStrip.Text = "Меню"; + // + // ControlsStripMenuItem + // + ControlsStripMenuItem.Name = "ControlsStripMenuItem"; + ControlsStripMenuItem.Size = new Size(90, 20); + ControlsStripMenuItem.Text = "Компоненты"; + // + // ActionsToolStripMenuItem + // + ActionsToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { ThesaurusToolStripMenuItem, AddElementToolStripMenuItem, UpdElementToolStripMenuItem, DelElementToolStripMenuItem }); + ActionsToolStripMenuItem.Name = "ActionsToolStripMenuItem"; + ActionsToolStripMenuItem.Size = new Size(70, 20); + ActionsToolStripMenuItem.Text = "Действия"; + // + // ThesaurusToolStripMenuItem + // + ThesaurusToolStripMenuItem.Name = "ThesaurusToolStripMenuItem"; + ThesaurusToolStripMenuItem.ShortcutKeys = Keys.Control | Keys.I; + ThesaurusToolStripMenuItem.Size = new Size(180, 22); + ThesaurusToolStripMenuItem.Text = "Справочник"; + ThesaurusToolStripMenuItem.Click += ThesaurusToolStripMenuItem_Click; + // + // AddElementToolStripMenuItem + // + AddElementToolStripMenuItem.Name = "AddElementToolStripMenuItem"; + AddElementToolStripMenuItem.ShortcutKeys = Keys.Control | Keys.A; + AddElementToolStripMenuItem.Size = new Size(180, 22); + AddElementToolStripMenuItem.Text = "Добавить"; + AddElementToolStripMenuItem.Click += AddElementToolStripMenuItem_Click; + // + // UpdElementToolStripMenuItem + // + UpdElementToolStripMenuItem.Name = "UpdElementToolStripMenuItem"; + UpdElementToolStripMenuItem.ShortcutKeys = Keys.Control | Keys.U; + UpdElementToolStripMenuItem.Size = new Size(180, 22); + UpdElementToolStripMenuItem.Text = "Изменить"; + UpdElementToolStripMenuItem.Click += UpdElementToolStripMenuItem_Click; + // + // DelElementToolStripMenuItem + // + DelElementToolStripMenuItem.Name = "DelElementToolStripMenuItem"; + DelElementToolStripMenuItem.ShortcutKeys = Keys.Control | Keys.D; + DelElementToolStripMenuItem.Size = new Size(180, 22); + DelElementToolStripMenuItem.Text = "Удалить"; + DelElementToolStripMenuItem.Click += DelElementToolStripMenuItem_Click; + // + // DocsToolStripMenuItem + // + DocsToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { SimpleDocToolStripMenuItem, TableDocToolStripMenuItem, ChartDocToolStripMenuItem }); + DocsToolStripMenuItem.Name = "DocsToolStripMenuItem"; + DocsToolStripMenuItem.Size = new Size(82, 20); + DocsToolStripMenuItem.Text = "Документы"; + // + // SimpleDocToolStripMenuItem + // + SimpleDocToolStripMenuItem.Name = "SimpleDocToolStripMenuItem"; + SimpleDocToolStripMenuItem.ShortcutKeys = Keys.Control | Keys.S; + SimpleDocToolStripMenuItem.Size = new Size(232, 22); + SimpleDocToolStripMenuItem.Text = "Простой документ"; + SimpleDocToolStripMenuItem.Click += SimpleDocToolStripMenuItem_Click; + // + // TableDocToolStripMenuItem + // + TableDocToolStripMenuItem.Name = "TableDocToolStripMenuItem"; + TableDocToolStripMenuItem.ShortcutKeys = Keys.Control | Keys.T; + TableDocToolStripMenuItem.Size = new Size(232, 22); + TableDocToolStripMenuItem.Text = "Документ с таблицей"; + TableDocToolStripMenuItem.Click += TableDocToolStripMenuItem_Click; + // + // ChartDocToolStripMenuItem + // + ChartDocToolStripMenuItem.Name = "ChartDocToolStripMenuItem"; + ChartDocToolStripMenuItem.ShortcutKeys = Keys.Control | Keys.C; + ChartDocToolStripMenuItem.Size = new Size(232, 22); + ChartDocToolStripMenuItem.Text = "Диаграмма"; + ChartDocToolStripMenuItem.Click += ChartDocToolStripMenuItem_Click; + // + // panelControl + // + panelControl.Dock = DockStyle.Fill; + panelControl.Location = new Point(0, 24); + panelControl.Name = "panelControl"; + panelControl.Size = new Size(800, 426); + panelControl.TabIndex = 1; + // + // FormMain + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(800, 450); + Controls.Add(panelControl); + Controls.Add(menuStrip); + MainMenuStrip = menuStrip; + Name = "FormMain"; + StartPosition = FormStartPosition.CenterScreen; + Text = "Главная форма"; + WindowState = FormWindowState.Maximized; + KeyDown += FormMain_KeyDown; + menuStrip.ResumeLayout(false); + menuStrip.PerformLayout(); + ResumeLayout(false); + 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; + } +} diff --git a/COP/PluginsApp/FormMain.cs b/COP/PluginsApp/FormMain.cs new file mode 100644 index 0000000..1fd4116 --- /dev/null +++ b/COP/PluginsApp/FormMain.cs @@ -0,0 +1,243 @@ +using PluginsConventionLibrary; +using System.Reflection; + +namespace PluginsApp +{ + public partial class FormMain : Form + { + private readonly Dictionary _plugins; + + private string _selectedPlugin; + + public FormMain() + { + InitializeComponent(); + _plugins = LoadPlugins(); + _selectedPlugin = string.Empty; + } + + private Dictionary LoadPlugins() + { + var plugins = new Dictionary(); + string pluginsDir = Path.Combine(Directory.GetParent(Directory.GetCurrentDirectory())!.Parent!.Parent!.FullName, "Plugins"); + if (!Directory.Exists(pluginsDir)) + { + MessageBox.Show($" {pluginsDir} .", "", MessageBoxButtons.OK, MessageBoxIcon.Error); + return plugins; + } + foreach (string dllFile in Directory.EnumerateFiles(pluginsDir, "*.dll", SearchOption.AllDirectories)) + { + try + { + Assembly assembly = Assembly.LoadFrom(dllFile); + Type[] types = assembly.GetTypes(); + foreach (var type in types) + { + if (typeof(IPluginsConvention).IsAssignableFrom(type) && !type.IsInterface && !type.IsAbstract) + { + var plugin = (IPluginsConvention)Activator.CreateInstance(type)!; + plugins.Add(plugin.PluginName, plugin); + CreateToolStripMenuItem(plugin.PluginName); + } + } + } + catch (Exception ex) + { + MessageBox.Show($" {dllFile}: {ex.Message}", "", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + return plugins; + } + + private void CreateToolStripMenuItem(string pluginName) + { + var menuItem = new ToolStripMenuItem(pluginName); + menuItem.Click += (object? sender, EventArgs e) => + { + _selectedPlugin = pluginName; + IPluginsConvention plugin = _plugins![pluginName]; + UserControl userControl = plugin?.GetControl ?? throw new Exception(" "); + 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() + { + using var dialog = new SaveFileDialog + { + Filter = "docx|*.docx" + }; + if (dialog.ShowDialog() == DialogResult.OK) + { + try + { + if (_plugins[_selectedPlugin].CreateSimpleDocument(new PluginsConventionSaveDocument() { FileName = dialog.FileName } )) + { + MessageBox.Show(" ", " ", MessageBoxButtons.OK, MessageBoxIcon.Information); + } + else + { + MessageBox.Show(" ", "", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + catch (Exception ex) + { + MessageBox.Show(" : " + ex.Message, "", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + + private void CreateTableDoc() + { + using var dialog = new SaveFileDialog + { + Filter = "PDF Files|*.pdf" + }; + if (dialog.ShowDialog() == DialogResult.OK) + { + try + { + if (_plugins[_selectedPlugin].CreateTableDocument(new PluginsConventionSaveDocument() { FileName = dialog.FileName })) + { + MessageBox.Show(" ", " ", MessageBoxButtons.OK, MessageBoxIcon.Information); + } + else + { + MessageBox.Show(" ", "", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + catch (Exception ex) + { + MessageBox.Show(" : " + ex.Message, "", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + + private void CreateChartDoc() + { + using var dialog = new SaveFileDialog + { + Filter = "Excel Files|*.xlsx" + }; + if (dialog.ShowDialog() == DialogResult.OK) + { + try + { + if (_plugins[_selectedPlugin].CreateChartDocument(new PluginsConventionSaveDocument() { FileName = dialog.FileName })) + { + MessageBox.Show(" ", " ", MessageBoxButtons.OK, MessageBoxIcon.Information); + } + else + { + MessageBox.Show(" ", "", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + catch (Exception ex) + { + MessageBox.Show(" : " + ex.Message, "", 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(); + } +} \ No newline at end of file diff --git a/COP/PluginsApp/FormMain.resx b/COP/PluginsApp/FormMain.resx new file mode 100644 index 0000000..31084d5 --- /dev/null +++ b/COP/PluginsApp/FormMain.resx @@ -0,0 +1,123 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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 + + \ No newline at end of file diff --git a/COP/PluginsApp/PluginsApp.csproj b/COP/PluginsApp/PluginsApp.csproj new file mode 100644 index 0000000..8482b18 --- /dev/null +++ b/COP/PluginsApp/PluginsApp.csproj @@ -0,0 +1,19 @@ + + + + WinExe + net6.0-windows + enable + true + enable + + + + + + + + + + + \ No newline at end of file diff --git a/COP/PluginsApp/Program.cs b/COP/PluginsApp/Program.cs new file mode 100644 index 0000000..1d6f10e --- /dev/null +++ b/COP/PluginsApp/Program.cs @@ -0,0 +1,17 @@ +namespace PluginsApp +{ + 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 diff --git a/COP/PluginsConventionLibrary/IPluginsConvention.cs b/COP/PluginsConventionLibrary/IPluginsConvention.cs new file mode 100644 index 0000000..dd5ab3d --- /dev/null +++ b/COP/PluginsConventionLibrary/IPluginsConvention.cs @@ -0,0 +1,66 @@ +namespace PluginsConventionLibrary +{ + 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); + } +} diff --git a/COP/PluginsConventionLibrary/PluginsConventionElement.cs b/COP/PluginsConventionLibrary/PluginsConventionElement.cs new file mode 100644 index 0000000..01caf21 --- /dev/null +++ b/COP/PluginsConventionLibrary/PluginsConventionElement.cs @@ -0,0 +1,7 @@ +namespace PluginsConventionLibrary +{ + public class PluginsConventionElement + { + public Guid Id { get; set; } + } +} diff --git a/COP/PluginsConventionLibrary/PluginsConventionLibrary.csproj b/COP/PluginsConventionLibrary/PluginsConventionLibrary.csproj new file mode 100644 index 0000000..060aa1c --- /dev/null +++ b/COP/PluginsConventionLibrary/PluginsConventionLibrary.csproj @@ -0,0 +1,10 @@ + + + + net6.0-windows + enable + true + enable + + + diff --git a/COP/PluginsConventionLibrary/PluginsConventionSaveDocument.cs b/COP/PluginsConventionLibrary/PluginsConventionSaveDocument.cs new file mode 100644 index 0000000..64491eb --- /dev/null +++ b/COP/PluginsConventionLibrary/PluginsConventionSaveDocument.cs @@ -0,0 +1,7 @@ +namespace PluginsConventionLibrary +{ + public class PluginsConventionSaveDocument + { + public string FileName { get; set; } + } +} diff --git a/COP/PortalAccountsView/PluginsConvention.cs b/COP/PortalAccountsView/PluginsConvention.cs new file mode 100644 index 0000000..5f19c46 --- /dev/null +++ b/COP/PortalAccountsView/PluginsConvention.cs @@ -0,0 +1,211 @@ +using ComponentsLibraryNet60.Models; +using ControlsLibraryNet60.Data; +using ControlsLibraryNet60.Models; +using PluginsConventionLibrary; +using PortalAccountsBusinessLogic.BusinessLogics; +using PortalAccountsContracts.BindingModels; +using PortalAccountsContracts.BusinessLogicsContracts; +using PortalAccountsContracts.ViewModels; +using PortalAccountsDatabaseImplement.Implements; +using RodionovLibrary.NonVisualComponents.HelperModels; +using System.Text; + +namespace PortalAccountsView +{ + public class PluginsConvention : IPluginsConvention + { + private readonly IAccountLogic _accountLogic; + private readonly IRoleLogic _roleLogic; + private readonly ControlDataTreeTable _controlDataTreeTable = new(); + private readonly RodionovLibrary.NonVisualComponents.WordLongTextComponent _wordLongTextComponent = new(); + private readonly ComponentsLibraryNet60.DocumentWithTable.ComponentDocumentWithTableMultiHeaderPdf _componentDocumentWithTableMultiHeaderPdf = new(); + private readonly ComponentsLibraryNet60.DocumentWithChart.ComponentDocumentWithChartPieExcel _componentDocumentWithChartPieExcel = new(); + + public PluginsConvention() + { + _accountLogic = new AccountLogic(new AccountStorage()); + _roleLogic = new RoleLogic(new RoleStorage()); + ReloadData(); + } + + public string PluginName => "LabWork3 Plugin"; + + public UserControl GetControl => _controlDataTreeTable; + + public PluginsConventionElement GetElement + { + get + { + var selected = _controlDataTreeTable.GetSelectedObject() + ?? throw new Exception("Не удалось получить выбранный элемент"); + return new PluginsConventionAccount() + { + Id = IntToGuid(selected.Id), + Login = selected.Login, + Warnings = selected.Warnings, + RoleName = selected.RoleName, + Rating = selected.OutputRating + }; + } + } + + public Form GetForm(PluginsConventionElement element) + { + var formAccount = new FormAccount(_accountLogic, _roleLogic); + if (element != null) + { + formAccount.Id = element.Id.GetHashCode(); + } + return formAccount; + } + + public Form GetThesaurus() + { + return new FormRoles(_roleLogic); + } + + public bool DeleteElement(PluginsConventionElement element) + { + return _accountLogic.Delete( + new AccountBindingModel { Id = element.Id.GetHashCode() } + ); + } + + public void ReloadData() + { + try + { + var accounts = _accountLogic.ReadList(null) ?? throw new Exception("Не удалось получить список аккаунтов"); + + _controlDataTreeTable.Clear(); + + var nodeNames = new Queue(); + nodeNames.Enqueue("RoleName"); + nodeNames.Enqueue("OutputRating"); + nodeNames.Enqueue("Id"); + nodeNames.Enqueue("Login"); + _controlDataTreeTable.LoadConfig(new DataTreeNodeConfig { NodeNames = nodeNames }); + + foreach (var account in accounts) + { + account.OutputRating = account.Rating?.ToString() ?? "Отсутствует"; + } + _controlDataTreeTable.AddTable(accounts); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + public bool CreateSimpleDocument(PluginsConventionSaveDocument saveDocument) + { + try + { + var accounts = _accountLogic.ReadList(null) ?? throw new Exception("Не удалось получить список аккаунтов"); + List paragraphs = new(); + foreach (var account in accounts) + { + if (account.Rating == null) + { + paragraphs.Add($"{account.Login}: {(string.IsNullOrWhiteSpace(account.Warnings) ? "Предупреждения отсутствуют" : account.Warnings)}"); + } + } + _wordLongTextComponent.CreateWordText(new WordLongTextInfo() + { + FileName = saveDocument.FileName, + Title = "Аккаунты без рейтинга", + Paragraphs = paragraphs.ToArray() + }); + MessageBox.Show("Готово!"); + return true; + } + catch (Exception ex) + { + MessageBox.Show("Произошла ошибка: " + ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return false; + } + } + + public bool CreateTableDocument(PluginsConventionSaveDocument saveDocument) + { + Encoding.RegisterProvider(CodePagesEncodingProvider.Instance); + try + { + var accounts = _accountLogic.ReadList(null) ?? throw new Exception("Не удалось получить список аккаунтов"); + foreach (var account in accounts) + { + account.OutputRating = account.Rating?.ToString() ?? "нет"; + } + _componentDocumentWithTableMultiHeaderPdf.CreateDoc(new ComponentDocumentWithTableHeaderDataConfig + { + FilePath = saveDocument.FileName, + Header = "Аккаунты портала", + ColumnsRowsWidth = new List<(int, int)> { (10, 10), (10, 10), (10, 10), (10, 10) }, // ширина столбцов и высота строк + Headers = new List<(int ColumnIndex, int RowIndex, string Header, string PropertyName)> + { + (0, 0, "Id", "Id"), + (1, 0, "Логин", "Login"), + (2, 0, "Роль", "RoleName"), + (3, 0, "Рейтинг", "OutputRating") + }, + Data = accounts.OrderBy(x => x.Id).ToList() + }); + MessageBox.Show("Готово!"); + return true; + } + catch (Exception ex) + { + MessageBox.Show("Произошла ошибка: " + ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return false; + } + } + + public bool CreateChartDocument(PluginsConventionSaveDocument saveDocument) + { + try + { + var accounts = _accountLogic.ReadList(null) ?? throw new Exception("Не удалось получить список аккаунтов"); + var roleMapping = new List(); + var data = new Dictionary> + { + { + "Аккаунты", + accounts + .Where(x => x.Rating != null) + .GroupBy(x => x.RoleName) + .Select((group, index) => + { + roleMapping.Add($"{group.Key} - {index + 1}"); + + return (Date: index + 1, Value: (double)group.Count()); + }) + .ToList() + } + }; + _componentDocumentWithChartPieExcel.CreateDoc(new ComponentDocumentWithChartConfig + { + FilePath = saveDocument.FileName, + Header = $"Аккаунты с рейтингом по ролям ({string.Join(", ", roleMapping)})", + ChartTitle = "Круговая диаграмма", + LegendLocation = Location.Bottom, + Data = data + }); + MessageBox.Show("Готово!"); + return true; + } + catch (Exception ex) + { + MessageBox.Show("Произошла ошибка: " + ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return false; + } + } + + private Guid IntToGuid(int value) + { + byte[] bytes = new byte[16]; + BitConverter.GetBytes(value).CopyTo(bytes, 0); + return new Guid(bytes); + } + } +} diff --git a/COP/PortalAccountsView/PluginsConventionAccount.cs b/COP/PortalAccountsView/PluginsConventionAccount.cs new file mode 100644 index 0000000..bed594a --- /dev/null +++ b/COP/PortalAccountsView/PluginsConventionAccount.cs @@ -0,0 +1,15 @@ +using PluginsConventionLibrary; + +namespace PortalAccountsView +{ + public class PluginsConventionAccount : PluginsConventionElement + { + public string Login { get; set; } = string.Empty; + + public string? Warnings { get; set; } + + public string RoleName { get; set; } = string.Empty; + + public string Rating { get; set; } = string.Empty; + } +} diff --git a/COP/PortalAccountsView/PortalAccountsView.csproj b/COP/PortalAccountsView/PortalAccountsView.csproj index cd605b7..bdaaf3a 100644 --- a/COP/PortalAccountsView/PortalAccountsView.csproj +++ b/COP/PortalAccountsView/PortalAccountsView.csproj @@ -20,6 +20,7 @@ +