Переход на Dictionary.
This commit is contained in:
parent
a60f4cd6ce
commit
cfba8354fb
@ -43,6 +43,8 @@ namespace VisualComponentsForm
|
||||
Car fifthCar = new("Opel", "Astra", 2100000, 2018);
|
||||
Car sixthCar = new("Mercedes", "E-class", 3200500, 2019);
|
||||
|
||||
Dictionary<int, ColumnName> colData;
|
||||
|
||||
public FormWord()
|
||||
{
|
||||
InitializeComponent();
|
||||
@ -51,6 +53,14 @@ namespace VisualComponentsForm
|
||||
{
|
||||
seventhCar, firstCar, secondCar, thirdCar, fourthCar, fifthCar, sixthCar
|
||||
};
|
||||
|
||||
colData = new Dictionary<int, ColumnName>()
|
||||
{
|
||||
{ 0, new ColumnName("Марка автомобиля", "Brand") },
|
||||
{ 1, new ColumnName("Модель", "Model") },
|
||||
{ 2, new ColumnName("Год выпуска", "YearProduction") },
|
||||
{ 3, new ColumnName("Цена", "Price") },
|
||||
};
|
||||
}
|
||||
|
||||
private void ButtonFirstTask_Click(object sender, EventArgs e)
|
||||
@ -90,7 +100,8 @@ namespace VisualComponentsForm
|
||||
{
|
||||
try
|
||||
{
|
||||
setDataTable = new(dialog.FileName, "Второе задание", new List<double> { 48, 24 }, new List<double> { 2000, 2000, 1500, 1500 }, listCars);
|
||||
setDataTable = new(dialog.FileName, "Второе задание", new List<double> { 48, 24 },
|
||||
new List<double> { 2000, 2000, 1500, 1500 }, listCars, colData);
|
||||
|
||||
componentBigTable.CreateDoc(setDataTable);
|
||||
|
||||
|
@ -11,6 +11,7 @@ using System.Threading.Tasks;
|
||||
using VisualComponentsLib.Components.SupportClasses;
|
||||
using Spire.Doc.Formatting;
|
||||
using System.CodeDom;
|
||||
using DocumentFormat.OpenXml.Vml;
|
||||
|
||||
namespace VisualComponentsLib.Components
|
||||
{
|
||||
@ -142,7 +143,8 @@ namespace VisualComponentsLib.Components
|
||||
int indexHeaderHeigh = 0;
|
||||
int indexHeaderWidth = 0;
|
||||
|
||||
foreach (var val in setDataTable.DataList[0].GetType().GetProperties())
|
||||
//пробегаемся по словарю, чтобы сразу заполнять данные в нужной последовательности
|
||||
foreach (var item in setDataTable.ColumnsSettings)
|
||||
{
|
||||
_tr.Append(new TableRowProperties(new TableRowHeight
|
||||
{
|
||||
@ -158,9 +160,39 @@ namespace VisualComponentsLib.Components
|
||||
}
|
||||
));
|
||||
|
||||
if (string.IsNullOrEmpty(val.Name))
|
||||
if (string.IsNullOrEmpty(setDataTable.ColumnsSettings[indexHeaderWidth].NameField) ||
|
||||
string.IsNullOrEmpty(setDataTable.ColumnsSettings[indexHeaderWidth].NameColumn))
|
||||
{
|
||||
throw new Exception("Некорректное заполнение заголовка таблицы");
|
||||
throw new Exception("Некорректное заполнение информации для шапки таблицы");
|
||||
}
|
||||
|
||||
tc.Append(new Paragraph(new Run(new Text(item.Value.NameColumn))));
|
||||
|
||||
_tr.Append(tc);
|
||||
|
||||
indexHeaderWidth++;
|
||||
}
|
||||
|
||||
/*foreach (var val in setDataTable.DataList[0].GetType().GetProperties())
|
||||
{
|
||||
_tr.Append(new TableRowProperties(new TableRowHeight
|
||||
{
|
||||
Val = Convert.ToUInt32(setDataTable.HeightRow[indexHeaderHeigh])
|
||||
}));
|
||||
|
||||
var tc = new TableCell();
|
||||
|
||||
tc.Append(new TableCellProperties(new TableCellWidth
|
||||
{
|
||||
Type = TableWidthUnitValues.Dxa,
|
||||
Width = setDataTable.WidthCol[indexHeaderWidth].ToString(),
|
||||
}
|
||||
));
|
||||
|
||||
if (string.IsNullOrEmpty(setDataTable.ColumnsSettings[indexHeaderWidth].NameField) ||
|
||||
string.IsNullOrEmpty(setDataTable.ColumnsSettings[indexHeaderWidth].NameColumn))
|
||||
{
|
||||
throw new Exception("Некорректное заполнение информации для шапки таблицы");
|
||||
}
|
||||
|
||||
tc.Append(new Paragraph(new Run(new Text(val.Name))));
|
||||
@ -168,7 +200,7 @@ namespace VisualComponentsLib.Components
|
||||
_tr.Append(tc);
|
||||
|
||||
indexHeaderWidth++;
|
||||
}
|
||||
}*/
|
||||
|
||||
table.Append(_tr);
|
||||
|
||||
|
22
VisualComponentsLib/Components/SupportClasses/ColumnName.cs
Normal file
22
VisualComponentsLib/Components/SupportClasses/ColumnName.cs
Normal file
@ -0,0 +1,22 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace VisualComponentsLib.Components.SupportClasses
|
||||
{
|
||||
//для настройки соответствия столбцов полям
|
||||
public class ColumnName
|
||||
{
|
||||
public string NameColumn { get; set; } = string.Empty;
|
||||
|
||||
public string NameField { get; set; } = string.Empty;
|
||||
|
||||
public ColumnName(string nameColumn, string nameField)
|
||||
{
|
||||
NameColumn = nameColumn;
|
||||
NameField = nameField;
|
||||
}
|
||||
}
|
||||
}
|
@ -22,16 +22,18 @@ namespace VisualComponentsLib.Components.SupportClasses
|
||||
|
||||
public List<T> DataList;
|
||||
|
||||
//настройки соответствия столбец-поле
|
||||
public Dictionary<int, ColumnName> ColumnsSettings;
|
||||
|
||||
public SetDataTable(string filePath, string fileHeader, List<double> heightRow,
|
||||
List<double> widthCol, List<T> dataList)
|
||||
List<double> widthCol, List<T> dataList, Dictionary<int, ColumnName> columnsSettings)
|
||||
{
|
||||
FilePath = filePath;
|
||||
FileHeader = fileHeader;
|
||||
FileHeader = fileHeader;
|
||||
HeightRow = heightRow;
|
||||
WidthCol = widthCol;
|
||||
DataList = dataList;
|
||||
|
||||
DataList.GroupBy(field => DataList[0]);
|
||||
ColumnsSettings = columnsSettings;
|
||||
}
|
||||
|
||||
////группировка элементов списка по первому полю
|
||||
|
Loading…
Reference in New Issue
Block a user