This commit is contained in:
ksenianeva 2023-10-20 09:23:18 +04:00
parent 6ed4cc2635
commit fa6498b47d
11 changed files with 409 additions and 58 deletions

View File

@ -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}") = "NevaevaLibrary", "NevaevaLibrary\NevaevaLibrary.csproj", "{E7CA58DB-9F0F-4380-96F7-EAFDA623CE84}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "NevaevaLibrary", "NevaevaLibrary\NevaevaLibrary.csproj", "{E7CA58DB-9F0F-4380-96F7-EAFDA623CE84}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TestApp", "TestApp\TestApp.csproj", "{38BE5966-BF1C-4D26-AC7A-74EDDD25A6B3}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
@ -15,6 +17,10 @@ Global
{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
{38BE5966-BF1C-4D26-AC7A-74EDDD25A6B3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{38BE5966-BF1C-4D26-AC7A-74EDDD25A6B3}.Debug|Any CPU.Build.0 = Debug|Any CPU
{38BE5966-BF1C-4D26-AC7A-74EDDD25A6B3}.Release|Any CPU.ActiveCfg = Release|Any CPU
{38BE5966-BF1C-4D26-AC7A-74EDDD25A6B3}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE

View File

@ -21,11 +21,14 @@ namespace NevaevaLibrary
{
get
{
return comboBoxCustom.SelectedValue.ToString() ?? "";
return comboBoxCustom.SelectedItem != null ? comboBoxCustom.SelectedItem.ToString() : "";
}
set
{
comboBoxCustom.SelectedValue = value;
if(comboBoxCustom.Items.Contains(value)) //если есть такой элемент, то помечаем, если нет, ничего не делаем
{
comboBoxCustom.SelectedItem = value;
}
}
}
@ -46,7 +49,7 @@ namespace NevaevaLibrary
private void comboBoxCustom_SelectedIndexChanged(object sender, EventArgs e)
{
SelectedValueChange.Invoke(comboBoxCustom.SelectedItem.ToString());
SelectedValueChange?.Invoke(comboBoxCustom.SelectedItem.ToString());
}
}
}

View File

@ -42,7 +42,7 @@ namespace NevaevaLibrary
}
}
public T? getSelectedItems<T>()
public T? getSelectedItem<T>()
{
if (template == null || !fromChar.HasValue || !toChar.HasValue || listBox.SelectedIndex == -1) throw new ArgumentException("Не хватает данных!");
var type = typeof(T);
@ -60,10 +60,10 @@ namespace NevaevaLibrary
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 indexBefore = i > 0 ? Array.IndexOf(words, wordsTemplate[i-1]) : -1;
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);
var fieldValue = String.Join(' ', words.Skip(indexBefore + 1).Take(indexAfter - indexBefore - 1).ToArray());
field.SetValue(item, Convert.ChangeType(fieldValue, field.FieldType));
}
}

View File

@ -30,8 +30,6 @@
{
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();
//
@ -42,41 +40,20 @@
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;
this.textBoxMail.MouseEnter += new System.EventHandler(this.textBoxMail_MouseEnter);
//
// toolTipEmail
//
this.toolTipEmail.Popup += new System.Windows.Forms.PopupEventHandler(this.toolTipEmail_Popup);
this.toolTipEmail.ToolTipIcon = System.Windows.Forms.ToolTipIcon.Info;
this.toolTipEmail.ToolTipTitle = "Пример ввода";
//
// 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.Size = new System.Drawing.Size(264, 34);
this.ResumeLayout(false);
this.PerformLayout();
@ -85,8 +62,6 @@
#endregion
private TextBox textBoxMail;
private CheckBox checkBoxNull;
private Label labelCheckAddress;
private ToolTip toolTipEmail;
}
}

View File

@ -18,46 +18,53 @@ namespace NevaevaLibrary
}
public event Action<string> TextChange;
private string? tooltipText;
public string errorMessage = "";
public string Email
public string? Email
{
get
{
return textBoxMail.Text;
//не забыл ли пользователь ввести регулярку и соответствует ли она
if (validateEmailRegex == null)
{
errorMessage = "Пустой шаблон!";
return null;
}
else if (!validateEmailRegex.IsMatch(textBoxMail.Text))
{
errorMessage = "Некорректный адрес эл. почты!";
return null;
}
else 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;
}
if (validateEmailRegex == null) errorMessage = "Пустой шаблон!";
else if (!validateEmailRegex.IsMatch(value)) errorMessage = "Некорректный адрес эл. почты!";
else
{
textBoxMail.Enabled = true;
textBoxMail.Text = "";
textBoxMail.Text = value;
}
}
}
private void textBoxMail_TextChanged(object sender, EventArgs e)
{
TextChange.Invoke(textBoxMail.Text);
TextChange?.Invoke(textBoxMail.Text);
Email = textBoxMail.Text;
}
public void toolTipEmail_Popup(object sender, PopupEventArgs e)
public void setTooltipText(string text)
{
toolTipEmail.ToolTipTitle = "qwerty@gmail.com";
tooltipText = text;
}
private void textBoxMail_MouseEnter(object sender, EventArgs e)
{
toolTipEmail.Show(tooltipText ?? "", textBoxMail);
}
//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])?$");
}
}

View File

@ -0,0 +1,173 @@
namespace TestApp
{
partial class FormTest
{
/// <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.comboBoxControl = new NevaevaLibrary.ComboBoxControl();
this.buttonInsert = new System.Windows.Forms.Button();
this.buttonClear = new System.Windows.Forms.Button();
this.buttonGetSelected = new System.Windows.Forms.Button();
this.buttonSetSelected = new System.Windows.Forms.Button();
this.mailControl = new NevaevaLibrary.MailControl();
this.buttonAddTemplate = new System.Windows.Forms.Button();
this.listBoxControl = new NevaevaLibrary.ListBoxControl();
this.buttonInsertList = new System.Windows.Forms.Button();
this.buttonGetSelectedList = new System.Windows.Forms.Button();
this.SuspendLayout();
//
// comboBoxControl
//
this.comboBoxControl.Location = new System.Drawing.Point(12, 12);
this.comboBoxControl.Name = "comboBoxControl";
this.comboBoxControl.SelectedValue = "";
this.comboBoxControl.Size = new System.Drawing.Size(366, 44);
this.comboBoxControl.TabIndex = 0;
this.comboBoxControl.SelectedValueChange += new System.Action<string>(this.comboBoxControl_SelectedValueChange);
//
// buttonInsert
//
this.buttonInsert.Location = new System.Drawing.Point(12, 48);
this.buttonInsert.Name = "buttonInsert";
this.buttonInsert.Size = new System.Drawing.Size(94, 29);
this.buttonInsert.TabIndex = 1;
this.buttonInsert.Text = "Заполнить";
this.buttonInsert.UseVisualStyleBackColor = true;
this.buttonInsert.Click += new System.EventHandler(this.buttonInsert_Click);
//
// buttonClear
//
this.buttonClear.Location = new System.Drawing.Point(112, 48);
this.buttonClear.Name = "buttonClear";
this.buttonClear.Size = new System.Drawing.Size(94, 29);
this.buttonClear.TabIndex = 2;
this.buttonClear.Text = "Очистить";
this.buttonClear.UseVisualStyleBackColor = true;
this.buttonClear.Click += new System.EventHandler(this.buttonClear_Click);
//
// buttonGetSelected
//
this.buttonGetSelected.Location = new System.Drawing.Point(212, 48);
this.buttonGetSelected.Name = "buttonGetSelected";
this.buttonGetSelected.Size = new System.Drawing.Size(94, 29);
this.buttonGetSelected.TabIndex = 3;
this.buttonGetSelected.Text = "Получить";
this.buttonGetSelected.UseVisualStyleBackColor = true;
this.buttonGetSelected.Click += new System.EventHandler(this.buttonGetSelected_Click);
//
// buttonSetSelected
//
this.buttonSetSelected.Location = new System.Drawing.Point(312, 48);
this.buttonSetSelected.Name = "buttonSetSelected";
this.buttonSetSelected.Size = new System.Drawing.Size(99, 29);
this.buttonSetSelected.TabIndex = 4;
this.buttonSetSelected.Text = "Установить";
this.buttonSetSelected.UseVisualStyleBackColor = true;
this.buttonSetSelected.Click += new System.EventHandler(this.buttonSetSelected_Click);
//
// mailControl
//
this.mailControl.Email = "";
this.mailControl.Location = new System.Drawing.Point(11, 95);
this.mailControl.Name = "mailControl";
this.mailControl.Size = new System.Drawing.Size(312, 94);
this.mailControl.TabIndex = 5;
this.mailControl.validateEmailRegex = null;
//
// buttonAddTemplate
//
this.buttonAddTemplate.Location = new System.Drawing.Point(12, 160);
this.buttonAddTemplate.Name = "buttonAddTemplate";
this.buttonAddTemplate.Size = new System.Drawing.Size(143, 29);
this.buttonAddTemplate.TabIndex = 6;
this.buttonAddTemplate.Text = "Передать шаблон";
this.buttonAddTemplate.UseVisualStyleBackColor = true;
this.buttonAddTemplate.Click += new System.EventHandler(this.buttonAddTemplate_Click);
//
// listBoxControl
//
this.listBoxControl.Location = new System.Drawing.Point(479, 12);
this.listBoxControl.Name = "listBoxControl";
this.listBoxControl.SelectedIndex = -1;
this.listBoxControl.Size = new System.Drawing.Size(608, 237);
this.listBoxControl.TabIndex = 7;
//
// buttonInsertList
//
this.buttonInsertList.Location = new System.Drawing.Point(483, 268);
this.buttonInsertList.Name = "buttonInsertList";
this.buttonInsertList.Size = new System.Drawing.Size(94, 29);
this.buttonInsertList.TabIndex = 8;
this.buttonInsertList.Text = "Заполнить";
this.buttonInsertList.UseVisualStyleBackColor = true;
this.buttonInsertList.Click += new System.EventHandler(this.buttonInsertList_Click);
//
// buttonGetSelectedList
//
this.buttonGetSelectedList.Location = new System.Drawing.Point(596, 268);
this.buttonGetSelectedList.Name = "buttonGetSelectedList";
this.buttonGetSelectedList.Size = new System.Drawing.Size(94, 29);
this.buttonGetSelectedList.TabIndex = 9;
this.buttonGetSelectedList.Text = "Получить";
this.buttonGetSelectedList.UseVisualStyleBackColor = true;
this.buttonGetSelectedList.Click += new System.EventHandler(this.buttonGetSelectedList_Click);
//
// FormTest
//
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(1109, 316);
this.Controls.Add(this.buttonGetSelectedList);
this.Controls.Add(this.buttonInsertList);
this.Controls.Add(this.listBoxControl);
this.Controls.Add(this.buttonAddTemplate);
this.Controls.Add(this.mailControl);
this.Controls.Add(this.buttonSetSelected);
this.Controls.Add(this.buttonGetSelected);
this.Controls.Add(this.buttonClear);
this.Controls.Add(this.buttonInsert);
this.Controls.Add(this.comboBoxControl);
this.Name = "FormTest";
this.Text = "FormTest";
this.ResumeLayout(false);
}
#endregion
private NevaevaLibrary.ComboBoxControl comboBoxControl;
private Button buttonInsert;
private Button buttonClear;
private Button buttonGetSelected;
private Button buttonSetSelected;
private NevaevaLibrary.MailControl mailControl;
private Button buttonAddTemplate;
private NevaevaLibrary.ListBoxControl listBoxControl;
private Button buttonInsertList;
private Button buttonGetSelectedList;
}
}

View File

@ -0,0 +1,70 @@
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 TestApp
{
public partial class FormTest : Form
{
public FormTest()
{
InitializeComponent();
}
private void buttonInsert_Click(object sender, EventArgs e)
{
List<string> testStrings = new List<string>() { "str1", "str2", "str3" };
comboBoxControl.addItems(testStrings);
}
private void buttonClear_Click(object sender, EventArgs e)
{
comboBoxControl.clear();
}
private void buttonGetSelected_Click(object sender, EventArgs e)
{
MessageBox.Show(comboBoxControl.SelectedValue, "Полученное значение");
}
private void buttonSetSelected_Click(object sender, EventArgs e)
{
comboBoxControl.SelectedValue = "str2";
}
private void comboBoxControl_SelectedValueChange(string obj)
{
MessageBox.Show(obj, "event");
}
private void buttonAddTemplate_Click(object sender, EventArgs e)
{
mailControl.validateEmailRegex = 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])?$");
mailControl.setTooltipText("qwerty@gmail.com");
}
private void buttonInsertList_Click(object sender, EventArgs e)
{
listBoxControl.setParams("{name} works in {department} for {workYears} year(s)", '{', '}');
Worker w1 = new Worker("Vasya", "Management", 5);
Worker w2 = new Worker("Vasya Utkin", "Tech department cool stuff", 1);
Worker w3 = new Worker("Ivan", "Management", 2);
List <Worker> workers = new List<Worker> { w1, w2, w3 };
listBoxControl.setItems(workers);
}
private void buttonGetSelectedList_Click(object sender, EventArgs e)
{
Worker? worker = listBoxControl.getSelectedItem<Worker>();
if (worker is not null) MessageBox.Show(worker.ToString() + $"\n{worker.name}, {worker.department}, {worker.workYears}");
}
}
}

View 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>

View File

@ -0,0 +1,17 @@
namespace TestApp
{
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 FormTest());
}
}
}

View 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="..\NevaevaLibrary\NevaevaLibrary.csproj" />
</ItemGroup>
</Project>

View File

@ -0,0 +1,25 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace TestApp
{
public class Worker
{
public string name;
public string department;
public int workYears;
public Worker(string name, string department, int workYears)
{
this.name = name;
this.department = department;
this.workYears = workYears;
}
public Worker()
{ }
}
}