diff --git a/WinForm/AppView/AppView.csproj b/WinForm/AppView/AppView.csproj index 793bad2..912d00c 100644 --- a/WinForm/AppView/AppView.csproj +++ b/WinForm/AppView/AppView.csproj @@ -23,6 +23,15 @@ + + + + + + + + + \ No newline at end of file diff --git a/WinForm/AppView/FormMain.cs b/WinForm/AppView/FormMain.cs index 3d95b30..8b1e25d 100644 --- a/WinForm/AppView/FormMain.cs +++ b/WinForm/AppView/FormMain.cs @@ -262,7 +262,6 @@ namespace AppView simpleCircleDiagram.NameData = names.ToArray(); try { - //componentDocumentWithChartPieWord.CreateDoc(config); circleDiagram.AddCircleDiagram(simpleCircleDiagram); MessageBox.Show( "Word-документ успешно сохранен.", diff --git a/WinForm/AppView/PluginsConvention.cs b/WinForm/AppView/PluginsConvention.cs new file mode 100644 index 0000000..6a08935 --- /dev/null +++ b/WinForm/AppView/PluginsConvention.cs @@ -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()!.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 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 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 + { + 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 results = new(); + List 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; + } + } + } +} diff --git a/WinForm/Contracts/BindingModels/ProviderBindingModel.cs b/WinForm/Contracts/BindingModels/ProviderBindingModel.cs index 43aec63..ec7aed1 100644 --- a/WinForm/Contracts/BindingModels/ProviderBindingModel.cs +++ b/WinForm/Contracts/BindingModels/ProviderBindingModel.cs @@ -22,5 +22,10 @@ namespace Contracts.BindingModels { Id = provider.Id; } + + public ProviderBindingModel(int id) + { + Id = id; + } } } diff --git a/WinForm/WinFormsAppByPlugins/Form1.resx b/WinForm/WinFormsAppByPlugins/Form1.resx deleted file mode 100644 index 1af7de1..0000000 --- a/WinForm/WinFormsAppByPlugins/Form1.resx +++ /dev/null @@ -1,120 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - text/microsoft-resx - - - 2.0 - - - System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - \ No newline at end of file diff --git a/WinForm/WinFormsAppByPlugins/Form1.Designer.cs b/WinForm/WinFormsAppByPlugins/FormMain.Designer.cs similarity index 78% rename from WinForm/WinFormsAppByPlugins/Form1.Designer.cs rename to WinForm/WinFormsAppByPlugins/FormMain.Designer.cs index b730c78..747ceb4 100644 --- a/WinForm/WinFormsAppByPlugins/Form1.Designer.cs +++ b/WinForm/WinFormsAppByPlugins/FormMain.Designer.cs @@ -1,6 +1,6 @@ namespace WinFormsAppByPlugins { - partial class Form1 + partial class FormMain { /// /// Required designer variable. @@ -28,10 +28,10 @@ /// 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 = "Form1"; + components = new System.ComponentModel.Container(); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(800, 450); + Text = "Form1"; } #endregion diff --git a/WinForm/WinFormsAppByPlugins/Form1.cs b/WinForm/WinFormsAppByPlugins/FormMain.cs similarity index 59% rename from WinForm/WinFormsAppByPlugins/Form1.cs rename to WinForm/WinFormsAppByPlugins/FormMain.cs index df452a8..6c2a407 100644 --- a/WinForm/WinFormsAppByPlugins/Form1.cs +++ b/WinForm/WinFormsAppByPlugins/FormMain.cs @@ -1,8 +1,8 @@ namespace WinFormsAppByPlugins { - public partial class Form1 : Form + public partial class FormMain : Form { - public Form1() + public FormMain() { InitializeComponent(); } diff --git a/WinForm/WinFormsAppByPlugins/FormMain.resx b/WinForm/WinFormsAppByPlugins/FormMain.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/WinForm/WinFormsAppByPlugins/FormMain.resx @@ -0,0 +1,60 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/WinForm/WinFormsAppByPlugins/Program.cs b/WinForm/WinFormsAppByPlugins/Program.cs index 2974b5f..24ce584 100644 --- a/WinForm/WinFormsAppByPlugins/Program.cs +++ b/WinForm/WinFormsAppByPlugins/Program.cs @@ -11,7 +11,7 @@ namespace WinFormsAppByPlugins // To customize application configuration such as set high DPI settings or default font, // see https://aka.ms/applicationconfiguration. ApplicationConfiguration.Initialize(); - Application.Run(new Form1()); + Application.Run(new FormMain()); } } } \ No newline at end of file