From 6ed4cc2635ee80fe76b843b1fca4fadb01c08bcc Mon Sep 17 00:00:00 2001 From: ksenianeva <95441235+ksenianeva@users.noreply.github.com> Date: Fri, 6 Oct 2023 00:52:09 +0400 Subject: [PATCH] Made components --- NevaevaLibrary/NevaevaLibrary.sln | 25 +++++ .../Components/ComboBoxControl.Designer.cs | 58 ++++++++++++ .../Components/ComboBoxControl.cs | 52 +++++++++++ .../Components/ComboBoxControl.resx | 60 ++++++++++++ .../Components/ListBoxControl.Designer.cs | 58 ++++++++++++ .../Components/ListBoxControl.cs | 92 +++++++++++++++++++ .../Components/ListBoxControl.resx | 60 ++++++++++++ .../Components/MailControl.Designer.cs | 92 +++++++++++++++++++ .../NevaevaLibrary/Components/MailControl.cs | 63 +++++++++++++ .../Components/MailControl.resx | 63 +++++++++++++ .../Exceptions/EmptySymbolsException.cs | 18 ++++ .../Exceptions/NullSampleException.cs | 18 ++++ .../NevaevaLibrary/NevaevaLibrary.csproj | 10 ++ 13 files changed, 669 insertions(+) create mode 100644 NevaevaLibrary/NevaevaLibrary.sln create mode 100644 NevaevaLibrary/NevaevaLibrary/Components/ComboBoxControl.Designer.cs create mode 100644 NevaevaLibrary/NevaevaLibrary/Components/ComboBoxControl.cs create mode 100644 NevaevaLibrary/NevaevaLibrary/Components/ComboBoxControl.resx create mode 100644 NevaevaLibrary/NevaevaLibrary/Components/ListBoxControl.Designer.cs create mode 100644 NevaevaLibrary/NevaevaLibrary/Components/ListBoxControl.cs create mode 100644 NevaevaLibrary/NevaevaLibrary/Components/ListBoxControl.resx create mode 100644 NevaevaLibrary/NevaevaLibrary/Components/MailControl.Designer.cs create mode 100644 NevaevaLibrary/NevaevaLibrary/Components/MailControl.cs create mode 100644 NevaevaLibrary/NevaevaLibrary/Components/MailControl.resx create mode 100644 NevaevaLibrary/NevaevaLibrary/Exceptions/EmptySymbolsException.cs create mode 100644 NevaevaLibrary/NevaevaLibrary/Exceptions/NullSampleException.cs create mode 100644 NevaevaLibrary/NevaevaLibrary/NevaevaLibrary.csproj diff --git a/NevaevaLibrary/NevaevaLibrary.sln b/NevaevaLibrary/NevaevaLibrary.sln new file mode 100644 index 0000000..f04aeec --- /dev/null +++ b/NevaevaLibrary/NevaevaLibrary.sln @@ -0,0 +1,25 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.3.32825.248 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NevaevaLibrary", "NevaevaLibrary\NevaevaLibrary.csproj", "{E7CA58DB-9F0F-4380-96F7-EAFDA623CE84}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {E7CA58DB-9F0F-4380-96F7-EAFDA623CE84}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {E7CA58DB-9F0F-4380-96F7-EAFDA623CE84}.Debug|Any CPU.Build.0 = Debug|Any CPU + {E7CA58DB-9F0F-4380-96F7-EAFDA623CE84}.Release|Any CPU.ActiveCfg = Release|Any CPU + {E7CA58DB-9F0F-4380-96F7-EAFDA623CE84}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {447455FF-8051-47FF-92EB-BA0A9E60D10E} + EndGlobalSection +EndGlobal diff --git a/NevaevaLibrary/NevaevaLibrary/Components/ComboBoxControl.Designer.cs b/NevaevaLibrary/NevaevaLibrary/Components/ComboBoxControl.Designer.cs new file mode 100644 index 0000000..cd54c4f --- /dev/null +++ b/NevaevaLibrary/NevaevaLibrary/Components/ComboBoxControl.Designer.cs @@ -0,0 +1,58 @@ +namespace NevaevaLibrary +{ + partial class ComboBoxControl + { + /// + /// Обязательная переменная конструктора. + /// + 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.comboBoxCustom = new System.Windows.Forms.ComboBox(); + this.SuspendLayout(); + // + // comboBoxCustom + // + this.comboBoxCustom.FormattingEnabled = true; + this.comboBoxCustom.Location = new System.Drawing.Point(3, 3); + this.comboBoxCustom.Name = "comboBoxCustom"; + this.comboBoxCustom.Size = new System.Drawing.Size(321, 28); + this.comboBoxCustom.TabIndex = 0; + this.comboBoxCustom.SelectedIndexChanged += new System.EventHandler(this.comboBoxCustom_SelectedIndexChanged); + // + // ComboBoxControl + // + this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.Controls.Add(this.comboBoxCustom); + this.Name = "ComboBoxControl"; + this.Size = new System.Drawing.Size(328, 35); + this.ResumeLayout(false); + + } + + #endregion + + private ComboBox comboBoxCustom; + } +} diff --git a/NevaevaLibrary/NevaevaLibrary/Components/ComboBoxControl.cs b/NevaevaLibrary/NevaevaLibrary/Components/ComboBoxControl.cs new file mode 100644 index 0000000..b3d6d2f --- /dev/null +++ b/NevaevaLibrary/NevaevaLibrary/Components/ComboBoxControl.cs @@ -0,0 +1,52 @@ +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 NevaevaLibrary +{ + public partial class ComboBoxControl : UserControl + { + public ComboBoxControl() + { + InitializeComponent(); + } + + public string SelectedValue + { + get + { + return comboBoxCustom.SelectedValue.ToString() ?? ""; + } + set + { + comboBoxCustom.SelectedValue = value; + } + } + + public event Action SelectedValueChange; + + public void addItems(List items) + { + foreach (string item in items) + { + comboBoxCustom.Items.Add(item); + } + } + + public void clear() + { + comboBoxCustom.Items.Clear(); + } + + private void comboBoxCustom_SelectedIndexChanged(object sender, EventArgs e) + { + SelectedValueChange.Invoke(comboBoxCustom.SelectedItem.ToString()); + } + } +} diff --git a/NevaevaLibrary/NevaevaLibrary/Components/ComboBoxControl.resx b/NevaevaLibrary/NevaevaLibrary/Components/ComboBoxControl.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/NevaevaLibrary/NevaevaLibrary/Components/ComboBoxControl.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/NevaevaLibrary/NevaevaLibrary/Components/ListBoxControl.Designer.cs b/NevaevaLibrary/NevaevaLibrary/Components/ListBoxControl.Designer.cs new file mode 100644 index 0000000..d4f9e7d --- /dev/null +++ b/NevaevaLibrary/NevaevaLibrary/Components/ListBoxControl.Designer.cs @@ -0,0 +1,58 @@ +namespace NevaevaLibrary +{ + partial class ListBoxControl + { + /// + /// Обязательная переменная конструктора. + /// + 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.listBox = new System.Windows.Forms.ListBox(); + this.SuspendLayout(); + // + // listBox + // + this.listBox.FormattingEnabled = true; + this.listBox.ItemHeight = 20; + this.listBox.Location = new System.Drawing.Point(0, 8); + this.listBox.Name = "listBox"; + this.listBox.Size = new System.Drawing.Size(599, 224); + this.listBox.TabIndex = 0; + // + // ListBoxControl + // + this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.Controls.Add(this.listBox); + this.Name = "ListBoxControl"; + this.Size = new System.Drawing.Size(599, 250); + this.ResumeLayout(false); + + } + + #endregion + + private ListBox listBox; + } +} diff --git a/NevaevaLibrary/NevaevaLibrary/Components/ListBoxControl.cs b/NevaevaLibrary/NevaevaLibrary/Components/ListBoxControl.cs new file mode 100644 index 0000000..67982ee --- /dev/null +++ b/NevaevaLibrary/NevaevaLibrary/Components/ListBoxControl.cs @@ -0,0 +1,92 @@ +using NevaevaLibrary.Exceptions; +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; +using static System.Windows.Forms.VisualStyles.VisualStyleElement; + +namespace NevaevaLibrary +{ + public partial class ListBoxControl : UserControl + { + public ListBoxControl() + { + InitializeComponent(); + } + + public string? template; + public char? fromChar; + public char? toChar; + + public void setItems(List items) + where T : class + { + if (template == null || !fromChar.HasValue || !toChar.HasValue) throw new ArgumentException("Не хватает данных!"); + listBox.Items.Clear(); + var type = typeof(T); + var fields = type.GetFields(); + foreach (T item in items) + { + string result = template; + foreach (var field in fields) + { + string search = fromChar.Value + field.Name + toChar.Value; + result = result.Replace(search, field.GetValue(item).ToString()); + } + listBox.Items.Add(result); + } + } + + public T? getSelectedItems() + { + if (template == null || !fromChar.HasValue || !toChar.HasValue || listBox.SelectedIndex == -1) throw new ArgumentException("Не хватает данных!"); + var type = typeof(T); + var fields = type.GetFields(); + + var item = Activator.CreateInstance(type); + + string[] wordsTemplate = template.Split(' '); + string[] words = listBox.SelectedItem.ToString().Split(' '); + for (int i = 0; i < wordsTemplate.Length; i++) + { + string word = wordsTemplate[i]; + if (word.StartsWith(fromChar.Value)) + { + string fieldName = word.Substring(1, word.Length - 2); + var field = fields.FirstOrDefault(x => x.Name == fieldName); + if (field == null) continue; + int indexBefore = i > 0 ? Array.IndexOf(words, wordsTemplate[i-1]) : 0; + int indexAfter = i < wordsTemplate.Length - 1 ? Array.IndexOf(words, wordsTemplate[i+1]) : wordsTemplate.Length - 1; + var fieldValue = String.Join(' ', words.Skip(indexBefore).Take(indexAfter - indexBefore - 1).ToArray()); + field.SetValue(item, fieldValue); + } + } + + return item != null ? (T)item : default(T); + } + + public int SelectedIndex + { + get + { + return listBox.SelectedIndex; + } + set + { + listBox.SelectedIndex = value; + } + } + + public void setParams(string template, char fromChar, char toChar) + { + this.template = template; + this.fromChar = fromChar; + this.toChar = toChar; + } + } +} \ No newline at end of file diff --git a/NevaevaLibrary/NevaevaLibrary/Components/ListBoxControl.resx b/NevaevaLibrary/NevaevaLibrary/Components/ListBoxControl.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/NevaevaLibrary/NevaevaLibrary/Components/ListBoxControl.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/NevaevaLibrary/NevaevaLibrary/Components/MailControl.Designer.cs b/NevaevaLibrary/NevaevaLibrary/Components/MailControl.Designer.cs new file mode 100644 index 0000000..4c95b14 --- /dev/null +++ b/NevaevaLibrary/NevaevaLibrary/Components/MailControl.Designer.cs @@ -0,0 +1,92 @@ +namespace NevaevaLibrary +{ + partial class MailControl + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Component Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.components = new System.ComponentModel.Container(); + this.textBoxMail = new System.Windows.Forms.TextBox(); + this.checkBoxNull = new System.Windows.Forms.CheckBox(); + this.labelCheckAddress = new System.Windows.Forms.Label(); + this.toolTipEmail = new System.Windows.Forms.ToolTip(this.components); + this.SuspendLayout(); + // + // textBoxMail + // + this.textBoxMail.Location = new System.Drawing.Point(3, 3); + this.textBoxMail.Name = "textBoxMail"; + this.textBoxMail.Size = new System.Drawing.Size(257, 27); + this.textBoxMail.TabIndex = 0; + this.textBoxMail.TextChanged += new System.EventHandler(this.textBoxMail_TextChanged); + // + // checkBoxNull + // + this.checkBoxNull.AutoSize = true; + this.checkBoxNull.Location = new System.Drawing.Point(3, 36); + this.checkBoxNull.Name = "checkBoxNull"; + this.checkBoxNull.Size = new System.Drawing.Size(126, 24); + this.checkBoxNull.TabIndex = 1; + this.checkBoxNull.Text = "Не заполнять"; + this.checkBoxNull.UseVisualStyleBackColor = true; + this.checkBoxNull.CheckedChanged += new System.EventHandler(this.checkBoxNull_CheckedChanged); + // + // labelCheckAddress + // + this.labelCheckAddress.AutoSize = true; + this.labelCheckAddress.BackColor = System.Drawing.SystemColors.Control; + this.labelCheckAddress.ForeColor = System.Drawing.Color.Firebrick; + this.labelCheckAddress.Location = new System.Drawing.Point(5, 69); + this.labelCheckAddress.Name = "labelCheckAddress"; + this.labelCheckAddress.Size = new System.Drawing.Size(0, 20); + this.labelCheckAddress.TabIndex = 2; + // + // toolTipEmail + // + this.toolTipEmail.Popup += new System.Windows.Forms.PopupEventHandler(this.toolTipEmail_Popup); + // + // MailControl + // + this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.Controls.Add(this.labelCheckAddress); + this.Controls.Add(this.checkBoxNull); + this.Controls.Add(this.textBoxMail); + this.Name = "MailControl"; + this.Size = new System.Drawing.Size(264, 102); + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private TextBox textBoxMail; + private CheckBox checkBoxNull; + private Label labelCheckAddress; + private ToolTip toolTipEmail; + } +} \ No newline at end of file diff --git a/NevaevaLibrary/NevaevaLibrary/Components/MailControl.cs b/NevaevaLibrary/NevaevaLibrary/Components/MailControl.cs new file mode 100644 index 0000000..c2a1653 --- /dev/null +++ b/NevaevaLibrary/NevaevaLibrary/Components/MailControl.cs @@ -0,0 +1,63 @@ +using NevaevaLibrary.Exceptions; +using System.Text.RegularExpressions; +using System.Windows.Forms; + +namespace NevaevaLibrary +{ + public partial class MailControl : UserControl + { + public MailControl() + { + InitializeComponent(); + } + + public Regex? validateEmailRegex + { + get; + set; + } + + public event Action TextChange; + + + public string Email + { + get + { + return textBoxMail.Text; + } + set + { + if (validateEmailRegex == null) throw new NullSampleException("Пустой шаблон!"); + if (!validateEmailRegex.IsMatch(value)) labelCheckAddress.Text = "Некорректный адрес эл. почты!"; + else textBoxMail.Text = value; + } + } + + private void checkBoxNull_CheckedChanged(object sender, EventArgs e) //enable entering a text + clean text area + { + if (checkBoxNull.Checked) + { + textBoxMail.Enabled = false; + } + else + { + textBoxMail.Enabled = true; + textBoxMail.Text = ""; + } + } + + private void textBoxMail_TextChanged(object sender, EventArgs e) + { + TextChange.Invoke(textBoxMail.Text); + } + + public void toolTipEmail_Popup(object sender, PopupEventArgs e) + { + toolTipEmail.ToolTipTitle = "qwerty@gmail.com"; + } + + + //new Regex("^[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?$"); + } +} \ No newline at end of file diff --git a/NevaevaLibrary/NevaevaLibrary/Components/MailControl.resx b/NevaevaLibrary/NevaevaLibrary/Components/MailControl.resx new file mode 100644 index 0000000..10c1bba --- /dev/null +++ b/NevaevaLibrary/NevaevaLibrary/Components/MailControl.resx @@ -0,0 +1,63 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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 + + + 17, 17 + + \ No newline at end of file diff --git a/NevaevaLibrary/NevaevaLibrary/Exceptions/EmptySymbolsException.cs b/NevaevaLibrary/NevaevaLibrary/Exceptions/EmptySymbolsException.cs new file mode 100644 index 0000000..705f250 --- /dev/null +++ b/NevaevaLibrary/NevaevaLibrary/Exceptions/EmptySymbolsException.cs @@ -0,0 +1,18 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Runtime.Serialization; +using System.Text; +using System.Threading.Tasks; + +namespace NevaevaLibrary.Exceptions +{ + [Serializable] + public class EmptySymbolsException : ApplicationException + { + public EmptySymbolsException() : base() { } + public EmptySymbolsException(string message) : base(message) { } + public EmptySymbolsException(string message, Exception exception) : base(message, exception) { } + protected EmptySymbolsException(SerializationInfo info, StreamingContext contex) : base(info, contex) { } + } +} diff --git a/NevaevaLibrary/NevaevaLibrary/Exceptions/NullSampleException.cs b/NevaevaLibrary/NevaevaLibrary/Exceptions/NullSampleException.cs new file mode 100644 index 0000000..cf056bc --- /dev/null +++ b/NevaevaLibrary/NevaevaLibrary/Exceptions/NullSampleException.cs @@ -0,0 +1,18 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Runtime.Serialization; +using System.Text; +using System.Threading.Tasks; + +namespace NevaevaLibrary.Exceptions +{ + [Serializable] + public class NullSampleException : ApplicationException + { + public NullSampleException() : base() { } + public NullSampleException(string message) : base(message) { } + public NullSampleException(string message, Exception exception) : base(message, exception) { } + protected NullSampleException(SerializationInfo info, StreamingContext contex) : base(info, contex) { } + } +} diff --git a/NevaevaLibrary/NevaevaLibrary/NevaevaLibrary.csproj b/NevaevaLibrary/NevaevaLibrary/NevaevaLibrary.csproj new file mode 100644 index 0000000..060aa1c --- /dev/null +++ b/NevaevaLibrary/NevaevaLibrary/NevaevaLibrary.csproj @@ -0,0 +1,10 @@ + + + + net6.0-windows + enable + true + enable + + +