Вроде сделал
This commit is contained in:
parent
82f6fc6e49
commit
5b17be9211
@ -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; }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
56
WinFormsProject/WinFormsLibrary/TreeClass.Designer.cs
generated
Normal file
56
WinFormsProject/WinFormsLibrary/TreeClass.Designer.cs
generated
Normal file
@ -0,0 +1,56 @@
|
||||
namespace WinFormsLibrary
|
||||
{
|
||||
partial class TreeClass
|
||||
{
|
||||
/// <summary>
|
||||
/// Обязательная переменная конструктора.
|
||||
/// </summary>
|
||||
private System.ComponentModel.IContainer components = null;
|
||||
|
||||
/// <summary>
|
||||
/// Освободить все используемые ресурсы.
|
||||
/// </summary>
|
||||
/// <param name="disposing">истинно, если управляемый ресурс должен быть удален; иначе ложно.</param>
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing && (components != null))
|
||||
{
|
||||
components.Dispose();
|
||||
}
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
|
||||
#region Код, автоматически созданный конструктором компонентов
|
||||
|
||||
/// <summary>
|
||||
/// Требуемый метод для поддержки конструктора — не изменяйте
|
||||
/// содержимое этого метода с помощью редактора кода.
|
||||
/// </summary>
|
||||
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;
|
||||
}
|
||||
}
|
133
WinFormsProject/WinFormsLibrary/TreeClass.cs
Normal file
133
WinFormsProject/WinFormsLibrary/TreeClass.cs
Normal file
@ -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<string> hierarchy;
|
||||
public bool hasError = false;
|
||||
|
||||
public TreeClass()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
public void setHierarchy(List<string> 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 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>(T data, string propertyName)
|
||||
{
|
||||
bool status = addData<T>(data, propertyName);
|
||||
if (!status) return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public T GetSelectedClass<T>() 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;
|
||||
}
|
||||
}
|
||||
}
|
60
WinFormsProject/WinFormsLibrary/TreeClass.resx
Normal file
60
WinFormsProject/WinFormsLibrary/TreeClass.resx
Normal file
@ -0,0 +1,60 @@
|
||||
<root>
|
||||
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
|
||||
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
|
||||
<xsd:element name="root" msdata:IsDataSet="true">
|
||||
<xsd:complexType>
|
||||
<xsd:choice maxOccurs="unbounded">
|
||||
<xsd:element name="metadata">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" use="required" type="xsd:string" />
|
||||
<xsd:attribute name="type" type="xsd:string" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="assembly">
|
||||
<xsd:complexType>
|
||||
<xsd:attribute name="alias" type="xsd:string" />
|
||||
<xsd:attribute name="name" type="xsd:string" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="data">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
|
||||
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="resheader">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:choice>
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:schema>
|
||||
<resheader name="resmimetype">
|
||||
<value>text/microsoft-resx</value>
|
||||
</resheader>
|
||||
<resheader name="version">
|
||||
<value>2.0</value>
|
||||
</resheader>
|
||||
<resheader name="reader">
|
||||
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<resheader name="writer">
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
</root>
|
Loading…
Reference in New Issue
Block a user