Zhelovanov_Dmitrii_COP/WinForm/NonVisualForm.cs

144 lines
3.4 KiB
C#
Raw Normal View History

using DocumentFormat.OpenXml.Bibliography;
using DocumentFormat.OpenXml.Spreadsheet;
using KOP_Labs.Classes;
using Microsoft.VisualBasic.ApplicationServices;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace WinForm
{
public partial class NonVisualForm : Form
{
public NonVisualForm()
{
InitializeComponent();
}
MyHistogramm histogram;
private void buttonWordSave_Click(object sender, EventArgs e)
{
2023-11-03 11:07:28 +04:00
using var dialog = new SaveFileDialog
{
Filter = "docx|*.docx"
};
if (dialog.ShowDialog() == DialogResult.OK)
{
try
{
string title = "Заголовок";
string[,] row1 = {
{ "Стр1 Кол1", "Стр1 Кол2" }
};
2023-11-03 11:07:28 +04:00
string[,] row2 = {
{ "Стр2 Кол1", "Стр2 Кол2" }
};
2023-11-03 11:07:28 +04:00
string[,] row3 = {
{ "Стр3 Кол1", "Стр3 Кол3" }
};
2023-11-03 11:07:28 +04:00
MyTable table = new MyTable(dialog.FileName, title, new List<string[,]> { row1, row2, row3 });
wordTableComponent1.CreateDoc(table);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
private void buttonSaveHist_Click(object sender, EventArgs e)
{
2023-11-03 11:07:28 +04:00
using var dialog = new SaveFileDialog
{
Filter = "docx|*.docx"
};
if (dialog.ShowDialog() == DialogResult.OK)
{
try
{
histogram = new(dialog.FileName, "Заголовок", "Гистограмма", EnumLegends.Right, new List<DataHistogramm> {
new DataHistogramm("Тихий дон", 170), new DataHistogramm("Мастер и Маргарита", 400),
new DataHistogramm("Сборник Пушкина", 240), new DataHistogramm("12 стульев", 200)
});
2023-11-03 11:07:28 +04:00
wordHistogramm1.CreateHistogramm(histogram);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
List<Book> books;
2023-11-03 11:07:28 +04:00
Book book1 = new Book("Pushkin", 1, "fgsddsdf", "fdsds");
Book book2 = new Book("Pushkin", 2, "aa", "fdads");
Book book3 = new Book("Pushkin", 3, "fgdf", "ffsds");
Book book4 = new Book("Lermontov", 4, "ffsssff", "asdss");
Book book5 = new Book("Lermontov", 5, "ffdsff", "asdsss");
Book book6 = new Book("Pushkin", 6, "fgdf", "ffsds");
Dictionary<int, ColumnParameters> colData;
private void buttonHead_Click(object sender, EventArgs e)
{
2023-11-03 11:07:28 +04:00
books = new()
{
2023-11-03 11:07:28 +04:00
book1, book2, book3, book4, book5, book6
};
colData = new Dictionary<int, ColumnParameters>()
{
2023-11-03 11:07:28 +04:00
{ 0, new ColumnParameters("Автор", "Author") },
{ 1, new ColumnParameters("Id книги", "Id") },
{ 2, new ColumnParameters("Имя", "Name") },
{ 3, new ColumnParameters("Аннотация", "Annotation") }
};
2023-11-03 11:07:28 +04:00
using var dialog = new SaveFileDialog
{
Filter = "docx|*.docx"
};
if (dialog.ShowDialog() == DialogResult.OK)
{
try
{
MyTableWithHead<Book> myTable = new(dialog.FileName, "Заголовок", new List<double> { 50, 50 },
new List<double> { 2000, 2000, 1500, 1500 }, books.GroupBy(b => b.Author).SelectMany(a => a).ToList(), colData);
wordTableHeaderComponent1.CreateDoc(myTable);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
}
}