This commit is contained in:
dyakonovr 2024-10-29 12:53:39 +04:00
parent f8fc0b4584
commit f8a4b504f0
57 changed files with 923 additions and 7 deletions

View File

@ -12,6 +12,6 @@ namespace Contracts.ReportModels
public string Name { get; set; }
public string Image { get; set; }
public string Manufacturers { get; set; }
public string DeliveryDate { get; set; }
public DateTime DeliveryDate { get; set; }
}
}

170
Lab4/Form1.Designer.cs generated Normal file
View File

@ -0,0 +1,170 @@
namespace Lab4
{
partial class Form1
{
/// <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()
{
menuStrip1 = new MenuStrip();
ControlsStripMenuItem = new ToolStripMenuItem();
действияToolStripMenuItem = new ToolStripMenuItem();
справочникToolStripMenuItem = new ToolStripMenuItem();
добавитьToolStripMenuItem = new ToolStripMenuItem();
изменитьToolStripMenuItem = new ToolStripMenuItem();
удалитьToolStripMenuItem = new ToolStripMenuItem();
документыToolStripMenuItem = new ToolStripMenuItem();
вордToolStripMenuItem = new ToolStripMenuItem();
эксельToolStripMenuItem = new ToolStripMenuItem();
пдфToolStripMenuItem = new ToolStripMenuItem();
panelControl = new Panel();
menuStrip1.SuspendLayout();
SuspendLayout();
//
// menuStrip1
//
menuStrip1.ImageScalingSize = new Size(20, 20);
menuStrip1.Items.AddRange(new ToolStripItem[] { ControlsStripMenuItem, действияToolStripMenuItem, документыToolStripMenuItem });
menuStrip1.Location = new Point(0, 0);
menuStrip1.Name = "menuStrip1";
menuStrip1.Size = new Size(800, 28);
menuStrip1.TabIndex = 0;
menuStrip1.Text = "menuStrip1";
//
// ControlsStripMenuItem
//
ControlsStripMenuItem.Name = "ControlsStripMenuItem";
ControlsStripMenuItem.Size = new Size(113, 24);
ControlsStripMenuItem.Text = "Компоненты";
//
// действияToolStripMenuItem
//
действияToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { справочникToolStripMenuItem, добавитьToolStripMenuItem, изменитьToolStripMenuItem, удалитьToolStripMenuItem });
действияToolStripMenuItem.Name = ействияToolStripMenuItem";
действияToolStripMenuItem.Size = new Size(88, 24);
действияToolStripMenuItem.Text = "Действия";
//
// справочникToolStripMenuItem
//
справочникToolStripMenuItem.Name = "справочникToolStripMenuItem";
справочникToolStripMenuItem.ShortcutKeys = Keys.Control | Keys.I;
справочникToolStripMenuItem.Size = new Size(223, 26);
справочникToolStripMenuItem.Text = "Справочник";
справочникToolStripMenuItem.Click += ThesaurusToolStripMenuItem_Click;
//
// добавитьToolStripMenuItem
//
добавитьToolStripMenuItem.Name = обавитьToolStripMenuItem";
добавитьToolStripMenuItem.ShortcutKeys = Keys.Control | Keys.A;
добавитьToolStripMenuItem.Size = new Size(223, 26);
добавитьToolStripMenuItem.Text = "Добавить";
добавитьToolStripMenuItem.Click += AddElementToolStripMenuItem_Click;
//
// изменитьToolStripMenuItem
//
изменитьToolStripMenuItem.Name = "изменитьToolStripMenuItem";
изменитьToolStripMenuItem.ShortcutKeys = Keys.Control | Keys.U;
изменитьToolStripMenuItem.Size = new Size(223, 26);
изменитьToolStripMenuItem.Text = "Изменить";
изменитьToolStripMenuItem.Click += UpdElementToolStripMenuItem_Click;
//
// удалитьToolStripMenuItem
//
удалитьToolStripMenuItem.Name = "удалитьToolStripMenuItem";
удалитьToolStripMenuItem.ShortcutKeys = Keys.Control | Keys.D;
удалитьToolStripMenuItem.Size = new Size(223, 26);
удалитьToolStripMenuItem.Text = "Удалить";
удалитьToolStripMenuItem.Click += DelElementToolStripMenuItem_Click;
//
// документыToolStripMenuItem
//
документыToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { вордToolStripMenuItem, эксельToolStripMenuItem, пдфToolStripMenuItem });
документыToolStripMenuItem.Name = окументыToolStripMenuItem";
документыToolStripMenuItem.Size = new Size(101, 24);
документыToolStripMenuItem.Text = "Документы";
//
// вордToolStripMenuItem
//
вордToolStripMenuItem.Name = ордToolStripMenuItem";
вордToolStripMenuItem.ShortcutKeys = Keys.Control | Keys.S;
вордToolStripMenuItem.Size = new Size(224, 26);
вордToolStripMenuItem.Text = "Ворд";
вордToolStripMenuItem.Click += WordDocToolStripMenuItem_Click;
//
// эксельToolStripMenuItem
//
эксельToolStripMenuItem.Name = "эксельToolStripMenuItem";
эксельToolStripMenuItem.ShortcutKeys = Keys.Control | Keys.T;
эксельToolStripMenuItem.Size = new Size(224, 26);
эксельToolStripMenuItem.Text = "Эксель";
эксельToolStripMenuItem.Click += ExcelDocToolStripMenuItem_Click;
//
// пдфToolStripMenuItem
//
пдфToolStripMenuItem.Name = "пдфToolStripMenuItem";
пдфToolStripMenuItem.ShortcutKeys = Keys.Control | Keys.C;
пдфToolStripMenuItem.Size = new Size(224, 26);
пдфToolStripMenuItem.Text = "Пдф";
пдфToolStripMenuItem.Click += PdfDocToolStripMenuItem_Click;
//
// panelControl
//
panelControl.Location = new Point(0, 31);
panelControl.Name = "panelControl";
panelControl.Size = new Size(800, 417);
panelControl.TabIndex = 1;
//
// Form1
//
AutoScaleDimensions = new SizeF(8F, 20F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(800, 450);
Controls.Add(panelControl);
Controls.Add(menuStrip1);
MainMenuStrip = menuStrip1;
Name = "Form1";
Text = "Form1";
menuStrip1.ResumeLayout(false);
menuStrip1.PerformLayout();
ResumeLayout(false);
PerformLayout();
}
#endregion
private MenuStrip menuStrip1;
private ToolStripMenuItem ControlsStripMenuItem;
private ToolStripMenuItem действияToolStripMenuItem;
private ToolStripMenuItem справочникToolStripMenuItem;
private ToolStripMenuItem добавитьToolStripMenuItem;
private ToolStripMenuItem изменитьToolStripMenuItem;
private ToolStripMenuItem удалитьToolStripMenuItem;
private ToolStripMenuItem документыToolStripMenuItem;
private ToolStripMenuItem вордToolStripMenuItem;
private ToolStripMenuItem эксельToolStripMenuItem;
private ToolStripMenuItem пдфToolStripMenuItem;
private Panel panelControl;
}
}

234
Lab4/Form1.cs Normal file
View File

@ -0,0 +1,234 @@
using Plugins;
using System.Reflection;
namespace Lab4
{
public partial class Form1 : Form
{
private readonly Dictionary<string, IPluginsConvention> _plugins;
private string _selectedPlugin;
public Form1()
{
InitializeComponent();
_plugins = LoadPlugins();
_selectedPlugin = string.Empty;
}
private Dictionary<string, IPluginsConvention> LoadPlugins()
{
Dictionary<string, IPluginsConvention> plugins = new();
string currentDirectory = Directory.GetParent(Environment.CurrentDirectory)!.Parent!.Parent!.Parent!.FullName + "\\plugin";
string[] dllFiles = Directory.GetFiles(currentDirectory, "*.dll", SearchOption.AllDirectories);
foreach (string dllFile in dllFiles)
{
try
{
Assembly assembly = Assembly.LoadFrom(dllFile);
Type[] types = assembly.GetTypes();
foreach (Type type in types)
{
if (typeof(IPluginsConvention).IsAssignableFrom(type) && !type.IsInterface)
{
var plugin = (IPluginsConvention)Activator.CreateInstance(type)!;
plugins.Add(plugin.PluginName, plugin);
}
}
}
catch (Exception ex)
{
Console.WriteLine($"Íå óäàëîñü çàãðóçèòü ïëàãèí {dllFile}: {ex.Message}");
}
}
foreach (var plugin in plugins)
{
CreateMenuItem(plugin.Value.PluginName);
}
return plugins;
}
private void CreateMenuItem(string pluginName)
{
ToolStripMenuItem menuItem = new ToolStripMenuItem(pluginName);
menuItem.Click += (object? sender, EventArgs a) =>
{
_selectedPlugin = pluginName;
IPluginsConvention plugin = _plugins[pluginName];
UserControl userControl = plugin.GetControl;
if (userControl != null)
{
panelControl.Controls.Clear();
plugin.ReloadData();
userControl.Dock = DockStyle.Fill;
panelControl.Controls.Add(userControl);
}
};
ControlsStripMenuItem.DropDownItems.Add(menuItem);
}
private void FormMain_KeyDown(object sender, KeyEventArgs e)
{
if (string.IsNullOrEmpty(_selectedPlugin) ||
!_plugins.ContainsKey(_selectedPlugin))
{
return;
}
if (!e.Control)
{
return;
}
switch (e.KeyCode)
{
case Keys.I:
ShowThesaurus();
break;
case Keys.A:
AddNewElement();
break;
case Keys.U:
UpdateElement();
break;
case Keys.D:
DeleteElement();
break;
case Keys.S:
CreateWordDoc();
break;
case Keys.T:
CreatePdfDoc();
break;
case Keys.C:
CreateExcelDoc();
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 CreateWordDoc()
{
SaveFileDialog saveFileDialog = new SaveFileDialog();
saveFileDialog.Filter = "Word Documents (*.docx)|*.docx";
saveFileDialog.Title = "Ñîõðàíèòü ïðîñòîé äîêóìåíò";
if (saveFileDialog.ShowDialog() == DialogResult.OK)
{
if (_plugins[_selectedPlugin].CreateWordDocument(new
PluginsConventionSaveDocument()
{ FileName = saveFileDialog.FileName }))
{
MessageBox.Show("Äîêóìåíò ñîõðàíåí", "Ñîçäàíèå" +
" äîêóìåíòà", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
else
{
MessageBox.Show("Îøèáêà ïðè ñîçäàíèè äîêóìåíòà",
"Îøèáêà", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
private void CreatePdfDoc()
{
SaveFileDialog saveFileDialog = new SaveFileDialog();
saveFileDialog.Filter = "PDF Files (*.pdf)|*.pdf";
saveFileDialog.Title = "Ñîõðàíèòü òàáëèöó";
if (saveFileDialog.ShowDialog() == DialogResult.OK)
{
if (_plugins[_selectedPlugin].CreatePdfDocument(new
PluginsConventionSaveDocument()
{ FileName = saveFileDialog.FileName }))
{
MessageBox.Show("Äîêóìåíò ñîõðàíåí", "Ñîçäàíèå" +
" äîêóìåíòà", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
else
{
MessageBox.Show("Îøèáêà ïðè ñîçäàíèè äîêóìåíòà",
"Îøèáêà", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
private void CreateExcelDoc()
{
SaveFileDialog saveFileDialog = new SaveFileDialog();
saveFileDialog.Filter = "Excel Files (*.xlsx)|*.xlsx";
saveFileDialog.Title = "Ñîõðàíèòü äèàãðàììó";
if (saveFileDialog.ShowDialog() == DialogResult.OK)
{
if (_plugins[_selectedPlugin].CreateExcelDocument(new
PluginsConventionSaveDocument()
{ FileName = saveFileDialog.FileName }))
{
MessageBox.Show("Äîêóìåíò ñîõðàíåí", "Ñîçäàíèå" +
" äîêóìåíòà", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
else
{
MessageBox.Show("Îøèáêà ïðè ñîçäàíèè äîêóìåíòà",
"Îøèáêà", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
private void ThesaurusToolStripMenuItem_Click(object sender,
EventArgs e) => ShowThesaurus();
private void AddElementToolStripMenuItem_Click(object sender,
EventArgs e) => AddNewElement();
private void UpdElementToolStripMenuItem_Click(object sender,
EventArgs e) => UpdateElement();
private void DelElementToolStripMenuItem_Click(object sender,
EventArgs e) => DeleteElement();
private void WordDocToolStripMenuItem_Click(object sender,
EventArgs e) => CreateWordDoc();
private void ExcelDocToolStripMenuItem_Click(object sender, EventArgs
e) => CreateExcelDoc();
private void PdfDocToolStripMenuItem_Click(object sender, EventArgs
e) => CreatePdfDoc();
}
}

123
Lab4/Form1.resx Normal file
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="menuStrip1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>17, 17</value>
</metadata>
</root>

16
Lab4/Lab4.csproj Normal file
View File

@ -0,0 +1,16 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>WinExe</OutputType>
<TargetFramework>net6.0-windows</TargetFramework>
<Nullable>enable</Nullable>
<UseWindowsForms>true</UseWindowsForms>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\Plugins\Plugins.csproj" />
<ProjectReference Include="..\ShopProducts\ShopProducts.csproj" />
</ItemGroup>
</Project>

17
Lab4/Program.cs Normal file
View File

@ -0,0 +1,17 @@
namespace Lab4
{
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 Form1());
}
}
}

View File

@ -0,0 +1,16 @@
namespace Plugins
{
public interface IPluginsConvention
{
string PluginName { get; }
UserControl GetControl { get; }
PluginsConventionElement GetElement { get; }
Form GetForm(PluginsConventionElement element);
Form GetThesaurus();
bool DeleteElement(PluginsConventionElement element);
void ReloadData();
bool CreateWordDocument(PluginsConventionSaveDocument saveDocument);
bool CreatePdfDocument(PluginsConventionSaveDocument saveDocument);
bool CreateExcelDocument(PluginsConventionSaveDocument saveDocument);
}
}

10
Plugins/Plugins.csproj Normal file
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,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; }
}
}

View File

@ -5,11 +5,15 @@ VisualStudioVersion = 17.8.34408.163
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ShopProducts", "ShopProducts\ShopProducts.csproj", "{E8F82DF1-6741-454A-B96D-C1F2FB29134D}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Contracts", "Contracts\Contracts.csproj", "{F2440E2E-293A-4107-980B-EC0020529692}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Contracts", "Contracts\Contracts.csproj", "{F2440E2E-293A-4107-980B-EC0020529692}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BusinessLogic", "BusinessLogic\BusinessLogic.csproj", "{344C1681-67A5-485B-8E99-89F7D5866078}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BusinessLogic", "BusinessLogic\BusinessLogic.csproj", "{344C1681-67A5-485B-8E99-89F7D5866078}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DatabaseImplement", "DatabaseImplement\DatabaseImplement.csproj", "{80BABD36-989A-4181-9159-23A0BD3CF04A}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DatabaseImplement", "DatabaseImplement\DatabaseImplement.csproj", "{80BABD36-989A-4181-9159-23A0BD3CF04A}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Plugins", "Plugins\Plugins.csproj", "{93670F3B-6242-4043-9F04-55D1D09F13F2}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Lab4", "Lab4\Lab4.csproj", "{8A6B55B8-934D-42BE-9C39-834FDA71A474}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
@ -33,6 +37,14 @@ Global
{80BABD36-989A-4181-9159-23A0BD3CF04A}.Debug|Any CPU.Build.0 = Debug|Any CPU
{80BABD36-989A-4181-9159-23A0BD3CF04A}.Release|Any CPU.ActiveCfg = Release|Any CPU
{80BABD36-989A-4181-9159-23A0BD3CF04A}.Release|Any CPU.Build.0 = Release|Any CPU
{93670F3B-6242-4043-9F04-55D1D09F13F2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{93670F3B-6242-4043-9F04-55D1D09F13F2}.Debug|Any CPU.Build.0 = Debug|Any CPU
{93670F3B-6242-4043-9F04-55D1D09F13F2}.Release|Any CPU.ActiveCfg = Release|Any CPU
{93670F3B-6242-4043-9F04-55D1D09F13F2}.Release|Any CPU.Build.0 = Release|Any CPU
{8A6B55B8-934D-42BE-9C39-834FDA71A474}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{8A6B55B8-934D-42BE-9C39-834FDA71A474}.Debug|Any CPU.Build.0 = Debug|Any CPU
{8A6B55B8-934D-42BE-9C39-834FDA71A474}.Release|Any CPU.ActiveCfg = Release|Any CPU
{8A6B55B8-934D-42BE-9C39-834FDA71A474}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE

View File

@ -142,9 +142,9 @@ namespace ShopProducts
ChartTitle = "Êîë-âî ïðîäóêöèè ïî ïðîèçâîäèòåëþ",
LegendLocation = ComponentsLibraryNet60.Models.Location.Bottom,
Data = new Dictionary<string, List<(int Date, double Value)>>
{
{ "TTT", data }
}
{
{ "TTT", data }
}
});
MessageBox.Show("Word óñïåøíî ñîçäàí!", "Óñïåõ", MessageBoxButtons.OK, MessageBoxIcon.Information);

View File

@ -0,0 +1,291 @@
using BusinessLogic;
using Contracts.BusinessLogicContracts;
using Contracts.ReportModels;
using ControlsLibraryNet60.Data;
using DatabaseImplement.Implements;
using DocumentFormat.OpenXml.Drawing.Charts;
using Plugins;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using WinFormsLibrary1.Configs.Image;
using WinFormsLibrary1;
using ComponentsLibraryNet60.DocumentWithChart;
using ComponentsLibraryNet60.Models;
using ComponentsLibraryNet60.DocumentWithTable;
using Contracts.ViewModels;
using ControlsLibraryNet60.Models;
using Contracts.BindingModels;
namespace ShopProducts
{
public class PluginsConvention : IPluginsConvention
{
private readonly ProductLogic _ProductLogic = new ProductLogic(new ProductStorage());
private readonly ManufacturerLogic _ManufacturerLogic = new ManufacturerLogic(new ManufacturerStorage());
/*private UserTreeView userTreeView1 = new UserTreeView();*/
private ControlDataTableRow controlDataTableRow1 = new ControlDataTableRow();
public string PluginName { get; set; } = "Лаба 4";
public UserControl GetControl
{
get
{
Load();
/*return userTreeView1;*/
return controlDataTableRow1;
}
}
public PluginsConventionElement GetElement
{
get
{
/*var selectedProduct = userTreeView1.GetSelectedObject<ProductReportModel>();*/
var selectedProduct = controlDataTableRow1.GetSelectedObject<ProductReportModel>();
int? id = null;
if (selectedProduct != null)
{
id = Convert.ToInt32(selectedProduct.Id);
}
byte[] bytes = new byte[16];
if (!id.HasValue)
{
id = -1;
}
BitConverter.GetBytes(id.Value).CopyTo(bytes, 0);
return new()
{
Id = new Guid(bytes)
};
}
}
public bool CreateExcelDocument(PluginsConventionSaveDocument saveDocument)
{
try
{
string fileName = saveDocument.FileName;
var list = _ProductLogic.Read(null);
ComponentDocumentWithTableHeaderRowExcel table = new ComponentDocumentWithTableHeaderRowExcel();
table.CreateDoc(new ComponentDocumentWithTableHeaderDataConfig<ProductViewModel>
{
FilePath = fileName,
Header = "Продукты",
UseUnion = true,
ColumnsRowsWidth = new List<(int, int)> { (5, 0), (10, 0), (10, 0), (10, 0) },
ColumnUnion = new List<(int StartIndex, int Count)> { (1, 2) },
Headers = new List<(int ColumnIndex, int RowIndex, string Header, string PropertyName)>
{
(0, 0, "ID", "Id"),
(1, 0, "Продукт", ""),
(1, 1, "Название", "Name"),
(2, 1, "Производитель", "Manufacturers"),
(3, 0, "Дата поставки", "DeliveryDate"),
},
Data = list
});
return true;
/*COP.PieChart pieChart1 = new COP.PieChart();
string fileName = saveDocument.FileName;
var dates = _ProductLogic.GetExcelInfo();
var chartData = dates.Select(x => new DataItem { Name = x.Item1, Value = x.Item2 }).ToList();
pieChart1.GenerateDocument(new ExcelChartInfo(fileName, "Сколько клиентов какого статуса совершали покупки",
"Круговая диаграмма", COP.Enums.LegendPosition.Bottom, chartData));
return true;*/
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
return false;
}
}
public bool CreateWordDocument(PluginsConventionSaveDocument saveDocument)
{
try
{
ComponentDocumentWithChartBarWord chart = new ComponentDocumentWithChartBarWord();
var data = _ProductLogic.GetWordInfo();
chart.CreateDoc(new ComponentDocumentWithChartConfig
{
FilePath = saveDocument.FileName,
Header = "Гистограмма продуктов",
ChartTitle = "Кол-во продукции по производителю",
LegendLocation = Location.Bottom,
Data = new Dictionary<string, List<(int Date, double Value)>>
{
{ "TTT", data }
}
});
/*string fileName = saveDocument.FileName;
List<string> textList = new List<string>();
var list = _ProductLogic.Read(new ProductBindingModel { PurchaseSum = 0 });
var rs = list.Select(item => string.Concat("ФИО: ", item.Name, " Отзывы: ", item.Reviews, '\n')).ToArray();
if (list != null)
{
BigTextDocument.CreateDocument(new BigTextDocumentInfo
(fileName, "Документ по клиентам, совершавшим покупки (ФИО клиента и его отзывы)", rs)
);
}*/
return true;
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
return false;
}
}
public bool CreatePdfDocument(PluginsConventionSaveDocument saveDocument)
{
try
{
PdfWithImages pdf = new PdfWithImages();
var productImages = _ProductLogic.Read(null).Select(p => p.Image).ToList();
var config = new PdfWithImageConfig
{
FilePath = saveDocument.FileName,
Header = "Документ с изображениями",
Images = productImages
};
pdf.CreatePdf(config);
/*string fileName = saveDocument.FileName;
KOP.PDFComponents.PdfTableComponent pdfTableComponent1 = new();
var Products = _ProductLogic.Read(null);
for (int i = 0; i < Products.Count; i++)
{
if (Products[i].PurchaseSum == null || Products[i].PurchaseSum == "") { Products[i].PurchaseSum = "нет"; }
}
pdfTableComponent1.CreateDocument(fileName, "Отчёт по всем клиентам",
new List<double> { 2.0, 6.0, 4.0, 4.0 }, new List<double> { 5.0, 3.0 },
new List<(string, string)> { ("Id", "Id"), ("ФИО", "Name"), ("Статус", "Manufacturer"), ("Сумма покупок", "PurchaseSum") },
Products
);*/
return true;
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
return false;
}
}
private void Load()
{
/*List<string> stringToHierachy = new List<string>() { "Manufacturer", "PurchaseSum", "Id", "Name" };
userTreeView1.Hierarchy = stringToHierachy;*/
var tableConfig = new List<DataTableColumnConfig>
{
new DataTableColumnConfig
{
ColumnHeader = "Id",
PropertyName = "Id",
Visible = false
},
new DataTableColumnConfig
{
ColumnHeader = "Name",
PropertyName = "Name",
Visible = true
},
new DataTableColumnConfig
{
ColumnHeader = "Manufacturers",
PropertyName = "Manufacturers",
Visible = true
},
new DataTableColumnConfig
{
ColumnHeader = "Delivery date",
PropertyName = "DeliveryDate",
Visible = true
}
};
controlDataTableRow1.LoadColumns(tableConfig);
LoadData();
}
private void LoadData()
{
try
{
/*var list = _ProductLogic.Read(null);
for (int i = 0; i < list.Count; i++)
{
if (list[i].PurchaseSum == null || list[i].PurchaseSum == "") { list[i].PurchaseSum = "нет"; }
}
userTreeView1.PopulateTree(list);*/
controlDataTableRow1.Clear();
var list = _ProductLogic.Read(null);
for (int i = 0; i < list.Count; i++)
{
controlDataTableRow1.AddRow(list[i]);
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
public bool DeleteElement(PluginsConventionElement element)
{
var selectedProduct = controlDataTableRow1.GetSelectedObject<ProductReportModel>();
int id = Convert.ToInt32(selectedProduct.Id);
try
{
_ProductLogic.Delete(new ProductBindingModel { Id = id });
LoadData();
return true;
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
return false;
}
}
public Form GetForm(PluginsConventionElement element)
{
if (element == null)
{
return new FormProduct(_ProductLogic, _ManufacturerLogic);
}
if (element.Id.GetHashCode() >= 0)
{
FormProduct form = new FormProduct(_ProductLogic, _ManufacturerLogic);
form.Id = element.Id.GetHashCode();
return form;
}
return null;
}
public Form GetThesaurus()
{
return new FormManufacturers(_ManufacturerLogic);
}
public void ReloadData()
{
LoadData();
}
}
}

View File

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

BIN
plugin/BusinessLogic.dll Normal file

Binary file not shown.

Binary file not shown.

BIN
plugin/Contracts.dll Normal file

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

BIN
plugin/Humanizer.dll Normal file

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

BIN
plugin/PdfSharp.dll Normal file

Binary file not shown.

Binary file not shown.

BIN
plugin/Plugins.dll Normal file

Binary file not shown.

BIN
plugin/ShopProducts.dll Normal file

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

BIN
plugin/WinFormsLibrary1.dll Normal file

Binary file not shown.