diff --git a/WinFormsProject/WinFormsLibrary/NumberTextBox.cs b/WinFormsProject/WinFormsLibrary/NumberTextBox.cs
index 58eb6a8..8dbb2b1 100644
--- a/WinFormsProject/WinFormsLibrary/NumberTextBox.cs
+++ b/WinFormsProject/WinFormsLibrary/NumberTextBox.cs
@@ -12,8 +12,8 @@ namespace WinFormsLibrary
{
public partial class NumberTextBox : UserControl
{
- public int maxValue;
- public int minValue;
+ public int? maxValue = null;
+ public int? minValue = null;
public bool error = false;
public NumberTextBox()
@@ -22,58 +22,53 @@ namespace WinFormsLibrary
}
-
- //публичное свойство
- public string Selected
+ public int? MinValue
{
- get
- {
- if (minValue == null)
- {
- error = true;
- }
-
- if (maxValue == null)
- {
- error = true;
- }
-
- if (Check_Value(Convert.ToInt32(numericUpDown.Value)))
- {
- return "";
- }
- return numericUpDown.Value.ToString();
- }
+ get { return minValue; }
set
{
- if (!Check_Value(Convert.ToInt32(numericUpDown.Value)))
+ if (value == null) return;
+ minValue = value;
+ numericUpDown.Minimum = (int)value;
+ }
+ }
+
+ public int? MaxValue
+ {
+ get { return maxValue; }
+ set
+ {
+ if (value == null) return;
+ maxValue = value;
+ numericUpDown.Maximum = (int)value;
+ }
+ }
+
+ public decimal Value
+ {
+ get { return numericUpDown.Value; }
+ set
+ {
+ if (MinValue == null || MaxValue == null)
{
error = true;
+ return;
}
- numericUpDown.Value = 0;
+
+ if (value < MinValue || value > MaxValue)
+ {
+ error = true;
+ return;
+ }
+
+ numericUpDown.Value = value;
}
}
- public void SetMaxValue(int number) // переделать через свойство
+ public event EventHandler DateChanged
{
- numericUpDown.Maximum = number;
- maxValue = number;
- }
-
- public void SetMinValue(int number) // переделать через свойство
- {
- numericUpDown.Minimum = number;
- minValue = number;
- }
-
- public bool Check_Value(int number)
- {
- if (number < numericUpDown.Minimum || number > numericUpDown.Maximum)
- {
- return false;
- }
-
- return true;
+ add { numericUpDown.ValueChanged += value; }
+ remove { numericUpDown.ValueChanged -= value; }
}
}
}
diff --git a/WinFormsProject/WinFormsLibrary/TreeClass.Designer.cs b/WinFormsProject/WinFormsLibrary/TreeClass.Designer.cs
new file mode 100644
index 0000000..698668f
--- /dev/null
+++ b/WinFormsProject/WinFormsLibrary/TreeClass.Designer.cs
@@ -0,0 +1,56 @@
+namespace WinFormsLibrary
+{
+ partial class TreeClass
+ {
+ ///
+ /// Обязательная переменная конструктора.
+ ///
+ 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(292, 224);
+ this.treeView.TabIndex = 0;
+ //
+ // TreeClass
+ //
+ this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
+ this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
+ this.Controls.Add(this.treeView);
+ this.Name = "TreeClass";
+ this.Size = new System.Drawing.Size(292, 224);
+ this.ResumeLayout(false);
+
+ }
+
+ #endregion
+
+ private TreeView treeView;
+ }
+}
diff --git a/WinFormsProject/WinFormsLibrary/TreeClass.cs b/WinFormsProject/WinFormsLibrary/TreeClass.cs
new file mode 100644
index 0000000..04d2c23
--- /dev/null
+++ b/WinFormsProject/WinFormsLibrary/TreeClass.cs
@@ -0,0 +1,133 @@
+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;
+using static System.Windows.Forms.VisualStyles.VisualStyleElement;
+
+namespace WinFormsLibrary
+{
+ public partial class TreeClass : UserControl
+ {
+ private List hierarchy;
+ public bool hasError = false;
+
+ public TreeClass()
+ {
+ InitializeComponent();
+ }
+
+ public void setHierarchy(List h)
+ {
+ hierarchy = h;
+ }
+
+ private bool hasValue(TreeNodeCollection nodes, string value)
+ {
+ foreach (TreeNode node in nodes)
+ {
+ if (node.Text == value) return true;
+ }
+
+ return false;
+ }
+
+ private bool addData(T t, string propertyName)
+ {
+ TreeNodeCollection current = treeView.Nodes;
+
+ foreach (string h in hierarchy)
+ {
+ if (h == propertyName)
+ {
+ var field = t.GetType().GetField(h);
+
+ if (field == null)
+ {
+ return false;
+ }
+
+ string value = field.GetValue(t).ToString();
+ if (!hasValue(current, value)) current.Add(value);
+
+ TreeNode elem = null;
+
+ foreach (TreeNode child in current)
+ {
+ if (child.Text == value)
+ {
+ elem = child;
+ break;
+ }
+ }
+
+ if (elem != null) current = elem.Nodes;
+ }
+ else
+ {
+ if (!hasValue(current, h)) current.Add(h);
+
+ TreeNode elem = null;
+
+ foreach (TreeNode child in current)
+ {
+ if (child.Text == h)
+ {
+ elem = child;
+ break;
+ }
+ }
+
+ if (elem != null) current = elem.Nodes;
+ }
+ }
+
+ return true;
+ }
+
+ public bool setData(T data, string propertyName)
+ {
+ bool status = addData(data, propertyName);
+ if (!status) return false;
+
+ return true;
+ }
+
+ public T GetSelectedClass() where T : new()
+ {
+ T res = new T();
+ TreeNode node = treeView.SelectedNode;
+
+ if (node.Nodes.Count != 0)
+ {
+ hasError = true;
+ return res;
+ }
+
+ for (int i = hierarchy.Count - 1; i >= 0; i--)
+ {
+ if (node == null)
+ {
+ hasError = true;
+ return res;
+ }
+
+ var curr = res.GetType().GetField(hierarchy[i]);
+ if (curr == null)
+ {
+ hasError = true;
+ return res;
+ }
+
+ curr.SetValue(res, node.Text);
+ node = node.Parent;
+ }
+
+ return res;
+ }
+ }
+}
diff --git a/WinFormsProject/WinFormsLibrary/TreeClass.resx b/WinFormsProject/WinFormsLibrary/TreeClass.resx
new file mode 100644
index 0000000..f298a7b
--- /dev/null
+++ b/WinFormsProject/WinFormsLibrary/TreeClass.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