принятая 1 лаба

This commit is contained in:
Артем Харламов 2023-10-20 10:42:08 +04:00
parent bee04958e0
commit 2b27fa48ab
3 changed files with 28 additions and 24 deletions

View File

@ -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)

View File

@ -19,18 +19,19 @@ namespace ViewComponents
InitializeComponent();
}
public String Error { get; set; } = String.Empty;
public event Action<string?> 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)
{

View File

@ -34,7 +34,7 @@ namespace ViewComponents
public T? getSelecetedNodeValue<T>()
{
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)