diff --git a/VolkovLabs/VolkovLabs.sln b/VolkovLabs/VolkovLabs.sln new file mode 100644 index 0000000..865e17e --- /dev/null +++ b/VolkovLabs/VolkovLabs.sln @@ -0,0 +1,31 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.9.34723.18 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "WinFormsLibraryVolkov", "WinFormsLibraryVolkov\WinFormsLibraryVolkov.csproj", "{80044A4D-FF3B-4CA9-AA16-4E4E2520B60C}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WinFormsTestApp", "WinFormsTestApp\WinFormsTestApp.csproj", "{10C4BDA8-E7E7-4B43-8F9E-6549C5C40646}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {80044A4D-FF3B-4CA9-AA16-4E4E2520B60C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {80044A4D-FF3B-4CA9-AA16-4E4E2520B60C}.Debug|Any CPU.Build.0 = Debug|Any CPU + {80044A4D-FF3B-4CA9-AA16-4E4E2520B60C}.Release|Any CPU.ActiveCfg = Release|Any CPU + {80044A4D-FF3B-4CA9-AA16-4E4E2520B60C}.Release|Any CPU.Build.0 = Release|Any CPU + {10C4BDA8-E7E7-4B43-8F9E-6549C5C40646}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {10C4BDA8-E7E7-4B43-8F9E-6549C5C40646}.Debug|Any CPU.Build.0 = Debug|Any CPU + {10C4BDA8-E7E7-4B43-8F9E-6549C5C40646}.Release|Any CPU.ActiveCfg = Release|Any CPU + {10C4BDA8-E7E7-4B43-8F9E-6549C5C40646}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {07EF6063-AD68-403B-A72B-B19E4B920CD0} + EndGlobalSection +EndGlobal diff --git a/VolkovLabs/WinFormsLibraryVolkov/CustomInputRangeDate.Designer.cs b/VolkovLabs/WinFormsLibraryVolkov/CustomInputRangeDate.Designer.cs new file mode 100644 index 0000000..ddacd33 --- /dev/null +++ b/VolkovLabs/WinFormsLibraryVolkov/CustomInputRangeDate.Designer.cs @@ -0,0 +1,56 @@ +namespace WinFormsLibraryVolkov +{ + partial class CustomInputRangeDate + { + /// + /// Обязательная переменная конструктора. + /// + 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() + { + dateTimePicker = new DateTimePicker(); + SuspendLayout(); + // + // dateTimePicker + // + dateTimePicker.Location = new Point(3, 3); + dateTimePicker.Name = "dateTimePicker"; + dateTimePicker.Size = new Size(200, 23); + dateTimePicker.TabIndex = 0; + dateTimePicker.ValueChanged += dateTimePicker_ValueChanged; + // + // CustomInputRangeDate + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + Controls.Add(dateTimePicker); + Name = "CustomInputRangeDate"; + Size = new Size(206, 183); + ResumeLayout(false); + } + + #endregion + + private DateTimePicker dateTimePicker; + } +} diff --git a/VolkovLabs/WinFormsLibraryVolkov/CustomInputRangeDate.cs b/VolkovLabs/WinFormsLibraryVolkov/CustomInputRangeDate.cs new file mode 100644 index 0000000..e7c4159 --- /dev/null +++ b/VolkovLabs/WinFormsLibraryVolkov/CustomInputRangeDate.cs @@ -0,0 +1,91 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; +using ToolTip = System.Windows.Forms.ToolTip; + +namespace WinFormsLibraryVolkov +{ + public partial class CustomInputRangeDate : UserControl + { + private EventHandler _changeEvent; + + // Диапазон + private string example = "Введите дату от " + DateTime.MinValue.ToShortDateString() + " до " + DateTime.MaxValue.ToShortDateString(); + + // 2 публичных поля для настройки границ диапазона + public DateTime? MinDate { get; set; } + public DateTime? MaxDate { get; set; } + + public CustomInputRangeDate() + { + InitializeComponent(); + } + + public string Error { get; protected set; } = string.Empty; + + //Публичное свойство для установки и получения введенного значения(set, get). + ///При получении проводиться проверка, + //если введенное значение не входит в диапазон, возвращать + //значение null, а в отдельное поле выводить текст ошибки.При + //установке должна проводиться проверка, если передаваемое + //значение не входит в диапазон, то не заполнять поле компонента. + public DateTime? Date + { + get + { + if (MinDate == null || MaxDate == null) + { + Error = "Диапазон не задан"; + return null; + } + if (dateTimePicker.Value >= MinDate && dateTimePicker.Value <= MaxDate) + { + return dateTimePicker.Value; + } + Error = "Введенная дата лежит вне диапазона " + MinDate?.ToShortDateString() + " - " + MaxDate?.ToShortDateString(); + return null; + } + set + { + if (MinDate == null || MaxDate == null) + { + Error = "Диапазон не задан"; + } + if (value.HasValue && value >= MinDate && value <= MaxDate) + { + dateTimePicker.Value = value.Value; + } + } + } + + private void dateTimePicker_Enter(object sender, EventArgs e) + { + ToolTip tt = new ToolTip(); + tt.Show(example, dateTimePicker, 30, -20, 1000); + } + + private void dateTimePicker_ValueChanged(object sender, EventArgs e) + { + _changeEvent?.Invoke(sender, e); + } + + //Cобытие, вызываемое при смене значения. + public event EventHandler ChangeEvent + { + add + { + _changeEvent += value; + } + remove + { + _changeEvent -= value; + } + } + } +} diff --git a/VolkovLabs/WinFormsLibraryVolkov/CustomInputRangeDate.resx b/VolkovLabs/WinFormsLibraryVolkov/CustomInputRangeDate.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/VolkovLabs/WinFormsLibraryVolkov/CustomInputRangeDate.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/VolkovLabs/WinFormsLibraryVolkov/CustomTreeCell.Designer.cs b/VolkovLabs/WinFormsLibraryVolkov/CustomTreeCell.Designer.cs new file mode 100644 index 0000000..868438d --- /dev/null +++ b/VolkovLabs/WinFormsLibraryVolkov/CustomTreeCell.Designer.cs @@ -0,0 +1,55 @@ +namespace WinFormsLibraryVolkov +{ + partial class CustomTreeCell + { + /// + /// Обязательная переменная конструктора. + /// + 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() + { + treeView = new TreeView(); + SuspendLayout(); + // + // treeView + // + treeView.Location = new Point(3, 3); + treeView.Name = "treeView"; + treeView.Size = new Size(447, 189); + treeView.TabIndex = 0; + // + // CustomTreeCell + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + Controls.Add(treeView); + Name = "CustomTreeCell"; + Size = new Size(453, 195); + ResumeLayout(false); + } + + #endregion + + private TreeView treeView; + } +} diff --git a/VolkovLabs/WinFormsLibraryVolkov/CustomTreeCell.cs b/VolkovLabs/WinFormsLibraryVolkov/CustomTreeCell.cs new file mode 100644 index 0000000..af749bd --- /dev/null +++ b/VolkovLabs/WinFormsLibraryVolkov/CustomTreeCell.cs @@ -0,0 +1,117 @@ +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 WinFormsLibraryVolkov +{ + public partial class CustomTreeCell : UserControl + { + public CustomTreeCell() + { + InitializeComponent(); + } + + public void Clear() + { + treeView.Nodes.Clear(); + } + + //Публичное свойство для установки и получения индекса выбранной ветки(set, get). + protected DataTreeNodeConfig Levels { get; set; } + + public void LoadConfig(DataTreeNodeConfig levels) + { + if (levels != null) + { + Levels = levels; + } + } + + public T GetSelectedObject() where T : class, new() + { + if (treeView.SelectedNode == null || Levels == null || treeView.SelectedNode.Nodes.Count > 0) + { + return null; + } + + Stack stack = new Stack(); + for (TreeNode treeNode = treeView.SelectedNode; treeNode != null; treeNode = treeNode.Parent) + { + stack.Push(treeNode.Text); + } + + if (stack.Count != Levels.NodeNames.Count) + { + return null; + } + + T val = new T(); + foreach (string nodeName in Levels.NodeNames) + { + PropertyInfo property = val.GetType().GetProperty(nodeName); + string value = stack.Pop(); + property?.SetValue(val, Convert.ChangeType(value, property?.PropertyType)); + } + + return val; + } + + public void AddCells(int columnIndex, List elements) + { + if (elements == null || elements.Count == 0) + { + return; + } + + foreach (T element in elements) + { + AddCell(columnIndex, element); + } + } + + // Обновленный метод для добавления одного элемента в дерево + public void AddCell(int columnIndex, T element) + { + if (Levels == null || element == null || columnIndex < 0 || columnIndex >= Levels.NodeNames.Count) + { + return; + } + + TreeNodeCollection treeNodeCollection = treeView.Nodes; + int num = 0; + foreach (string nodeName in Levels.NodeNames) + { + // Получение значения свойства или поля + PropertyInfo property = element.GetType().GetProperty(nodeName); + string text = property?.GetValue(element, null)?.ToString() ?? nodeName; + + TreeNode treeNode = null; + foreach (TreeNode item in treeNodeCollection) + { + if (item.Text == text) + { + treeNode = item; + break; + } + } + + // Если узел не найден, добавляем новый + treeNodeCollection = (treeNode == null) ? treeNodeCollection.Add(text).Nodes : treeNode.Nodes; + + if (num >= columnIndex) + { + break; + } + + num++; + } + } + } +} diff --git a/VolkovLabs/WinFormsLibraryVolkov/CustomTreeCell.resx b/VolkovLabs/WinFormsLibraryVolkov/CustomTreeCell.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/VolkovLabs/WinFormsLibraryVolkov/CustomTreeCell.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/VolkovLabs/WinFormsLibraryVolkov/DataTreeNodeConfig.cs b/VolkovLabs/WinFormsLibraryVolkov/DataTreeNodeConfig.cs new file mode 100644 index 0000000..adeb9d2 --- /dev/null +++ b/VolkovLabs/WinFormsLibraryVolkov/DataTreeNodeConfig.cs @@ -0,0 +1,13 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace WinFormsLibraryVolkov +{ + public class DataTreeNodeConfig + { + public Queue NodeNames { get; set; } + } +} diff --git a/VolkovLabs/WinFormsLibraryVolkov/SelectionListBox.Designer.cs b/VolkovLabs/WinFormsLibraryVolkov/SelectionListBox.Designer.cs new file mode 100644 index 0000000..02f10f4 --- /dev/null +++ b/VolkovLabs/WinFormsLibraryVolkov/SelectionListBox.Designer.cs @@ -0,0 +1,56 @@ +namespace WinFormsLibraryVolkov +{ + partial class SelectionListBox + { + /// + /// Обязательная переменная конструктора. + /// + 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() + { + checkedListBox = new CheckedListBox(); + SuspendLayout(); + // + // checkedListBox + // + checkedListBox.FormattingEnabled = true; + checkedListBox.Location = new Point(3, 1); + checkedListBox.Name = "checkedListBox"; + checkedListBox.Size = new Size(144, 148); + checkedListBox.TabIndex = 0; + checkedListBox.Dock = DockStyle.Fill; + // + // SelectionListBox + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + Controls.Add(checkedListBox); + Name = "SelectionListBox"; + ResumeLayout(false); + } + + #endregion + + private CheckedListBox checkedListBox; + } +} diff --git a/VolkovLabs/WinFormsLibraryVolkov/SelectionListBox.cs b/VolkovLabs/WinFormsLibraryVolkov/SelectionListBox.cs new file mode 100644 index 0000000..a202908 --- /dev/null +++ b/VolkovLabs/WinFormsLibraryVolkov/SelectionListBox.cs @@ -0,0 +1,97 @@ +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 WinFormsLibraryVolkov +{ + public partial class SelectionListBox : UserControl + { + public event EventHandler _changeEvent; + + public SelectionListBox() + { + InitializeComponent(); + } + + // Метод для заполнения списка строками + public void PopulateList(IEnumerable items) + { + if (items == null) + throw new ArgumentNullException(nameof(items)); + + checkedListBox.Items.Clear(); + foreach (var item in items) + { + checkedListBox.Items.Add(item, false); + } + } + + // Метод для очистки списка + public void ClearList() + { + checkedListBox.Items.Clear(); + } + + // Публичное свойство для получения и установки выбранного значения + public string SelectedValue + { + get + { + foreach (var item in checkedListBox.CheckedItems) + { + return item.ToString(); + } + return string.Empty; + } + set + { + bool found = false; + for (int i = 0; i < checkedListBox.Items.Count; i++) + { + if (checkedListBox.Items[i].ToString() == value) + { + checkedListBox.SetItemChecked(i, true); + found = true; + } + else + { + checkedListBox.SetItemChecked(i, false); + } + } + if (!found) + { + // Если значение не найдено, очистить выбор + foreach (int index in checkedListBox.CheckedIndices) + { + checkedListBox.SetItemChecked(index, false); + } + } + } + } + + // Обработчик изменения состояния элементов + private void CheckedListBox_ItemCheck(object sender, ItemCheckEventArgs e) + { + // Используем BeginInvoke, чтобы дождаться завершения изменения + this.BeginInvoke((MethodInvoker)delegate + { + // Убедимся, что только один элемент выбран + for (int i = 0; i < checkedListBox.Items.Count; i++) + { + if (i != e.Index) + { + checkedListBox.SetItemChecked(i, false); + } + } + // Вызов события + _changeEvent?.Invoke(this, EventArgs.Empty); + }); + } + } +} diff --git a/VolkovLabs/WinFormsLibraryVolkov/SelectionListBox.resx b/VolkovLabs/WinFormsLibraryVolkov/SelectionListBox.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/VolkovLabs/WinFormsLibraryVolkov/SelectionListBox.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/VolkovLabs/WinFormsLibraryVolkov/WinFormsLibraryVolkov.csproj b/VolkovLabs/WinFormsLibraryVolkov/WinFormsLibraryVolkov.csproj new file mode 100644 index 0000000..060aa1c --- /dev/null +++ b/VolkovLabs/WinFormsLibraryVolkov/WinFormsLibraryVolkov.csproj @@ -0,0 +1,10 @@ + + + + net6.0-windows + enable + true + enable + + + diff --git a/VolkovLabs/WinFormsTestApp/FormMain.Designer.cs b/VolkovLabs/WinFormsTestApp/FormMain.Designer.cs new file mode 100644 index 0000000..2eb3295 --- /dev/null +++ b/VolkovLabs/WinFormsTestApp/FormMain.Designer.cs @@ -0,0 +1,358 @@ +namespace WinFormsTestApp +{ + 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() + { + this.components = new System.ComponentModel.Container(); + this.customInputRangeDate = new WinFormsLibraryVolkov.CustomInputRangeDate(); + this.buttonCheck = new System.Windows.Forms.Button(); + this.labelCheckValue = new System.Windows.Forms.Label(); + this.groupBoxInput = new System.Windows.Forms.GroupBox(); + this.groupBoxSelected = new System.Windows.Forms.GroupBox(); + this.buttonGetSelected = new System.Windows.Forms.Button(); + this.labelSelectedValue = new System.Windows.Forms.Label(); + this.buttonClear = new System.Windows.Forms.Button(); + this.buttonAdd = new System.Windows.Forms.Button(); + this.textBoxAdd = new System.Windows.Forms.TextBox(); + this.SelectionListBox = new WinFormsLibraryVolkov.SelectionListBox(); + this.groupBoxData = new System.Windows.Forms.GroupBox(); + this.labelTransportType = new System.Windows.Forms.Label(); + this.labelModel = new System.Windows.Forms.Label(); + this.labelRegNum = new System.Windows.Forms.Label(); + this.buttonGetFromTree = new System.Windows.Forms.Button(); + this.buttonAddToTree = new System.Windows.Forms.Button(); + this.comboBoxTransportType = new System.Windows.Forms.ComboBox(); + this.textBoxModel = new System.Windows.Forms.TextBox(); + this.textBoxRegNumber = new System.Windows.Forms.TextBox(); + this.customTreeCell = new WinFormsLibraryVolkov.CustomTreeCell(); + this.tabControl = new System.Windows.Forms.TabControl(); + this.Visual = new System.Windows.Forms.TabPage(); + this.groupBoxInput.SuspendLayout(); + this.groupBoxSelected.SuspendLayout(); + this.groupBoxData.SuspendLayout(); + this.tabControl.SuspendLayout(); + this.Visual.SuspendLayout(); + this.SuspendLayout(); + // + // customInputRangeDate + // + this.customInputRangeDate.AutoValidate = System.Windows.Forms.AutoValidate.Disable; + this.customInputRangeDate.CausesValidation = false; + this.customInputRangeDate.Location = new System.Drawing.Point(34, 25); + this.customInputRangeDate.Margin = new System.Windows.Forms.Padding(3, 5, 3, 5); + this.customInputRangeDate.MaxDate = new DateTime(2024, 12, 31); + this.customInputRangeDate.MinDate = new DateTime(2004, 01, 11); + this.customInputRangeDate.Name = "customInputRangeDate"; + this.customInputRangeDate.Size = new System.Drawing.Size(144, 40); + this.customInputRangeDate.TabIndex = 0; + this.customInputRangeDate.Date = new DateTime(2024, 9, 1); + // + // buttonCheck + // + this.buttonCheck.Location = new System.Drawing.Point(193, 29); + this.buttonCheck.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); + this.buttonCheck.Name = "buttonCheck"; + this.buttonCheck.Size = new System.Drawing.Size(144, 31); + this.buttonCheck.TabIndex = 1; + this.buttonCheck.Text = "Check"; + this.buttonCheck.UseVisualStyleBackColor = true; + this.buttonCheck.Click += new System.EventHandler(this.buttonCheck_Click); + // + // labelCheckValue + // + this.labelCheckValue.AutoSize = true; + this.labelCheckValue.Location = new System.Drawing.Point(34, 148); + this.labelCheckValue.Name = "labelCheckValue"; + this.labelCheckValue.Size = new System.Drawing.Size(82, 20); + this.labelCheckValue.TabIndex = 2; + this.labelCheckValue.Text = "Enter value"; + // + // groupBoxInput + // + this.groupBoxInput.Controls.Add(this.customInputRangeDate); + this.groupBoxInput.Controls.Add(this.labelCheckValue); + this.groupBoxInput.Controls.Add(this.buttonCheck); + this.groupBoxInput.Location = new System.Drawing.Point(7, 8); + this.groupBoxInput.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); + this.groupBoxInput.Name = "groupBoxInput"; + this.groupBoxInput.Padding = new System.Windows.Forms.Padding(3, 4, 3, 4); + this.groupBoxInput.Size = new System.Drawing.Size(355, 253); + this.groupBoxInput.TabIndex = 9; + this.groupBoxInput.TabStop = false; + this.groupBoxInput.Text = "Input"; + // + // groupBoxSelected + // + this.groupBoxSelected.Controls.Add(this.buttonGetSelected); + this.groupBoxSelected.Controls.Add(this.labelSelectedValue); + this.groupBoxSelected.Controls.Add(this.buttonClear); + this.groupBoxSelected.Controls.Add(this.buttonAdd); + this.groupBoxSelected.Controls.Add(this.textBoxAdd); + this.groupBoxSelected.Controls.Add(this.SelectionListBox); + this.groupBoxSelected.Location = new System.Drawing.Point(370, 8); + this.groupBoxSelected.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); + this.groupBoxSelected.Name = "groupBoxSelected"; + this.groupBoxSelected.Padding = new System.Windows.Forms.Padding(3, 4, 3, 4); + this.groupBoxSelected.Size = new System.Drawing.Size(355, 253); + this.groupBoxSelected.TabIndex = 10; + this.groupBoxSelected.TabStop = false; + this.groupBoxSelected.Text = "Selected"; + // + // buttonGetSelected + // + this.buttonGetSelected.Location = new System.Drawing.Point(219, 192); + this.buttonGetSelected.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); + this.buttonGetSelected.Name = "buttonGetSelected"; + this.buttonGetSelected.Size = new System.Drawing.Size(114, 31); + this.buttonGetSelected.TabIndex = 14; + this.buttonGetSelected.Text = "Get Selected"; + this.buttonGetSelected.UseVisualStyleBackColor = true; + this.buttonGetSelected.Click += new System.EventHandler(this.buttonGetSelected_Click); + // + // labelSelectedValue + // + this.labelSelectedValue.AutoSize = true; + this.labelSelectedValue.Location = new System.Drawing.Point(219, 148); + this.labelSelectedValue.Name = "labelSelectedValue"; + this.labelSelectedValue.Size = new System.Drawing.Size(105, 20); + this.labelSelectedValue.TabIndex = 11; + this.labelSelectedValue.Text = "Selected value"; + // + // buttonClear + // + this.buttonClear.Location = new System.Drawing.Point(219, 108); + this.buttonClear.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); + this.buttonClear.Name = "buttonClear"; + this.buttonClear.Size = new System.Drawing.Size(114, 31); + this.buttonClear.TabIndex = 13; + this.buttonClear.Text = "Clear"; + this.buttonClear.UseVisualStyleBackColor = true; + this.buttonClear.Click += new System.EventHandler(this.buttonClear_Click); + // + // buttonAdd + // + this.buttonAdd.Location = new System.Drawing.Point(219, 69); + this.buttonAdd.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); + this.buttonAdd.Name = "buttonAdd"; + this.buttonAdd.Size = new System.Drawing.Size(114, 31); + this.buttonAdd.TabIndex = 12; + this.buttonAdd.Text = "Add or Select"; + this.buttonAdd.UseVisualStyleBackColor = true; + this.buttonAdd.Click += new System.EventHandler(this.buttonAdd_Click); + // + // textBoxAdd + // + this.textBoxAdd.Location = new System.Drawing.Point(219, 31); + this.textBoxAdd.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); + this.textBoxAdd.Name = "textBoxAdd"; + this.textBoxAdd.Size = new System.Drawing.Size(114, 27); + this.textBoxAdd.TabIndex = 11; + // + // SelectionListBox + // + this.SelectionListBox.Location = new System.Drawing.Point(41, 25); + this.SelectionListBox.Margin = new System.Windows.Forms.Padding(3, 5, 3, 5); + this.SelectionListBox.Name = "SelectionListBox"; + this.SelectionListBox.SelectedValue = ""; + this.SelectionListBox.Size = new System.Drawing.Size(171, 209); + this.SelectionListBox.TabIndex = 0; + // + // groupBoxData + // + this.groupBoxData.Controls.Add(this.labelTransportType); + this.groupBoxData.Controls.Add(this.labelModel); + this.groupBoxData.Controls.Add(this.labelRegNum); + this.groupBoxData.Controls.Add(this.buttonGetFromTree); + this.groupBoxData.Controls.Add(this.buttonAddToTree); + this.groupBoxData.Controls.Add(this.comboBoxTransportType); + this.groupBoxData.Controls.Add(this.textBoxModel); + this.groupBoxData.Controls.Add(this.textBoxRegNumber); + this.groupBoxData.Controls.Add(this.customTreeCell); + this.groupBoxData.Location = new System.Drawing.Point(7, 269); + this.groupBoxData.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); + this.groupBoxData.Name = "groupBoxData"; + this.groupBoxData.Padding = new System.Windows.Forms.Padding(3, 4, 3, 4); + this.groupBoxData.Size = new System.Drawing.Size(719, 307); + this.groupBoxData.TabIndex = 11; + this.groupBoxData.TabStop = false; + this.groupBoxData.Text = "Data"; + // + // labelTransportType + // + this.labelTransportType.AutoSize = true; + this.labelTransportType.Location = new System.Drawing.Point(494, 155); + this.labelTransportType.Name = "labelTransportType"; + this.labelTransportType.Size = new System.Drawing.Size(119, 20); + this.labelTransportType.TabIndex = 8; + this.labelTransportType.Text = "Тип транспорта"; + // + // labelModel + // + this.labelModel.AutoSize = true; + this.labelModel.Location = new System.Drawing.Point(494, 96); + this.labelModel.Name = "labelModel"; + this.labelModel.Size = new System.Drawing.Size(63, 20); + this.labelModel.TabIndex = 7; + this.labelModel.Text = "Модель"; + // + // labelRegNum + // + this.labelRegNum.AutoSize = true; + this.labelRegNum.Location = new System.Drawing.Point(494, 37); + this.labelRegNum.Name = "labelRegNum"; + this.labelRegNum.Size = new System.Drawing.Size(185, 20); + this.labelRegNum.TabIndex = 6; + this.labelRegNum.Text = "Регистрационный номер"; + // + // buttonGetFromTree + // + this.buttonGetFromTree.Location = new System.Drawing.Point(494, 260); + this.buttonGetFromTree.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); + this.buttonGetFromTree.Name = "buttonGetFromTree"; + this.buttonGetFromTree.Size = new System.Drawing.Size(215, 31); + this.buttonGetFromTree.TabIndex = 5; + this.buttonGetFromTree.Text = "Get Selected"; + this.buttonGetFromTree.UseVisualStyleBackColor = true; + this.buttonGetFromTree.Click += new System.EventHandler(this.buttonGetFromTree_Click); + // + // buttonAddToTree + // + this.buttonAddToTree.Location = new System.Drawing.Point(494, 221); + this.buttonAddToTree.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); + this.buttonAddToTree.Name = "buttonAddToTree"; + this.buttonAddToTree.Size = new System.Drawing.Size(215, 31); + this.buttonAddToTree.TabIndex = 4; + this.buttonAddToTree.Text = "Add"; + this.buttonAddToTree.UseVisualStyleBackColor = true; + this.buttonAddToTree.Click += new System.EventHandler(this.buttonAddToTree_Click); + // + // comboBoxTransportType + // + this.comboBoxTransportType.FormattingEnabled = true; + this.comboBoxTransportType.Location = new System.Drawing.Point(494, 179); + this.comboBoxTransportType.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); + this.comboBoxTransportType.Name = "comboBoxTransportType"; + this.comboBoxTransportType.Size = new System.Drawing.Size(214, 28); + this.comboBoxTransportType.TabIndex = 3; + // + // textBoxModel + // + this.textBoxModel.Location = new System.Drawing.Point(494, 120); + this.textBoxModel.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); + this.textBoxModel.Name = "textBoxModel"; + this.textBoxModel.Size = new System.Drawing.Size(214, 27); + this.textBoxModel.TabIndex = 2; + // + // textBoxRegNumber + // + this.textBoxRegNumber.Location = new System.Drawing.Point(494, 61); + this.textBoxRegNumber.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); + this.textBoxRegNumber.Name = "textBoxRegNumber"; + this.textBoxRegNumber.Size = new System.Drawing.Size(214, 27); + this.textBoxRegNumber.TabIndex = 1; + // + // customTreeCell + // + this.customTreeCell.Location = new System.Drawing.Point(17, 29); + this.customTreeCell.Margin = new System.Windows.Forms.Padding(3, 5, 3, 5); + this.customTreeCell.Name = "customTreeCell"; + this.customTreeCell.Size = new System.Drawing.Size(455, 269); + this.customTreeCell.TabIndex = 0; + // + // tabControl + // + this.tabControl.Controls.Add(this.Visual); + this.tabControl.Location = new System.Drawing.Point(14, 16); + this.tabControl.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); + this.tabControl.Name = "tabControl"; + this.tabControl.SelectedIndex = 0; + this.tabControl.Size = new System.Drawing.Size(746, 621); + this.tabControl.TabIndex = 12; + // + // Visual + // + this.Visual.Controls.Add(this.groupBoxData); + this.Visual.Controls.Add(this.groupBoxInput); + this.Visual.Controls.Add(this.groupBoxSelected); + this.Visual.Location = new System.Drawing.Point(4, 29); + this.Visual.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); + this.Visual.Name = "Visual"; + this.Visual.Padding = new System.Windows.Forms.Padding(3, 4, 3, 4); + this.Visual.Size = new System.Drawing.Size(738, 588); + this.Visual.TabIndex = 0; + this.Visual.Text = "Visual"; + this.Visual.UseVisualStyleBackColor = true; + // + // FormMain + // + this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(771, 648); + this.Controls.Add(this.tabControl); + this.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); + this.Name = "FormMain"; + this.Text = "FormMain"; + this.groupBoxInput.ResumeLayout(false); + this.groupBoxInput.PerformLayout(); + this.groupBoxSelected.ResumeLayout(false); + this.groupBoxSelected.PerformLayout(); + this.groupBoxData.ResumeLayout(false); + this.groupBoxData.PerformLayout(); + this.tabControl.ResumeLayout(false); + this.Visual.ResumeLayout(false); + this.ResumeLayout(false); + + } + + #endregion + + private WinFormsLibraryVolkov.CustomInputRangeDate customInputRangeDate; + private Button buttonCheck; + private Label labelCheckValue; + private GroupBox groupBoxInput; + private GroupBox groupBoxSelected; + private Button buttonGetSelected; + private Label labelSelectedValue; + private Button buttonClear; + private Button buttonAdd; + private TextBox textBoxAdd; + private WinFormsLibraryVolkov.SelectionListBox SelectionListBox; + private GroupBox groupBoxData; + private WinFormsLibraryVolkov.CustomTreeCell customTreeCell; + private Button buttonGetFromTree; + private Button buttonAddToTree; + private ComboBox comboBoxTransportType; + private TextBox textBoxModel; + private TextBox textBoxRegNumber; + private Label labelTransportType; + private Label labelModel; + private Label labelRegNum; + private TabControl tabControl; + private TabPage Visual; + } +} \ No newline at end of file diff --git a/VolkovLabs/WinFormsTestApp/FormMain.cs b/VolkovLabs/WinFormsTestApp/FormMain.cs new file mode 100644 index 0000000..9517da8 --- /dev/null +++ b/VolkovLabs/WinFormsTestApp/FormMain.cs @@ -0,0 +1,120 @@ +using WinFormsLibraryVolkov; +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 WinFormsTestApp +{ + public partial class FormMain : Form + { + readonly List transports = new() + { + new Transport { Id = 1, Fuel="Авиакеросин", Mileage=239000, Owner="Аэрофлот", Price=70000000, State="Эксплуатируется", RegNumber = "EW-009EC", TransportType = "Воздушный транспорт", Model = "Ан-30" }, + new Transport { Id = 2, Fuel="Авиакеросин", Mileage=452005, Owner="Азимут", Price=95000000, State="Не эксплуатируется", RegNumber = "EW-987ZY", TransportType = "Воздушный транспорт", Model = "Ан-28" }, + new Transport { Id = 3, Fuel="Мазут", Mileage=790222, Owner="ВМФ США", Price=100000000, State="Эксплуатируется", RegNumber = "SSH-988", TransportType = "Морской транспорт", Model = "авианосец 'Нимиц'" }, + new Transport { Id = 4, Fuel="92", Mileage=105777, Owner="Ползунова Татьяна Михайловна",State="Не эксплуатируется", Price=400000, RegNumber = "B901AУ74", TransportType = "Наземный транспорт", Model = "Renault Logan" }, + new Transport { Id = 5, Fuel="Газ", Mileage=66782, Owner="Аветесян Сергей Георгиевич", State="Эксплуатируется", Price=160000, RegNumber = "Р187КН73", TransportType = "Наземный транспорт", Model = "Daewoo Matiz" }, + }; + public FormMain() + { + InitializeComponent(); + var list = new List() { "Значение 1", "Значение 2", "Значение 3", "Значение 4", "Значение 5" }; + SelectionListBox.PopulateList(list); + + comboBoxTransportType.Items.Add("Наземный транспорт"); + comboBoxTransportType.Items.Add("Воздушный транспорт"); + comboBoxTransportType.Items.Add("Морской транспорт"); + + var nodeNames = new Queue(); + nodeNames.Enqueue("TransportType"); + nodeNames.Enqueue("Model"); + nodeNames.Enqueue("RegNumber"); + var treeConfig = new DataTreeNodeConfig { NodeNames = nodeNames }; + + customTreeCell.LoadConfig(treeConfig); + + int counter = 0; + foreach (var transport in transports) + { + + customTreeCell.AddCell(0, transport); + customTreeCell.AddCell(1, transport); + customTreeCell.AddCell(2, transport); + customTreeCell.AddCell(3, transport); + + counter++; + } + } + + private void buttonCheck_Click(object sender, EventArgs e) + { + // доделать + } + + private void textBoxMin_KeyPress(object sender, KeyPressEventArgs e) + { + char ch = e.KeyChar; + if (!Char.IsDigit(ch) && ch != 8 && ch != 45) + { + e.Handled = true; + } + } + + private void textBoxMax_KeyPress(object sender, KeyPressEventArgs e) + { + char ch = e.KeyChar; + if (!Char.IsDigit(ch) && ch != 8 && ch != 45) + { + e.Handled = true; + } + } + + private void buttonAdd_Click(object sender, EventArgs e) + { + // доделать + } + + private void buttonClear_Click(object sender, EventArgs e) + { + SelectionListBox.ClearList(); + } + + private void buttonGetSelected_Click(object sender, EventArgs e) + { + labelSelectedValue.Text = SelectionListBox.SelectedValue; + if (labelSelectedValue.Text == "") + { + labelSelectedValue.Text = "Значение \nне выбрано"; + } + } + + private void buttonAddToTree_Click(object sender, EventArgs e) + { + if (textBoxRegNumber.Text == null || textBoxModel.Text == null || comboBoxTransportType.SelectedItem == null) + { + return; + } + customTreeCell.AddCell(2, new(textBoxRegNumber.Text, comboBoxTransportType.SelectedItem.ToString(), textBoxModel.Text)); + customTreeCell.Update(); + } + + private void buttonGetFromTree_Click(object sender, EventArgs e) + { + Transport tp = customTreeCell.GetSelectedObject(); + if (tp == null) + { + return; + } + textBoxRegNumber.Text = tp.RegNumber; + textBoxModel.Text = tp.Model; + comboBoxTransportType.SelectedItem = tp.TransportType; + } + + } +} diff --git a/VolkovLabs/WinFormsTestApp/FormMain.resx b/VolkovLabs/WinFormsTestApp/FormMain.resx new file mode 100644 index 0000000..93c550b --- /dev/null +++ b/VolkovLabs/WinFormsTestApp/FormMain.resx @@ -0,0 +1,69 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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 + + + 161, 17 + + + 295, 17 + + \ No newline at end of file diff --git a/VolkovLabs/WinFormsTestApp/Program.cs b/VolkovLabs/WinFormsTestApp/Program.cs new file mode 100644 index 0000000..5a16538 --- /dev/null +++ b/VolkovLabs/WinFormsTestApp/Program.cs @@ -0,0 +1,17 @@ +namespace WinFormsTestApp +{ + 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 diff --git a/VolkovLabs/WinFormsTestApp/Transport.cs b/VolkovLabs/WinFormsTestApp/Transport.cs new file mode 100644 index 0000000..46bb86e --- /dev/null +++ b/VolkovLabs/WinFormsTestApp/Transport.cs @@ -0,0 +1,37 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace WinFormsTestApp +{ + public class Transport + { + public int Id { get; set; } + + public string RegNumber { get; set; } + + public string State { get; set; } + + public int Mileage { get; set; } + + public int Price { get; set; } + + public string TransportType { get; set; } + + public string Model { get; set; } + + public string Owner { get; set; } + + public string Fuel { get; set; } + + public Transport(string regNumber, string transportType, string model) + { + RegNumber = regNumber; + TransportType = transportType; + Model = model; + } + public Transport() { } + } +} diff --git a/VolkovLabs/WinFormsTestApp/WinFormsTestApp.csproj b/VolkovLabs/WinFormsTestApp/WinFormsTestApp.csproj new file mode 100644 index 0000000..7ed8a99 --- /dev/null +++ b/VolkovLabs/WinFormsTestApp/WinFormsTestApp.csproj @@ -0,0 +1,15 @@ + + + + WinExe + net6.0-windows + enable + true + enable + + + + + + + \ No newline at end of file