LabWork04 Done

This commit is contained in:
parent e1c605a649
commit b12ff971df
58 changed files with 1172 additions and 4 deletions

View File

@ -7,13 +7,17 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Components", "Components\Co
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "WinForms", "WinForms\WinForms.csproj", "{A961BB11-3AD9-4687-B338-FCDD7887E758}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DataModels", "DataModels\DataModels.csproj", "{E47EA28F-3148-4A37-BACE-35F70E297E9F}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DataModels", "DataModels\DataModels.csproj", "{E47EA28F-3148-4A37-BACE-35F70E297E9F}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Contracts", "Contracts\Contracts.csproj", "{4BA581C3-3921-4086-A41F-C507ADD258B9}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Contracts", "Contracts\Contracts.csproj", "{4BA581C3-3921-4086-A41F-C507ADD258B9}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DatabaseImplement", "DatabaseImplement\DatabaseImplement.csproj", "{4007A4AB-770E-4E72-8337-BC342A8C09BD}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DatabaseImplement", "DatabaseImplement\DatabaseImplement.csproj", "{4007A4AB-770E-4E72-8337-BC342A8C09BD}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BusinessLogics", "BusinessLogics\BusinessLogics.csproj", "{324D5883-FDDE-46D1-ADF0-31D46EF95AFF}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BusinessLogics", "BusinessLogics\BusinessLogics.csproj", "{324D5883-FDDE-46D1-ADF0-31D46EF95AFF}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Plugins", "Plugins\Plugins.csproj", "{C8AE2AD4-952F-4D20-B15B-F329B30CE0FC}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WinFormsPlugins", "WinFormsPlugins\WinFormsPlugins.csproj", "{10BD4FBA-80C9-4B31-BE68-5A2F128F5289}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
@ -45,6 +49,14 @@ Global
{324D5883-FDDE-46D1-ADF0-31D46EF95AFF}.Debug|Any CPU.Build.0 = Debug|Any CPU
{324D5883-FDDE-46D1-ADF0-31D46EF95AFF}.Release|Any CPU.ActiveCfg = Release|Any CPU
{324D5883-FDDE-46D1-ADF0-31D46EF95AFF}.Release|Any CPU.Build.0 = Release|Any CPU
{C8AE2AD4-952F-4D20-B15B-F329B30CE0FC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{C8AE2AD4-952F-4D20-B15B-F329B30CE0FC}.Debug|Any CPU.Build.0 = Debug|Any CPU
{C8AE2AD4-952F-4D20-B15B-F329B30CE0FC}.Release|Any CPU.ActiveCfg = Release|Any CPU
{C8AE2AD4-952F-4D20-B15B-F329B30CE0FC}.Release|Any CPU.Build.0 = Release|Any CPU
{10BD4FBA-80C9-4B31-BE68-5A2F128F5289}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{10BD4FBA-80C9-4B31-BE68-5A2F128F5289}.Debug|Any CPU.Build.0 = Debug|Any CPU
{10BD4FBA-80C9-4B31-BE68-5A2F128F5289}.Release|Any CPU.ActiveCfg = Release|Any CPU
{10BD4FBA-80C9-4B31-BE68-5A2F128F5289}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE

View File

@ -0,0 +1,75 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Plugins
{
/// <summary>
/// Интерфейс-соглашение для плагинов
/// </summary>
public interface IPluginsConvention
{
/// <summary>
/// Название плагина
/// </summary>
string PluginName { get; }
/// <summary>
/// Получение контрола для вывода набора данных
/// </summary>
UserControl GetControl { get; }
/// <summary>
/// Получение элемента, выбранного в контроле
/// </summary>
PluginsConventionElement GetElement { get; }
/// <summary>
/// Получение формы для создания/редактирования объекта
/// </summary>
/// <param name="element"></param>
/// <returns></returns>
Form GetForm(PluginsConventionElement element);
/// <summary>
/// Получение формы для работы со справочником
/// </summary>
/// <returns></returns>
Form GetThesaurus();
/// <summary>
/// Удаление элемента
/// </summary>
/// <param name="element"></param>
/// <returns></returns>
bool DeleteElement(PluginsConventionElement element);
/// <summary>
/// Обновление набора данных в контроле
/// </summary>
void ReloadData();
/// <summary>
/// Создание простого документа
/// </summary>
/// <param name="saveDocument"></param>
/// <returns></returns>
bool CreateSimpleDocument(PluginsConventionSaveDocument saveDocument);
/// <summary>
/// Создание документа с настраиваемой таблицей
/// </summary>
/// <param name="saveDocument"></param>
/// <returns></returns>
bool CreateTableDocument(PluginsConventionSaveDocument saveDocument);
/// <summary>
/// Создание документа с диаграммой
/// </summary>
/// <param name="saveDocument"></param>
/// <returns></returns>
bool CreateChartDocument(PluginsConventionSaveDocument saveDocument);
}
}

View File

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

View File

@ -0,0 +1,19 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Plugins
{
/// <summary>
/// Класс для передачи объекта на форму и удаления
/// </summary>
public class PluginsConventionElement
{
/// <summary>
/// Глобальный уникальный идентификатор
/// </summary>
public Guid Id { get; set; }
}
}

View File

@ -0,0 +1,19 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Plugins
{
/// <summary>
/// Класс для передачи данных в методы создания документов
/// </summary>
public class PluginsConventionSaveDocument
{
/// <summary>
/// Путь к файлу
/// </summary>
public string FileName { get; set; } = string.Empty;
}
}

View File

@ -0,0 +1,335 @@
using BusinessLogics.BusinessLogics;
using Components.NonVisualComponents;
using ComponentsLibrary.NonVisualComponents.HelperModels;
using ComponentsLibrary.NonVisualComponents;
using ComponentsLibrary.VisualComponents;
using ComponentsLibraryNet60.DocumentWithTable;
using ComponentsLibraryNet60.Models;
using Contracts.BindingModels;
using Contracts.BusinessLogicsContracts;
using Contracts.ViewModels;
using DatabaseImplement.Implements;
using Microsoft.Extensions.Logging;
using Plugins;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using NLog.Extensions.Logging;
namespace WinForms
{
/// <summary>
/// Реализация интерфейса-соглашения для плагинов
/// </summary>
public class PluginsConvention : IPluginsConvention
{
/// <summary>
/// Название плагина
/// </summary>
public string PluginName => "Orders";
/// <summary>
/// Визуальный компонент для вывода списка в виде дерева
/// </summary>
private readonly UserTreeView _userTreeView;
/// <summary>
/// Бизнес-логика для сущности "Счет"
/// </summary>
private readonly IOrderLogic _orderLogic;
/// <summary>
/// Бизнес-логика для сущности "Тип заказа"
/// </summary>
private readonly IOrderTypeLogic _orderTypeLogic;
/// <summary>
/// Конструктор
/// </summary>
public PluginsConvention()
{
_userTreeView = new UserTreeView();
var hierarchy = new List<string>()
{
"Type",
"Sum",
"Id",
"WaiterFullName"
};
_userTreeView.SetHierarchy(hierarchy);
var loggerFactory = LoggerFactory.Create(builder => builder.AddNLog());
var orderLogicLogger = loggerFactory.CreateLogger<OrderLogic>();
var orderTypeLogicLogger = loggerFactory.CreateLogger<OrderTypeLogic>();
_orderLogic = new OrderLogic(orderLogicLogger, new OrderStorage());
_orderTypeLogic = new OrderTypeLogic(orderTypeLogicLogger, new OrderTypeStorage());
}
/// <summary>
/// Получение контрола для вывода набора данных
/// </summary>
public UserControl GetControl
{
get
{
ReloadData();
return _userTreeView;
}
}
/// <summary>
/// Получение элемента, выбранного в контроле
/// </summary>
public PluginsConventionElement GetElement
{
get
{
var order = _userTreeView.GetSelectedObject<OrderViewModel>();
int id = -1;
if (order != null)
{
id = order.Id;
}
byte[] bytes = new byte[16];
BitConverter.GetBytes(id).CopyTo(bytes, 0);
return new PluginsConventionElement { Id = new Guid(bytes) };
}
}
/// <summary>
/// Получение формы для создания/редактирования объекта
/// </summary>
/// <param name="element"></param>
/// <returns></returns>
public Form GetForm(PluginsConventionElement element)
{
if (element == null)
{
return new FormOrder(_orderLogic, _orderTypeLogic);
}
if (element.Id.GetHashCode() >= 0)
{
byte[] bytes = element.Id.ToByteArray();
int Id = BitConverter.ToInt32(bytes, 0);
var form = new FormOrder(_orderLogic, _orderTypeLogic);
form.Id = Id;
return form;
}
return null;
}
/// <summary>
/// Получение формы для работы со справочником
/// </summary>
/// <returns></returns>
public Form GetThesaurus()
{
return new FormOrderTypes(_orderTypeLogic);
}
/// <summary>
/// Удаление элемента
/// </summary>
/// <param name="element"></param>
/// <returns></returns>
public bool DeleteElement(PluginsConventionElement element)
{
if (MessageBox.Show("Удалить запись?", "Вопрос", MessageBoxButtons.YesNo, MessageBoxIcon.Question) != DialogResult.Yes)
{
return false;
}
byte[] bytes = element.Id.ToByteArray();
int Id = BitConverter.ToInt32(bytes, 0);
try
{
_orderLogic.Delete(new OrderBindingModel() { Id = Id });
ReloadData();
return true;
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
return false;
}
}
/// <summary>
/// Обновление набора данных в контроле
/// </summary>
public void ReloadData()
{
try
{
var orders = _orderLogic.ReadList(null);
if (orders == null)
{
return;
}
foreach (var order in orders)
{
if (string.IsNullOrEmpty(order.Sum))
{
order.Sum = "По акции";
}
_userTreeView.AddObjectToTree(order);
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
/// <summary>
/// Создание простого документа
/// </summary>
/// <param name="saveDocument"></param>
/// <returns></returns>
public bool CreateSimpleDocument(PluginsConventionSaveDocument saveDocument)
{
try
{
var orders = _orderLogic.ReadList(null);
if (orders == null)
{
return false;
}
string title = "Информация по аукционным счетам.";
List<string> rows = new List<string>();
foreach (var order in orders)
{
if (string.IsNullOrEmpty(order.Sum))
{
string row = $"ФИО официанта: {order.WaiterFullName} -- Описание счета: {order.Info}";
rows.Add(row);
}
}
string[] rowsArray = rows.ToArray();
var bigTextComponent = new BigTextComponent();
bigTextComponent.CreateDocument(saveDocument.FileName, title, rowsArray);
return true;
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
return false;
}
}
/// <summary>
/// Создание документа с настраиваемой таблицей
/// </summary>
/// <param name="saveDocument"></param>
/// <returns></returns>
public bool CreateTableDocument(PluginsConventionSaveDocument saveDocument)
{
try
{
var orders = _orderLogic.ReadList(null);
if (orders == null)
{
return false;
}
foreach (var order in orders)
{
if (string.IsNullOrEmpty(order.Sum))
{
order.Sum = "По акции";
}
}
var componentDocumentWithTableMultiHeaderWord = new ComponentDocumentWithTableMultiHeaderWord();
componentDocumentWithTableMultiHeaderWord.CreateDoc(new ComponentDocumentWithTableHeaderDataConfig<OrderViewModel>
{
FilePath = saveDocument.FileName,
Header = "Информация по счетам.",
ColumnsRowsWidth = new List<(int Column, int Row)>()
{
(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, "ФИО официанта", "WaiterFullName"),
(2, 0, "Тип заказа", "Type"),
(3, 0, "Сумма заказа", "Sum")
},
Data = orders,
});
return true;
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
return false;
}
}
/// <summary>
/// Создание документа с диаграммой
/// </summary>
/// <param name="saveDocument"></param>
/// <returns></returns>
public bool CreateChartDocument(PluginsConventionSaveDocument saveDocument)
{
try
{
var orders = _orderLogic.ReadList(null);
if (orders == null)
{
return false;
}
var orderTypes = _orderTypeLogic.ReadList(null);
if (orderTypes == null)
{
return false;
}
List<(double, string)> items = new List<(double, string)>();
foreach (var orderType in orderTypes)
{
int count = 0;
foreach (var order in orders)
{
if (order.Type == orderType.Name && string.IsNullOrEmpty(order.Sum))
{
count++;
}
}
items.Add((count, orderType.Name));
}
var pdfPieChart = new PdfPieChart();
pdfPieChart.CreatePieChart(new DataForPieChart(saveDocument.FileName, "Информация по оплаченным счетам каждого типа заказов", "Круговая диаграмма", DiagramLegendEnum.Top, "Типы заказов", items));
return true;
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
return false;
}
}
}
}

View File

@ -5,6 +5,7 @@ using DatabaseImplement.Implements;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using NLog.Extensions.Logging;
using Plugins;
using System;
namespace WinForms

View File

@ -35,6 +35,7 @@
<ProjectReference Include="..\BusinessLogics\BusinessLogics.csproj" />
<ProjectReference Include="..\Components\Components.csproj" />
<ProjectReference Include="..\Contracts\Contracts.csproj" />
<ProjectReference Include="..\Plugins\Plugins.csproj" />
</ItemGroup>
<ItemGroup>

View File

@ -0,0 +1,184 @@
namespace WinFormsPlugins
{
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,309 @@
using DocumentFormat.OpenXml.Office2010.CustomUI;
using Plugins;
using System.Reflection;
namespace WinFormsPlugins
{
/// <summary>
/// Ãëàâíàÿ ôîðìà
/// </summary>
public partial class FormMain : Form
{
/// <summary>
/// Ïëàãèíû
/// </summary>
private readonly Dictionary<string, IPluginsConvention> _plugins;
/// <summary>
/// Âûáðàííûé ïëàãèí
/// </summary>
private string _selectedPlugin;
/// <summary>
/// Êîíñòðóêòîð
/// </summary>
public FormMain()
{
InitializeComponent();
_plugins = LoadPlugins();
_selectedPlugin = string.Empty;
}
/// <summary>
/// Çàãðóçêà ïëàãèíîâ
/// </summary>
/// <returns></returns>
private Dictionary<string, IPluginsConvention> LoadPlugins()
{
var plugins = new Dictionary<string, IPluginsConvention>();
string pluginsDir = Directory.GetParent(Directory.GetCurrentDirectory())!
.Parent!.Parent!.FullName + "\\plugins";
string[] dllFiles = Directory.GetFiles(pluginsDir, "*.dll", SearchOption.AllDirectories);
foreach (string dllFile in dllFiles)
{
try
{
Assembly assembly = Assembly.LoadFrom(dllFile);
Type[] types = assembly.GetTypes();
foreach (var type in types)
{
if (typeof(IPluginsConvention).IsAssignableFrom(type) && !type.IsInterface)
{
var plugin = (IPluginsConvention)Activator.CreateInstance(type)!;
plugins.Add(plugin.PluginName, plugin);
CreateToolStripMenuItem(plugin.PluginName);
}
}
}
catch (Exception ex)
{
// Ïðîñòè, Ãîñïîäè, ãðåøíèêà, çà òî, ÷òî ïðÿ÷ó âûëåçàþùèå Exceptions, íî ÿ íå íàø¸ë êàê èõ ïîôèêñèòü
// Unable to load one or more of the requested types
Console.WriteLine($"Îøèáêà ïðè çàãðóçêå ñáîðêè {dllFile}: {ex.Message}");
}
}
return plugins;
}
/// <summary>
/// Ñîçäàòü ToolStripMenuItem äëÿ ïëàãèíà
/// </summary>
/// <param name="pluginName"></param>
private void CreateToolStripMenuItem(string pluginName)
{
var menuItem = new ToolStripMenuItem(pluginName);
menuItem.Click += (object? sender, EventArgs e) =>
{
_selectedPlugin = pluginName;
IPluginsConvention plugin = _plugins![pluginName];
UserControl userControl = plugin.GetControl;
if (userControl != null)
{
panelControl.Controls.Clear();
plugin.ReloadData();
userControl.Dock = DockStyle.Fill;
panelControl.Controls.Add(userControl);
}
};
ControlsStripMenuItem.DropDownItems.Add(menuItem);
}
/// <summary>
/// Îáðàáîòêà íàæàòèÿ êíîïîê
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
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;
}
}
/// <summary>
/// Îòîáðàçèòü ôîðìó äëÿ ðàáîòû ñî ñïðàâî÷íèêîì
/// </summary>
private void ShowThesaurus()
{
_plugins[_selectedPlugin].GetThesaurus()?.Show();
}
/// <summary>
/// Ñîçäàòü ýëåìåíò
/// </summary>
private void AddNewElement()
{
var form = _plugins[_selectedPlugin].GetForm(null);
if (form != null && form.ShowDialog() == DialogResult.OK)
{
_plugins[_selectedPlugin].ReloadData();
}
}
/// <summary>
/// Ðåäàêòèðîâàòü ýëåìåíò
/// </summary>
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();
}
}
/// <summary>
/// Óäàëèòü ýëåìåíò
/// </summary>
private void DeleteElement()
{
var element = _plugins[_selectedPlugin].GetElement;
if (element == null)
{
MessageBox.Show("Íåò âûáðàííîãî ýëåìåíòà!", "Îøèáêà", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
if (_plugins[_selectedPlugin].DeleteElement(element))
{
_plugins[_selectedPlugin].ReloadData();
}
}
/// <summary>
/// Ñîçäàòü ïðîñòîé äîêóìåíò
/// </summary>
private void CreateSimpleDoc()
{
using (var dialog = new SaveFileDialog { Filter = "xlsx|*.xlsx" })
{
if (dialog.ShowDialog() == DialogResult.OK)
{
string fileName = dialog.FileName.ToString();
if (_plugins[_selectedPlugin].CreateSimpleDocument(new PluginsConventionSaveDocument() { FileName = fileName }))
{
MessageBox.Show("Äîêóìåíò ñîõðàíåí", "Ñîçäàíèå äîêóìåíòà", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
else
{
MessageBox.Show("Îøèáêà ïðè ñîçäàíèè äîêóìåíòà", "Îøèáêà", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
}
/// <summary>
/// Ñîçäàòü äîêóìåíò ñ íàñòðàèâàåìîé òàáëèöåé
/// </summary>
private void CreateTableDoc()
{
using (var dialog = new SaveFileDialog { Filter = "docx|*.docx" })
{
if (dialog.ShowDialog() == DialogResult.OK)
{
string fileName = dialog.FileName.ToString();
if (_plugins[_selectedPlugin].CreateTableDocument(new PluginsConventionSaveDocument() { FileName = fileName }))
{
MessageBox.Show("Äîêóìåíò ñîõðàíåí", "Ñîçäàíèå äîêóìåíòà", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
else
{
MessageBox.Show("Îøèáêà ïðè ñîçäàíèè äîêóìåíòà", "Îøèáêà", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
}
/// <summary>
/// Ñîçäàòü äîêóìåíò ñ äèàãðàììîé
/// </summary>
private void CreateChartDoc()
{
using (var dialog = new SaveFileDialog { Filter = "pdf|*.pdf" })
{
if (dialog.ShowDialog() == DialogResult.OK)
{
string fileName = dialog.FileName.ToString();
if (_plugins[_selectedPlugin].CreateChartDocument(new PluginsConventionSaveDocument() { FileName = fileName }))
{
MessageBox.Show("Äîêóìåíò ñîõðàíåí", "Ñîçäàíèå äîêóìåíòà", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
else
{
MessageBox.Show("Îøèáêà ïðè ñîçäàíèè äîêóìåíòà", "Îøèáêà", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
}
/// <summary>
/// Îòîáðàçèòü ôîðìó äëÿ ðàáîòû ñî ñïðàâî÷íèêîì
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ThesaurusToolStripMenuItem_Click(object sender, EventArgs e) => ShowThesaurus();
/// <summary>
/// Ñîçäàòü ýëåìåíò
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void AddElementToolStripMenuItem_Click(object sender, EventArgs e) => AddNewElement();
/// <summary>
/// Ðåäàêòèðîâàòü ýëåìåíò
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void UpdElementToolStripMenuItem_Click(object sender, EventArgs e) => UpdateElement();
/// <summary>
/// Óäàëèòü ýëåìåíò
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void DelElementToolStripMenuItem_Click(object sender, EventArgs e) => DeleteElement();
/// <summary>
/// Ñîçäàòü ïðîñòîé äîêóìåíò
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void SimpleDocToolStripMenuItem_Click(object sender, EventArgs e) => CreateSimpleDoc();
/// <summary>
/// Ñîçäàòü äîêóìåíò ñ íàñòðàèâàåìîé òàáëèöåé
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void TableDocToolStripMenuItem_Click(object sender, EventArgs e) => CreateTableDoc();
/// <summary>
/// Ñîçäàòü äîêóìåíò ñ äèàãðàììîé
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
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,61 @@
using BusinessLogics.BusinessLogics;
using Contracts.BusinessLogicsContracts;
using Contracts.StoragesContracts;
using DatabaseImplement.Implements;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using NLog.Extensions.Logging;
namespace WinFormsPlugins
{
internal static class Program
{
/// <summary>
/// IoC-êîíòåéíåð
/// </summary>
private static ServiceProvider? _serviceProvider;
/// <summary>
/// IoC-êîíòåéíåð
/// </summary>
public static ServiceProvider? ServiceProvider => _serviceProvider;
/// <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();
var services = new ServiceCollection();
ConfigureServices(services);
_serviceProvider = services.BuildServiceProvider();
Application.Run(new FormMain());
}
/// <summary>
/// Êîíôèãóðàöèÿ ñåðâèñîâ
/// </summary>
/// <param name="services"></param>
private static void ConfigureServices(ServiceCollection services)
{
// Ëîããåð
services.AddLogging(option =>
{
option.SetMinimumLevel(LogLevel.Information);
option.AddNLog("nlog.config");
});
// IoC-êîíòåéíåð, áèçíåñ-ëîãèêà
services.AddTransient<IOrderLogic, OrderLogic>();
services.AddTransient<IOrderTypeLogic, OrderTypeLogic>();
// IoC-êîíòåéíåð, ôîðìû îòîáðàæåíèÿ
services.AddTransient<FormMain>();
}
}
}

View File

@ -0,0 +1,22 @@
<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="..\Components\Components.csproj" />
<ProjectReference Include="..\Contracts\Contracts.csproj" />
<ProjectReference Include="..\Plugins\Plugins.csproj" />
<ProjectReference Include="..\WinForms\WinForms.csproj" />
</ItemGroup>
<ItemGroup>
<Folder Include="plugins\" />
</ItemGroup>
</Project>

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.