fix FormMain

This commit is contained in:
Zakharov_Rostislav 2024-11-17 20:55:39 +04:00
parent 529eb62a76
commit ff8343bc90
2 changed files with 236 additions and 248 deletions

View File

@ -1,253 +1,237 @@
//using NPOI.HPSF; using LibraryPlugin;
//using Plugins; using LibraryPlugin.Helpers;
//using System; using LibraryUtils.FileChooser;
//using System.Collections.Generic; using Microsoft.Win32;
//using System.ComponentModel; using System;
//using System.Data; using System.Collections.Generic;
//using System.Drawing; using System.ComponentModel;
//using System.Linq; using System.Data;
//using System.Reflection; using System.Drawing;
//using System.Text; using System.Linq;
//using System.Threading.Tasks; using System.Reflection;
//using System.Windows.Forms; using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using static LibraryUtils.FileChooser.FileChooser;
//namespace LibraryPluginWinFormsApp namespace LibraryPluginWinFormsApp
//{ {
// public partial class FormMain : Form public partial class FormMain : Form
// { {
// private readonly Dictionary<string, IPluginsConvention> _plugins; private readonly Dictionary<string, IPluginsConvention> _plugins;
// private string _selectedPlugin; private string _selectedPlugin;
// public FormMain() public FormMain()
// { {
// InitializeComponent(); InitializeComponent();
// _plugins = LoadPlugins(); _plugins = LoadPlugins();
// _selectedPlugin = string.Empty; _selectedPlugin = string.Empty;
// } }
// private Dictionary<string, IPluginsConvention> LoadPlugins() #region load_plugins
// { private Dictionary<string, IPluginsConvention> LoadPlugins()
// Dictionary<string, IPluginsConvention> plugins = new(); {
// string currentDirectory = Directory Dictionary<string, IPluginsConvention> plugins = new();
// .GetParent(Environment.CurrentDirectory)! string currentDirectory = Directory
// .Parent! .GetParent(Environment.CurrentDirectory)!
// .Parent! .Parent!
// .Parent! .Parent!
// .FullName + "\\plugin"; .FullName + "\\bin\\Debug\\net6.0-windows";
// string[] dllFiles = Directory.GetFiles(currentDirectory, "*.dll", SearchOption.AllDirectories); string[] dllFiles = Directory.GetFiles(currentDirectory, "*.dll", SearchOption.AllDirectories);
// foreach (string dllFile in dllFiles) foreach (string dllFile in dllFiles)
// { {
// try try
// { {
// Assembly assembly = Assembly.LoadFrom(dllFile); Assembly assembly = Assembly.LoadFrom(dllFile);
// Type[] types = assembly.GetTypes(); Type[] types = assembly.GetTypes();
// foreach (Type type in types) foreach (Type type in types)
// { {
// if (typeof(IPluginsConvention).IsAssignableFrom(type) && !type.IsInterface) if (typeof(IPluginsConvention).IsAssignableFrom(type) && !type.IsInterface)
// { {
// var plugin = (IPluginsConvention)Activator.CreateInstance(type)!; var plugin = (IPluginsConvention)Activator.CreateInstance(type)!;
// plugins.Add(plugin.PluginName, plugin); plugins.Add(plugin.PluginName, plugin);
// } }
// } }
// } }
// catch (Exception ex) catch (Exception ex)
// { {
// Console.WriteLine($"Не удалось загрузить плагин {dllFile}: {ex.Message}"); Console.WriteLine($"Не удалось загрузить плагин {dllFile}: {ex.Message}");
// } }
// } }
// foreach (var plugin in plugins) foreach (var plugin in plugins)
// { {
// CreateMenuItem(plugin.Value.PluginName); CreateMenuItem(plugin.Value.PluginName);
// } }
// return plugins; return plugins;
// } }
// private void CreateMenuItem(string pluginName) private void CreateMenuItem(string pluginName)
// { {
// ToolStripMenuItem menuItem = new ToolStripMenuItem(pluginName); ToolStripMenuItem menuItem = new ToolStripMenuItem(pluginName);
// menuItem.Click += (object? sender, EventArgs a) => menuItem.Click += (object? sender, EventArgs a) =>
// { {
// _selectedPlugin = pluginName; _selectedPlugin = pluginName;
// IPluginsConvention plugin = _plugins[pluginName]; IPluginsConvention plugin = _plugins[pluginName];
// UserControl userControl = plugin.GetControl; UserControl userControl = plugin.GetControl;
// if (userControl != null) if (userControl != null)
// { {
// panelControl.Controls.Clear(); panelControl.Controls.Clear();
// plugin.ReloadData(); plugin.ReloadData();
// userControl.Dock = DockStyle.Fill; userControl.Dock = DockStyle.Fill;
// panelControl.Controls.Add(userControl); panelControl.Controls.Add(userControl);
// } }
// }; };
// ControlsStripMenuItem.DropDownItems.Add(menuItem); ControlsStripMenuItem.DropDownItems.Add(menuItem);
// } }
// private void FormMain_KeyDown(object sender, KeyEventArgs e) #endregion
// { #region crud_ops
// if (string.IsNullOrEmpty(_selectedPlugin) || private void ShowThesaurus()
// !_plugins.ContainsKey(_selectedPlugin)) {
// { _plugins[_selectedPlugin].GetThesaurus()?.Show();
// return; }
// } private void AddNewElement()
// if (!e.Control) {
// { var form = _plugins[_selectedPlugin].GetForm(null);
// return; if (form != null && form.ShowDialog() == DialogResult.OK)
// } {
// switch (e.KeyCode) _plugins[_selectedPlugin].ReloadData();
// { }
// case Keys.I: }
// ShowThesaurus(); private void UpdateElement()
// break; {
// case Keys.A: var element = _plugins[_selectedPlugin].GetElement;
// AddNewElement(); if (element == null)
// break; {
// case Keys.U: MessageBox.Show("Нет выбранного элемента", "Ошибка",
// UpdateElement(); MessageBoxButtons.OK, MessageBoxIcon.Error);
// break; return;
// case Keys.D: }
// DeleteElement(); var form = _plugins[_selectedPlugin].GetForm(element);
// break; if (form != null && form.ShowDialog() == DialogResult.OK)
// case Keys.S: {
// CreateSimpleDoc(); _plugins[_selectedPlugin].ReloadData();
// break; }
// case Keys.T: }
// CreateTableDoc(); private void DeleteElement()
// break; {
// case Keys.C: if (MessageBox.Show("Удалить выбранный элемент", "Удаление",
// CreateChartDoc(); MessageBoxButtons.YesNo,
// break; MessageBoxIcon.Question) != DialogResult.Yes)
// } {
// } return;
// private void ShowThesaurus() }
// { var element = _plugins[_selectedPlugin].GetElement;
// _plugins[_selectedPlugin].GetThesaurus()?.Show(); if (element == null)
// } {
// private void AddNewElement() MessageBox.Show("Нет выбранного элемента", "Ошибка",
// { MessageBoxButtons.OK, MessageBoxIcon.Error);
// var form = _plugins[_selectedPlugin].GetForm(null); return;
// 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)) if (_plugins[_selectedPlugin].DeleteElement(element))
// { {
// _plugins[_selectedPlugin].ReloadData(); _plugins[_selectedPlugin].ReloadData();
// } }
// } }
// private void CreateSimpleDoc() #endregion
// { #region docs_ops
// SaveFileDialog saveFileDialog = new SaveFileDialog(); private void CreateSimpleDoc()
// saveFileDialog.Filter = "Word Documents (*.docx)|*.docx"; {
// saveFileDialog.Title = "Сохранить простой документ"; string fileName = GetFileFullName(DocType.Pdf);
// if (saveFileDialog.ShowDialog() == DialogResult.OK) if (_plugins[_selectedPlugin].CreateSimpleDocument(
// { new PluginsConventionSaveDocument() { FileName = fileName, }))
// if (_plugins[_selectedPlugin].CreateSimpleDocument( {
// new PluginsConventionSaveDocument() MessageBox.Show("Документ сохранен", "Создание документа",
// { MessageBoxButtons.OK, MessageBoxIcon.Information);
// FileName = saveFileDialog.FileName }
// })) else
// { {
// MessageBox.Show("Документ сохранен", "Создание" + MessageBox.Show("Ошибка при создании документа",
// " документа", MessageBoxButtons.OK, MessageBoxIcon.Information); "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
// } }
// else }
// { private void CreateTableDoc()
// MessageBox.Show("Ошибка при создании документа", {
// "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); string fileName = GetFileFullName(DocType.Excel);
// } if (_plugins[_selectedPlugin].CreateTableDocument(
new PluginsConventionSaveDocument() { FileName = fileName, }))
// } {
// } MessageBox.Show("Документ сохранен", "Создание документа",
// private void CreateTableDoc() MessageBoxButtons.OK, MessageBoxIcon.Information);
// { }
// SaveFileDialog saveFileDialog = new SaveFileDialog(); else
// saveFileDialog.Filter = "PDF Files (*.pdf)|*.pdf"; {
// saveFileDialog.Title = "Сохранить таблицу"; MessageBox.Show("Ошибка при создании документа",
// if (saveFileDialog.ShowDialog() == DialogResult.OK) "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
// { }
// if (_plugins[_selectedPlugin].CreateTableDocument( }
// new PluginsConventionSaveDocument() private void CreateChartDoc()
// { {
// FileName = saveFileDialog.FileName string fileName = GetFileFullName(DocType.Word);
// })) if (_plugins[_selectedPlugin].CreateChartDocument(
// { new PluginsConventionSaveDocument() { FileName = fileName, }))
// MessageBox.Show("Документ сохранен", "Создание" + {
// " документа", MessageBoxButtons.OK, MessageBoxIcon.Information); MessageBox.Show("Документ сохранен", "Создание документа",
// } MessageBoxButtons.OK, MessageBoxIcon.Information);
// else }
// { else
// MessageBox.Show("Ошибка при создании документа", {
// "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); MessageBox.Show("Ошибка при создании документа",
// } "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
// } }
// } }
// private void CreateChartDoc() #endregion
// { #region event-handlers
// SaveFileDialog saveFileDialog = new SaveFileDialog(); private void FormMain_KeyDown(object sender, KeyEventArgs e)
// saveFileDialog.Filter = "Excel Files (*.xlsx)|*.xlsx"; {
// saveFileDialog.Title = "Сохранить диаграмму"; if (string.IsNullOrEmpty(_selectedPlugin) ||
// if (saveFileDialog.ShowDialog() == DialogResult.OK) !_plugins.ContainsKey(_selectedPlugin))
// { {
// if (_plugins[_selectedPlugin].CreateChartDocument( return;
// new PluginsConventionSaveDocument() }
// { if (!e.Control)
// FileName = saveFileDialog.FileName {
// })) return;
// { }
// MessageBox.Show("Документ сохранен", "Создание" + switch (e.KeyCode)
// " документа", MessageBoxButtons.OK, MessageBoxIcon.Information); {
// } case Keys.I:
// else ShowThesaurus();
// { break;
// MessageBox.Show("Ошибка при создании документа", case Keys.A:
// "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); AddNewElement();
// } break;
case Keys.U:
// } UpdateElement();
// } break;
// private void ThesaurusToolStripMenuItem_Click(object sender, case Keys.D:
// EventArgs e) => ShowThesaurus(); DeleteElement();
// private void AddElementToolStripMenuItem_Click(object sender, break;
// EventArgs e) => AddNewElement(); case Keys.S:
// private void UpdElementToolStripMenuItem_Click(object sender, CreateSimpleDoc();
// EventArgs e) => UpdateElement(); break;
// private void DelElementToolStripMenuItem_Click(object sender, case Keys.T:
// EventArgs e) => DeleteElement(); CreateTableDoc();
// private void SimpleDocToolStripMenuItem_Click(object sender, break;
// EventArgs e) => CreateSimpleDoc(); case Keys.C:
// private void TableDocToolStripMenuItem_Click(object sender, EventArgs CreateChartDoc();
// e) => CreateTableDoc(); break;
// private void ChartDocToolStripMenuItem_Click(object sender, EventArgs }
// e) => CreateChartDoc(); }
// } 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();
#endregion
}
}

View File

@ -8,6 +8,10 @@
<ImplicitUsings>enable</ImplicitUsings> <ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup> </PropertyGroup>
<ItemGroup>
<PackageReference Include="LibraryPlugin" Version="1.0.0" />
</ItemGroup>
<ItemGroup> <ItemGroup>
<Compile Update="FormMain.cs" /> <Compile Update="FormMain.cs" />
</ItemGroup> </ItemGroup>