Лабораторная 4

This commit is contained in:
Даниил Путинцев 2024-11-21 01:48:17 +04:00
parent 48ae5ef9ad
commit 7cb96b6f96
74 changed files with 919 additions and 1 deletions

View File

@ -15,7 +15,11 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PortalAccountsDatabaseImple
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PortalAccountsDataModels", "PortalAccountsDataModels\PortalAccountsDataModels.csproj", "{FA4B05BE-8AEB-4D83-9381-53493BFFBCA1}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PortalAccountsView", "PortalAccountsView\PortalAccountsView.csproj", "{36667C40-A6AE-422B-BFD2-BCEEC0A54EA2}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PortalAccountsView", "PortalAccountsView\PortalAccountsView.csproj", "{36667C40-A6AE-422B-BFD2-BCEEC0A54EA2}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PluginsApp", "PluginsApp\PluginsApp.csproj", "{9A329DF5-120D-4695-9E0D-F0727649C16D}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PluginsConventionLibrary", "PluginsConventionLibrary\PluginsConventionLibrary.csproj", "{93871BA7-1708-4403-B01B-8D16B0D140C4}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
@ -51,6 +55,14 @@ Global
{36667C40-A6AE-422B-BFD2-BCEEC0A54EA2}.Debug|Any CPU.Build.0 = Debug|Any CPU
{36667C40-A6AE-422B-BFD2-BCEEC0A54EA2}.Release|Any CPU.ActiveCfg = Release|Any CPU
{36667C40-A6AE-422B-BFD2-BCEEC0A54EA2}.Release|Any CPU.Build.0 = Release|Any CPU
{9A329DF5-120D-4695-9E0D-F0727649C16D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{9A329DF5-120D-4695-9E0D-F0727649C16D}.Debug|Any CPU.Build.0 = Debug|Any CPU
{9A329DF5-120D-4695-9E0D-F0727649C16D}.Release|Any CPU.ActiveCfg = Release|Any CPU
{9A329DF5-120D-4695-9E0D-F0727649C16D}.Release|Any CPU.Build.0 = Release|Any CPU
{93871BA7-1708-4403-B01B-8D16B0D140C4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{93871BA7-1708-4403-B01B-8D16B0D140C4}.Debug|Any CPU.Build.0 = Debug|Any CPU
{93871BA7-1708-4403-B01B-8D16B0D140C4}.Release|Any CPU.ActiveCfg = Release|Any CPU
{93871BA7-1708-4403-B01B-8D16B0D140C4}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE

173
COP/PluginsApp/FormMain.Designer.cs generated Normal file
View File

@ -0,0 +1,173 @@
namespace PluginsApp
{
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()
{
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(232, 22);
SimpleDocToolStripMenuItem.Text = "Простой документ";
SimpleDocToolStripMenuItem.Click += SimpleDocToolStripMenuItem_Click;
//
// TableDocToolStripMenuItem
//
TableDocToolStripMenuItem.Name = "TableDocToolStripMenuItem";
TableDocToolStripMenuItem.ShortcutKeys = Keys.Control | Keys.T;
TableDocToolStripMenuItem.Size = new Size(232, 22);
TableDocToolStripMenuItem.Text = "Документ с таблицей";
TableDocToolStripMenuItem.Click += TableDocToolStripMenuItem_Click;
//
// ChartDocToolStripMenuItem
//
ChartDocToolStripMenuItem.Name = "ChartDocToolStripMenuItem";
ChartDocToolStripMenuItem.ShortcutKeys = Keys.Control | Keys.C;
ChartDocToolStripMenuItem.Size = new Size(232, 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;
}
}

243
COP/PluginsApp/FormMain.cs Normal file
View File

@ -0,0 +1,243 @@
using PluginsConventionLibrary;
using System.Reflection;
namespace PluginsApp
{
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()
{
var plugins = new Dictionary<string, IPluginsConvention>();
string pluginsDir = Path.Combine(Directory.GetParent(Directory.GetCurrentDirectory())!.Parent!.Parent!.FullName, "Plugins");
if (!Directory.Exists(pluginsDir))
{
MessageBox.Show($"Êàòàëîã {pluginsDir} íå íàéäåí.", "Îøèáêà", MessageBoxButtons.OK, MessageBoxIcon.Error);
return plugins;
}
foreach (string dllFile in Directory.EnumerateFiles(pluginsDir, "*.dll", SearchOption.AllDirectories))
{
try
{
Assembly assembly = Assembly.LoadFrom(dllFile);
Type[] types = assembly.GetTypes();
foreach (var type in types)
{
if (typeof(IPluginsConvention).IsAssignableFrom(type) && !type.IsInterface && !type.IsAbstract)
{
var plugin = (IPluginsConvention)Activator.CreateInstance(type)!;
plugins.Add(plugin.PluginName, plugin);
CreateToolStripMenuItem(plugin.PluginName);
}
}
}
catch (Exception ex)
{
MessageBox.Show($"Îøèáêà ïðè çàãðóçêå ñáîðêè {dllFile}: {ex.Message}", "Îøèáêà", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
return plugins;
}
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 ?? throw new Exception("Ïðîáëåìà ñ çàãðóçêîé ýëåìåíòà äëÿ âûâîäà äàííûõ");
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()
{
using var dialog = new SaveFileDialog
{
Filter = "docx|*.docx"
};
if (dialog.ShowDialog() == DialogResult.OK)
{
try
{
if (_plugins[_selectedPlugin].CreateSimpleDocument(new PluginsConventionSaveDocument() { FileName = dialog.FileName } ))
{
MessageBox.Show("Äîêóìåíò ñîõðàíåí", "Ñîçäàíèå äîêóìåíòà", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
else
{
MessageBox.Show("Îøèáêà ïðè ñîçäàíèè äîêóìåíòà", "Îøèáêà", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
catch (Exception ex)
{
MessageBox.Show("Ïðîèçîøëà îøèáêà: " + ex.Message, "Îøèáêà", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
private void CreateTableDoc()
{
using var dialog = new SaveFileDialog
{
Filter = "PDF Files|*.pdf"
};
if (dialog.ShowDialog() == DialogResult.OK)
{
try
{
if (_plugins[_selectedPlugin].CreateTableDocument(new PluginsConventionSaveDocument() { FileName = dialog.FileName }))
{
MessageBox.Show("Äîêóìåíò ñîõðàíåí", "Ñîçäàíèå äîêóìåíòà", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
else
{
MessageBox.Show("Îøèáêà ïðè ñîçäàíèè äîêóìåíòà", "Îøèáêà", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
catch (Exception ex)
{
MessageBox.Show("Ïðîèçîøëà îøèáêà: " + ex.Message, "Îøèáêà", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
private void CreateChartDoc()
{
using var dialog = new SaveFileDialog
{
Filter = "Excel Files|*.xlsx"
};
if (dialog.ShowDialog() == DialogResult.OK)
{
try
{
if (_plugins[_selectedPlugin].CreateChartDocument(new PluginsConventionSaveDocument() { FileName = dialog.FileName }))
{
MessageBox.Show("Äîêóìåíò ñîõðàíåí", "Ñîçäàíèå äîêóìåíòà", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
else
{
MessageBox.Show("Îøèáêà ïðè ñîçäàíèè äîêóìåíòà", "Îøèáêà", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
catch (Exception ex)
{
MessageBox.Show("Ïðîèçîøëà îøèáêà: " + ex.Message, "Îøèáêà", 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,123 @@
<?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>
<metadata name="menuStrip.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>17, 17</value>
</metadata>
</root>

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.

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

@ -0,0 +1,19 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>WinExe</OutputType>
<TargetFramework>net8.0-windows7.0</TargetFramework>
<Nullable>enable</Nullable>
<UseWindowsForms>true</UseWindowsForms>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="System.Text.Encoding.CodePages" Version="7.0.0" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\PluginsConventionLibrary\PluginsConventionLibrary.csproj" />
</ItemGroup>
</Project>

17
COP/PluginsApp/Program.cs Normal file
View File

@ -0,0 +1,17 @@
namespace PluginsApp
{
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,66 @@
namespace PluginsConventionLibrary
{
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,7 @@
namespace PluginsConventionLibrary
{
public class PluginsConventionElement
{
public Guid Id { get; set; }
}
}

View File

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

View File

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

View File

@ -0,0 +1,224 @@
using Components;
using Components.NonVisual;
using Components.SaveToPdfHelpers;
using NPOI.HPSF;
using PluginsConventionLibrary;
using PortalAccountsBusinessLogic.BusinessLogics;
using PortalAccountsContracts.BindingModels;
using PortalAccountsContracts.BusinessLogicsContracts;
using PortalAccountsContracts.ViewModels;
using PortalAccountsDatabaseImplement.Implements;
using PutincevLibrary;
using RodionovLibrary.NonVisualComponents;
using RodionovLibrary.NonVisualComponents.HelperModels;
using System.Text;
namespace PortalAccountsView
{
public class PluginsConvention : IPluginsConvention
{
private readonly IAccountLogic _accountLogic;
private readonly IInterestLogic _interestLogic;
private readonly CustomDataGridView _customDataGridViewTable = new();
private readonly ComponentExcelWithImage _componentExcelWithImage = new();
private readonly WordTableComponent _wordTableComponent = new();
private readonly HistogramPDF _histogrampdf = new();
public PluginsConvention()
{
_accountLogic = new AccountLogic(new AccountStorage());
_interestLogic = new InterestLogic(new InterestStorage());
ReloadData();
}
public string PluginName => "LabWork3 Plugin";
public UserControl GetControl => _customDataGridViewTable;
public PluginsConventionElement GetElement
{
get
{
var selected = _customDataGridViewTable.GetSelectedObject<AccountViewModel>()
?? throw new Exception("Не удалось получить выбранный элемент");
return new PluginsConventionAccount()
{
Id = IntToGuid(selected.Id),
Login = selected.Login,
AvatarPath = selected.AvatarPath,
InterestName = selected.InterestName,
Email = selected.Email
};
}
}
public Form GetForm(PluginsConventionElement element)
{
var formAccount = new FormAccount(_accountLogic, _interestLogic);
if (element != null)
{
formAccount.Id = element.Id.GetHashCode();
}
return formAccount;
}
public Form GetThesaurus()
{
return new FormInterests(_interestLogic);
}
public bool DeleteElement(PluginsConventionElement element)
{
return _accountLogic.Delete(
new AccountBindingModel { Id = element.Id.GetHashCode() }
);
}
public void ReloadData()
{
try
{
var accounts = _accountLogic.ReadList(null) ?? throw new Exception("Не удалось получить список аккаунтов");
_customDataGridViewTable.ClearRows();
var tables = new List<(string, string, float)> {
("Идентификатор", "Id", 1),
("Логин", "Login", 1),
("Интерес", "InterestName", 2),
("Почта", "Email", 2)
};
_customDataGridViewTable.ConfigureColumns(tables);
_customDataGridViewTable.FillData(accounts);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
public bool CreateSimpleDocument(PluginsConventionSaveDocument saveDocument)
{
try
{
List<string> images = new List<string>();
var list = _accountLogic.ReadList(null);
if (list != null)
{
foreach (var item in list)
{
images.Add(item.AvatarPath);
}
string[] imagesArray = images.ToArray();
_componentExcelWithImage.CreateExcelWithImages(saveDocument.FileName, "Сканы чеков", imagesArray);
}
return true;
}
catch (Exception)
{
return false;
}
}
public bool CreateTableDocument(PluginsConventionSaveDocument saveDocument)
{
Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);
try
{
string title = "Документ с таблицей";
var mergedColumns = new List<(int, int)>
{
(1, 2),
};
var columns = new List<ColumnParameters>
{
new() { FirstRowHeader = "Идент", PropertyName = "Id", Width = 1.3 },
new() { FirstRowHeader = "Личные данные", SecondRowHeader = "Логин", PropertyName = "Login", Width = 1.7 },
new() { FirstRowHeader = "Личные данные", SecondRowHeader = "Почта", PropertyName = "Email", Width = 1.7 },
new() { FirstRowHeader = "Интерес", PropertyName = "InterestName", Width = 1.7 },
};
var list = _accountLogic.ReadList(null);
var tableInfo = new WordTableInfo<AccountViewModel>
{
FileName = saveDocument.FileName,
Title = title,
ColumnParameters = columns,
Items = list,
MergedColumns = mergedColumns
};
_wordTableComponent.CreateTable(tableInfo);
return true;
}
catch (Exception)
{
return false;
}
}
public bool CreateChartDocument(PluginsConventionSaveDocument saveDocument)
{
try
{
var accounts = _accountLogic.ReadList(null);
var list = new ChartData();
var groupedAccounts = accounts.GroupBy(account => account.InterestName)
.Select(group => new
{
InterestName = group.Key,
AccountCount = group.Count()
})
.ToList();
var data = new Dictionary<string, double>();
foreach (var group in groupedAccounts)
{
data.Add(group.InterestName, (double)group.AccountCount);
}
list.Data = data;
list.SeriesName = "Пользователи";
var acc = new List<ChartData>();
acc.Add(list);
var histogrammInfo = new HistogramData
{
FilePath = saveDocument.FileName,
DocumentTitle = "Гистограмма PDF",
ChartTitle = "Количетсво интересов у пользователей",
LegendPosition = LegendPositions.Bottom,
ChartData = acc,
};
_histogrampdf.CreateHistogramPdf(histogrammInfo);
return true;
}
catch (Exception)
{
return false;
}
}
private Guid IntToGuid(int value)
{
byte[] bytes = new byte[16];
BitConverter.GetBytes(value).CopyTo(bytes, 0);
return new Guid(bytes);
}
}
}

View File

@ -0,0 +1,15 @@
using PluginsConventionLibrary;
namespace PortalAccountsView
{
public class PluginsConventionAccount : PluginsConventionElement
{
public string Login { get; set; } = string.Empty;
public string? AvatarPath { get; set; }
public string InterestName { get; set; } = string.Empty;
public string Email { get; set; } = string.Empty;
}
}

View File

@ -22,6 +22,8 @@
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\PluginsApp\PluginsApp.csproj" />
<ProjectReference Include="..\PluginsConventionLibrary\PluginsConventionLibrary.csproj" />
<ProjectReference Include="..\PortalAccountsBusinessLogic\PortalAccountsBusinessLogic.csproj" />
<ProjectReference Include="..\PortalAccountsContracts\PortalAccountsContracts.csproj" />
<ProjectReference Include="..\PortalAccountsDatabaseImplement\PortalAccountsDatabaseImplement.csproj" />