diff --git a/COP/COP.sln b/COP/COP.sln index 3bd2c44..6433672 100644 --- a/COP/COP.sln +++ b/COP/COP.sln @@ -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", "{F22A3AAE-6F8D-4AEB-91B1-E8303166B5FF}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Components", "Components\Components.csproj", "{F22A3AAE-6F8D-4AEB-91B1-E8303166B5FF}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WinFormsTest", "WinFormsTest\WinFormsTest.csproj", "{F589AB00-F69A-4826-BE33-662F14E39F25}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -15,6 +17,10 @@ Global {F22A3AAE-6F8D-4AEB-91B1-E8303166B5FF}.Debug|Any CPU.Build.0 = Debug|Any CPU {F22A3AAE-6F8D-4AEB-91B1-E8303166B5FF}.Release|Any CPU.ActiveCfg = Release|Any CPU {F22A3AAE-6F8D-4AEB-91B1-E8303166B5FF}.Release|Any CPU.Build.0 = Release|Any CPU + {F589AB00-F69A-4826-BE33-662F14E39F25}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {F589AB00-F69A-4826-BE33-662F14E39F25}.Debug|Any CPU.Build.0 = Debug|Any CPU + {F589AB00-F69A-4826-BE33-662F14E39F25}.Release|Any CPU.ActiveCfg = Release|Any CPU + {F589AB00-F69A-4826-BE33-662F14E39F25}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/COP/WinFormsApp1/Form1.Designer.cs b/COP/WinFormsApp1/Form1.Designer.cs new file mode 100644 index 0000000..b1a57bb --- /dev/null +++ b/COP/WinFormsApp1/Form1.Designer.cs @@ -0,0 +1,39 @@ +namespace WinFormsApp1 +{ + partial class Form + { + /// + /// 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.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(800, 450); + this.Text = "Form"; + } + + #endregion + } +} \ No newline at end of file diff --git a/COP/WinFormsApp1/Form1.cs b/COP/WinFormsApp1/Form1.cs new file mode 100644 index 0000000..a9d1ecb --- /dev/null +++ b/COP/WinFormsApp1/Form1.cs @@ -0,0 +1,10 @@ +namespace WinFormsApp1 +{ + public partial class Form : Form + { + public Form() + { + InitializeComponent(); + } + } +} \ No newline at end of file diff --git a/COP/WinFormsApp1/Form1.resx b/COP/WinFormsApp1/Form1.resx new file mode 100644 index 0000000..1af7de1 --- /dev/null +++ b/COP/WinFormsApp1/Form1.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/COP/WinFormsApp1/Program.cs b/COP/WinFormsApp1/Program.cs new file mode 100644 index 0000000..19eec1e --- /dev/null +++ b/COP/WinFormsApp1/Program.cs @@ -0,0 +1,17 @@ +namespace WinFormsApp1 +{ + 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 Form()); + } + } +} \ No newline at end of file diff --git a/COP/WinFormsApp1/WinForms.csproj b/COP/WinFormsApp1/WinForms.csproj new file mode 100644 index 0000000..b57c89e --- /dev/null +++ b/COP/WinFormsApp1/WinForms.csproj @@ -0,0 +1,11 @@ + + + + WinExe + net6.0-windows + enable + true + enable + + + \ No newline at end of file diff --git a/COP/WinFormsTest/FormTest.Designer.cs b/COP/WinFormsTest/FormTest.Designer.cs new file mode 100644 index 0000000..3c9f63f --- /dev/null +++ b/COP/WinFormsTest/FormTest.Designer.cs @@ -0,0 +1,227 @@ +namespace WinFormsTest +{ + partial class FormTest + { + /// + /// 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.userCheckedListBox = new Components.Components.UserCheckedListBox(); + this.buttonAdd = new System.Windows.Forms.Button(); + this.buttonClear = new System.Windows.Forms.Button(); + this.buttonSelected = new System.Windows.Forms.Button(); + this.userDatePicker = new Components.Components.UserDatePicker(); + this.buttonBoundries = new System.Windows.Forms.Button(); + this.buttonSetDate = new System.Windows.Forms.Button(); + this.buttonGetDate = new System.Windows.Forms.Button(); + this.userTreeView = new Components.Components.UserTreeView(); + this.buttonSetHierarchy = new System.Windows.Forms.Button(); + this.buttonAddWorkers = new System.Windows.Forms.Button(); + this.buttonGetValue = new System.Windows.Forms.Button(); + this.buttonGetIndex = new System.Windows.Forms.Button(); + this.buttonSetIndex = new System.Windows.Forms.Button(); + this.SuspendLayout(); + // + // userCheckedListBox + // + this.userCheckedListBox.Location = new System.Drawing.Point(12, 12); + this.userCheckedListBox.Name = "userCheckedListBox"; + this.userCheckedListBox.selectedItem = null; + this.userCheckedListBox.Size = new System.Drawing.Size(170, 134); + this.userCheckedListBox.TabIndex = 0; + this.userCheckedListBox.SelectedItemChange += new System.Action(this.userCheckedListBox_SelectedItemChange); + // + // buttonAdd + // + this.buttonAdd.Location = new System.Drawing.Point(12, 143); + this.buttonAdd.Name = "buttonAdd"; + this.buttonAdd.Size = new System.Drawing.Size(150, 29); + this.buttonAdd.TabIndex = 1; + this.buttonAdd.Text = "Добавить"; + this.buttonAdd.UseVisualStyleBackColor = true; + this.buttonAdd.Click += new System.EventHandler(this.buttonAdd_Click); + // + // buttonClear + // + this.buttonClear.Location = new System.Drawing.Point(12, 178); + this.buttonClear.Name = "buttonClear"; + this.buttonClear.Size = new System.Drawing.Size(150, 29); + this.buttonClear.TabIndex = 2; + this.buttonClear.Text = "Очистить"; + this.buttonClear.UseVisualStyleBackColor = true; + this.buttonClear.Click += new System.EventHandler(this.buttonClear_Click); + // + // buttonSelected + // + this.buttonSelected.Location = new System.Drawing.Point(12, 213); + this.buttonSelected.Name = "buttonSelected"; + this.buttonSelected.Size = new System.Drawing.Size(150, 48); + this.buttonSelected.TabIndex = 3; + this.buttonSelected.Text = "Выбранный элемент"; + this.buttonSelected.UseVisualStyleBackColor = true; + this.buttonSelected.Click += new System.EventHandler(this.buttonSelected_Click); + // + // userDatePicker + // + this.userDatePicker.dateFrom = null; + this.userDatePicker.dateTo = null; + this.userDatePicker.Location = new System.Drawing.Point(188, 12); + this.userDatePicker.Name = "userDatePicker"; + this.userDatePicker.Size = new System.Drawing.Size(275, 48); + this.userDatePicker.TabIndex = 4; + this.userDatePicker.DateChange += new System.Action(this.userDatePicker_DateChange); + this.userDatePicker.AutoSizeChanged += new System.EventHandler(this.userDatePicker_DateChange); + // + // buttonBoundries + // + this.buttonBoundries.Location = new System.Drawing.Point(188, 143); + this.buttonBoundries.Name = "buttonBoundries"; + this.buttonBoundries.Size = new System.Drawing.Size(254, 29); + this.buttonBoundries.TabIndex = 5; + this.buttonBoundries.Text = "Установить границы"; + this.buttonBoundries.UseVisualStyleBackColor = true; + this.buttonBoundries.Click += new System.EventHandler(this.buttonBoundries_Click); + // + // buttonSetDate + // + this.buttonSetDate.Location = new System.Drawing.Point(188, 178); + this.buttonSetDate.Name = "buttonSetDate"; + this.buttonSetDate.Size = new System.Drawing.Size(254, 29); + this.buttonSetDate.TabIndex = 6; + this.buttonSetDate.Text = "Установить значение"; + this.buttonSetDate.UseVisualStyleBackColor = true; + this.buttonSetDate.Click += new System.EventHandler(this.buttonSetDate_Click); + // + // buttonGetDate + // + this.buttonGetDate.Location = new System.Drawing.Point(188, 213); + this.buttonGetDate.Name = "buttonGetDate"; + this.buttonGetDate.Size = new System.Drawing.Size(254, 29); + this.buttonGetDate.TabIndex = 7; + this.buttonGetDate.Text = "Получить значение"; + this.buttonGetDate.UseVisualStyleBackColor = true; + this.buttonGetDate.Click += new System.EventHandler(this.buttonGetDate_Click); + // + // userTreeView + // + this.userTreeView.Location = new System.Drawing.Point(469, 12); + this.userTreeView.Name = "userTreeView"; + this.userTreeView.SelectedNodeIndex = -1; + this.userTreeView.Size = new System.Drawing.Size(369, 249); + this.userTreeView.TabIndex = 8; + // + // buttonSetHierarchy + // + this.buttonSetHierarchy.Location = new System.Drawing.Point(469, 257); + this.buttonSetHierarchy.Name = "buttonSetHierarchy"; + this.buttonSetHierarchy.Size = new System.Drawing.Size(296, 29); + this.buttonSetHierarchy.TabIndex = 9; + this.buttonSetHierarchy.Text = "Установить иерархию"; + this.buttonSetHierarchy.UseVisualStyleBackColor = true; + this.buttonSetHierarchy.Click += new System.EventHandler(this.buttonSetHierarchy_Click); + // + // buttonAddWorkers + // + this.buttonAddWorkers.Location = new System.Drawing.Point(469, 292); + this.buttonAddWorkers.Name = "buttonAddWorkers"; + this.buttonAddWorkers.Size = new System.Drawing.Size(296, 29); + this.buttonAddWorkers.TabIndex = 10; + this.buttonAddWorkers.Text = "Добавить рабочих"; + this.buttonAddWorkers.UseVisualStyleBackColor = true; + this.buttonAddWorkers.Click += new System.EventHandler(this.buttonAddWorkers_Click); + // + // buttonGetValue + // + this.buttonGetValue.Location = new System.Drawing.Point(469, 327); + this.buttonGetValue.Name = "buttonGetValue"; + this.buttonGetValue.Size = new System.Drawing.Size(296, 29); + this.buttonGetValue.TabIndex = 11; + this.buttonGetValue.Text = "Получить значение"; + this.buttonGetValue.UseVisualStyleBackColor = true; + this.buttonGetValue.Click += new System.EventHandler(this.buttonGetValue_Click); + // + // buttonGetIndex + // + this.buttonGetIndex.Location = new System.Drawing.Point(469, 362); + this.buttonGetIndex.Name = "buttonGetIndex"; + this.buttonGetIndex.Size = new System.Drawing.Size(296, 29); + this.buttonGetIndex.TabIndex = 12; + this.buttonGetIndex.Text = "Получить индекс"; + this.buttonGetIndex.UseVisualStyleBackColor = true; + this.buttonGetIndex.Click += new System.EventHandler(this.buttonGetIndex_Click); + // + // buttonSetIndex + // + this.buttonSetIndex.Location = new System.Drawing.Point(469, 397); + this.buttonSetIndex.Name = "buttonSetIndex"; + this.buttonSetIndex.Size = new System.Drawing.Size(296, 29); + this.buttonSetIndex.TabIndex = 13; + this.buttonSetIndex.Text = "Установить индекс"; + this.buttonSetIndex.UseVisualStyleBackColor = true; + this.buttonSetIndex.Click += new System.EventHandler(this.buttonSetIndex_Click); + // + // FormTest + // + this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(850, 450); + this.Controls.Add(this.buttonSetIndex); + this.Controls.Add(this.buttonGetIndex); + this.Controls.Add(this.buttonGetValue); + this.Controls.Add(this.buttonAddWorkers); + this.Controls.Add(this.buttonSetHierarchy); + this.Controls.Add(this.userTreeView); + this.Controls.Add(this.buttonGetDate); + this.Controls.Add(this.buttonSetDate); + this.Controls.Add(this.buttonBoundries); + this.Controls.Add(this.userDatePicker); + this.Controls.Add(this.buttonSelected); + this.Controls.Add(this.buttonClear); + this.Controls.Add(this.buttonAdd); + this.Controls.Add(this.userCheckedListBox); + this.Name = "FormTest"; + this.Text = "FormTest"; + this.ResumeLayout(false); + + } + + #endregion + + private Components.Components.UserCheckedListBox userCheckedListBox; + private Button buttonAdd; + private Button buttonClear; + private Button buttonSelected; + private Components.Components.UserDatePicker userDatePicker; + private Button buttonBoundries; + private Button buttonSetDate; + private Button buttonGetDate; + private Components.Components.UserTreeView userTreeView; + private Button buttonSetHierarchy; + private Button buttonAddWorkers; + private Button buttonGetValue; + private Button buttonGetIndex; + private Button buttonSetIndex; + } +} \ No newline at end of file diff --git a/COP/WinFormsTest/FormTest.cs b/COP/WinFormsTest/FormTest.cs new file mode 100644 index 0000000..f634b0a --- /dev/null +++ b/COP/WinFormsTest/FormTest.cs @@ -0,0 +1,137 @@ +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 WinFormsTest +{ + public partial class FormTest : Form + { + public FormTest() + { + InitializeComponent(); + } + + private void buttonAdd_Click(object sender, EventArgs e) + { + Random random = new Random(); + List items = new List(); + for (int i = 0; i < 3; i++) + { + items.Add("item" + random.Next(0, 10000)); + } + userCheckedListBox.addItems(items); + userCheckedListBox.selectedItem = items[1]; + } + + private void userCheckedListBox_SelectedItemChange(string obj) + { + MessageBox.Show(obj, "Select event"); + } + + private void buttonClear_Click(object sender, EventArgs e) + { + userCheckedListBox.clear(); + } + + private void buttonSelected_Click(object sender, EventArgs e) + { + MessageBox.Show(userCheckedListBox.selectedItem ?? "null", "By getter"); + } + + private void buttonBoundries_Click(object sender, EventArgs e) + { + userDatePicker.dateFrom = new DateTime(1970, 01, 01); + userDatePicker.dateTo = new DateTime(2010, 01, 01); + } + + private void buttonSetDate_Click(object sender, EventArgs e) + { + var result = MessageBox.Show("Установить значение в границах?", "Выбор", MessageBoxButtons.YesNo); + if (result == DialogResult.Yes) + { + userDatePicker.Value = new DateTime(2000, 01, 01); + } + else + { + userDatePicker.Value = new DateTime(1900, 01, 01); + } + } + + private void userDatePicker_DateChange(object sender, EventArgs e) + { + MessageBox.Show("ok"); + } + + private void userDatePicker_DateChange(DateTime obj) + { + MessageBox.Show(obj.ToShortDateString(), "Date change event"); + } + + private void buttonGetDate_Click(object sender, EventArgs e) + { + try + { + DateTime? date = userDatePicker.Value; + if (date.HasValue && date == new DateTime(2000, 01, 01)) + { + MessageBox.Show(date.Value.ToShortDateString(), "Через свойство", MessageBoxButtons.OK, MessageBoxIcon.Information); + } + else + { + MessageBox.Show("Дата не выбрана, дата выходит за пределы диапазона или диапазон не задан.", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + catch (DateBoundsNotSetException ex) + { + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + catch (DateOutOfBoundsException ex) + { + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void buttonSetHierarchy_Click(object sender, EventArgs e) + { + userTreeView.setHierarchy(new List<(string, bool)>() { ("department", false), ("groupNumber", false), ("name", true) }); + } + + private void buttonAddWorkers_Click(object sender, EventArgs e) + { + List workers = new List(); + workers.Add(new Worker("Отдел 1", 1, "Иванов")); + workers.Add(new Worker("Отдел 1", 1, "Петров")); + workers.Add(new Worker("Отдел 1", 1, "Иванов")); + workers.Add(new Worker("Отдел 1", 2, "Иванов")); + workers.Add(new Worker("Отдел 2", 1, "Иванов")); + workers.Add(new Worker("Отдел 2", 1, "Иванов")); + workers.Add(new Worker("Отдел 2", 1, "Петров")); + workers.Add(new Worker("Отдел 2", 2, "Иванов")); + userTreeView.addItems(workers); + } + + private void buttonGetValue_Click(object sender, EventArgs e) + { + Worker? worker = userTreeView.getSelecetedNodeValue(); + if (worker == null) return; + MessageBox.Show(worker.department + ", номер группы: " + worker.groupNumber + ", " + worker.name); + } + + private void buttonGetIndex_Click(object sender, EventArgs e) + { + MessageBox.Show(userTreeView.SelectedNodeIndex.ToString()); + } + + private void buttonSetIndex_Click(object sender, EventArgs e) + { + userTreeView.SelectedNodeIndex = 0; + } + } +} diff --git a/COP/WinFormsTest/FormTest.resx b/COP/WinFormsTest/FormTest.resx new file mode 100644 index 0000000..1af7de1 --- /dev/null +++ b/COP/WinFormsTest/FormTest.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/COP/WinFormsTest/Program.cs b/COP/WinFormsTest/Program.cs new file mode 100644 index 0000000..58dce58 --- /dev/null +++ b/COP/WinFormsTest/Program.cs @@ -0,0 +1,17 @@ +namespace WinFormsTest +{ + 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 FormTest()); + } + } +} \ No newline at end of file diff --git a/COP/WinFormsTest/WinFormsTest.csproj b/COP/WinFormsTest/WinFormsTest.csproj new file mode 100644 index 0000000..a813ce4 --- /dev/null +++ b/COP/WinFormsTest/WinFormsTest.csproj @@ -0,0 +1,15 @@ + + + + WinExe + net6.0-windows + enable + true + enable + + + + + + + \ No newline at end of file diff --git a/COP/WinFormsTest/Worker.cs b/COP/WinFormsTest/Worker.cs new file mode 100644 index 0000000..372d182 --- /dev/null +++ b/COP/WinFormsTest/Worker.cs @@ -0,0 +1,22 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace WinFormsTest +{ + public class Worker + { + public Worker(string department, int groupNumber, string name) + { + this.department = department; + this.groupNumber = groupNumber; + this.name = name; + } + + public string department; + public int groupNumber; + public string name; + } +}