Add PluginsConvention to Account App

This commit is contained in:
abazov73 2023-11-30 21:05:37 +04:00
parent 0b515dc8c4
commit f20d17f212
9 changed files with 391 additions and 1 deletions

View File

@ -19,6 +19,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AccountsDataBaseImplement",
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PluginsConventionLibrary", "PluginsConventionLibrary\PluginsConventionLibrary.csproj", "{B97362C6-7FB3-4696-BE00-7E42C4E40274}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AccountAppPlugins", "AccountAppPlugins\AccountAppPlugins.csproj", "{0FE49AC5-A83A-46D6-8590-DD06DC9E34A0}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@ -57,6 +59,10 @@ Global
{B97362C6-7FB3-4696-BE00-7E42C4E40274}.Debug|Any CPU.Build.0 = Debug|Any CPU
{B97362C6-7FB3-4696-BE00-7E42C4E40274}.Release|Any CPU.ActiveCfg = Release|Any CPU
{B97362C6-7FB3-4696-BE00-7E42C4E40274}.Release|Any CPU.Build.0 = Release|Any CPU
{0FE49AC5-A83A-46D6-8590-DD06DC9E34A0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{0FE49AC5-A83A-46D6-8590-DD06DC9E34A0}.Debug|Any CPU.Build.0 = Debug|Any CPU
{0FE49AC5-A83A-46D6-8590-DD06DC9E34A0}.Release|Any CPU.ActiveCfg = Release|Any CPU
{0FE49AC5-A83A-46D6-8590-DD06DC9E34A0}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE

View File

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

View File

@ -0,0 +1,39 @@
namespace AccountAppPlugins
{
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.components = new System.ComponentModel.Container();
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(800, 450);
this.Text = "FormMain";
}
#endregion
}
}

View File

@ -0,0 +1,20 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace AccountAppPlugins
{
public partial class FormMain : Form
{
public FormMain()
{
InitializeComponent();
}
}
}

View File

@ -0,0 +1,120 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
</root>

View File

@ -0,0 +1,17 @@
namespace AccountAppPlugins
{
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

@ -23,8 +23,17 @@
<ProjectReference Include="..\AbazovViewComponents\AbazovViewComponents.csproj" />
<ProjectReference Include="..\AccountsBusinessLogic\AccountsBusinessLogic.csproj" />
<ProjectReference Include="..\AccountsDataBaseImplement\AccountsDataBaseImplement.csproj" />
<ProjectReference Include="..\PluginsConventionLibrary\PluginsConventionLibrary.csproj" />
</ItemGroup>
<Target Name="CreatePluginsFolder" BeforeTargets="PreBuildEvent" Condition="!Exists('$(SolutionDir)Plugins')">
<MakeDir Directories="$(SolutionDir)Plugins" />
</Target>
<Target Name="CopyPlugins" AfterTargets="PostBuildEvent">
<Exec Command="copy /Y &quot;$(TargetDir)*.dll&quot; &quot;$(SolutionDir)Plugins\*.dll&quot;" />
</Target>
<ItemGroup>
<Compile Update="Properties\Resources.Designer.cs">
<DesignTime>True</DesignTime>

View File

@ -0,0 +1,163 @@
using AbazovViewComponents.LogicalComponents;
using AccountsContracts.BusinessLogicContracts;
using AccountsContracts.StorageContracts;
using AccountsContracts.ViewModels;
using ComponentsLibraryNet60.DocumentWithChart;
using ComponentsLibraryNet60.Models;
using ControlsLibraryNet60.Core;
using ControlsLibraryNet60.Data;
using ControlsLibraryNet60.Models;
using NevaevaLibrary.LogicalComponents;
using PluginsConventionLibrary;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace AccountsApp
{
public class PluginsConvention : IPluginsConvention
{
private readonly IAccountLogic _accountLogic;
private readonly IInterestLogic _interestLogic;
private readonly ControlDataTableTable _controlDataTable;
private readonly ExcelImagesComponent _excelImagesComponent;
private readonly WordTableComponent _wordTableComponent;
private readonly ComponentDocumentWithChartBarPdf _chartBar;
public string PluginName { get; set; } = "LabWork_03_plugin";
public UserControl GetControl
{
get { return _controlDataTable; }
}
public PluginsConventionElement GetElement
{
get
{
int Id = _controlDataTable.GetSelectedObject<AccountViewModel>()!.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 FormAccount(_accountLogic, _interestLogic);
}
else
{
FormAccount form = new FormAccount(_accountLogic, _interestLogic);
form.Id = element.Id.GetHashCode();
return form;
}
}
public Form GetThesaurus()
{
return new FormInterests(_interestLogic);
}
public bool DeleteElement(PluginsConventionElement element)
{
_accountLogic.Delete(
new(element.Id.GetHashCode())
);
return true;
}
public void ReloadData()
{
try
{
var account = _accountLogic.ReadList(null);
if (account != null)
{
_controlDataTable.Clear();
_controlDataTable.LoadColumns(new List<DataTableColumnConfig> {
new DataTableColumnConfig { ColumnHeader = "", PropertyName = "Id", Visible = false, Width = 10},
new DataTableColumnConfig { ColumnHeader = "Логин", PropertyName = "Login", Visible = true, Width = 200},
new DataTableColumnConfig { ColumnHeader = "Выбранный интерес", PropertyName = "InterestName", Visible = true, Width = 200},
new DataTableColumnConfig { ColumnHeader = "Email", PropertyName = "Email", Visible = true, Width = 200},
});
_controlDataTable.AddTable(account);
}
}
catch (Exception ex)
{
MessageBox.Show(
ex.Message,
"Ошибка",
MessageBoxButtons.OK,
MessageBoxIcon.Error
);
}
}
public bool CreateSimpleDocument(PluginsConventionSaveDocument saveDocument)
{
List<string> avatars = new List<string>();
foreach (var account in _accountLogic.ReadList(null))
{
avatars.Add(account.Avatar);
}
string path = AppDomain.CurrentDomain.BaseDirectory + "Аватары.xlsx";
if (_excelImagesComponent.createWithImages(new ExcelImageInfo(path, "Аватары", avatars.ToArray())))
{
MessageBox.Show("Документ создан");
return true;
}
return false;
}
public bool CreateTableDocument(PluginsConventionSaveDocument saveDocument)
{
string path = AppDomain.CurrentDomain.BaseDirectory + "Аккаунты.docx";
List<(int, int)> merges = new List<(int, int)> { (1, 2) };
List<int> widths = new List<int> { 100, 100, 100, 100 };
List<(string, string)> headers = new List<(string, string)> {
("Id", "Идентификатор"),
("", "Личные данные"),
("Login", "Логин"),
("Email", "Эл. почта"),
("InterestName", "Выбранный интерес")
};
_wordTableComponent.createWithTable(path, "Список аккаунтов", merges, widths, headers, _accountLogic.ReadList(null));
MessageBox.Show("Документ создан");
return true;
}
public bool CreateChartDocument(PluginsConventionSaveDocument saveDocument)
{
Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);
string path = AppDomain.CurrentDomain.BaseDirectory + "Интересы.pdf";
Dictionary<string, List<(int, double)>> data = new Dictionary<string, List<(int, double)>>();
data = _accountLogic
.ReadList(null)
.GroupBy(x => x.InterestName)
.ToDictionary(x => x.Key, x => new List<(int, double)> { (0, x.Count()) });
_chartBar.CreateDoc(new ComponentDocumentWithChartConfig
{
Header = "Интересы",
FilePath = path,
ChartTitle = "Интересы",
LegendLocation = ComponentsLibraryNet60.Models.Location.Bottom,
Data = data,
});
MessageBox.Show("Успех");
return false;
}
}
}

View File

@ -19,6 +19,11 @@ namespace AccountsContracts.BindingModels
public int InterestId { get; set; }
public string Avatar { get; set; }
public string Avatar { get; set; } = string.Empty;
public AccountBindingModel(int id)
{
Id = id;
}
}
}