using Contracts.StorageContracts; using Contracts.ViewModels; using ControlsLibraryNet60.Data; using ControlsLibraryNet60.Models; using DateBaseImplement.Implements; using PdfFormsLibrary; using PluginsConventionLibrary; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; using WinFormsLibrary; using WinFormsLibrary.not_visual; using WinFormsLibrary.SupportClasses; namespace AppView { public class PluginsConvention : IPluginsConvention { private readonly IProviderStorage _providerStorage; private readonly ITypeStorage _typeStorage; private readonly DocumentWithImage documentWithImage1; private readonly Table2column table2column1; private readonly Gistograma gistograma1; private readonly ControlDataTableTable DataTable = new ControlDataTableTable(); public string PluginName { get; set; } = "LabWork_03_plugin"; public UserControl GetControl { get { ReloadData(); return DataTable; } } public PluginsConventionElement GetElement { get { var provider = DataTable.GetSelectedObject(); int id = -1; if (provider != null) { id = Convert.ToInt32(provider.Id); } byte[] bytes = new byte[16]; BitConverter.GetBytes(id).CopyTo(bytes, 0); return new() { Id = new Guid(bytes) }; } } public PluginsConvention() { _providerStorage = new ProviderStorage(); _typeStorage = new TypeStorage(); documentWithImage1 = new(); table2column1 = new(); gistograma1 = new(); List columns = new List { new DataTableColumnConfig { ColumnHeader = "Id", PropertyName = "Id", Visible = false }, new DataTableColumnConfig { ColumnHeader = "Название", PropertyName = "Name", Visible = true }, new DataTableColumnConfig { ColumnHeader = "Тип изделий", PropertyName = "Type", Visible = true }, new DataTableColumnConfig { ColumnHeader = "Телефон", PropertyName = "Number", Visible = true } }; DataTable.LoadColumns(columns); } public Form GetForm(PluginsConventionElement element) { if (element == null) { return new FormProvider(_providerStorage, _typeStorage); } else { FormProvider form = new FormProvider(_providerStorage, _typeStorage); form.Id = element.Id.GetHashCode(); return form; } } public Form GetThesaurus() { return new FormType(_typeStorage); } public bool DeleteElement(PluginsConventionElement element) { _providerStorage.Delete( new(element.Id.GetHashCode()) ); return true; } public void ReloadData() { try { var list = _providerStorage.GetFullList(); DataTable.Clear(); DataTable.AddTable(list); } catch (Exception ex) { MessageBox.Show( ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error ); } } public bool CreateWordDocument(PluginsConventionSaveDocument saveDocument) { ImageClass info = new ImageClass(); var images = _providerStorage.GetFullList().Select(x => x.Logo).ToList(); info.Title = "Images"; info.Path = saveDocument.FileName; info.Files = images; documentWithImage1.CreateDocument(info); return true; } public bool CreateTableDocument(PluginsConventionSaveDocument saveDocument) { System.Text.Encoding.RegisterProvider(System.Text.CodePagesEncodingProvider.Instance); List columnDefinitionsUp = new List { new ColumnDefinition{Header = "#", PropertyName = "Id", Weight = 30}, new ColumnDefinition{Header = "Информация", PropertyName = "NumberType", Weight = 30}, new ColumnDefinition{Header = "", PropertyName = "NumberType", Weight = 30}, new ColumnDefinition{Header = "Номер телефона", PropertyName = "Number", Weight = 30}, }; List columnDefinitionsDown = new List { new ColumnDefinition{Header = "#", PropertyName = "Id", Weight = 30}, new ColumnDefinition{Header = "Название", PropertyName = "Name", Weight = 30}, new ColumnDefinition{Header = "Тип изделия", PropertyName = "Type", Weight = 30}, new ColumnDefinition{Header = "-", PropertyName = "Number", Weight = 30}, }; var providers = _providerStorage.GetFullList(); List mergedColums = new() { new int[] { 1, 2 } }; BigTable info = new(saveDocument.FileName, "Table", columnDefinitionsUp, columnDefinitionsDown, providers, mergedColums); table2column1.CreateTable(info); MessageBox.Show("Готово"); return true; } public bool CreateChartDocument(PluginsConventionSaveDocument saveDocument) { var providers = _providerStorage.GetFullList(); var uniqueTypes = providers.Select(p => p.Type).Distinct(); List data = new List(); foreach (var uniqueType in uniqueTypes) { var typeProviders = providers.Where(p => p.Type == uniqueType).ToList(); var dataList = new List(); // Используем Count() для подсчета общего количества поставщиков каждого типа int totalCount = typeProviders.Count(); ChartData chData = new ChartData(); chData.SeriesName = uniqueType; chData.Data = new double[] { totalCount }; data.Add(chData); } gistograma1.GenerateExcelChartDocument(saveDocument.FileName, "Сводка по типам изделия.", "Количество поставщиков для товаров каждого типа", WinFormsLibrary.not_visual.LegendPosition.Bottom, data); return true; } } }