Compare commits

...

3 Commits

Author SHA1 Message Date
a503ccac17 fix AddList 2024-10-04 11:08:12 +04:00
8db45c48bf AddList fix 2024-10-04 06:48:52 +04:00
9863bdba24 update dirs 2024-10-04 06:47:49 +04:00
13 changed files with 22 additions and 48 deletions

View File

@ -4,7 +4,7 @@ using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace WinFormsLibrary1 namespace Components.Exceptions
{ {
public class UncheckedNullException : Exception public class UncheckedNullException : Exception
{ {

View File

@ -4,7 +4,7 @@ using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace WinFormsLibrary1 namespace Components.Exceptions
{ {
public class UnexpectedTypeException : Exception public class UnexpectedTypeException : Exception
{ {

View File

@ -1,23 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace WinFormsLibrary1
{
public class User
{
public string username { get; private set; }
public string email { get; private set; }
public DateTime birthday { get; private set; }
public User(string username, string email, DateTime birthday)
{
this.username = username;
this.email = email;
this.birthday = birthday;
}
}
}

View File

@ -4,7 +4,7 @@ using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace WinFormsLibrary1 namespace Components.Visual
{ {
public class ColumnInfo public class ColumnInfo
{ {

View File

@ -1,4 +1,5 @@
using System; using Components.Exceptions;
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.ComponentModel; using System.ComponentModel;
using System.Data; using System.Data;

View File

@ -8,6 +8,7 @@ using System.Reflection;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using System.Windows.Forms; using System.Windows.Forms;
using Components.Visual;
namespace WinFormsLibrary1 namespace WinFormsLibrary1
{ {
@ -51,9 +52,22 @@ namespace WinFormsLibrary1
dataGridViewTable.Rows.Clear(); dataGridViewTable.Rows.Clear();
} }
public void AddObjectList(List<object> os) public void AddList<T>(List<T> values)
{ {
dataGridViewTable.DataSource = os ?? throw new ArgumentNullException(); ClearRows();
var props = typeof(T).GetProperties();
foreach (T value in values)
{
int newRowInd = dataGridViewTable.Rows.Add();
foreach (DataGridViewColumn col in dataGridViewTable.Columns)
{
var prop = props.FirstOrDefault(x => x.Name == col.Name)
?? throw new InvalidOperationException($"No property {col.Name} found in type {typeof(T).Name}");
var val = prop.GetValue(value);
dataGridViewTable.Rows[newRowInd].Cells[col.Index].Value = val;
}
}
} }
public T GetObjectFromRow<T>() public T GetObjectFromRow<T>()
@ -78,23 +92,5 @@ namespace WinFormsLibrary1
} }
return returnObject; return returnObject;
} }
public void AddList<T> (List<T> values)
{
ClearRows();
var props = typeof(T).GetProperties();
foreach (T value in values)
{
int newRowInd = dataGridViewTable.Rows.Add(value);
foreach (DataGridViewColumn col in dataGridViewTable.Columns)
{
var prop = props.FirstOrDefault(x => x.Name == col.Name)
?? throw new InvalidOperationException($"No property {col.Name} found in type {typeof(T).Name}");
var val = prop.GetValue(value);
dataGridViewTable.Rows[newRowInd].Cells[col.Index].Value = val;
}
}
}
} }
} }