From a4e1485bc6005b7fe5ab60c17f190df47d658f37 Mon Sep 17 00:00:00 2001 From: sardq Date: Wed, 13 Nov 2024 16:00:48 +0400 Subject: [PATCH] 4 lab --- ClientRecordView/ClientRecordView.csproj | 1 + ClientRecordView/FormMain.Designer.cs | 4 +- ClientRecordView/FormMain.cs | 6 +- ClientRecordView/PluginsConvention.cs | 216 ++++++++++++++++ ClientRecordView/PluginsConventionClient.cs | 13 + PluginConventionLibrary/IPluginConvention.cs | 59 +++++ .../PluginConventionElement.cs | 7 + .../PluginConventionLibrary.csproj | 10 + .../PluginsConventionSaveDocument.cs | 7 + WinForms.sln | 22 +- WinForms/FormComponents.Designer.cs | 4 +- .../NonVisualComponents/WordText.Designer.cs | 2 +- .../NonVisualComponents/WordText.cs | 2 +- .../VisualComponent/EmailTextBox.Designer.cs | 19 +- WindowsFormAppPlugin/FormMain.Designer.cs | 188 ++++++++++++++ WindowsFormAppPlugin/FormMain.cs | 235 ++++++++++++++++++ WindowsFormAppPlugin/FormMain.resx | 120 +++++++++ WindowsFormAppPlugin/Program.cs | 17 ++ .../WindowsFormAppPlugin.csproj | 25 ++ 19 files changed, 928 insertions(+), 29 deletions(-) create mode 100644 ClientRecordView/PluginsConvention.cs create mode 100644 ClientRecordView/PluginsConventionClient.cs create mode 100644 PluginConventionLibrary/IPluginConvention.cs create mode 100644 PluginConventionLibrary/PluginConventionElement.cs create mode 100644 PluginConventionLibrary/PluginConventionLibrary.csproj create mode 100644 PluginConventionLibrary/PluginsConventionSaveDocument.cs create mode 100644 WindowsFormAppPlugin/FormMain.Designer.cs create mode 100644 WindowsFormAppPlugin/FormMain.cs create mode 100644 WindowsFormAppPlugin/FormMain.resx create mode 100644 WindowsFormAppPlugin/Program.cs create mode 100644 WindowsFormAppPlugin/WindowsFormAppPlugin.csproj diff --git a/ClientRecordView/ClientRecordView.csproj b/ClientRecordView/ClientRecordView.csproj index c14c906..5b19b72 100644 --- a/ClientRecordView/ClientRecordView.csproj +++ b/ClientRecordView/ClientRecordView.csproj @@ -25,6 +25,7 @@ + diff --git a/ClientRecordView/FormMain.Designer.cs b/ClientRecordView/FormMain.Designer.cs index dbb9639..3190782 100644 --- a/ClientRecordView/FormMain.Designer.cs +++ b/ClientRecordView/FormMain.Designer.cs @@ -40,7 +40,7 @@ this.отчетСДиаграммойToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.статусыToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.componentDocumentWithChartPieExcel = new ComponentsLibraryNet60.DocumentWithChart.ComponentDocumentWithChartPieExcel(this.components); - this.wordText = new WinFormsLibrary.WordText(this.components); + this.wordText = new WinFormsLibrary.NonVisualComponents.WordText(this.components); this.controlDataTreeTable = new ControlsLibraryNet60.Data.ControlDataTreeTable(); this.userControlConfigurableTableDocument = new Components.Nonvisual.UserControlConfigurableTableDocument(this.components); this.menuStrip.SuspendLayout(); @@ -174,7 +174,7 @@ private ToolStripMenuItem отчетСДиаграммойToolStripMenuItem; private ToolStripMenuItem статусыToolStripMenuItem; private ComponentsLibraryNet60.DocumentWithChart.ComponentDocumentWithChartPieExcel componentDocumentWithChartPieExcel; - private WinFormsLibrary.WordText wordText; + private WinFormsLibrary.NonVisualComponents.WordText wordText; private ControlsLibraryNet60.Data.ControlDataTreeTable controlDataTreeTable; private Components.Nonvisual.UserControlConfigurableTableDocument userControlConfigurableTableDocument; } diff --git a/ClientRecordView/FormMain.cs b/ClientRecordView/FormMain.cs index eb20afb..bdda502 100644 --- a/ClientRecordView/FormMain.cs +++ b/ClientRecordView/FormMain.cs @@ -129,10 +129,10 @@ namespace ClientRecordView { try { - var clients = _logic.ReadList(null) ?? throw new Exception("Не удалось получить список аккаунтов"); - foreach (var account in clients) + var clients = _logic.ReadList(null) ?? throw new Exception("Не удалось получить список клиентов"); + foreach (var client in clients) { - account.AmountString = account.Amount?.ToString() ?? "нет"; + client.AmountString = client.Amount?.ToString() ?? "нет"; } userControlConfigurableTableDocument.SaveToDocument( dialog.FileName, diff --git a/ClientRecordView/PluginsConvention.cs b/ClientRecordView/PluginsConvention.cs new file mode 100644 index 0000000..c40300d --- /dev/null +++ b/ClientRecordView/PluginsConvention.cs @@ -0,0 +1,216 @@ +using ClientRecordBuisinessLogic.BuisinessLogic; +using ClientRecordContracts.BindingModels; +using ClientRecordContracts.BusinessLogicContracts; +using ClientRecordContracts.ViewModels; +using ClientRecordDatabaseImplement.Implements; +using Components.Nonvisual; +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 WinFormsLibrary.NonVisualComponents.Helpers; +using static System.Windows.Forms.VisualStyles.VisualStyleElement.Window; + +namespace ClientRecordView +{ + public class PluginsConvention : IPluginsConvention + { + private readonly IClientLogic _clientLogic; + + private readonly IStatusLogic _statusLogic; + + private readonly ControlDataTreeTable _controlDataTreeTable = new(); + + private readonly WinFormsLibrary.NonVisualComponents.WordText _wordText = new(); + + private readonly Components.Nonvisual.UserControlConfigurableTableDocument _componentDocumentWithTableMultiHeaderPdf = new(); + + private readonly ComponentsLibraryNet60.DocumentWithChart.ComponentDocumentWithChartPieExcel _componentDocumentWithChartPieExcel = new(); + + public PluginsConvention() + { + _clientLogic = new ClientLogic(new ClientStorage()); + _statusLogic = new StatusLogic(new StatusStorage()); + ReloadData(); + } + + public string PluginName => "LabWork3 Plugin"; + + public UserControl GetControl => _controlDataTreeTable; + + public PluginsConventionElement GetElement + { + get + { + var selected = _controlDataTreeTable.GetSelectedObject() + ?? throw new Exception("Не удалось получить выбранный элемент"); + return new PluginsConventionClient() + { + Id = IntToGuid(selected.Id), + ClientFIO= selected.ClientFIO, + Amount= selected.AmountString, + Reviews= selected.Reviews, + Status= selected.Status, + }; + } + } + + public Form GetForm(PluginsConventionElement element) + { + var formClient = new FormClient(_clientLogic, _statusLogic); + if (element != null) + { + formClient.Id = element.Id.GetHashCode(); + } + return formClient; + } + public Form GetThesaurus() + { + return new FormStatuses(_statusLogic); + } + + public bool DeleteElement(PluginsConventionElement element) + { + return _clientLogic.Delete( + new ClientBindingModel { Id = element.Id.GetHashCode() } + ); + } + + public void ReloadData() + { + try + { + var clients = _clientLogic.ReadList(null) ?? throw new Exception("Не удалось получить список аккаунтов"); + + _controlDataTreeTable.Clear(); + + var nodeNames = new Queue(); + nodeNames.Enqueue("Status"); + nodeNames.Enqueue("AmountString"); + nodeNames.Enqueue("Id"); + nodeNames.Enqueue("ClientFIO"); + _controlDataTreeTable.LoadConfig(new DataTreeNodeConfig { NodeNames = nodeNames }); + + foreach (var client in clients) + { + client.AmountString = client.Amount?.ToString() ?? "Нет"; + } + _controlDataTreeTable.AddTable(clients); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + public bool CreateSimpleDocument(PluginsConventionSaveDocument saveDocument) + { + try + { + var clients = _clientLogic.ReadList(null) ?? throw new Exception("Не удалось получить список аккаунтов"); + List paragraphs = new(); + foreach (var client in clients) + { + if (client.Amount != null) + { + paragraphs.Add($"{client.ClientFIO}: {(string.IsNullOrWhiteSpace(client.Reviews) ? "Отзывы отсутствуют" : client.Reviews)}"); + } + } + _wordText.CreateWordText(new LongWordInfo() + { + Path = saveDocument.FileName, + Title = "Клиенты с покупками", + Paragraphs = paragraphs.ToArray() + }); + return true; + } + catch (Exception) + { + return false; + } + } + + public bool CreateTableDocument(PluginsConventionSaveDocument saveDocument) + { + Encoding.RegisterProvider(CodePagesEncodingProvider.Instance); + try + { + var clients = _clientLogic.ReadList(null) ?? throw new Exception("Не удалось получить список клиентов"); + foreach (var client in clients) + { + client.AmountString = client.Amount?.ToString() ?? "нет"; + } + _componentDocumentWithTableMultiHeaderPdf.SaveToDocument( + saveDocument.FileName, + "Учет клиентов", + new List<(double, string Header, string PropertyName)> + { + (1, "Id", "Id"), + (3, "ФИО", "ClientFIO"), + (2, "Статус", "Status"), + (3, "Сумма", "AmountString") + }, + 2, + 2, + clients.OrderBy(x => x.Id).ToList() + ); + return true; + } + catch (Exception) + { + return false; + } + } + + public bool CreateChartDocument(PluginsConventionSaveDocument saveDocument) + { + try + { + var clients = _clientLogic.ReadList(null) ?? throw new Exception("Не удалось получить список клиентов"); + var roleMapping = new List(); + var data = new Dictionary> + { + { + "Клиенты", + clients + .Where(x => x.Amount != null) + .GroupBy(x => x.Status) + .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 + }); + return true; + } + catch (Exception) + { + 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/ClientRecordView/PluginsConventionClient.cs b/ClientRecordView/PluginsConventionClient.cs new file mode 100644 index 0000000..bdd9e71 --- /dev/null +++ b/ClientRecordView/PluginsConventionClient.cs @@ -0,0 +1,13 @@ +using PluginsConventionLibrary; + +namespace ClientRecordView +{ + internal class PluginsConventionClient : PluginsConventionElement + { + public string? Reviews { get; set; } + public string ClientFIO { get; set; } = string.Empty; + public string? Amount { get; set; } + public string Status { get; set; } = string.Empty; + + } +} diff --git a/PluginConventionLibrary/IPluginConvention.cs b/PluginConventionLibrary/IPluginConvention.cs new file mode 100644 index 0000000..3e6401f --- /dev/null +++ b/PluginConventionLibrary/IPluginConvention.cs @@ -0,0 +1,59 @@ +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/PluginConventionLibrary/PluginConventionElement.cs b/PluginConventionLibrary/PluginConventionElement.cs new file mode 100644 index 0000000..7342dfc --- /dev/null +++ b/PluginConventionLibrary/PluginConventionElement.cs @@ -0,0 +1,7 @@ +namespace PluginsConventionLibrary +{ + public class PluginsConventionElement + { + public Guid Id { get; set; } + } +} diff --git a/PluginConventionLibrary/PluginConventionLibrary.csproj b/PluginConventionLibrary/PluginConventionLibrary.csproj new file mode 100644 index 0000000..060aa1c --- /dev/null +++ b/PluginConventionLibrary/PluginConventionLibrary.csproj @@ -0,0 +1,10 @@ + + + + net6.0-windows + enable + true + enable + + + diff --git a/PluginConventionLibrary/PluginsConventionSaveDocument.cs b/PluginConventionLibrary/PluginsConventionSaveDocument.cs new file mode 100644 index 0000000..3af0f93 --- /dev/null +++ b/PluginConventionLibrary/PluginsConventionSaveDocument.cs @@ -0,0 +1,7 @@ +namespace PluginsConventionLibrary +{ + public class PluginsConventionSaveDocument + { + public string FileName { get; set; } + } +} diff --git a/WinForms.sln b/WinForms.sln index ccf180a..ca16812 100644 --- a/WinForms.sln +++ b/WinForms.sln @@ -5,18 +5,22 @@ VisualStudioVersion = 17.4.33110.190 MinimumVisualStudioVersion = 10.0.40219.1 Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "WinFormsLibraryRazubaev", "WinFormsLibrary\WinFormsLibraryRazubaev.csproj", "{FA2C000C-0815-44C4-BBA7-FB37C33DE121}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ClientRecordDataModels", "ClientRecordDataModels\ClientRecordDataModels.csproj", "{A7D71AAC-2AEE-4878-81DE-72429FBBA93B}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ClientRecordDataModels", "ClientRecordDataModels\ClientRecordDataModels.csproj", "{A7D71AAC-2AEE-4878-81DE-72429FBBA93B}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ClientRecordContracts", "ClientRecordContracts\ClientRecordContracts.csproj", "{B641C70B-17E3-454A-8749-E8D54928E733}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ClientRecordContracts", "ClientRecordContracts\ClientRecordContracts.csproj", "{B641C70B-17E3-454A-8749-E8D54928E733}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ClientRecordBuisinessLogic", "ClientRecordBuisinessLogic\ClientRecordBuisinessLogic.csproj", "{56768B0F-B9C4-48E5-AAC4-E82514B64BD8}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ClientRecordBuisinessLogic", "ClientRecordBuisinessLogic\ClientRecordBuisinessLogic.csproj", "{56768B0F-B9C4-48E5-AAC4-E82514B64BD8}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ClientRecordDatabaseImplement", "ClientRecordDatabaseImplement\ClientRecordDatabaseImplement.csproj", "{3272666F-969A-4350-8A71-C70CF2F13527}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ClientRecordDatabaseImplement", "ClientRecordDatabaseImplement\ClientRecordDatabaseImplement.csproj", "{3272666F-969A-4350-8A71-C70CF2F13527}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ClientRecordView", "ClientRecordView\ClientRecordView.csproj", "{F6A250F2-C027-4DA9-AABC-3C69C153F58B}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ClientRecordView", "ClientRecordView\ClientRecordView.csproj", "{F6A250F2-C027-4DA9-AABC-3C69C153F58B}" EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "WinForms", "WinForms\WinForms.csproj", "{CA2C31AC-090D-45CB-B6F2-292B8F823438}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PluginConventionLibrary", "PluginConventionLibrary\PluginConventionLibrary.csproj", "{EEF969D3-121B-48D2-B88D-CC2F5DD42A4A}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WindowsFormAppPlugin", "WindowsFormAppPlugin\WindowsFormAppPlugin.csproj", "{967D9E94-166F-47B5-8C9B-61AE9961C491}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -51,6 +55,14 @@ Global {CA2C31AC-090D-45CB-B6F2-292B8F823438}.Debug|Any CPU.Build.0 = Debug|Any CPU {CA2C31AC-090D-45CB-B6F2-292B8F823438}.Release|Any CPU.ActiveCfg = Release|Any CPU {CA2C31AC-090D-45CB-B6F2-292B8F823438}.Release|Any CPU.Build.0 = Release|Any CPU + {EEF969D3-121B-48D2-B88D-CC2F5DD42A4A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {EEF969D3-121B-48D2-B88D-CC2F5DD42A4A}.Debug|Any CPU.Build.0 = Debug|Any CPU + {EEF969D3-121B-48D2-B88D-CC2F5DD42A4A}.Release|Any CPU.ActiveCfg = Release|Any CPU + {EEF969D3-121B-48D2-B88D-CC2F5DD42A4A}.Release|Any CPU.Build.0 = Release|Any CPU + {967D9E94-166F-47B5-8C9B-61AE9961C491}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {967D9E94-166F-47B5-8C9B-61AE9961C491}.Debug|Any CPU.Build.0 = Debug|Any CPU + {967D9E94-166F-47B5-8C9B-61AE9961C491}.Release|Any CPU.ActiveCfg = Release|Any CPU + {967D9E94-166F-47B5-8C9B-61AE9961C491}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/WinForms/FormComponents.Designer.cs b/WinForms/FormComponents.Designer.cs index 6ee9b48..94dd146 100644 --- a/WinForms/FormComponents.Designer.cs +++ b/WinForms/FormComponents.Designer.cs @@ -47,7 +47,7 @@ this.buttonWordDiagram = new System.Windows.Forms.Button(); this.buttonWordTable = new System.Windows.Forms.Button(); this.buttonWordText = new System.Windows.Forms.Button(); - this.wordTextComponent = new WinFormsLibrary.WordText(this.components); + this.wordTextComponent = new WinFormsLibrary.NonVisualComponents.WordText(this.components); this.wordTableComponent = new WinFormsLibrary.NonVisualComponents.WordTable(this.components); this.wordDiagramComponent = new WinFormsLibrary.NonVisualComponents.WordDiagram(this.components); this.panel1.SuspendLayout(); @@ -275,7 +275,7 @@ private Button buttonWordDiagram; private Button buttonWordTable; private Button buttonWordText; - private WinFormsLibrary.WordText wordTextComponent; + private WinFormsLibrary.NonVisualComponents.WordText wordTextComponent; private WinFormsLibrary.NonVisualComponents.WordTable wordTableComponent; private WinFormsLibrary.NonVisualComponents.WordDiagram wordDiagramComponent; } diff --git a/WinFormsLibrary/NonVisualComponents/WordText.Designer.cs b/WinFormsLibrary/NonVisualComponents/WordText.Designer.cs index 5ead08b..b7b6e9a 100644 --- a/WinFormsLibrary/NonVisualComponents/WordText.Designer.cs +++ b/WinFormsLibrary/NonVisualComponents/WordText.Designer.cs @@ -1,4 +1,4 @@ -namespace WinFormsLibrary +namespace WinFormsLibrary.NonVisualComponents { partial class WordText { diff --git a/WinFormsLibrary/NonVisualComponents/WordText.cs b/WinFormsLibrary/NonVisualComponents/WordText.cs index 0ab3453..e9e0b6f 100644 --- a/WinFormsLibrary/NonVisualComponents/WordText.cs +++ b/WinFormsLibrary/NonVisualComponents/WordText.cs @@ -4,7 +4,7 @@ using WinFormsLibrary.NonVisualComponents.Helpers; using Application = Microsoft.Office.Interop.Word.Application; -namespace WinFormsLibrary +namespace WinFormsLibrary.NonVisualComponents { public partial class WordText : Component { diff --git a/WinFormsLibrary/VisualComponent/EmailTextBox.Designer.cs b/WinFormsLibrary/VisualComponent/EmailTextBox.Designer.cs index ed3d2ac..1cd7f5d 100644 --- a/WinFormsLibrary/VisualComponent/EmailTextBox.Designer.cs +++ b/WinFormsLibrary/VisualComponent/EmailTextBox.Designer.cs @@ -31,35 +31,25 @@ this.components = new System.ComponentModel.Container(); this.textBoxEmail = new System.Windows.Forms.TextBox(); this.toolTipEmail = new System.Windows.Forms.ToolTip(this.components); - this.labelEmail = new System.Windows.Forms.Label(); this.SuspendLayout(); // // textBoxEmail // - this.textBoxEmail.Location = new System.Drawing.Point(0, 55); + this.textBoxEmail.Dock = System.Windows.Forms.DockStyle.Fill; + this.textBoxEmail.Location = new System.Drawing.Point(0, 0); this.textBoxEmail.Name = "textBoxEmail"; - this.textBoxEmail.Size = new System.Drawing.Size(209, 31); + this.textBoxEmail.Size = new System.Drawing.Size(146, 31); this.textBoxEmail.TabIndex = 0; this.textBoxEmail.TextChanged += new System.EventHandler(this.textBoxEmail_TextChanged); this.textBoxEmail.MouseEnter += new System.EventHandler(this.textBoxEmail_MouseEnter); // - // labelEmail - // - this.labelEmail.AutoSize = true; - this.labelEmail.Location = new System.Drawing.Point(3, 6); - this.labelEmail.Name = "labelEmail"; - this.labelEmail.Size = new System.Drawing.Size(62, 25); - this.labelEmail.TabIndex = 1; - this.labelEmail.Text = "Почта"; - // // EmailTextBox // this.AutoScaleDimensions = new System.Drawing.SizeF(10F, 25F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.Controls.Add(this.labelEmail); this.Controls.Add(this.textBoxEmail); this.Name = "EmailTextBox"; - this.Size = new System.Drawing.Size(185, 86); + this.Size = new System.Drawing.Size(146, 33); this.ResumeLayout(false); this.PerformLayout(); @@ -69,6 +59,5 @@ private TextBox textBoxEmail; private ToolTip toolTipEmail; - private Label labelEmail; } } diff --git a/WindowsFormAppPlugin/FormMain.Designer.cs b/WindowsFormAppPlugin/FormMain.Designer.cs new file mode 100644 index 0000000..445daab --- /dev/null +++ b/WindowsFormAppPlugin/FormMain.Designer.cs @@ -0,0 +1,188 @@ +namespace WindowsFormAppPlugin +{ + 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/WindowsFormAppPlugin/FormMain.cs b/WindowsFormAppPlugin/FormMain.cs new file mode 100644 index 0000000..deb6c48 --- /dev/null +++ b/WindowsFormAppPlugin/FormMain.cs @@ -0,0 +1,235 @@ +using PluginsConventionLibrary; +using System.Reflection; + +namespace WindowsFormAppPlugin +{ + 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(); + + } +} diff --git a/WindowsFormAppPlugin/FormMain.resx b/WindowsFormAppPlugin/FormMain.resx new file mode 100644 index 0000000..1af7de1 --- /dev/null +++ b/WindowsFormAppPlugin/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/WindowsFormAppPlugin/Program.cs b/WindowsFormAppPlugin/Program.cs new file mode 100644 index 0000000..eb4ca4d --- /dev/null +++ b/WindowsFormAppPlugin/Program.cs @@ -0,0 +1,17 @@ +namespace WindowsFormAppPlugin +{ + 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/WindowsFormAppPlugin/WindowsFormAppPlugin.csproj b/WindowsFormAppPlugin/WindowsFormAppPlugin.csproj new file mode 100644 index 0000000..8c67b97 --- /dev/null +++ b/WindowsFormAppPlugin/WindowsFormAppPlugin.csproj @@ -0,0 +1,25 @@ + + + + WinExe + net7.0-windows + enable + true + enable + + + + + + + + + + + + + Form + + + + \ No newline at end of file