diff --git a/COP.sln b/COP.sln index 2818cf1..05eefb0 100644 --- a/COP.sln +++ b/COP.sln @@ -3,7 +3,9 @@ Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio Version 17 VisualStudioVersion = 17.9.34723.18 MinimumVisualStudioVersion = 10.0.40219.1 -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "COP", "COP\COP.csproj", "{D1C9120F-690B-4C6A-B860-5D3979390A5C}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Forms", "Forms\Forms.csproj", "{E466851D-D186-4EE0-BE53-C4FE4569F0DE}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Controls", "Controls\Controls.csproj", "{609671BA-C1E8-489E-A203-54DE4799BD66}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -11,10 +13,14 @@ Global Release|Any CPU = Release|Any CPU EndGlobalSection GlobalSection(ProjectConfigurationPlatforms) = postSolution - {D1C9120F-690B-4C6A-B860-5D3979390A5C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {D1C9120F-690B-4C6A-B860-5D3979390A5C}.Debug|Any CPU.Build.0 = Debug|Any CPU - {D1C9120F-690B-4C6A-B860-5D3979390A5C}.Release|Any CPU.ActiveCfg = Release|Any CPU - {D1C9120F-690B-4C6A-B860-5D3979390A5C}.Release|Any CPU.Build.0 = Release|Any CPU + {E466851D-D186-4EE0-BE53-C4FE4569F0DE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {E466851D-D186-4EE0-BE53-C4FE4569F0DE}.Debug|Any CPU.Build.0 = Debug|Any CPU + {E466851D-D186-4EE0-BE53-C4FE4569F0DE}.Release|Any CPU.ActiveCfg = Release|Any CPU + {E466851D-D186-4EE0-BE53-C4FE4569F0DE}.Release|Any CPU.Build.0 = Release|Any CPU + {609671BA-C1E8-489E-A203-54DE4799BD66}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {609671BA-C1E8-489E-A203-54DE4799BD66}.Debug|Any CPU.Build.0 = Debug|Any CPU + {609671BA-C1E8-489E-A203-54DE4799BD66}.Release|Any CPU.ActiveCfg = Release|Any CPU + {609671BA-C1E8-489E-A203-54DE4799BD66}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/COP/Class1.cs b/COP/Class1.cs deleted file mode 100644 index e14ff36..0000000 --- a/COP/Class1.cs +++ /dev/null @@ -1,7 +0,0 @@ -namespace COP -{ - public class Class1 - { - - } -} diff --git a/COP/COP.csproj b/Controls/Controls.csproj similarity index 62% rename from COP/COP.csproj rename to Controls/Controls.csproj index fa71b7a..3e210aa 100644 --- a/COP/COP.csproj +++ b/Controls/Controls.csproj @@ -1,9 +1,10 @@  - net8.0 - enable + net8.0-windows enable + true + enable diff --git a/Controls/CustomComboBox.Designer.cs b/Controls/CustomComboBox.Designer.cs new file mode 100644 index 0000000..065e766 --- /dev/null +++ b/Controls/CustomComboBox.Designer.cs @@ -0,0 +1,56 @@ +namespace Controls +{ + partial class CustomComboBox + { + /// + /// Обязательная переменная конструктора. + /// + 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() + { + comboBoxMain = new ComboBox(); + SuspendLayout(); + // + // comboBoxMain + // + comboBoxMain.FormattingEnabled = true; + comboBoxMain.Location = new Point(18, 62); + comboBoxMain.Name = "comboBoxMain"; + comboBoxMain.Size = new Size(230, 28); + comboBoxMain.TabIndex = 0; + // + // CustomComboBox + // + AutoScaleDimensions = new SizeF(8F, 20F); + AutoScaleMode = AutoScaleMode.Font; + Controls.Add(comboBoxMain); + Name = "CustomComboBox"; + Size = new Size(262, 150); + ResumeLayout(false); + } + + #endregion + + private ComboBox comboBoxMain; + } +} diff --git a/Controls/CustomComboBox.cs b/Controls/CustomComboBox.cs new file mode 100644 index 0000000..a19823e --- /dev/null +++ b/Controls/CustomComboBox.cs @@ -0,0 +1,95 @@ +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 Controls +{ + public partial class CustomComboBox : UserControl + { + /// + /// Конструктор + /// + public CustomComboBox() + { + InitializeComponent(); + } + + /// + /// Очищение списка + /// + public void ComboBoxClear() + { + comboBoxMain.Items.Clear(); + comboBoxMain.SelectedItem = null; + } + + /// + /// Выбранный элемент + /// + public string SelectedItem + { + get + { + if (comboBoxMain.Items.Count == 0) + { + return " "; + } + if (comboBoxMain.SelectedItem == null) + { + return " "; + } + return comboBoxMain.SelectedItem.ToString()!; + } + set + { + if (comboBoxMain.Items.Contains(value)) + { + comboBoxMain.SelectedItem = value; + } + + } + } + + /// + /// Публичное свойство + /// + public ComboBox.ObjectCollection ComboBoxItems + { + get { return comboBoxMain.Items; } + } + + /// + /// Событие, вызываемое при смене значения + /// + private EventHandler _onValueChangedEvent; + + /// + /// Событие, вызываемое при смене значения + /// + public event EventHandler ValueChanged + { + add + { + _onValueChangedEvent += value; + } + + remove + { + _onValueChangedEvent -= value; + } + } + /// + /// Смена значения + /// + private void CustomComboBox_SelectedValueChanged(object sender, EventArgs e) + { + _onValueChangedEvent?.Invoke(sender, e); + } + } +} diff --git a/Controls/CustomComboBox.resx b/Controls/CustomComboBox.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/Controls/CustomComboBox.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 diff --git a/Controls/CustomListBox.Designer.cs b/Controls/CustomListBox.Designer.cs new file mode 100644 index 0000000..96e16aa --- /dev/null +++ b/Controls/CustomListBox.Designer.cs @@ -0,0 +1,58 @@ +namespace Controls +{ + partial class CustomListBox + { + /// + /// Обязательная переменная конструктора. + /// + 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() + { + listBoxMain = new ListBox(); + SuspendLayout(); + // + // listBoxMain + // + listBoxMain.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right; + listBoxMain.FormattingEnabled = true; + listBoxMain.ItemHeight = 20; + listBoxMain.Location = new Point(3, 3); + listBoxMain.Name = "listBoxMain"; + listBoxMain.Size = new Size(270, 184); + listBoxMain.TabIndex = 0; + // + // CustomListBox + // + AutoScaleDimensions = new SizeF(8F, 20F); + AutoScaleMode = AutoScaleMode.Font; + Controls.Add(listBoxMain); + Name = "CustomListBox"; + Size = new Size(276, 212); + ResumeLayout(false); + } + + #endregion + + private ListBox listBoxMain; + } +} diff --git a/Controls/CustomListBox.cs b/Controls/CustomListBox.cs new file mode 100644 index 0000000..3da3c13 --- /dev/null +++ b/Controls/CustomListBox.cs @@ -0,0 +1,132 @@ +using Controls.Exceptions; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Reflection; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace Controls +{ + public partial class CustomListBox : UserControl + { + /// + /// Конструктор по умолчанию + /// + public CustomListBox() + { + InitializeComponent(); + } + + /// + /// Макет + /// + private string _templateString; + + /// + /// Символ начала + /// + private string _startSymbol; + + /// + /// Символ конца + /// + private string _endSymbol; + + /// + /// Шаблон строки + /// + public void SetTemplateString(string templateString, string startSymbol, string endSymbol) + { + if (templateString != "" && startSymbol != "" && endSymbol != "") + { + _templateString = templateString; + _startSymbol = startSymbol; + _endSymbol = endSymbol; + } + else + { + throw new ArgumentNullException("Вы не ввели все значения"); + } + } + + /// + /// Выбранная строка + /// + public int SelectedIndex + { + get { return listBoxMain.SelectedIndex; } + set + { + if (listBoxMain.SelectedIndex != 0) + { + listBoxMain.SelectedIndex = value; + } + } + } + + /// + /// Получение обхекта + /// + public T GetObjectFromStr() where T : class, new() + { + if (listBoxMain.SelectedIndex == -1) + { + return null; + } + string row = listBoxMain.SelectedItem.ToString(); + T curObject = new T(); + StringBuilder sb = new StringBuilder(row); + foreach (var property in typeof(T).GetProperties()) + { + if (!property.CanWrite) + { + continue; + } + + int borderOne = sb.ToString().IndexOf(_startSymbol); + if (borderOne == -1) + { + break; + } + + int borderTwo = sb.ToString().IndexOf(_endSymbol, borderOne + 1); + if (borderTwo == -1) + { + break; + } + + string propertyValue = sb.ToString(borderOne + 1, borderTwo - borderOne - 1); + sb.Remove(0, borderTwo + 1); + property.SetValue(curObject, Convert.ChangeType(propertyValue, property.PropertyType)); + } + return curObject; + } + + /// + /// Заполнение + /// + public void FillProperty(T dataObject, int rowIndex, string propertyName) + { + + while (listBoxMain.Items.Count <= rowIndex) + { + listBoxMain.Items.Add(_templateString); + } + + string row = listBoxMain.Items[rowIndex].ToString(); + PropertyInfo propertyInfo = dataObject.GetType().GetProperty(propertyName); + + if (propertyInfo != null) + { + object propertyValue = propertyInfo.GetValue(dataObject); + row = row.Replace($"{_startSymbol}{propertyName}{_endSymbol}", propertyValue.ToString()); + listBoxMain.Items[rowIndex] = row; + } + } + } +} diff --git a/Controls/CustomListBox.resx b/Controls/CustomListBox.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/Controls/CustomListBox.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 diff --git a/Controls/CustomTextBoxNumber.Designer.cs b/Controls/CustomTextBoxNumber.Designer.cs new file mode 100644 index 0000000..b46ed44 --- /dev/null +++ b/Controls/CustomTextBoxNumber.Designer.cs @@ -0,0 +1,62 @@ +namespace Controls +{ + partial class CustomTextBoxNumber + { + /// + /// Обязательная переменная конструктора. + /// + 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() + { + components = new System.ComponentModel.Container(); + textBoxNumber = new TextBox(); + toolTipNumber = new ToolTip(components); + SuspendLayout(); + // + // textBoxNumber + // + textBoxNumber.Location = new Point(25, 61); + textBoxNumber.Name = "textBoxNumber"; + textBoxNumber.Size = new Size(213, 27); + textBoxNumber.TabIndex = 0; + toolTipNumber.SetToolTip(textBoxNumber, "+79378811555"); + textBoxNumber.Click += textBox_Enter; + textBoxNumber.Text = "+79991144333"; + // + // CustomNumberBox + // + AutoScaleDimensions = new SizeF(8F, 20F); + AutoScaleMode = AutoScaleMode.Font; + Controls.Add(textBoxNumber); + Name = "CustomNumberBox"; + Size = new Size(264, 150); + ResumeLayout(false); + PerformLayout(); + } + + #endregion + + private TextBox textBoxNumber; + private ToolTip toolTipNumber; + } +} diff --git a/Controls/CustomTextBoxNumber.cs b/Controls/CustomTextBoxNumber.cs new file mode 100644 index 0000000..9de52d5 --- /dev/null +++ b/Controls/CustomTextBoxNumber.cs @@ -0,0 +1,111 @@ +using Controls.Exceptions; +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 Controls +{ + public partial class CustomTextBoxNumber : UserControl + { + /// + /// Конструктор + /// + public CustomTextBoxNumber() + { + InitializeComponent(); + } + + /// + /// Шаблон вводимого значения + /// + private string? _numberPattern; + + /// + /// Шаблон вводимого значения + /// + public string? NumPattern + { + get { return _numberPattern; } + set { _numberPattern = value; } + } + + /// + /// Введенное значение + /// + public string? TextBoxNumber + { + get + { + if (NumPattern == null) + { + throw new CustomNumberException("Шаблон не заполнен!"); + } + + Regex regex = new Regex(NumPattern); + if (regex.IsMatch(textBoxNumber.Text)) + { + return textBoxNumber.Text; + } + else + { + throw new CustomNumberException(textBoxNumber.Text + " не соответствует шаблону!"); + } + } + + set + { + Regex regex = new Regex(NumPattern!); + if (regex.IsMatch(value)) + { + textBoxNumber.Text = value; + } + + } + } + + /// + /// Событие, вызываемое при смене значения + /// + private EventHandler _onValueChangedEvent; + + /// + /// Событие, вызываемое при смене значения + /// + public event EventHandler ValueChanged + { + add + { + _onValueChangedEvent += value; + } + + remove + { + _onValueChangedEvent -= value; + } + } + /// + /// Смена значения + /// + private void CustomNumberBox_NumberChanged(object sender, EventArgs e) + { + _onValueChangedEvent?.Invoke(sender, e); + } + + /// + /// Выведение подсказки на экран + /// + private void textBox_Enter(object sender, EventArgs e) + { + int visibleTime = 2000; + ToolTip tooltip = new ToolTip(); + tooltip.Show("+79991144333", textBoxNumber, 30, -20, visibleTime); + } + } +} diff --git a/Controls/CustomTextBoxNumber.resx b/Controls/CustomTextBoxNumber.resx new file mode 100644 index 0000000..61a1145 --- /dev/null +++ b/Controls/CustomTextBoxNumber.resx @@ -0,0 +1,123 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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/Controls/Exceptions/CustomNumberException.cs b/Controls/Exceptions/CustomNumberException.cs new file mode 100644 index 0000000..63ce6b6 --- /dev/null +++ b/Controls/Exceptions/CustomNumberException.cs @@ -0,0 +1,23 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Controls.Exceptions +{ + public class CustomNumberException : Exception + { + /// + /// Конструктор по умолчанию + /// + public CustomNumberException() { } + + /// + /// Конструктор с сообщением ошибки + /// + public CustomNumberException(string message) : base(message) + { + } + } +} diff --git a/Forms/Department.cs b/Forms/Department.cs new file mode 100644 index 0000000..c6c8c34 --- /dev/null +++ b/Forms/Department.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Forms +{ + public class Department + { + public string Name { get; set; } + public string Code { get; set; } + public string Number { get; set; } + } +} diff --git a/Forms/FormMain.Designer.cs b/Forms/FormMain.Designer.cs new file mode 100644 index 0000000..c464767 --- /dev/null +++ b/Forms/FormMain.Designer.cs @@ -0,0 +1,162 @@ +namespace Forms +{ + partial class FormMain + { + /// + /// 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() + { + components = new System.ComponentModel.Container(); + customTextBoxNumber = new Controls.CustomTextBoxNumber(); + customComboBox = new Controls.CustomComboBox(); + labelNum = new Label(); + labelCombo = new Label(); + labelList = new Label(); + customListBox = new Controls.CustomListBox(); + buttonValidate = new Button(); + buttonGetBro = new Button(); + toolTip = new ToolTip(components); + button1 = new Button(); + SuspendLayout(); + // + // customTextBoxNumber + // + customTextBoxNumber.Location = new Point(2, 187); + customTextBoxNumber.Name = "customTextBoxNumber"; + customTextBoxNumber.NumPattern = null; + customTextBoxNumber.Size = new Size(261, 105); + customTextBoxNumber.TabIndex = 0; + // + // customComboBox + // + customComboBox.Location = new Point(2, 19); + customComboBox.Name = "customComboBox"; + customComboBox.SelectedItem = " "; + customComboBox.Size = new Size(301, 188); + customComboBox.TabIndex = 1; + // + // labelNum + // + labelNum.AutoSize = true; + labelNum.Location = new Point(68, 187); + labelNum.Name = "labelNum"; + labelNum.Size = new Size(130, 20); + labelNum.TabIndex = 2; + labelNum.Text = "Номер телефона:"; + // + // labelCombo + // + labelCombo.AutoSize = true; + labelCombo.Location = new Point(88, 42); + labelCombo.Name = "labelCombo"; + labelCombo.Size = new Size(95, 20); + labelCombo.TabIndex = 3; + labelCombo.Text = "Комбо-бокс:"; + // + // labelList + // + labelList.AutoSize = true; + labelList.Location = new Point(509, 19); + labelList.Name = "labelList"; + labelList.Size = new Size(59, 20); + labelList.TabIndex = 4; + labelList.Text = "Список"; + // + // customListBox + // + customListBox.Location = new Point(334, 42); + customListBox.Name = "customListBox"; + customListBox.SelectedIndex = -1; + customListBox.Size = new Size(454, 250); + customListBox.TabIndex = 5; + // + // buttonValidate + // + buttonValidate.Location = new Point(22, 298); + buttonValidate.Name = "buttonValidate"; + buttonValidate.Size = new Size(215, 29); + buttonValidate.TabIndex = 6; + buttonValidate.Text = "Проверка"; + buttonValidate.UseVisualStyleBackColor = true; + buttonValidate.Click += buttonValidate_Click; + // + // buttonGetBro + // + buttonGetBro.Location = new Point(334, 263); + buttonGetBro.Name = "buttonGetBro"; + buttonGetBro.Size = new Size(273, 29); + buttonGetBro.TabIndex = 7; + buttonGetBro.Text = "Получить отдел"; + buttonGetBro.UseVisualStyleBackColor = true; + buttonGetBro.Click += buttonGetObject_Click; + // + // toolTip + // + toolTip.ToolTipTitle = "AAAA"; + // + // button1 + // + button1.Location = new Point(22, 119); + button1.Name = "button1"; + button1.Size = new Size(94, 29); + button1.TabIndex = 8; + button1.Text = "Добавить"; + button1.UseVisualStyleBackColor = true; + button1.Click += buttonAdd_Click; + // + // FormMain + // + AutoScaleDimensions = new SizeF(8F, 20F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(800, 450); + Controls.Add(button1); + Controls.Add(buttonGetBro); + Controls.Add(buttonValidate); + Controls.Add(customListBox); + Controls.Add(labelList); + Controls.Add(labelCombo); + Controls.Add(labelNum); + Controls.Add(customComboBox); + Controls.Add(customTextBoxNumber); + Name = "FormMain"; + Text = "FormMain"; + ResumeLayout(false); + PerformLayout(); + } + + #endregion + + private Controls.CustomTextBoxNumber customTextBoxNumber; + private Controls.CustomComboBox customComboBox; + private Label labelNum; + private Label labelCombo; + private Label labelList; + private Controls.CustomListBox customListBox; + private Button buttonValidate; + private Button buttonGetBro; + private ToolTip toolTip; + private Button button1; + } +} \ No newline at end of file diff --git a/Forms/FormMain.cs b/Forms/FormMain.cs new file mode 100644 index 0000000..c7a191f --- /dev/null +++ b/Forms/FormMain.cs @@ -0,0 +1,69 @@ +using Controls; +using Controls.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 Forms +{ + public partial class FormMain : Form + { + public FormMain() + { + InitializeComponent(); + customComboBox.ComboBoxItems.Add("Chel1"); + customComboBox.ComboBoxItems.Add("Chel2"); + customComboBox.SelectedItem = "Chel1"; + + customTextBoxNumber.NumPattern = @"^\+7\d{10}$"; + + customListBox.SetTemplateString("Имя: {Name}, Код: {Code}, Номер: {Number}", "{", "}"); + Department dep1 = new Department { Name = "Отдел продаж", Code = "705", Number = "+79677156215" }; + Department dep2 = new Department { Name = "Отдел маркетинга", Code = "706", Number = "+79278146171" }; + customListBox.FillProperty(dep1, 0, "Name"); + customListBox.FillProperty(dep1, 0, "Code"); + customListBox.FillProperty(dep1, 0, "Number"); + + customListBox.FillProperty(dep2, 1, "Name"); + customListBox.FillProperty(dep2, 1, "Code"); + customListBox.FillProperty(dep2, 1, "Number"); + } + private void buttonValidate_Click(object sender, EventArgs e) + { + try + { + string phoneNumber = customTextBoxNumber.TextBoxNumber; + MessageBox.Show($"Введенный номер: {phoneNumber}"); + } + catch (CustomNumberException ex) + { + MessageBox.Show($"Ошибка: {ex.Message}"); + } + } + + private void buttonGetObject_Click(object sender, EventArgs e) + { + try + { + Department selectedPerson = customListBox.GetObjectFromStr(); + MessageBox.Show($"Отдел. Имя: {selectedPerson.Name}, Код: {selectedPerson.Code}, Номер: {selectedPerson.Number}"); + } + catch (Exception ex) + { + MessageBox.Show($"Ошибка: {ex.Message}"); + } + } + + private void buttonAdd_Click(object sender, EventArgs e) + { + customComboBox.ComboBoxItems.Add("ChelNew"); + } + + } +} diff --git a/Forms/FormMain.resx b/Forms/FormMain.resx new file mode 100644 index 0000000..1f052d5 --- /dev/null +++ b/Forms/FormMain.resx @@ -0,0 +1,123 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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/Forms/Forms.csproj b/Forms/Forms.csproj new file mode 100644 index 0000000..ec91ae7 --- /dev/null +++ b/Forms/Forms.csproj @@ -0,0 +1,15 @@ + + + + WinExe + net8.0-windows + enable + true + enable + + + + + + + \ No newline at end of file diff --git a/Forms/Program.cs b/Forms/Program.cs new file mode 100644 index 0000000..db0074d --- /dev/null +++ b/Forms/Program.cs @@ -0,0 +1,17 @@ +namespace Forms +{ + 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 FormMain()); + } + } +} \ No newline at end of file