This commit is contained in:
ityurner02@mail.ru 2023-10-31 22:44:35 +04:00
parent f882b814ab
commit 9ecf656150
68 changed files with 894 additions and 8 deletions

View File

@ -7,11 +7,15 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "WinForms", "WinForms\WinFor
EndProject EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "VisualCompLib", "VisualCompLib\VisualCompLib.csproj", "{FC1CFC63-5739-4519-B689-E8B614A9D106}" Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "VisualCompLib", "VisualCompLib\VisualCompLib.csproj", "{FC1CFC63-5739-4519-B689-E8B614A9D106}"
EndProject EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ClientsContracts", "ClientsContracts\ClientsContracts.csproj", "{849DCBC2-7B2D-43A5-87BD-CFE9BC4F0B6C}" Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ClientsContracts", "ClientsContracts\ClientsContracts.csproj", "{849DCBC2-7B2D-43A5-87BD-CFE9BC4F0B6C}"
EndProject EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ClientBusinessLogic", "ClientBusinessLogic\ClientBusinessLogic.csproj", "{6A4A31E6-F956-4312-B63D-807ABF5CD63E}" Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ClientBusinessLogic", "ClientBusinessLogic\ClientBusinessLogic.csproj", "{6A4A31E6-F956-4312-B63D-807ABF5CD63E}"
EndProject EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ClientsDatabaseImplement", "ClientsDatabaseImplement\ClientsDatabaseImplement.csproj", "{662252C6-5C66-43CD-8D94-5360E2761EB6}" Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ClientsDatabaseImplement", "ClientsDatabaseImplement\ClientsDatabaseImplement.csproj", "{662252C6-5C66-43CD-8D94-5360E2761EB6}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Plugins", "Plugins\Plugins.csproj", "{02FB0192-28B9-480A-B38B-5AC41BB4141F}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WinFormsByPlugins", "WinFormsByPlugins\WinFormsByPlugins.csproj", "{37D75819-DB6E-4FD5-808D-B424058C4F02}"
EndProject EndProject
Global Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution GlobalSection(SolutionConfigurationPlatforms) = preSolution
@ -39,6 +43,14 @@ Global
{662252C6-5C66-43CD-8D94-5360E2761EB6}.Debug|Any CPU.Build.0 = Debug|Any CPU {662252C6-5C66-43CD-8D94-5360E2761EB6}.Debug|Any CPU.Build.0 = Debug|Any CPU
{662252C6-5C66-43CD-8D94-5360E2761EB6}.Release|Any CPU.ActiveCfg = Release|Any CPU {662252C6-5C66-43CD-8D94-5360E2761EB6}.Release|Any CPU.ActiveCfg = Release|Any CPU
{662252C6-5C66-43CD-8D94-5360E2761EB6}.Release|Any CPU.Build.0 = Release|Any CPU {662252C6-5C66-43CD-8D94-5360E2761EB6}.Release|Any CPU.Build.0 = Release|Any CPU
{02FB0192-28B9-480A-B38B-5AC41BB4141F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{02FB0192-28B9-480A-B38B-5AC41BB4141F}.Debug|Any CPU.Build.0 = Debug|Any CPU
{02FB0192-28B9-480A-B38B-5AC41BB4141F}.Release|Any CPU.ActiveCfg = Release|Any CPU
{02FB0192-28B9-480A-B38B-5AC41BB4141F}.Release|Any CPU.Build.0 = Release|Any CPU
{37D75819-DB6E-4FD5-808D-B424058C4F02}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{37D75819-DB6E-4FD5-808D-B424058C4F02}.Debug|Any CPU.Build.0 = Debug|Any CPU
{37D75819-DB6E-4FD5-808D-B424058C4F02}.Release|Any CPU.ActiveCfg = Release|Any CPU
{37D75819-DB6E-4FD5-808D-B424058C4F02}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection EndGlobalSection
GlobalSection(SolutionProperties) = preSolution GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE HideSolutionNode = FALSE

View File

@ -8,6 +8,7 @@ namespace ClientBusinessLogic.BusinessLogics
public class ClientLogic : IClientLogic public class ClientLogic : IClientLogic
{ {
private readonly IClientStorage _clientStorage; private readonly IClientStorage _clientStorage;
public ClientLogic(IClientStorage clientStorage) public ClientLogic(IClientStorage clientStorage)
{ {
_clientStorage = clientStorage; _clientStorage = clientStorage;

View File

@ -8,6 +8,7 @@ namespace ClientBusinessLogic.BusinessLogics
public class StatusLogic : IStatusLogic public class StatusLogic : IStatusLogic
{ {
private readonly IStatusStorage _statusStorage; private readonly IStatusStorage _statusStorage;
public StatusLogic(IStatusStorage statusStorage) public StatusLogic(IStatusStorage statusStorage)
{ {
_statusStorage = statusStorage; _statusStorage = statusStorage;

View File

@ -0,0 +1,16 @@
namespace Plugins
{
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 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0-windows</TargetFramework>
<Nullable>enable</Nullable>
<UseWindowsForms>true</UseWindowsForms>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\ClientsDatabaseImplement\ClientsDatabaseImplement.csproj" />
</ItemGroup>
</Project>

View File

@ -0,0 +1,7 @@
namespace Plugins
{
public class PluginsConventionElement
{
public Guid Id { get; set; }
}
}

View File

@ -0,0 +1,7 @@
namespace Plugins
{
public class PluginsConventionSaveDocument
{
public string FileName { get; set; }
}
}

View File

@ -43,7 +43,7 @@ namespace WinForms
textBoxReviews.Text = view.Reviews; textBoxReviews.Text = view.Reviews;
textBoxName.Text = view.Name; textBoxName.Text = view.Name;
myDropDownList1.SelectedValue = view.Status; myDropDownList1.SelectedValue = view.Status;
if (view.Amount != null) if (view.Amount != null && view.Amount != "")
{ {
controlInputNullableInt1.Value = Int32.Parse(view.Amount); controlInputNullableInt1.Value = Int32.Parse(view.Amount);
} }

View File

@ -58,10 +58,10 @@ namespace WinForms
private void UpdateElement() private void UpdateElement()
{ {
var form = Program.Container.Resolve<FormClient>(); var form = Program.Container.Resolve<FormClient>();
var selectedClient = myTreeView1.GetNode(typeof(ClientBindingModel)); var selectedClient = myTreeView1.GetNode(typeof(ClientViewModel));
if (selectedClient != null) if (selectedClient != null)
{ {
form.Id = Convert.ToInt32((selectedClient as ClientBindingModel).Id); form.Id = Convert.ToInt32((selectedClient as ClientViewModel).Id);
if (form.ShowDialog() == DialogResult.OK) if (form.ShowDialog() == DialogResult.OK)
{ {
LoadData(); LoadData();
@ -77,8 +77,8 @@ namespace WinForms
{ {
if (MessageBox.Show("Удалить запись", "Вопрос", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) if (MessageBox.Show("Удалить запись", "Вопрос", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
{ {
var selectedClient = myTreeView1.GetNode(typeof(ClientBindingModel)); var selectedClient = myTreeView1.GetNode(typeof(ClientViewModel));
int id = Convert.ToInt32((selectedClient as ClientBindingModel).Id); int id = Convert.ToInt32((selectedClient as ClientViewModel).Id);
try try
{ {
_clientLogic.Delete(new ClientBindingModel { Id = id }); _clientLogic.Delete(new ClientBindingModel { Id = id });

View File

@ -0,0 +1,215 @@
using ClientBusinessLogic.BusinessLogics;
using ClientsContracts.BindingModels;
using Plugins;
using VisableComponents;
using UnvisableComponents;
using VisualCompLib.Components;
using ComponentsLibraryNet60.DocumentWithTable;
using ClientsContracts.ViewModels;
using ComponentsLibraryNet60.Models;
using ClientsDatabaseImplement.Implements;
namespace WinForms
{
public class PluginsConvention : IPluginsConvention
{
private readonly ClientLogic _clientLogic = new ClientLogic(new ClientStorage());
private readonly StatusLogic _statusLogic = new StatusLogic(new StatusStorage());
private MyTreeView myTreeView1 = new MyTreeView();
public string PluginName { get; set; } = "Дерево большое";
public UserControl GetControl
{
get
{
Load();
return myTreeView1;
}
}
public PluginsConventionElement GetElement
{
get
{
var selectedClient = myTreeView1.GetNode(typeof(ClientViewModel));
int? id = null;
if (selectedClient != null)
{
id = Convert.ToInt32((selectedClient as ClientViewModel).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
{
ExcelChart excelChart1 = new ExcelChart();
var statuses = _statusLogic.Read(null);
var clients = _clientLogic.Read(null);
List<(string, int)> dates = new List<(string, int)>();
for (int i = 0; i < statuses.Count; i++)
{
int counter = 0;
for (int j = 0; j < clients.Count; j++)
{
if (clients[j].Status == statuses[i].Name && clients[j].Amount != null) counter++;
}
dates.Add((statuses[i].Name, counter));
}
excelChart1.Load(new ChartInfo
{
Path = saveDocument.FileName,
Title = "Сколько клиентов какого статуса совершали покупки",
DiagrammTitle = "Круговая диаграмма",
Dates = dates,
DirLegend = DirectionLegend.Right
});
return true;
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
return false;
}
}
public bool CreateSimpleDocument(PluginsConventionSaveDocument saveDocument)
{
try
{
WordText wordText1 = new WordText();
List<string> textList = new List<string>();
var list = _clientLogic.Read(null);
if (list != null)
{
foreach (var item in list)
{
if (item.Amount != null && item.Amount != "")
{
string clients = string.Concat("ФИО: ", item.Name, " Отзывы: ", item.Reviews);
textList.Add(clients);
}
}
string[] textArray = textList.ToArray();
wordText1.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
{
System.Text.Encoding.RegisterProvider(System.Text.CodePagesEncodingProvider.Instance);
ComponentDocumentWithTableMultiHeaderPdf componentDocumentWithTableMultiHeaderPdf1 = new ComponentDocumentWithTableMultiHeaderPdf();
var clients = _clientLogic.Read(null);
for (int i = 0; i < clients.Count; i++)
{
if (clients[i].Amount == null || clients[i].Amount == "") { clients[i].Amount = "нет"; }
}
componentDocumentWithTableMultiHeaderPdf1.CreateDoc(new ComponentDocumentWithTableHeaderDataConfig<ClientViewModel>
{
FilePath = saveDocument.FileName,
Header = "Отчет по клиентам",
ColumnsRowsWidth = new List<(int, int)> { (5, 5), (10, 5), (15, 0), (15, 0) },
Headers = new List<(int ColumnIndex, int RowIndex, string Header, string PropertyName)>
{
(0, 0, "Id", "Id"),
(1, 0, "ФИО", "Name"),
(2, 0, "Статус", "Status"),
(3, 0, "Сумма покупок", "Amount")
},
Data = clients
});
return true;
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
return false;
}
}
private void Load()
{
List<string> stringToHierachy = new List<string>() { "Status", "Amount", "Id", "Name" };
myTreeView1.addToHierarchy(stringToHierachy);
LoadData();
}
private void LoadData()
{
try
{
var list = _clientLogic.Read(null);
for (int i = 0; i < list.Count; i++)
{
if (list[i].Amount == null || list[i].Amount == "") { list[i].Amount = "нет"; }
}
myTreeView1.LoadTree(list);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
public bool DeleteElement(PluginsConventionElement element)
{
var selectedClient = myTreeView1.GetNode(typeof(ClientViewModel));
int id = Convert.ToInt32((selectedClient as ClientViewModel).Id);
try
{
_clientLogic.Delete(new ClientBindingModel { 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 FormClient(_clientLogic, _statusLogic);
}
if (element.Id.GetHashCode() >= 0)
{
FormClient form = new FormClient(_clientLogic, _statusLogic);
form.Id = element.Id.GetHashCode();
return form;
}
return null;
}
public Form GetThesaurus()
{
return new FormStatus(_statusLogic);
}
public void ReloadData()
{
LoadData();
}
}
}

View File

@ -24,6 +24,11 @@
<ItemGroup> <ItemGroup>
<ProjectReference Include="..\ClientBusinessLogic\ClientBusinessLogic.csproj" /> <ProjectReference Include="..\ClientBusinessLogic\ClientBusinessLogic.csproj" />
<ProjectReference Include="..\ClientsDatabaseImplement\ClientsDatabaseImplement.csproj" /> <ProjectReference Include="..\ClientsDatabaseImplement\ClientsDatabaseImplement.csproj" />
<ProjectReference Include="..\Plugins\Plugins.csproj" />
</ItemGroup> </ItemGroup>
<Target Name="PostBuild" AfterTargets="PostBuildEvent">
<Exec Command="copy /Y &quot;$(TargetDir)*.dll&quot; &quot;$(SolutionDir)plugin\*.dll&quot;" />
</Target>
</Project> </Project>

233
COP/WinFormsByPlugins/FormMain.Designer.cs generated Normal file
View File

@ -0,0 +1,233 @@
namespace WinFormsByPlugins
{
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,222 @@
using Plugins;
using System.Reflection;
using WinForms;
namespace WinFormsByPlugins
{
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 = "Word Documents (*.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 = "Âûáåðèòå ôàéë";
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,120 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<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,17 @@
namespace WinFormsByPlugins
{
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 @@
<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>
<ProjectReference Include="..\Plugins\Plugins.csproj" />
<ProjectReference Include="..\WinForms\WinForms.csproj" />
</ItemGroup>
</Project>

Binary file not shown.

BIN
COP/plugin/Aspose.Words.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.

BIN
COP/plugin/EPPlus.dll Normal file

Binary file not shown.

BIN
COP/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.

BIN
COP/plugin/Npgsql.dll Normal file

Binary file not shown.

Binary file not shown.

BIN
COP/plugin/PdfSharp.dll Normal file

Binary file not shown.

BIN
COP/plugin/Plugins.dll Normal file

Binary file not shown.

BIN
COP/plugin/SkiaSharp.dll Normal file

Binary file not shown.

BIN
COP/plugin/Spire.Doc.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.

BIN
COP/plugin/WinForms.dll Normal file

Binary file not shown.