From a9cace146fbfe0bd6f3ba35eef69e1034ed46868 Mon Sep 17 00:00:00 2001 From: bulatova_karina Date: Thu, 21 Nov 2024 11:52:51 +0400 Subject: [PATCH] =?UTF-8?q?4=D0=B0=D1=8F=20=D0=BB=D0=B0=D0=B1=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 2 + COP/AppByPlugins/AppByPlugins.csproj | 28 +++ COP/AppByPlugins/FormMain.Designer.cs | 173 ++++++++++++++ COP/AppByPlugins/FormMain.cs | 225 ++++++++++++++++++ COP/AppByPlugins/FormMain.resx | 120 ++++++++++ COP/AppByPlugins/Program.cs | 17 ++ COP/COP.sln | 16 +- .../IPluginsConvention.cs | 64 +++++ .../PluginsConventionElement.cs | 13 + .../PluginsConventionLibrary.csproj | 10 + .../PluginsConventionSaveDocument.cs | 13 + COP/WinForms/PluginsConvention.cs | 200 ++++++++++++++++ COP/WinForms/WinForms.csproj | 9 + 13 files changed, 888 insertions(+), 2 deletions(-) create mode 100644 COP/AppByPlugins/AppByPlugins.csproj create mode 100644 COP/AppByPlugins/FormMain.Designer.cs create mode 100644 COP/AppByPlugins/FormMain.cs create mode 100644 COP/AppByPlugins/FormMain.resx create mode 100644 COP/AppByPlugins/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/WinForms/PluginsConvention.cs diff --git a/.gitignore b/.gitignore index ca1c7a3..99b8a56 100644 --- a/.gitignore +++ b/.gitignore @@ -4,6 +4,8 @@ ## ## Get latest from https://github.com/github/gitignore/blob/main/VisualStudio.gitignore +*.dll + # User-specific files *.rsuser *.suo diff --git a/COP/AppByPlugins/AppByPlugins.csproj b/COP/AppByPlugins/AppByPlugins.csproj new file mode 100644 index 0000000..6fd083a --- /dev/null +++ b/COP/AppByPlugins/AppByPlugins.csproj @@ -0,0 +1,28 @@ + + + + WinExe + net6.0-windows + enable + true + enable + + + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + + + + + + + + + + + \ No newline at end of file diff --git a/COP/AppByPlugins/FormMain.Designer.cs b/COP/AppByPlugins/FormMain.Designer.cs new file mode 100644 index 0000000..32d52a8 --- /dev/null +++ b/COP/AppByPlugins/FormMain.Designer.cs @@ -0,0 +1,173 @@ +namespace AppByPlugins +{ + 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(233, 22); + SimpleDocToolStripMenuItem.Text = "Простой документ"; + SimpleDocToolStripMenuItem.Click += SimpleDocToolStripMenuItem_Click; + // + // TableDocToolStripMenuItem + // + TableDocToolStripMenuItem.Name = "TableDocToolStripMenuItem"; + TableDocToolStripMenuItem.ShortcutKeys = Keys.Control | Keys.T; + TableDocToolStripMenuItem.Size = new Size(233, 22); + TableDocToolStripMenuItem.Text = "Документ с таблицой"; + TableDocToolStripMenuItem.Click += TableDocToolStripMenuItem_Click; + // + // ChartDocToolStripMenuItem + // + ChartDocToolStripMenuItem.Name = "ChartDocToolStripMenuItem"; + ChartDocToolStripMenuItem.ShortcutKeys = Keys.Control | Keys.C; + ChartDocToolStripMenuItem.Size = new Size(233, 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; + } +} \ No newline at end of file diff --git a/COP/AppByPlugins/FormMain.cs b/COP/AppByPlugins/FormMain.cs new file mode 100644 index 0000000..6673cae --- /dev/null +++ b/COP/AppByPlugins/FormMain.cs @@ -0,0 +1,225 @@ +using PluginsConventionLibrary; +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 AppByPlugins +{ + 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 = Directory.GetParent(Directory.GetCurrentDirectory())!.Parent!.Parent!.Parent!.FullName + "\\Plugins"; + + string[] dllFiles = Directory.GetFiles(pluginsDir, "*.dll", SearchOption.AllDirectories); + + foreach (string dllFile in dllFiles) + { + try + { + + Assembly assembly = Assembly.LoadFrom(dllFile); + Type[] types = assembly.GetTypes(); + + foreach (var type in types) + { + + if (typeof(IPluginsConvention).IsAssignableFrom(type) && !type.IsInterface) + { + var plugin = (IPluginsConvention)Activator.CreateInstance(type)!; + plugins.Add(plugin.PluginName, plugin); + CreateMenuItem(plugin.PluginName); + } + } + } + catch (Exception ex) + { + Console.WriteLine($"Ошибка при загрузке сборки {dllFile}: {ex.Message}"); + } + } + + return plugins; + } + + + + private void CreateMenuItem(string pluginName) + { + ToolStripMenuItem menuItem = new(pluginName); + menuItem.Click += (object? sender, EventArgs e) => + { + UserControl userControl = _plugins[pluginName].GetControl; + if (userControl != null) + { + panelControl.Controls.Clear(); + userControl.Dock = DockStyle.Fill; + _plugins[pluginName].ReloadData(); + _selectedPlugin = pluginName; + 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() + { + Filter = "Word Files|*.docx" + }; + if (saveFileDialog.ShowDialog() == DialogResult.OK) + { + _plugins[_selectedPlugin].CreateSimpleDocument(new PluginsConventionSaveDocument() { FileName = saveFileDialog.FileName }); + + } + } + private void CreateTableDoc() + { + SaveFileDialog saveFileDialog = new() + { + Filter = "PDF Files|*.pdf" + }; + if (saveFileDialog.ShowDialog() == DialogResult.OK) + { + _plugins[_selectedPlugin].CreateTableDocument(new PluginsConventionSaveDocument() { FileName = saveFileDialog.FileName }); + + } + } + private void CreateChartDoc() + { + SaveFileDialog saveFileDialog = new() + { + Filter = "Excel Files|*.xlsx" + }; + if (saveFileDialog.ShowDialog() == DialogResult.OK) + { + _plugins[_selectedPlugin].CreateChartDocument(new PluginsConventionSaveDocument() { FileName = saveFileDialog.FileName }); + } + } + + 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/AppByPlugins/FormMain.resx b/COP/AppByPlugins/FormMain.resx new file mode 100644 index 0000000..1af7de1 --- /dev/null +++ b/COP/AppByPlugins/FormMain.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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/COP/AppByPlugins/Program.cs b/COP/AppByPlugins/Program.cs new file mode 100644 index 0000000..a783345 --- /dev/null +++ b/COP/AppByPlugins/Program.cs @@ -0,0 +1,17 @@ +namespace AppByPlugins +{ + 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/COP.sln b/COP/COP.sln index 6883e86..ae251ed 100644 --- a/COP/COP.sln +++ b/COP/COP.sln @@ -13,9 +13,13 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ClientsContracts", "Clients EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ClientsDatabaseImplement", "ClientsDatabaseImplement\ClientsDatabaseImplement.csproj", "{725F3378-1474-4195-9F76-B9C98690CC76}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BulatovaComponents", "BulatovaComponents\BulatovaComponents.csproj", "{A8DDA2DE-1B0C-4870-BA0B-BDE84B705B3E}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BulatovaComponents", "BulatovaComponents\BulatovaComponents.csproj", "{A8DDA2DE-1B0C-4870-BA0B-BDE84B705B3E}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ClientsDataModels", "ClientsDataModels\ClientsDataModels.csproj", "{83105892-317C-4442-B064-E489D2CFE39D}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ClientsDataModels", "ClientsDataModels\ClientsDataModels.csproj", "{83105892-317C-4442-B064-E489D2CFE39D}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PluginsConventionLibrary", "PluginsConventionLibrary\PluginsConventionLibrary.csproj", "{21F2683A-8624-4C9B-A765-2E7CCA8D8BBD}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AppByPlugins", "AppByPlugins\AppByPlugins.csproj", "{586FCB30-AC9A-4229-B7F7-3FB2ADF581B6}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -51,6 +55,14 @@ Global {83105892-317C-4442-B064-E489D2CFE39D}.Debug|Any CPU.Build.0 = Debug|Any CPU {83105892-317C-4442-B064-E489D2CFE39D}.Release|Any CPU.ActiveCfg = Release|Any CPU {83105892-317C-4442-B064-E489D2CFE39D}.Release|Any CPU.Build.0 = Release|Any CPU + {21F2683A-8624-4C9B-A765-2E7CCA8D8BBD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {21F2683A-8624-4C9B-A765-2E7CCA8D8BBD}.Debug|Any CPU.Build.0 = Debug|Any CPU + {21F2683A-8624-4C9B-A765-2E7CCA8D8BBD}.Release|Any CPU.ActiveCfg = Release|Any CPU + {21F2683A-8624-4C9B-A765-2E7CCA8D8BBD}.Release|Any CPU.Build.0 = Release|Any CPU + {586FCB30-AC9A-4229-B7F7-3FB2ADF581B6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {586FCB30-AC9A-4229-B7F7-3FB2ADF581B6}.Debug|Any CPU.Build.0 = Debug|Any CPU + {586FCB30-AC9A-4229-B7F7-3FB2ADF581B6}.Release|Any CPU.ActiveCfg = Release|Any CPU + {586FCB30-AC9A-4229-B7F7-3FB2ADF581B6}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/COP/PluginsConventionLibrary/IPluginsConvention.cs b/COP/PluginsConventionLibrary/IPluginsConvention.cs new file mode 100644 index 0000000..0f9f6c2 --- /dev/null +++ b/COP/PluginsConventionLibrary/IPluginsConvention.cs @@ -0,0 +1,64 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +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); + } +} \ No newline at end of file diff --git a/COP/PluginsConventionLibrary/PluginsConventionElement.cs b/COP/PluginsConventionLibrary/PluginsConventionElement.cs new file mode 100644 index 0000000..43fe051 --- /dev/null +++ b/COP/PluginsConventionLibrary/PluginsConventionElement.cs @@ -0,0 +1,13 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace PluginsConventionLibrary +{ + public class PluginsConventionElement + { + public Guid Id { get; set; } + } +} \ No newline at end of file diff --git a/COP/PluginsConventionLibrary/PluginsConventionLibrary.csproj b/COP/PluginsConventionLibrary/PluginsConventionLibrary.csproj new file mode 100644 index 0000000..7be9540 --- /dev/null +++ b/COP/PluginsConventionLibrary/PluginsConventionLibrary.csproj @@ -0,0 +1,10 @@ + + + + net6.0-windows + enable + enable + true + + + \ No newline at end of file diff --git a/COP/PluginsConventionLibrary/PluginsConventionSaveDocument.cs b/COP/PluginsConventionLibrary/PluginsConventionSaveDocument.cs new file mode 100644 index 0000000..7dc0eb4 --- /dev/null +++ b/COP/PluginsConventionLibrary/PluginsConventionSaveDocument.cs @@ -0,0 +1,13 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace PluginsConventionLibrary +{ + public class PluginsConventionSaveDocument + { + public string FileName { get; set; } + } +} \ No newline at end of file diff --git a/COP/WinForms/PluginsConvention.cs b/COP/WinForms/PluginsConvention.cs new file mode 100644 index 0000000..dd6676d --- /dev/null +++ b/COP/WinForms/PluginsConvention.cs @@ -0,0 +1,200 @@ +using ChubykinaComponents.Components; +using ChubykinaComponents.LogicalComponents; +using BulatovaComponents.NonVisualComponents; +using ComponentsLibraryNet60.DocumentWithChart; +using ComponentsLibraryNet60.DocumentWithTable; +using ComponentsLibraryNet60.Models; +using ControlsLibraryNet60.Data; +using ControlsLibraryNet60.Models; +using PluginsConventionLibrary; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; +using ClientsContracts.BusinessLogicContracts; +using ClientsContracts.ViewModels; +using ClientBusinessLogic.BusinessLogics; +using ClientsDatabaseImplement.Implements; + +namespace WinForms +{ + public class PluginsConvention : IPluginsConvention + { + private readonly IClientLogic _clientLogic; + private readonly IStatusLogic _statusLogic; + private readonly UserTreeView _myTreeView; + private readonly WordLongTextComponent wordLongTextComponent; + private readonly ExcelDiagramComponent excelDiagramComponent; + private readonly ComponentDocumentWithTableMultiHeaderPdf componentDocumentWithTableMultiHeaderPdf; + public string PluginName { get; set; } = "LabWork_03_plugin"; + + public UserControl GetControl + { + get { return _myTreeView; } + } + + public PluginsConvention() + { + _clientLogic = new ClientLogic(new ClientStorage()); + _statusLogic = new StatusLogic(new StatusStorage()); + wordLongTextComponent = new(); + excelDiagramComponent = new(); + componentDocumentWithTableMultiHeaderPdf = new(); + _myTreeView = new(); + } + + public PluginsConventionElement GetElement + { + get + { + int Id = _myTreeView.getSelecetedNodeValue()!.Id; + byte[] bytes = new byte[16]; + BitConverter.GetBytes(Id).CopyTo(bytes, 0); + Guid guid = new Guid(bytes); + return new PluginsConventionElement() { Id = guid }; + } + } + + public Form GetForm(PluginsConventionElement element) + { + if (element == null) + { + return new FormClient(_clientLogic, _statusLogic); + } + else + { + FormClient form = new FormClient(_clientLogic, _statusLogic); + form.Id = element.Id.GetHashCode(); + return form; + } + } + + public Form GetThesaurus() + { + return new FormStatus(_statusLogic); + } + + public bool DeleteElement(PluginsConventionElement element) + { + _clientLogic.Delete( + new ClientsContracts.BindingModels.ClientBindingModel { Id = element.Id.GetHashCode() } + ); + return true; + } + + public void ReloadData() + { + try + { + var clients = _clientLogic.ReadList(null); + if (clients != null) + { + _myTreeView.clear(); + + _myTreeView.setHierarchy(new List<(string, bool)> { ("StatusName", false), ("ViewAmount", false), ("Id", true), ("Name", true) }); + + foreach (var client in clients) + { + if (!client.Amount.HasValue) + { + client.ViewAmount = "нет покупок"; + } + else + { + client.ViewAmount = client.Amount.Value.ToString(); + } + } + + _myTreeView.addItems(clients); + } + } + catch (Exception ex) + { + MessageBox.Show( + ex.Message, + "Ошибка", + MessageBoxButtons.OK, + MessageBoxIcon.Error + ); + } + } + + public bool CreateSimpleDocument(PluginsConventionSaveDocument saveDocument) + { + List paragraphs = new List(); + foreach (var client in _clientLogic.ReadList(null)) + { + if (client.Amount == null) + { + paragraphs.Add(client.Name + ": " + client.Reviews); + } + } + string path = saveDocument.FileName; + wordLongTextComponent.createWithLongText(new WordLongTextInfo(path, "Аккаунты без суммы покупок", paragraphs.ToArray())); + MessageBox.Show("Документ создан"); + return true; + } + + public bool CreateTableDocument(PluginsConventionSaveDocument saveDocument) + { + Encoding.RegisterProvider(CodePagesEncodingProvider.Instance); + List paragraphs = new List(); + string path = saveDocument.FileName; + var clients = _clientLogic.ReadList(null); + foreach (var client in clients) + { + if (!client.Amount.HasValue) + { + client.DocAmount = "нет"; + } + else + { + client.DocAmount = client.Amount.Value.ToString(); + } + } + ComponentDocumentWithTableHeaderDataConfig config = new ComponentsLibraryNet60.Models.ComponentDocumentWithTableHeaderDataConfig + { + Data = clients, + UseUnion = false, + Header = "Аккаунты", + ColumnsRowsDataCount = (4, 1), + Headers = new List<(int ColumnIndex, int RowIndex, string Header, string PropertyName)> + { + (0, 0, "Id", "Id"), + (1, 0, "ФИО", "Name"), + (2, 0, "Статус", "StatusName"), + (3, 0, "Сумма покупок", "DocAmount") + }, + ColumnsRowsWidth = new List<(int Column, int Row)> + { + (10, 10), + (10, 10), + (10, 10), + (10, 10) + }, + ColumnUnion = new List<(int StartIndex, int Count)>(), + FilePath = path + }; + componentDocumentWithTableMultiHeaderPdf.CreateDoc(config); + MessageBox.Show("Документ создан"); + return true; + } + + public bool CreateChartDocument(PluginsConventionSaveDocument saveDocument) + { + List paragraphs = new List(); + string path = saveDocument.FileName; + var data = _clientLogic.ReadList(null).Where(x => x.Amount == null).GroupBy(x => x.StatusName).Select(x => new + { + StatusName = x.Key, + StatusCount = x.Count(), + }).ToList(); + excelDiagramComponent.createWithDiagram(path, "Статус без суммы покупок", "Статус без суммы покупок", ChubykinaComponents.LogicalComponents.DiagramLegendEnum.BottomRight, + data, "StatusName", "StatusCount"); + MessageBox.Show("Документ создан"); + return true; + } + } +} \ No newline at end of file diff --git a/COP/WinForms/WinForms.csproj b/COP/WinForms/WinForms.csproj index 8710ca1..676d7de 100644 --- a/COP/WinForms/WinForms.csproj +++ b/COP/WinForms/WinForms.csproj @@ -19,10 +19,19 @@ + + + + + + + + + \ No newline at end of file