diff --git a/Library36/Library36.sln b/Library36/Library36.sln new file mode 100644 index 0000000..ffc627b --- /dev/null +++ b/Library36/Library36.sln @@ -0,0 +1,34 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.11.35327.3 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Library36", "Library36\Library36.csproj", "{C00E43CC-2774-49D4-A88B-68511E92C85D}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Test", "Test\Test.csproj", "{C53E2551-8E80-4180-A4A9-61AA4A080C74}" + ProjectSection(ProjectDependencies) = postProject + {C00E43CC-2774-49D4-A88B-68511E92C85D} = {C00E43CC-2774-49D4-A88B-68511E92C85D} + EndProjectSection +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {C00E43CC-2774-49D4-A88B-68511E92C85D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {C00E43CC-2774-49D4-A88B-68511E92C85D}.Debug|Any CPU.Build.0 = Debug|Any CPU + {C00E43CC-2774-49D4-A88B-68511E92C85D}.Release|Any CPU.ActiveCfg = Release|Any CPU + {C00E43CC-2774-49D4-A88B-68511E92C85D}.Release|Any CPU.Build.0 = Release|Any CPU + {C53E2551-8E80-4180-A4A9-61AA4A080C74}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {C53E2551-8E80-4180-A4A9-61AA4A080C74}.Debug|Any CPU.Build.0 = Debug|Any CPU + {C53E2551-8E80-4180-A4A9-61AA4A080C74}.Release|Any CPU.ActiveCfg = Release|Any CPU + {C53E2551-8E80-4180-A4A9-61AA4A080C74}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {950FED72-BF84-4C12-94A7-ADBC5A288FDA} + EndGlobalSection +EndGlobal diff --git a/Library36/Library36/ColumnsConfiguratoin.cs b/Library36/Library36/ColumnsConfiguratoin.cs new file mode 100644 index 0000000..b780d1c --- /dev/null +++ b/Library36/Library36/ColumnsConfiguratoin.cs @@ -0,0 +1,11 @@ +namespace Library36 +{ + public class ColumnsConfiguratoin + { + public int ColumnsCount { get; set; } + public string[] NameColumn { get; set; } = Array.Empty(); + public int[] Width { get; set; } = { 0, 0 }; + public bool[] Visible { get; set; } = Array.Empty(); + public string[]? PropertiesObject { get; set; } + } +} diff --git a/Library36/Library36/CustomDataGridView.Designer.cs b/Library36/Library36/CustomDataGridView.Designer.cs new file mode 100644 index 0000000..4119fe7 --- /dev/null +++ b/Library36/Library36/CustomDataGridView.Designer.cs @@ -0,0 +1,67 @@ +namespace Library36 +{ + partial class CustomDataGridView + { + /// + /// Обязательная переменная конструктора. + /// + 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() + { + dataGridViewItems = new DataGridView(); + ((System.ComponentModel.ISupportInitialize)dataGridViewItems).BeginInit(); + SuspendLayout(); + // + // dataGridViewItems + // + dataGridViewItems.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right; + dataGridViewItems.BackgroundColor = SystemColors.ButtonHighlight; + dataGridViewItems.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; + dataGridViewItems.Location = new Point(0, 0); + dataGridViewItems.Margin = new Padding(4); + dataGridViewItems.MultiSelect = false; // <--- Добавлено для выбора только одной строки + dataGridViewItems.Name = "dataGridViewItems"; + dataGridViewItems.RowHeadersVisible = false; + dataGridViewItems.RowHeadersWidth = 51; + dataGridViewItems.RowTemplate.Height = 29; + dataGridViewItems.Size = new Size(729, 441); + dataGridViewItems.TabIndex = 0; + dataGridViewItems.SelectionMode = System.Windows.Forms.DataGridViewSelectionMode.FullRowSelect; + // + // CustomDataGridView + // + AutoScaleDimensions = new SizeF(10F, 25F); + AutoScaleMode = AutoScaleMode.Font; + Controls.Add(dataGridViewItems); + Margin = new Padding(4, 5, 4, 5); + Name = "CustomDataGridView"; + Size = new Size(729, 441); + ((System.ComponentModel.ISupportInitialize)dataGridViewItems).EndInit(); + ResumeLayout(false); + } + + #endregion + + private DataGridView dataGridViewItems; + } +} diff --git a/Library36/Library36/CustomDataGridView.cs b/Library36/Library36/CustomDataGridView.cs new file mode 100644 index 0000000..000be96 --- /dev/null +++ b/Library36/Library36/CustomDataGridView.cs @@ -0,0 +1,123 @@ +namespace Library36 +{ + public partial class CustomDataGridView : UserControl + { + private DataGridView dataGridView; + + public CustomDataGridView() + { + InitializeComponent(); + } + public DataGridViewRowCollection Rows + { + get { return dataGridViewItems.Rows; } + } + public int SelectedRow + { + get { return dataGridViewItems.SelectedRows[0].Index; } + set + { + if (dataGridViewItems.SelectedRows.Count <= value || value < 0) + throw new ArgumentException(string.Format("{0} is an invalid row index.", value)); + else + { + dataGridViewItems.ClearSelection(); + dataGridViewItems.Rows[value].Selected = true; + } + } + } + public void ClearDataGrid() + { + dataGridViewItems.DataSource = null; + dataGridViewItems.Rows.Clear(); + } + public void ConfigColumn(ColumnsConfiguratoin columnsData) + { + dataGridViewItems.ColumnCount = columnsData.ColumnsCount; + for (int i = 0; i < columnsData.ColumnsCount; i++) + { + dataGridViewItems.Columns[i].Name = columnsData.NameColumn[i]; + dataGridViewItems.Columns[i].Width = columnsData.Width[i]; + dataGridViewItems.Columns[i].Visible = columnsData.Visible[i]; + dataGridViewItems.Columns[i].DataPropertyName = columnsData.PropertiesObject[i]; + } + } + public T GetSelectedObjectInRow() where T : class, new() + { + T val = new(); + + var propertiesObj = typeof(T).GetProperties(); + foreach (var properties in propertiesObj) + { + bool propIsExist = false; + int columnIndex = 0; + for (; columnIndex < dataGridViewItems.Columns.Count; columnIndex++) + { + if (dataGridViewItems.Columns[columnIndex].DataPropertyName == properties.Name) + { + propIsExist = true; + break; + } + } + if (propIsExist) + { + object value = dataGridViewItems.SelectedRows[0].Cells[columnIndex].Value; + if (value == null || value == DBNull.Value) + { + if (properties.PropertyType == typeof(int?)) + { + properties.SetValue(val, null); + } + else if (properties.PropertyType.IsValueType) + { + properties.SetValue(val, Activator.CreateInstance(properties.PropertyType)); + } + } + else + { + try + { + if (properties.PropertyType == typeof(int?)) + { + if (int.TryParse(value.ToString(), out int intValue)) + { + properties.SetValue(val, intValue); + } + else + { + properties.SetValue(val, null); + } + } + else + { + properties.SetValue(val, Convert.ChangeType(value, properties.PropertyType)); + } + } + catch (Exception ex) + { + Console.WriteLine($"Ошибка преобразования для свойства {properties.Name}: {ex.Message}"); + } + } + } + } + + return val; + } + + public void AddItem(T item, int RowIndex, int ColumnIndex) + { + if (item == null) + return; + + string propertyName = dataGridViewItems.Columns[ColumnIndex].DataPropertyName.ToString(); + string? value = item.GetType().GetProperty(propertyName)?.GetValue(item)?.ToString(); + + if (RowIndex >= dataGridViewItems.Rows.Count) + { + dataGridViewItems.RowCount = RowIndex + 1; + } + + dataGridViewItems.Rows[RowIndex].Cells[ColumnIndex].Value = value; + } + } +} diff --git a/Library36/Library36/CustomDataGridView.resx b/Library36/Library36/CustomDataGridView.resx new file mode 100644 index 0000000..8b2ff64 --- /dev/null +++ b/Library36/Library36/CustomDataGridView.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/Library36/Library36/CustomListBox.Designer.cs b/Library36/Library36/CustomListBox.Designer.cs new file mode 100644 index 0000000..9e55dd8 --- /dev/null +++ b/Library36/Library36/CustomListBox.Designer.cs @@ -0,0 +1,61 @@ +namespace Library36 +{ + 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() + { + listBoxCustom = new ListBox(); + SuspendLayout(); + // + // listBoxCustom + // + listBoxCustom.Dock = DockStyle.Fill; + listBoxCustom.FormattingEnabled = true; + listBoxCustom.ItemHeight = 25; + listBoxCustom.Location = new Point(0, 0); + listBoxCustom.Margin = new Padding(4); + listBoxCustom.Name = "listBoxCustom"; + listBoxCustom.Size = new Size(306, 315); + listBoxCustom.TabIndex = 0; + listBoxCustom.SelectedIndexChanged += ListBox_SelectedIndexChanged; + // + // CustomListBox + // + AutoScaleDimensions = new SizeF(10F, 25F); + AutoScaleMode = AutoScaleMode.Font; + Controls.Add(listBoxCustom); + Margin = new Padding(4, 5, 4, 5); + Name = "CustomListBox"; + Size = new Size(306, 315); + ResumeLayout(false); + } + + #endregion + + private ListBox listBoxCustom; + } +} \ No newline at end of file diff --git a/Library36/Library36/CustomListBox.cs b/Library36/Library36/CustomListBox.cs new file mode 100644 index 0000000..51fd64d --- /dev/null +++ b/Library36/Library36/CustomListBox.cs @@ -0,0 +1,41 @@ +namespace Library36 +{ + public partial class CustomListBox : UserControl + { + private ListBox listBox; + public event EventHandler ValueChanged; + public CustomListBox() + { + InitializeComponent(); + } + private void ListBox_SelectedIndexChanged(object sender, EventArgs e) + { + ValueChanged?.Invoke(this, EventArgs.Empty); + } + public string SelectedValue + { + get => listBoxCustom.SelectedItem?.ToString() ?? string.Empty; + set + { + if (listBoxCustom.Items.Contains(value)) + listBoxCustom.SelectedItem = value; + } + } + public ListBox.ObjectCollection ItemCollection + { + get => listBoxCustom.Items; + } + public void ClearList() + { + listBoxCustom.Items.Clear(); + } + public void PopulateList(List items) + { + listBoxCustom.Items.Clear(); + foreach (var item in items) + { + listBoxCustom.Items.Add(item); + } + } + } +} diff --git a/Library36/Library36/CustomListBox.resx b/Library36/Library36/CustomListBox.resx new file mode 100644 index 0000000..8b2ff64 --- /dev/null +++ b/Library36/Library36/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/Library36/Library36/DateBoxWithNull.Designer.cs b/Library36/Library36/DateBoxWithNull.Designer.cs new file mode 100644 index 0000000..211fa15 --- /dev/null +++ b/Library36/Library36/DateBoxWithNull.Designer.cs @@ -0,0 +1,73 @@ +namespace Library36 +{ + partial class DateBoxWithNull + { + /// + /// Обязательная переменная конструктора. + /// + 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() + { + checkBoxNull = new CheckBox(); + textBoxDate = new TextBox(); + SuspendLayout(); + // + // checkBoxNull + // + checkBoxNull.AutoSize = true; + checkBoxNull.Location = new Point(5, 10); + checkBoxNull.Margin = new Padding(4, 4, 4, 4); + checkBoxNull.Name = "checkBoxNull"; + checkBoxNull.Size = new Size(22, 21); + checkBoxNull.TabIndex = 0; + checkBoxNull.UseVisualStyleBackColor = true; + checkBoxNull.CheckedChanged += CheckBoxNull_CheckedChanged; + // + // textBoxDate + // + textBoxDate.Location = new Point(35, 2); + textBoxDate.Margin = new Padding(4, 4, 4, 4); + textBoxDate.Name = "textBoxDate"; + textBoxDate.Size = new Size(283, 31); + textBoxDate.TabIndex = 1; + textBoxDate.TextChanged += TextBoxDate_TextChanged; + // + // DateBoxWithNull + // + AutoScaleDimensions = new SizeF(10F, 25F); + AutoScaleMode = AutoScaleMode.Font; + Controls.Add(textBoxDate); + Controls.Add(checkBoxNull); + Margin = new Padding(4, 4, 4, 4); + Name = "DateBoxWithNull"; + Size = new Size(334, 45); + ResumeLayout(false); + PerformLayout(); + } + + #endregion + + private CheckBox checkBoxNull; + private TextBox textBoxDate; + } +} diff --git a/Library36/Library36/DateBoxWithNull.cs b/Library36/Library36/DateBoxWithNull.cs new file mode 100644 index 0000000..3711b0b --- /dev/null +++ b/Library36/Library36/DateBoxWithNull.cs @@ -0,0 +1,50 @@ +using System.Globalization; +namespace Library36 +{ + public partial class DateBoxWithNull : UserControl + { + public event EventHandler? CombinedEvent; + public Exception? Error; + public DateBoxWithNull() + { + InitializeComponent(); + } + public DateTime? Value + { + get + { + if (!checkBoxNull.Checked) + { + if (string.IsNullOrEmpty(textBoxDate.Text)) + { + throw new NotFilledException("Text box can't be empty, click checkbox if value must be empty!"); + } + if (DateTime.TryParseExact(textBoxDate.Text, "dd.MM.yyyy", null, DateTimeStyles.None, out DateTime parsedDate)) + { + return parsedDate; + } + else + { + throw new ParseException($"Wrong format <{textBoxDate.Text}>!"); + } + } + return null; + } + set + { + bool isNull = value is null; + checkBoxNull.Checked = isNull; + textBoxDate.Text = isNull ? string.Empty : value?.ToString("dd.MM.yyyy"); + } + } + private void TextBoxDate_TextChanged(object sender, EventArgs e) + { + CombinedEvent?.Invoke(sender, e); + } + private void CheckBoxNull_CheckedChanged(object sender, EventArgs e) + { + textBoxDate.Enabled = !checkBoxNull.Checked; + CombinedEvent?.Invoke(sender, e); + } + } +} diff --git a/Library36/Library36/DateBoxWithNull.resx b/Library36/Library36/DateBoxWithNull.resx new file mode 100644 index 0000000..8b2ff64 --- /dev/null +++ b/Library36/Library36/DateBoxWithNull.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/Library36/Library36/Library36.csproj b/Library36/Library36/Library36.csproj new file mode 100644 index 0000000..060aa1c --- /dev/null +++ b/Library36/Library36/Library36.csproj @@ -0,0 +1,10 @@ + + + + net6.0-windows + enable + true + enable + + + diff --git a/Library36/Library36/NotFilledException.cs b/Library36/Library36/NotFilledException.cs new file mode 100644 index 0000000..21d2928 --- /dev/null +++ b/Library36/Library36/NotFilledException.cs @@ -0,0 +1,9 @@ +namespace Library36 +{ + public class NotFilledException : Exception + { + public NotFilledException() { } + public NotFilledException(string message) : base(message) { } + public NotFilledException(string message, Exception inner) : base(message, inner) { } + } +} diff --git a/Library36/Library36/ParseException.cs b/Library36/Library36/ParseException.cs new file mode 100644 index 0000000..971f381 --- /dev/null +++ b/Library36/Library36/ParseException.cs @@ -0,0 +1,9 @@ +namespace Library36 +{ + public class ParseException : Exception + { + public ParseException() { } + public ParseException(string message) : base(message) { } + public ParseException(string message, Exception innerException) : base(message, innerException) { } + } +} diff --git a/Library36/Test/FormTest.Designer.cs b/Library36/Test/FormTest.Designer.cs new file mode 100644 index 0000000..a6803d7 --- /dev/null +++ b/Library36/Test/FormTest.Designer.cs @@ -0,0 +1,222 @@ +using static System.Net.Mime.MediaTypeNames; +using System.Windows.Forms; +using System.Xml.Linq; +using Library36; + +namespace Test +{ + 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() + { + customDataGridView1 = new CustomDataGridView(); + customListBox1 = new CustomListBox(); + dateBoxWithNull1 = new DateBoxWithNull(); + buttonClear = new Button(); + buttonLoad = new Button(); + buttonClearTable = new Button(); + buttonTableAdd = new Button(); + buttonGetValue = new Button(); + buttonGetValueCheckBox = new Button(); + buttonSetValueCheckBox = new Button(); + buttonGetList = new Button(); + buttonAddOneRow = new Button(); + textBoxDate = new TextBox(); + SuspendLayout(); + // + // customDataGridView1 + // + customDataGridView1.Location = new Point(329, 16); + customDataGridView1.Margin = new Padding(4, 5, 4, 5); + customDataGridView1.Name = "customDataGridView1"; + customDataGridView1.Size = new Size(419, 289); + customDataGridView1.TabIndex = 0; + // + // customListBox1 + // + customListBox1.Location = new Point(15, 16); + customListBox1.Margin = new Padding(4, 5, 4, 5); + customListBox1.Name = "customListBox1"; + customListBox1.SelectedValue = ""; + customListBox1.Size = new Size(306, 232); + customListBox1.TabIndex = 1; + customListBox1.ValueChanged += CustomListBox1_ValueChanged; + // + // dateBoxWithNull1 + // + dateBoxWithNull1.Location = new Point(15, 314); + dateBoxWithNull1.Margin = new Padding(5); + dateBoxWithNull1.Name = "dateBoxWithNull1"; + dateBoxWithNull1.Size = new Size(306, 42); + dateBoxWithNull1.TabIndex = 2; + // + // buttonClear + // + buttonClear.Location = new Point(203, 257); + buttonClear.Margin = new Padding(4); + buttonClear.Name = "buttonClear"; + buttonClear.Size = new Size(118, 36); + buttonClear.TabIndex = 3; + buttonClear.Text = "Clear List"; + buttonClear.UseVisualStyleBackColor = true; + buttonClear.Click += buttonClear_Click; + // + // buttonLoad + // + buttonLoad.Location = new Point(15, 258); + buttonLoad.Margin = new Padding(4); + buttonLoad.Name = "buttonLoad"; + buttonLoad.Size = new Size(100, 36); + buttonLoad.TabIndex = 4; + buttonLoad.Text = "Load List"; + buttonLoad.UseVisualStyleBackColor = true; + buttonLoad.Click += buttonLoad_Click; + // + // buttonClearTable + // + buttonClearTable.Location = new Point(329, 314); + buttonClearTable.Margin = new Padding(4); + buttonClearTable.Name = "buttonClearTable"; + buttonClearTable.Size = new Size(103, 36); + buttonClearTable.TabIndex = 5; + buttonClearTable.Text = "Table clear"; + buttonClearTable.UseVisualStyleBackColor = true; + buttonClearTable.Click += buttonClearTable_Click; + // + // buttonTableAdd + // + buttonTableAdd.Location = new Point(440, 314); + buttonTableAdd.Margin = new Padding(4); + buttonTableAdd.Name = "buttonTableAdd"; + buttonTableAdd.Size = new Size(105, 36); + buttonTableAdd.TabIndex = 6; + buttonTableAdd.Text = "Add Table"; + buttonTableAdd.UseVisualStyleBackColor = true; + buttonTableAdd.Click += buttonTableAdd_Click; + // + // buttonGetValue + // + buttonGetValue.Location = new Point(553, 315); + buttonGetValue.Margin = new Padding(4); + buttonGetValue.Name = "buttonGetValue"; + buttonGetValue.Size = new Size(94, 36); + buttonGetValue.TabIndex = 7; + buttonGetValue.Text = "Get Value"; + buttonGetValue.UseVisualStyleBackColor = true; + buttonGetValue.Click += buttonGetValue_Click; + // + // buttonGetValueCheckBox + // + buttonGetValueCheckBox.Location = new Point(12, 358); + buttonGetValueCheckBox.Margin = new Padding(4); + buttonGetValueCheckBox.Name = "buttonGetValueCheckBox"; + buttonGetValueCheckBox.Size = new Size(103, 31); + buttonGetValueCheckBox.TabIndex = 8; + buttonGetValueCheckBox.Text = "Get value"; + buttonGetValueCheckBox.UseVisualStyleBackColor = true; + buttonGetValueCheckBox.Click += buttonGetValueCheckBox_Click; + // + // buttonSetValueCheckBox + // + buttonSetValueCheckBox.Location = new Point(271, 358); + buttonSetValueCheckBox.Margin = new Padding(4); + buttonSetValueCheckBox.Name = "buttonSetValueCheckBox"; + buttonSetValueCheckBox.Size = new Size(50, 31); + buttonSetValueCheckBox.TabIndex = 9; + buttonSetValueCheckBox.Text = "Set"; + buttonSetValueCheckBox.UseVisualStyleBackColor = true; + buttonSetValueCheckBox.Click += buttonSetDate_Click; + // + // buttonGetList + // + buttonGetList.Location = new Point(122, 257); + buttonGetList.Name = "buttonGetList"; + buttonGetList.Size = new Size(74, 36); + buttonGetList.TabIndex = 11; + buttonGetList.Text = "Get"; + buttonGetList.UseVisualStyleBackColor = true; + buttonGetList.Click += buttonGetList_Click; + // + // buttonAddOneRow + // + buttonAddOneRow.Location = new Point(654, 316); + buttonAddOneRow.Name = "buttonAddOneRow"; + buttonAddOneRow.Size = new Size(94, 34); + buttonAddOneRow.TabIndex = 12; + buttonAddOneRow.Text = "Add Row"; + buttonAddOneRow.UseVisualStyleBackColor = true; + buttonAddOneRow.Click += buttonAddOneRow_Click; + // + // textBoxDate + // + textBoxDate.Location = new Point(122, 358); + textBoxDate.Name = "textBoxDate"; + textBoxDate.Size = new Size(142, 31); + textBoxDate.TabIndex = 13; + // + // FormTest + // + AutoScaleDimensions = new SizeF(10F, 25F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(763, 398); + Controls.Add(textBoxDate); + Controls.Add(buttonAddOneRow); + Controls.Add(buttonGetList); + Controls.Add(buttonSetValueCheckBox); + Controls.Add(buttonGetValueCheckBox); + Controls.Add(buttonGetValue); + Controls.Add(buttonTableAdd); + Controls.Add(buttonClearTable); + Controls.Add(buttonLoad); + Controls.Add(buttonClear); + Controls.Add(dateBoxWithNull1); + Controls.Add(customListBox1); + Controls.Add(customDataGridView1); + Margin = new Padding(4); + Name = "FormTest"; + Text = "FormTest"; + ResumeLayout(false); + PerformLayout(); + } + + #endregion + + private Library36.CustomDataGridView customDataGridView1; + private Library36.CustomListBox customListBox1; + private Library36.DateBoxWithNull dateBoxWithNull1; + private Button buttonClear; + private Button buttonLoad; + private Button buttonClearTable; + private Button buttonTableAdd; + private Button buttonGetValue; + private Button buttonGetValueCheckBox; + private Button buttonSetValueCheckBox; + private Button buttonGetList; + private Button buttonAddOneRow; + private TextBox textBoxDate; + } +} diff --git a/Library36/Test/FormTest.cs b/Library36/Test/FormTest.cs new file mode 100644 index 0000000..aaaec01 --- /dev/null +++ b/Library36/Test/FormTest.cs @@ -0,0 +1,120 @@ +namespace Test +{ + public partial class FormTest : Form + { + private bool EmptyFill = false; + readonly List students = new() + { + new Student { Id = 0, Surname = "Elatomtsev", Height = 195, Iq = 155 }, + new Student { Id = 1, Surname = "Bakshaeva", Height = 150, Iq = 170 }, + new Student { Id = 2, Surname = "Firsov", Height = 180, Iq = 100 }, + new Student { Id = 3, Surname = "Razin", Height = 185, Iq = 140 }, + + }; + readonly List items = new() + { + new string("item1"), + new string("item2"), + new string("item3"), + new string("item4"), + new string("item5"), + new string("item6"), + new string("item7"), + + }; + public FormTest() + { + InitializeComponent(); + CreateList(); + } + private void CustomListBox1_ValueChanged(object sender, EventArgs e) + { + MessageBox.Show($"Selected item: {customListBox1.SelectedValue}"); + } + private void CreateList() + { + customListBox1.PopulateList(items); + } + private void buttonClear_Click(object sender, EventArgs e) + { + customListBox1.ClearList(); + } + private void buttonLoad_Click(object sender, EventArgs e) + { + CreateList(); + customListBox1.Refresh(); + } + private void buttonGetList_Click(object sender, EventArgs e) + { + string selectedValue = customListBox1.SelectedValue; + MessageBox.Show($"Selected Value: {selectedValue}"); + } + + + + + private void CreateTable() + { + customDataGridView1.ConfigColumn(new() + { + ColumnsCount = 4, + NameColumn = new string[] { "Id", "Surname", "Height", "Iq" }, + Width = new int[] { 10, 150, 250, 200 }, + Visible = new bool[] { false, true, true, true }, + PropertiesObject = new string[] { "Id", "Surname", "Height", "Iq" }, + }); + + foreach (Student student in students) + { + int rowIndex = customDataGridView1.Rows.Add(); + for (int i = 0; i < 4; i++) + { + customDataGridView1.AddItem(student, rowIndex, i); + } + } + } + private void buttonClearTable_Click(object sender, EventArgs e) + { + customDataGridView1.ClearDataGrid(); + } + private void buttonTableAdd_Click(object sender, EventArgs e) + { + CreateTable(); + } + private void buttonGetValue_Click(object sender, EventArgs e) + { + Student selectedStudent = customDataGridView1.GetSelectedObjectInRow(); + MessageBox.Show($"Selected Row Index: {customDataGridView1.SelectedRow}"); + MessageBox.Show($"Selected Student: {selectedStudent}"); + } + private void buttonAddOneRow_Click(object sender, EventArgs e) + { + Student newStudent = new Student { Id = 4, Surname = "New Student", Height = 185, Iq = 125 }; + int rowIndex = customDataGridView1.Rows.Add(); + for (int i = 0; i < 4; i++) + { + customDataGridView1.AddItem(newStudent, rowIndex, i); + } + } + + + + + + private void buttonGetValueCheckBox_Click(object sender, EventArgs e) + { + MessageBox.Show($"Value is {dateBoxWithNull1.Value}"); + } + private void buttonSetDate_Click(object sender, EventArgs e) + { + if (string.IsNullOrWhiteSpace(textBoxDate.Text)) + { + dateBoxWithNull1.Value = null; // null, textBox + } + else if (DateTime.TryParse(textBoxDate.Text, out DateTime date)) + { + dateBoxWithNull1.Value = date; + } + } + } +} diff --git a/Library36/Test/FormTest.resx b/Library36/Test/FormTest.resx new file mode 100644 index 0000000..8b2ff64 --- /dev/null +++ b/Library36/Test/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/Library36/Test/Program.cs b/Library36/Test/Program.cs new file mode 100644 index 0000000..afcacb8 --- /dev/null +++ b/Library36/Test/Program.cs @@ -0,0 +1,17 @@ +namespace Test +{ + 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/Library36/Test/Student.cs b/Library36/Test/Student.cs new file mode 100644 index 0000000..775374c --- /dev/null +++ b/Library36/Test/Student.cs @@ -0,0 +1,26 @@ +using static System.Windows.Forms.VisualStyles.VisualStyleElement; +using System.Xml.Linq; + +namespace Test +{ + public class Student + { + public int Id { get; set; } + public string Surname { get; set; } = string.Empty; + public int? Height { get; set; } + public int? Iq { get; set; } + public Student(int id, string surname, int? height, int? iq) + { + Id = id; + this.Surname = surname; + this.Height = height; + this.Iq = iq; + } + public Student() { } + public override string ToString() + { + return $"Surname: {Surname}, Iq: {Iq}"; + } + + } +} diff --git a/Library36/Test/Test.csproj b/Library36/Test/Test.csproj new file mode 100644 index 0000000..2a7964b --- /dev/null +++ b/Library36/Test/Test.csproj @@ -0,0 +1,15 @@ + + + + WinExe + net6.0-windows + enable + true + enable + + + + + + + \ No newline at end of file