diff --git a/AbazovApp/AbazovApp.sln b/AbazovApp/AbazovApp.sln index fc719ea..972f6ce 100644 --- a/AbazovApp/AbazovApp.sln +++ b/AbazovApp/AbazovApp.sln @@ -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 diff --git a/AbazovApp/AccountAppPlugins/AccountAppPlugins.csproj b/AbazovApp/AccountAppPlugins/AccountAppPlugins.csproj new file mode 100644 index 0000000..b57c89e --- /dev/null +++ b/AbazovApp/AccountAppPlugins/AccountAppPlugins.csproj @@ -0,0 +1,11 @@ + + + + WinExe + net6.0-windows + enable + true + enable + + + \ No newline at end of file diff --git a/AbazovApp/AccountAppPlugins/FormMain.Designer.cs b/AbazovApp/AccountAppPlugins/FormMain.Designer.cs new file mode 100644 index 0000000..af0909e --- /dev/null +++ b/AbazovApp/AccountAppPlugins/FormMain.Designer.cs @@ -0,0 +1,39 @@ +namespace AccountAppPlugins +{ + partial class FormMain + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + 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 + } +} \ No newline at end of file diff --git a/AbazovApp/AccountAppPlugins/FormMain.cs b/AbazovApp/AccountAppPlugins/FormMain.cs new file mode 100644 index 0000000..7c60377 --- /dev/null +++ b/AbazovApp/AccountAppPlugins/FormMain.cs @@ -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(); + } + } +} diff --git a/AbazovApp/AccountAppPlugins/FormMain.resx b/AbazovApp/AccountAppPlugins/FormMain.resx new file mode 100644 index 0000000..1af7de1 --- /dev/null +++ b/AbazovApp/AccountAppPlugins/FormMain.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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/AbazovApp/AccountAppPlugins/Program.cs b/AbazovApp/AccountAppPlugins/Program.cs new file mode 100644 index 0000000..507934a --- /dev/null +++ b/AbazovApp/AccountAppPlugins/Program.cs @@ -0,0 +1,17 @@ +namespace AccountAppPlugins +{ + internal static class Program + { + /// + /// The main entry point for the application. + /// + [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()); + } + } +} \ No newline at end of file diff --git a/AbazovApp/AccountsApp/AccountsApp.csproj b/AbazovApp/AccountsApp/AccountsApp.csproj index ff7b89f..3e093f8 100644 --- a/AbazovApp/AccountsApp/AccountsApp.csproj +++ b/AbazovApp/AccountsApp/AccountsApp.csproj @@ -23,8 +23,17 @@ + + + + + + + + + True diff --git a/AbazovApp/AccountsApp/PluginsConvention.cs b/AbazovApp/AccountsApp/PluginsConvention.cs new file mode 100644 index 0000000..aa16346 --- /dev/null +++ b/AbazovApp/AccountsApp/PluginsConvention.cs @@ -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()!.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 { + 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 avatars = new List(); + 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 widths = new List { 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> data = new Dictionary>(); + + 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; + } + } +} diff --git a/AbazovApp/AccountsContracts/BindingModels/AccountBindingModel.cs b/AbazovApp/AccountsContracts/BindingModels/AccountBindingModel.cs index 9e832c0..d05fb83 100644 --- a/AbazovApp/AccountsContracts/BindingModels/AccountBindingModel.cs +++ b/AbazovApp/AccountsContracts/BindingModels/AccountBindingModel.cs @@ -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; + } } }