доделал компонент, чтобы работало без ошибок и по тз

This commit is contained in:
Алексей Крюков 2024-10-22 21:30:06 +04:00
parent 3c1b43cb30
commit 7f404cadd4
3 changed files with 22 additions and 5 deletions

View File

@ -41,6 +41,7 @@
dataGridViewItems.Name = "dataGridViewItems";
dataGridViewItems.RowHeadersWidth = 51;
dataGridViewItems.RowTemplate.Height = 29;
dataGridViewItems.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
dataGridViewItems.Size = new Size(583, 353);
dataGridViewItems.TabIndex = 0;
//

View File

@ -57,28 +57,43 @@ namespace KryukovLib
T val = new();
var propertiesObj = typeof(T).GetProperties();
foreach (var properties in propertiesObj)
foreach (var property in propertiesObj)
{
bool propIsExist = false;
int columnIndex = 0;
for (; columnIndex < dataGridViewItems.Columns.Count; columnIndex++)
{
if (dataGridViewItems.Columns[columnIndex].DataPropertyName.ToString() == properties.Name)
if (dataGridViewItems.Columns[columnIndex].DataPropertyName.ToString() == property.Name)
{
propIsExist = true;
break;
}
}
if (propIsExist)
{
object value = dataGridViewItems.SelectedRows[0].Cells[columnIndex].Value;
properties.SetValue(val, Convert.ChangeType(value, properties?.PropertyType));
};
Type propertyType = Nullable.GetUnderlyingType(property.PropertyType) ?? property.PropertyType;
if (value == null || value == DBNull.Value)
{
if (property.PropertyType.IsGenericType && property.PropertyType.GetGenericTypeDefinition() == typeof(Nullable<>))
{
property.SetValue(val, null);
}
}
else
{
property.SetValue(val, Convert.ChangeType(value, propertyType));
}
}
}
return val;
}
public void AddItem<T>(T item, int RowIndex) where T : class
{
if (item == null)

View File

@ -153,6 +153,7 @@ namespace Test
{
(sender as Control).BackColor = Color.White;
var rnd = new Random();
var list2d = new List<(string Name, double value)>() { ("Series 2", rnd.Next()), ("Series 3", rnd.Next()), ("Series 52", rnd.Next()) };
excelGistogram1.CreateDoc(new ChartConfig
{
FilePath = "bar.xlsx",
@ -161,7 +162,7 @@ namespace Test
LegendLocation = KryukovLib.Models.Location.Top,
Data = new Dictionary<string, List<(string Name, double Value)>>
{
{ "Series 1", new() { ("Series 2", rnd.Next()), ("Series 3", rnd.Next()), ("Series 52", rnd.Next()) } }
{ "Series 1", list2d }
}
});
(sender as Control).BackColor = Color.Green;