Add plugins convention
This commit is contained in:
parent
d80bc5497c
commit
33236df431
@ -19,11 +19,20 @@
|
|||||||
<PackageReference Include="System.Text.Encoding.CodePages" Version="7.0.0" />
|
<PackageReference Include="System.Text.Encoding.CodePages" Version="7.0.0" />
|
||||||
</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 "$(TargetDir)*.dll" "$(SolutionDir)Plugins\*.dll"" />
|
||||||
|
</Target>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ProjectReference Include="..\AccountBusinessLogic\AccountBusinessLogic.csproj" />
|
<ProjectReference Include="..\AccountBusinessLogic\AccountBusinessLogic.csproj" />
|
||||||
<ProjectReference Include="..\AccountContracts\AccountContracts.csproj" />
|
<ProjectReference Include="..\AccountContracts\AccountContracts.csproj" />
|
||||||
<ProjectReference Include="..\AccountDatabaseImplement\AccountDatabaseImplement.csproj" />
|
<ProjectReference Include="..\AccountDatabaseImplement\AccountDatabaseImplement.csproj" />
|
||||||
<ProjectReference Include="..\NevaevaLibrary\NevaevaLibrary.csproj" />
|
<ProjectReference Include="..\NevaevaLibrary\NevaevaLibrary.csproj" />
|
||||||
|
<ProjectReference Include="..\PluginsConventionLibrary\PluginsConventionLibrary.csproj" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
</Project>
|
</Project>
|
188
NevaevaLibrary/AccountsView/PluginsConvention.cs
Normal file
188
NevaevaLibrary/AccountsView/PluginsConvention.cs
Normal file
@ -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<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 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<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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user