LabWork01 is done.
This commit is contained in:
parent
178a5c90ab
commit
d1b89209ef
@ -24,6 +24,7 @@ namespace CustomComponents.Classes
|
||||
Login = login;
|
||||
Town = town;
|
||||
LoginTimes.Add(DateTime.Now);
|
||||
LoginTimes.Add(DateTime.Today);
|
||||
}
|
||||
|
||||
}
|
||||
|
1
CustomComponents/CustomDataGridView.Designer.cs
generated
1
CustomComponents/CustomDataGridView.Designer.cs
generated
@ -34,6 +34,7 @@
|
||||
//
|
||||
// customGridView
|
||||
//
|
||||
customGridView.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right;
|
||||
customGridView.BackgroundColor = SystemColors.ButtonHighlight;
|
||||
customGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize;
|
||||
customGridView.Location = new Point(5, 3);
|
||||
|
@ -2,6 +2,7 @@
|
||||
using CustomComponents.Classes;
|
||||
using System;
|
||||
using System.CodeDom;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Data;
|
||||
@ -26,9 +27,9 @@ namespace CustomComponents
|
||||
|
||||
public void ColumnConfiguration(int columnsQuantity, List<string> headers, List<int> columnWidth, List<bool> visibility, List<string> columnName)
|
||||
{
|
||||
for(int i = 0; i < columnsQuantity; i++)
|
||||
for (int i = 0; i < columnsQuantity; i++)
|
||||
{
|
||||
customGridView.Columns.Add(headers.ElementAt(i),columnName.ElementAt(i));
|
||||
customGridView.Columns.Add(headers.ElementAt(i), columnName.ElementAt(i));
|
||||
customGridView.Columns[i].Width = columnWidth.ElementAt(i);
|
||||
customGridView.Columns[i].Visible = visibility.ElementAt(i);
|
||||
}
|
||||
@ -42,10 +43,9 @@ namespace CustomComponents
|
||||
}
|
||||
set
|
||||
{
|
||||
if (customGridView.SelectedRows.Count != 0)
|
||||
{
|
||||
RowIndex = value;
|
||||
}
|
||||
|
||||
RowIndex = value;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@ -59,7 +59,7 @@ namespace CustomComponents
|
||||
var type = objects.GetType();
|
||||
var fields = type.GetProperties();
|
||||
|
||||
foreach(var obj in objects)
|
||||
foreach (var obj in objects)
|
||||
{
|
||||
List<object> values = new();
|
||||
values.AddRange(obj.GetType().GetProperties().Select(prop => prop.GetValue(obj)));
|
||||
@ -67,10 +67,19 @@ namespace CustomComponents
|
||||
DataGridViewRow row = new DataGridViewRow();
|
||||
row.CreateCells(customGridView);
|
||||
|
||||
foreach(DataGridViewColumn column in customGridView.Columns )
|
||||
|
||||
int columnIndex = 0;
|
||||
foreach(var value in values)
|
||||
{
|
||||
row.Cells[column.Index].Value = values.First();
|
||||
values.RemoveAt(0);
|
||||
if (!(value is string) && typeof(IEnumerable).IsAssignableFrom(value.GetType()))
|
||||
{
|
||||
row.Cells[columnIndex].Value = EnumerableConverter(value);
|
||||
}
|
||||
else
|
||||
{
|
||||
row.Cells[columnIndex].Value = value;
|
||||
}
|
||||
columnIndex++;
|
||||
}
|
||||
customGridView.Rows.Add(row);
|
||||
}
|
||||
@ -79,23 +88,49 @@ namespace CustomComponents
|
||||
public T GetAccount<T>() where T : new()
|
||||
{
|
||||
T obj = new T();
|
||||
|
||||
|
||||
var props = obj.GetType().GetProperties();
|
||||
|
||||
foreach(var prop in props)
|
||||
foreach (var prop in props)
|
||||
{
|
||||
if(customGridView.Columns.Contains(prop.Name))
|
||||
if (customGridView.Columns.Contains(prop.Name))
|
||||
{
|
||||
prop.SetValue(obj, customGridView.Rows[IndexProperty].Cells[prop.Name].Value);
|
||||
var elem = customGridView.Rows[IndexProperty].Cells[prop.Name].Value;
|
||||
if(prop.PropertyType.IsGenericType)
|
||||
{
|
||||
prop.SetValue(obj, elem.ToString().Split(";").Select(item => Convert.ToDateTime(item)).ToList());
|
||||
continue;
|
||||
}
|
||||
prop.SetValue(obj, elem);
|
||||
}
|
||||
}
|
||||
|
||||
return obj;
|
||||
}
|
||||
|
||||
public string EnumerableConverter(object value)
|
||||
{
|
||||
|
||||
IEnumerable? elements = value as IEnumerable;
|
||||
|
||||
List<string> list = new List<string>();
|
||||
foreach (var elem in elements)
|
||||
{
|
||||
list.Add(elem.ToString());
|
||||
}
|
||||
|
||||
string listAsString = String.Join(";", list);
|
||||
|
||||
return listAsString;
|
||||
}
|
||||
|
||||
private void SelectionChanged(object sender, EventArgs e)
|
||||
{
|
||||
var element = sender as DataGridView;
|
||||
if (customGridView.SelectedRows.Count == 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
IndexProperty = element.SelectedRows[0].Index;
|
||||
TaskHandler?.Invoke(this, e);
|
||||
}
|
||||
|
21
TestForms/Form1.Designer.cs
generated
21
TestForms/Form1.Designer.cs
generated
@ -36,6 +36,7 @@
|
||||
buttonConfigureGridView = new Button();
|
||||
fillGridViewButton = new Button();
|
||||
getSelectedRowButton = new Button();
|
||||
buttonClear = new Button();
|
||||
SuspendLayout();
|
||||
//
|
||||
// fillButton
|
||||
@ -79,12 +80,12 @@
|
||||
frameCustomGridView1.IndexProperty = 0;
|
||||
frameCustomGridView1.Location = new Point(12, 166);
|
||||
frameCustomGridView1.Name = "frameCustomGridView1";
|
||||
frameCustomGridView1.Size = new Size(309, 194);
|
||||
frameCustomGridView1.Size = new Size(393, 189);
|
||||
frameCustomGridView1.TabIndex = 5;
|
||||
//
|
||||
// buttonConfigureGridView
|
||||
//
|
||||
buttonConfigureGridView.Location = new Point(327, 182);
|
||||
buttonConfigureGridView.Location = new Point(411, 180);
|
||||
buttonConfigureGridView.Name = "buttonConfigureGridView";
|
||||
buttonConfigureGridView.Size = new Size(111, 29);
|
||||
buttonConfigureGridView.TabIndex = 6;
|
||||
@ -94,7 +95,7 @@
|
||||
//
|
||||
// fillGridViewButton
|
||||
//
|
||||
fillGridViewButton.Location = new Point(327, 250);
|
||||
fillGridViewButton.Location = new Point(411, 248);
|
||||
fillGridViewButton.Name = "fillGridViewButton";
|
||||
fillGridViewButton.Size = new Size(111, 29);
|
||||
fillGridViewButton.TabIndex = 7;
|
||||
@ -105,7 +106,7 @@
|
||||
//
|
||||
// getSelectedRowButton
|
||||
//
|
||||
getSelectedRowButton.Location = new Point(327, 285);
|
||||
getSelectedRowButton.Location = new Point(411, 283);
|
||||
getSelectedRowButton.Name = "getSelectedRowButton";
|
||||
getSelectedRowButton.Size = new Size(111, 29);
|
||||
getSelectedRowButton.TabIndex = 8;
|
||||
@ -114,11 +115,22 @@
|
||||
getSelectedRowButton.Visible = false;
|
||||
getSelectedRowButton.Click += getSelectedRowButton_Click;
|
||||
//
|
||||
// buttonClear
|
||||
//
|
||||
buttonClear.Location = new Point(411, 318);
|
||||
buttonClear.Name = "buttonClear";
|
||||
buttonClear.Size = new Size(111, 29);
|
||||
buttonClear.TabIndex = 9;
|
||||
buttonClear.Text = "CLEAR";
|
||||
buttonClear.UseVisualStyleBackColor = true;
|
||||
buttonClear.Click += buttonClear_Click;
|
||||
//
|
||||
// TestFrame
|
||||
//
|
||||
AutoScaleDimensions = new SizeF(8F, 20F);
|
||||
AutoScaleMode = AutoScaleMode.Font;
|
||||
ClientSize = new Size(800, 451);
|
||||
Controls.Add(buttonClear);
|
||||
Controls.Add(getSelectedRowButton);
|
||||
Controls.Add(fillGridViewButton);
|
||||
Controls.Add(buttonConfigureGridView);
|
||||
@ -141,5 +153,6 @@
|
||||
private Button buttonConfigureGridView;
|
||||
private Button fillGridViewButton;
|
||||
private Button getSelectedRowButton;
|
||||
private Button buttonClear;
|
||||
}
|
||||
}
|
@ -25,12 +25,13 @@ namespace TestForms
|
||||
{
|
||||
frameCustomGridView1.ColumnConfiguration(5,
|
||||
new List<string>() { "ID", "Login", "LoginTimes", "Town", "Creation" },
|
||||
new List<int>() { 50, 50, 50, 50, 50 },
|
||||
new List<int>() { 80, 80, 80, 80, 80 },
|
||||
new List<bool> { true, true, true, true, true },
|
||||
new List<string> { "ID", "Login", "LoginTimes", "Town", "Creation" });
|
||||
buttonConfigureGridView.Visible = false;
|
||||
fillGridViewButton.Visible = true;
|
||||
getSelectedRowButton.Visible = true;
|
||||
clearButton.Visible = true;
|
||||
}
|
||||
|
||||
private void fillGridViewButton_Click(object sender, EventArgs e)
|
||||
@ -51,11 +52,21 @@ namespace TestForms
|
||||
|
||||
StringBuilder sb = new StringBuilder();
|
||||
|
||||
foreach(var prop in properties)
|
||||
foreach (var prop in properties)
|
||||
{
|
||||
if(prop.PropertyType.IsGenericType)
|
||||
{
|
||||
sb.Append(($"{prop.Name}: {frameCustomGridView1.EnumerableConverter(prop.GetValue(obj))}\n"));
|
||||
continue;
|
||||
}
|
||||
sb.Append($"{prop.Name}: {prop.GetValue(obj)}\n");
|
||||
}
|
||||
MessageBox.Show( sb.ToString() );
|
||||
MessageBox.Show(sb.ToString());
|
||||
}
|
||||
|
||||
private void buttonClear_Click(object sender, EventArgs e)
|
||||
{
|
||||
frameCustomGridView1.ClearRows();
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user