From 3910b2022e4be4666fa4ac26301d659902d305f7 Mon Sep 17 00:00:00 2001 From: Yuee Shiness Date: Fri, 22 Sep 2023 01:36:57 +0400 Subject: [PATCH] dunno if it works or not, i hope so. --- CustomComponents/Classes/Account.cs | 26 ++++ .../CustomDataGridView.Designer.cs | 65 ++++++++++ CustomComponents/CustomDataGridView.cs | 94 ++++++++++++++ CustomComponents/CustomDataGridView.resx | 120 ++++++++++++++++++ ...opList.Designer.cs => ListBox.Designer.cs} | 0 CustomComponents/{DropList.cs => ListBox.cs} | 0 .../{DropList.resx => ListBox.resx} | 0 7 files changed, 305 insertions(+) create mode 100644 CustomComponents/Classes/Account.cs create mode 100644 CustomComponents/CustomDataGridView.Designer.cs create mode 100644 CustomComponents/CustomDataGridView.cs create mode 100644 CustomComponents/CustomDataGridView.resx rename CustomComponents/{DropList.Designer.cs => ListBox.Designer.cs} (100%) rename CustomComponents/{DropList.cs => ListBox.cs} (100%) rename CustomComponents/{DropList.resx => ListBox.resx} (100%) diff --git a/CustomComponents/Classes/Account.cs b/CustomComponents/Classes/Account.cs new file mode 100644 index 0000000..950c63e --- /dev/null +++ b/CustomComponents/Classes/Account.cs @@ -0,0 +1,26 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace CustomComponents.Classes +{ + public class Account + { + public int ID { get; private set; } + public string Login { get; private set; } = string.Empty; + public List LoginTimes { get; private set; } = new(); + public string Town { get; private set; } = string.Empty; + public DateTime CreationDate { get; private set; } = DateTime.Now; + + public Account(int id, string login, string town) + { + ID = id; + Login = login; + Town = town; + LoginTimes.Add(DateTime.Now); + } + + } +} diff --git a/CustomComponents/CustomDataGridView.Designer.cs b/CustomComponents/CustomDataGridView.Designer.cs new file mode 100644 index 0000000..e96b498 --- /dev/null +++ b/CustomComponents/CustomDataGridView.Designer.cs @@ -0,0 +1,65 @@ +namespace CustomComponents +{ + partial class frameCustomGridView + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Component Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + customGridView = new DataGridView(); + ((System.ComponentModel.ISupportInitialize)customGridView).BeginInit(); + SuspendLayout(); + // + // customGridView + // + customGridView.BackgroundColor = SystemColors.ButtonHighlight; + customGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; + customGridView.Location = new Point(5, 3); + customGridView.MultiSelect = false; + customGridView.Name = "customGridView"; + customGridView.RowHeadersVisible = false; + customGridView.RowHeadersWidth = 51; + customGridView.RowTemplate.Height = 29; + customGridView.SelectionMode = DataGridViewSelectionMode.FullRowSelect; + customGridView.Size = new Size(300, 188); + customGridView.TabIndex = 0; + customGridView.SelectionChanged += SelectionChanged; + // + // frameCustomGridView + // + AutoScaleDimensions = new SizeF(8F, 20F); + AutoScaleMode = AutoScaleMode.Font; + Controls.Add(customGridView); + Name = "frameCustomGridView"; + Size = new Size(308, 197); + ((System.ComponentModel.ISupportInitialize)customGridView).EndInit(); + ResumeLayout(false); + } + + #endregion + + private DataGridView customGridView; + } +} diff --git a/CustomComponents/CustomDataGridView.cs b/CustomComponents/CustomDataGridView.cs new file mode 100644 index 0000000..ee07e39 --- /dev/null +++ b/CustomComponents/CustomDataGridView.cs @@ -0,0 +1,94 @@ +using Accessibility; +using CustomComponents.Classes; +using System; +using System.CodeDom; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Dynamic; +using System.Linq; +using System.Reflection; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace CustomComponents +{ + public partial class frameCustomGridView : UserControl + { + public event EventHandler TaskHandler; + public int RowIndex; + public frameCustomGridView() + { + InitializeComponent(); + } + + public void ColumnConfiguration(int columnsQuantity, List headers, List columnWidth, List visibility, List columnName) + { + for(int i = 0; i < columnsQuantity; i++) + { + customGridView.Columns.Add(headers.ElementAt(i),columnName.ElementAt(i)); + customGridView.Columns[i].Width = columnWidth.ElementAt(i); + customGridView.Columns[i].Visible = visibility.ElementAt(i); + } + } + + public int IndexProperty + { + get + { + return RowIndex; + } + set + { + if (customGridView.SelectedRows.Count != 0) + { + RowIndex = value; + } + } + } + + public void ClearRows() + { + customGridView.Rows.Clear(); + } + + public void AddRow(List objects) + { + var type = objects.GetType(); + var fields = type.GetProperties(); + + foreach(var obj in objects) + { + List values = new(); + values.AddRange(obj.GetType().GetProperties().Select(prop => prop.GetValue(obj))); + customGridView.Rows.Add(values); + } + } + + public T GetAccount() where T : new() + { + T obj = new T(); + + var props = obj.GetType().GetProperties(); + + foreach(var prop in props) + { + if(customGridView.Columns.Contains(prop.Name)) + { + prop.SetValue(obj, customGridView.Rows[IndexProperty].Cells[prop.Name].Value); + } + } + + return obj; + } + + private void SelectionChanged(object sender, EventArgs e) + { + var element = sender as DataGridView; + IndexProperty = element.SelectedRows[0].Index; + TaskHandler?.Invoke(this, e); + } + } +} diff --git a/CustomComponents/CustomDataGridView.resx b/CustomComponents/CustomDataGridView.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/CustomComponents/CustomDataGridView.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/CustomComponents/DropList.Designer.cs b/CustomComponents/ListBox.Designer.cs similarity index 100% rename from CustomComponents/DropList.Designer.cs rename to CustomComponents/ListBox.Designer.cs diff --git a/CustomComponents/DropList.cs b/CustomComponents/ListBox.cs similarity index 100% rename from CustomComponents/DropList.cs rename to CustomComponents/ListBox.cs diff --git a/CustomComponents/DropList.resx b/CustomComponents/ListBox.resx similarity index 100% rename from CustomComponents/DropList.resx rename to CustomComponents/ListBox.resx