Скоро будет готово

This commit is contained in:
maxnes3 2023-11-15 01:14:11 +04:00
parent 0bc52d4d10
commit b61f216f16
9 changed files with 331 additions and 129 deletions

View File

@ -23,6 +23,15 @@
<ProjectReference Include="..\Contracts\Contracts.csproj" /> <ProjectReference Include="..\Contracts\Contracts.csproj" />
<ProjectReference Include="..\DataBaseImplement\DataBaseImplement.csproj" /> <ProjectReference Include="..\DataBaseImplement\DataBaseImplement.csproj" />
<ProjectReference Include="..\PdfFormsLibrary\PdfFormsLibrary.csproj" /> <ProjectReference Include="..\PdfFormsLibrary\PdfFormsLibrary.csproj" />
<ProjectReference Include="..\PluginsConventionLibrary\PluginsConventionLibrary.csproj" />
</ItemGroup> </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>
</Project> </Project>

View File

@ -262,7 +262,6 @@ namespace AppView
simpleCircleDiagram.NameData = names.ToArray(); simpleCircleDiagram.NameData = names.ToArray();
try try
{ {
//componentDocumentWithChartPieWord.CreateDoc(config);
circleDiagram.AddCircleDiagram(simpleCircleDiagram); circleDiagram.AddCircleDiagram(simpleCircleDiagram);
MessageBox.Show( MessageBox.Show(
"Word-документ успешно сохранен.", "Word-документ успешно сохранен.",

View File

@ -0,0 +1,249 @@
using Contracts.StoragesContracts;
using Contracts.ViewModels;
using ControlsLibraryNet60.Data;
using ControlsLibraryNet60.Models;
using DataBaseImplement.Implements;
using PdfFormsLibrary;
using PluginsConventionLibrary;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using WinFormsLibrary;
using WinFormsLibrary.not_visual;
using WinFormsLibrary.SupportClasses.Enums;
using WinFormsLibrary.SupportClasses;
namespace AppView
{
public class PluginsConvention : IPluginsConvention
{
private readonly IProviderStorage _providerStorage;
private readonly ITypeStorage _typeStorage;
private readonly ControlDataTreeCell _controlDataTreeCell;
private readonly PdfGeneratorControl _pdfGeneratorControl;
private readonly ComponentWithSettings _componentWithSettings;
private readonly CircleDiagram _circleDiagram;
public string PluginName { get; set; } = "LabWork_03_plugin";
public UserControl GetControl
{
get { return _controlDataTreeCell; }
}
public PluginsConventionElement GetElement
{
get
{
int Id = _controlDataTreeCell.GetSelectedObject<ProviderViewModel>()!.Id;
byte[] bytes = new byte[16];
BitConverter.GetBytes(Id).CopyTo(bytes, 0);
Guid guid = new Guid(bytes);
return new PluginsConventionElement() { Id = guid };
}
}
public PluginsConvention()
{
_providerStorage = new ProviderStorage();
_typeStorage = new TypeStorage();
_pdfGeneratorControl = new();
_componentWithSettings = new();
_circleDiagram = new();
_controlDataTreeCell = new();
}
public Form GetForm(PluginsConventionElement element)
{
if (element == null)
{
return new FormProvider(_providerStorage, _typeStorage);
}
else
{
FormProvider form = new FormProvider(_providerStorage, _typeStorage);
form.Id = element.Id.GetHashCode();
return form;
}
}
public Form GetThesaurus()
{
return new FormType(_typeStorage);
}
public bool DeleteElement(PluginsConventionElement element)
{
_providerStorage.Delete(
new(element.Id.GetHashCode())
);
return true;
}
public void ReloadData()
{
try
{
var providers = _providerStorage.GetFullList();
if (providers != null)
{
_controlDataTreeCell.Clear();
DataTreeNodeConfig treeConfig = new();
treeConfig.NodeNames = new();
treeConfig.NodeNames.Enqueue("Type");
treeConfig.NodeNames.Enqueue("SupplyDateTime");
treeConfig.NodeNames.Enqueue("Id");
treeConfig.NodeNames.Enqueue("Name");
_controlDataTreeCell.LoadConfig(treeConfig);
if (providers.Count > 0)
{
int numOfProperties = typeof(ProviderViewModel).GetProperties().Length;
for (int i = 0; i < providers.Count; ++i)
{
providers[i].SupplyDateTime = providers[i].SupplyDate.ToString();
for (int j = 0; j < numOfProperties; ++j)
{
_controlDataTreeCell.AddCell(j, providers[i]);
}
}
}
}
}
catch (Exception ex)
{
MessageBox.Show(
ex.Message,
"Ошибка",
MessageBoxButtons.OK,
MessageBoxIcon.Error
);
}
}
public bool CreateSimpleDocument(PluginsConventionSaveDocument saveDocument)
{
System.Text.Encoding.RegisterProvider(System.Text.CodePagesEncodingProvider.Instance);
string filePath = saveDocument.FileName;
string documentTitle = "Поставщики";
List<string> textData = new();
foreach (var provider in _providerStorage.GetFullList())
{
textData.Add(provider.Name + ": " + provider.Furniture);
}
try
{
_pdfGeneratorControl.GeneratePdf(filePath, documentTitle, textData);
MessageBox.Show("PDF-документ успешно сохранен.", "Успех", MessageBoxButtons.OK, MessageBoxIcon.Information);
return true;
}
catch (Exception ex)
{
MessageBox.Show(
$"Ошибка при создании PDF-документа: {ex.Message}",
"Ошибка",
MessageBoxButtons.OK,
MessageBoxIcon.Error
);
return false;
}
}
public bool CreateTableDocument(PluginsConventionSaveDocument saveDocument)
{
List<ProviderViewModel> providersList = _providerStorage.GetFullList();
foreach (var provider in providersList)
{
if (provider.SupplyDate == null)
{
provider.SupplyDateTime = "Поставок не было";
provider.SupplyDate = DateTime.MinValue;
continue;
}
provider.SupplyDateTime = provider.SupplyDate.ToString();
}
var columnConfigs = new List<ColumnConfig>
{
new ColumnConfig { Width = 50f, PropertyName = "Id" },
new ColumnConfig { Width = 50f, PropertyName = "Name" },
new ColumnConfig { Width = 50f, PropertyName = "Type" },
new ColumnConfig { Width = 70f, PropertyName = "SupplyDateTime" },
};
try
{
_componentWithSettings.GenerateExcelDocument(saveDocument.FileName, "Отчет по всем поставщикам", columnConfigs, 25f, 35f, providersList);
MessageBox.Show(
"Excel-документ успешно сохранен.",
"Успех",
MessageBoxButtons.OK,
MessageBoxIcon.Information
);
return true;
}
catch (Exception ex)
{
MessageBox.Show(
$"Ошибка при создании Excel-документа: {ex.Message}",
"Ошибка",
MessageBoxButtons.OK,
MessageBoxIcon.Error
);
return false;
}
}
public bool CreateChartDocument(PluginsConventionSaveDocument saveDocument)
{
var providersList = _providerStorage
.GetFullList()
.Where(item => item.SupplyDate?.Year == DateTime.Now.Year)
.GroupBy(item => item.Type)
.Select(group => new
{
Type = group.Key,
Date = group.Select(item => item.SupplyDate),
Count = (double)group.Count(),
});
List<double> results = new();
List<string> names = new();
foreach (var provider in providersList)
{
results.Add(provider.Count);
names.Add(provider.Type);
}
SimpleCircleDiagram simpleCircleDiagram = new(saveDocument.FileName, "Круговая диаграмма", "Количество поставщиков в разрезе типа организации",
EnumAreaLegend.Right, new() { new DataCircleDiagram("Типы организации", results.ToArray()) });
simpleCircleDiagram.NameData = names.ToArray();
try
{
_circleDiagram.AddCircleDiagram(simpleCircleDiagram);
MessageBox.Show(
"Word-документ успешно сохранен.",
"Успех",
MessageBoxButtons.OK,
MessageBoxIcon.Information
);
return true;
}
catch (Exception ex)
{
MessageBox.Show(
$"Ошибка при создании Word-документа: {ex.Message}",
"Ошибка",
MessageBoxButtons.OK,
MessageBoxIcon.Error
);
return false;
}
}
}
}

View File

@ -22,5 +22,10 @@ namespace Contracts.BindingModels
{ {
Id = provider.Id; Id = provider.Id;
} }
public ProviderBindingModel(int id)
{
Id = id;
}
} }
} }

View File

@ -1,120 +0,0 @@
<?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

@ -1,6 +1,6 @@
namespace WinFormsAppByPlugins namespace WinFormsAppByPlugins
{ {
partial class Form1 partial class FormMain
{ {
/// <summary> /// <summary>
/// Required designer variable. /// Required designer variable.
@ -28,10 +28,10 @@
/// </summary> /// </summary>
private void InitializeComponent() private void InitializeComponent()
{ {
this.components = new System.ComponentModel.Container(); components = new System.ComponentModel.Container();
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; AutoScaleMode = AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(800, 450); ClientSize = new Size(800, 450);
this.Text = "Form1"; Text = "Form1";
} }
#endregion #endregion

View File

@ -1,8 +1,8 @@
namespace WinFormsAppByPlugins namespace WinFormsAppByPlugins
{ {
public partial class Form1 : Form public partial class FormMain : Form
{ {
public Form1() public FormMain()
{ {
InitializeComponent(); InitializeComponent();
} }

View File

@ -0,0 +1,60 @@
<root>
<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

@ -11,7 +11,7 @@ namespace WinFormsAppByPlugins
// To customize application configuration such as set high DPI settings or default font, // To customize application configuration such as set high DPI settings or default font,
// see https://aka.ms/applicationconfiguration. // see https://aka.ms/applicationconfiguration.
ApplicationConfiguration.Initialize(); ApplicationConfiguration.Initialize();
Application.Run(new Form1()); Application.Run(new FormMain());
} }
} }
} }