From 2b27fa48ab0489a8163cd870abe59ef90b8dca4b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=90=D1=80=D1=82=D0=B5=D0=BC=20=D0=A5=D0=B0=D1=80=D0=BB?= =?UTF-8?q?=D0=B0=D0=BC=D0=BE=D0=B2?= Date: Fri, 20 Oct 2023 10:42:08 +0400 Subject: [PATCH] =?UTF-8?q?=D0=BF=D1=80=D0=B8=D0=BD=D1=8F=D1=82=D0=B0?= =?UTF-8?q?=D1=8F=201=20=D0=BB=D0=B0=D0=B1=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- TestView/Form1.cs | 21 ++++----------------- ViewComponents/Input_text.cs | 27 ++++++++++++++++++++++----- ViewComponents/MyTreeView.cs | 4 ++-- 3 files changed, 28 insertions(+), 24 deletions(-) diff --git a/TestView/Form1.cs b/TestView/Form1.cs index a5d65e0..ce8dd70 100644 --- a/TestView/Form1.cs +++ b/TestView/Form1.cs @@ -53,23 +53,10 @@ namespace TestView private void buttonCheck_Click(object sender, EventArgs e) { - try - { - if (input_text.Element.Equals("Range exeption")) - throw new TextBoundsNotSetExeption("Диапазон не задан"); - if (input_text.Element.Equals("Value exeption")) - throw new TextOutOfBoundsExeption("Слово вне диапазона"); - - MessageBox.Show(input_text.Element, "Через свойство"); - } - catch (TextBoundsNotSetExeption ex) - { - MessageBox.Show(ex.Message); - } - catch (TextOutOfBoundsExeption ex) - { - MessageBox.Show(ex.Message); - } + if (input_text.Element == null) + MessageBox.Show(input_text.Error); + else MessageBox.Show(input_text.Element, "Через свойство"); + } private void buttonIerarhy_Click(object sender, EventArgs e) diff --git a/ViewComponents/Input_text.cs b/ViewComponents/Input_text.cs index 4357236..e73a5dd 100644 --- a/ViewComponents/Input_text.cs +++ b/ViewComponents/Input_text.cs @@ -19,18 +19,19 @@ namespace ViewComponents InitializeComponent(); } + public String Error { get; set; } = String.Empty; + public event Action ItemChange; public int MinLen { get; set; } = -1; public int MaxLen { get; set; } = -1; - public string Element + public string? Element { get { - if (MinLen < 0 || MaxLen < 0) return "Range exeption"; - if (textBox1.Text.Length < MinLen || textBox1.Text.Length > MaxLen) return "Value exeption"; - return textBox1.Text; + if (CheckValue()) return textBox1.Text; + return null; } set { @@ -38,7 +39,23 @@ namespace ViewComponents } } - + public bool CheckValue() + { + Error = string.Empty; + if (MinLen < 0 || MaxLen < 0) + { + Error = "Bounds error"; + return false; + } + + if (textBox1.Text.Length < MinLen || textBox1.Text.Length > MaxLen) + { + Error = "Value error"; + return false; + } + + return true; + } private void textBox1_TextChanged(object sender, EventArgs e) { diff --git a/ViewComponents/MyTreeView.cs b/ViewComponents/MyTreeView.cs index f5dab4c..70be559 100644 --- a/ViewComponents/MyTreeView.cs +++ b/ViewComponents/MyTreeView.cs @@ -34,7 +34,7 @@ namespace ViewComponents public T? getSelecetedNodeValue() { - if (treeView.SelectedNode == null || treeView.SelectedNode.Nodes.Count > 0) return default(T); + if (treeView.SelectedNode == null || treeView.SelectedNode.Nodes.Count > 0) throw new ArgumentException(); TreeNode? node = treeView.SelectedNode; @@ -53,7 +53,7 @@ namespace ViewComponents node = node.Parent; } - return item != null ? (T)item : default(T); + return (T)item; } public void setHierarchy(List<(string, bool)> fields)