This commit is contained in:
Екатерина Рогашова 2023-11-09 22:15:18 +04:00
parent 58f5ede797
commit fcfd5b06bf
93 changed files with 886 additions and 25 deletions

View File

@ -15,7 +15,11 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "UniversityContracts", "Univ
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "UniversityBusinessLogic", "UniversityBusinessLogic\UniversityBusinessLogic.csproj", "{2AAADED7-BE04-41CF-B45D-9FBF1DFD346B}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "UniversityForms", "UniversityForms\UniversityForms.csproj", "{690ADFAC-1C2A-4130-82BD-46A59ECE933A}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "UniversityForms", "UniversityForms\UniversityForms.csproj", "{690ADFAC-1C2A-4130-82BD-46A59ECE933A}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PluginsConventionLibraryNet60", "PluginsConventionLibraryNet60\PluginsConventionLibraryNet60.csproj", "{07A710A3-C6B0-4D52-85AA-4882151F5BFA}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FormsByPlugins", "FormsByPlugins\FormsByPlugins.csproj", "{45B39F84-AF33-4739-9FD9-A0E1D7C062AE}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
@ -51,6 +55,14 @@ Global
{690ADFAC-1C2A-4130-82BD-46A59ECE933A}.Debug|Any CPU.Build.0 = Debug|Any CPU
{690ADFAC-1C2A-4130-82BD-46A59ECE933A}.Release|Any CPU.ActiveCfg = Release|Any CPU
{690ADFAC-1C2A-4130-82BD-46A59ECE933A}.Release|Any CPU.Build.0 = Release|Any CPU
{07A710A3-C6B0-4D52-85AA-4882151F5BFA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{07A710A3-C6B0-4D52-85AA-4882151F5BFA}.Debug|Any CPU.Build.0 = Debug|Any CPU
{07A710A3-C6B0-4D52-85AA-4882151F5BFA}.Release|Any CPU.ActiveCfg = Release|Any CPU
{07A710A3-C6B0-4D52-85AA-4882151F5BFA}.Release|Any CPU.Build.0 = Release|Any CPU
{45B39F84-AF33-4739-9FD9-A0E1D7C062AE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{45B39F84-AF33-4739-9FD9-A0E1D7C062AE}.Debug|Any CPU.Build.0 = Debug|Any CPU
{45B39F84-AF33-4739-9FD9-A0E1D7C062AE}.Release|Any CPU.ActiveCfg = Release|Any CPU
{45B39F84-AF33-4739-9FD9-A0E1D7C062AE}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE

231
COP_1/FormsByPlugins/FormMain.Designer.cs generated Normal file
View File

@ -0,0 +1,231 @@
namespace FormsByPlugins
{
partial class FormMain
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
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;
}
}

View File

@ -0,0 +1,221 @@
using PluginsConventionLibraryNet60;
using System.Reflection;
namespace FormsByPlugins
{
public partial class FormMain : Form
{
private readonly Dictionary<string, IPluginsConvention> _plugins;
private string _selectedPlugin;
public FormMain()
{
InitializeComponent();
_plugins = LoadPlugins();
_selectedPlugin = string.Empty;
}
private Dictionary<string, IPluginsConvention> LoadPlugins()
{
Dictionary<string, IPluginsConvention> plugins = new();
string currentDirectory = Directory.GetParent(Environment.CurrentDirectory)!.Parent!.Parent!.Parent!.FullName + "\\plugin";
string[] dllFiles = Directory.GetFiles(currentDirectory, "*.dll", SearchOption.AllDirectories);
foreach (string dllFile in dllFiles)
{
try
{
Assembly assembly = Assembly.LoadFrom(dllFile);
Type[] types = assembly.GetTypes();
foreach (Type type in types)
{
if (typeof(IPluginsConvention).IsAssignableFrom(type) && !type.IsInterface)
{
var plugin = (IPluginsConvention)Activator.CreateInstance(type)!;
plugins.Add(plugin.PluginName, plugin);
}
}
}
catch (Exception ex)
{
Console.WriteLine($"Îøèáêà ïðè çàãðóçêå ñáîðêè {dllFile}: {ex.Message}");
}
}
foreach (var plugin in plugins)
{
CreateMenuItem(plugin.Value.PluginName);
}
return plugins;
}
private void CreateMenuItem(string pluginName)
{
ToolStripMenuItem menuItem = new ToolStripMenuItem(pluginName);
menuItem.Click += (object? sender, EventArgs a) =>
{
_selectedPlugin = pluginName;
IPluginsConvention plugin = _plugins[pluginName];
UserControl userControl = plugin.GetControl;
if (userControl != null)
{
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()
{
SaveFileDialog saveFileDialog = new SaveFileDialog();
saveFileDialog.Filter = "PDF Files (*.docx)|*.docx";
saveFileDialog.Title = "Список";
if (saveFileDialog.ShowDialog() == DialogResult.OK)
{
if (_plugins[_selectedPlugin].CreateSimpleDocument(new PluginsConventionSaveDocument() { FileName = saveFileDialog.FileName }))
{
MessageBox.Show("Документ сохранен", "Создание документа", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
else
{
MessageBox.Show("Ошибка при создании документа",
"Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
private void CreateTableDoc()
{
SaveFileDialog saveFileDialog = new SaveFileDialog();
saveFileDialog.Filter = "PDF Files (*.pdf)|*.pdf";
saveFileDialog.Title = "Table";
if (saveFileDialog.ShowDialog() == DialogResult.OK)
{
if (_plugins[_selectedPlugin].CreateTableDocument(new PluginsConventionSaveDocument() { FileName = saveFileDialog.FileName }))
{
MessageBox.Show("Документ сохранен", "Создание документа", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
else
{
MessageBox.Show("Ошибка при создании документа",
"Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
private void CreateChartDoc()
{
SaveFileDialog saveFileDialog = new SaveFileDialog();
saveFileDialog.Filter = "Excel Files (*.xlsx)|*.xlsx";
saveFileDialog.Title = "Круговая диаграмма";
if (saveFileDialog.ShowDialog() == DialogResult.OK)
{
if (_plugins[_selectedPlugin].CreateChartDocument(new PluginsConventionSaveDocument() { FileName = saveFileDialog.FileName }))
{
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();
}
}

View File

@ -0,0 +1,60 @@
<root>
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
</root>

View File

@ -0,0 +1,20 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>WinExe</OutputType>
<TargetFramework>net6.0-windows</TargetFramework>
<Nullable>enable</Nullable>
<UseWindowsForms>true</UseWindowsForms>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="System.ComponentModel.Composition" Version="7.0.0" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\PluginsConventionLibraryNet60\PluginsConventionLibraryNet60.csproj" />
<ProjectReference Include="..\UniversityForms\UniversityForms.csproj" />
</ItemGroup>
</Project>

View File

@ -0,0 +1,48 @@
using PluginsConventionLibraryNet60;
using System;
using System.Collections.Generic;
using System.ComponentModel.Composition;
using System.ComponentModel.Composition.Hosting;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace FormsByPlugins
{
public class PluginsManager
{
//Тег, указывающий, что plugins должны быть заполнены CompositionContainer
[ImportMany(typeof(IPluginsConvention))]
IEnumerable<IPluginsConvention> plugins { get; set; }
public readonly Dictionary<string, IPluginsConvention> plugins_dictionary = new Dictionary<string, IPluginsConvention>();
public PluginsManager()
{
AggregateCatalog catalog = new AggregateCatalog();
catalog.Catalogs.Add(new DirectoryCatalog(AppDomain.CurrentDomain.BaseDirectory));
catalog.Catalogs.Add(new DirectoryCatalog(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Plugins")));
//Контейнер композиции
CompositionContainer container = new CompositionContainer(catalog);
try
{
container.ComposeParts(this);
}
catch (CompositionException compositionException)
{
MessageBox.Show(compositionException.ToString());
}
if (plugins.Any())
{
plugins
.ToList()
.ForEach(p =>
{
if (!plugins_dictionary.Keys.Contains(p.PluginName))
plugins_dictionary.Add(p.PluginName, p);
});
}
}
}
}

View File

@ -0,0 +1,17 @@
namespace FormsByPlugins
{
internal static class Program
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[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());
}
}
}

View File

@ -0,0 +1,16 @@
namespace PluginsConventionLibraryNet60
{
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);
}
}

View File

@ -0,0 +1,14 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace PluginsConventionLibraryNet60
{
public class PluginsConventionElement
{
public Guid Id { get; set; }
}
}

View File

@ -0,0 +1,10 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0-windows</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<UseWindowsForms>true</UseWindowsForms>
<Nullable>enable</Nullable>
</PropertyGroup>
</Project>

View File

@ -0,0 +1,14 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace PluginsConventionLibraryNet60
{
public class PluginsConventionSaveDocument
{
public string FileName { get; set; }
}
}

View File

@ -14,11 +14,9 @@ namespace UniversityBusinessLogic.BusinessLogics
{
public class CourseLogic: ICourseLogic
{
private readonly ILogger _logger;
private readonly ICourseStorage _courseStorage;
public CourseLogic(ILogger<CourseLogic> logger, ICourseStorage courseStorage)
public CourseLogic( ICourseStorage courseStorage)
{
_logger = logger;
_courseStorage = courseStorage;
}
public bool Create(CourseBindingModels model)
@ -26,7 +24,6 @@ namespace UniversityBusinessLogic.BusinessLogics
CheckModel(model);
if (_courseStorage.Insert(model) == null)
{
_logger.LogWarning("Insert operation failed");
return false;
}
return true;
@ -35,10 +32,8 @@ namespace UniversityBusinessLogic.BusinessLogics
public bool Delete(CourseBindingModels model)
{
CheckModel(model, false);
_logger.LogInformation("Delete. Id:{Id}", model.Id);
if (_courseStorage.Delete(model) == null)
{
_logger.LogWarning("Delete operation failed");
return false;
}
return true;
@ -50,27 +45,21 @@ namespace UniversityBusinessLogic.BusinessLogics
{
throw new ArgumentNullException(nameof(model));
}
_logger.LogInformation("ReadElement. Name:{Name}. Id:{ Id}", model.Name, model.Id);
var element = _courseStorage.GetElement(model);
if (element == null)
{
_logger.LogWarning("ReadElement element not found");
return null;
}
_logger.LogInformation("ReadElement find. Id:{Id}", element.Id);
return element;
}
public List<CourseViewModel>? ReadList(CourseSearchModel? model)
{
_logger.LogInformation("ReadList. Name:{Name}. Id:{ Id}", model?.Name, model?.Id);
var list = model == null ? _courseStorage.GetFullList() : _courseStorage.GetFilteredList(model);
if (list == null)
{
_logger.LogWarning("ReadList return null list");
return null;
}
_logger.LogInformation("ReadList. Count:{Count}", list.Count);
return list;
}
@ -79,7 +68,6 @@ namespace UniversityBusinessLogic.BusinessLogics
CheckModel(model);
if (_courseStorage.Update(model) == null)
{
_logger.LogWarning("Update operation failed");
return false;
}
return true;
@ -99,7 +87,6 @@ namespace UniversityBusinessLogic.BusinessLogics
{
throw new ArgumentNullException("Нет названия курса", nameof(model.Name));
}
_logger.LogInformation("Course. Name:{Name}. Id: { Id} ", model.Name, model.Id);
var element = _courseStorage.GetElement(new CourseSearchModel
{
Name = model.Name

View File

@ -14,11 +14,9 @@ namespace UniversityBusinessLogic.BusinessLogics
{
public class StudentLogic: IStudentLogic
{
private readonly ILogger _logger;
private readonly IStudentStorage _studentStorage;
public StudentLogic(ILogger<StudentLogic> logger, IStudentStorage studentStorage)
public StudentLogic(IStudentStorage studentStorage)
{
_logger = logger;
_studentStorage = studentStorage;
}
public bool Create(StudentBindingModels model)
@ -26,7 +24,6 @@ namespace UniversityBusinessLogic.BusinessLogics
CheckModel(model);
if (_studentStorage.Insert(model) == null)
{
_logger.LogWarning("Insert operation failed");
return false;
}
return true;
@ -35,10 +32,8 @@ namespace UniversityBusinessLogic.BusinessLogics
public bool Delete(StudentBindingModels model)
{
CheckModel(model, false);
_logger.LogInformation("Delete. Id:{Id}", model.Id);
if (_studentStorage.Delete(model) == null)
{
_logger.LogWarning("Delete operation failed");
return false;
}
return true;
@ -53,10 +48,8 @@ namespace UniversityBusinessLogic.BusinessLogics
var element = _studentStorage.GetElement(model);
if (element == null)
{
_logger.LogWarning("ReadElement element not found");
return null;
}
_logger.LogInformation("ReadElement find. Id:{Id}", element.Id);
return element;
}
@ -65,7 +58,6 @@ namespace UniversityBusinessLogic.BusinessLogics
var list = model == null ? _studentStorage.GetFullList() : _studentStorage.GetFilteredList(model);
if (list == null)
{
_logger.LogWarning("ReadList return null list");
return null;
}
return list;
@ -76,7 +68,6 @@ namespace UniversityBusinessLogic.BusinessLogics
CheckModel(model);
if (_studentStorage.Update(model) == null)
{
_logger.LogWarning("Update operation failed");
return false;
}
return true;

View File

@ -0,0 +1,215 @@
using COP;
using COP.Info;
using COPWinForms;
using PluginsConventionLibraryNet60;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using UniversityBusinessLogic.BusinessLogics;
using UniversityContracts.BindingModels;
using UniversityContracts.ViewModels;
using UniversityDataBaseImplements.Implements;
using VisableComponents;
using WinFormsControlLibrary;
namespace UniversityForms
{
public class PluginsConvention : IPluginsConvention
{
private readonly StudentLogic _studentLogic = new StudentLogic(new StudentStorage());
private readonly CourseLogic _courseLogic = new CourseLogic(new CourseStorage());
private MyTreeView myTreeView1 = new MyTreeView();
public string PluginName { get; set; } = "Дерево";
public UserControl GetControl
{
get
{
Load();
return myTreeView1;
}
}
public PluginsConventionElement GetElement
{
get
{
var selectedStudent = myTreeView1.GetNode(typeof(StudentViewModel));
int? id = null;
if (selectedStudent != null)
{
id = Convert.ToInt32((selectedStudent as StudentViewModel).Id);
}
byte[] bytes = new byte[16];
if (!id.HasValue)
{
id = -1;
}
BitConverter.GetBytes(id.Value).CopyTo(bytes, 0);
return new()
{
Id = new Guid(bytes)
};
}
}
public bool CreateChartDocument(PluginsConventionSaveDocument saveDocument)
{
try
{
PieChart chart = new();
var listStudents = _studentLogic.ReadList(null);
var listCourses = _courseLogic.ReadList(null);
List<(string, int)> data = new List<(string, int)>();
for (int i = 0; i < listCourses.Count; i++)
{
int counter = 0;
for (int j = 0; j < listStudents.Count; j++)
{
if (listStudents[j].Course == listCourses[i].Name && listStudents[j].Scholarship != null) counter++;
}
data.Add((listCourses[i].Name, counter));
}
List<DataItem> chartData = new List<DataItem>();
foreach (var item in data)
{
chartData.Add(new DataItem
{
Name = item.Item1,
Value = item.Item2
});
}
chart.GenerateDocument(new ExcelChartInfo(saveDocument.FileName, "Сколько студентов на каком курсе", "Курсы", COP.Enums.LegendPosition.Right, chartData));
return true;
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
return false;
}
}
public bool CreateSimpleDocument(PluginsConventionSaveDocument saveDocument)
{
try
{
ComponentWord1 text = new ComponentWord1();
List<string> textList = new List<string>();
var list = _studentLogic.ReadList(null);
if (list != null)
{
foreach (var item in list)
{
if (item.Scholarship != null)
{
string clients = string.Concat("ФИО: ", item.FIO, ", Краткая характеристика: ", item.Сharacteristic);
textList.Add(clients);
}
}
string[] textArray = textList.ToArray();
text.CreateWordText(new(saveDocument.FileName, "Документ по студентам со стипендией", textArray));
}
return true;
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
return false;
}
}
public bool CreateTableDocument(PluginsConventionSaveDocument saveDocument)
{
try
{
CustomTablePdfComponent2 generator = new CustomTablePdfComponent2();
var list = _studentLogic.ReadList(null);
for (int i = 0; i < list.Count; i++)
{
if (list[i].Scholarship == null) { list[i].ScholarshipStr = "No"; }
}
var columnConfigs = new List<ColumnConfig>
{
new ColumnConfig { Width = 50f, PropertyName = "Id", ShowName = "Id"},
new ColumnConfig { Width = 300f, PropertyName = "FIO", ShowName = "FIO" },
new ColumnConfig { Width = 100f, PropertyName = "Course", ShowName = "Course" },
new ColumnConfig { Width = 100f, PropertyName = "ScholarshipStr", ShowName = "Scholarship" },
};
generator.GenerateDocument(saveDocument.FileName, "Students", 100f, 50f, list, columnConfigs);
return true;
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
return false;
}
}
private void Load()
{
List<string> stringToHierachy = new List<string>() { "Course", "ScholarshipStr", "Id", "FIO" };
myTreeView1.addToHierarchy(stringToHierachy);
LoadData();
}
private void LoadData()
{
try
{
var list = _studentLogic.ReadList(null);
for (int i = 0; i < list.Count; i++)
{
if (list[i].Scholarship == null) { list[i].ScholarshipStr = "Нет стипендии"; }
}
myTreeView1.LoadTree(list);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
public bool DeleteElement(PluginsConventionElement element)
{
var selectedStudent = myTreeView1.GetNode(typeof(StudentViewModel));
int id = Convert.ToInt32((selectedStudent as StudentViewModel).Id);
try
{
_studentLogic.Delete(new StudentBindingModels { Id = id });
LoadData();
return true;
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
return false;
}
}
public Form GetForm(PluginsConventionElement element)
{
if (element == null)
{
return new FormStudent(_studentLogic, _courseLogic);
}
if (element.Id.GetHashCode() >= 0)
{
FormStudent form = new FormStudent(_studentLogic, _courseLogic);
form.Id = element.Id.GetHashCode();
return form;
}
return null;
}
public Form GetThesaurus()
{
return new FormCourses(_courseLogic);
}
public void ReloadData()
{
LoadData();
}
}
}

View File

@ -8,6 +8,10 @@
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>
<Target Name="PostBuild" AfterTargets="PostBuildEvent">
<Exec Command="xcopy /Y &quot;$(TargetDir)*.dll&quot; &quot;$(SolutionDir)plugin\*.dll&quot;" />
</Target>
<ItemGroup>
<PackageReference Include="cop" Version="1.0.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="7.0.13">
@ -21,6 +25,7 @@
<ItemGroup>
<ProjectReference Include="..\..\COPWinForms\COPWinForms.csproj" />
<ProjectReference Include="..\PluginsConventionLibraryNet60\PluginsConventionLibraryNet60.csproj" />
<ProjectReference Include="..\UniversityBusinessLogic\UniversityBusinessLogic.csproj" />
<ProjectReference Include="..\UniversityContracts\UniversityContracts.csproj" />
<ProjectReference Include="..\UniversityDataBaseImplements\UniversityDataBaseImplements.csproj" />

Binary file not shown.

Binary file not shown.

BIN
COP_1/plugin/Azure.Core.dll Normal file

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

BIN
COP_1/plugin/COP.dll Normal file

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

BIN
COP_1/plugin/EPPlus.dll Normal file

Binary file not shown.

BIN
COP_1/plugin/Enums.NET.dll Normal file

Binary file not shown.

BIN
COP_1/plugin/Humanizer.dll Normal file

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

BIN
COP_1/plugin/NLog.dll Normal file

Binary file not shown.

BIN
COP_1/plugin/NPOI.Core.dll Normal file

Binary file not shown.

BIN
COP_1/plugin/NPOI.OOXML.dll Normal file

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

BIN
COP_1/plugin/SkiaSharp.dll Normal file

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

BIN
COP_1/plugin/itextsharp.dll Normal file

Binary file not shown.