202 lines
7.3 KiB
C#
202 lines
7.3 KiB
C#
using AbazovViewComponents.Components;
|
|
using AbazovViewComponents.LogicalComponents;
|
|
using AccountBusinessLogic.BusinessLogic;
|
|
using AccountContracts.BusinessLogicsContracts;
|
|
using AccountContracts.ViewModels;
|
|
using AccountDatabaseImplement.Implements;
|
|
using AccountDatabaseImplement.Models;
|
|
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 : IPluginsConvention
|
|
{
|
|
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<AccountViewModel>()!.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 accounts = _accountLogic.ReadList(null);
|
|
if (accounts != null)
|
|
{
|
|
_abazovTreeView.clear();
|
|
|
|
_abazovTreeView.setHierarchy(new List<(string, bool)> { ("RoleName", false), ("ViewRating", false), ("Id", true), ("Login", true) });
|
|
|
|
foreach (var account in accounts)
|
|
{
|
|
if (!account.Rating.HasValue)
|
|
{
|
|
account.ViewRating = 0;
|
|
}
|
|
else
|
|
{
|
|
account.ViewRating = account.Rating.Value;
|
|
}
|
|
}
|
|
|
|
_abazovTreeView.addItems(accounts);
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
MessageBox.Show(
|
|
ex.Message,
|
|
"Ошибка",
|
|
MessageBoxButtons.OK,
|
|
MessageBoxIcon.Error
|
|
);
|
|
}
|
|
}
|
|
|
|
public bool CreateSimpleDocument(PluginsConventionSaveDocument saveDocument)
|
|
{
|
|
List<string> paragraphs = new List<string>();
|
|
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<string> paragraphs = new List<string>();
|
|
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<AccountViewModel> config = new ComponentsLibraryNet60.Models.ComponentDocumentWithTableHeaderDataConfig<AccountViewModel>
|
|
{
|
|
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<string> paragraphs = new List<string>();
|
|
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;
|
|
}
|
|
}
|
|
}
|