3
This commit is contained in:
parent
11c1ae95fb
commit
918cbc514b
30
ExecForm/Form1.Designer.cs
generated
30
ExecForm/Form1.Designer.cs
generated
@ -29,7 +29,8 @@
|
|||||||
private void InitializeComponent()
|
private void InitializeComponent()
|
||||||
{
|
{
|
||||||
chooseList1 = new Library14Petrushin.ChooseList();
|
chooseList1 = new Library14Petrushin.ChooseList();
|
||||||
rangeTextBox1 = new Library14Petrushin.RangeTextBox();
|
hierarchicalTreeView1 = new Library14Petrushin.HierarchicalTreeView();
|
||||||
|
textBoxRange1 = new Library14Petrushin.TextBoxRange();
|
||||||
SuspendLayout();
|
SuspendLayout();
|
||||||
//
|
//
|
||||||
// chooseList1
|
// chooseList1
|
||||||
@ -40,21 +41,28 @@
|
|||||||
chooseList1.Size = new Size(185, 190);
|
chooseList1.Size = new Size(185, 190);
|
||||||
chooseList1.TabIndex = 0;
|
chooseList1.TabIndex = 0;
|
||||||
//
|
//
|
||||||
// rangeTextBox1
|
// hierarchicalTreeView1
|
||||||
//
|
//
|
||||||
rangeTextBox1.Location = new Point(259, 14);
|
hierarchicalTreeView1.Location = new Point(567, 2);
|
||||||
rangeTextBox1.MaxLength = 0;
|
hierarchicalTreeView1.Name = "hierarchicalTreeView1";
|
||||||
rangeTextBox1.MinLength = 0;
|
hierarchicalTreeView1.SelectedNodeIndex = -1;
|
||||||
rangeTextBox1.Name = "rangeTextBox1";
|
hierarchicalTreeView1.Size = new Size(266, 504);
|
||||||
rangeTextBox1.Size = new Size(188, 188);
|
hierarchicalTreeView1.TabIndex = 2;
|
||||||
rangeTextBox1.TabIndex = 1;
|
//
|
||||||
|
// textBoxRange1
|
||||||
|
//
|
||||||
|
textBoxRange1.Location = new Point(233, 24);
|
||||||
|
textBoxRange1.Name = "textBoxRange1";
|
||||||
|
textBoxRange1.Size = new Size(259, 66);
|
||||||
|
textBoxRange1.TabIndex = 3;
|
||||||
//
|
//
|
||||||
// Form1
|
// Form1
|
||||||
//
|
//
|
||||||
AutoScaleDimensions = new SizeF(8F, 20F);
|
AutoScaleDimensions = new SizeF(8F, 20F);
|
||||||
AutoScaleMode = AutoScaleMode.Font;
|
AutoScaleMode = AutoScaleMode.Font;
|
||||||
ClientSize = new Size(800, 450);
|
ClientSize = new Size(834, 507);
|
||||||
Controls.Add(rangeTextBox1);
|
Controls.Add(textBoxRange1);
|
||||||
|
Controls.Add(hierarchicalTreeView1);
|
||||||
Controls.Add(chooseList1);
|
Controls.Add(chooseList1);
|
||||||
Name = "Form1";
|
Name = "Form1";
|
||||||
Text = "Form1";
|
Text = "Form1";
|
||||||
@ -64,6 +72,8 @@
|
|||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
private Library14Petrushin.ChooseList chooseList1;
|
private Library14Petrushin.ChooseList chooseList1;
|
||||||
|
private Library14Petrushin.HierarchicalTreeView hierarchicalTreeView1;
|
||||||
private Library14Petrushin.RangeTextBox rangeTextBox1;
|
private Library14Petrushin.RangeTextBox rangeTextBox1;
|
||||||
|
private Library14Petrushin.TextBoxRange textBoxRange1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
15
Library14Petrushin/Classes/Employee.cs
Normal file
15
Library14Petrushin/Classes/Employee.cs
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace Library14Petrushin.Classes
|
||||||
|
{
|
||||||
|
public class Employee
|
||||||
|
{
|
||||||
|
public string? Department { get; set; }
|
||||||
|
public string? Position { get; set; }
|
||||||
|
public string? FullName { get; set; }
|
||||||
|
}
|
||||||
|
}
|
@ -1,6 +1,6 @@
|
|||||||
namespace Library14Petrushin
|
namespace Library14Petrushin
|
||||||
{
|
{
|
||||||
partial class TreeViewIerarch
|
partial class HierarchicalTreeView
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Обязательная переменная конструктора.
|
/// Обязательная переменная конструктора.
|
||||||
@ -28,10 +28,28 @@
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
private void InitializeComponent()
|
private void InitializeComponent()
|
||||||
{
|
{
|
||||||
components = new System.ComponentModel.Container();
|
treeView1 = new TreeView();
|
||||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
SuspendLayout();
|
||||||
|
//
|
||||||
|
// treeView1
|
||||||
|
//
|
||||||
|
treeView1.Location = new Point(3, 3);
|
||||||
|
treeView1.Name = "treeView1";
|
||||||
|
treeView1.Size = new Size(258, 496);
|
||||||
|
treeView1.TabIndex = 0;
|
||||||
|
//
|
||||||
|
// TreeViewIerarch
|
||||||
|
//
|
||||||
|
AutoScaleDimensions = new SizeF(8F, 20F);
|
||||||
|
AutoScaleMode = AutoScaleMode.Font;
|
||||||
|
Controls.Add(treeView1);
|
||||||
|
Name = "TreeViewIerarch";
|
||||||
|
Size = new Size(264, 502);
|
||||||
|
ResumeLayout(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
private TreeView treeView1;
|
||||||
}
|
}
|
||||||
}
|
}
|
98
Library14Petrushin/HierarchicalTreeView.cs
Normal file
98
Library14Petrushin/HierarchicalTreeView.cs
Normal file
@ -0,0 +1,98 @@
|
|||||||
|
using Library14Petrushin.Classes;
|
||||||
|
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 Library14Petrushin
|
||||||
|
{
|
||||||
|
public partial class HierarchicalTreeView : UserControl
|
||||||
|
{
|
||||||
|
private List<string> hierarchy;
|
||||||
|
private Dictionary<string, bool> alwaysNewBranch;
|
||||||
|
|
||||||
|
public HierarchicalTreeView()
|
||||||
|
{
|
||||||
|
InitializeComponent();
|
||||||
|
hierarchy = new List<string>();
|
||||||
|
alwaysNewBranch = new Dictionary<string, bool>();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void SetHierarchy(List<string> hierarchy, Dictionary<string, bool> alwaysNewBranch)
|
||||||
|
{
|
||||||
|
this.hierarchy = hierarchy;
|
||||||
|
this.alwaysNewBranch = alwaysNewBranch;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void AddObjectToTree(object obj, string stopAtProperty)
|
||||||
|
{
|
||||||
|
TreeNode currentNode = treeView1.Nodes.Cast<TreeNode>().FirstOrDefault();
|
||||||
|
foreach (var property in hierarchy)
|
||||||
|
{
|
||||||
|
var value = obj.GetType().GetProperty(property).GetValue(obj, null).ToString();
|
||||||
|
bool createNewBranch = alwaysNewBranch.ContainsKey(property) && alwaysNewBranch[property];
|
||||||
|
|
||||||
|
if (currentNode == null)
|
||||||
|
{
|
||||||
|
currentNode = treeView1.Nodes.Add(value);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
var childNode = currentNode.Nodes.Cast<TreeNode>().FirstOrDefault(n => n.Text == value);
|
||||||
|
if (childNode == null || createNewBranch)
|
||||||
|
{
|
||||||
|
childNode = currentNode.Nodes.Add(value);
|
||||||
|
}
|
||||||
|
currentNode = childNode;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (property == stopAtProperty)
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public int SelectedNodeIndex
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
return treeView1.SelectedNode?.Index ?? -1;
|
||||||
|
}
|
||||||
|
set
|
||||||
|
{
|
||||||
|
if (value >= 0 && value < treeView1.Nodes.Count)
|
||||||
|
{
|
||||||
|
treeView1.SelectedNode = treeView1.Nodes[value];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public object GetSelectedObject()
|
||||||
|
{
|
||||||
|
if (treeView1.SelectedNode == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
var node = treeView1.SelectedNode;
|
||||||
|
var obj = Activator.CreateInstance(typeof(Employee));
|
||||||
|
foreach (var property in hierarchy)
|
||||||
|
{
|
||||||
|
var value = node.Text;
|
||||||
|
obj.GetType().GetProperty(property).SetValue(obj, value);
|
||||||
|
node = node.Parent;
|
||||||
|
if (node == null)
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return obj;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -1,57 +0,0 @@
|
|||||||
using Library14Petrushin.Exeptions;
|
|
||||||
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 Library14Petrushin
|
|
||||||
{
|
|
||||||
public partial class RangeTextBox : UserControl
|
|
||||||
{
|
|
||||||
public int MinLength { get; set; }
|
|
||||||
public int MaxLength { get; set; }
|
|
||||||
|
|
||||||
public event EventHandler? ValueChanged;
|
|
||||||
|
|
||||||
public string InputValue
|
|
||||||
{
|
|
||||||
get
|
|
||||||
{
|
|
||||||
if (MinLength == 0 && MaxLength == 0)
|
|
||||||
{
|
|
||||||
throw new RangeException("Диапазон не задан.");
|
|
||||||
}
|
|
||||||
if (textBox1.Text.Length < MinLength || textBox1.Text.Length > MaxLength)
|
|
||||||
{
|
|
||||||
throw new RangeException("Введенное значение не входит в диапазон.");
|
|
||||||
}
|
|
||||||
return textBox1.Text;
|
|
||||||
}
|
|
||||||
set
|
|
||||||
{
|
|
||||||
if (MinLength != 0 && MaxLength != 0)
|
|
||||||
{
|
|
||||||
if (value.Length >= MinLength && value.Length <= MaxLength)
|
|
||||||
{
|
|
||||||
textBox1.Text = value;
|
|
||||||
ValueChanged?.Invoke(this, EventArgs.Empty);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
throw new RangeException("Диапазон не задан.");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void TextBox1_TextChanged(object sender, EventArgs e)
|
|
||||||
{
|
|
||||||
ValueChanged?.Invoke(this, e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,6 +1,6 @@
|
|||||||
namespace Library14Petrushin
|
namespace Library14Petrushin
|
||||||
{
|
{
|
||||||
partial class RangeTextBox
|
partial class TextBoxRange
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Обязательная переменная конструктора.
|
/// Обязательная переменная конструктора.
|
||||||
@ -33,19 +33,18 @@
|
|||||||
//
|
//
|
||||||
// textBox1
|
// textBox1
|
||||||
//
|
//
|
||||||
textBox1.Location = new Point(0, 3);
|
textBox1.Location = new Point(3, 14);
|
||||||
textBox1.Name = "textBox1";
|
textBox1.Name = "textBox1";
|
||||||
textBox1.Size = new Size(270, 27);
|
textBox1.Size = new Size(243, 27);
|
||||||
textBox1.TabIndex = 0;
|
textBox1.TabIndex = 0;
|
||||||
textBox1.TextChanged += TextBox1_TextChanged;
|
|
||||||
//
|
//
|
||||||
// RangeTextBox
|
// TextBoxRange
|
||||||
//
|
//
|
||||||
AutoScaleDimensions = new SizeF(8F, 20F);
|
AutoScaleDimensions = new SizeF(8F, 20F);
|
||||||
AutoScaleMode = AutoScaleMode.Font;
|
AutoScaleMode = AutoScaleMode.Font;
|
||||||
Controls.Add(textBox1);
|
Controls.Add(textBox1);
|
||||||
Name = "RangeTextBox";
|
Name = "TextBoxRange";
|
||||||
Size = new Size(273, 37);
|
Size = new Size(252, 53);
|
||||||
ResumeLayout(false);
|
ResumeLayout(false);
|
||||||
PerformLayout();
|
PerformLayout();
|
||||||
}
|
}
|
@ -10,9 +10,9 @@ using System.Windows.Forms;
|
|||||||
|
|
||||||
namespace Library14Petrushin
|
namespace Library14Petrushin
|
||||||
{
|
{
|
||||||
public partial class TreeViewIerarch : UserControl
|
public partial class TextBoxRange : UserControl
|
||||||
{
|
{
|
||||||
public TreeViewIerarch()
|
public TextBoxRange()
|
||||||
{
|
{
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
}
|
}
|
@ -1,17 +1,17 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<root>
|
<root>
|
||||||
<!--
|
<!--
|
||||||
Microsoft ResX Schema
|
Microsoft ResX Schema
|
||||||
|
|
||||||
Version 2.0
|
Version 2.0
|
||||||
|
|
||||||
The primary goals of this format is to allow a simple XML format
|
The primary goals of this format is to allow a simple XML format
|
||||||
that is mostly human readable. The generation and parsing of the
|
that is mostly human readable. The generation and parsing of the
|
||||||
various data types are done through the TypeConverter classes
|
various data types are done through the TypeConverter classes
|
||||||
associated with the data types.
|
associated with the data types.
|
||||||
|
|
||||||
Example:
|
Example:
|
||||||
|
|
||||||
... ado.net/XML headers & schema ...
|
... ado.net/XML headers & schema ...
|
||||||
<resheader name="resmimetype">text/microsoft-resx</resheader>
|
<resheader name="resmimetype">text/microsoft-resx</resheader>
|
||||||
<resheader name="version">2.0</resheader>
|
<resheader name="version">2.0</resheader>
|
||||||
@ -26,36 +26,36 @@
|
|||||||
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
|
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
|
||||||
<comment>This is a comment</comment>
|
<comment>This is a comment</comment>
|
||||||
</data>
|
</data>
|
||||||
|
|
||||||
There are any number of "resheader" rows that contain simple
|
There are any number of "resheader" rows that contain simple
|
||||||
name/value pairs.
|
name/value pairs.
|
||||||
|
|
||||||
Each data row contains a name, and value. The row also contains a
|
Each data row contains a name, and value. The row also contains a
|
||||||
type or mimetype. Type corresponds to a .NET class that support
|
type or mimetype. Type corresponds to a .NET class that support
|
||||||
text/value conversion through the TypeConverter architecture.
|
text/value conversion through the TypeConverter architecture.
|
||||||
Classes that don't support this are serialized and stored with the
|
Classes that don't support this are serialized and stored with the
|
||||||
mimetype set.
|
mimetype set.
|
||||||
|
|
||||||
The mimetype is used for serialized objects, and tells the
|
The mimetype is used for serialized objects, and tells the
|
||||||
ResXResourceReader how to depersist the object. This is currently not
|
ResXResourceReader how to depersist the object. This is currently not
|
||||||
extensible. For a given mimetype the value must be set accordingly:
|
extensible. For a given mimetype the value must be set accordingly:
|
||||||
|
|
||||||
Note - application/x-microsoft.net.object.binary.base64 is the format
|
Note - application/x-microsoft.net.object.binary.base64 is the format
|
||||||
that the ResXResourceWriter will generate, however the reader can
|
that the ResXResourceWriter will generate, however the reader can
|
||||||
read any of the formats listed below.
|
read any of the formats listed below.
|
||||||
|
|
||||||
mimetype: application/x-microsoft.net.object.binary.base64
|
mimetype: application/x-microsoft.net.object.binary.base64
|
||||||
value : The object must be serialized with
|
value : The object must be serialized with
|
||||||
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
|
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
|
||||||
: and then encoded with base64 encoding.
|
: and then encoded with base64 encoding.
|
||||||
|
|
||||||
mimetype: application/x-microsoft.net.object.soap.base64
|
mimetype: application/x-microsoft.net.object.soap.base64
|
||||||
value : The object must be serialized with
|
value : The object must be serialized with
|
||||||
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
|
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
|
||||||
: and then encoded with base64 encoding.
|
: and then encoded with base64 encoding.
|
||||||
|
|
||||||
mimetype: application/x-microsoft.net.object.bytearray.base64
|
mimetype: application/x-microsoft.net.object.bytearray.base64
|
||||||
value : The object must be serialized into a byte array
|
value : The object must be serialized into a byte array
|
||||||
: using a System.ComponentModel.TypeConverter
|
: using a System.ComponentModel.TypeConverter
|
||||||
: and then encoded with base64 encoding.
|
: and then encoded with base64 encoding.
|
||||||
-->
|
-->
|
Loading…
x
Reference in New Issue
Block a user