From 7d7ce6cb91e321dca2c57620c6a68a2898c16829 Mon Sep 17 00:00:00 2001 From: platoff aeeee Date: Tue, 17 Sep 2024 12:41:48 +0400 Subject: [PATCH] try2 --- ...st.Designer.cs => DefaultList.Designer.cs} | 2 +- .../{DefoltList.cs => DefaultList.cs} | 4 +- .../{DefoltList.resx => DefaultList.resx} | 0 .../Exceptions/EmptyValueException.cs | 15 ++++ .../Exceptions/MalformedRealException.cs | 15 ++++ .../InputRealNumber.Designer.cs | 18 +++-- Library15Gerimovich/InputRealNumber.cs | 71 +++++++++++++++++++ .../Models/CustomDataTableColumnParameter.cs | 13 ++++ Library15Gerimovich/OutputTableResults.cs | 1 + 9 files changed, 132 insertions(+), 7 deletions(-) rename Library15Gerimovich/{DefoltList.Designer.cs => DefaultList.Designer.cs} (98%) rename Library15Gerimovich/{DefoltList.cs => DefaultList.cs} (94%) rename Library15Gerimovich/{DefoltList.resx => DefaultList.resx} (100%) create mode 100644 Library15Gerimovich/Exceptions/EmptyValueException.cs create mode 100644 Library15Gerimovich/Exceptions/MalformedRealException.cs create mode 100644 Library15Gerimovich/Models/CustomDataTableColumnParameter.cs diff --git a/Library15Gerimovich/DefoltList.Designer.cs b/Library15Gerimovich/DefaultList.Designer.cs similarity index 98% rename from Library15Gerimovich/DefoltList.Designer.cs rename to Library15Gerimovich/DefaultList.Designer.cs index e5cd2a0..73bbccd 100644 --- a/Library15Gerimovich/DefoltList.Designer.cs +++ b/Library15Gerimovich/DefaultList.Designer.cs @@ -1,6 +1,6 @@ namespace Library15Gerimovich { - partial class DefoltList + partial class DefaultList { /// /// Обязательная переменная конструктора. diff --git a/Library15Gerimovich/DefoltList.cs b/Library15Gerimovich/DefaultList.cs similarity index 94% rename from Library15Gerimovich/DefoltList.cs rename to Library15Gerimovich/DefaultList.cs index 9307f41..977830d 100644 --- a/Library15Gerimovich/DefoltList.cs +++ b/Library15Gerimovich/DefaultList.cs @@ -10,7 +10,7 @@ using System.Windows.Forms; namespace Library15Gerimovich { - public partial class DefoltList : UserControl + public partial class DefaultList : UserControl { public event EventHandler? SelectedValueChanged; @@ -34,7 +34,7 @@ namespace Library15Gerimovich } } - public DefoltList() + public DefaultList() { InitializeComponent(); } diff --git a/Library15Gerimovich/DefoltList.resx b/Library15Gerimovich/DefaultList.resx similarity index 100% rename from Library15Gerimovich/DefoltList.resx rename to Library15Gerimovich/DefaultList.resx diff --git a/Library15Gerimovich/Exceptions/EmptyValueException.cs b/Library15Gerimovich/Exceptions/EmptyValueException.cs new file mode 100644 index 0000000..840d13b --- /dev/null +++ b/Library15Gerimovich/Exceptions/EmptyValueException.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Library15Gerimovich.Exceptions +{ + public class EmptyValueException : ApplicationException + { + public EmptyValueException() + : base("Значение не введено") + { } + } +} diff --git a/Library15Gerimovich/Exceptions/MalformedRealException.cs b/Library15Gerimovich/Exceptions/MalformedRealException.cs new file mode 100644 index 0000000..d9d5e40 --- /dev/null +++ b/Library15Gerimovich/Exceptions/MalformedRealException.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Library15Gerimovich.Exceptions +{ + public class MalformedRealException : ApplicationException + { + public MalformedRealException() + : base("Введенное значение не является вещественным") + { } + } +} diff --git a/Library15Gerimovich/InputRealNumber.Designer.cs b/Library15Gerimovich/InputRealNumber.Designer.cs index 6a9b08c..0ba355a 100644 --- a/Library15Gerimovich/InputRealNumber.Designer.cs +++ b/Library15Gerimovich/InputRealNumber.Designer.cs @@ -29,25 +29,34 @@ private void InitializeComponent() { this.IsNullCheckBox = new System.Windows.Forms.CheckBox(); + this.MainTextBox = new System.Windows.Forms.TextBox(); this.SuspendLayout(); // // IsNullCheckBox // this.IsNullCheckBox.AutoSize = true; - this.IsNullCheckBox.Location = new System.Drawing.Point(42, 103); + this.IsNullCheckBox.Location = new System.Drawing.Point(3, 62); this.IsNullCheckBox.Name = "IsNullCheckBox"; - this.IsNullCheckBox.Size = new System.Drawing.Size(83, 19); + this.IsNullCheckBox.Size = new System.Drawing.Size(127, 19); this.IsNullCheckBox.TabIndex = 0; - this.IsNullCheckBox.Text = "checkBox1"; + this.IsNullCheckBox.Text = "Нулевое значение"; this.IsNullCheckBox.UseVisualStyleBackColor = true; // + // MainTextBox + // + this.MainTextBox.Location = new System.Drawing.Point(3, 20); + this.MainTextBox.Name = "MainTextBox"; + this.MainTextBox.Size = new System.Drawing.Size(127, 23); + this.MainTextBox.TabIndex = 1; + // // InputRealNumber // this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.Controls.Add(this.MainTextBox); this.Controls.Add(this.IsNullCheckBox); this.Name = "InputRealNumber"; - this.Size = new System.Drawing.Size(188, 187); + this.Size = new System.Drawing.Size(135, 101); this.ResumeLayout(false); this.PerformLayout(); @@ -56,5 +65,6 @@ #endregion private CheckBox IsNullCheckBox; + private TextBox MainTextBox; } } diff --git a/Library15Gerimovich/InputRealNumber.cs b/Library15Gerimovich/InputRealNumber.cs index d696fa7..e38d82b 100644 --- a/Library15Gerimovich/InputRealNumber.cs +++ b/Library15Gerimovich/InputRealNumber.cs @@ -7,14 +7,85 @@ using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; +using Library15Gerimovich.Exceptions; namespace Library15Gerimovich { public partial class InputRealNumber : UserControl { + private event EventHandler? _valueChanged; + public InputRealNumber() { InitializeComponent(); } + + /// + /// Установка и получение введенного значения + /// + public int? IntValue + { + get + { + if (IsNullCheckBox.Checked) + { + return null; + } + + if (string.IsNullOrEmpty(MainTextBox.Text)) + { + throw new EmptyValueException(); + } + + int ParsedInt; + if (Int32.TryParse(MainTextBox.Text, out ParsedInt)) + { + return ParsedInt; + } + else + { + throw new MalformedRealException(); + } + } + set + { + SetNullState(value is null, true); + if (value is not null) + { + MainTextBox.Text = value.ToString(); + } + } + } + + /// + /// Событие, вызываемое при смене значения (либо при смене CheckBox) + /// + public event EventHandler? ValueChanged + { + add { _valueChanged += value; } + remove { _valueChanged -= value; } + } + + private void SetNullState(bool IsNull, bool ClearText = false) + { + IsNullCheckBox.Checked = IsNull; + MainTextBox.Enabled = !IsNull; + + if (ClearText) + { + MainTextBox.Text = string.Empty; + } + } + + private void IsNullCheckBox_CheckedChanged(object sender, EventArgs e) + { + SetNullState(IsNullCheckBox.Checked); + _valueChanged?.Invoke(this, e); + } + + private void MainTextBox_TextChanged(object sender, EventArgs e) + { + _valueChanged?.Invoke(this, e); + } } } diff --git a/Library15Gerimovich/Models/CustomDataTableColumnParameter.cs b/Library15Gerimovich/Models/CustomDataTableColumnParameter.cs new file mode 100644 index 0000000..09a66da --- /dev/null +++ b/Library15Gerimovich/Models/CustomDataTableColumnParameter.cs @@ -0,0 +1,13 @@ +namespace Library15Gerimovich.Models +{ + public record CustomDataTableColumnParameter + { + public string HeaderName { get; init; } = string.Empty; + + public int Width { get; init; } = 0; + + public bool Visible { get; init; } = true; + + public string PropertyName { get; init; } = string.Empty; + } +} diff --git a/Library15Gerimovich/OutputTableResults.cs b/Library15Gerimovich/OutputTableResults.cs index a1f1b2e..45291c1 100644 --- a/Library15Gerimovich/OutputTableResults.cs +++ b/Library15Gerimovich/OutputTableResults.cs @@ -8,6 +8,7 @@ using System.Reflection; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; +using Library15Gerimovich.Models; namespace Library15Gerimovich {