diff --git a/WinForms.sln b/WinForms.sln new file mode 100644 index 0000000..4bd2c79 --- /dev/null +++ b/WinForms.sln @@ -0,0 +1,31 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.4.33110.190 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "WinFormsLibrary", "WinFormsLibrary\WinFormsLibrary.csproj", "{FA2C000C-0815-44C4-BBA7-FB37C33DE121}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WinForms", "WinForms\WinForms.csproj", "{AA566691-FB51-4E4C-BB7B-9BA77AD20FD1}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {FA2C000C-0815-44C4-BBA7-FB37C33DE121}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {FA2C000C-0815-44C4-BBA7-FB37C33DE121}.Debug|Any CPU.Build.0 = Debug|Any CPU + {FA2C000C-0815-44C4-BBA7-FB37C33DE121}.Release|Any CPU.ActiveCfg = Release|Any CPU + {FA2C000C-0815-44C4-BBA7-FB37C33DE121}.Release|Any CPU.Build.0 = Release|Any CPU + {AA566691-FB51-4E4C-BB7B-9BA77AD20FD1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {AA566691-FB51-4E4C-BB7B-9BA77AD20FD1}.Debug|Any CPU.Build.0 = Debug|Any CPU + {AA566691-FB51-4E4C-BB7B-9BA77AD20FD1}.Release|Any CPU.ActiveCfg = Release|Any CPU + {AA566691-FB51-4E4C-BB7B-9BA77AD20FD1}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {078F9A05-555B-4C61-9BDB-BAD29FC4166B} + EndGlobalSection +EndGlobal diff --git a/WinForms/FormComponents.Designer.cs b/WinForms/FormComponents.Designer.cs new file mode 100644 index 0000000..71d8a88 --- /dev/null +++ b/WinForms/FormComponents.Designer.cs @@ -0,0 +1,218 @@ +namespace WinForms +{ + partial class FormComponents + { + /// + /// 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 Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.dropDownList = new WinFormsLibrary.DropDownList(); + this.buttonAdd = new System.Windows.Forms.Button(); + this.buttonClear = new System.Windows.Forms.Button(); + this.buttonInfo = new System.Windows.Forms.Button(); + this.labelInfo = new System.Windows.Forms.Label(); + this.emailTextBox = new WinFormsLibrary.EmailTextBox(); + this.buttonExample = new System.Windows.Forms.Button(); + this.buttonShow = new System.Windows.Forms.Button(); + this.labelEmail = new System.Windows.Forms.Label(); + this.textBoxExample = new System.Windows.Forms.TextBox(); + this.listBoxValues = new WinFormsLibrary.ListBoxValues(); + this.buttonAddValues = new System.Windows.Forms.Button(); + this.buttonShowItem = new System.Windows.Forms.Button(); + this.labelShowInput = new System.Windows.Forms.Label(); + this.SuspendLayout(); + // + // dropDownList + // + this.dropDownList.Location = new System.Drawing.Point(-1, 3); + this.dropDownList.Name = "dropDownList"; + this.dropDownList.Selected = ""; + this.dropDownList.Size = new System.Drawing.Size(191, 104); + this.dropDownList.TabIndex = 0; + // + // buttonAdd + // + this.buttonAdd.Location = new System.Drawing.Point(12, 135); + this.buttonAdd.Name = "buttonAdd"; + this.buttonAdd.Size = new System.Drawing.Size(163, 40); + this.buttonAdd.TabIndex = 1; + this.buttonAdd.Text = "Добавить"; + this.buttonAdd.UseVisualStyleBackColor = true; + this.buttonAdd.Click += new System.EventHandler(this.buttonAdd_Click); + // + // buttonClear + // + this.buttonClear.Location = new System.Drawing.Point(12, 227); + this.buttonClear.Name = "buttonClear"; + this.buttonClear.Size = new System.Drawing.Size(163, 40); + this.buttonClear.TabIndex = 2; + this.buttonClear.Text = "Очистить"; + this.buttonClear.UseVisualStyleBackColor = true; + this.buttonClear.Click += new System.EventHandler(this.buttonClear_Click); + // + // buttonInfo + // + this.buttonInfo.Location = new System.Drawing.Point(12, 181); + this.buttonInfo.Name = "buttonInfo"; + this.buttonInfo.Size = new System.Drawing.Size(163, 40); + this.buttonInfo.TabIndex = 3; + this.buttonInfo.Text = "Показать"; + this.buttonInfo.UseVisualStyleBackColor = true; + this.buttonInfo.Click += new System.EventHandler(this.buttonInfo_Click); + // + // labelInfo + // + this.labelInfo.AutoSize = true; + this.labelInfo.Location = new System.Drawing.Point(64, 107); + this.labelInfo.Name = "labelInfo"; + this.labelInfo.Size = new System.Drawing.Size(58, 25); + this.labelInfo.TabIndex = 4; + this.labelInfo.Text = "Инфо"; + // + // emailTextBox + // + this.emailTextBox.Location = new System.Drawing.Point(196, 3); + this.emailTextBox.Name = "emailTextBox"; + this.emailTextBox.Pattern = null; + this.emailTextBox.Size = new System.Drawing.Size(185, 104); + this.emailTextBox.TabIndex = 5; + // + // buttonExample + // + this.buttonExample.Location = new System.Drawing.Point(202, 236); + this.buttonExample.Name = "buttonExample"; + this.buttonExample.Size = new System.Drawing.Size(147, 68); + this.buttonExample.TabIndex = 6; + this.buttonExample.Text = "Поменять пример"; + this.buttonExample.UseVisualStyleBackColor = true; + this.buttonExample.Click += new System.EventHandler(this.buttonSetExample_Click); + // + // buttonShow + // + this.buttonShow.Location = new System.Drawing.Point(196, 107); + this.buttonShow.Name = "buttonShow"; + this.buttonShow.Size = new System.Drawing.Size(185, 40); + this.buttonShow.TabIndex = 7; + this.buttonShow.Text = "Ввести"; + this.buttonShow.UseVisualStyleBackColor = true; + this.buttonShow.Click += new System.EventHandler(this.buttonShow_Click); + // + // labelEmail + // + this.labelEmail.AutoSize = true; + this.labelEmail.Location = new System.Drawing.Point(221, 150); + this.labelEmail.Name = "labelEmail"; + this.labelEmail.Size = new System.Drawing.Size(128, 25); + this.labelEmail.TabIndex = 8; + this.labelEmail.Text = "Для проверки"; + // + // textBoxExample + // + this.textBoxExample.Location = new System.Drawing.Point(199, 199); + this.textBoxExample.Name = "textBoxExample"; + this.textBoxExample.Size = new System.Drawing.Size(182, 31); + this.textBoxExample.TabIndex = 9; + // + // listBoxValues + // + this.listBoxValues.Location = new System.Drawing.Point(437, 30); + this.listBoxValues.Name = "listBoxValues"; + this.listBoxValues.SelectedIndex = -1; + this.listBoxValues.Size = new System.Drawing.Size(594, 237); + this.listBoxValues.TabIndex = 10; + // + // buttonAddValues + // + this.buttonAddValues.Location = new System.Drawing.Point(437, 273); + this.buttonAddValues.Name = "buttonAddValues"; + this.buttonAddValues.Size = new System.Drawing.Size(112, 34); + this.buttonAddValues.TabIndex = 11; + this.buttonAddValues.Text = "Добавить"; + this.buttonAddValues.UseVisualStyleBackColor = true; + this.buttonAddValues.Click += new System.EventHandler(this.buttonAddValues_Click); + // + // buttonShowItem + // + this.buttonShowItem.Location = new System.Drawing.Point(437, 313); + this.buttonShowItem.Name = "buttonShowItem"; + this.buttonShowItem.Size = new System.Drawing.Size(112, 34); + this.buttonShowItem.TabIndex = 12; + this.buttonShowItem.Text = "Получить"; + this.buttonShowItem.UseVisualStyleBackColor = true; + this.buttonShowItem.Click += new System.EventHandler(this.buttonShowItem_Click); + // + // labelShowInput + // + this.labelShowInput.AutoSize = true; + this.labelShowInput.Location = new System.Drawing.Point(437, 359); + this.labelShowInput.Name = "labelShowInput"; + this.labelShowInput.Size = new System.Drawing.Size(128, 25); + this.labelShowInput.TabIndex = 13; + this.labelShowInput.Text = "Для проверки"; + // + // FormComponents + // + this.AutoScaleDimensions = new System.Drawing.SizeF(10F, 25F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(1067, 450); + this.Controls.Add(this.labelShowInput); + this.Controls.Add(this.buttonShowItem); + this.Controls.Add(this.buttonAddValues); + this.Controls.Add(this.listBoxValues); + this.Controls.Add(this.textBoxExample); + this.Controls.Add(this.labelEmail); + this.Controls.Add(this.buttonShow); + this.Controls.Add(this.buttonExample); + this.Controls.Add(this.emailTextBox); + this.Controls.Add(this.labelInfo); + this.Controls.Add(this.buttonInfo); + this.Controls.Add(this.buttonClear); + this.Controls.Add(this.buttonAdd); + this.Controls.Add(this.dropDownList); + this.Name = "FormComponents"; + this.Text = "Form1"; + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private WinFormsLibrary.DropDownList dropDownList; + private Button buttonAdd; + private Button buttonClear; + private Button buttonInfo; + private Label labelInfo; + private WinFormsLibrary.EmailTextBox emailTextBox; + private Button buttonExample; + private Button buttonShow; + private Label labelEmail; + private TextBox textBoxExample; + private WinFormsLibrary.ListBoxValues listBoxValues; + private Button buttonAddValues; + private Button buttonShowItem; + private Label labelShowInput; + } +} \ No newline at end of file diff --git a/WinForms/FormComponents.cs b/WinForms/FormComponents.cs new file mode 100644 index 0000000..e67a3e2 --- /dev/null +++ b/WinForms/FormComponents.cs @@ -0,0 +1,81 @@ +using System.Collections.Generic; +using WinFormsLibrary; +using WinFormsLibrary.Object; + +namespace WinForms +{ + public partial class FormComponents : Form + { + List list = new List(); + List clients = new List(); + public FormComponents() + { + list = new List(); + list.AddRange(new string[] { "привет", "пока", "бб" }); + Client client1 = new Client("Сергей", "нет", "Идиот", 3); + Client client2 = new Client("Давид", "да-11", "Гений", 1); + Client client3 = new Client("Руслан", "Асу", "Летальный", 4); + clients.Add(client1); + clients.Add(client2); + clients.Add(client3); + InitializeComponent(); + dropDownList.LoadValues(new List() { "чего", "забей", "пример" }); + emailTextBox.Pattern = @"^([\w\.\-]+)@([\w\-]+)((\.(\w){2,3})+)$"; + listBoxValues.SetLayout("ФИО [FIO] Обзор [Review] Статус [Status] сумма [Sum]", "[", "]"); + dropDownList.ValueChanged += CustomEventHandler; + } + private void CustomEventHandler(object sender, EventArgs e) + { + MessageBox.Show("Хрю"); + } + + private void buttonAdd_Click(object sender, EventArgs e) + { + dropDownList.LoadValues(list); + } + private void buttonInfo_Click(object sender, EventArgs e) + { + labelInfo.Text = dropDownList.Selected; + } + + private void buttonClear_Click(object sender, EventArgs e) + { + dropDownList.Clear(); + } + private void buttonSetExample_Click(object sender, EventArgs e) + { + if (textBoxExample.Text == String.Empty) + { + return; + } + emailTextBox.setExample(textBoxExample.Text); + } + + private void buttonShow_Click(object sender, EventArgs e) + { + try + { + if (emailTextBox.TextBoxValue != null) + { + labelEmail.Text = emailTextBox.TextBoxValue; + } + } + catch (Exception ex) + { + MessageBox.Show(ex.Message); + } + } + + private void buttonShowItem_Click(object sender, EventArgs e) + { + string str = listBoxValues.GetObjectFromStr().FIO + " " + listBoxValues.GetObjectFromStr().Review + " " + listBoxValues.GetObjectFromStr().Status + " " + listBoxValues.GetObjectFromStr().Sum; + + labelShowInput.Text = str; + } + + private void buttonAddValues_Click(object sender, EventArgs e) + { + listBoxValues.AddInListBox(clients); + } + } +} \ No newline at end of file diff --git a/WinForms/FormComponents.resx b/WinForms/FormComponents.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/WinForms/FormComponents.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/WinForms/Program.cs b/WinForms/Program.cs new file mode 100644 index 0000000..e0c6595 --- /dev/null +++ b/WinForms/Program.cs @@ -0,0 +1,17 @@ +namespace WinForms +{ + internal static class Program + { + /// + /// The main entry point for the application. + /// + [STAThread] + static void Main() + { + // To customize application configuration such as set high DPI settings or default font, + // see https://aka.ms/applicationconfiguration. + ApplicationConfiguration.Initialize(); + Application.Run(new FormComponents()); + } + } +} \ No newline at end of file diff --git a/WinForms/WinForms.csproj b/WinForms/WinForms.csproj new file mode 100644 index 0000000..0654708 --- /dev/null +++ b/WinForms/WinForms.csproj @@ -0,0 +1,15 @@ + + + + WinExe + net6.0-windows + enable + true + enable + + + + + + + \ No newline at end of file diff --git a/WinFormsLibrary/DropDownList.Designer.cs b/WinFormsLibrary/DropDownList.Designer.cs new file mode 100644 index 0000000..0337b6e --- /dev/null +++ b/WinFormsLibrary/DropDownList.Designer.cs @@ -0,0 +1,71 @@ +namespace WinFormsLibrary +{ + partial class DropDownList + { + /// + /// Обязательная переменная конструктора. + /// + 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.comboBox = new System.Windows.Forms.ComboBox(); + this.labelDropDownList = new System.Windows.Forms.Label(); + this.SuspendLayout(); + // + // comboBox + // + this.comboBox.FormattingEnabled = true; + this.comboBox.Location = new System.Drawing.Point(3, 60); + this.comboBox.Name = "comboBox"; + this.comboBox.Size = new System.Drawing.Size(182, 33); + this.comboBox.TabIndex = 0; + this.comboBox.SelectedIndexChanged += new System.EventHandler(this.comboBox_SelectedIndexChanged); + // + // labelDropDownList + // + this.labelDropDownList.AutoSize = true; + this.labelDropDownList.Location = new System.Drawing.Point(3, 12); + this.labelDropDownList.Name = "labelDropDownList"; + this.labelDropDownList.Size = new System.Drawing.Size(184, 25); + this.labelDropDownList.TabIndex = 1; + this.labelDropDownList.Text = "Выпадающий список"; + // + // DropDownList + // + this.AutoScaleDimensions = new System.Drawing.SizeF(10F, 25F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.Controls.Add(this.labelDropDownList); + this.Controls.Add(this.comboBox); + this.Name = "DropDownList"; + this.Size = new System.Drawing.Size(199, 105); + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private ComboBox comboBox; + private Label labelDropDownList; + } +} diff --git a/WinFormsLibrary/DropDownList.cs b/WinFormsLibrary/DropDownList.cs new file mode 100644 index 0000000..76f9b5e --- /dev/null +++ b/WinFormsLibrary/DropDownList.cs @@ -0,0 +1,60 @@ +namespace WinFormsLibrary +{ + public partial class DropDownList : UserControl + { + public DropDownList() + { + InitializeComponent(); + } + public void Clear() + { + comboBox.Items.Clear(); + } + public void LoadValues(List values) + { + if (values.Count == 0) + { + return; + } + comboBox.Items.AddRange(values.ToArray()); + } + + public string Selected + { + get + { + if(comboBox.Items.Count == 0) + { + return ""; + } + if(comboBox.SelectedItem == null) + { + return ""; + } + return comboBox.SelectedItem.ToString()!; + } + set + { + if (comboBox.Items.Contains(value)) + { + comboBox.SelectedItem = value; + } + } + } + public ComboBox.ObjectCollection comboBoxItems + { + get { return comboBox.Items; } + } + private EventHandler _onValueChanged; + public event EventHandler ValueChanged + { + add { _onValueChanged += value; } + remove { _onValueChanged -= value; } + } + + private void comboBox_SelectedIndexChanged(object sender, EventArgs e) + { + _onValueChanged?.Invoke(sender, e); + } + } + } diff --git a/WinFormsLibrary/DropDownList.resx b/WinFormsLibrary/DropDownList.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/WinFormsLibrary/DropDownList.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/WinFormsLibrary/EmailTextBox.Designer.cs b/WinFormsLibrary/EmailTextBox.Designer.cs new file mode 100644 index 0000000..4818796 --- /dev/null +++ b/WinFormsLibrary/EmailTextBox.Designer.cs @@ -0,0 +1,74 @@ +namespace WinFormsLibrary +{ + partial class EmailTextBox + { + /// + /// Обязательная переменная конструктора. + /// + 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.components = new System.ComponentModel.Container(); + this.textBoxEmail = new System.Windows.Forms.TextBox(); + this.toolTipEmail = new System.Windows.Forms.ToolTip(this.components); + this.labelEmail = new System.Windows.Forms.Label(); + this.SuspendLayout(); + // + // textBoxEmail + // + this.textBoxEmail.Location = new System.Drawing.Point(0, 55); + this.textBoxEmail.Name = "textBoxEmail"; + this.textBoxEmail.Size = new System.Drawing.Size(181, 31); + this.textBoxEmail.TabIndex = 0; + this.textBoxEmail.TextChanged += new System.EventHandler(this.textBoxEmail_TextChanged); + this.textBoxEmail.MouseEnter += new System.EventHandler(this.textBoxEmail_MouseEnter); + // + // labelEmail + // + this.labelEmail.AutoSize = true; + this.labelEmail.Location = new System.Drawing.Point(3, 6); + this.labelEmail.Name = "labelEmail"; + this.labelEmail.Size = new System.Drawing.Size(129, 25); + this.labelEmail.TabIndex = 1; + this.labelEmail.Text = "Введите почту"; + // + // EmailTextBox + // + this.AutoScaleDimensions = new System.Drawing.SizeF(10F, 25F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.Controls.Add(this.labelEmail); + this.Controls.Add(this.textBoxEmail); + this.Name = "EmailTextBox"; + this.Size = new System.Drawing.Size(209, 118); + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private TextBox textBoxEmail; + private ToolTip toolTipEmail; + private Label labelEmail; + } +} diff --git a/WinFormsLibrary/EmailTextBox.cs b/WinFormsLibrary/EmailTextBox.cs new file mode 100644 index 0000000..27ab39a --- /dev/null +++ b/WinFormsLibrary/EmailTextBox.cs @@ -0,0 +1,79 @@ +using System.Text.RegularExpressions; + +namespace WinFormsLibrary +{ + public partial class EmailTextBox : UserControl + { + public EmailTextBox() + { + InitializeComponent(); + } + private string _pattern; + private string example = "hello@mail.ru"; + private EventHandler _onValueChanged; + + public string Pattern + { + get { return _pattern; } + set { _pattern = value; } + } + 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; + } + + } + + public string TextBoxValue + { + get + { + Regex regex = new Regex(Pattern); + if (regex.IsMatch(textBoxEmail.Text)) + { + return textBoxEmail.Text; + } + else + { + Error = "Некорректный ввод"; + return null; + } + } + set + { + Regex regex = new Regex(Pattern); + if (regex.IsMatch(value)) + { + textBoxEmail.Text = value; + } + else + { + Error = "Некорректный ввод"; + } + } + } + private void textBoxEmail_MouseEnter(object sender, EventArgs e) + { + toolTipEmail.Show(example, textBoxEmail, 30, -20); + } + + public event EventHandler ValueChanged + { + add { _onValueChanged += value; } + remove { _onValueChanged -= value; } + } + + private void textBoxEmail_TextChanged(object sender, EventArgs e) + { + _onValueChanged?.Invoke(sender, e); + } + } +} \ No newline at end of file diff --git a/WinFormsLibrary/EmailTextBox.resx b/WinFormsLibrary/EmailTextBox.resx new file mode 100644 index 0000000..10c1bba --- /dev/null +++ b/WinFormsLibrary/EmailTextBox.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/WinFormsLibrary/ListBoxValues.Designer.cs b/WinFormsLibrary/ListBoxValues.Designer.cs new file mode 100644 index 0000000..cac5031 --- /dev/null +++ b/WinFormsLibrary/ListBoxValues.Designer.cs @@ -0,0 +1,59 @@ +namespace WinFormsLibrary +{ + partial class ListBoxValues + { + /// + /// Обязательная переменная конструктора. + /// + 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.listBoxObjects = new System.Windows.Forms.ListBox(); + this.SuspendLayout(); + // + // listBoxObjects + // + this.listBoxObjects.Dock = System.Windows.Forms.DockStyle.Fill; + this.listBoxObjects.FormattingEnabled = true; + this.listBoxObjects.ItemHeight = 25; + this.listBoxObjects.Location = new System.Drawing.Point(0, 0); + this.listBoxObjects.Name = "listBoxObjects"; + this.listBoxObjects.Size = new System.Drawing.Size(223, 158); + this.listBoxObjects.TabIndex = 0; + // + // ListBoxValues + // + this.AutoScaleDimensions = new System.Drawing.SizeF(10F, 25F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.Controls.Add(this.listBoxObjects); + this.Name = "ListBoxValues"; + this.Size = new System.Drawing.Size(223, 158); + this.ResumeLayout(false); + + } + + #endregion + + private ListBox listBoxObjects; + } +} diff --git a/WinFormsLibrary/ListBoxValues.cs b/WinFormsLibrary/ListBoxValues.cs new file mode 100644 index 0000000..3a8b438 --- /dev/null +++ b/WinFormsLibrary/ListBoxValues.cs @@ -0,0 +1,94 @@ +using System.Text; + + +namespace WinFormsLibrary +{ + public partial class ListBoxValues : UserControl + { + private string _layout; + private string _endSymbol; + private string _startSymbol; + public ListBoxValues() + { + InitializeComponent(); + } + public void SetLayout(string layout, string startSymbol, string endSymbol) + { + if (layout == null || startSymbol == null || endSymbol == null) + { + return; + } + _layout = layout; + _endSymbol = endSymbol; + _startSymbol = startSymbol; + } + public int SelectedIndex + { + get + { + if (listBoxObjects.SelectedIndex == -1) + { + return -1; + } + return listBoxObjects.SelectedIndex; + } + set + { + if (listBoxObjects.SelectedItems.Count != 0) + { + listBoxObjects.SelectedIndex = value; + } + } + } + public T GetObjectFromStr() where T : class, new() + { + string selectedString = ""; + if (listBoxObjects.SelectedIndex != -1) + { + selectedString = listBoxObjects.SelectedItem.ToString(); + } + T curObject = new T(); + foreach (var pr in typeof(T).GetProperties()) + { + if (!pr.CanWrite) + { + continue; + } + int borderOne = selectedString.IndexOf(_startSymbol); + StringBuilder sb = new StringBuilder(selectedString); + selectedString = sb.ToString(); + int borderTwo = selectedString.IndexOf(_endSymbol); + if (borderOne == -1 || borderTwo == -1) break; + string propertyValue = selectedString.Substring(borderOne + 1, borderTwo - borderOne-1); + selectedString = selectedString.Substring(borderTwo + 1); + pr.SetValue(curObject, Convert.ChangeType(propertyValue, pr.PropertyType)); + } + return curObject; + } + + public void AddInListBox(List values) + { + if (_layout == null || _startSymbol == null || _endSymbol == null) + { + MessageBox.Show("заполните информацию о макетной строке"); + return; + } + if (!_layout.Contains(_startSymbol) || !_layout.Contains(_endSymbol)) + { + MessageBox.Show("Макетная строка не содержит нужные элементы"); + return; + } + foreach (var item in values) + { + string str = _layout; + foreach (var prop in item.GetType().GetProperties()) + { + string str1 = $"{_startSymbol}" + $"{prop.Name}" + $"{_endSymbol}"; + str = str.Replace(str1, $"{_startSymbol}" + prop.GetValue(item).ToString() + $"{_endSymbol}"); + } + listBoxObjects.Items.Add(str); + } + } + + } +} diff --git a/WinFormsLibrary/ListBoxValues.resx b/WinFormsLibrary/ListBoxValues.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/WinFormsLibrary/ListBoxValues.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/WinFormsLibrary/Object/Client.cs b/WinFormsLibrary/Object/Client.cs new file mode 100644 index 0000000..4d16541 --- /dev/null +++ b/WinFormsLibrary/Object/Client.cs @@ -0,0 +1,22 @@ +namespace WinFormsLibrary.Object +{ + public class Client + { + public string FIO { get; set; } + public string Review { get; set; } + public string Status { get; set; } + public int Sum { get; set; } + + public Client(string fio, string review, string status, int sum) + { + FIO = fio; + Review = review; + Status = status; + Sum = sum; + } + public Client() + { + } + } + +} diff --git a/WinFormsLibrary/WinFormsLibrary.csproj b/WinFormsLibrary/WinFormsLibrary.csproj new file mode 100644 index 0000000..060aa1c --- /dev/null +++ b/WinFormsLibrary/WinFormsLibrary.csproj @@ -0,0 +1,10 @@ + + + + net6.0-windows + enable + true + enable + + +