From af59090657067799440fd01784e7b1e6f6e905c7 Mon Sep 17 00:00:00 2001 From: "a.puchkina" Date: Mon, 11 Nov 2024 20:04:51 +0400 Subject: [PATCH] =?UTF-8?q?=D0=BD=D0=B0=D1=87=D0=B0=D0=BB=D0=BE=204=20?= =?UTF-8?q?=D0=BB=D0=B0=D0=B1=D1=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- COP_5/COP_5.sln | 8 +- .../FormMain.Designer.cs | 246 ++++++++++++++++++ COP_5/PluginsConventionLibrary/FormMain.cs | 161 ++++++++++++ COP_5/PluginsConventionLibrary/FormMain.resx | 120 +++++++++ .../IPluginsConvention .cs | 66 +++++ .../PluginsConventionElement.cs | 7 + .../PluginsConventionLibrary.csproj | 11 + .../PluginsConventionSaveDocument.cs | 7 + COP_5/PluginsConventionLibrary/Program.cs | 17 ++ 9 files changed, 642 insertions(+), 1 deletion(-) create mode 100644 COP_5/PluginsConventionLibrary/FormMain.Designer.cs create mode 100644 COP_5/PluginsConventionLibrary/FormMain.cs create mode 100644 COP_5/PluginsConventionLibrary/FormMain.resx create mode 100644 COP_5/PluginsConventionLibrary/IPluginsConvention .cs create mode 100644 COP_5/PluginsConventionLibrary/PluginsConventionElement.cs create mode 100644 COP_5/PluginsConventionLibrary/PluginsConventionLibrary.csproj create mode 100644 COP_5/PluginsConventionLibrary/PluginsConventionSaveDocument.cs create mode 100644 COP_5/PluginsConventionLibrary/Program.cs diff --git a/COP_5/COP_5.sln b/COP_5/COP_5.sln index 0a698e7..e451b05 100644 --- a/COP_5/COP_5.sln +++ b/COP_5/COP_5.sln @@ -7,7 +7,9 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "COP_5", "COP_5\COP_5.csproj EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "WinFormsApp", "WinFormsApp\WinFormsApp.csproj", "{82CFE6F8-94F2-45E0-B6C2-59E036235BB9}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LibraryAccountingApp_lab3", "LibraryAccountingApp_lab3\LibraryAccountingApp_lab3.csproj", "{6B665435-1A86-44B4-B4C9-B0F29559314D}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "LibraryAccountingApp_lab3", "LibraryAccountingApp_lab3\LibraryAccountingApp_lab3.csproj", "{6B665435-1A86-44B4-B4C9-B0F29559314D}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PluginsConventionLibrary", "PluginsConventionLibrary\PluginsConventionLibrary.csproj", "{546EACBF-3463-4F53-B1DE-86141E8B3BCA}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -27,6 +29,10 @@ Global {6B665435-1A86-44B4-B4C9-B0F29559314D}.Debug|Any CPU.Build.0 = Debug|Any CPU {6B665435-1A86-44B4-B4C9-B0F29559314D}.Release|Any CPU.ActiveCfg = Release|Any CPU {6B665435-1A86-44B4-B4C9-B0F29559314D}.Release|Any CPU.Build.0 = Release|Any CPU + {546EACBF-3463-4F53-B1DE-86141E8B3BCA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {546EACBF-3463-4F53-B1DE-86141E8B3BCA}.Debug|Any CPU.Build.0 = Debug|Any CPU + {546EACBF-3463-4F53-B1DE-86141E8B3BCA}.Release|Any CPU.ActiveCfg = Release|Any CPU + {546EACBF-3463-4F53-B1DE-86141E8B3BCA}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/COP_5/PluginsConventionLibrary/FormMain.Designer.cs b/COP_5/PluginsConventionLibrary/FormMain.Designer.cs new file mode 100644 index 0000000..0234fd7 --- /dev/null +++ b/COP_5/PluginsConventionLibrary/FormMain.Designer.cs @@ -0,0 +1,246 @@ +namespace PluginsConventionLibrary +{ + 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/COP_5/PluginsConventionLibrary/FormMain.cs b/COP_5/PluginsConventionLibrary/FormMain.cs new file mode 100644 index 0000000..d22ada5 --- /dev/null +++ b/COP_5/PluginsConventionLibrary/FormMain.cs @@ -0,0 +1,161 @@ +namespace PluginsConventionLibrary +{ + public partial class FormMain : Form + { + private readonly Dictionary _plugins; + private string _selectedPlugin; + public FormMain() + { + InitializeComponent(); + _plugins = LoadPlugins(); + _selectedPlugin = string.Empty; + } + + private Dictionary LoadPlugins() + { + // TODO Заполнить IPluginsConvention + // TODO Заполнить пункт меню "Компоненты" на основе IPluginsConvention.PluginName + // TODO Например, создавать ToolStripMenuItem, привязывать к ним обработку событий и добавлять в menuStrip + // TODO При выборе пункта меню получать UserControl заполнять элемент panelControl этим контролом на всю площадь + // Пример: panelControl.Controls.Clear(); panelControl.Controls.Add(ctrl); + return new Dictionary(); + } + + 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() + { + // TODO узнать где сохранять + if (_plugins[_selectedPlugin].CreateSimpleDocument(new PluginsConventionSaveDocument())) + { + MessageBox.Show("Документ сохранен", "Создание документа", MessageBoxButtons.OK, MessageBoxIcon.Information); + + } + else + { + MessageBox.Show("Ошибка при создании документа", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void CreateTableDoc() + { + // TODO узнать где сохранять + if (_plugins[_selectedPlugin].CreateTableDocument(new PluginsConventionSaveDocument())) + { + MessageBox.Show("Документ сохранен", "Создание документа", MessageBoxButtons.OK, MessageBoxIcon.Information); + + } + else + { + MessageBox.Show("Ошибка при создании документа", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void CreateChartDoc() + { + // TODO узнать где сохранять + if (_plugins[_selectedPlugin].CreateChartDocument(new PluginsConventionSaveDocument())) + { + MessageBox.Show("Документ сохранен", "Создание документа", MessageBoxButtons.OK, MessageBoxIcon.Information); + + } + else + { + MessageBox.Show("Ошибка при создании документа", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void ThesaurusToolStripMenuItem_Click(object sender, EventArgs e) => ShowThesaurus(); + + private void AddElementToolStripMenuItem_Click(object sender, EventArgs e) => AddNewElement(); + + private void UpdElementToolStripMenuItem_Click(object sender, EventArgs e) => UpdateElement(); + + private void DelElementToolStripMenuItem_Click(object sender, EventArgs e) => DeleteElement(); + + private void SimpleDocToolStripMenuItem_Click(object sender, EventArgs e) => CreateSimpleDoc(); + private void TableDocToolStripMenuItem_Click(object sender, EventArgs e) => CreateTableDoc(); + private void ChartDocToolStripMenuItem_Click(object sender, EventArgs e) => CreateChartDoc(); + } +} diff --git a/COP_5/PluginsConventionLibrary/FormMain.resx b/COP_5/PluginsConventionLibrary/FormMain.resx new file mode 100644 index 0000000..1af7de1 --- /dev/null +++ b/COP_5/PluginsConventionLibrary/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_5/PluginsConventionLibrary/IPluginsConvention .cs b/COP_5/PluginsConventionLibrary/IPluginsConvention .cs new file mode 100644 index 0000000..25759da --- /dev/null +++ b/COP_5/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_5/PluginsConventionLibrary/PluginsConventionElement.cs b/COP_5/PluginsConventionLibrary/PluginsConventionElement.cs new file mode 100644 index 0000000..7342dfc --- /dev/null +++ b/COP_5/PluginsConventionLibrary/PluginsConventionElement.cs @@ -0,0 +1,7 @@ +namespace PluginsConventionLibrary +{ + public class PluginsConventionElement + { + public Guid Id { get; set; } + } +} diff --git a/COP_5/PluginsConventionLibrary/PluginsConventionLibrary.csproj b/COP_5/PluginsConventionLibrary/PluginsConventionLibrary.csproj new file mode 100644 index 0000000..b57c89e --- /dev/null +++ b/COP_5/PluginsConventionLibrary/PluginsConventionLibrary.csproj @@ -0,0 +1,11 @@ + + + + WinExe + net6.0-windows + enable + true + enable + + + \ No newline at end of file diff --git a/COP_5/PluginsConventionLibrary/PluginsConventionSaveDocument.cs b/COP_5/PluginsConventionLibrary/PluginsConventionSaveDocument.cs new file mode 100644 index 0000000..3af0f93 --- /dev/null +++ b/COP_5/PluginsConventionLibrary/PluginsConventionSaveDocument.cs @@ -0,0 +1,7 @@ +namespace PluginsConventionLibrary +{ + public class PluginsConventionSaveDocument + { + public string FileName { get; set; } + } +} diff --git a/COP_5/PluginsConventionLibrary/Program.cs b/COP_5/PluginsConventionLibrary/Program.cs new file mode 100644 index 0000000..132ed77 --- /dev/null +++ b/COP_5/PluginsConventionLibrary/Program.cs @@ -0,0 +1,17 @@ +namespace PluginsConventionLibrary +{ + 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