надеюсь первая лаба все
This commit is contained in:
parent
6a5d109bba
commit
6999216c4a
@ -3,7 +3,9 @@ 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}") = "Components", "Components\Components.csproj", "{218522CC-CD60-403C-9B12-C683EEA06E32}"
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Components", "Components\Components.csproj", "{218522CC-CD60-403C-9B12-C683EEA06E32}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WinForms", "WinForms\WinForms.csproj", "{AFFC45E9-4318-4446-89E4-FEB441CD92F0}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
@ -15,6 +17,10 @@ Global
|
||||
{218522CC-CD60-403C-9B12-C683EEA06E32}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{218522CC-CD60-403C-9B12-C683EEA06E32}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{218522CC-CD60-403C-9B12-C683EEA06E32}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{AFFC45E9-4318-4446-89E4-FEB441CD92F0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{AFFC45E9-4318-4446-89E4-FEB441CD92F0}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{AFFC45E9-4318-4446-89E4-FEB441CD92F0}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{AFFC45E9-4318-4446-89E4-FEB441CD92F0}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
|
@ -33,15 +33,7 @@ namespace Components.Components
|
||||
{
|
||||
get
|
||||
{
|
||||
if (dropDownList.Items.Count == 0)
|
||||
{
|
||||
return "";
|
||||
}
|
||||
if (dropDownList.SelectedItem == null)
|
||||
{
|
||||
return "";
|
||||
}
|
||||
return dropDownList.SelectedItem.ToString();
|
||||
return dropDownList.SelectedItem?.ToString() ?? string.Empty;
|
||||
}
|
||||
set
|
||||
{
|
||||
|
@ -8,6 +8,7 @@ using System.Text;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Forms;
|
||||
using Components.Exceptions;
|
||||
|
||||
namespace Components.Components
|
||||
{
|
||||
@ -19,16 +20,32 @@ namespace Components.Components
|
||||
public UserEmailTextBox()
|
||||
{
|
||||
InitializeComponent();
|
||||
emailTextBox.Enter += textBox_Enter;
|
||||
emailTextBox.TextChanged += textBox_TextChanged;
|
||||
}
|
||||
|
||||
public string Pattern
|
||||
{
|
||||
get { return pattern; }
|
||||
set { pattern = value; }
|
||||
set
|
||||
{
|
||||
if (string.IsNullOrEmpty(value))
|
||||
{
|
||||
throw new NullPatternException("Шаблон не может быть нулевым или пустым");
|
||||
}
|
||||
pattern = value;
|
||||
}
|
||||
}
|
||||
|
||||
public string TextBoxValue
|
||||
{
|
||||
get
|
||||
{
|
||||
if (string.IsNullOrEmpty(Pattern))
|
||||
{
|
||||
throw new NullPatternException("Шаблон не задан");
|
||||
}
|
||||
|
||||
Regex rg = new Regex(Pattern);
|
||||
bool address = rg.IsMatch(emailTextBox.Text);
|
||||
if (address)
|
||||
@ -37,38 +54,49 @@ namespace Components.Components
|
||||
}
|
||||
else
|
||||
{
|
||||
Error = "Некорректный ввод";
|
||||
return null;
|
||||
throw new NotMatchPatternException("Введенный адрес электронной почты не соответствует шаблону.");
|
||||
}
|
||||
}
|
||||
set
|
||||
{
|
||||
if (string.IsNullOrEmpty(Pattern))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
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)
|
||||
|
||||
public void SetExample(string str)
|
||||
{
|
||||
if (string.IsNullOrEmpty(Pattern))
|
||||
{
|
||||
throw new NullPatternException("Pattern is not set.");
|
||||
}
|
||||
|
||||
Regex rg = new Regex(Pattern);
|
||||
bool address = rg.IsMatch(str);
|
||||
if (address)
|
||||
{
|
||||
example = str;
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
throw new NotMatchPatternException("The provided example does not match the pattern.");
|
||||
}
|
||||
}
|
||||
|
||||
private void textBox_Enter(object sender, EventArgs e)
|
||||
{
|
||||
int VisibleTime = 2000; //ms
|
||||
@ -94,5 +122,4 @@ namespace Components.Components
|
||||
onValueChanged?.Invoke(sender, e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -12,96 +12,87 @@ 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;
|
||||
}
|
||||
private string? _template;
|
||||
|
||||
private char? _fromChar;
|
||||
|
||||
private char? _toChar;
|
||||
|
||||
//свойство для получения и заполнения индекса выбранного элемента
|
||||
public int SelectedIndex
|
||||
{
|
||||
get
|
||||
{
|
||||
if (listBoxObj.SelectedIndex == -1)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
return listBoxObj.SelectedIndex;
|
||||
}
|
||||
set
|
||||
{
|
||||
if (listBoxObj.SelectedItems.Count != 0)
|
||||
{
|
||||
listBoxObj.SelectedIndex = value;
|
||||
}
|
||||
listBoxObj.SelectedIndex = value;
|
||||
}
|
||||
}
|
||||
public UserListBoxObject()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
public void SetParams(string template, char fromChar, char toChar)
|
||||
{
|
||||
_template = template;
|
||||
_fromChar = fromChar;
|
||||
_toChar = toChar;
|
||||
}
|
||||
|
||||
//Публичный параметризованный метод для получения объекта из выбранной строки(создать объект и через рефлексию заполнить свойства его).
|
||||
public T GetObjectFromStr<T>() where T : class, new()
|
||||
public T? GetObject<T>()
|
||||
{
|
||||
string selStr = "";
|
||||
if (listBoxObj.SelectedIndex != -1)
|
||||
if (listBoxObj.SelectedIndex == -1 || string.IsNullOrEmpty(_template) || !_fromChar.HasValue || !_toChar.HasValue)
|
||||
throw new ArgumentException("Не хватает данных");
|
||||
|
||||
var type = typeof(T);
|
||||
var properties = type.GetProperties();
|
||||
var curObject = Activator.CreateInstance(type);
|
||||
|
||||
string[] wordsTemplate = _template.Split(' ');
|
||||
string[] words = listBoxObj.SelectedItem.ToString().Split(' ');
|
||||
|
||||
for (int i = 0; i < wordsTemplate.Length; i++)
|
||||
{
|
||||
selStr = listBoxObj.SelectedItem.ToString();
|
||||
}
|
||||
T curObject = new T();
|
||||
foreach (var pr in typeof(T).GetProperties())
|
||||
{
|
||||
if (!pr.CanWrite)
|
||||
string word = wordsTemplate[i];
|
||||
if (word.Contains(_fromChar.Value) && word.Contains(_toChar.Value))
|
||||
{
|
||||
continue;
|
||||
int startCharIndex = word.IndexOf(_fromChar.Value);
|
||||
int endCharIndex = word.LastIndexOf(_toChar.Value);
|
||||
|
||||
string propertyName = word.Substring(startCharIndex + 1, endCharIndex - startCharIndex - 1);
|
||||
var property = properties.FirstOrDefault(x => x.Name == propertyName);
|
||||
if (property == null)
|
||||
continue;
|
||||
|
||||
int extraCharsBefore = startCharIndex;
|
||||
int extraCharsAfter = word.Length - endCharIndex - 1;
|
||||
|
||||
string propertyValue = words[i].Substring(extraCharsBefore,
|
||||
words[i].Length - extraCharsBefore - extraCharsAfter);
|
||||
property.SetValue(curObject, Convert.ChangeType(propertyValue, property.PropertyType));
|
||||
}
|
||||
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;
|
||||
return (T?)curObject;
|
||||
}
|
||||
//параметризованный метод, у которого в передаваемых параметрах идет список объектов некого класса и через этот список идет заполнение ListBox;
|
||||
public void AddInListBox<T>(List<T> objects)
|
||||
|
||||
public void AddItems<T>(List<T> items)
|
||||
where T : class
|
||||
{
|
||||
if (layoutString == null || startSymbol == null || endSymbol == null)
|
||||
if (string.IsNullOrEmpty(_template) || !_fromChar.HasValue || !_toChar.HasValue)
|
||||
throw new ArgumentException("Не хватает данных");
|
||||
listBoxObj.Items.Clear();
|
||||
var type = typeof(T);
|
||||
var properties = type.GetProperties();
|
||||
foreach (T item in items)
|
||||
{
|
||||
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 result = _template;
|
||||
foreach (var property in properties)
|
||||
{
|
||||
string str1 = $"{startSymbol}" + $"{prop.Name}" + $"{endSymbol}";
|
||||
str = str.Replace(str1, $"{startSymbol}" + prop.GetValue(item).ToString() + $"{endSymbol}");
|
||||
string search = _fromChar.Value + property.Name + _toChar.Value;
|
||||
result = result.Replace(search, property.GetValue(item)?.ToString() ?? "");
|
||||
}
|
||||
listBoxObj.Items.Add(str);
|
||||
listBoxObj.Items.Add(result);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
21
COP/Components/Exceptions/NotMatchPatternException.cs
Normal file
21
COP/Components/Exceptions/NotMatchPatternException.cs
Normal file
@ -0,0 +1,21 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Runtime.Serialization;
|
||||
|
||||
namespace Components.Exceptions
|
||||
{
|
||||
[Serializable]
|
||||
public class NotMatchPatternException : ApplicationException
|
||||
{
|
||||
public NotMatchPatternException() : base() { }
|
||||
|
||||
public NotMatchPatternException(string message) : base(message) { }
|
||||
|
||||
public NotMatchPatternException(string message, Exception exception) : base(message, exception) { }
|
||||
|
||||
protected NotMatchPatternException(SerializationInfo info, StreamingContext contex) : base(info, contex) { }
|
||||
}
|
||||
}
|
21
COP/Components/Exceptions/NullPatternException.cs
Normal file
21
COP/Components/Exceptions/NullPatternException.cs
Normal file
@ -0,0 +1,21 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Runtime.Serialization;
|
||||
|
||||
namespace Components.Exceptions
|
||||
{
|
||||
[Serializable]
|
||||
public class NullPatternException : ApplicationException
|
||||
{
|
||||
public NullPatternException() : base() { }
|
||||
|
||||
public NullPatternException(string message) : base(message) { }
|
||||
|
||||
public NullPatternException(string message, Exception exception) : base(message, exception) { }
|
||||
|
||||
protected NullPatternException(SerializationInfo info, StreamingContext contex) : base(info, contex) { }
|
||||
}
|
||||
}
|
228
COP/WinForms/FormForComponents.Designer.cs
generated
Normal file
228
COP/WinForms/FormForComponents.Designer.cs
generated
Normal file
@ -0,0 +1,228 @@
|
||||
namespace WinForms
|
||||
{
|
||||
partial class FormForComponents
|
||||
{
|
||||
/// <summary>
|
||||
/// Required designer variable.
|
||||
/// </summary>
|
||||
private System.ComponentModel.IContainer components = null;
|
||||
|
||||
/// <summary>
|
||||
/// Clean up any resources being used.
|
||||
/// </summary>
|
||||
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing && (components != null))
|
||||
{
|
||||
components.Dispose();
|
||||
}
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
|
||||
#region Windows Form Designer generated code
|
||||
|
||||
/// <summary>
|
||||
/// Required method for Designer support - do not modify
|
||||
/// the contents of this method with the code editor.
|
||||
/// </summary>
|
||||
private void InitializeComponent()
|
||||
{
|
||||
this.dropDownList = new Components.Components.UserDropDownList();
|
||||
this.buttonAdd = new System.Windows.Forms.Button();
|
||||
this.buttonInfo = new System.Windows.Forms.Button();
|
||||
this.labelInfo = new System.Windows.Forms.Label();
|
||||
this.buttonClear = new System.Windows.Forms.Button();
|
||||
this.emailTextBox = new Components.Components.UserEmailTextBox();
|
||||
this.labelShow = new System.Windows.Forms.Label();
|
||||
this.buttonShow = new System.Windows.Forms.Button();
|
||||
this.buttonSetExample = new System.Windows.Forms.Button();
|
||||
this.labelExample = new System.Windows.Forms.Label();
|
||||
this.textBoxExample = new System.Windows.Forms.TextBox();
|
||||
this.listBoxObj = new Components.Components.UserListBoxObject();
|
||||
this.buttonAddObjects = 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(3, 3);
|
||||
this.dropDownList.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
|
||||
this.dropDownList.Name = "dropDownList";
|
||||
this.dropDownList.SelectedValue = "";
|
||||
this.dropDownList.Size = new System.Drawing.Size(196, 36);
|
||||
this.dropDownList.TabIndex = 0;
|
||||
//
|
||||
// buttonAdd
|
||||
//
|
||||
this.buttonAdd.Location = new System.Drawing.Point(3, 46);
|
||||
this.buttonAdd.Name = "buttonAdd";
|
||||
this.buttonAdd.Size = new System.Drawing.Size(92, 29);
|
||||
this.buttonAdd.TabIndex = 1;
|
||||
this.buttonAdd.Text = "добавить";
|
||||
this.buttonAdd.UseVisualStyleBackColor = true;
|
||||
this.buttonAdd.Click += new System.EventHandler(this.buttonAdd_Click);
|
||||
//
|
||||
// buttonInfo
|
||||
//
|
||||
this.buttonInfo.Location = new System.Drawing.Point(211, 46);
|
||||
this.buttonInfo.Name = "buttonInfo";
|
||||
this.buttonInfo.Size = new System.Drawing.Size(94, 29);
|
||||
this.buttonInfo.TabIndex = 2;
|
||||
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(205, 9);
|
||||
this.labelInfo.Name = "labelInfo";
|
||||
this.labelInfo.Size = new System.Drawing.Size(154, 20);
|
||||
this.labelInfo.TabIndex = 3;
|
||||
this.labelInfo.Text = "Выбранный элемент";
|
||||
//
|
||||
// buttonClear
|
||||
//
|
||||
this.buttonClear.Location = new System.Drawing.Point(101, 46);
|
||||
this.buttonClear.Name = "buttonClear";
|
||||
this.buttonClear.Size = new System.Drawing.Size(94, 29);
|
||||
this.buttonClear.TabIndex = 4;
|
||||
this.buttonClear.Text = "очистить";
|
||||
this.buttonClear.UseVisualStyleBackColor = true;
|
||||
this.buttonClear.Click += new System.EventHandler(this.buttonClear_Click);
|
||||
//
|
||||
// emailTextBox
|
||||
//
|
||||
this.emailTextBox.Location = new System.Drawing.Point(12, 132);
|
||||
this.emailTextBox.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
|
||||
this.emailTextBox.Name = "emailTextBox";
|
||||
this.emailTextBox.Pattern = null;
|
||||
this.emailTextBox.Size = new System.Drawing.Size(179, 34);
|
||||
this.emailTextBox.TabIndex = 5;
|
||||
//
|
||||
// labelShow
|
||||
//
|
||||
this.labelShow.AutoSize = true;
|
||||
this.labelShow.Location = new System.Drawing.Point(12, 170);
|
||||
this.labelShow.Name = "labelShow";
|
||||
this.labelShow.Size = new System.Drawing.Size(76, 20);
|
||||
this.labelShow.TabIndex = 10;
|
||||
this.labelShow.Text = "проверка";
|
||||
//
|
||||
// buttonShow
|
||||
//
|
||||
this.buttonShow.Location = new System.Drawing.Point(12, 196);
|
||||
this.buttonShow.Name = "buttonShow";
|
||||
this.buttonShow.Size = new System.Drawing.Size(94, 29);
|
||||
this.buttonShow.TabIndex = 9;
|
||||
this.buttonShow.Text = "Проверка";
|
||||
this.buttonShow.UseVisualStyleBackColor = true;
|
||||
//
|
||||
// buttonSetExample
|
||||
//
|
||||
this.buttonSetExample.Location = new System.Drawing.Point(12, 328);
|
||||
this.buttonSetExample.Name = "buttonSetExample";
|
||||
this.buttonSetExample.Size = new System.Drawing.Size(188, 29);
|
||||
this.buttonSetExample.TabIndex = 8;
|
||||
this.buttonSetExample.Text = "Поменять пример";
|
||||
this.buttonSetExample.UseVisualStyleBackColor = true;
|
||||
//
|
||||
// labelExample
|
||||
//
|
||||
this.labelExample.AutoSize = true;
|
||||
this.labelExample.Location = new System.Drawing.Point(12, 263);
|
||||
this.labelExample.Name = "labelExample";
|
||||
this.labelExample.Size = new System.Drawing.Size(147, 20);
|
||||
this.labelExample.TabIndex = 7;
|
||||
this.labelExample.Text = "Для ввода примера";
|
||||
//
|
||||
// textBoxExample
|
||||
//
|
||||
this.textBoxExample.Location = new System.Drawing.Point(12, 295);
|
||||
this.textBoxExample.Name = "textBoxExample";
|
||||
this.textBoxExample.Size = new System.Drawing.Size(188, 27);
|
||||
this.textBoxExample.TabIndex = 6;
|
||||
//
|
||||
// listBoxObj
|
||||
//
|
||||
this.listBoxObj.Location = new System.Drawing.Point(388, 13);
|
||||
this.listBoxObj.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
|
||||
this.listBoxObj.Name = "listBoxObj";
|
||||
this.listBoxObj.SelectedIndex = -1;
|
||||
this.listBoxObj.Size = new System.Drawing.Size(368, 159);
|
||||
this.listBoxObj.TabIndex = 11;
|
||||
//
|
||||
// buttonAddObjects
|
||||
//
|
||||
this.buttonAddObjects.Location = new System.Drawing.Point(388, 179);
|
||||
this.buttonAddObjects.Name = "buttonAddObjects";
|
||||
this.buttonAddObjects.Size = new System.Drawing.Size(380, 29);
|
||||
this.buttonAddObjects.TabIndex = 12;
|
||||
this.buttonAddObjects.Text = "Добавить";
|
||||
this.buttonAddObjects.UseVisualStyleBackColor = true;
|
||||
//
|
||||
// buttonShowItem
|
||||
//
|
||||
this.buttonShowItem.Location = new System.Drawing.Point(388, 310);
|
||||
this.buttonShowItem.Name = "buttonShowItem";
|
||||
this.buttonShowItem.Size = new System.Drawing.Size(380, 29);
|
||||
this.buttonShowItem.TabIndex = 13;
|
||||
this.buttonShowItem.Text = "Получить";
|
||||
this.buttonShowItem.UseVisualStyleBackColor = true;
|
||||
//
|
||||
// labelShowInput
|
||||
//
|
||||
this.labelShowInput.AutoSize = true;
|
||||
this.labelShowInput.Location = new System.Drawing.Point(388, 273);
|
||||
this.labelShowInput.Name = "labelShowInput";
|
||||
this.labelShowInput.Size = new System.Drawing.Size(54, 20);
|
||||
this.labelShowInput.TabIndex = 14;
|
||||
this.labelShowInput.Text = "Вывод";
|
||||
//
|
||||
// FormForComponents
|
||||
//
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F);
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||
this.ClientSize = new System.Drawing.Size(800, 450);
|
||||
this.Controls.Add(this.dropDownList);
|
||||
this.Controls.Add(this.buttonAdd);
|
||||
this.Controls.Add(this.buttonInfo);
|
||||
this.Controls.Add(this.labelInfo);
|
||||
this.Controls.Add(this.buttonClear);
|
||||
this.Controls.Add(this.emailTextBox);
|
||||
this.Controls.Add(this.textBoxExample);
|
||||
this.Controls.Add(this.labelExample);
|
||||
this.Controls.Add(this.buttonSetExample);
|
||||
this.Controls.Add(this.labelShow);
|
||||
this.Controls.Add(this.buttonShow);
|
||||
this.Controls.Add(this.listBoxObj);
|
||||
this.Controls.Add(this.buttonAddObjects);
|
||||
this.Controls.Add(this.buttonShowItem);
|
||||
this.Controls.Add(this.labelShowInput);
|
||||
this.Name = "FormForComponents";
|
||||
this.Text = "FormForComponents";
|
||||
this.ResumeLayout(false);
|
||||
this.PerformLayout();
|
||||
|
||||
}
|
||||
|
||||
#endregion
|
||||
private Components.Components.UserDropDownList dropDownList;
|
||||
private Button buttonAdd;
|
||||
private Button buttonInfo;
|
||||
private Label labelInfo;
|
||||
private Button buttonClear;
|
||||
private Components.Components.UserEmailTextBox emailTextBox;
|
||||
private TextBox textBoxExample;
|
||||
private Label labelExample;
|
||||
private Button buttonSetExample;
|
||||
private Label labelShow;
|
||||
private Button buttonShow;
|
||||
private Components.Components.UserListBoxObject listBoxObj;
|
||||
private Button buttonAddObjects;
|
||||
private Button buttonShowItem;
|
||||
private Label labelShowInput;
|
||||
}
|
||||
}
|
73
COP/WinForms/FormForComponents.cs
Normal file
73
COP/WinForms/FormForComponents.cs
Normal file
@ -0,0 +1,73 @@
|
||||
using Components.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;
|
||||
|
||||
namespace WinForms
|
||||
{
|
||||
public partial class FormForComponents : Form
|
||||
{
|
||||
List<string> list = new List<string>();
|
||||
List<Worker> students = new List<Worker>();
|
||||
public FormForComponents()
|
||||
{
|
||||
InitializeComponent();
|
||||
list = new List<string>();
|
||||
list.AddRange(new string[] { "слон", "волк", "кролик" });
|
||||
listBoxObj.SetParams("Имя: {FirstName}, Фамилия: {LastName}. {Experience} ({Age}) лет.", '{', '}');
|
||||
listBoxObj.AddItems(new List<Worker> { new() { Name = "Иван", LastName = "Иванов", Age = 23, Experience = 5 },
|
||||
new() { Name = "Егор", LastName = "Булаткин", Age = 30, Experience = 10 },
|
||||
new() { Name = "Арбуз", LastName = "Арбуз", Age = 40, Experience = 7 } });
|
||||
dropDownList.LoadValues(new List<string>() { "котенок", "собачка", "лиса" });
|
||||
emailTextBox.Pattern = @"^([\w\.\-]+)@([\w\-]+)((\.(\w){2,3})+)$";
|
||||
}
|
||||
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.SelectedValue;
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
labelShow.Text = "подходит";
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
MessageBox.Show(ex.Message);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
60
COP/WinForms/FormForComponents.resx
Normal file
60
COP/WinForms/FormForComponents.resx
Normal file
@ -0,0 +1,60 @@
|
||||
<root>
|
||||
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
|
||||
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
|
||||
<xsd:element name="root" msdata:IsDataSet="true">
|
||||
<xsd:complexType>
|
||||
<xsd:choice maxOccurs="unbounded">
|
||||
<xsd:element name="metadata">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" use="required" type="xsd:string" />
|
||||
<xsd:attribute name="type" type="xsd:string" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="assembly">
|
||||
<xsd:complexType>
|
||||
<xsd:attribute name="alias" type="xsd:string" />
|
||||
<xsd:attribute name="name" type="xsd:string" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="data">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
|
||||
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="resheader">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:choice>
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:schema>
|
||||
<resheader name="resmimetype">
|
||||
<value>text/microsoft-resx</value>
|
||||
</resheader>
|
||||
<resheader name="version">
|
||||
<value>2.0</value>
|
||||
</resheader>
|
||||
<resheader name="reader">
|
||||
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<resheader name="writer">
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
</root>
|
17
COP/WinForms/Program.cs
Normal file
17
COP/WinForms/Program.cs
Normal file
@ -0,0 +1,17 @@
|
||||
namespace WinForms
|
||||
{
|
||||
internal static class Program
|
||||
{
|
||||
/// <summary>
|
||||
/// The main entry point for the application.
|
||||
/// </summary>
|
||||
[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 FormForComponents());
|
||||
}
|
||||
}
|
||||
}
|
15
COP/WinForms/WinForms.csproj
Normal file
15
COP/WinForms/WinForms.csproj
Normal file
@ -0,0 +1,15 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>WinExe</OutputType>
|
||||
<TargetFramework>net6.0-windows</TargetFramework>
|
||||
<Nullable>enable</Nullable>
|
||||
<UseWindowsForms>true</UseWindowsForms>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Components\Components.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
19
COP/WinForms/Worker.cs
Normal file
19
COP/WinForms/Worker.cs
Normal file
@ -0,0 +1,19 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace WinForms
|
||||
{
|
||||
public class Worker
|
||||
{
|
||||
public string Name { get; set; } = string.Empty;
|
||||
|
||||
public string LastName { get; set; } = string.Empty;
|
||||
|
||||
public int Age { get; set; }
|
||||
|
||||
public int Experience { get; set; }
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user