From 1cd0c609736a78a95c2af29fb889ee7470cccabf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9F=D0=BE=D0=BB=D0=B8=D0=BD=D0=B0=20=D0=A7=D1=83=D0=B1?= =?UTF-8?q?=D1=8B=D0=BA=D0=B8=D0=BD=D0=B0?= Date: Mon, 16 Sep 2024 14:43:21 +0400 Subject: [PATCH] =?UTF-8?q?=D0=BA=D0=BE=D0=BC=D0=BF=D0=BE=D0=BD=D0=B5?= =?UTF-8?q?=D0=BD=D1=82=D1=8B=20=D1=81=D0=B4=D0=B5=D0=BB=D0=B0=D0=BB=D0=B0?= =?UTF-8?q?=20=D0=B2=D1=80=D0=BE=D0=B4=D0=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- COP/Components/Class1.cs | 6 - .../Components/UserCheckedListBox.Designer.cs | 58 +++++++++ .../Components/UserCheckedListBox.cs | 52 ++++++++ .../Components/UserCheckedListBox.resx | 60 +++++++++ .../Components/UserDatePicker.Designer.cs | 56 ++++++++ COP/Components/Components/UserDatePicker.cs | 74 +++++++++++ COP/Components/Components/UserDatePicker.resx | 120 ++++++++++++++++++ .../Components/UserTreeView.Designer.cs | 55 ++++++++ COP/Components/Components/UserTreeView.cs | 90 +++++++++++++ COP/Components/Components/UserTreeView.resx | 120 ++++++++++++++++++ .../Exceptions/DateBoundsNotSetException.cs | 18 +++ .../Exceptions/DateOutOfBoundsException.cs | 17 +++ 12 files changed, 720 insertions(+), 6 deletions(-) delete mode 100644 COP/Components/Class1.cs create mode 100644 COP/Components/Components/UserCheckedListBox.Designer.cs create mode 100644 COP/Components/Components/UserCheckedListBox.cs create mode 100644 COP/Components/Components/UserCheckedListBox.resx create mode 100644 COP/Components/Components/UserDatePicker.Designer.cs create mode 100644 COP/Components/Components/UserDatePicker.cs create mode 100644 COP/Components/Components/UserDatePicker.resx create mode 100644 COP/Components/Components/UserTreeView.Designer.cs create mode 100644 COP/Components/Components/UserTreeView.cs create mode 100644 COP/Components/Components/UserTreeView.resx create mode 100644 COP/Components/Exceptions/DateBoundsNotSetException.cs create mode 100644 COP/Components/Exceptions/DateOutOfBoundsException.cs diff --git a/COP/Components/Class1.cs b/COP/Components/Class1.cs deleted file mode 100644 index 777a957..0000000 --- a/COP/Components/Class1.cs +++ /dev/null @@ -1,6 +0,0 @@ -namespace Components -{ - public class Class1 - { - } -} \ No newline at end of file diff --git a/COP/Components/Components/UserCheckedListBox.Designer.cs b/COP/Components/Components/UserCheckedListBox.Designer.cs new file mode 100644 index 0000000..4ba7be0 --- /dev/null +++ b/COP/Components/Components/UserCheckedListBox.Designer.cs @@ -0,0 +1,58 @@ +namespace Components.Components +{ + partial class UserCheckedListBox + { + /// + /// Обязательная переменная конструктора. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Освободить все используемые ресурсы. + /// + /// истинно, если управляемый ресурс должен быть удален; иначе ложно. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Код, автоматически созданный конструктором компонентов + + /// + /// Требуемый метод для поддержки конструктора — не изменяйте + /// содержимое этого метода с помощью редактора кода. + /// + private void InitializeComponent() + { + this.checkedListBox = new System.Windows.Forms.CheckedListBox(); + this.SuspendLayout(); + // + // checkedListBox + // + this.checkedListBox.FormattingEnabled = true; + this.checkedListBox.Location = new System.Drawing.Point(0, 0); + this.checkedListBox.Name = "checkedListBox"; + this.checkedListBox.Size = new System.Drawing.Size(150, 114); + this.checkedListBox.TabIndex = 0; + this.checkedListBox.SelectedIndexChanged += new System.EventHandler(this.checkedListBox_SelectedIndexChanged); + // + // UserCheckedListBox + // + this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.Controls.Add(this.checkedListBox); + this.Name = "UserCheckedListBox"; + this.Size = new System.Drawing.Size(150, 115); + this.ResumeLayout(false); + + } + + #endregion + + private CheckedListBox checkedListBox; + } +} diff --git a/COP/Components/Components/UserCheckedListBox.cs b/COP/Components/Components/UserCheckedListBox.cs new file mode 100644 index 0000000..c76c023 --- /dev/null +++ b/COP/Components/Components/UserCheckedListBox.cs @@ -0,0 +1,52 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace Components.Components +{ + public partial class UserCheckedListBox : UserControl + { + public UserCheckedListBox() + { + InitializeComponent(); + } + + public string? selectedItem + { + get + { + return checkedListBox.SelectedItem is null ? null : checkedListBox.SelectedItem.ToString(); + } + set + { + if (value != null && checkedListBox.Items.Contains(value)) checkedListBox.SelectedItem = value; + } + } + + public event Action SelectedItemChange; + + public void addItems(List items) + { + foreach (string item in items) + { + checkedListBox.Items.Add(item); + } + } + + public void clear() + { + checkedListBox.Items.Clear(); + } + + private void checkedListBox_SelectedIndexChanged(object sender, EventArgs e) + { + SelectedItemChange?.Invoke(checkedListBox.SelectedItem.ToString()); + } + } +} diff --git a/COP/Components/Components/UserCheckedListBox.resx b/COP/Components/Components/UserCheckedListBox.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/COP/Components/Components/UserCheckedListBox.resx @@ -0,0 +1,60 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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/COP/Components/Components/UserDatePicker.Designer.cs b/COP/Components/Components/UserDatePicker.Designer.cs new file mode 100644 index 0000000..a3cfbeb --- /dev/null +++ b/COP/Components/Components/UserDatePicker.Designer.cs @@ -0,0 +1,56 @@ +namespace Components.Components +{ + partial class UserDatePicker + { + /// + /// Обязательная переменная конструктора. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Освободить все используемые ресурсы. + /// + /// истинно, если управляемый ресурс должен быть удален; иначе ложно. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Код, автоматически созданный конструктором компонентов + + /// + /// Требуемый метод для поддержки конструктора — не изменяйте + /// содержимое этого метода с помощью редактора кода. + /// + private void InitializeComponent() + { + this.dateTimePicker = new System.Windows.Forms.DateTimePicker(); + this.SuspendLayout(); + // + // dateTimePicker + // + this.dateTimePicker.Location = new System.Drawing.Point(3, 3); + this.dateTimePicker.Name = "dateTimePicker"; + this.dateTimePicker.Size = new System.Drawing.Size(250, 27); + this.dateTimePicker.TabIndex = 0; + this.dateTimePicker.ValueChanged += new System.EventHandler(this.dateTimePicker_ValueChanged); + // + // UserDatePicker + // + this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.Controls.Add(this.dateTimePicker); + this.Name = "UserDatePicker"; + this.Size = new System.Drawing.Size(257, 38); + this.ResumeLayout(false); + } + + #endregion + + private DateTimePicker dateTimePicker; + } +} diff --git a/COP/Components/Components/UserDatePicker.cs b/COP/Components/Components/UserDatePicker.cs new file mode 100644 index 0000000..87dc0d4 --- /dev/null +++ b/COP/Components/Components/UserDatePicker.cs @@ -0,0 +1,74 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace Components.Components +{ + public partial class UserDatePicker : UserControl + { + public UserDatePicker() + { + InitializeComponent(); + } + public event Action DateChange; + private bool lowBoundrySet = false; + private bool highBoundrySet = false; + + public bool BoundriesSet { get { return lowBoundrySet && highBoundrySet; } } + + public DateTime? dateFrom + { + get + { + return lowBoundrySet ? dateTimePicker.MinDate : null; + } + set + { + if (value.HasValue) + { + dateTimePicker.MinDate = value.Value; + lowBoundrySet = true; + } + } + } + public DateTime? dateTo + { + get + { + return highBoundrySet ? dateTimePicker.MaxDate : null; + } + set + { + if (value.HasValue) + { + dateTimePicker.MaxDate = value.Value; + highBoundrySet = true; + } + } + } + + public DateTime? Value + { + get + { + if (!lowBoundrySet || !highBoundrySet || dateTimePicker.Value < dateFrom || dateTimePicker.Value > dateTo) return null; + return dateTimePicker.Value; + } + set + { + if (lowBoundrySet && highBoundrySet && value.HasValue && value.Value >= dateFrom && value.Value <= dateTo) dateTimePicker.Value = value.Value; + } + } + + private void dateTimePicker_ValueChanged(object sender, EventArgs e) + { + DateChange?.Invoke(dateTimePicker.Value); + } + } +} diff --git a/COP/Components/Components/UserDatePicker.resx b/COP/Components/Components/UserDatePicker.resx new file mode 100644 index 0000000..1af7de1 --- /dev/null +++ b/COP/Components/Components/UserDatePicker.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/COP/Components/Components/UserTreeView.Designer.cs b/COP/Components/Components/UserTreeView.Designer.cs new file mode 100644 index 0000000..f927508 --- /dev/null +++ b/COP/Components/Components/UserTreeView.Designer.cs @@ -0,0 +1,55 @@ +namespace Components.Components +{ + partial class UserTreeView + { + /// + /// Обязательная переменная конструктора. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Освободить все используемые ресурсы. + /// + /// истинно, если управляемый ресурс должен быть удален; иначе ложно. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Код, автоматически созданный конструктором компонентов + + /// + /// Требуемый метод для поддержки конструктора — не изменяйте + /// содержимое этого метода с помощью редактора кода. + /// + private void InitializeComponent() + { + this.treeView = new System.Windows.Forms.TreeView(); + this.SuspendLayout(); + // + // treeView + // + this.treeView.Location = new System.Drawing.Point(0, 0); + this.treeView.Name = "treeView"; + this.treeView.Size = new System.Drawing.Size(295, 212); + this.treeView.TabIndex = 0; + // + // UserTreeView + // + this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.Controls.Add(this.treeView); + this.Name = "UserTreeView"; + this.Size = new System.Drawing.Size(295, 212); + this.ResumeLayout(false); + } + + #endregion + + private TreeView treeView; + } +} diff --git a/COP/Components/Components/UserTreeView.cs b/COP/Components/Components/UserTreeView.cs new file mode 100644 index 0000000..f0171f5 --- /dev/null +++ b/COP/Components/Components/UserTreeView.cs @@ -0,0 +1,90 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace Components.Components +{ + public partial class UserTreeView : UserControl + { + public UserTreeView() + { + InitializeComponent(); + } + private List<(string, bool)> hierarchy = new List<(string, bool)>(); + + public int SelectedNodeIndex + { + get + { + return treeView.SelectedNode?.Index ?? -1; + } + set + { + if (treeView.SelectedNode == null) treeView.SelectedNode = value >= 0 && value < treeView.Nodes.Count ? treeView.Nodes[value] : treeView.SelectedNode; + else treeView.SelectedNode = value >= 0 && value < treeView.SelectedNode.Nodes.Count ? treeView.SelectedNode.Nodes[value] : treeView.SelectedNode; + } + } + + public T? getSelecetedNodeValue() + { + if (treeView.SelectedNode == null || treeView.SelectedNode.Nodes.Count > 0) return default(T); + + TreeNode? node = treeView.SelectedNode; + + var type = typeof(T); + var fields = type.GetFields(); + + var item = Activator.CreateInstance(type); + + while (node != null) + { + var field = fields.FirstOrDefault(x => x.Name == node.Name); + if (field != null) + { + field.SetValue(item, node.Text); + } + node = node.Parent; + } + + return item != null ? (T)item : default(T); + } + + public void setHierarchy(List<(string, bool)> fields) + { + hierarchy = fields; + } + + public void addItems(List items) + { + var type = typeof(T); + var fields = type.GetFields(); + foreach (T item in items) + { + TreeNodeCollection nodes = treeView.Nodes; + for (int i = 0; i < hierarchy.Count; i++) + { + var field = fields.FirstOrDefault(x => x.Name.Equals(hierarchy[i].Item1)); + if (field is not null) + { + var node = nodes.Find(field.Name, false).FirstOrDefault(x => x.Text == field.GetValue(item).ToString()); + if (node is not null && !hierarchy[i].Item2) + { + nodes = node.Nodes; + } + else + { + TreeNode newNode = nodes.Add(field.Name, field.GetValue(item).ToString()); + nodes = newNode.Nodes; + } + } + } + } + } + } +} diff --git a/COP/Components/Components/UserTreeView.resx b/COP/Components/Components/UserTreeView.resx new file mode 100644 index 0000000..1af7de1 --- /dev/null +++ b/COP/Components/Components/UserTreeView.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/COP/Components/Exceptions/DateBoundsNotSetException.cs b/COP/Components/Exceptions/DateBoundsNotSetException.cs new file mode 100644 index 0000000..d162017 --- /dev/null +++ b/COP/Components/Exceptions/DateBoundsNotSetException.cs @@ -0,0 +1,18 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Runtime.Serialization; + +namespace Components.Exceptions +{ + [Serializable] + public class DateBoundsNotSetException : ApplicationException + { + public DateBoundsNotSetException() : base() { } + public DateBoundsNotSetException(string message) : base(message) { } + public DateBoundsNotSetException(string message, Exception exception) : base(message, exception) { } + protected DateBoundsNotSetException(SerializationInfo info, StreamingContext contex) : base(info, contex) { } + } +} diff --git a/COP/Components/Exceptions/DateOutOfBoundsException.cs b/COP/Components/Exceptions/DateOutOfBoundsException.cs new file mode 100644 index 0000000..6480b72 --- /dev/null +++ b/COP/Components/Exceptions/DateOutOfBoundsException.cs @@ -0,0 +1,17 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Runtime.Serialization; +using System.Text; +using System.Threading.Tasks; + +namespace Components.Exceptions +{ + public class DateOutOfBoundsException : ApplicationException + { + public DateOutOfBoundsException() : base() { } + public DateOutOfBoundsException(string message) : base(message) { } + public DateOutOfBoundsException(string message, Exception exception) : base(message, exception) { } + protected DateOutOfBoundsException(SerializationInfo info, StreamingContext contex) : base(info, contex) { } + } +}