diff --git a/WinFormsProject/AppView/PluginsConvention.cs b/WinFormsProject/AppView/PluginsConvention.cs index ee80b67..86006b5 100644 --- a/WinFormsProject/AppView/PluginsConvention.cs +++ b/WinFormsProject/AppView/PluginsConvention.cs @@ -146,73 +146,99 @@ namespace AppView public bool CreateWordDocument(PluginsConventionSaveDocument saveDocument) { - ImageClass info = new ImageClass(); + try + { + ImageClass info = new ImageClass(); - var images = _providerStorage.GetFullList().Select(x => x.Logo).ToList(); + var images = _providerStorage.GetFullList().Select(x => x.Logo).ToList(); - info.Title = "Images"; - info.Path = saveDocument.FileName; - info.Files = images; + info.Title = "Images"; + info.Path = saveDocument.FileName; + info.Files = images; - documentWithImage1.CreateDocument(info); - return true; + documentWithImage1.CreateDocument(info); + MessageBox.Show("Готово"); + return true; + } + catch(Exception e) + { + MessageBox.Show(e.Message, "Ошибка"); + return false; + } } public bool CreateTableDocument(PluginsConventionSaveDocument saveDocument) { - System.Text.Encoding.RegisterProvider(System.Text.CodePagesEncodingProvider.Instance); + try + { + System.Text.Encoding.RegisterProvider(System.Text.CodePagesEncodingProvider.Instance); - List columnDefinitionsUp = new List { + 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 { + 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(); + var providers = _providerStorage.GetFullList(); - List mergedColums = new() { new int[] { 1, 2 } }; + List mergedColums = new() { new int[] { 1, 2 } }; - BigTable info = new(saveDocument.FileName, "Table", columnDefinitionsUp, columnDefinitionsDown, providers, mergedColums); + BigTable info = new(saveDocument.FileName, "Table", columnDefinitionsUp, columnDefinitionsDown, providers, mergedColums); - table2column1.CreateTable(info); - MessageBox.Show("Готово"); - return true; + table2column1.CreateTable(info); + MessageBox.Show("Готово"); + return true; + } + catch(Exception e) + { + MessageBox.Show(e.Message, "Ошибка"); + return false; + } } 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) + try { - var typeProviders = providers.Where(p => p.Type == uniqueType).ToList(); + var providers = _providerStorage.GetFullList(); - var dataList = new List(); + var uniqueTypes = providers.Select(p => p.Type).Distinct(); - // Используем Count() для подсчета общего количества поставщиков каждого типа - int totalCount = typeProviders.Count(); + List data = new List(); - ChartData chData = new ChartData(); - chData.SeriesName = uniqueType; - chData.Data = new double[] { totalCount }; + foreach (var uniqueType in uniqueTypes) + { + var typeProviders = providers.Where(p => p.Type == uniqueType).ToList(); - data.Add(chData); + 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); + MessageBox.Show("Готово"); + return true; + } + catch(Exception e) + { + MessageBox.Show(e.Message, "Ошибка"); + return false; } - - gistograma1.GenerateExcelChartDocument(saveDocument.FileName, "Сводка по типам изделия.", "Количество поставщиков для товаров каждого типа", WinFormsLibrary.not_visual.LegendPosition.Bottom, data); - return true; } diff --git a/WinFormsProject/Plugins/AppView.dll b/WinFormsProject/Plugins/AppView.dll index 2246454..5cb2a4c 100644 Binary files a/WinFormsProject/Plugins/AppView.dll and b/WinFormsProject/Plugins/AppView.dll differ diff --git a/WinFormsProject/WinFormsAppByPlugins/FormMain.cs b/WinFormsProject/WinFormsAppByPlugins/FormMain.cs index 4fd4907..6813cf0 100644 --- a/WinFormsProject/WinFormsAppByPlugins/FormMain.cs +++ b/WinFormsProject/WinFormsAppByPlugins/FormMain.cs @@ -183,38 +183,50 @@ namespace WinFormsAppByPlugins private void CreateSimpleDoc() { - SaveFileDialog saveFileDialog = new() + try { - Filter = "Word Files|*.docx" - }; - if (saveFileDialog.ShowDialog() == DialogResult.OK) - { - _plugins[_selectedPlugin].CreateWordDocument(new PluginsConventionSaveDocument() { FileName = saveFileDialog.FileName }); + SaveFileDialog saveFileDialog = new() + { + Filter = "Word Files|*.docx" + }; + if (saveFileDialog.ShowDialog() == DialogResult.OK) + { + _plugins[_selectedPlugin].CreateWordDocument(new PluginsConventionSaveDocument() { FileName = saveFileDialog.FileName }); - } + } + } + catch(Exception ex) { MessageBox.Show(ex.Message, " ."); } } private void CreateTableDoc() { - SaveFileDialog saveFileDialog = new() + try { - Filter = "PDF Files|*.pdf" - }; - if (saveFileDialog.ShowDialog() == DialogResult.OK) - { - _plugins[_selectedPlugin].CreateTableDocument(new PluginsConventionSaveDocument() { FileName = saveFileDialog.FileName }); + SaveFileDialog saveFileDialog = new() + { + Filter = "PDF Files|*.pdf" + }; + if (saveFileDialog.ShowDialog() == DialogResult.OK) + { + _plugins[_selectedPlugin].CreateTableDocument(new PluginsConventionSaveDocument() { FileName = saveFileDialog.FileName }); + } } + catch (Exception ex) { MessageBox.Show(ex.Message, " ."); } } private void CreateChartDoc() { - SaveFileDialog saveFileDialog = new() + try { - Filter = "Excel Files|*.xlsx" - }; - if (saveFileDialog.ShowDialog() == DialogResult.OK) - { - _plugins[_selectedPlugin].CreateChartDocument(new PluginsConventionSaveDocument() { FileName = saveFileDialog.FileName }); + SaveFileDialog saveFileDialog = new() + { + Filter = "Excel Files|*.xlsx" + }; + if (saveFileDialog.ShowDialog() == DialogResult.OK) + { + _plugins[_selectedPlugin].CreateChartDocument(new PluginsConventionSaveDocument() { FileName = saveFileDialog.FileName }); + } } + catch (Exception ex) { MessageBox.Show(ex.Message, " ."); } } private void ThesaurusToolStripMenuItem_Click(object sender, EventArgs e) => ShowThesaurus();