Полностью доделал

This commit is contained in:
Артём Алейкин 2023-12-14 01:48:08 +04:00
parent 34d262287b
commit 290b40fe1c
3 changed files with 91 additions and 53 deletions

View File

@ -146,73 +146,99 @@ namespace AppView
public bool CreateWordDocument(PluginsConventionSaveDocument saveDocument) 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.Title = "Images";
info.Path = saveDocument.FileName; info.Path = saveDocument.FileName;
info.Files = images; info.Files = images;
documentWithImage1.CreateDocument(info); documentWithImage1.CreateDocument(info);
return true; MessageBox.Show("Готово");
return true;
}
catch(Exception e)
{
MessageBox.Show(e.Message, "Ошибка");
return false;
}
} }
public bool CreateTableDocument(PluginsConventionSaveDocument saveDocument) public bool CreateTableDocument(PluginsConventionSaveDocument saveDocument)
{ {
System.Text.Encoding.RegisterProvider(System.Text.CodePagesEncodingProvider.Instance); try
{
System.Text.Encoding.RegisterProvider(System.Text.CodePagesEncodingProvider.Instance);
List<ColumnDefinition> columnDefinitionsUp = new List<ColumnDefinition> { List<ColumnDefinition> columnDefinitionsUp = new List<ColumnDefinition> {
new ColumnDefinition{Header = "#", PropertyName = "Id", Weight = 30}, 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 = "NumberType", Weight = 30}, new ColumnDefinition{Header = "", PropertyName = "NumberType", Weight = 30},
new ColumnDefinition{Header = "Номер телефона", PropertyName = "Number", Weight = 30}, new ColumnDefinition{Header = "Номер телефона", PropertyName = "Number", Weight = 30},
}; };
List<ColumnDefinition> columnDefinitionsDown = new List<ColumnDefinition> { List<ColumnDefinition> columnDefinitionsDown = new List<ColumnDefinition> {
new ColumnDefinition{Header = "#", PropertyName = "Id", Weight = 30}, new ColumnDefinition{Header = "#", PropertyName = "Id", Weight = 30},
new ColumnDefinition{Header = "Название", PropertyName = "Name", Weight = 30}, new ColumnDefinition{Header = "Название", PropertyName = "Name", Weight = 30},
new ColumnDefinition{Header = "Тип изделия", PropertyName = "Type", Weight = 30}, new ColumnDefinition{Header = "Тип изделия", PropertyName = "Type", Weight = 30},
new ColumnDefinition{Header = "-", PropertyName = "Number", Weight = 30}, new ColumnDefinition{Header = "-", PropertyName = "Number", Weight = 30},
}; };
var providers = _providerStorage.GetFullList(); var providers = _providerStorage.GetFullList();
List<int[]> mergedColums = new() { new int[] { 1, 2 } }; List<int[]> mergedColums = new() { new int[] { 1, 2 } };
BigTable<ProviderViewModel> info = new(saveDocument.FileName, "Table", columnDefinitionsUp, columnDefinitionsDown, providers, mergedColums); BigTable<ProviderViewModel> info = new(saveDocument.FileName, "Table", columnDefinitionsUp, columnDefinitionsDown, providers, mergedColums);
table2column1.CreateTable(info); table2column1.CreateTable(info);
MessageBox.Show("Готово"); MessageBox.Show("Готово");
return true; return true;
}
catch(Exception e)
{
MessageBox.Show(e.Message, "Ошибка");
return false;
}
} }
public bool CreateChartDocument(PluginsConventionSaveDocument saveDocument) public bool CreateChartDocument(PluginsConventionSaveDocument saveDocument)
{ {
var providers = _providerStorage.GetFullList(); try
var uniqueTypes = providers.Select(p => p.Type).Distinct();
List<ChartData> data = new List<ChartData>();
foreach (var uniqueType in uniqueTypes)
{ {
var typeProviders = providers.Where(p => p.Type == uniqueType).ToList(); var providers = _providerStorage.GetFullList();
var dataList = new List<double>(); var uniqueTypes = providers.Select(p => p.Type).Distinct();
// Используем Count() для подсчета общего количества поставщиков каждого типа List<ChartData> data = new List<ChartData>();
int totalCount = typeProviders.Count();
ChartData chData = new ChartData(); foreach (var uniqueType in uniqueTypes)
chData.SeriesName = uniqueType; {
chData.Data = new double[] { totalCount }; var typeProviders = providers.Where(p => p.Type == uniqueType).ToList();
data.Add(chData); var dataList = new List<double>();
// Используем 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;
} }

Binary file not shown.

View File

@ -183,38 +183,50 @@ namespace WinFormsAppByPlugins
private void CreateSimpleDoc() private void CreateSimpleDoc()
{ {
SaveFileDialog saveFileDialog = new() try
{ {
Filter = "Word Files|*.docx" SaveFileDialog saveFileDialog = new()
}; {
if (saveFileDialog.ShowDialog() == DialogResult.OK) Filter = "Word Files|*.docx"
{ };
_plugins[_selectedPlugin].CreateWordDocument(new PluginsConventionSaveDocument() { FileName = saveFileDialog.FileName }); if (saveFileDialog.ShowDialog() == DialogResult.OK)
{
_plugins[_selectedPlugin].CreateWordDocument(new PluginsConventionSaveDocument() { FileName = saveFileDialog.FileName });
} }
}
catch(Exception ex) { MessageBox.Show(ex.Message, "Îøèáêà çàãðóçêè ïëàãèíà."); }
} }
private void CreateTableDoc() private void CreateTableDoc()
{ {
SaveFileDialog saveFileDialog = new() try
{ {
Filter = "PDF Files|*.pdf" SaveFileDialog saveFileDialog = new()
}; {
if (saveFileDialog.ShowDialog() == DialogResult.OK) Filter = "PDF Files|*.pdf"
{ };
_plugins[_selectedPlugin].CreateTableDocument(new PluginsConventionSaveDocument() { FileName = saveFileDialog.FileName }); if (saveFileDialog.ShowDialog() == DialogResult.OK)
{
_plugins[_selectedPlugin].CreateTableDocument(new PluginsConventionSaveDocument() { FileName = saveFileDialog.FileName });
}
} }
catch (Exception ex) { MessageBox.Show(ex.Message, "Îøèáêà çàãðóçêè ïëàãèíà."); }
} }
private void CreateChartDoc() private void CreateChartDoc()
{ {
SaveFileDialog saveFileDialog = new() try
{ {
Filter = "Excel Files|*.xlsx" SaveFileDialog saveFileDialog = new()
}; {
if (saveFileDialog.ShowDialog() == DialogResult.OK) Filter = "Excel Files|*.xlsx"
{ };
_plugins[_selectedPlugin].CreateChartDocument(new PluginsConventionSaveDocument() { FileName = saveFileDialog.FileName }); 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(); private void ThesaurusToolStripMenuItem_Click(object sender, EventArgs e) => ShowThesaurus();