LabWork01 is done.

This commit is contained in:
Yuee Shiness 2023-09-22 22:04:15 +04:00
parent 178a5c90ab
commit d1b89209ef
5 changed files with 82 additions and 21 deletions

View File

@ -24,6 +24,7 @@ namespace CustomComponents.Classes
Login = login;
Town = town;
LoginTimes.Add(DateTime.Now);
LoginTimes.Add(DateTime.Today);
}
}

View File

@ -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);

View File

@ -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;
@ -42,10 +43,9 @@ namespace CustomComponents
}
set
{
if (customGridView.SelectedRows.Count != 0)
{
RowIndex = value;
}
}
}
@ -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);
}
@ -86,16 +95,42 @@ namespace CustomComponents
{
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);
}

View File

@ -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;
}
}

View File

@ -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)
@ -53,9 +54,19 @@ namespace TestForms
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());
}
private void buttonClear_Click(object sender, EventArgs e)
{
frameCustomGridView1.ClearRows();
}
}
}