From f455d5c1475ee0560945e775f6139a68714c3034 Mon Sep 17 00:00:00 2001 From: DavidMakarov Date: Thu, 3 Oct 2024 23:07:05 +0400 Subject: [PATCH 01/15] lab1 done --- WinFormsLibrary1.sln | 31 +++ WinFormsLibrary1/ColumnInfo.cs | 23 ++ WinFormsLibrary1/UncheckedNullException.cs | 14 + WinFormsLibrary1/UnexpectedTypeException.cs | 14 + WinFormsLibrary1/User.cs | 23 ++ .../UserControlIntegerInput.Designer.cs | 71 +++++ WinFormsLibrary1/UserControlIntegerInput.cs | 70 +++++ WinFormsLibrary1/UserControlIntegerInput.resx | 120 +++++++++ .../UserControlStringsListBox.Designer.cs | 58 +++++ WinFormsLibrary1/UserControlStringsListBox.cs | 70 +++++ .../UserControlStringsListBox.resx | 120 +++++++++ WinFormsLibrary1/UserControlTable.Designer.cs | 62 +++++ WinFormsLibrary1/UserControlTable.cs | 100 +++++++ WinFormsLibrary1/UserControlTable.resx | 120 +++++++++ WinFormsLibrary1/WinFormsLibrary1.csproj | 10 + WinFormsMain/Form1.Designer.cs | 244 ++++++++++++++++++ WinFormsMain/Form1.cs | 67 +++++ WinFormsMain/Form1.resx | 120 +++++++++ WinFormsMain/Program.cs | 17 ++ WinFormsMain/WinFormsMain.csproj | 15 ++ 20 files changed, 1369 insertions(+) create mode 100644 WinFormsLibrary1.sln create mode 100644 WinFormsLibrary1/ColumnInfo.cs create mode 100644 WinFormsLibrary1/UncheckedNullException.cs create mode 100644 WinFormsLibrary1/UnexpectedTypeException.cs create mode 100644 WinFormsLibrary1/User.cs create mode 100644 WinFormsLibrary1/UserControlIntegerInput.Designer.cs create mode 100644 WinFormsLibrary1/UserControlIntegerInput.cs create mode 100644 WinFormsLibrary1/UserControlIntegerInput.resx create mode 100644 WinFormsLibrary1/UserControlStringsListBox.Designer.cs create mode 100644 WinFormsLibrary1/UserControlStringsListBox.cs create mode 100644 WinFormsLibrary1/UserControlStringsListBox.resx create mode 100644 WinFormsLibrary1/UserControlTable.Designer.cs create mode 100644 WinFormsLibrary1/UserControlTable.cs create mode 100644 WinFormsLibrary1/UserControlTable.resx create mode 100644 WinFormsLibrary1/WinFormsLibrary1.csproj create mode 100644 WinFormsMain/Form1.Designer.cs create mode 100644 WinFormsMain/Form1.cs create mode 100644 WinFormsMain/Form1.resx create mode 100644 WinFormsMain/Program.cs create mode 100644 WinFormsMain/WinFormsMain.csproj diff --git a/WinFormsLibrary1.sln b/WinFormsLibrary1.sln new file mode 100644 index 0000000..497a321 --- /dev/null +++ b/WinFormsLibrary1.sln @@ -0,0 +1,31 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.9.34728.123 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "WinFormsLibrary1", "WinFormsLibrary1\WinFormsLibrary1.csproj", "{260D3E8C-3599-49F1-BF42-64A92DD0FB62}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WinFormsMain", "WinFormsMain\WinFormsMain.csproj", "{D671A342-9B1B-4662-B7CB-9E7382CCFBC7}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {260D3E8C-3599-49F1-BF42-64A92DD0FB62}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {260D3E8C-3599-49F1-BF42-64A92DD0FB62}.Debug|Any CPU.Build.0 = Debug|Any CPU + {260D3E8C-3599-49F1-BF42-64A92DD0FB62}.Release|Any CPU.ActiveCfg = Release|Any CPU + {260D3E8C-3599-49F1-BF42-64A92DD0FB62}.Release|Any CPU.Build.0 = Release|Any CPU + {D671A342-9B1B-4662-B7CB-9E7382CCFBC7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {D671A342-9B1B-4662-B7CB-9E7382CCFBC7}.Debug|Any CPU.Build.0 = Debug|Any CPU + {D671A342-9B1B-4662-B7CB-9E7382CCFBC7}.Release|Any CPU.ActiveCfg = Release|Any CPU + {D671A342-9B1B-4662-B7CB-9E7382CCFBC7}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {1208CC7E-AF27-4982-8E30-0DC89F09BBA6} + EndGlobalSection +EndGlobal diff --git a/WinFormsLibrary1/ColumnInfo.cs b/WinFormsLibrary1/ColumnInfo.cs new file mode 100644 index 0000000..f504008 --- /dev/null +++ b/WinFormsLibrary1/ColumnInfo.cs @@ -0,0 +1,23 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace WinFormsLibrary1 +{ + public class ColumnInfo + { + public string HeaderText { get; set; } = string.Empty; + public int Width { get; set; } + public bool Visible { get; set; } + public string Name { get; set; } = string.Empty; + public ColumnInfo(string headerText, string name, int width, bool visible) + { + HeaderText = headerText; + Name = name; + Width = width; + Visible = visible; + } + } +} diff --git a/WinFormsLibrary1/UncheckedNullException.cs b/WinFormsLibrary1/UncheckedNullException.cs new file mode 100644 index 0000000..73b6e8c --- /dev/null +++ b/WinFormsLibrary1/UncheckedNullException.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace WinFormsLibrary1 +{ + public class UncheckedNullException : Exception + { + public UncheckedNullException() { } + public UncheckedNullException(string message) : base(message) { } + } +} diff --git a/WinFormsLibrary1/UnexpectedTypeException.cs b/WinFormsLibrary1/UnexpectedTypeException.cs new file mode 100644 index 0000000..19eace9 --- /dev/null +++ b/WinFormsLibrary1/UnexpectedTypeException.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace WinFormsLibrary1 +{ + public class UnexpectedTypeException : Exception + { + public UnexpectedTypeException() { } + public UnexpectedTypeException(string message) : base(message) { } + } +} diff --git a/WinFormsLibrary1/User.cs b/WinFormsLibrary1/User.cs new file mode 100644 index 0000000..8a521b8 --- /dev/null +++ b/WinFormsLibrary1/User.cs @@ -0,0 +1,23 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace WinFormsLibrary1 +{ + public class User + { + public string username { get; private set; } + public string email { get; private set; } + public DateTime birthday { get; private set; } + + public User(string username, string email, DateTime birthday) + { + this.username = username; + this.email = email; + this.birthday = birthday; + } + + } +} diff --git a/WinFormsLibrary1/UserControlIntegerInput.Designer.cs b/WinFormsLibrary1/UserControlIntegerInput.Designer.cs new file mode 100644 index 0000000..e978ffc --- /dev/null +++ b/WinFormsLibrary1/UserControlIntegerInput.Designer.cs @@ -0,0 +1,71 @@ +namespace WinFormsLibrary1 +{ + partial class UserControlIntegerInput + { + /// + /// Обязательная переменная конструктора. + /// + 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() + { + textBoxInteger = new TextBox(); + checkBoxNullable = new CheckBox(); + SuspendLayout(); + // + // textBoxInteger + // + textBoxInteger.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right; + textBoxInteger.Location = new Point(24, 1); + textBoxInteger.Name = "textBoxInteger"; + textBoxInteger.Size = new Size(144, 23); + textBoxInteger.TabIndex = 0; + textBoxInteger.TextChanged += textBoxInteger_TextChanged; + // + // checkBoxNullable + // + checkBoxNullable.AutoSize = true; + checkBoxNullable.Location = new Point(3, 5); + checkBoxNullable.Name = "checkBoxNullable"; + checkBoxNullable.Size = new Size(15, 14); + checkBoxNullable.TabIndex = 1; + checkBoxNullable.UseVisualStyleBackColor = true; + checkBoxNullable.CheckedChanged += checkBoxNullable_CheckedChanged; + // + // UserControlIntegerInput + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + Controls.Add(checkBoxNullable); + Controls.Add(textBoxInteger); + Name = "UserControlIntegerInput"; + Size = new Size(171, 30); + ResumeLayout(false); + PerformLayout(); + } + + #endregion + + private TextBox textBoxInteger; + private CheckBox checkBoxNullable; + } +} diff --git a/WinFormsLibrary1/UserControlIntegerInput.cs b/WinFormsLibrary1/UserControlIntegerInput.cs new file mode 100644 index 0000000..3413573 --- /dev/null +++ b/WinFormsLibrary1/UserControlIntegerInput.cs @@ -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.Threading.Tasks; +using System.Windows.Forms; + +namespace WinFormsLibrary1 +{ + public partial class UserControlIntegerInput : UserControl + { + private event EventHandler? _elementChanged; + private event Action? _errorOccured; + public string Error { get; private set; } + public int? InputtedInteger + { + get + { + if (checkBoxNullable.Checked) + { + return null; + } + if (textBoxInteger.Text.Equals(string.Empty) || textBoxInteger.Text == null) + { + throw new UncheckedNullException("Input was null, but checkbox wasnt checked"); + } + if (Int32.TryParse(textBoxInteger.Text, out var number)) + { + return number; + } + throw new UnexpectedTypeException("Input was non integer"); + } + set + { + textBoxInteger.Text = value.ToString(); + checkBoxNullable.Checked = value == null; + } + } + public event EventHandler ElementChanged + { + add { _elementChanged += value; } + remove { _elementChanged -= value; } + } + public event Action AnErrorOccurred + { + add { _errorOccured += value; } + remove { _errorOccured -= value; } + } + public UserControlIntegerInput() + { + InitializeComponent(); + Error = string.Empty; + } + + private void textBoxInteger_TextChanged(object sender, EventArgs e) + { + _elementChanged?.Invoke(this, e); + } + + private void checkBoxNullable_CheckedChanged(object sender, EventArgs e) + { + textBoxInteger.Enabled = !checkBoxNullable.Checked; + textBoxInteger.Text = null; + _elementChanged?.Invoke(this, e); + } + } +} diff --git a/WinFormsLibrary1/UserControlIntegerInput.resx b/WinFormsLibrary1/UserControlIntegerInput.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/WinFormsLibrary1/UserControlIntegerInput.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/WinFormsLibrary1/UserControlStringsListBox.Designer.cs b/WinFormsLibrary1/UserControlStringsListBox.Designer.cs new file mode 100644 index 0000000..6b42aee --- /dev/null +++ b/WinFormsLibrary1/UserControlStringsListBox.Designer.cs @@ -0,0 +1,58 @@ +namespace WinFormsLibrary1 +{ + partial class UserControlStringsListBox + { + /// + /// Обязательная переменная конструктора. + /// + 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() + { + listBoxStrings = new ListBox(); + SuspendLayout(); + // + // listBoxStrings + // + listBoxStrings.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right; + listBoxStrings.FormattingEnabled = true; + listBoxStrings.ItemHeight = 15; + listBoxStrings.Location = new Point(3, 3); + listBoxStrings.Name = "listBoxStrings"; + listBoxStrings.Size = new Size(144, 139); + listBoxStrings.TabIndex = 0; + listBoxStrings.SelectedValueChanged += listBoxStrings_SelectedValueChanged; + // + // UserControlStringsListBox + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + Controls.Add(listBoxStrings); + Name = "UserControlStringsListBox"; + ResumeLayout(false); + } + + #endregion + + private ListBox listBoxStrings; + } +} diff --git a/WinFormsLibrary1/UserControlStringsListBox.cs b/WinFormsLibrary1/UserControlStringsListBox.cs new file mode 100644 index 0000000..0cf9580 --- /dev/null +++ b/WinFormsLibrary1/UserControlStringsListBox.cs @@ -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.Threading.Tasks; +using System.Windows.Forms; + +namespace WinFormsLibrary1 +{ + public partial class UserControlStringsListBox : UserControl + { + private event EventHandler? _listChanged; + private event Action? _errorOccured; + public string Error { get; private set; } + public string ListElement + { + get + { + return listBoxStrings.SelectedItem?.ToString(); + } + set + { + if (listBoxStrings.Items.Contains(value)) + { + listBoxStrings.SelectedItem = value; + } + } + } + public event EventHandler ListChanged + { + add { _listChanged += value; } + remove { _listChanged -= value; } + } + public event Action AnErrorOccurred + { + add { _errorOccured += value; } + remove { _errorOccured -= value; } + } + public UserControlStringsListBox() + { + InitializeComponent(); + Error = string.Empty; + } + + public void AddList(List l) + { + try + { + listBoxStrings.Items.AddRange(l.ToArray()); + } + catch (Exception ex) + { + Error = ex.Message; + _errorOccured?.Invoke(); + } + } + public void ClearList() + { + listBoxStrings.Items.Clear(); + } + + private void listBoxStrings_SelectedValueChanged(object sender, EventArgs e) + { + _listChanged?.Invoke(sender, e); + } + } +} diff --git a/WinFormsLibrary1/UserControlStringsListBox.resx b/WinFormsLibrary1/UserControlStringsListBox.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/WinFormsLibrary1/UserControlStringsListBox.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/WinFormsLibrary1/UserControlTable.Designer.cs b/WinFormsLibrary1/UserControlTable.Designer.cs new file mode 100644 index 0000000..9db1b39 --- /dev/null +++ b/WinFormsLibrary1/UserControlTable.Designer.cs @@ -0,0 +1,62 @@ +namespace WinFormsLibrary1 +{ + partial class UserControlTable + { + /// + /// Обязательная переменная конструктора. + /// + 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() + { + dataGridViewTable = new DataGridView(); + ((System.ComponentModel.ISupportInitialize)dataGridViewTable).BeginInit(); + SuspendLayout(); + // + // dataGridViewTable + // + dataGridViewTable.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right; + dataGridViewTable.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; + dataGridViewTable.Location = new Point(3, 3); + dataGridViewTable.Name = "dataGridViewTable"; + dataGridViewTable.RowHeadersVisible = false; + dataGridViewTable.RowTemplate.Height = 25; + dataGridViewTable.SelectionMode = DataGridViewSelectionMode.FullRowSelect; + dataGridViewTable.Size = new Size(325, 150); + dataGridViewTable.TabIndex = 0; + // + // UserControlTable + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + Controls.Add(dataGridViewTable); + Name = "UserControlTable"; + Size = new Size(331, 157); + ((System.ComponentModel.ISupportInitialize)dataGridViewTable).EndInit(); + ResumeLayout(false); + } + + #endregion + + private DataGridView dataGridViewTable; + } +} diff --git a/WinFormsLibrary1/UserControlTable.cs b/WinFormsLibrary1/UserControlTable.cs new file mode 100644 index 0000000..f341e31 --- /dev/null +++ b/WinFormsLibrary1/UserControlTable.cs @@ -0,0 +1,100 @@ +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 WinFormsLibrary1 +{ + public partial class UserControlTable : UserControl + { + public int index + { + get => dataGridViewTable.SelectedRows.Count > 0 ? dataGridViewTable.SelectedRows[0].Index : -1; + set + { + if (value >= 0 && value < dataGridViewTable.Rows.Count) + { + dataGridViewTable.ClearSelection(); + dataGridViewTable.Rows[value].Selected = true; + } + } + } + public UserControlTable() + { + InitializeComponent(); + } + + public void ConfigureColumns(List columnInfo) + { + dataGridViewTable.Columns.Clear(); + for (int i = 0; i < columnInfo.Count; i++) + { + DataGridViewTextBoxColumn column = new DataGridViewTextBoxColumn + { + Name = columnInfo[i].Name, + HeaderText = columnInfo[i].HeaderText, + Width = columnInfo[i].Width, + Visible = columnInfo[i].Visible, + }; + dataGridViewTable.Columns.Add(column); + } + } + + public void ClearRows() + { + dataGridViewTable.Rows.Clear(); + } + + public void AddObjectList(List os) + { + dataGridViewTable.DataSource = os ?? throw new ArgumentNullException(); + } + + public T GetObjectFromRow() + where T : new() + { + if (dataGridViewTable.SelectedRows.Count == 0) + { + throw new InvalidOperationException("At least one row must be selected"); + } + + T returnObject = new(); + + var selectedRow = dataGridViewTable.SelectedRows[0]; + var props = typeof(T).GetProperties(); + var cells = dataGridViewTable.Rows[selectedRow.Index].Cells; + + for (int i = 0; i < dataGridViewTable.ColumnCount; i++) + { + var curCell = cells[i]; + var prop = props.FirstOrDefault(x => x.Name == dataGridViewTable.Columns[i].Name); + prop?.SetValue(returnObject, curCell.Value); + } + return returnObject; + } + + public void AddList (List values) + { + ClearRows(); + var props = typeof(T).GetProperties(); + + foreach (T value in values) + { + int newRowInd = dataGridViewTable.Rows.Add(value); + foreach (DataGridViewColumn col in dataGridViewTable.Columns) + { + var prop = props.FirstOrDefault(x => x.Name == col.Name) + ?? throw new InvalidOperationException($"No property {col.Name} found in type {typeof(T).Name}"); + var val = prop.GetValue(value); + dataGridViewTable.Rows[newRowInd].Cells[col.Index].Value = val; + } + } + } + } +} diff --git a/WinFormsLibrary1/UserControlTable.resx b/WinFormsLibrary1/UserControlTable.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/WinFormsLibrary1/UserControlTable.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/WinFormsLibrary1/WinFormsLibrary1.csproj b/WinFormsLibrary1/WinFormsLibrary1.csproj new file mode 100644 index 0000000..3d78086 --- /dev/null +++ b/WinFormsLibrary1/WinFormsLibrary1.csproj @@ -0,0 +1,10 @@ + + + + net7.0-windows + enable + true + enable + + + diff --git a/WinFormsMain/Form1.Designer.cs b/WinFormsMain/Form1.Designer.cs new file mode 100644 index 0000000..6712231 --- /dev/null +++ b/WinFormsMain/Form1.Designer.cs @@ -0,0 +1,244 @@ +namespace WinFormsMain +{ + partial class Form1 + { + /// + /// 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() + { + groupBox1 = new GroupBox(); + buttonSetList = new Button(); + textBoxList = new TextBox(); + buttonCheckSelected = new Button(); + labelListStatus = new Label(); + label1 = new Label(); + buttonAddTestList = new Button(); + buttonClearList = new Button(); + userControlStringsListBox = new WinFormsLibrary1.UserControlStringsListBox(); + groupBox2 = new GroupBox(); + userControlTable = new WinFormsLibrary1.UserControlTable(); + groupBox3 = new GroupBox(); + buttonSetInputtedInteger = new Button(); + textBoxInputtedInteger = new TextBox(); + buttonGetInputtedValue = new Button(); + userControlIntegerInput = new WinFormsLibrary1.UserControlIntegerInput(); + groupBox1.SuspendLayout(); + groupBox2.SuspendLayout(); + groupBox3.SuspendLayout(); + SuspendLayout(); + // + // groupBox1 + // + groupBox1.Controls.Add(buttonSetList); + groupBox1.Controls.Add(textBoxList); + groupBox1.Controls.Add(buttonCheckSelected); + groupBox1.Controls.Add(labelListStatus); + groupBox1.Controls.Add(label1); + groupBox1.Controls.Add(buttonAddTestList); + groupBox1.Controls.Add(buttonClearList); + groupBox1.Controls.Add(userControlStringsListBox); + groupBox1.Location = new Point(12, 12); + groupBox1.Name = "groupBox1"; + groupBox1.Size = new Size(225, 413); + groupBox1.TabIndex = 0; + groupBox1.TabStop = false; + groupBox1.Text = "Визуальный компонент выбора"; + // + // buttonSetList + // + buttonSetList.Location = new Point(144, 300); + buttonSetList.Name = "buttonSetList"; + buttonSetList.Size = new Size(75, 23); + buttonSetList.TabIndex = 7; + buttonSetList.Text = "Выбрать"; + buttonSetList.UseVisualStyleBackColor = true; + buttonSetList.Click += buttonSetList_Click; + // + // textBoxList + // + textBoxList.Location = new Point(6, 300); + textBoxList.Name = "textBoxList"; + textBoxList.Size = new Size(132, 23); + textBoxList.TabIndex = 6; + // + // buttonCheckSelected + // + buttonCheckSelected.Location = new Point(6, 256); + buttonCheckSelected.Name = "buttonCheckSelected"; + buttonCheckSelected.Size = new Size(213, 33); + buttonCheckSelected.TabIndex = 5; + buttonCheckSelected.Text = "Выбранный элемент"; + buttonCheckSelected.UseVisualStyleBackColor = true; + buttonCheckSelected.Click += buttonCheckSelected_Click; + // + // labelListStatus + // + labelListStatus.AutoSize = true; + labelListStatus.Location = new Point(22, 387); + labelListStatus.Name = "labelListStatus"; + labelListStatus.Size = new Size(0, 15); + labelListStatus.TabIndex = 4; + // + // label1 + // + label1.AutoSize = true; + label1.Location = new Point(6, 360); + label1.Name = "label1"; + label1.Size = new Size(87, 15); + label1.TabIndex = 3; + label1.Text = "Статус списка:"; + // + // buttonAddTestList + // + buttonAddTestList.Location = new Point(6, 178); + buttonAddTestList.Name = "buttonAddTestList"; + buttonAddTestList.Size = new Size(213, 33); + buttonAddTestList.TabIndex = 2; + buttonAddTestList.Text = "Добавить список из 5 элементов"; + buttonAddTestList.UseVisualStyleBackColor = true; + buttonAddTestList.Click += buttonAddTestList_Click; + // + // buttonClearList + // + buttonClearList.Location = new Point(6, 217); + buttonClearList.Name = "buttonClearList"; + buttonClearList.Size = new Size(213, 33); + buttonClearList.TabIndex = 1; + buttonClearList.Text = "Очистить"; + buttonClearList.UseVisualStyleBackColor = true; + buttonClearList.Click += buttonClearList_Click; + // + // userControlStringsListBox + // + userControlStringsListBox.ListElement = ""; + userControlStringsListBox.Location = new Point(6, 22); + userControlStringsListBox.Name = "userControlStringsListBox"; + userControlStringsListBox.Size = new Size(213, 150); + userControlStringsListBox.TabIndex = 0; + userControlStringsListBox.ListChanged += userControlStringsListBox_ListChanged; + // + // groupBox2 + // + groupBox2.Controls.Add(userControlTable); + groupBox2.Location = new Point(496, 12); + groupBox2.Name = "groupBox2"; + groupBox2.Size = new Size(344, 323); + groupBox2.TabIndex = 1; + groupBox2.TabStop = false; + groupBox2.Text = "Визуальный компонент вывода списков"; + // + // userControlTable + // + userControlTable.index = -1; + userControlTable.Location = new Point(7, 22); + userControlTable.Name = "userControlTable"; + userControlTable.Size = new Size(331, 157); + userControlTable.TabIndex = 0; + // + // groupBox3 + // + groupBox3.Controls.Add(buttonSetInputtedInteger); + groupBox3.Controls.Add(textBoxInputtedInteger); + groupBox3.Controls.Add(buttonGetInputtedValue); + groupBox3.Controls.Add(userControlIntegerInput); + groupBox3.Location = new Point(243, 12); + groupBox3.Name = "groupBox3"; + groupBox3.Size = new Size(247, 384); + groupBox3.TabIndex = 2; + groupBox3.TabStop = false; + groupBox3.Text = "Визуальный компонент ввода"; + // + // buttonSetInputtedInteger + // + buttonSetInputtedInteger.Location = new Point(166, 115); + buttonSetInputtedInteger.Name = "buttonSetInputtedInteger"; + buttonSetInputtedInteger.Size = new Size(75, 23); + buttonSetInputtedInteger.TabIndex = 8; + buttonSetInputtedInteger.Text = "Заменить"; + buttonSetInputtedInteger.UseVisualStyleBackColor = true; + buttonSetInputtedInteger.Click += buttonSetInputtedInteger_Click; + // + // textBoxInputtedInteger + // + textBoxInputtedInteger.Location = new Point(6, 115); + textBoxInputtedInteger.Name = "textBoxInputtedInteger"; + textBoxInputtedInteger.Size = new Size(154, 23); + textBoxInputtedInteger.TabIndex = 2; + // + // buttonGetInputtedValue + // + buttonGetInputtedValue.Location = new Point(6, 58); + buttonGetInputtedValue.Name = "buttonGetInputtedValue"; + buttonGetInputtedValue.Size = new Size(235, 42); + buttonGetInputtedValue.TabIndex = 1; + buttonGetInputtedValue.Text = "Получить значение"; + buttonGetInputtedValue.UseVisualStyleBackColor = true; + buttonGetInputtedValue.Click += buttonGetInputtedValue_Click; + // + // userControlIntegerInput + // + userControlIntegerInput.Location = new Point(6, 22); + userControlIntegerInput.Name = "userControlIntegerInput"; + userControlIntegerInput.Size = new Size(235, 30); + userControlIntegerInput.TabIndex = 0; + // + // Form1 + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(849, 437); + Controls.Add(groupBox3); + Controls.Add(groupBox2); + Controls.Add(groupBox1); + Name = "Form1"; + Text = "Основная форма"; + groupBox1.ResumeLayout(false); + groupBox1.PerformLayout(); + groupBox2.ResumeLayout(false); + groupBox3.ResumeLayout(false); + groupBox3.PerformLayout(); + ResumeLayout(false); + } + + #endregion + + private GroupBox groupBox1; + private WinFormsLibrary1.UserControlStringsListBox userControlStringsListBox; + private GroupBox groupBox2; + private WinFormsLibrary1.UserControlTable userControlTable; + private GroupBox groupBox3; + private WinFormsLibrary1.UserControlIntegerInput userControlIntegerInput; + private Button buttonAddTestList; + private Button buttonClearList; + private Label labelListStatus; + private Label label1; + private Button buttonCheckSelected; + private Button buttonGetInputtedValue; + private Button buttonSetList; + private TextBox textBoxList; + private Button buttonSetInputtedInteger; + private TextBox textBoxInputtedInteger; + } +} diff --git a/WinFormsMain/Form1.cs b/WinFormsMain/Form1.cs new file mode 100644 index 0000000..75abb3f --- /dev/null +++ b/WinFormsMain/Form1.cs @@ -0,0 +1,67 @@ +namespace WinFormsMain +{ + public partial class Form1 : Form + { + private Random rnd = new Random(); + public Form1() + { + InitializeComponent(); + } + + private void buttonAddTestList_Click(object sender, EventArgs e) + { + List testList = new List(); + for (int i = 0; i < 5; i++) + { + testList.Add("test " + i); + } + userControlStringsListBox.AddList(testList); + } + + private void buttonClearList_Click(object sender, EventArgs e) + { + userControlStringsListBox.ClearList(); + } + + private void userControlStringsListBox_ListChanged(object sender, EventArgs e) + { + labelListStatus.Text = userControlStringsListBox.ListElement; + } + + private void buttonCheckSelected_Click(object sender, EventArgs e) + { + MessageBox.Show(" \"" + userControlStringsListBox.ListElement + "\""); + } + + private void buttonSetList_Click(object sender, EventArgs e) + { + userControlStringsListBox.ListElement = textBoxList.Text; + } + + private void buttonSetInputtedInteger_Click(object sender, EventArgs e) + { + try + { + userControlIntegerInput.InputtedInteger = Convert.ToInt32(textBoxInputtedInteger.Text); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message); + } + } + + private void buttonGetInputtedValue_Click(object sender, EventArgs e) + { + int? i; + try + { + i = userControlIntegerInput.InputtedInteger; + MessageBox.Show(": \"" + i + "\""); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message); + } + } + } +} diff --git a/WinFormsMain/Form1.resx b/WinFormsMain/Form1.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/WinFormsMain/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/WinFormsMain/Program.cs b/WinFormsMain/Program.cs new file mode 100644 index 0000000..d7087fc --- /dev/null +++ b/WinFormsMain/Program.cs @@ -0,0 +1,17 @@ +namespace WinFormsMain +{ + 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 Form1()); + } + } +} \ No newline at end of file diff --git a/WinFormsMain/WinFormsMain.csproj b/WinFormsMain/WinFormsMain.csproj new file mode 100644 index 0000000..be88b1e --- /dev/null +++ b/WinFormsMain/WinFormsMain.csproj @@ -0,0 +1,15 @@ + + + + WinExe + net7.0-windows + enable + true + enable + + + + + + + \ No newline at end of file From 421ff97e84811c538f19fe929c43dc3c39c2f887 Mon Sep 17 00:00:00 2001 From: DavidMakarov Date: Thu, 3 Oct 2024 23:09:48 +0400 Subject: [PATCH 02/15] rename lib --- ...sLibrary1.sln => ComponentsProgramming.sln | 8 +- .../ColumnInfo.cs | 0 .../UncheckedNullException.cs | 0 .../UnexpectedTypeException.cs | 0 .../User.cs | 0 .../UserControlIntegerInput.Designer.cs | 0 .../UserControlIntegerInput.cs | 0 .../UserControlIntegerInput.resx | 0 .../UserControlStringsListBox.Designer.cs | 0 .../UserControlStringsListBox.cs | 0 .../UserControlStringsListBox.resx | 0 .../UserControlTable.Designer.cs | 0 .../UserControlTable.cs | 0 .../UserControlTable.resx | 0 .../VisualComponents.csproj | 0 WinFormsMain/Form1.Designer.cs | 244 ------------------ WinFormsMain/Form1.cs | 67 ----- WinFormsMain/Form1.resx | 120 --------- WinFormsMain/Program.cs | 17 -- WinFormsMain/WinFormsMain.csproj | 15 -- 20 files changed, 1 insertion(+), 470 deletions(-) rename WinFormsLibrary1.sln => ComponentsProgramming.sln (62%) rename {WinFormsLibrary1 => VisualComponents}/ColumnInfo.cs (100%) rename {WinFormsLibrary1 => VisualComponents}/UncheckedNullException.cs (100%) rename {WinFormsLibrary1 => VisualComponents}/UnexpectedTypeException.cs (100%) rename {WinFormsLibrary1 => VisualComponents}/User.cs (100%) rename {WinFormsLibrary1 => VisualComponents}/UserControlIntegerInput.Designer.cs (100%) rename {WinFormsLibrary1 => VisualComponents}/UserControlIntegerInput.cs (100%) rename {WinFormsLibrary1 => VisualComponents}/UserControlIntegerInput.resx (100%) rename {WinFormsLibrary1 => VisualComponents}/UserControlStringsListBox.Designer.cs (100%) rename {WinFormsLibrary1 => VisualComponents}/UserControlStringsListBox.cs (100%) rename {WinFormsLibrary1 => VisualComponents}/UserControlStringsListBox.resx (100%) rename {WinFormsLibrary1 => VisualComponents}/UserControlTable.Designer.cs (100%) rename {WinFormsLibrary1 => VisualComponents}/UserControlTable.cs (100%) rename {WinFormsLibrary1 => VisualComponents}/UserControlTable.resx (100%) rename WinFormsLibrary1/WinFormsLibrary1.csproj => VisualComponents/VisualComponents.csproj (100%) delete mode 100644 WinFormsMain/Form1.Designer.cs delete mode 100644 WinFormsMain/Form1.cs delete mode 100644 WinFormsMain/Form1.resx delete mode 100644 WinFormsMain/Program.cs delete mode 100644 WinFormsMain/WinFormsMain.csproj diff --git a/WinFormsLibrary1.sln b/ComponentsProgramming.sln similarity index 62% rename from WinFormsLibrary1.sln rename to ComponentsProgramming.sln index 497a321..d8c418e 100644 --- a/WinFormsLibrary1.sln +++ b/ComponentsProgramming.sln @@ -3,9 +3,7 @@ Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio Version 17 VisualStudioVersion = 17.9.34728.123 MinimumVisualStudioVersion = 10.0.40219.1 -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "WinFormsLibrary1", "WinFormsLibrary1\WinFormsLibrary1.csproj", "{260D3E8C-3599-49F1-BF42-64A92DD0FB62}" -EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WinFormsMain", "WinFormsMain\WinFormsMain.csproj", "{D671A342-9B1B-4662-B7CB-9E7382CCFBC7}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "VisualComponents", "WinFormsLibrary1\VisualComponents.csproj", "{260D3E8C-3599-49F1-BF42-64A92DD0FB62}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -17,10 +15,6 @@ Global {260D3E8C-3599-49F1-BF42-64A92DD0FB62}.Debug|Any CPU.Build.0 = Debug|Any CPU {260D3E8C-3599-49F1-BF42-64A92DD0FB62}.Release|Any CPU.ActiveCfg = Release|Any CPU {260D3E8C-3599-49F1-BF42-64A92DD0FB62}.Release|Any CPU.Build.0 = Release|Any CPU - {D671A342-9B1B-4662-B7CB-9E7382CCFBC7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {D671A342-9B1B-4662-B7CB-9E7382CCFBC7}.Debug|Any CPU.Build.0 = Debug|Any CPU - {D671A342-9B1B-4662-B7CB-9E7382CCFBC7}.Release|Any CPU.ActiveCfg = Release|Any CPU - {D671A342-9B1B-4662-B7CB-9E7382CCFBC7}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/WinFormsLibrary1/ColumnInfo.cs b/VisualComponents/ColumnInfo.cs similarity index 100% rename from WinFormsLibrary1/ColumnInfo.cs rename to VisualComponents/ColumnInfo.cs diff --git a/WinFormsLibrary1/UncheckedNullException.cs b/VisualComponents/UncheckedNullException.cs similarity index 100% rename from WinFormsLibrary1/UncheckedNullException.cs rename to VisualComponents/UncheckedNullException.cs diff --git a/WinFormsLibrary1/UnexpectedTypeException.cs b/VisualComponents/UnexpectedTypeException.cs similarity index 100% rename from WinFormsLibrary1/UnexpectedTypeException.cs rename to VisualComponents/UnexpectedTypeException.cs diff --git a/WinFormsLibrary1/User.cs b/VisualComponents/User.cs similarity index 100% rename from WinFormsLibrary1/User.cs rename to VisualComponents/User.cs diff --git a/WinFormsLibrary1/UserControlIntegerInput.Designer.cs b/VisualComponents/UserControlIntegerInput.Designer.cs similarity index 100% rename from WinFormsLibrary1/UserControlIntegerInput.Designer.cs rename to VisualComponents/UserControlIntegerInput.Designer.cs diff --git a/WinFormsLibrary1/UserControlIntegerInput.cs b/VisualComponents/UserControlIntegerInput.cs similarity index 100% rename from WinFormsLibrary1/UserControlIntegerInput.cs rename to VisualComponents/UserControlIntegerInput.cs diff --git a/WinFormsLibrary1/UserControlIntegerInput.resx b/VisualComponents/UserControlIntegerInput.resx similarity index 100% rename from WinFormsLibrary1/UserControlIntegerInput.resx rename to VisualComponents/UserControlIntegerInput.resx diff --git a/WinFormsLibrary1/UserControlStringsListBox.Designer.cs b/VisualComponents/UserControlStringsListBox.Designer.cs similarity index 100% rename from WinFormsLibrary1/UserControlStringsListBox.Designer.cs rename to VisualComponents/UserControlStringsListBox.Designer.cs diff --git a/WinFormsLibrary1/UserControlStringsListBox.cs b/VisualComponents/UserControlStringsListBox.cs similarity index 100% rename from WinFormsLibrary1/UserControlStringsListBox.cs rename to VisualComponents/UserControlStringsListBox.cs diff --git a/WinFormsLibrary1/UserControlStringsListBox.resx b/VisualComponents/UserControlStringsListBox.resx similarity index 100% rename from WinFormsLibrary1/UserControlStringsListBox.resx rename to VisualComponents/UserControlStringsListBox.resx diff --git a/WinFormsLibrary1/UserControlTable.Designer.cs b/VisualComponents/UserControlTable.Designer.cs similarity index 100% rename from WinFormsLibrary1/UserControlTable.Designer.cs rename to VisualComponents/UserControlTable.Designer.cs diff --git a/WinFormsLibrary1/UserControlTable.cs b/VisualComponents/UserControlTable.cs similarity index 100% rename from WinFormsLibrary1/UserControlTable.cs rename to VisualComponents/UserControlTable.cs diff --git a/WinFormsLibrary1/UserControlTable.resx b/VisualComponents/UserControlTable.resx similarity index 100% rename from WinFormsLibrary1/UserControlTable.resx rename to VisualComponents/UserControlTable.resx diff --git a/WinFormsLibrary1/WinFormsLibrary1.csproj b/VisualComponents/VisualComponents.csproj similarity index 100% rename from WinFormsLibrary1/WinFormsLibrary1.csproj rename to VisualComponents/VisualComponents.csproj diff --git a/WinFormsMain/Form1.Designer.cs b/WinFormsMain/Form1.Designer.cs deleted file mode 100644 index 6712231..0000000 --- a/WinFormsMain/Form1.Designer.cs +++ /dev/null @@ -1,244 +0,0 @@ -namespace WinFormsMain -{ - partial class Form1 - { - /// - /// 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() - { - groupBox1 = new GroupBox(); - buttonSetList = new Button(); - textBoxList = new TextBox(); - buttonCheckSelected = new Button(); - labelListStatus = new Label(); - label1 = new Label(); - buttonAddTestList = new Button(); - buttonClearList = new Button(); - userControlStringsListBox = new WinFormsLibrary1.UserControlStringsListBox(); - groupBox2 = new GroupBox(); - userControlTable = new WinFormsLibrary1.UserControlTable(); - groupBox3 = new GroupBox(); - buttonSetInputtedInteger = new Button(); - textBoxInputtedInteger = new TextBox(); - buttonGetInputtedValue = new Button(); - userControlIntegerInput = new WinFormsLibrary1.UserControlIntegerInput(); - groupBox1.SuspendLayout(); - groupBox2.SuspendLayout(); - groupBox3.SuspendLayout(); - SuspendLayout(); - // - // groupBox1 - // - groupBox1.Controls.Add(buttonSetList); - groupBox1.Controls.Add(textBoxList); - groupBox1.Controls.Add(buttonCheckSelected); - groupBox1.Controls.Add(labelListStatus); - groupBox1.Controls.Add(label1); - groupBox1.Controls.Add(buttonAddTestList); - groupBox1.Controls.Add(buttonClearList); - groupBox1.Controls.Add(userControlStringsListBox); - groupBox1.Location = new Point(12, 12); - groupBox1.Name = "groupBox1"; - groupBox1.Size = new Size(225, 413); - groupBox1.TabIndex = 0; - groupBox1.TabStop = false; - groupBox1.Text = "Визуальный компонент выбора"; - // - // buttonSetList - // - buttonSetList.Location = new Point(144, 300); - buttonSetList.Name = "buttonSetList"; - buttonSetList.Size = new Size(75, 23); - buttonSetList.TabIndex = 7; - buttonSetList.Text = "Выбрать"; - buttonSetList.UseVisualStyleBackColor = true; - buttonSetList.Click += buttonSetList_Click; - // - // textBoxList - // - textBoxList.Location = new Point(6, 300); - textBoxList.Name = "textBoxList"; - textBoxList.Size = new Size(132, 23); - textBoxList.TabIndex = 6; - // - // buttonCheckSelected - // - buttonCheckSelected.Location = new Point(6, 256); - buttonCheckSelected.Name = "buttonCheckSelected"; - buttonCheckSelected.Size = new Size(213, 33); - buttonCheckSelected.TabIndex = 5; - buttonCheckSelected.Text = "Выбранный элемент"; - buttonCheckSelected.UseVisualStyleBackColor = true; - buttonCheckSelected.Click += buttonCheckSelected_Click; - // - // labelListStatus - // - labelListStatus.AutoSize = true; - labelListStatus.Location = new Point(22, 387); - labelListStatus.Name = "labelListStatus"; - labelListStatus.Size = new Size(0, 15); - labelListStatus.TabIndex = 4; - // - // label1 - // - label1.AutoSize = true; - label1.Location = new Point(6, 360); - label1.Name = "label1"; - label1.Size = new Size(87, 15); - label1.TabIndex = 3; - label1.Text = "Статус списка:"; - // - // buttonAddTestList - // - buttonAddTestList.Location = new Point(6, 178); - buttonAddTestList.Name = "buttonAddTestList"; - buttonAddTestList.Size = new Size(213, 33); - buttonAddTestList.TabIndex = 2; - buttonAddTestList.Text = "Добавить список из 5 элементов"; - buttonAddTestList.UseVisualStyleBackColor = true; - buttonAddTestList.Click += buttonAddTestList_Click; - // - // buttonClearList - // - buttonClearList.Location = new Point(6, 217); - buttonClearList.Name = "buttonClearList"; - buttonClearList.Size = new Size(213, 33); - buttonClearList.TabIndex = 1; - buttonClearList.Text = "Очистить"; - buttonClearList.UseVisualStyleBackColor = true; - buttonClearList.Click += buttonClearList_Click; - // - // userControlStringsListBox - // - userControlStringsListBox.ListElement = ""; - userControlStringsListBox.Location = new Point(6, 22); - userControlStringsListBox.Name = "userControlStringsListBox"; - userControlStringsListBox.Size = new Size(213, 150); - userControlStringsListBox.TabIndex = 0; - userControlStringsListBox.ListChanged += userControlStringsListBox_ListChanged; - // - // groupBox2 - // - groupBox2.Controls.Add(userControlTable); - groupBox2.Location = new Point(496, 12); - groupBox2.Name = "groupBox2"; - groupBox2.Size = new Size(344, 323); - groupBox2.TabIndex = 1; - groupBox2.TabStop = false; - groupBox2.Text = "Визуальный компонент вывода списков"; - // - // userControlTable - // - userControlTable.index = -1; - userControlTable.Location = new Point(7, 22); - userControlTable.Name = "userControlTable"; - userControlTable.Size = new Size(331, 157); - userControlTable.TabIndex = 0; - // - // groupBox3 - // - groupBox3.Controls.Add(buttonSetInputtedInteger); - groupBox3.Controls.Add(textBoxInputtedInteger); - groupBox3.Controls.Add(buttonGetInputtedValue); - groupBox3.Controls.Add(userControlIntegerInput); - groupBox3.Location = new Point(243, 12); - groupBox3.Name = "groupBox3"; - groupBox3.Size = new Size(247, 384); - groupBox3.TabIndex = 2; - groupBox3.TabStop = false; - groupBox3.Text = "Визуальный компонент ввода"; - // - // buttonSetInputtedInteger - // - buttonSetInputtedInteger.Location = new Point(166, 115); - buttonSetInputtedInteger.Name = "buttonSetInputtedInteger"; - buttonSetInputtedInteger.Size = new Size(75, 23); - buttonSetInputtedInteger.TabIndex = 8; - buttonSetInputtedInteger.Text = "Заменить"; - buttonSetInputtedInteger.UseVisualStyleBackColor = true; - buttonSetInputtedInteger.Click += buttonSetInputtedInteger_Click; - // - // textBoxInputtedInteger - // - textBoxInputtedInteger.Location = new Point(6, 115); - textBoxInputtedInteger.Name = "textBoxInputtedInteger"; - textBoxInputtedInteger.Size = new Size(154, 23); - textBoxInputtedInteger.TabIndex = 2; - // - // buttonGetInputtedValue - // - buttonGetInputtedValue.Location = new Point(6, 58); - buttonGetInputtedValue.Name = "buttonGetInputtedValue"; - buttonGetInputtedValue.Size = new Size(235, 42); - buttonGetInputtedValue.TabIndex = 1; - buttonGetInputtedValue.Text = "Получить значение"; - buttonGetInputtedValue.UseVisualStyleBackColor = true; - buttonGetInputtedValue.Click += buttonGetInputtedValue_Click; - // - // userControlIntegerInput - // - userControlIntegerInput.Location = new Point(6, 22); - userControlIntegerInput.Name = "userControlIntegerInput"; - userControlIntegerInput.Size = new Size(235, 30); - userControlIntegerInput.TabIndex = 0; - // - // Form1 - // - AutoScaleDimensions = new SizeF(7F, 15F); - AutoScaleMode = AutoScaleMode.Font; - ClientSize = new Size(849, 437); - Controls.Add(groupBox3); - Controls.Add(groupBox2); - Controls.Add(groupBox1); - Name = "Form1"; - Text = "Основная форма"; - groupBox1.ResumeLayout(false); - groupBox1.PerformLayout(); - groupBox2.ResumeLayout(false); - groupBox3.ResumeLayout(false); - groupBox3.PerformLayout(); - ResumeLayout(false); - } - - #endregion - - private GroupBox groupBox1; - private WinFormsLibrary1.UserControlStringsListBox userControlStringsListBox; - private GroupBox groupBox2; - private WinFormsLibrary1.UserControlTable userControlTable; - private GroupBox groupBox3; - private WinFormsLibrary1.UserControlIntegerInput userControlIntegerInput; - private Button buttonAddTestList; - private Button buttonClearList; - private Label labelListStatus; - private Label label1; - private Button buttonCheckSelected; - private Button buttonGetInputtedValue; - private Button buttonSetList; - private TextBox textBoxList; - private Button buttonSetInputtedInteger; - private TextBox textBoxInputtedInteger; - } -} diff --git a/WinFormsMain/Form1.cs b/WinFormsMain/Form1.cs deleted file mode 100644 index 75abb3f..0000000 --- a/WinFormsMain/Form1.cs +++ /dev/null @@ -1,67 +0,0 @@ -namespace WinFormsMain -{ - public partial class Form1 : Form - { - private Random rnd = new Random(); - public Form1() - { - InitializeComponent(); - } - - private void buttonAddTestList_Click(object sender, EventArgs e) - { - List testList = new List(); - for (int i = 0; i < 5; i++) - { - testList.Add("test " + i); - } - userControlStringsListBox.AddList(testList); - } - - private void buttonClearList_Click(object sender, EventArgs e) - { - userControlStringsListBox.ClearList(); - } - - private void userControlStringsListBox_ListChanged(object sender, EventArgs e) - { - labelListStatus.Text = userControlStringsListBox.ListElement; - } - - private void buttonCheckSelected_Click(object sender, EventArgs e) - { - MessageBox.Show(" \"" + userControlStringsListBox.ListElement + "\""); - } - - private void buttonSetList_Click(object sender, EventArgs e) - { - userControlStringsListBox.ListElement = textBoxList.Text; - } - - private void buttonSetInputtedInteger_Click(object sender, EventArgs e) - { - try - { - userControlIntegerInput.InputtedInteger = Convert.ToInt32(textBoxInputtedInteger.Text); - } - catch (Exception ex) - { - MessageBox.Show(ex.Message); - } - } - - private void buttonGetInputtedValue_Click(object sender, EventArgs e) - { - int? i; - try - { - i = userControlIntegerInput.InputtedInteger; - MessageBox.Show(": \"" + i + "\""); - } - catch (Exception ex) - { - MessageBox.Show(ex.Message); - } - } - } -} diff --git a/WinFormsMain/Form1.resx b/WinFormsMain/Form1.resx deleted file mode 100644 index af32865..0000000 --- a/WinFormsMain/Form1.resx +++ /dev/null @@ -1,120 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 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/WinFormsMain/Program.cs b/WinFormsMain/Program.cs deleted file mode 100644 index d7087fc..0000000 --- a/WinFormsMain/Program.cs +++ /dev/null @@ -1,17 +0,0 @@ -namespace WinFormsMain -{ - 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 Form1()); - } - } -} \ No newline at end of file diff --git a/WinFormsMain/WinFormsMain.csproj b/WinFormsMain/WinFormsMain.csproj deleted file mode 100644 index be88b1e..0000000 --- a/WinFormsMain/WinFormsMain.csproj +++ /dev/null @@ -1,15 +0,0 @@ - - - - WinExe - net7.0-windows - enable - true - enable - - - - - - - \ No newline at end of file From 8da8edca170b4f015b23ec665b925d6f34b8cc07 Mon Sep 17 00:00:00 2001 From: DavidMakarov Date: Thu, 3 Oct 2024 23:11:39 +0400 Subject: [PATCH 03/15] sln file fix --- ComponentsProgramming.sln | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ComponentsProgramming.sln b/ComponentsProgramming.sln index d8c418e..eb95f1b 100644 --- a/ComponentsProgramming.sln +++ b/ComponentsProgramming.sln @@ -3,7 +3,7 @@ Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio Version 17 VisualStudioVersion = 17.9.34728.123 MinimumVisualStudioVersion = 10.0.40219.1 -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "VisualComponents", "WinFormsLibrary1\VisualComponents.csproj", "{260D3E8C-3599-49F1-BF42-64A92DD0FB62}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "VisualComponents", "VisualComponents\VisualComponents.csproj", "{260D3E8C-3599-49F1-BF42-64A92DD0FB62}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution From 637271039c417ba620f85abe6b2b9727906d3361 Mon Sep 17 00:00:00 2001 From: DavidMakarov Date: Thu, 3 Oct 2024 23:14:26 +0400 Subject: [PATCH 04/15] rename winformslib --- {VisualComponents => Components}/ColumnInfo.cs | 0 .../VisualComponents.csproj => Components/Components.csproj | 0 {VisualComponents => Components}/UncheckedNullException.cs | 0 {VisualComponents => Components}/UnexpectedTypeException.cs | 0 {VisualComponents => Components}/User.cs | 0 .../UserControlIntegerInput.Designer.cs | 0 {VisualComponents => Components}/UserControlIntegerInput.cs | 0 {VisualComponents => Components}/UserControlIntegerInput.resx | 0 .../UserControlStringsListBox.Designer.cs | 0 {VisualComponents => Components}/UserControlStringsListBox.cs | 0 {VisualComponents => Components}/UserControlStringsListBox.resx | 0 {VisualComponents => Components}/UserControlTable.Designer.cs | 0 {VisualComponents => Components}/UserControlTable.cs | 0 {VisualComponents => Components}/UserControlTable.resx | 0 ComponentsProgramming.sln | 2 +- 15 files changed, 1 insertion(+), 1 deletion(-) rename {VisualComponents => Components}/ColumnInfo.cs (100%) rename VisualComponents/VisualComponents.csproj => Components/Components.csproj (100%) rename {VisualComponents => Components}/UncheckedNullException.cs (100%) rename {VisualComponents => Components}/UnexpectedTypeException.cs (100%) rename {VisualComponents => Components}/User.cs (100%) rename {VisualComponents => Components}/UserControlIntegerInput.Designer.cs (100%) rename {VisualComponents => Components}/UserControlIntegerInput.cs (100%) rename {VisualComponents => Components}/UserControlIntegerInput.resx (100%) rename {VisualComponents => Components}/UserControlStringsListBox.Designer.cs (100%) rename {VisualComponents => Components}/UserControlStringsListBox.cs (100%) rename {VisualComponents => Components}/UserControlStringsListBox.resx (100%) rename {VisualComponents => Components}/UserControlTable.Designer.cs (100%) rename {VisualComponents => Components}/UserControlTable.cs (100%) rename {VisualComponents => Components}/UserControlTable.resx (100%) diff --git a/VisualComponents/ColumnInfo.cs b/Components/ColumnInfo.cs similarity index 100% rename from VisualComponents/ColumnInfo.cs rename to Components/ColumnInfo.cs diff --git a/VisualComponents/VisualComponents.csproj b/Components/Components.csproj similarity index 100% rename from VisualComponents/VisualComponents.csproj rename to Components/Components.csproj diff --git a/VisualComponents/UncheckedNullException.cs b/Components/UncheckedNullException.cs similarity index 100% rename from VisualComponents/UncheckedNullException.cs rename to Components/UncheckedNullException.cs diff --git a/VisualComponents/UnexpectedTypeException.cs b/Components/UnexpectedTypeException.cs similarity index 100% rename from VisualComponents/UnexpectedTypeException.cs rename to Components/UnexpectedTypeException.cs diff --git a/VisualComponents/User.cs b/Components/User.cs similarity index 100% rename from VisualComponents/User.cs rename to Components/User.cs diff --git a/VisualComponents/UserControlIntegerInput.Designer.cs b/Components/UserControlIntegerInput.Designer.cs similarity index 100% rename from VisualComponents/UserControlIntegerInput.Designer.cs rename to Components/UserControlIntegerInput.Designer.cs diff --git a/VisualComponents/UserControlIntegerInput.cs b/Components/UserControlIntegerInput.cs similarity index 100% rename from VisualComponents/UserControlIntegerInput.cs rename to Components/UserControlIntegerInput.cs diff --git a/VisualComponents/UserControlIntegerInput.resx b/Components/UserControlIntegerInput.resx similarity index 100% rename from VisualComponents/UserControlIntegerInput.resx rename to Components/UserControlIntegerInput.resx diff --git a/VisualComponents/UserControlStringsListBox.Designer.cs b/Components/UserControlStringsListBox.Designer.cs similarity index 100% rename from VisualComponents/UserControlStringsListBox.Designer.cs rename to Components/UserControlStringsListBox.Designer.cs diff --git a/VisualComponents/UserControlStringsListBox.cs b/Components/UserControlStringsListBox.cs similarity index 100% rename from VisualComponents/UserControlStringsListBox.cs rename to Components/UserControlStringsListBox.cs diff --git a/VisualComponents/UserControlStringsListBox.resx b/Components/UserControlStringsListBox.resx similarity index 100% rename from VisualComponents/UserControlStringsListBox.resx rename to Components/UserControlStringsListBox.resx diff --git a/VisualComponents/UserControlTable.Designer.cs b/Components/UserControlTable.Designer.cs similarity index 100% rename from VisualComponents/UserControlTable.Designer.cs rename to Components/UserControlTable.Designer.cs diff --git a/VisualComponents/UserControlTable.cs b/Components/UserControlTable.cs similarity index 100% rename from VisualComponents/UserControlTable.cs rename to Components/UserControlTable.cs diff --git a/VisualComponents/UserControlTable.resx b/Components/UserControlTable.resx similarity index 100% rename from VisualComponents/UserControlTable.resx rename to Components/UserControlTable.resx diff --git a/ComponentsProgramming.sln b/ComponentsProgramming.sln index eb95f1b..b8d9e2a 100644 --- a/ComponentsProgramming.sln +++ b/ComponentsProgramming.sln @@ -3,7 +3,7 @@ Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio Version 17 VisualStudioVersion = 17.9.34728.123 MinimumVisualStudioVersion = 10.0.40219.1 -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "VisualComponents", "VisualComponents\VisualComponents.csproj", "{260D3E8C-3599-49F1-BF42-64A92DD0FB62}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Components", "Components\Components.csproj", "{260D3E8C-3599-49F1-BF42-64A92DD0FB62}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution From 9cfa4fdf2a412a56754283163a3fc52b5a2658d4 Mon Sep 17 00:00:00 2001 From: DavidMakarov Date: Fri, 4 Oct 2024 00:04:22 +0400 Subject: [PATCH 05/15] add packages, 1 nonvisual comp of 3 is done --- Components/Components.csproj | 5 + .../UncheckedNullException.cs | 2 +- .../UnexpectedTypeException.cs | 2 +- .../UserControlTableDocument.Designer.cs | 36 ++++++ .../Nonvisual/UserControlTableDocument.cs | 36 ++++++ Components/SaveToPdf.cs | 117 ++++++++++++++++++ Components/SaveToPdfHelpers/PdfParagraph.cs | 9 ++ .../PdfParagraphAlignmentType.cs | 9 ++ .../SaveToPdfHelpers/PdfRowParameters.cs | 10 ++ Components/User.cs | 23 ---- Components/{ => Visual}/ColumnInfo.cs | 4 +- .../UserControlIntegerInput.Designer.cs | 2 +- .../{ => Visual}/UserControlIntegerInput.cs | 2 +- .../{ => Visual}/UserControlIntegerInput.resx | 0 .../UserControlStringsListBox.Designer.cs | 2 +- .../{ => Visual}/UserControlStringsListBox.cs | 2 +- .../UserControlStringsListBox.resx | 0 .../{ => Visual}/UserControlTable.Designer.cs | 2 +- Components/{ => Visual}/UserControlTable.cs | 3 +- Components/{ => Visual}/UserControlTable.resx | 0 20 files changed, 233 insertions(+), 33 deletions(-) rename Components/{ => Exceptions}/UncheckedNullException.cs (90%) rename Components/{ => Exceptions}/UnexpectedTypeException.cs (90%) create mode 100644 Components/Nonvisual/UserControlTableDocument.Designer.cs create mode 100644 Components/Nonvisual/UserControlTableDocument.cs create mode 100644 Components/SaveToPdf.cs create mode 100644 Components/SaveToPdfHelpers/PdfParagraph.cs create mode 100644 Components/SaveToPdfHelpers/PdfParagraphAlignmentType.cs create mode 100644 Components/SaveToPdfHelpers/PdfRowParameters.cs delete mode 100644 Components/User.cs rename Components/{ => Visual}/ColumnInfo.cs (89%) rename Components/{ => Visual}/UserControlIntegerInput.Designer.cs (98%) rename Components/{ => Visual}/UserControlIntegerInput.cs (98%) rename Components/{ => Visual}/UserControlIntegerInput.resx (100%) rename Components/{ => Visual}/UserControlStringsListBox.Designer.cs (98%) rename Components/{ => Visual}/UserControlStringsListBox.cs (98%) rename Components/{ => Visual}/UserControlStringsListBox.resx (100%) rename Components/{ => Visual}/UserControlTable.Designer.cs (98%) rename Components/{ => Visual}/UserControlTable.cs (98%) rename Components/{ => Visual}/UserControlTable.resx (100%) diff --git a/Components/Components.csproj b/Components/Components.csproj index 3d78086..3b33f9a 100644 --- a/Components/Components.csproj +++ b/Components/Components.csproj @@ -7,4 +7,9 @@ enable + + + + + diff --git a/Components/UncheckedNullException.cs b/Components/Exceptions/UncheckedNullException.cs similarity index 90% rename from Components/UncheckedNullException.cs rename to Components/Exceptions/UncheckedNullException.cs index 73b6e8c..e66fdae 100644 --- a/Components/UncheckedNullException.cs +++ b/Components/Exceptions/UncheckedNullException.cs @@ -4,7 +4,7 @@ using System.Linq; using System.Text; using System.Threading.Tasks; -namespace WinFormsLibrary1 +namespace Components.Exceptions { public class UncheckedNullException : Exception { diff --git a/Components/UnexpectedTypeException.cs b/Components/Exceptions/UnexpectedTypeException.cs similarity index 90% rename from Components/UnexpectedTypeException.cs rename to Components/Exceptions/UnexpectedTypeException.cs index 19eace9..e742c0a 100644 --- a/Components/UnexpectedTypeException.cs +++ b/Components/Exceptions/UnexpectedTypeException.cs @@ -4,7 +4,7 @@ using System.Linq; using System.Text; using System.Threading.Tasks; -namespace WinFormsLibrary1 +namespace Components.Exceptions { public class UnexpectedTypeException : Exception { diff --git a/Components/Nonvisual/UserControlTableDocument.Designer.cs b/Components/Nonvisual/UserControlTableDocument.Designer.cs new file mode 100644 index 0000000..525ee88 --- /dev/null +++ b/Components/Nonvisual/UserControlTableDocument.Designer.cs @@ -0,0 +1,36 @@ +namespace Components +{ + partial class UserControlTableDocument + { + /// + /// Обязательная переменная конструктора. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Освободить все используемые ресурсы. + /// + /// истинно, если управляемый ресурс должен быть удален; иначе ложно. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Код, автоматически созданный конструктором компонентов + + /// + /// Требуемый метод для поддержки конструктора — не изменяйте + /// содержимое этого метода с помощью редактора кода. + /// + private void InitializeComponent() + { + components = new System.ComponentModel.Container(); + } + + #endregion + } +} diff --git a/Components/Nonvisual/UserControlTableDocument.cs b/Components/Nonvisual/UserControlTableDocument.cs new file mode 100644 index 0000000..a1ce594 --- /dev/null +++ b/Components/Nonvisual/UserControlTableDocument.cs @@ -0,0 +1,36 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Diagnostics; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Components +{ + public partial class UserControlTableDocument : Component + { + public UserControlTableDocument() + { + InitializeComponent(); + } + + public UserControlTableDocument(IContainer container) + { + container.Add(this); + + InitializeComponent(); + } + + public void SaveToDocument(string filePath, string header, List tables) + { + if (string.IsNullOrEmpty(filePath)) throw new ArgumentNullException("Empty string instead of path to file"); + if (string.IsNullOrEmpty(header)) throw new ArgumentNullException("Header string is empty"); + if (tables.Count == 0) throw new ArgumentNullException("Table list is empty"); + + SaveToPdf saver = new SaveToPdf(); + + saver.CreateDoc(filePath, header, tables); + } + } +} diff --git a/Components/SaveToPdf.cs b/Components/SaveToPdf.cs new file mode 100644 index 0000000..7ac3f44 --- /dev/null +++ b/Components/SaveToPdf.cs @@ -0,0 +1,117 @@ +using MigraDoc.DocumentObjectModel; +using MigraDoc.DocumentObjectModel.Tables; +using MigraDoc.Rendering; +using Components.SaveToPdfHelpers; + +namespace Components +{ + internal class SaveToPdf + { + private Document? _document; + private Section? _section; + private Table? _table; + public void CreateDoc(string title, string path, List tables) + { + _document = new Document(); + DefineStyles(_document); + _section = _document.AddSection(); + + CreateParagraph(new PdfParagraph + { + Text = title, + Style = "NormalTitle", + ParagraphAlignment = PdfParagraphAlignmentType.Left + }); + + foreach (var table in tables) + { + if (table.Length == 0) continue; + + CreateTable(Enumerable.Repeat("3cm", table[0].Length).ToList()); + + foreach (var row in table) + { + CreateRow(new PdfRowParameters + { + Texts = row.ToList(), + Style = "Normal", + ParagraphAlignment = PdfParagraphAlignmentType.Left + }); + } + + CreateParagraph(new PdfParagraph()); + } + + var renderer = new PdfDocumentRenderer(true) + { + Document = _document + }; + renderer.RenderDocument(); + renderer.PdfDocument.Save(path); + } + private static ParagraphAlignment GetParagraphAlignment(PdfParagraphAlignmentType type) + { + return type switch + { + PdfParagraphAlignmentType.Center => ParagraphAlignment.Center, + PdfParagraphAlignmentType.Left => ParagraphAlignment.Left, + PdfParagraphAlignmentType.Right => ParagraphAlignment.Right, + _ => ParagraphAlignment.Justify, + }; + } + private static void DefineStyles(Document document) + { + var style = document.Styles["Normal"]; + style.Font.Name = "Times New Roman"; + style.Font.Size = 14; + style = document.Styles.AddStyle("NormalTitle", "Normal"); + style.Font.Bold = true; + } + protected void CreateParagraph(PdfParagraph pdfParagraph) + { + if (_section == null) + { + return; + } + var paragraph = _section.AddParagraph(pdfParagraph.Text); + paragraph.Format.SpaceAfter = "1cm"; + paragraph.Format.Alignment = GetParagraphAlignment(pdfParagraph.ParagraphAlignment); + paragraph.Style = pdfParagraph.Style; + } + protected void CreateTable(List columns) + { + if (_document == null) + { + return; + } + _table = _document.LastSection.AddTable(); + foreach (var elem in columns) + { + _table.AddColumn(elem); + } + } + protected void CreateRow(PdfRowParameters rowParameters) + { + if (_table == null) + { + return; + } + var row = _table.AddRow(); + for (int i = 0; i < rowParameters.Texts.Count; ++i) + { + row.Cells[i].AddParagraph(rowParameters.Texts[i]); + if (!string.IsNullOrEmpty(rowParameters.Style)) + { + row.Cells[i].Style = rowParameters.Style; + } + Unit borderWidth = 0.5; + row.Cells[i].Borders.Left.Width = borderWidth; + row.Cells[i].Borders.Right.Width = borderWidth; + row.Cells[i].Borders.Top.Width = borderWidth; + row.Cells[i].Borders.Bottom.Width = borderWidth; + row.Cells[i].Format.Alignment = GetParagraphAlignment(rowParameters.ParagraphAlignment); + row.Cells[i].VerticalAlignment = VerticalAlignment.Center; + } + } + } +} diff --git a/Components/SaveToPdfHelpers/PdfParagraph.cs b/Components/SaveToPdfHelpers/PdfParagraph.cs new file mode 100644 index 0000000..ac1f2ab --- /dev/null +++ b/Components/SaveToPdfHelpers/PdfParagraph.cs @@ -0,0 +1,9 @@ +namespace Components.SaveToPdfHelpers +{ + public class PdfParagraph + { + public string Text { get; set; } = string.Empty; + public string Style { get; set; } = string.Empty; + public PdfParagraphAlignmentType ParagraphAlignment { get; set; } + } +} diff --git a/Components/SaveToPdfHelpers/PdfParagraphAlignmentType.cs b/Components/SaveToPdfHelpers/PdfParagraphAlignmentType.cs new file mode 100644 index 0000000..bde3c13 --- /dev/null +++ b/Components/SaveToPdfHelpers/PdfParagraphAlignmentType.cs @@ -0,0 +1,9 @@ +namespace Components.SaveToPdfHelpers +{ + public enum PdfParagraphAlignmentType + { + Center, + Left, + Right + } +} diff --git a/Components/SaveToPdfHelpers/PdfRowParameters.cs b/Components/SaveToPdfHelpers/PdfRowParameters.cs new file mode 100644 index 0000000..76435a6 --- /dev/null +++ b/Components/SaveToPdfHelpers/PdfRowParameters.cs @@ -0,0 +1,10 @@ + +namespace Components.SaveToPdfHelpers +{ + public class PdfRowParameters + { + public List Texts { get; set; } = new(); + public string Style { get; set; } = string.Empty; + public PdfParagraphAlignmentType ParagraphAlignment { get; set; } + } +} diff --git a/Components/User.cs b/Components/User.cs deleted file mode 100644 index 8a521b8..0000000 --- a/Components/User.cs +++ /dev/null @@ -1,23 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace WinFormsLibrary1 -{ - public class User - { - public string username { get; private set; } - public string email { get; private set; } - public DateTime birthday { get; private set; } - - public User(string username, string email, DateTime birthday) - { - this.username = username; - this.email = email; - this.birthday = birthday; - } - - } -} diff --git a/Components/ColumnInfo.cs b/Components/Visual/ColumnInfo.cs similarity index 89% rename from Components/ColumnInfo.cs rename to Components/Visual/ColumnInfo.cs index f504008..553b5dd 100644 --- a/Components/ColumnInfo.cs +++ b/Components/Visual/ColumnInfo.cs @@ -4,12 +4,12 @@ using System.Linq; using System.Text; using System.Threading.Tasks; -namespace WinFormsLibrary1 +namespace Components.Visual { public class ColumnInfo { public string HeaderText { get; set; } = string.Empty; - public int Width { get; set; } + public int Width { get; set; } public bool Visible { get; set; } public string Name { get; set; } = string.Empty; public ColumnInfo(string headerText, string name, int width, bool visible) diff --git a/Components/UserControlIntegerInput.Designer.cs b/Components/Visual/UserControlIntegerInput.Designer.cs similarity index 98% rename from Components/UserControlIntegerInput.Designer.cs rename to Components/Visual/UserControlIntegerInput.Designer.cs index e978ffc..5a4661d 100644 --- a/Components/UserControlIntegerInput.Designer.cs +++ b/Components/Visual/UserControlIntegerInput.Designer.cs @@ -1,4 +1,4 @@ -namespace WinFormsLibrary1 +namespace Components { partial class UserControlIntegerInput { diff --git a/Components/UserControlIntegerInput.cs b/Components/Visual/UserControlIntegerInput.cs similarity index 98% rename from Components/UserControlIntegerInput.cs rename to Components/Visual/UserControlIntegerInput.cs index 3413573..1b0d204 100644 --- a/Components/UserControlIntegerInput.cs +++ b/Components/Visual/UserControlIntegerInput.cs @@ -8,7 +8,7 @@ using System.Text; using System.Threading.Tasks; using System.Windows.Forms; -namespace WinFormsLibrary1 +namespace Components { public partial class UserControlIntegerInput : UserControl { diff --git a/Components/UserControlIntegerInput.resx b/Components/Visual/UserControlIntegerInput.resx similarity index 100% rename from Components/UserControlIntegerInput.resx rename to Components/Visual/UserControlIntegerInput.resx diff --git a/Components/UserControlStringsListBox.Designer.cs b/Components/Visual/UserControlStringsListBox.Designer.cs similarity index 98% rename from Components/UserControlStringsListBox.Designer.cs rename to Components/Visual/UserControlStringsListBox.Designer.cs index 6b42aee..382b913 100644 --- a/Components/UserControlStringsListBox.Designer.cs +++ b/Components/Visual/UserControlStringsListBox.Designer.cs @@ -1,4 +1,4 @@ -namespace WinFormsLibrary1 +namespace Components { partial class UserControlStringsListBox { diff --git a/Components/UserControlStringsListBox.cs b/Components/Visual/UserControlStringsListBox.cs similarity index 98% rename from Components/UserControlStringsListBox.cs rename to Components/Visual/UserControlStringsListBox.cs index 0cf9580..8693f27 100644 --- a/Components/UserControlStringsListBox.cs +++ b/Components/Visual/UserControlStringsListBox.cs @@ -8,7 +8,7 @@ using System.Text; using System.Threading.Tasks; using System.Windows.Forms; -namespace WinFormsLibrary1 +namespace Components { public partial class UserControlStringsListBox : UserControl { diff --git a/Components/UserControlStringsListBox.resx b/Components/Visual/UserControlStringsListBox.resx similarity index 100% rename from Components/UserControlStringsListBox.resx rename to Components/Visual/UserControlStringsListBox.resx diff --git a/Components/UserControlTable.Designer.cs b/Components/Visual/UserControlTable.Designer.cs similarity index 98% rename from Components/UserControlTable.Designer.cs rename to Components/Visual/UserControlTable.Designer.cs index 9db1b39..01b9469 100644 --- a/Components/UserControlTable.Designer.cs +++ b/Components/Visual/UserControlTable.Designer.cs @@ -1,4 +1,4 @@ -namespace WinFormsLibrary1 +namespace Components { partial class UserControlTable { diff --git a/Components/UserControlTable.cs b/Components/Visual/UserControlTable.cs similarity index 98% rename from Components/UserControlTable.cs rename to Components/Visual/UserControlTable.cs index f341e31..b5e7041 100644 --- a/Components/UserControlTable.cs +++ b/Components/Visual/UserControlTable.cs @@ -8,8 +8,9 @@ using System.Reflection; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; +using Components.Visual; -namespace WinFormsLibrary1 +namespace Components { public partial class UserControlTable : UserControl { diff --git a/Components/UserControlTable.resx b/Components/Visual/UserControlTable.resx similarity index 100% rename from Components/UserControlTable.resx rename to Components/Visual/UserControlTable.resx From 9863bdba24ef05757ff5525f2cf6e8d605ff9819 Mon Sep 17 00:00:00 2001 From: DavidMakarov Date: Fri, 4 Oct 2024 06:47:49 +0400 Subject: [PATCH 06/15] update dirs --- .../UncheckedNullException.cs | 2 +- .../UnexpectedTypeException.cs | 2 +- Components/User.cs | 23 ------------------- Components/{ => Visual}/ColumnInfo.cs | 4 ++-- .../UserControlIntegerInput.Designer.cs | 0 .../{ => Visual}/UserControlIntegerInput.cs | 3 ++- .../{ => Visual}/UserControlIntegerInput.resx | 0 .../UserControlStringsListBox.Designer.cs | 0 .../{ => Visual}/UserControlStringsListBox.cs | 0 .../UserControlStringsListBox.resx | 0 .../{ => Visual}/UserControlTable.Designer.cs | 0 Components/{ => Visual}/UserControlTable.cs | 1 + Components/{ => Visual}/UserControlTable.resx | 0 13 files changed, 7 insertions(+), 28 deletions(-) rename Components/{ => Exceptions}/UncheckedNullException.cs (90%) rename Components/{ => Exceptions}/UnexpectedTypeException.cs (90%) delete mode 100644 Components/User.cs rename Components/{ => Visual}/ColumnInfo.cs (89%) rename Components/{ => Visual}/UserControlIntegerInput.Designer.cs (100%) rename Components/{ => Visual}/UserControlIntegerInput.cs (97%) rename Components/{ => Visual}/UserControlIntegerInput.resx (100%) rename Components/{ => Visual}/UserControlStringsListBox.Designer.cs (100%) rename Components/{ => Visual}/UserControlStringsListBox.cs (100%) rename Components/{ => Visual}/UserControlStringsListBox.resx (100%) rename Components/{ => Visual}/UserControlTable.Designer.cs (100%) rename Components/{ => Visual}/UserControlTable.cs (99%) rename Components/{ => Visual}/UserControlTable.resx (100%) diff --git a/Components/UncheckedNullException.cs b/Components/Exceptions/UncheckedNullException.cs similarity index 90% rename from Components/UncheckedNullException.cs rename to Components/Exceptions/UncheckedNullException.cs index 73b6e8c..e66fdae 100644 --- a/Components/UncheckedNullException.cs +++ b/Components/Exceptions/UncheckedNullException.cs @@ -4,7 +4,7 @@ using System.Linq; using System.Text; using System.Threading.Tasks; -namespace WinFormsLibrary1 +namespace Components.Exceptions { public class UncheckedNullException : Exception { diff --git a/Components/UnexpectedTypeException.cs b/Components/Exceptions/UnexpectedTypeException.cs similarity index 90% rename from Components/UnexpectedTypeException.cs rename to Components/Exceptions/UnexpectedTypeException.cs index 19eace9..e742c0a 100644 --- a/Components/UnexpectedTypeException.cs +++ b/Components/Exceptions/UnexpectedTypeException.cs @@ -4,7 +4,7 @@ using System.Linq; using System.Text; using System.Threading.Tasks; -namespace WinFormsLibrary1 +namespace Components.Exceptions { public class UnexpectedTypeException : Exception { diff --git a/Components/User.cs b/Components/User.cs deleted file mode 100644 index 8a521b8..0000000 --- a/Components/User.cs +++ /dev/null @@ -1,23 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace WinFormsLibrary1 -{ - public class User - { - public string username { get; private set; } - public string email { get; private set; } - public DateTime birthday { get; private set; } - - public User(string username, string email, DateTime birthday) - { - this.username = username; - this.email = email; - this.birthday = birthday; - } - - } -} diff --git a/Components/ColumnInfo.cs b/Components/Visual/ColumnInfo.cs similarity index 89% rename from Components/ColumnInfo.cs rename to Components/Visual/ColumnInfo.cs index f504008..553b5dd 100644 --- a/Components/ColumnInfo.cs +++ b/Components/Visual/ColumnInfo.cs @@ -4,12 +4,12 @@ using System.Linq; using System.Text; using System.Threading.Tasks; -namespace WinFormsLibrary1 +namespace Components.Visual { public class ColumnInfo { public string HeaderText { get; set; } = string.Empty; - public int Width { get; set; } + public int Width { get; set; } public bool Visible { get; set; } public string Name { get; set; } = string.Empty; public ColumnInfo(string headerText, string name, int width, bool visible) diff --git a/Components/UserControlIntegerInput.Designer.cs b/Components/Visual/UserControlIntegerInput.Designer.cs similarity index 100% rename from Components/UserControlIntegerInput.Designer.cs rename to Components/Visual/UserControlIntegerInput.Designer.cs diff --git a/Components/UserControlIntegerInput.cs b/Components/Visual/UserControlIntegerInput.cs similarity index 97% rename from Components/UserControlIntegerInput.cs rename to Components/Visual/UserControlIntegerInput.cs index 3413573..8754656 100644 --- a/Components/UserControlIntegerInput.cs +++ b/Components/Visual/UserControlIntegerInput.cs @@ -1,4 +1,5 @@ -using System; +using Components.Exceptions; +using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; diff --git a/Components/UserControlIntegerInput.resx b/Components/Visual/UserControlIntegerInput.resx similarity index 100% rename from Components/UserControlIntegerInput.resx rename to Components/Visual/UserControlIntegerInput.resx diff --git a/Components/UserControlStringsListBox.Designer.cs b/Components/Visual/UserControlStringsListBox.Designer.cs similarity index 100% rename from Components/UserControlStringsListBox.Designer.cs rename to Components/Visual/UserControlStringsListBox.Designer.cs diff --git a/Components/UserControlStringsListBox.cs b/Components/Visual/UserControlStringsListBox.cs similarity index 100% rename from Components/UserControlStringsListBox.cs rename to Components/Visual/UserControlStringsListBox.cs diff --git a/Components/UserControlStringsListBox.resx b/Components/Visual/UserControlStringsListBox.resx similarity index 100% rename from Components/UserControlStringsListBox.resx rename to Components/Visual/UserControlStringsListBox.resx diff --git a/Components/UserControlTable.Designer.cs b/Components/Visual/UserControlTable.Designer.cs similarity index 100% rename from Components/UserControlTable.Designer.cs rename to Components/Visual/UserControlTable.Designer.cs diff --git a/Components/UserControlTable.cs b/Components/Visual/UserControlTable.cs similarity index 99% rename from Components/UserControlTable.cs rename to Components/Visual/UserControlTable.cs index f341e31..5f3a2a8 100644 --- a/Components/UserControlTable.cs +++ b/Components/Visual/UserControlTable.cs @@ -8,6 +8,7 @@ using System.Reflection; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; +using Components.Visual; namespace WinFormsLibrary1 { diff --git a/Components/UserControlTable.resx b/Components/Visual/UserControlTable.resx similarity index 100% rename from Components/UserControlTable.resx rename to Components/Visual/UserControlTable.resx From 8db45c48bfc95f512201c153f2dbe737568f6d55 Mon Sep 17 00:00:00 2001 From: DavidMakarov Date: Fri, 4 Oct 2024 06:48:52 +0400 Subject: [PATCH 07/15] AddList fix --- Components/Visual/UserControlTable.cs | 35 ++++++++++++--------------- 1 file changed, 15 insertions(+), 20 deletions(-) diff --git a/Components/Visual/UserControlTable.cs b/Components/Visual/UserControlTable.cs index 5f3a2a8..872e3c5 100644 --- a/Components/Visual/UserControlTable.cs +++ b/Components/Visual/UserControlTable.cs @@ -52,9 +52,22 @@ namespace WinFormsLibrary1 dataGridViewTable.Rows.Clear(); } - public void AddObjectList(List os) + public void AddList(List values) { - dataGridViewTable.DataSource = os ?? throw new ArgumentNullException(); + ClearRows(); + var props = typeof(T).GetProperties(); + + foreach (T value in values) + { + int newRowInd = dataGridViewTable.Rows.Add(value); + foreach (DataGridViewColumn col in dataGridViewTable.Columns) + { + var prop = props.FirstOrDefault(x => x.Name == col.Name) + ?? throw new InvalidOperationException($"No property {col.Name} found in type {typeof(T).Name}"); + var val = prop.GetValue(value); + dataGridViewTable.Rows[newRowInd].Cells[col.Index].Value = val; + } + } } public T GetObjectFromRow() @@ -79,23 +92,5 @@ namespace WinFormsLibrary1 } return returnObject; } - - public void AddList (List values) - { - ClearRows(); - var props = typeof(T).GetProperties(); - - foreach (T value in values) - { - int newRowInd = dataGridViewTable.Rows.Add(value); - foreach (DataGridViewColumn col in dataGridViewTable.Columns) - { - var prop = props.FirstOrDefault(x => x.Name == col.Name) - ?? throw new InvalidOperationException($"No property {col.Name} found in type {typeof(T).Name}"); - var val = prop.GetValue(value); - dataGridViewTable.Rows[newRowInd].Cells[col.Index].Value = val; - } - } - } } } From a503ccac176c99813b939420be759e98418dfc87 Mon Sep 17 00:00:00 2001 From: DavidMakarov Date: Fri, 4 Oct 2024 11:08:12 +0400 Subject: [PATCH 08/15] fix AddList --- Components/Visual/UserControlTable.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Components/Visual/UserControlTable.cs b/Components/Visual/UserControlTable.cs index 872e3c5..f404238 100644 --- a/Components/Visual/UserControlTable.cs +++ b/Components/Visual/UserControlTable.cs @@ -59,7 +59,7 @@ namespace WinFormsLibrary1 foreach (T value in values) { - int newRowInd = dataGridViewTable.Rows.Add(value); + int newRowInd = dataGridViewTable.Rows.Add(); foreach (DataGridViewColumn col in dataGridViewTable.Columns) { var prop = props.FirstOrDefault(x => x.Name == col.Name) From 38db4c11d2e77c6f10b1bcf505e97e0948589ed0 Mon Sep 17 00:00:00 2001 From: DavidMakarov Date: Fri, 4 Oct 2024 11:22:00 +0400 Subject: [PATCH 09/15] add TestingForm --- Components/Visual/UserControlIntegerInput.cs | 3 +- ComponentsProgramming.sln | 6 + TestingForm/FormMain.Designer.cs | 45 +++++++ TestingForm/FormMain.cs | 10 ++ TestingForm/FormMain.resx | 120 +++++++++++++++++++ TestingForm/Program.cs | 17 +++ TestingForm/TestingForm.csproj | 15 +++ 7 files changed, 215 insertions(+), 1 deletion(-) create mode 100644 TestingForm/FormMain.Designer.cs create mode 100644 TestingForm/FormMain.cs create mode 100644 TestingForm/FormMain.resx create mode 100644 TestingForm/Program.cs create mode 100644 TestingForm/TestingForm.csproj diff --git a/Components/Visual/UserControlIntegerInput.cs b/Components/Visual/UserControlIntegerInput.cs index 1b0d204..b6f982c 100644 --- a/Components/Visual/UserControlIntegerInput.cs +++ b/Components/Visual/UserControlIntegerInput.cs @@ -1,4 +1,5 @@ -using System; +using Components.Exceptions; +using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; diff --git a/ComponentsProgramming.sln b/ComponentsProgramming.sln index b8d9e2a..af87b6f 100644 --- a/ComponentsProgramming.sln +++ b/ComponentsProgramming.sln @@ -5,6 +5,8 @@ VisualStudioVersion = 17.9.34728.123 MinimumVisualStudioVersion = 10.0.40219.1 Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Components", "Components\Components.csproj", "{260D3E8C-3599-49F1-BF42-64A92DD0FB62}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TestingForm", "TestingForm\TestingForm.csproj", "{4F4882A1-4DF1-4BC3-B022-9935E70E5552}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -15,6 +17,10 @@ Global {260D3E8C-3599-49F1-BF42-64A92DD0FB62}.Debug|Any CPU.Build.0 = Debug|Any CPU {260D3E8C-3599-49F1-BF42-64A92DD0FB62}.Release|Any CPU.ActiveCfg = Release|Any CPU {260D3E8C-3599-49F1-BF42-64A92DD0FB62}.Release|Any CPU.Build.0 = Release|Any CPU + {4F4882A1-4DF1-4BC3-B022-9935E70E5552}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {4F4882A1-4DF1-4BC3-B022-9935E70E5552}.Debug|Any CPU.Build.0 = Debug|Any CPU + {4F4882A1-4DF1-4BC3-B022-9935E70E5552}.Release|Any CPU.ActiveCfg = Release|Any CPU + {4F4882A1-4DF1-4BC3-B022-9935E70E5552}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/TestingForm/FormMain.Designer.cs b/TestingForm/FormMain.Designer.cs new file mode 100644 index 0000000..05ec2ff --- /dev/null +++ b/TestingForm/FormMain.Designer.cs @@ -0,0 +1,45 @@ +namespace TestingForm +{ + 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() + { + SuspendLayout(); + // + // FormMain + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(800, 450); + Name = "FormMain"; + Text = "cB"; + ResumeLayout(false); + } + + #endregion + } +} diff --git a/TestingForm/FormMain.cs b/TestingForm/FormMain.cs new file mode 100644 index 0000000..80839c4 --- /dev/null +++ b/TestingForm/FormMain.cs @@ -0,0 +1,10 @@ +namespace TestingForm +{ + public partial class FormMain : Form + { + public FormMain() + { + InitializeComponent(); + } + } +} diff --git a/TestingForm/FormMain.resx b/TestingForm/FormMain.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/TestingForm/FormMain.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/TestingForm/Program.cs b/TestingForm/Program.cs new file mode 100644 index 0000000..47a2336 --- /dev/null +++ b/TestingForm/Program.cs @@ -0,0 +1,17 @@ +namespace TestingForm +{ + 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/TestingForm/TestingForm.csproj b/TestingForm/TestingForm.csproj new file mode 100644 index 0000000..5a248b2 --- /dev/null +++ b/TestingForm/TestingForm.csproj @@ -0,0 +1,15 @@ + + + + WinExe + net7.0-windows + enable + true + enable + + + + + + + \ No newline at end of file From 6501dc17d8658b43e5ef34e22ef12694cca46555 Mon Sep 17 00:00:00 2001 From: DavidMakarov Date: Fri, 4 Oct 2024 11:42:32 +0400 Subject: [PATCH 10/15] fix UserControlTable --- Components/Visual/ColumnInfo.cs | 8 +------- Components/Visual/UserControlTable.cs | 7 ++++--- 2 files changed, 5 insertions(+), 10 deletions(-) diff --git a/Components/Visual/ColumnInfo.cs b/Components/Visual/ColumnInfo.cs index 553b5dd..08a8955 100644 --- a/Components/Visual/ColumnInfo.cs +++ b/Components/Visual/ColumnInfo.cs @@ -12,12 +12,6 @@ namespace Components.Visual public int Width { get; set; } public bool Visible { get; set; } public string Name { get; set; } = string.Empty; - public ColumnInfo(string headerText, string name, int width, bool visible) - { - HeaderText = headerText; - Name = name; - Width = width; - Visible = visible; - } + public string DataPropertyName { get; set; } = string.Empty; } } diff --git a/Components/Visual/UserControlTable.cs b/Components/Visual/UserControlTable.cs index f404238..e2e0157 100644 --- a/Components/Visual/UserControlTable.cs +++ b/Components/Visual/UserControlTable.cs @@ -42,6 +42,7 @@ namespace WinFormsLibrary1 HeaderText = columnInfo[i].HeaderText, Width = columnInfo[i].Width, Visible = columnInfo[i].Visible, + DataPropertyName = columnInfo[i].DataPropertyName, }; dataGridViewTable.Columns.Add(column); } @@ -62,8 +63,8 @@ namespace WinFormsLibrary1 int newRowInd = dataGridViewTable.Rows.Add(); foreach (DataGridViewColumn col in dataGridViewTable.Columns) { - var prop = props.FirstOrDefault(x => x.Name == col.Name) - ?? throw new InvalidOperationException($"No property {col.Name} found in type {typeof(T).Name}"); + var prop = props.FirstOrDefault(x => x.Name == col.DataPropertyName) + ?? throw new InvalidOperationException($"No property {col.DataPropertyName} found in type {typeof(T).Name}"); var val = prop.GetValue(value); dataGridViewTable.Rows[newRowInd].Cells[col.Index].Value = val; } @@ -87,7 +88,7 @@ namespace WinFormsLibrary1 for (int i = 0; i < dataGridViewTable.ColumnCount; i++) { var curCell = cells[i]; - var prop = props.FirstOrDefault(x => x.Name == dataGridViewTable.Columns[i].Name); + var prop = props.FirstOrDefault(x => x.Name == dataGridViewTable.Columns[i].DataPropertyName); prop?.SetValue(returnObject, curCell.Value); } return returnObject; From 7895adaa07b6c83dcc6734ab092d2745a7359d00 Mon Sep 17 00:00:00 2001 From: DavidMakarov Date: Fri, 4 Oct 2024 06:48:52 +0400 Subject: [PATCH 11/15] AddList fix --- Components/Visual/UserControlTable.cs | 35 ++++++++++++--------------- 1 file changed, 15 insertions(+), 20 deletions(-) diff --git a/Components/Visual/UserControlTable.cs b/Components/Visual/UserControlTable.cs index b5e7041..085905e 100644 --- a/Components/Visual/UserControlTable.cs +++ b/Components/Visual/UserControlTable.cs @@ -52,9 +52,22 @@ namespace Components dataGridViewTable.Rows.Clear(); } - public void AddObjectList(List os) + public void AddList(List values) { - dataGridViewTable.DataSource = os ?? throw new ArgumentNullException(); + ClearRows(); + var props = typeof(T).GetProperties(); + + foreach (T value in values) + { + int newRowInd = dataGridViewTable.Rows.Add(value); + foreach (DataGridViewColumn col in dataGridViewTable.Columns) + { + var prop = props.FirstOrDefault(x => x.Name == col.Name) + ?? throw new InvalidOperationException($"No property {col.Name} found in type {typeof(T).Name}"); + var val = prop.GetValue(value); + dataGridViewTable.Rows[newRowInd].Cells[col.Index].Value = val; + } + } } public T GetObjectFromRow() @@ -79,23 +92,5 @@ namespace Components } return returnObject; } - - public void AddList (List values) - { - ClearRows(); - var props = typeof(T).GetProperties(); - - foreach (T value in values) - { - int newRowInd = dataGridViewTable.Rows.Add(value); - foreach (DataGridViewColumn col in dataGridViewTable.Columns) - { - var prop = props.FirstOrDefault(x => x.Name == col.Name) - ?? throw new InvalidOperationException($"No property {col.Name} found in type {typeof(T).Name}"); - var val = prop.GetValue(value); - dataGridViewTable.Rows[newRowInd].Cells[col.Index].Value = val; - } - } - } } } From e3016a658775abff416371175747e42b776d8cd6 Mon Sep 17 00:00:00 2001 From: DavidMakarov Date: Fri, 4 Oct 2024 11:08:12 +0400 Subject: [PATCH 12/15] fix AddList --- Components/Visual/UserControlTable.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Components/Visual/UserControlTable.cs b/Components/Visual/UserControlTable.cs index 085905e..7398b83 100644 --- a/Components/Visual/UserControlTable.cs +++ b/Components/Visual/UserControlTable.cs @@ -59,7 +59,7 @@ namespace Components foreach (T value in values) { - int newRowInd = dataGridViewTable.Rows.Add(value); + int newRowInd = dataGridViewTable.Rows.Add(); foreach (DataGridViewColumn col in dataGridViewTable.Columns) { var prop = props.FirstOrDefault(x => x.Name == col.Name) From 8ab777b3b7160ac9ffa6e7ee0377de9ba64b08c1 Mon Sep 17 00:00:00 2001 From: DavidMakarov Date: Fri, 4 Oct 2024 11:42:32 +0400 Subject: [PATCH 13/15] fix UserControlTable --- Components/Visual/ColumnInfo.cs | 8 +------- Components/Visual/UserControlTable.cs | 7 ++++--- 2 files changed, 5 insertions(+), 10 deletions(-) diff --git a/Components/Visual/ColumnInfo.cs b/Components/Visual/ColumnInfo.cs index 553b5dd..08a8955 100644 --- a/Components/Visual/ColumnInfo.cs +++ b/Components/Visual/ColumnInfo.cs @@ -12,12 +12,6 @@ namespace Components.Visual public int Width { get; set; } public bool Visible { get; set; } public string Name { get; set; } = string.Empty; - public ColumnInfo(string headerText, string name, int width, bool visible) - { - HeaderText = headerText; - Name = name; - Width = width; - Visible = visible; - } + public string DataPropertyName { get; set; } = string.Empty; } } diff --git a/Components/Visual/UserControlTable.cs b/Components/Visual/UserControlTable.cs index 7398b83..116c37f 100644 --- a/Components/Visual/UserControlTable.cs +++ b/Components/Visual/UserControlTable.cs @@ -42,6 +42,7 @@ namespace Components HeaderText = columnInfo[i].HeaderText, Width = columnInfo[i].Width, Visible = columnInfo[i].Visible, + DataPropertyName = columnInfo[i].DataPropertyName, }; dataGridViewTable.Columns.Add(column); } @@ -62,8 +63,8 @@ namespace Components int newRowInd = dataGridViewTable.Rows.Add(); foreach (DataGridViewColumn col in dataGridViewTable.Columns) { - var prop = props.FirstOrDefault(x => x.Name == col.Name) - ?? throw new InvalidOperationException($"No property {col.Name} found in type {typeof(T).Name}"); + var prop = props.FirstOrDefault(x => x.Name == col.DataPropertyName) + ?? throw new InvalidOperationException($"No property {col.DataPropertyName} found in type {typeof(T).Name}"); var val = prop.GetValue(value); dataGridViewTable.Rows[newRowInd].Cells[col.Index].Value = val; } @@ -87,7 +88,7 @@ namespace Components for (int i = 0; i < dataGridViewTable.ColumnCount; i++) { var curCell = cells[i]; - var prop = props.FirstOrDefault(x => x.Name == dataGridViewTable.Columns[i].Name); + var prop = props.FirstOrDefault(x => x.Name == dataGridViewTable.Columns[i].DataPropertyName); prop?.SetValue(returnObject, curCell.Value); } return returnObject; From 2277c29e88232a0d8dbf22b2cc5fd29c72cf90c7 Mon Sep 17 00:00:00 2001 From: DavidMakarov Date: Fri, 4 Oct 2024 11:46:06 +0400 Subject: [PATCH 14/15] revert --- Components/Components.csproj | 5 + .../UncheckedNullException.cs | 2 +- .../UnexpectedTypeException.cs | 2 +- .../UserControlTableDocument.Designer.cs | 36 ++++++ .../Nonvisual/UserControlTableDocument.cs | 36 ++++++ Components/SaveToPdf.cs | 117 +++++++++++++++++ Components/SaveToPdfHelpers/PdfParagraph.cs | 9 ++ .../PdfParagraphAlignmentType.cs | 9 ++ .../SaveToPdfHelpers/PdfRowParameters.cs | 10 ++ Components/User.cs | 23 ---- Components/{ => Visual}/ColumnInfo.cs | 12 +- .../UserControlIntegerInput.Designer.cs | 2 +- .../{ => Visual}/UserControlIntegerInput.cs | 5 +- .../{ => Visual}/UserControlIntegerInput.resx | 0 .../UserControlStringsListBox.Designer.cs | 2 +- .../{ => Visual}/UserControlStringsListBox.cs | 2 +- .../UserControlStringsListBox.resx | 0 .../{ => Visual}/UserControlTable.Designer.cs | 2 +- Components/{ => Visual}/UserControlTable.cs | 41 +++--- Components/{ => Visual}/UserControlTable.resx | 0 ComponentsProgramming.sln | 6 + TestingForm/FormMain.Designer.cs | 45 +++++++ TestingForm/FormMain.cs | 10 ++ TestingForm/FormMain.resx | 120 ++++++++++++++++++ TestingForm/Program.cs | 17 +++ TestingForm/TestingForm.csproj | 15 +++ 26 files changed, 466 insertions(+), 62 deletions(-) rename Components/{ => Exceptions}/UncheckedNullException.cs (90%) rename Components/{ => Exceptions}/UnexpectedTypeException.cs (90%) create mode 100644 Components/Nonvisual/UserControlTableDocument.Designer.cs create mode 100644 Components/Nonvisual/UserControlTableDocument.cs create mode 100644 Components/SaveToPdf.cs create mode 100644 Components/SaveToPdfHelpers/PdfParagraph.cs create mode 100644 Components/SaveToPdfHelpers/PdfParagraphAlignmentType.cs create mode 100644 Components/SaveToPdfHelpers/PdfRowParameters.cs delete mode 100644 Components/User.cs rename Components/{ => Visual}/ColumnInfo.cs (52%) rename Components/{ => Visual}/UserControlIntegerInput.Designer.cs (98%) rename Components/{ => Visual}/UserControlIntegerInput.cs (96%) rename Components/{ => Visual}/UserControlIntegerInput.resx (100%) rename Components/{ => Visual}/UserControlStringsListBox.Designer.cs (98%) rename Components/{ => Visual}/UserControlStringsListBox.cs (98%) rename Components/{ => Visual}/UserControlStringsListBox.resx (100%) rename Components/{ => Visual}/UserControlTable.Designer.cs (98%) rename Components/{ => Visual}/UserControlTable.cs (87%) rename Components/{ => Visual}/UserControlTable.resx (100%) create mode 100644 TestingForm/FormMain.Designer.cs create mode 100644 TestingForm/FormMain.cs create mode 100644 TestingForm/FormMain.resx create mode 100644 TestingForm/Program.cs create mode 100644 TestingForm/TestingForm.csproj diff --git a/Components/Components.csproj b/Components/Components.csproj index 3d78086..3b33f9a 100644 --- a/Components/Components.csproj +++ b/Components/Components.csproj @@ -7,4 +7,9 @@ enable + + + + + diff --git a/Components/UncheckedNullException.cs b/Components/Exceptions/UncheckedNullException.cs similarity index 90% rename from Components/UncheckedNullException.cs rename to Components/Exceptions/UncheckedNullException.cs index 73b6e8c..e66fdae 100644 --- a/Components/UncheckedNullException.cs +++ b/Components/Exceptions/UncheckedNullException.cs @@ -4,7 +4,7 @@ using System.Linq; using System.Text; using System.Threading.Tasks; -namespace WinFormsLibrary1 +namespace Components.Exceptions { public class UncheckedNullException : Exception { diff --git a/Components/UnexpectedTypeException.cs b/Components/Exceptions/UnexpectedTypeException.cs similarity index 90% rename from Components/UnexpectedTypeException.cs rename to Components/Exceptions/UnexpectedTypeException.cs index 19eace9..e742c0a 100644 --- a/Components/UnexpectedTypeException.cs +++ b/Components/Exceptions/UnexpectedTypeException.cs @@ -4,7 +4,7 @@ using System.Linq; using System.Text; using System.Threading.Tasks; -namespace WinFormsLibrary1 +namespace Components.Exceptions { public class UnexpectedTypeException : Exception { diff --git a/Components/Nonvisual/UserControlTableDocument.Designer.cs b/Components/Nonvisual/UserControlTableDocument.Designer.cs new file mode 100644 index 0000000..525ee88 --- /dev/null +++ b/Components/Nonvisual/UserControlTableDocument.Designer.cs @@ -0,0 +1,36 @@ +namespace Components +{ + partial class UserControlTableDocument + { + /// + /// Обязательная переменная конструктора. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Освободить все используемые ресурсы. + /// + /// истинно, если управляемый ресурс должен быть удален; иначе ложно. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Код, автоматически созданный конструктором компонентов + + /// + /// Требуемый метод для поддержки конструктора — не изменяйте + /// содержимое этого метода с помощью редактора кода. + /// + private void InitializeComponent() + { + components = new System.ComponentModel.Container(); + } + + #endregion + } +} diff --git a/Components/Nonvisual/UserControlTableDocument.cs b/Components/Nonvisual/UserControlTableDocument.cs new file mode 100644 index 0000000..a1ce594 --- /dev/null +++ b/Components/Nonvisual/UserControlTableDocument.cs @@ -0,0 +1,36 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Diagnostics; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Components +{ + public partial class UserControlTableDocument : Component + { + public UserControlTableDocument() + { + InitializeComponent(); + } + + public UserControlTableDocument(IContainer container) + { + container.Add(this); + + InitializeComponent(); + } + + public void SaveToDocument(string filePath, string header, List tables) + { + if (string.IsNullOrEmpty(filePath)) throw new ArgumentNullException("Empty string instead of path to file"); + if (string.IsNullOrEmpty(header)) throw new ArgumentNullException("Header string is empty"); + if (tables.Count == 0) throw new ArgumentNullException("Table list is empty"); + + SaveToPdf saver = new SaveToPdf(); + + saver.CreateDoc(filePath, header, tables); + } + } +} diff --git a/Components/SaveToPdf.cs b/Components/SaveToPdf.cs new file mode 100644 index 0000000..7ac3f44 --- /dev/null +++ b/Components/SaveToPdf.cs @@ -0,0 +1,117 @@ +using MigraDoc.DocumentObjectModel; +using MigraDoc.DocumentObjectModel.Tables; +using MigraDoc.Rendering; +using Components.SaveToPdfHelpers; + +namespace Components +{ + internal class SaveToPdf + { + private Document? _document; + private Section? _section; + private Table? _table; + public void CreateDoc(string title, string path, List tables) + { + _document = new Document(); + DefineStyles(_document); + _section = _document.AddSection(); + + CreateParagraph(new PdfParagraph + { + Text = title, + Style = "NormalTitle", + ParagraphAlignment = PdfParagraphAlignmentType.Left + }); + + foreach (var table in tables) + { + if (table.Length == 0) continue; + + CreateTable(Enumerable.Repeat("3cm", table[0].Length).ToList()); + + foreach (var row in table) + { + CreateRow(new PdfRowParameters + { + Texts = row.ToList(), + Style = "Normal", + ParagraphAlignment = PdfParagraphAlignmentType.Left + }); + } + + CreateParagraph(new PdfParagraph()); + } + + var renderer = new PdfDocumentRenderer(true) + { + Document = _document + }; + renderer.RenderDocument(); + renderer.PdfDocument.Save(path); + } + private static ParagraphAlignment GetParagraphAlignment(PdfParagraphAlignmentType type) + { + return type switch + { + PdfParagraphAlignmentType.Center => ParagraphAlignment.Center, + PdfParagraphAlignmentType.Left => ParagraphAlignment.Left, + PdfParagraphAlignmentType.Right => ParagraphAlignment.Right, + _ => ParagraphAlignment.Justify, + }; + } + private static void DefineStyles(Document document) + { + var style = document.Styles["Normal"]; + style.Font.Name = "Times New Roman"; + style.Font.Size = 14; + style = document.Styles.AddStyle("NormalTitle", "Normal"); + style.Font.Bold = true; + } + protected void CreateParagraph(PdfParagraph pdfParagraph) + { + if (_section == null) + { + return; + } + var paragraph = _section.AddParagraph(pdfParagraph.Text); + paragraph.Format.SpaceAfter = "1cm"; + paragraph.Format.Alignment = GetParagraphAlignment(pdfParagraph.ParagraphAlignment); + paragraph.Style = pdfParagraph.Style; + } + protected void CreateTable(List columns) + { + if (_document == null) + { + return; + } + _table = _document.LastSection.AddTable(); + foreach (var elem in columns) + { + _table.AddColumn(elem); + } + } + protected void CreateRow(PdfRowParameters rowParameters) + { + if (_table == null) + { + return; + } + var row = _table.AddRow(); + for (int i = 0; i < rowParameters.Texts.Count; ++i) + { + row.Cells[i].AddParagraph(rowParameters.Texts[i]); + if (!string.IsNullOrEmpty(rowParameters.Style)) + { + row.Cells[i].Style = rowParameters.Style; + } + Unit borderWidth = 0.5; + row.Cells[i].Borders.Left.Width = borderWidth; + row.Cells[i].Borders.Right.Width = borderWidth; + row.Cells[i].Borders.Top.Width = borderWidth; + row.Cells[i].Borders.Bottom.Width = borderWidth; + row.Cells[i].Format.Alignment = GetParagraphAlignment(rowParameters.ParagraphAlignment); + row.Cells[i].VerticalAlignment = VerticalAlignment.Center; + } + } + } +} diff --git a/Components/SaveToPdfHelpers/PdfParagraph.cs b/Components/SaveToPdfHelpers/PdfParagraph.cs new file mode 100644 index 0000000..ac1f2ab --- /dev/null +++ b/Components/SaveToPdfHelpers/PdfParagraph.cs @@ -0,0 +1,9 @@ +namespace Components.SaveToPdfHelpers +{ + public class PdfParagraph + { + public string Text { get; set; } = string.Empty; + public string Style { get; set; } = string.Empty; + public PdfParagraphAlignmentType ParagraphAlignment { get; set; } + } +} diff --git a/Components/SaveToPdfHelpers/PdfParagraphAlignmentType.cs b/Components/SaveToPdfHelpers/PdfParagraphAlignmentType.cs new file mode 100644 index 0000000..bde3c13 --- /dev/null +++ b/Components/SaveToPdfHelpers/PdfParagraphAlignmentType.cs @@ -0,0 +1,9 @@ +namespace Components.SaveToPdfHelpers +{ + public enum PdfParagraphAlignmentType + { + Center, + Left, + Right + } +} diff --git a/Components/SaveToPdfHelpers/PdfRowParameters.cs b/Components/SaveToPdfHelpers/PdfRowParameters.cs new file mode 100644 index 0000000..76435a6 --- /dev/null +++ b/Components/SaveToPdfHelpers/PdfRowParameters.cs @@ -0,0 +1,10 @@ + +namespace Components.SaveToPdfHelpers +{ + public class PdfRowParameters + { + public List Texts { get; set; } = new(); + public string Style { get; set; } = string.Empty; + public PdfParagraphAlignmentType ParagraphAlignment { get; set; } + } +} diff --git a/Components/User.cs b/Components/User.cs deleted file mode 100644 index 8a521b8..0000000 --- a/Components/User.cs +++ /dev/null @@ -1,23 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace WinFormsLibrary1 -{ - public class User - { - public string username { get; private set; } - public string email { get; private set; } - public DateTime birthday { get; private set; } - - public User(string username, string email, DateTime birthday) - { - this.username = username; - this.email = email; - this.birthday = birthday; - } - - } -} diff --git a/Components/ColumnInfo.cs b/Components/Visual/ColumnInfo.cs similarity index 52% rename from Components/ColumnInfo.cs rename to Components/Visual/ColumnInfo.cs index f504008..08a8955 100644 --- a/Components/ColumnInfo.cs +++ b/Components/Visual/ColumnInfo.cs @@ -4,20 +4,14 @@ using System.Linq; using System.Text; using System.Threading.Tasks; -namespace WinFormsLibrary1 +namespace Components.Visual { public class ColumnInfo { public string HeaderText { get; set; } = string.Empty; - public int Width { get; set; } + public int Width { get; set; } public bool Visible { get; set; } public string Name { get; set; } = string.Empty; - public ColumnInfo(string headerText, string name, int width, bool visible) - { - HeaderText = headerText; - Name = name; - Width = width; - Visible = visible; - } + public string DataPropertyName { get; set; } = string.Empty; } } diff --git a/Components/UserControlIntegerInput.Designer.cs b/Components/Visual/UserControlIntegerInput.Designer.cs similarity index 98% rename from Components/UserControlIntegerInput.Designer.cs rename to Components/Visual/UserControlIntegerInput.Designer.cs index e978ffc..5a4661d 100644 --- a/Components/UserControlIntegerInput.Designer.cs +++ b/Components/Visual/UserControlIntegerInput.Designer.cs @@ -1,4 +1,4 @@ -namespace WinFormsLibrary1 +namespace Components { partial class UserControlIntegerInput { diff --git a/Components/UserControlIntegerInput.cs b/Components/Visual/UserControlIntegerInput.cs similarity index 96% rename from Components/UserControlIntegerInput.cs rename to Components/Visual/UserControlIntegerInput.cs index 3413573..b6f982c 100644 --- a/Components/UserControlIntegerInput.cs +++ b/Components/Visual/UserControlIntegerInput.cs @@ -1,4 +1,5 @@ -using System; +using Components.Exceptions; +using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; @@ -8,7 +9,7 @@ using System.Text; using System.Threading.Tasks; using System.Windows.Forms; -namespace WinFormsLibrary1 +namespace Components { public partial class UserControlIntegerInput : UserControl { diff --git a/Components/UserControlIntegerInput.resx b/Components/Visual/UserControlIntegerInput.resx similarity index 100% rename from Components/UserControlIntegerInput.resx rename to Components/Visual/UserControlIntegerInput.resx diff --git a/Components/UserControlStringsListBox.Designer.cs b/Components/Visual/UserControlStringsListBox.Designer.cs similarity index 98% rename from Components/UserControlStringsListBox.Designer.cs rename to Components/Visual/UserControlStringsListBox.Designer.cs index 6b42aee..382b913 100644 --- a/Components/UserControlStringsListBox.Designer.cs +++ b/Components/Visual/UserControlStringsListBox.Designer.cs @@ -1,4 +1,4 @@ -namespace WinFormsLibrary1 +namespace Components { partial class UserControlStringsListBox { diff --git a/Components/UserControlStringsListBox.cs b/Components/Visual/UserControlStringsListBox.cs similarity index 98% rename from Components/UserControlStringsListBox.cs rename to Components/Visual/UserControlStringsListBox.cs index 0cf9580..8693f27 100644 --- a/Components/UserControlStringsListBox.cs +++ b/Components/Visual/UserControlStringsListBox.cs @@ -8,7 +8,7 @@ using System.Text; using System.Threading.Tasks; using System.Windows.Forms; -namespace WinFormsLibrary1 +namespace Components { public partial class UserControlStringsListBox : UserControl { diff --git a/Components/UserControlStringsListBox.resx b/Components/Visual/UserControlStringsListBox.resx similarity index 100% rename from Components/UserControlStringsListBox.resx rename to Components/Visual/UserControlStringsListBox.resx diff --git a/Components/UserControlTable.Designer.cs b/Components/Visual/UserControlTable.Designer.cs similarity index 98% rename from Components/UserControlTable.Designer.cs rename to Components/Visual/UserControlTable.Designer.cs index 9db1b39..01b9469 100644 --- a/Components/UserControlTable.Designer.cs +++ b/Components/Visual/UserControlTable.Designer.cs @@ -1,4 +1,4 @@ -namespace WinFormsLibrary1 +namespace Components { partial class UserControlTable { diff --git a/Components/UserControlTable.cs b/Components/Visual/UserControlTable.cs similarity index 87% rename from Components/UserControlTable.cs rename to Components/Visual/UserControlTable.cs index f341e31..116c37f 100644 --- a/Components/UserControlTable.cs +++ b/Components/Visual/UserControlTable.cs @@ -8,8 +8,9 @@ using System.Reflection; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; +using Components.Visual; -namespace WinFormsLibrary1 +namespace Components { public partial class UserControlTable : UserControl { @@ -41,6 +42,7 @@ namespace WinFormsLibrary1 HeaderText = columnInfo[i].HeaderText, Width = columnInfo[i].Width, Visible = columnInfo[i].Visible, + DataPropertyName = columnInfo[i].DataPropertyName, }; dataGridViewTable.Columns.Add(column); } @@ -51,9 +53,22 @@ namespace WinFormsLibrary1 dataGridViewTable.Rows.Clear(); } - public void AddObjectList(List os) + public void AddList(List values) { - dataGridViewTable.DataSource = os ?? throw new ArgumentNullException(); + ClearRows(); + var props = typeof(T).GetProperties(); + + foreach (T value in values) + { + int newRowInd = dataGridViewTable.Rows.Add(); + foreach (DataGridViewColumn col in dataGridViewTable.Columns) + { + var prop = props.FirstOrDefault(x => x.Name == col.DataPropertyName) + ?? throw new InvalidOperationException($"No property {col.DataPropertyName} found in type {typeof(T).Name}"); + var val = prop.GetValue(value); + dataGridViewTable.Rows[newRowInd].Cells[col.Index].Value = val; + } + } } public T GetObjectFromRow() @@ -73,28 +88,10 @@ namespace WinFormsLibrary1 for (int i = 0; i < dataGridViewTable.ColumnCount; i++) { var curCell = cells[i]; - var prop = props.FirstOrDefault(x => x.Name == dataGridViewTable.Columns[i].Name); + var prop = props.FirstOrDefault(x => x.Name == dataGridViewTable.Columns[i].DataPropertyName); prop?.SetValue(returnObject, curCell.Value); } return returnObject; } - - public void AddList (List values) - { - ClearRows(); - var props = typeof(T).GetProperties(); - - foreach (T value in values) - { - int newRowInd = dataGridViewTable.Rows.Add(value); - foreach (DataGridViewColumn col in dataGridViewTable.Columns) - { - var prop = props.FirstOrDefault(x => x.Name == col.Name) - ?? throw new InvalidOperationException($"No property {col.Name} found in type {typeof(T).Name}"); - var val = prop.GetValue(value); - dataGridViewTable.Rows[newRowInd].Cells[col.Index].Value = val; - } - } - } } } diff --git a/Components/UserControlTable.resx b/Components/Visual/UserControlTable.resx similarity index 100% rename from Components/UserControlTable.resx rename to Components/Visual/UserControlTable.resx diff --git a/ComponentsProgramming.sln b/ComponentsProgramming.sln index b8d9e2a..af87b6f 100644 --- a/ComponentsProgramming.sln +++ b/ComponentsProgramming.sln @@ -5,6 +5,8 @@ VisualStudioVersion = 17.9.34728.123 MinimumVisualStudioVersion = 10.0.40219.1 Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Components", "Components\Components.csproj", "{260D3E8C-3599-49F1-BF42-64A92DD0FB62}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TestingForm", "TestingForm\TestingForm.csproj", "{4F4882A1-4DF1-4BC3-B022-9935E70E5552}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -15,6 +17,10 @@ Global {260D3E8C-3599-49F1-BF42-64A92DD0FB62}.Debug|Any CPU.Build.0 = Debug|Any CPU {260D3E8C-3599-49F1-BF42-64A92DD0FB62}.Release|Any CPU.ActiveCfg = Release|Any CPU {260D3E8C-3599-49F1-BF42-64A92DD0FB62}.Release|Any CPU.Build.0 = Release|Any CPU + {4F4882A1-4DF1-4BC3-B022-9935E70E5552}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {4F4882A1-4DF1-4BC3-B022-9935E70E5552}.Debug|Any CPU.Build.0 = Debug|Any CPU + {4F4882A1-4DF1-4BC3-B022-9935E70E5552}.Release|Any CPU.ActiveCfg = Release|Any CPU + {4F4882A1-4DF1-4BC3-B022-9935E70E5552}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/TestingForm/FormMain.Designer.cs b/TestingForm/FormMain.Designer.cs new file mode 100644 index 0000000..05ec2ff --- /dev/null +++ b/TestingForm/FormMain.Designer.cs @@ -0,0 +1,45 @@ +namespace TestingForm +{ + 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() + { + SuspendLayout(); + // + // FormMain + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(800, 450); + Name = "FormMain"; + Text = "cB"; + ResumeLayout(false); + } + + #endregion + } +} diff --git a/TestingForm/FormMain.cs b/TestingForm/FormMain.cs new file mode 100644 index 0000000..80839c4 --- /dev/null +++ b/TestingForm/FormMain.cs @@ -0,0 +1,10 @@ +namespace TestingForm +{ + public partial class FormMain : Form + { + public FormMain() + { + InitializeComponent(); + } + } +} diff --git a/TestingForm/FormMain.resx b/TestingForm/FormMain.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/TestingForm/FormMain.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/TestingForm/Program.cs b/TestingForm/Program.cs new file mode 100644 index 0000000..47a2336 --- /dev/null +++ b/TestingForm/Program.cs @@ -0,0 +1,17 @@ +namespace TestingForm +{ + 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/TestingForm/TestingForm.csproj b/TestingForm/TestingForm.csproj new file mode 100644 index 0000000..5a248b2 --- /dev/null +++ b/TestingForm/TestingForm.csproj @@ -0,0 +1,15 @@ + + + + WinExe + net7.0-windows + enable + true + enable + + + + + + + \ No newline at end of file From 497dae509144f73981d67ee46257514b3c6e21ab Mon Sep 17 00:00:00 2001 From: DavidMakarov Date: Fri, 4 Oct 2024 11:48:14 +0400 Subject: [PATCH 15/15] revert to lab1 --- Components/Components.csproj | 1 - .../UserControlTableDocument.Designer.cs | 36 ------ .../Nonvisual/UserControlTableDocument.cs | 36 ------ Components/SaveToPdf.cs | 117 ----------------- Components/SaveToPdfHelpers/PdfParagraph.cs | 9 -- .../PdfParagraphAlignmentType.cs | 9 -- .../SaveToPdfHelpers/PdfRowParameters.cs | 10 -- ComponentsProgramming.sln | 6 - TestingForm/FormMain.Designer.cs | 45 ------- TestingForm/FormMain.cs | 10 -- TestingForm/FormMain.resx | 120 ------------------ TestingForm/Program.cs | 17 --- TestingForm/TestingForm.csproj | 15 --- 13 files changed, 431 deletions(-) delete mode 100644 Components/Nonvisual/UserControlTableDocument.Designer.cs delete mode 100644 Components/Nonvisual/UserControlTableDocument.cs delete mode 100644 Components/SaveToPdf.cs delete mode 100644 Components/SaveToPdfHelpers/PdfParagraph.cs delete mode 100644 Components/SaveToPdfHelpers/PdfParagraphAlignmentType.cs delete mode 100644 Components/SaveToPdfHelpers/PdfRowParameters.cs delete mode 100644 TestingForm/FormMain.Designer.cs delete mode 100644 TestingForm/FormMain.cs delete mode 100644 TestingForm/FormMain.resx delete mode 100644 TestingForm/Program.cs delete mode 100644 TestingForm/TestingForm.csproj diff --git a/Components/Components.csproj b/Components/Components.csproj index 3b33f9a..d501559 100644 --- a/Components/Components.csproj +++ b/Components/Components.csproj @@ -8,7 +8,6 @@ - diff --git a/Components/Nonvisual/UserControlTableDocument.Designer.cs b/Components/Nonvisual/UserControlTableDocument.Designer.cs deleted file mode 100644 index 525ee88..0000000 --- a/Components/Nonvisual/UserControlTableDocument.Designer.cs +++ /dev/null @@ -1,36 +0,0 @@ -namespace Components -{ - partial class UserControlTableDocument - { - /// - /// Обязательная переменная конструктора. - /// - private System.ComponentModel.IContainer components = null; - - /// - /// Освободить все используемые ресурсы. - /// - /// истинно, если управляемый ресурс должен быть удален; иначе ложно. - protected override void Dispose(bool disposing) - { - if (disposing && (components != null)) - { - components.Dispose(); - } - base.Dispose(disposing); - } - - #region Код, автоматически созданный конструктором компонентов - - /// - /// Требуемый метод для поддержки конструктора — не изменяйте - /// содержимое этого метода с помощью редактора кода. - /// - private void InitializeComponent() - { - components = new System.ComponentModel.Container(); - } - - #endregion - } -} diff --git a/Components/Nonvisual/UserControlTableDocument.cs b/Components/Nonvisual/UserControlTableDocument.cs deleted file mode 100644 index a1ce594..0000000 --- a/Components/Nonvisual/UserControlTableDocument.cs +++ /dev/null @@ -1,36 +0,0 @@ -using System; -using System.Collections.Generic; -using System.ComponentModel; -using System.Diagnostics; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace Components -{ - public partial class UserControlTableDocument : Component - { - public UserControlTableDocument() - { - InitializeComponent(); - } - - public UserControlTableDocument(IContainer container) - { - container.Add(this); - - InitializeComponent(); - } - - public void SaveToDocument(string filePath, string header, List tables) - { - if (string.IsNullOrEmpty(filePath)) throw new ArgumentNullException("Empty string instead of path to file"); - if (string.IsNullOrEmpty(header)) throw new ArgumentNullException("Header string is empty"); - if (tables.Count == 0) throw new ArgumentNullException("Table list is empty"); - - SaveToPdf saver = new SaveToPdf(); - - saver.CreateDoc(filePath, header, tables); - } - } -} diff --git a/Components/SaveToPdf.cs b/Components/SaveToPdf.cs deleted file mode 100644 index 7ac3f44..0000000 --- a/Components/SaveToPdf.cs +++ /dev/null @@ -1,117 +0,0 @@ -using MigraDoc.DocumentObjectModel; -using MigraDoc.DocumentObjectModel.Tables; -using MigraDoc.Rendering; -using Components.SaveToPdfHelpers; - -namespace Components -{ - internal class SaveToPdf - { - private Document? _document; - private Section? _section; - private Table? _table; - public void CreateDoc(string title, string path, List tables) - { - _document = new Document(); - DefineStyles(_document); - _section = _document.AddSection(); - - CreateParagraph(new PdfParagraph - { - Text = title, - Style = "NormalTitle", - ParagraphAlignment = PdfParagraphAlignmentType.Left - }); - - foreach (var table in tables) - { - if (table.Length == 0) continue; - - CreateTable(Enumerable.Repeat("3cm", table[0].Length).ToList()); - - foreach (var row in table) - { - CreateRow(new PdfRowParameters - { - Texts = row.ToList(), - Style = "Normal", - ParagraphAlignment = PdfParagraphAlignmentType.Left - }); - } - - CreateParagraph(new PdfParagraph()); - } - - var renderer = new PdfDocumentRenderer(true) - { - Document = _document - }; - renderer.RenderDocument(); - renderer.PdfDocument.Save(path); - } - private static ParagraphAlignment GetParagraphAlignment(PdfParagraphAlignmentType type) - { - return type switch - { - PdfParagraphAlignmentType.Center => ParagraphAlignment.Center, - PdfParagraphAlignmentType.Left => ParagraphAlignment.Left, - PdfParagraphAlignmentType.Right => ParagraphAlignment.Right, - _ => ParagraphAlignment.Justify, - }; - } - private static void DefineStyles(Document document) - { - var style = document.Styles["Normal"]; - style.Font.Name = "Times New Roman"; - style.Font.Size = 14; - style = document.Styles.AddStyle("NormalTitle", "Normal"); - style.Font.Bold = true; - } - protected void CreateParagraph(PdfParagraph pdfParagraph) - { - if (_section == null) - { - return; - } - var paragraph = _section.AddParagraph(pdfParagraph.Text); - paragraph.Format.SpaceAfter = "1cm"; - paragraph.Format.Alignment = GetParagraphAlignment(pdfParagraph.ParagraphAlignment); - paragraph.Style = pdfParagraph.Style; - } - protected void CreateTable(List columns) - { - if (_document == null) - { - return; - } - _table = _document.LastSection.AddTable(); - foreach (var elem in columns) - { - _table.AddColumn(elem); - } - } - protected void CreateRow(PdfRowParameters rowParameters) - { - if (_table == null) - { - return; - } - var row = _table.AddRow(); - for (int i = 0; i < rowParameters.Texts.Count; ++i) - { - row.Cells[i].AddParagraph(rowParameters.Texts[i]); - if (!string.IsNullOrEmpty(rowParameters.Style)) - { - row.Cells[i].Style = rowParameters.Style; - } - Unit borderWidth = 0.5; - row.Cells[i].Borders.Left.Width = borderWidth; - row.Cells[i].Borders.Right.Width = borderWidth; - row.Cells[i].Borders.Top.Width = borderWidth; - row.Cells[i].Borders.Bottom.Width = borderWidth; - row.Cells[i].Format.Alignment = GetParagraphAlignment(rowParameters.ParagraphAlignment); - row.Cells[i].VerticalAlignment = VerticalAlignment.Center; - } - } - } -} diff --git a/Components/SaveToPdfHelpers/PdfParagraph.cs b/Components/SaveToPdfHelpers/PdfParagraph.cs deleted file mode 100644 index ac1f2ab..0000000 --- a/Components/SaveToPdfHelpers/PdfParagraph.cs +++ /dev/null @@ -1,9 +0,0 @@ -namespace Components.SaveToPdfHelpers -{ - public class PdfParagraph - { - public string Text { get; set; } = string.Empty; - public string Style { get; set; } = string.Empty; - public PdfParagraphAlignmentType ParagraphAlignment { get; set; } - } -} diff --git a/Components/SaveToPdfHelpers/PdfParagraphAlignmentType.cs b/Components/SaveToPdfHelpers/PdfParagraphAlignmentType.cs deleted file mode 100644 index bde3c13..0000000 --- a/Components/SaveToPdfHelpers/PdfParagraphAlignmentType.cs +++ /dev/null @@ -1,9 +0,0 @@ -namespace Components.SaveToPdfHelpers -{ - public enum PdfParagraphAlignmentType - { - Center, - Left, - Right - } -} diff --git a/Components/SaveToPdfHelpers/PdfRowParameters.cs b/Components/SaveToPdfHelpers/PdfRowParameters.cs deleted file mode 100644 index 76435a6..0000000 --- a/Components/SaveToPdfHelpers/PdfRowParameters.cs +++ /dev/null @@ -1,10 +0,0 @@ - -namespace Components.SaveToPdfHelpers -{ - public class PdfRowParameters - { - public List Texts { get; set; } = new(); - public string Style { get; set; } = string.Empty; - public PdfParagraphAlignmentType ParagraphAlignment { get; set; } - } -} diff --git a/ComponentsProgramming.sln b/ComponentsProgramming.sln index af87b6f..b8d9e2a 100644 --- a/ComponentsProgramming.sln +++ b/ComponentsProgramming.sln @@ -5,8 +5,6 @@ VisualStudioVersion = 17.9.34728.123 MinimumVisualStudioVersion = 10.0.40219.1 Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Components", "Components\Components.csproj", "{260D3E8C-3599-49F1-BF42-64A92DD0FB62}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TestingForm", "TestingForm\TestingForm.csproj", "{4F4882A1-4DF1-4BC3-B022-9935E70E5552}" -EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -17,10 +15,6 @@ Global {260D3E8C-3599-49F1-BF42-64A92DD0FB62}.Debug|Any CPU.Build.0 = Debug|Any CPU {260D3E8C-3599-49F1-BF42-64A92DD0FB62}.Release|Any CPU.ActiveCfg = Release|Any CPU {260D3E8C-3599-49F1-BF42-64A92DD0FB62}.Release|Any CPU.Build.0 = Release|Any CPU - {4F4882A1-4DF1-4BC3-B022-9935E70E5552}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {4F4882A1-4DF1-4BC3-B022-9935E70E5552}.Debug|Any CPU.Build.0 = Debug|Any CPU - {4F4882A1-4DF1-4BC3-B022-9935E70E5552}.Release|Any CPU.ActiveCfg = Release|Any CPU - {4F4882A1-4DF1-4BC3-B022-9935E70E5552}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/TestingForm/FormMain.Designer.cs b/TestingForm/FormMain.Designer.cs deleted file mode 100644 index 05ec2ff..0000000 --- a/TestingForm/FormMain.Designer.cs +++ /dev/null @@ -1,45 +0,0 @@ -namespace TestingForm -{ - 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() - { - SuspendLayout(); - // - // FormMain - // - AutoScaleDimensions = new SizeF(7F, 15F); - AutoScaleMode = AutoScaleMode.Font; - ClientSize = new Size(800, 450); - Name = "FormMain"; - Text = "cB"; - ResumeLayout(false); - } - - #endregion - } -} diff --git a/TestingForm/FormMain.cs b/TestingForm/FormMain.cs deleted file mode 100644 index 80839c4..0000000 --- a/TestingForm/FormMain.cs +++ /dev/null @@ -1,10 +0,0 @@ -namespace TestingForm -{ - public partial class FormMain : Form - { - public FormMain() - { - InitializeComponent(); - } - } -} diff --git a/TestingForm/FormMain.resx b/TestingForm/FormMain.resx deleted file mode 100644 index af32865..0000000 --- a/TestingForm/FormMain.resx +++ /dev/null @@ -1,120 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 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/TestingForm/Program.cs b/TestingForm/Program.cs deleted file mode 100644 index 47a2336..0000000 --- a/TestingForm/Program.cs +++ /dev/null @@ -1,17 +0,0 @@ -namespace TestingForm -{ - 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/TestingForm/TestingForm.csproj b/TestingForm/TestingForm.csproj deleted file mode 100644 index 5a248b2..0000000 --- a/TestingForm/TestingForm.csproj +++ /dev/null @@ -1,15 +0,0 @@ - - - - WinExe - net7.0-windows - enable - true - enable - - - - - - - \ No newline at end of file