From 33236df4314c27e1c5e14993556e327dfc585934 Mon Sep 17 00:00:00 2001
From: ksenianeva <95441235+ksenianeva@users.noreply.github.com>
Date: Fri, 1 Dec 2023 02:47:11 +0400
Subject: [PATCH] Add plugins convention
---
.../AccountsView/AccountsView.csproj | 9 +
.../AccountsView/PluginsConvention.cs | 188 ++++++++++++++++++
2 files changed, 197 insertions(+)
create mode 100644 NevaevaLibrary/AccountsView/PluginsConvention.cs
diff --git a/NevaevaLibrary/AccountsView/AccountsView.csproj b/NevaevaLibrary/AccountsView/AccountsView.csproj
index e96fc91..351ad8a 100644
--- a/NevaevaLibrary/AccountsView/AccountsView.csproj
+++ b/NevaevaLibrary/AccountsView/AccountsView.csproj
@@ -19,11 +19,20 @@
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/NevaevaLibrary/AccountsView/PluginsConvention.cs b/NevaevaLibrary/AccountsView/PluginsConvention.cs
new file mode 100644
index 0000000..7dc7ad7
--- /dev/null
+++ b/NevaevaLibrary/AccountsView/PluginsConvention.cs
@@ -0,0 +1,188 @@
+using AbazovViewComponents.Components;
+using AbazovViewComponents.LogicalComponents;
+using AccountBusinessLogic.BusinessLogic;
+using AccountContracts.BusinessLogicsContracts;
+using AccountContracts.ViewModels;
+using AccountDatabaseImplement.Implements;
+using ComponentsLibraryNet60.DocumentWithChart;
+using ComponentsLibraryNet60.DocumentWithTable;
+using ComponentsLibraryNet60.Models;
+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;
+using System.Windows.Forms;
+
+namespace AccountsView
+{
+ public class PluginsConvention
+ {
+ private readonly IAccountLogic _accountLogic;
+ private readonly IRoleLogic _roleLogic;
+ private readonly AbazovTreeView _abazovTreeView;
+ private readonly WordLongTextComponent wordLongTextComponent;
+ private readonly ExcelDiagramComponent excelDiagramComponent;
+ private readonly ComponentDocumentWithTableMultiHeaderPdf componentDocumentWithTableMultiHeaderPdf;
+ public string PluginName { get; set; } = "LabWork_03_plugin";
+
+ public UserControl GetControl
+ {
+ get { return _abazovTreeView; }
+ }
+
+ public PluginsConvention()
+ {
+ _accountLogic = new AccountLogic(new AccountStorage());
+ _roleLogic = new RoleLogic(new RoleStorage());
+ wordLongTextComponent = new();
+ excelDiagramComponent = new();
+ componentDocumentWithTableMultiHeaderPdf = new();
+ _abazovTreeView = new();
+ }
+
+ public PluginsConventionElement GetElement
+ {
+ get
+ {
+ int Id = _abazovTreeView.getSelecetedNodeValue()!.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, _roleLogic);
+ }
+ else
+ {
+ FormAccount form = new FormAccount(_accountLogic, _roleLogic);
+ form.Id = element.Id.GetHashCode();
+ return form;
+ }
+ }
+
+ public Form GetThesaurus()
+ {
+ return new FormRoles(_roleLogic);
+ }
+
+ public bool DeleteElement(PluginsConventionElement element)
+ {
+ _accountLogic.Delete(
+ new AccountContracts.BindingModels.AccountBindingModel { Id = element.Id.GetHashCode() }
+ );
+ return true;
+ }
+
+ public void ReloadData()
+ {
+ try
+ {
+ var account = _accountLogic.ReadList(null);
+ if (account != null)
+ {
+ _abazovTreeView.clear();
+
+ _abazovTreeView.setHierarchy(new List<(string, bool)> { ("RoleName", false), ("ViewRating", false), ("Id", true), ("Login", true) });
+
+ _abazovTreeView.addItems(account);
+ }
+ }
+ catch (Exception ex)
+ {
+ MessageBox.Show(
+ ex.Message,
+ "Ошибка",
+ MessageBoxButtons.OK,
+ MessageBoxIcon.Error
+ );
+ }
+ }
+
+ public bool CreateSimpleDocument(PluginsConventionSaveDocument saveDocument)
+ {
+ List paragraphs = new List();
+ foreach (var account in _accountLogic.ReadList(null))
+ {
+ if (account.Rating == null)
+ {
+ paragraphs.Add(account.Login + ": " + account.Warnings);
+ }
+ }
+ string path = saveDocument.FileName;
+ wordLongTextComponent.createWithLongText(new WordLongTextInfo(path, "Аккаунты без рейтинга", paragraphs.ToArray()));
+ MessageBox.Show("Документ создан");
+ return true;
+ }
+
+ public bool CreateTableDocument(PluginsConventionSaveDocument saveDocument)
+ {
+ Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);
+ List paragraphs = new List();
+ string path = saveDocument.FileName;
+ var accounts = _accountLogic.ReadList(null);
+ foreach (var account in accounts)
+ {
+ if (!account.Rating.HasValue)
+ {
+ account.DocRating = "нет";
+ }
+ else
+ {
+ account.DocRating = account.Rating.Value.ToString();
+ }
+ }
+ ComponentDocumentWithTableHeaderDataConfig config = new ComponentsLibraryNet60.Models.ComponentDocumentWithTableHeaderDataConfig
+ {
+ Data = accounts,
+ UseUnion = false,
+ Header = "Аккаунты",
+ ColumnsRowsDataCount = (4, 1),
+ Headers = new List<(int ColumnIndex, int RowIndex, string Header, string PropertyName)>
+ {
+ (0, 0, "Id", "Id"),
+ (1, 0, "Логин", "Login"),
+ (2, 0, "Роль", "RoleName"),
+ (3, 0, "Рейтинг", "DocRating")
+ },
+ ColumnsRowsWidth = new List<(int Column, int Row)>
+ {
+ (10, 10),
+ (10, 10),
+ (10, 10),
+ (10, 10)
+ },
+ ColumnUnion = new List<(int StartIndex, int Count)>(),
+ FilePath = path
+ };
+ componentDocumentWithTableMultiHeaderPdf.CreateDoc(config);
+ MessageBox.Show("Документ создан");
+ return true;
+ }
+
+ public bool CreateChartDocument(PluginsConventionSaveDocument saveDocument)
+ {
+ List paragraphs = new List();
+ string path = saveDocument.FileName;
+ var data = _accountLogic.ReadList(null).Where(x => x.Rating == null).GroupBy(x => x.RoleName).Select(x => new
+ {
+ RoleName = x.Key,
+ RoleCount = x.Count(),
+ }).ToList();
+ excelDiagramComponent.createWithDiagram(path, "Роли без рейтинга", "Роли без рейтинга", AbazovViewComponents.LogicalComponents.DiagramLegendEnum.BottomRight,
+ data, "RoleName", "RoleCount");
+ MessageBox.Show("Документ создан");
+ return true;
+ }
+ }
+}