Таблица генерится.
This commit is contained in:
parent
056880251c
commit
e79648acd7
@ -35,8 +35,12 @@
|
||||
groupBox2 = new GroupBox();
|
||||
buttonThirdTask = new Button();
|
||||
componentWordHistogram = new VisualComponentsLib.Components.ComponentWordHistogram(components);
|
||||
componentBigTable = new VisualComponentsLib.Components.ComponentBigTable(components);
|
||||
groupBox3 = new GroupBox();
|
||||
buttonStartSecond = new Button();
|
||||
groupBox1.SuspendLayout();
|
||||
groupBox2.SuspendLayout();
|
||||
groupBox3.SuspendLayout();
|
||||
SuspendLayout();
|
||||
//
|
||||
// buttonFirstTask
|
||||
@ -62,7 +66,7 @@
|
||||
// groupBox2
|
||||
//
|
||||
groupBox2.Controls.Add(buttonThirdTask);
|
||||
groupBox2.Location = new Point(154, 12);
|
||||
groupBox2.Location = new Point(270, 12);
|
||||
groupBox2.Name = "groupBox2";
|
||||
groupBox2.Size = new Size(129, 79);
|
||||
groupBox2.TabIndex = 2;
|
||||
@ -79,17 +83,39 @@
|
||||
buttonThirdTask.UseVisualStyleBackColor = true;
|
||||
buttonThirdTask.Click += ButtonThirdTask_Click;
|
||||
//
|
||||
// groupBox3
|
||||
//
|
||||
groupBox3.Controls.Add(buttonStartSecond);
|
||||
groupBox3.Location = new Point(138, 12);
|
||||
groupBox3.Name = "groupBox3";
|
||||
groupBox3.Size = new Size(126, 79);
|
||||
groupBox3.TabIndex = 3;
|
||||
groupBox3.TabStop = false;
|
||||
groupBox3.Text = "Второе задание";
|
||||
//
|
||||
// buttonStartSecond
|
||||
//
|
||||
buttonStartSecond.Location = new Point(24, 32);
|
||||
buttonStartSecond.Name = "buttonStartSecond";
|
||||
buttonStartSecond.Size = new Size(75, 23);
|
||||
buttonStartSecond.TabIndex = 0;
|
||||
buttonStartSecond.Text = "Создать";
|
||||
buttonStartSecond.UseVisualStyleBackColor = true;
|
||||
buttonStartSecond.Click += ButtonStartSecond_Click;
|
||||
//
|
||||
// FormWord
|
||||
//
|
||||
AutoScaleDimensions = new SizeF(7F, 15F);
|
||||
AutoScaleMode = AutoScaleMode.Font;
|
||||
ClientSize = new Size(295, 103);
|
||||
ClientSize = new Size(411, 103);
|
||||
Controls.Add(groupBox3);
|
||||
Controls.Add(groupBox2);
|
||||
Controls.Add(groupBox1);
|
||||
Name = "FormWord";
|
||||
Text = "Невизуальные компоненты";
|
||||
groupBox1.ResumeLayout(false);
|
||||
groupBox2.ResumeLayout(false);
|
||||
groupBox3.ResumeLayout(false);
|
||||
ResumeLayout(false);
|
||||
}
|
||||
|
||||
@ -101,5 +127,8 @@
|
||||
private GroupBox groupBox2;
|
||||
private Button buttonThirdTask;
|
||||
private VisualComponentsLib.Components.ComponentWordHistogram componentWordHistogram;
|
||||
private VisualComponentsLib.Components.ComponentBigTable componentBigTable;
|
||||
private GroupBox groupBox3;
|
||||
private Button buttonStartSecond;
|
||||
}
|
||||
}
|
@ -17,6 +17,10 @@ namespace VisualComponentsForm
|
||||
{
|
||||
SimpleTable table;
|
||||
|
||||
SimpleHistogram histogram;
|
||||
|
||||
SetDataTable<Car> setDataTable;
|
||||
|
||||
string[,] first = {
|
||||
{ "Первый", "Второй" }
|
||||
};
|
||||
@ -29,11 +33,24 @@ namespace VisualComponentsForm
|
||||
{ "Пятый", "Шестой" }
|
||||
};
|
||||
|
||||
SimpleHistogram histogram;
|
||||
List<Car> listCars;
|
||||
|
||||
Car seventhCar = new("Audi", "TT", 3500000, 2005);
|
||||
Car firstCar = new ("Lada", "XRay", 1566000, 2016);
|
||||
Car secondCar = new("Opel", "Astra", 1320000, 2017);
|
||||
Car thirdCar = new("Lada", "Granta", 430000, 2009);
|
||||
Car fourthCar = new("Lada", "Vesta", 1220000, 2022);
|
||||
Car fifthCar = new("Opel", "Astra", 2100000, 2018);
|
||||
Car sixthCar = new("Mercedes", "E-class", 3200500, 2019);
|
||||
|
||||
public FormWord()
|
||||
{
|
||||
InitializeComponent();
|
||||
|
||||
listCars = new()
|
||||
{
|
||||
seventhCar, firstCar, secondCar, thirdCar, fourthCar, fifthCar, sixthCar
|
||||
};
|
||||
}
|
||||
|
||||
private void ButtonFirstTask_Click(object sender, EventArgs e)
|
||||
@ -61,6 +78,31 @@ namespace VisualComponentsForm
|
||||
}
|
||||
}
|
||||
|
||||
private void ButtonStartSecond_Click(object sender, EventArgs e)
|
||||
{
|
||||
//фильтрация файлов для диалогового окна
|
||||
using var dialog = new SaveFileDialog
|
||||
{
|
||||
Filter = "docx|*.docx"
|
||||
};
|
||||
|
||||
if (dialog.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
try
|
||||
{
|
||||
setDataTable = new(dialog.FileName, "Второе задание", new List<double> { 48, 24 }, new List<double> { 2000, 2000, 1500, 1500 }, listCars);
|
||||
|
||||
componentBigTable.CreateDoc(setDataTable);
|
||||
|
||||
MessageBox.Show("Выполнено", "Успех", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void ButtonThirdTask_Click(object sender, EventArgs e)
|
||||
{
|
||||
//фильтрация файлов для диалогового окна
|
||||
@ -73,8 +115,8 @@ namespace VisualComponentsForm
|
||||
{
|
||||
try
|
||||
{
|
||||
histogram = new(dialog.FileName, "Третье задание", "Гистограмма", EnumAreaLegend.Right, new List<DataHistogram> {
|
||||
new DataHistogram("Доход", "Январь", "300"), new DataHistogram("Доход", "Апрель", "600"),
|
||||
histogram = new(dialog.FileName, "Третье задание", "Гистограмма", EnumAreaLegend.Right, new List<DataHistogram> {
|
||||
new DataHistogram("Доход", "Январь", "300"), new DataHistogram("Доход", "Апрель", "600"),
|
||||
new DataHistogram("Доход", "Июль", "400"), new DataHistogram("Доход", "Октябрь", "200")
|
||||
});
|
||||
|
||||
|
@ -123,4 +123,7 @@
|
||||
<metadata name="componentWordHistogram.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
|
||||
<value>162, 17</value>
|
||||
</metadata>
|
||||
<metadata name="componentBigTable.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
|
||||
<value>363, 17</value>
|
||||
</metadata>
|
||||
</root>
|
@ -9,6 +9,7 @@ using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using VisualComponentsLib.Components.SupportClasses;
|
||||
using Spire.Doc.Formatting;
|
||||
|
||||
namespace VisualComponentsLib.Components
|
||||
{
|
||||
@ -51,10 +52,10 @@ namespace VisualComponentsLib.Components
|
||||
//создание таблицы
|
||||
private void AddTable<T> (SetDataTable<T> setDataTable)
|
||||
{
|
||||
if (!CheckData(setDataTable.DataList))
|
||||
/*if (!CheckData(setDataTable.DataList))
|
||||
{
|
||||
throw new Exception("Не все ячейки заполнены");
|
||||
}
|
||||
}*/
|
||||
|
||||
using (var document = WordprocessingDocument.Open(setDataTable.FilePath, true))
|
||||
{
|
||||
@ -160,20 +161,22 @@ namespace VisualComponentsLib.Components
|
||||
|
||||
_tr.Append(tc);
|
||||
|
||||
table.Append(_tr);
|
||||
|
||||
indexHeaderWidth++;
|
||||
}
|
||||
|
||||
table.Append(_tr);
|
||||
|
||||
|
||||
//увеличиваем счётчик на 1, т. к. в списке только два значения
|
||||
indexHeaderHeigh++;
|
||||
indexHeaderWidth = 0;
|
||||
|
||||
//генерация тела таблицы
|
||||
for (var i = 1; i < setDataTable.DataList.Count; i++)
|
||||
{
|
||||
var tr = new TableRow();
|
||||
|
||||
foreach (var val in setDataTable.DataList[i].GetType().GetFields())
|
||||
foreach (var val in setDataTable.DataList[i].GetType().GetProperties())
|
||||
{
|
||||
tr.Append(new TableRowProperties(new TableRowHeight
|
||||
{
|
||||
@ -189,12 +192,10 @@ namespace VisualComponentsLib.Components
|
||||
}
|
||||
));
|
||||
|
||||
tc.Append(new Paragraph(new Run(new Text(val.GetValue(setDataTable.DataList[i].GetType()).ToString()))));
|
||||
tc.Append(new Paragraph(new Run(new Text(val.GetValue(setDataTable.DataList[i]).ToString()))));
|
||||
|
||||
tr.Append(tc);
|
||||
|
||||
table.Append(tr);
|
||||
|
||||
indexHeaderWidth++;
|
||||
}
|
||||
|
||||
@ -205,6 +206,8 @@ namespace VisualComponentsLib.Components
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
|
||||
doc.Body.Append(header);
|
||||
|
||||
doc.Body.Append(table);
|
||||
@ -218,7 +221,7 @@ namespace VisualComponentsLib.Components
|
||||
{
|
||||
foreach(var data in dataList)
|
||||
{
|
||||
foreach (var value in data.GetType().GetFields())
|
||||
foreach (var value in data.GetType().GetProperties())
|
||||
{
|
||||
//для простоты проверки приводим значение каждого поля к типу string
|
||||
if(string.IsNullOrEmpty(dataList.GetType().GetField(value.Name).GetValue(data).ToString()))
|
||||
|
28
VisualComponentsLib/Components/SupportClasses/Car.cs
Normal file
28
VisualComponentsLib/Components/SupportClasses/Car.cs
Normal file
@ -0,0 +1,28 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.Contracts;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace VisualComponentsLib.Components.SupportClasses
|
||||
{
|
||||
public class Car
|
||||
{
|
||||
public string Brand { get; set; } = string.Empty;
|
||||
|
||||
public string Model { get; set; } = string.Empty;
|
||||
|
||||
public int Price { get; set; }
|
||||
|
||||
public int YearProduction { get; set; }
|
||||
|
||||
public Car(string brand, string model, int price, int yearProduction)
|
||||
{
|
||||
Brand = brand;
|
||||
Model = model;
|
||||
Price = price;
|
||||
YearProduction = yearProduction;
|
||||
}
|
||||
}
|
||||
}
|
@ -31,15 +31,15 @@ namespace VisualComponentsLib.Components.SupportClasses
|
||||
WidthCol = widthCol;
|
||||
DataList = dataList;
|
||||
|
||||
DataList = GroupValue(DataList);
|
||||
//DataList = DataList.GroupBy(field => field.GetType().GetProperties().First().Name).Select(field => field.ToList());
|
||||
}
|
||||
|
||||
//группировка элементов списка по первому полю
|
||||
private static List<T> GroupValue<T>(List<T> data)
|
||||
{
|
||||
var mainField = data[0].GetType().GetProperties().First().Name;
|
||||
////группировка элементов списка по первому полю
|
||||
//private static List<T> GroupValue<T>(List<T> data)
|
||||
//{
|
||||
// var mainField = data[0].GetType().GetProperties().First().Name;
|
||||
|
||||
return (List<T>)data.GroupBy(field => field.GetType().GetProperties().First().Name).Select(field => field.ToList());
|
||||
}
|
||||
// return data.GroupBy(field => field.GetType().GetProperties().First().Name).Select(field => field.ToList());
|
||||
//}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user