2 лаба

This commit is contained in:
dimazhelovanov 2023-11-03 11:07:28 +04:00
parent 27ea0895d3
commit 0bd1b174eb
6 changed files with 90 additions and 37 deletions

View File

@ -8,15 +8,15 @@ namespace KOP_Labs.Classes
{ {
public class DataHistogramm public class DataHistogramm
{ {
public string _nameSeries { get; set; } = string.Empty;
public string _nameData { get; set; } = string.Empty; public string _nameData { get; set; } = string.Empty;
public double _data { get; set; } public double _data { get; set; }
public DataHistogramm(string nameSeries, string nameData, double data) public DataHistogramm(string nameData, int data)
{ {
_nameSeries = nameSeries;
_nameData = nameData; _nameData = nameData;
_data = data; _data = data;
} }

View File

@ -12,15 +12,13 @@ namespace KOP_Labs.Classes
public string _fileHeader = string.Empty; public string _fileHeader = string.Empty;
//высота столбцов
public List<double> _heightRow = new(); public List<double> _heightRow = new();
//высота колонок
public List<double> _widthCol = new(); public List<double> _widthCol = new();
public List<T> _dataList; public List<T> _dataList;
//настройки соответствия столбец-поле
public Dictionary<int, ColumnParameters> _columnsSettings; public Dictionary<int, ColumnParameters> _columnsSettings;
public MyTableWithHead(string filePath, string fileHeader, List<double> heightRow, public MyTableWithHead(string filePath, string fileHeader, List<double> heightRow,

View File

@ -28,7 +28,7 @@ namespace KOP_Labs.NonVisualComponents
public void CreateHistogramm(MyHistogramm myHistogramm) public void CreateHistogramm(MyHistogramm myHistogramm)
{ {
if(CheckData(myHistogramm._dataList)) { if(!CheckData(myHistogramm._dataList)) {
return; return;
} }
Document doc = new Document(); Document doc = new Document();
@ -76,7 +76,7 @@ namespace KOP_Labs.NonVisualComponents
{ {
foreach (var _data in data) foreach (var _data in data)
{ {
if (string.IsNullOrEmpty(_data._nameSeries) || string.IsNullOrEmpty(_data._data.ToString())) if (string.IsNullOrEmpty(_data._data.ToString()))
{ {
return false; return false;
} }

View File

@ -153,7 +153,7 @@ namespace KOP_Labs.NonVisualComponents
for (int i = 1; i < myTable._dataList.Count; i++) for (int i = 0; i < myTable._dataList.Count; i++)
{ {
var tr = new TableRow(); var tr = new TableRow();

View File

@ -45,9 +45,9 @@ namespace WinForm
private void buttonTable_Click(object sender, EventArgs e) private void buttonTable_Click(object sender, EventArgs e)
{ {
tableComponent.AddRow(new Book(1, "book1", "lalala")); tableComponent.AddRow(new Book("gfgdf",1, "book1", "lalala"));
tableComponent.AddRow(new Book(1, "book2", "lalala2")); tableComponent.AddRow(new Book("Pushkin", 1, "book2", "lalala2"));
tableComponent.AddRow(new Book(1, "book3", "lalala")); tableComponent.AddRow(new Book("Pushkin", 1, "book3", "lalala"));
} }

View File

@ -25,62 +25,117 @@ namespace WinForm
private void buttonWordSave_Click(object sender, EventArgs e) private void buttonWordSave_Click(object sender, EventArgs e)
{ {
string filePath = "C:\\Users\\User\\Desktop\\универ\\3курс\\КОП\\Отчет.docx"; using var dialog = new SaveFileDialog
string title = "Заголовок"; {
string[,] row1 = { Filter = "docx|*.docx"
};
if (dialog.ShowDialog() == DialogResult.OK)
{
try
{
string title = "Заголовок";
string[,] row1 = {
{ "Стр1 Кол1", "Стр1 Кол2" } { "Стр1 Кол1", "Стр1 Кол2" }
}; };
string[,] row2 = { string[,] row2 = {
{ "Стр2 Кол1", "Стр2 Кол2" } { "Стр2 Кол1", "Стр2 Кол2" }
}; };
string[,] row3 = { string[,] row3 = {
{ "Стр3 Кол1", "Стр3 Кол3" } { "Стр3 Кол1", "Стр3 Кол3" }
}; };
MyTable table = new MyTable(filePath, title, new List<string[,]> { row1, row2, row3 }); MyTable table = new MyTable(dialog.FileName, title, new List<string[,]> { row1, row2, row3 });
wordTableComponent1.CreateDoc(table); wordTableComponent1.CreateDoc(table);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
} }
private void buttonSaveHist_Click(object sender, EventArgs e) private void buttonSaveHist_Click(object sender, EventArgs e)
{ {
histogram = new("C:\\Users\\User\\Desktop\\универ\\3курс\\КОП\\Report.docx", "Третье задание", "Гистограмма", EnumLegends.Right, new List<DataHistogramm> { using var dialog = new SaveFileDialog
new DataHistogramm("Доход", "Январь", 300), new DataHistogramm("Доход", "Апрель", 600), {
new DataHistogramm("Доход", "Июль", 400), new DataHistogramm("Доход", "Октябрь", 200) 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)
}); });
wordHistogramm1.CreateHistogramm(histogram); wordHistogramm1.CreateHistogramm(histogram);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
} }
List<Book> books; List<Book> books;
Book book1 = new Book(1, "fgdf", "fdsds"); Book book1 = new Book("Pushkin", 1, "fgsddsdf", "fdsds");
Book book2 = new Book(1, "aa", "fdads"); Book book2 = new Book("Pushkin", 2, "aa", "fdads");
Book book3 = new Book(1, "fgdf", "ffsds"); Book book3 = new Book("Pushkin", 3, "fgdf", "ffsds");
Book book4 = new Book(1, "ffdsff", "asds"); Book book4 = new Book("Lermontov", 4, "ffsssff", "asdss");
Book book5 = new Book(1, "ffdsff", "asds"); Book book5 = new Book("Lermontov", 5, "ffdsff", "asdsss");
Book book6 = new Book("Pushkin", 6, "fgdf", "ffsds");
Dictionary<int, ColumnParameters> colData; Dictionary<int, ColumnParameters> colData;
private void buttonHead_Click(object sender, EventArgs e) private void buttonHead_Click(object sender, EventArgs e)
{ {
books = new() books = new()
{ {
book1, book2, book3, book4, book5 book1, book2, book3, book4, book5, book6
}; };
colData = new Dictionary<int, ColumnParameters>() colData = new Dictionary<int, ColumnParameters>()
{ {
{ 0, new ColumnParameters("Марка автомобиля", "Id") }, { 0, new ColumnParameters("Автор", "Author") },
{ 1, new ColumnParameters("Модель", "Name") }, { 1, new ColumnParameters("Id книги", "Id") },
{ 2, new ColumnParameters("Год выпуска", "Annotation") } { 2, new ColumnParameters("Имя", "Name") },
{ 3, new ColumnParameters("Аннотация", "Annotation") }
}; };
MyTableWithHead<Book> myTable; using var dialog = new SaveFileDialog
//сгруппируй {
myTable = new("C:\\Users\\User\\Desktop\\универ\\3курс\\КОП\\Report2.docx", "Второе задание", new List<double> { 48, 24 }, Filter = "docx|*.docx"
new List<double> { 2000, 2000, 1500, 1500 }, books, colData); };
wordTableHeaderComponent1.CreateDoc(myTable);
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);
}
}
} }