This commit is contained in:
DyCTaTOR 2024-12-09 22:40:09 +04:00
parent 7bd3733c6e
commit 9fe6519826
81 changed files with 884 additions and 42 deletions

View File

@ -0,0 +1,64 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Plugins
{
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>net8.0-windows</TargetFramework>
<Nullable>enable</Nullable>
<UseWindowsForms>true</UseWindowsForms>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>
</Project>

View File

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

View File

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

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.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -22,6 +22,7 @@
<ProjectReference Include="..\Businesslogic\BusinessLogics.csproj" />
<ProjectReference Include="..\Contracts\Contracts.csproj" />
<ProjectReference Include="..\DatabaseImplement\DatabaseImplement.csproj" />
<ProjectReference Include="..\Plugins\Plugins.csproj" />
<ProjectReference Include="..\WinFormsLibrary1\WinFormsLibrary1.csproj" />
</ItemGroup>

View File

@ -0,0 +1,211 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Plugins;
using Contracts.BusinessLogicContracts;
using Library14Petrushin;
using WinFormsLibrary1;
using Library15Gerimovich.OfficePackage.HelperModels;
using Contracts.ViewModels;
using BusinessLogics.BusinessLogics;
using DatabaseImplement.Implements;
using Contracts.BindingModels;
using DatabaseImplement.Models;
using Library15Gerimovich;
using Library14Petrushin.Classes;
namespace Forms
{
public class PluginsConvention : IPluginsConvention
{
private readonly IProductLogic _productLogic;
private readonly ICategoryLogic _categoryLogic;
private readonly HierarchicalTreeView _myTreeView;
private readonly ComponentWithBigText wordLongTextComponent;
private readonly WordTablesComponent excelDiagramComponent;
private readonly PdfCirclDiagr componentDocumentWithTableMultiHeaderPdf;
public string PluginName { get; set; } = "Products";
public UserControl GetControl
{
get { return _myTreeView; }
}
public PluginsConvention()
{
_productLogic = new ProductLogic(new ProductStorage());
_categoryLogic = new CategoryLogic(new CategoryStorage());
wordLongTextComponent = new();
excelDiagramComponent = new();
componentDocumentWithTableMultiHeaderPdf = new();
_myTreeView = new();
}
public PluginsConventionElement GetElement
{
get
{
int Id = int.Parse(_myTreeView.GetSelectedObject<ProductViewModel>()!.Id);
byte[] bytes = new byte[16];
BitConverter.GetBytes(Id).CopyTo(bytes, 0);
Guid guid = new Guid(bytes);
return new PluginsConventionElement() { Id = guid };
}
}
public Form GetForm(PluginsConventionElement element)
{
if (element == null)
{
return new ProductForm(_productLogic, _categoryLogic);
}
else
{
int id = element.Id.GetHashCode();
int? idl = id;
ProductViewModel model = _productLogic.ReadElement(new Contracts.SearchModels.ProductSearchModel { Id = idl });
ProductForm form = new ProductForm(_productLogic, _categoryLogic, model);
// form.Id = element.Id.GetHashCode();
return form;
}
}
public Form GetThesaurus()
{
return new CategoryForm(_categoryLogic);
}
public bool DeleteElement(PluginsConventionElement element)
{
_productLogic.Delete(
new ProductBindingModel { Id = element.Id.GetHashCode() }
);
return true;
}
public void ReloadData()
{
try
{
var products = _productLogic.ReadList(null);
var hierarchy = new List<string> { "Category", "CountOnStorageS", "Id", "Name" };
var alwaysNewBranch = new Dictionary<string, bool> { { "Name", true } };
_myTreeView.SetHierarchy(hierarchy, alwaysNewBranch);
foreach (var product in products)
{
_myTreeView.AddObjectToTree(product, "Name");
}
}
catch (Exception ex)
{
MessageBox.Show(
ex.Message,
"Ошибка",
MessageBoxButtons.OK,
MessageBoxIcon.Error
);
}
}
public bool CreateSimpleDocument(PluginsConventionSaveDocument saveDocument)
{
using (var saveFileDialog = new SaveFileDialog())
{
saveFileDialog.Filter = "Excel files (*.xlsx)|*.xlsx|All files (*.*)|*.*";
if (saveFileDialog.ShowDialog() == DialogResult.OK)
{
var products = _productLogic.ReadList(null);
var rows = products.Select(p => $"{p.Name} - {p.Description}").ToArray();
var component = new ComponentWithBigText();
component.CreateDocument(saveFileDialog.FileName, "Список продуктов", rows);
MessageBox.Show("Документ успешно создан.");
}
return true;
}
}
public bool CreateTableDocument(PluginsConventionSaveDocument saveDocument)
{
using (var saveFileDialog = new SaveFileDialog())
{
saveFileDialog.Filter = "Word files (*.docx)|*.docx|All files (*.*)|*.*";
if (saveFileDialog.ShowDialog() == DialogResult.OK)
{
var products = _productLogic.ReadList(null);
if (products == null || products.Count == 0)
{
MessageBox.Show("Нет данных для создания документа.");
return false;
}
var headers = new List<(int, int, string, string)>
{
(0, 0, "Id", "Id"),
(1, 0, "Name", "Name"),
(2, 0, "Category", "Category"),
(3, 0, "CountOnStorage", "CountOnStorage")
};
var columnsRowsWidth = new List<(int Column, int Row)>
{
(100, 0),
(200, 1),
(150, 2),
(150, 3)
};
var config = new WordTableWithData<ProductViewModel>
{
FileName = saveFileDialog.FileName,
Title = "Список продуктов",
Headers = headers,
Data = products,
ColumnsRowsWidth = columnsRowsWidth,
NullReplace = "-",
};
var wordTables = new WordTablesComponent();
wordTables.CreateTable(config);
MessageBox.Show("Документ успешно создан.");
}
return true;
}
}
public bool CreateChartDocument(PluginsConventionSaveDocument saveDocument)
{
using (var saveFileDialog = new SaveFileDialog())
{
saveFileDialog.Filter = "PDF files (*.pdf)|*.pdf|All files (*.*)|*.*";
if (saveFileDialog.ShowDialog() == DialogResult.OK)
{
var products = _productLogic.ReadList(null);
var categories = products.Where(p => p.CountOnStorage == 0).GroupBy(p => p.Category)
.Select(g => new ChartData
{
SeriesName = g.Key,
Value = g.Count(p => p.CountOnStorage == 0)
}).ToList();
if (categories.Count == 0)
{
MessageBox.Show("Нет данных для создания диаграммы.");
return false;
}
var component = new PdfCirclDiagr();
component.GeneratePdf(saveFileDialog.FileName,
"Диаграмма продуктов", "Продукты без наличия",
LegendPosition.Right,
categories);
MessageBox.Show("Документ успешно создан.");
}
return true;
}
}
}
}

View File

@ -0,0 +1,175 @@
using DocumentFormat.OpenXml.Spreadsheet;
namespace Forms
{
partial class PluginsForm
{
/// <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()
{
menuStrip = new MenuStrip();
ControlsStripMenuItem = new ToolStripMenuItem();
ActionsToolStripMenuItem = new ToolStripMenuItem();
ThesaurusToolStripMenuItem = new ToolStripMenuItem();
AddElementToolStripMenuItem = new ToolStripMenuItem();
UpdElementToolStripMenuItem = new ToolStripMenuItem();
DelElementToolStripMenuItem = new ToolStripMenuItem();
DocsToolStripMenuItem = new ToolStripMenuItem();
SimpleDocToolStripMenuItem = new ToolStripMenuItem();
TableDocToolStripMenuItem = new ToolStripMenuItem();
ChartDocToolStripMenuItem = new ToolStripMenuItem();
panelControl = new Panel();
menuStrip.SuspendLayout();
SuspendLayout();
//
// menuStrip
//
menuStrip.Items.AddRange(new ToolStripItem[] { ControlsStripMenuItem, ActionsToolStripMenuItem, DocsToolStripMenuItem });
menuStrip.Location = new Point(0, 0);
menuStrip.Name = "menuStrip";
menuStrip.Size = new Size(800, 24);
menuStrip.TabIndex = 0;
menuStrip.Text = "Меню";
//
// ControlsStripMenuItem
//
ControlsStripMenuItem.Name = "ControlsStripMenuItem";
ControlsStripMenuItem.Size = new Size(90, 20);
ControlsStripMenuItem.Text = "Компоненты";
//
// ActionsToolStripMenuItem
//
ActionsToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { ThesaurusToolStripMenuItem, AddElementToolStripMenuItem, UpdElementToolStripMenuItem, DelElementToolStripMenuItem });
ActionsToolStripMenuItem.Name = "ActionsToolStripMenuItem";
ActionsToolStripMenuItem.Size = new Size(70, 20);
ActionsToolStripMenuItem.Text = "Действия";
//
// ThesaurusToolStripMenuItem
//
ThesaurusToolStripMenuItem.Name = "ThesaurusToolStripMenuItem";
ThesaurusToolStripMenuItem.ShortcutKeys = Keys.Control | Keys.I;
ThesaurusToolStripMenuItem.Size = new Size(180, 22);
ThesaurusToolStripMenuItem.Text = "Справочник";
ThesaurusToolStripMenuItem.Click += ThesaurusToolStripMenuItem_Click;
//
// AddElementToolStripMenuItem
//
AddElementToolStripMenuItem.Name = "AddElementToolStripMenuItem";
AddElementToolStripMenuItem.ShortcutKeys = Keys.Control | Keys.A;
AddElementToolStripMenuItem.Size = new Size(180, 22);
AddElementToolStripMenuItem.Text = "Добавить";
AddElementToolStripMenuItem.Click += AddElementToolStripMenuItem_Click;
//
// UpdElementToolStripMenuItem
//
UpdElementToolStripMenuItem.Name = "UpdElementToolStripMenuItem";
UpdElementToolStripMenuItem.ShortcutKeys = Keys.Control | Keys.U;
UpdElementToolStripMenuItem.Size = new Size(180, 22);
UpdElementToolStripMenuItem.Text = "Изменить";
UpdElementToolStripMenuItem.Click += UpdElementToolStripMenuItem_Click;
//
// DelElementToolStripMenuItem
//
DelElementToolStripMenuItem.Name = "DelElementToolStripMenuItem";
DelElementToolStripMenuItem.ShortcutKeys = Keys.Control | Keys.D;
DelElementToolStripMenuItem.Size = new Size(180, 22);
DelElementToolStripMenuItem.Text = "Удалить";
DelElementToolStripMenuItem.Click += DelElementToolStripMenuItem_Click;
//
// DocsToolStripMenuItem
//
DocsToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { SimpleDocToolStripMenuItem, TableDocToolStripMenuItem, ChartDocToolStripMenuItem });
DocsToolStripMenuItem.Name = "DocsToolStripMenuItem";
DocsToolStripMenuItem.Size = new Size(82, 20);
DocsToolStripMenuItem.Text = "Документы";
//
// SimpleDocToolStripMenuItem
//
SimpleDocToolStripMenuItem.Name = "SimpleDocToolStripMenuItem";
SimpleDocToolStripMenuItem.ShortcutKeys = Keys.Control | Keys.S;
SimpleDocToolStripMenuItem.Size = new Size(233, 22);
SimpleDocToolStripMenuItem.Text = "Простой документ";
SimpleDocToolStripMenuItem.Click += SimpleDocToolStripMenuItem_Click;
//
// TableDocToolStripMenuItem
//
TableDocToolStripMenuItem.Name = "TableDocToolStripMenuItem";
TableDocToolStripMenuItem.ShortcutKeys = Keys.Control | Keys.T;
TableDocToolStripMenuItem.Size = new Size(233, 22);
TableDocToolStripMenuItem.Text = "Документ с таблицой";
TableDocToolStripMenuItem.Click += TableDocToolStripMenuItem_Click;
//
// ChartDocToolStripMenuItem
//
ChartDocToolStripMenuItem.Name = "ChartDocToolStripMenuItem";
ChartDocToolStripMenuItem.ShortcutKeys = Keys.Control | Keys.C;
ChartDocToolStripMenuItem.Size = new Size(233, 22);
ChartDocToolStripMenuItem.Text = "Документ с диаграммой";
ChartDocToolStripMenuItem.Click += ChartDocToolStripMenuItem_Click;
//
// panelControl
//
panelControl.Dock = DockStyle.Fill;
panelControl.Location = new Point(0, 24);
panelControl.Name = "panelControl";
panelControl.Size = new Size(800, 426);
panelControl.TabIndex = 1;
//
// FormMain
//
AutoScaleDimensions = new SizeF(7F, 15F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(800, 450);
Controls.Add(panelControl);
Controls.Add(menuStrip);
MainMenuStrip = menuStrip;
Name = "FormMain";
StartPosition = FormStartPosition.CenterScreen;
Text = "Главная форма";
WindowState = FormWindowState.Maximized;
KeyDown += FormMain_KeyDown;
menuStrip.ResumeLayout(false);
menuStrip.PerformLayout();
ResumeLayout(false);
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,226 @@
using DocumentFormat.OpenXml.Office2010.CustomUI;
using Plugins;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Forms
{
public partial class PluginsForm : Form
{
private readonly Dictionary<string, IPluginsConvention> _plugins;
private string _selectedPlugin;
public PluginsForm()
{
InitializeComponent();
_plugins = LoadPlugins();
_selectedPlugin = string.Empty;
}
private Dictionary<string, IPluginsConvention> LoadPlugins()
{
var plugins = new Dictionary<string, IPluginsConvention>();
string pluginsDir = Directory.GetParent(Directory.GetCurrentDirectory())!.Parent!.Parent!.Parent!.FullName + "\\PluginsP";
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);
CreateMenuItem(plugin.PluginName);
}
}
}
catch (Exception ex)
{
Console.WriteLine($"Ошибка при загрузке сборки {dllFile}: {ex.Message}");
}
}
return plugins;
}
private void CreateMenuItem(string pluginName)
{
ToolStripMenuItem menuItem = new(pluginName);
menuItem.Click += (object? sender, EventArgs e) =>
{
UserControl userControl = _plugins[pluginName].GetControl;
if (userControl != null)
{
panelControl.Controls.Clear();
userControl.Dock = DockStyle.Fill;
_plugins[pluginName].ReloadData();
_selectedPlugin = pluginName;
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()
{
Filter = "Word Files|*.docx"
};
if (saveFileDialog.ShowDialog() == DialogResult.OK)
{
_plugins[_selectedPlugin].CreateSimpleDocument(new PluginsConventionSaveDocument() { FileName = saveFileDialog.FileName });
}
}
private void CreateTableDoc()
{
SaveFileDialog saveFileDialog = new()
{
Filter = "PDF Files|*.pdf"
};
if (saveFileDialog.ShowDialog() == DialogResult.OK)
{
_plugins[_selectedPlugin].CreateTableDocument(new PluginsConventionSaveDocument() { FileName = saveFileDialog.FileName });
}
}
private void CreateChartDoc()
{
SaveFileDialog saveFileDialog = new()
{
Filter = "Excel Files|*.xlsx"
};
if (saveFileDialog.ShowDialog() == DialogResult.OK)
{
_plugins[_selectedPlugin].CreateChartDocument(new PluginsConventionSaveDocument() { FileName = saveFileDialog.FileName });
}
}
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

@ -28,7 +28,7 @@ namespace WinFormsApp1
ConfigureServices(services);
_serviceProvider = services.BuildServiceProvider();
Application.Run(_serviceProvider.GetRequiredService<Form1>());
Application.Run(_serviceProvider.GetRequiredService<PluginsForm>());
}
private static void ConfigureServices(ServiceCollection services)
@ -48,6 +48,7 @@ namespace WinFormsApp1
services.AddTransient<ProductForm>();
services.AddTransient<MainForm>();
services.AddTransient<Form1>();
services.AddTransient<PluginsForm>();
}
}
}

View File

@ -15,6 +15,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Contracts", "Contracts\Cont
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DatabaseImplement", "DatabaseImplement\DatabaseImplement.csproj", "{02E84641-9C21-43C3-99CD-765878F8C8F6}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Plugins", "Plugins\Plugins.csproj", "{1E1177E8-5664-4A09-AE2A-1C58F3A7CADD}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@ -45,6 +47,10 @@ Global
{02E84641-9C21-43C3-99CD-765878F8C8F6}.Debug|Any CPU.Build.0 = Debug|Any CPU
{02E84641-9C21-43C3-99CD-765878F8C8F6}.Release|Any CPU.ActiveCfg = Release|Any CPU
{02E84641-9C21-43C3-99CD-765878F8C8F6}.Release|Any CPU.Build.0 = Release|Any CPU
{1E1177E8-5664-4A09-AE2A-1C58F3A7CADD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{1E1177E8-5664-4A09-AE2A-1C58F3A7CADD}.Debug|Any CPU.Build.0 = Debug|Any CPU
{1E1177E8-5664-4A09-AE2A-1C58F3A7CADD}.Release|Any CPU.ActiveCfg = Release|Any CPU
{1E1177E8-5664-4A09-AE2A-1C58F3A7CADD}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE

View File

@ -31,6 +31,11 @@ namespace WinFormsLibrary1
InitializeComponent();
}
public void Clear()
{
listBox.Items.Clear();
}
public void SetParams(string template, char? fromChar, char? toChar)
{
_template = template;
@ -40,57 +45,54 @@ namespace WinFormsLibrary1
public T? GetObject<T>() where T : class, new()
{
if (listBox.SelectedIndex == -1 || string.IsNullOrEmpty(_template) || !_startSymbol.HasValue || !_endSymbol.HasValue)
throw new ArgumentException("Не хватает данных");
var type = typeof(T);
var fields = type.GetFields();
var properties = type.GetProperties();
var members = fields.Cast<MemberInfo>().Concat(properties.Cast<MemberInfo>()).ToArray();
var curObject = new T();
string text = listBox.SelectedItem?.ToString() ?? "";
var words = Regex.Split(_template, $@"\{_startSymbol.Value}.*?\{_endSymbol.Value}");
int firstWordStart = text.IndexOf(words[0], 0);
if (firstWordStart == -1)
throw new Exception("Не найден элемент шаблона");
if (firstWordStart != 0)
if (listBox.SelectedIndex == -1)
{
string beginning = text[..firstWordStart];
FillMember(_template.Substring(1, firstWordStart - 2), curObject, beginning, members);
return null;
}
int start = 0;
for (int i = 0; i < words.Length - 1; i++)
string value = listBox.SelectedItem.ToString();
StringBuilder stringBuilder = new StringBuilder(value);
T val = new T();
PropertyInfo[] properties = val.GetType().GetProperties();
foreach (PropertyInfo propertyInfo in properties)
{
start = text.IndexOf(words[i], start);
if (start == -1)
throw new Exception("Не найден элемент шаблона");
start += words[i].Length;
if (propertyInfo.CanWrite)
{
int num = stringBuilder.ToString().IndexOf(_startSymbol.Value);
if (num == -1)
{
break;
}
int nextWordIndex = text.IndexOf(words[i + 1], start);
if (nextWordIndex == -1)
throw new Exception("Не найден следующий элемент шаблона");
int num2 = stringBuilder.ToString().IndexOf(_endSymbol.Value, num + 1);
if (num2 == -1)
{
break;
}
string valueBetween = text[start..nextWordIndex];
string value2 = stringBuilder.ToString(num + 1, num2 - num - 1);
stringBuilder.Remove(0, num2 + 1);
string layoutPart = _template.Substring(_template.IndexOf(words[i]) + words[i].Length);
int startCharIndex = layoutPart.IndexOf(_startSymbol.Value);
int endCharIndex = layoutPart.IndexOf(_endSymbol.Value);
string memberName = layoutPart.Substring(startCharIndex + 1, endCharIndex - startCharIndex - 1);
FillMember(memberName, curObject, valueBetween, members);
start = nextWordIndex;
try
{
propertyInfo.SetValue(val, Convert.ChangeType(value2, propertyInfo.PropertyType));
}
catch (FormatException)
{
// Обработка ошибки преобразования формата
// Можно либо пропустить это поле, либо установить значение по умолчанию
// Например:
// propertyInfo.SetValue(val, default);
// Или вывести сообщение об ошибке
MessageBox.Show($"Не удалось преобразовать значение '{value2}' в тип {propertyInfo.PropertyType} для поля {propertyInfo.Name}.");
}
}
}
return (T?)curObject;
return val;
}
private void SetMemberValue(object obj, MemberInfo member, object value)
{
if (member is PropertyInfo property)

View File

@ -6,7 +6,7 @@
<UseWindowsForms>true</UseWindowsForms>
<ImplicitUsings>enable</ImplicitUsings>
<GeneratePackageOnBuild>True</GeneratePackageOnBuild>
<Version>1.0.3</Version>
<Version>1.0.6</Version>
<Title>Library13StroevV</Title>
</PropertyGroup>

BIN
reports/diagrams.vpp Normal file

Binary file not shown.

Binary file not shown.

BIN
reports/Лаб5/Adapter.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.8 KiB

BIN
reports/Лаб5/Bridge.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 29 KiB

BIN
reports/Лаб5/Facade.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 21 KiB

Binary file not shown.

Binary file not shown.

After

Width:  |  Height:  |  Size: 23 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

Binary file not shown.

After

Width:  |  Height:  |  Size: 97 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 75 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 21 KiB

Binary file not shown.