From 6a5d109bbadcfe22008053b8800a606947b93c12 Mon Sep 17 00:00:00 2001 From: bulatova_karina Date: Mon, 16 Sep 2024 14:43:23 +0400 Subject: [PATCH] =?UTF-8?q?=D1=81=D0=BE=D0=B7=D0=B4=D0=B0=D0=BB=D0=B0=20?= =?UTF-8?q?=D0=B2=D1=81=D0=B5=20=D0=BA=D0=BE=D0=BC=D0=BF=D0=BE=D0=BD=D0=B5?= =?UTF-8?q?=D0=BD=D1=82=D1=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- COP/Components/Class1.cs | 6 - .../Components/UserDropDownList.Designer.cs | 59 +++++++++ COP/Components/Components/UserDropDownList.cs | 73 +++++++++++ .../Components/UserDropDownList.resx | 60 +++++++++ .../Components/UserEmailTextBox.Designer.cs | 59 +++++++++ COP/Components/Components/UserEmailTextBox.cs | 98 ++++++++++++++ .../Components/UserEmailTextBox.resx | 60 +++++++++ .../Components/UserListBoxObject.Designer.cs | 59 +++++++++ .../Components/UserListBoxObject.cs | 108 ++++++++++++++++ .../Components/UserListBoxObject.resx | 120 ++++++++++++++++++ 10 files changed, 696 insertions(+), 6 deletions(-) delete mode 100644 COP/Components/Class1.cs create mode 100644 COP/Components/Components/UserDropDownList.Designer.cs create mode 100644 COP/Components/Components/UserDropDownList.cs create mode 100644 COP/Components/Components/UserDropDownList.resx create mode 100644 COP/Components/Components/UserEmailTextBox.Designer.cs create mode 100644 COP/Components/Components/UserEmailTextBox.cs create mode 100644 COP/Components/Components/UserEmailTextBox.resx create mode 100644 COP/Components/Components/UserListBoxObject.Designer.cs create mode 100644 COP/Components/Components/UserListBoxObject.cs create mode 100644 COP/Components/Components/UserListBoxObject.resx diff --git a/COP/Components/Class1.cs b/COP/Components/Class1.cs deleted file mode 100644 index 777a957..0000000 --- a/COP/Components/Class1.cs +++ /dev/null @@ -1,6 +0,0 @@ -namespace Components -{ - public class Class1 - { - } -} \ No newline at end of file diff --git a/COP/Components/Components/UserDropDownList.Designer.cs b/COP/Components/Components/UserDropDownList.Designer.cs new file mode 100644 index 0000000..0f3e92f --- /dev/null +++ b/COP/Components/Components/UserDropDownList.Designer.cs @@ -0,0 +1,59 @@ +namespace Components.Components +{ + partial class UserDropDownList + { + /// + /// Обязательная переменная конструктора. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Освободить все используемые ресурсы. + /// + /// истинно, если управляемый ресурс должен быть удален; иначе ложно. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Код, автоматически созданный конструктором компонентов + + /// + /// Требуемый метод для поддержки конструктора — не изменяйте + /// содержимое этого метода с помощью редактора кода. + /// + private void InitializeComponent() + { + this.dropDownList = new System.Windows.Forms.ComboBox(); + this.SuspendLayout(); + // + // dropDownList + // + this.dropDownList.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; + this.dropDownList.FormattingEnabled = true; + this.dropDownList.Location = new System.Drawing.Point(3, 3); + this.dropDownList.Name = "dropDownList"; + this.dropDownList.Size = new System.Drawing.Size(187, 24); + this.dropDownList.TabIndex = 0; + this.dropDownList.SelectedValueChanged += new System.EventHandler(this.comboBox_SelectedValueChanged); + // + // UserDropDownList + // + this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 16F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.Controls.Add(this.dropDownList); + this.Name = "UserDropDownList"; + this.Size = new System.Drawing.Size(193, 30); + this.ResumeLayout(false); + + } + + #endregion + + private System.Windows.Forms.ComboBox dropDownList; + } +} \ No newline at end of file diff --git a/COP/Components/Components/UserDropDownList.cs b/COP/Components/Components/UserDropDownList.cs new file mode 100644 index 0000000..c7929c7 --- /dev/null +++ b/COP/Components/Components/UserDropDownList.cs @@ -0,0 +1,73 @@ +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 Components.Components +{ + public partial class UserDropDownList : UserControl + { + public UserDropDownList() + { + InitializeComponent(); + } + public void LoadValues(List Values) + { + if (Values.Count == 0) + { + return; + } + dropDownList.Items.AddRange(Values.ToArray()); + } + public void Clear() + { + dropDownList.Items.Clear(); + } + + public string SelectedValue + { + get + { + if (dropDownList.Items.Count == 0) + { + return ""; + } + if (dropDownList.SelectedItem == null) + { + return ""; + } + return dropDownList.SelectedItem.ToString(); + } + set + { + if (dropDownList.Items.Contains(value)) + { + dropDownList.SelectedItem = value; + } + } + } + + private EventHandler onValueChanged; + public event EventHandler ValueChanged + { + add + { + onValueChanged += value; + } + remove + { + onValueChanged -= value; + } + } + + private void comboBox_SelectedValueChanged(object sender, EventArgs e) + { + onValueChanged?.Invoke(sender, e); + } + } +} diff --git a/COP/Components/Components/UserDropDownList.resx b/COP/Components/Components/UserDropDownList.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/COP/Components/Components/UserDropDownList.resx @@ -0,0 +1,60 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/COP/Components/Components/UserEmailTextBox.Designer.cs b/COP/Components/Components/UserEmailTextBox.Designer.cs new file mode 100644 index 0000000..9493299 --- /dev/null +++ b/COP/Components/Components/UserEmailTextBox.Designer.cs @@ -0,0 +1,59 @@ +namespace Components.Components +{ + partial class UserEmailTextBox + { + /// + /// Обязательная переменная конструктора. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Освободить все используемые ресурсы. + /// + /// истинно, если управляемый ресурс должен быть удален; иначе ложно. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Код, автоматически созданный конструктором компонентов + + /// + /// Требуемый метод для поддержки конструктора — не изменяйте + /// содержимое этого метода с помощью редактора кода. + /// + private void InitializeComponent() + { + this.emailTextBox = new System.Windows.Forms.TextBox(); + this.SuspendLayout(); + // + // emailTextBox + // + this.emailTextBox.Location = new System.Drawing.Point(3, 3); + this.emailTextBox.Name = "emailTextBox"; + this.emailTextBox.Size = new System.Drawing.Size(170, 22); + this.emailTextBox.TabIndex = 0; + this.emailTextBox.TextChanged += new System.EventHandler(this.textBox_TextChanged); + this.emailTextBox.Enter += new System.EventHandler(this.textBox_Enter); + // + // UserEmailTextBox + // + this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 16F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.Controls.Add(this.emailTextBox); + this.Name = "UserEmailTextBox"; + this.Size = new System.Drawing.Size(177, 30); + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private System.Windows.Forms.TextBox emailTextBox; + } +} \ No newline at end of file diff --git a/COP/Components/Components/UserEmailTextBox.cs b/COP/Components/Components/UserEmailTextBox.cs new file mode 100644 index 0000000..2a589d9 --- /dev/null +++ b/COP/Components/Components/UserEmailTextBox.cs @@ -0,0 +1,98 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Text.RegularExpressions; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace Components.Components +{ + public partial class UserEmailTextBox : UserControl + { + private string pattern; + + private string example = "example@yandex.ru"; + public UserEmailTextBox() + { + InitializeComponent(); + } + public string Pattern + { + get { return pattern; } + set { pattern = value; } + } + public string TextBoxValue + { + get + { + Regex rg = new Regex(Pattern); + bool address = rg.IsMatch(emailTextBox.Text); + if (address) + { + return emailTextBox.Text; + } + else + { + Error = "Некорректный ввод"; + return null; + } + } + set + { + Regex rg = new Regex(Pattern); + bool address = rg.IsMatch(value); + if (address) + { + emailTextBox.Text = value; + } + else + { + Error = "Некорректный ввод"; + } + } + } + public string Error + { + get; private set; + } + public void setExample(string str) + { + Regex rg = new Regex(Pattern); + bool address = rg.IsMatch(str); + if (address) + { + example = str; + } + + } + private void textBox_Enter(object sender, EventArgs e) + { + int VisibleTime = 2000; //ms + ToolTip tooltip = new ToolTip(); + tooltip.Show(example, emailTextBox, 30, -20, VisibleTime); + } + + private EventHandler onValueChanged; + public event EventHandler ValueChanged + { + add + { + onValueChanged += value; + } + remove + { + onValueChanged -= value; + } + } + + private void textBox_TextChanged(object sender, EventArgs e) + { + onValueChanged?.Invoke(sender, e); + } + } +} + diff --git a/COP/Components/Components/UserEmailTextBox.resx b/COP/Components/Components/UserEmailTextBox.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/COP/Components/Components/UserEmailTextBox.resx @@ -0,0 +1,60 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/COP/Components/Components/UserListBoxObject.Designer.cs b/COP/Components/Components/UserListBoxObject.Designer.cs new file mode 100644 index 0000000..8d5316c --- /dev/null +++ b/COP/Components/Components/UserListBoxObject.Designer.cs @@ -0,0 +1,59 @@ +namespace Components.Components +{ + partial class UserListBoxObject + { + /// + /// Обязательная переменная конструктора. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Освободить все используемые ресурсы. + /// + /// истинно, если управляемый ресурс должен быть удален; иначе ложно. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Код, автоматически созданный конструктором компонентов + + /// + /// Требуемый метод для поддержки конструктора — не изменяйте + /// содержимое этого метода с помощью редактора кода. + /// + private void InitializeComponent() + { + this.listBoxObj = new System.Windows.Forms.ListBox(); + this.SuspendLayout(); + // + // listBoxObj + // + this.listBoxObj.FormattingEnabled = true; + this.listBoxObj.HorizontalScrollbar = true; + this.listBoxObj.ItemHeight = 16; + this.listBoxObj.Location = new System.Drawing.Point(3, 3); + this.listBoxObj.Name = "listBoxObj"; + this.listBoxObj.Size = new System.Drawing.Size(353, 116); + this.listBoxObj.TabIndex = 0; + // + // UserListBoxObjects + // + this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 16F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.Controls.Add(this.listBoxObj); + this.Name = "UserListBoxObjects"; + this.Size = new System.Drawing.Size(359, 133); + this.ResumeLayout(false); + + } + + #endregion + + private System.Windows.Forms.ListBox listBoxObj; + } +} diff --git a/COP/Components/Components/UserListBoxObject.cs b/COP/Components/Components/UserListBoxObject.cs new file mode 100644 index 0000000..9b9be16 --- /dev/null +++ b/COP/Components/Components/UserListBoxObject.cs @@ -0,0 +1,108 @@ +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 Components.Components +{ + public partial class UserListBoxObject : UserControl + { + //Макетная строка + private string layoutString; + //начальный символ для обнаружения свойств/полей + private string startSymbol; + //конечный символ для обнаружения свойств/полей + private string endSymbol; + public UserListBoxObject() + { + InitializeComponent(); + } + public void SetLayoutInfo(string layout, string startS, string endS) + { + if (layout == null || startS == null || endS == null) + { + return; + } + layoutString = layout; + startSymbol = startS; + endSymbol = endS; + } + + //свойство для получения и заполнения индекса выбранного элемента + public int SelectedIndex + { + get + { + if (listBoxObj.SelectedIndex == -1) + { + return -1; + } + return listBoxObj.SelectedIndex; + } + set + { + if (listBoxObj.SelectedItems.Count != 0) + { + listBoxObj.SelectedIndex = value; + } + } + } + + //Публичный параметризованный метод для получения объекта из выбранной строки(создать объект и через рефлексию заполнить свойства его). + public T GetObjectFromStr() where T : class, new() + { + string selStr = ""; + if (listBoxObj.SelectedIndex != -1) + { + selStr = listBoxObj.SelectedItem.ToString(); + } + T curObject = new T(); + foreach (var pr in typeof(T).GetProperties()) + { + if (!pr.CanWrite) + { + continue; + } + int borderOne = selStr.IndexOf(startSymbol); + StringBuilder sb = new StringBuilder(selStr); + sb[borderOne] = 'z'; + selStr = sb.ToString(); + int borderTwo = selStr.IndexOf(endSymbol); + if (borderOne == -1 || borderTwo == -1) break; + string propertyValue = selStr.Substring(borderOne + 1, borderTwo - borderOne - 1); + selStr = selStr.Substring(borderTwo + 1); + pr.SetValue(curObject, Convert.ChangeType(propertyValue, pr.PropertyType)); + } + return curObject; + } + //параметризованный метод, у которого в передаваемых параметрах идет список объектов некого класса и через этот список идет заполнение ListBox; + public void AddInListBox(List objects) + { + if (layoutString == null || startSymbol == null || endSymbol == null) + { + MessageBox.Show("заполните информацию о макетной строке"); + return; + } + if (!layoutString.Contains(startSymbol) || !layoutString.Contains(endSymbol)) + { + MessageBox.Show("Макетная строка не содержит нужные элементы"); + return; + } + foreach (var item in objects) + { + string str = layoutString; + foreach (var prop in item.GetType().GetProperties()) + { + string str1 = $"{startSymbol}" + $"{prop.Name}" + $"{endSymbol}"; + str = str.Replace(str1, $"{startSymbol}" + prop.GetValue(item).ToString() + $"{endSymbol}"); + } + listBoxObj.Items.Add(str); + } + } + } +} diff --git a/COP/Components/Components/UserListBoxObject.resx b/COP/Components/Components/UserListBoxObject.resx new file mode 100644 index 0000000..1af7de1 --- /dev/null +++ b/COP/Components/Components/UserListBoxObject.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file