200 lines
7.3 KiB
C#
200 lines
7.3 KiB
C#
using ChubykinaComponents.Components;
|
|
using ChubykinaComponents.LogicalComponents;
|
|
using BulatovaComponents.NonVisualComponents;
|
|
using ComponentsLibraryNet60.DocumentWithChart;
|
|
using ComponentsLibraryNet60.DocumentWithTable;
|
|
using ComponentsLibraryNet60.Models;
|
|
using ControlsLibraryNet60.Data;
|
|
using ControlsLibraryNet60.Models;
|
|
using PluginsConventionLibrary;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using System.Windows.Forms;
|
|
using ClientsContracts.BusinessLogicContracts;
|
|
using ClientsContracts.ViewModels;
|
|
using ClientBusinessLogic.BusinessLogics;
|
|
using ClientsDatabaseImplement.Implements;
|
|
|
|
namespace WinForms
|
|
{
|
|
public class PluginsConvention : IPluginsConvention
|
|
{
|
|
private readonly IClientLogic _clientLogic;
|
|
private readonly IStatusLogic _statusLogic;
|
|
private readonly UserTreeView _myTreeView;
|
|
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 _myTreeView; }
|
|
}
|
|
|
|
public PluginsConvention()
|
|
{
|
|
_clientLogic = new ClientLogic(new ClientStorage());
|
|
_statusLogic = new StatusLogic(new StatusStorage());
|
|
wordLongTextComponent = new();
|
|
excelDiagramComponent = new();
|
|
componentDocumentWithTableMultiHeaderPdf = new();
|
|
_myTreeView = new();
|
|
}
|
|
|
|
public PluginsConventionElement GetElement
|
|
{
|
|
get
|
|
{
|
|
int Id = _myTreeView.getSelecetedNodeValue<ClientViewModel>()!.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 FormClient(_clientLogic, _statusLogic);
|
|
}
|
|
else
|
|
{
|
|
FormClient form = new FormClient(_clientLogic, _statusLogic);
|
|
form.Id = element.Id.GetHashCode();
|
|
return form;
|
|
}
|
|
}
|
|
|
|
public Form GetThesaurus()
|
|
{
|
|
return new FormStatus(_statusLogic);
|
|
}
|
|
|
|
public bool DeleteElement(PluginsConventionElement element)
|
|
{
|
|
_clientLogic.Delete(
|
|
new ClientsContracts.BindingModels.ClientBindingModel { Id = element.Id.GetHashCode() }
|
|
);
|
|
return true;
|
|
}
|
|
|
|
public void ReloadData()
|
|
{
|
|
try
|
|
{
|
|
var clients = _clientLogic.ReadList(null);
|
|
if (clients != null)
|
|
{
|
|
_myTreeView.clear();
|
|
|
|
_myTreeView.setHierarchy(new List<(string, bool)> { ("StatusName", false), ("ViewAmount", false), ("Id", true), ("Name", true) });
|
|
|
|
foreach (var client in clients)
|
|
{
|
|
if (!client.Amount.HasValue)
|
|
{
|
|
client.ViewAmount = "нет покупок";
|
|
}
|
|
else
|
|
{
|
|
client.ViewAmount = client.Amount.Value.ToString();
|
|
}
|
|
}
|
|
|
|
_myTreeView.addItems(clients);
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
MessageBox.Show(
|
|
ex.Message,
|
|
"Ошибка",
|
|
MessageBoxButtons.OK,
|
|
MessageBoxIcon.Error
|
|
);
|
|
}
|
|
}
|
|
|
|
public bool CreateSimpleDocument(PluginsConventionSaveDocument saveDocument)
|
|
{
|
|
List<string> paragraphs = new List<string>();
|
|
foreach (var client in _clientLogic.ReadList(null))
|
|
{
|
|
if (client.Amount == null)
|
|
{
|
|
paragraphs.Add(client.Name + ": " + client.Reviews);
|
|
}
|
|
}
|
|
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 clients = _clientLogic.ReadList(null);
|
|
foreach (var client in clients)
|
|
{
|
|
if (!client.Amount.HasValue)
|
|
{
|
|
client.DocAmount = "нет";
|
|
}
|
|
else
|
|
{
|
|
client.DocAmount = client.Amount.Value.ToString();
|
|
}
|
|
}
|
|
ComponentDocumentWithTableHeaderDataConfig<ClientViewModel> config = new ComponentsLibraryNet60.Models.ComponentDocumentWithTableHeaderDataConfig<ClientViewModel>
|
|
{
|
|
Data = clients,
|
|
UseUnion = false,
|
|
Header = "Аккаунты",
|
|
ColumnsRowsDataCount = (4, 1),
|
|
Headers = new List<(int ColumnIndex, int RowIndex, string Header, string PropertyName)>
|
|
{
|
|
(0, 0, "Id", "Id"),
|
|
(1, 0, "ФИО", "Name"),
|
|
(2, 0, "Статус", "StatusName"),
|
|
(3, 0, "Сумма покупок", "DocAmount")
|
|
},
|
|
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 = _clientLogic.ReadList(null).Where(x => x.Amount == null).GroupBy(x => x.StatusName).Select(x => new
|
|
{
|
|
StatusName = x.Key,
|
|
StatusCount = x.Count(),
|
|
}).ToList();
|
|
excelDiagramComponent.createWithDiagram(path, "Статус без суммы покупок", "Статус без суммы покупок", ChubykinaComponents.LogicalComponents.DiagramLegendEnum.BottomRight,
|
|
data, "StatusName", "StatusCount");
|
|
MessageBox.Show("Документ создан");
|
|
return true;
|
|
}
|
|
}
|
|
} |