From 07ccf1e048078d1c845f36d785b47d826bfae7d1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9C=D0=B0=D0=BA=D1=81=D0=B8=D0=BC=20=D0=A1=D0=B5=D1=80?= =?UTF-8?q?=D0=B3=D1=83=D0=BD=D0=BE=D0=B2?= Date: Thu, 16 Nov 2023 19:05:42 +0400 Subject: [PATCH] Labs 1 & 2 --- .../BigTextComponent.Designer.cs | 36 +++ Library/CustomComponents/BigTextComponent.cs | 53 ++++ .../CustomComponents/CustomComponents.csproj | 15 + .../CustomComponents/DateTextBox.Designer.cs | 70 +++++ Library/CustomComponents/DateTextBox.cs | 99 +++++++ Library/CustomComponents/DateTextBox.resx | 60 ++++ .../DiagramComponent.Designer.cs | 36 +++ Library/CustomComponents/DiagramComponent.cs | 98 +++++++ .../CustomComponents/DropDownList.Designer.cs | 71 +++++ Library/CustomComponents/DropDownList.cs | 66 +++++ Library/CustomComponents/DropDownList.resx | 60 ++++ Library/CustomComponents/LegendPosition.cs | 10 + Library/CustomComponents/LineChartConfig.cs | 17 ++ .../ListBoxObjects.Designer.cs | 58 ++++ Library/CustomComponents/ListBoxObjects.cs | 98 +++++++ Library/CustomComponents/ListBoxObjects.resx | 60 ++++ Library/CustomComponents/MergeCells.cs | 14 + Library/CustomComponents/Objects/Person.cs | 19 ++ .../TableComponent.Designer.cs | 36 +++ Library/CustomComponents/TableComponent.cs | 166 +++++++++++ Library/Library.sln | 6 + Library/LibraryView/Form1.Designer.cs | 39 --- Library/LibraryView/Form1.cs | 10 - Library/LibraryView/Form1.resx | 120 -------- Library/LibraryView/FormLibrary.Designer.cs | 257 ++++++++++++++++++ Library/LibraryView/FormLibrary.cs | 82 ++++++ Library/LibraryView/FormLibrary.resx | 60 ++++ Library/LibraryView/FormSecond.Designer.cs | 89 ++++++ Library/LibraryView/FormSecond.cs | 77 ++++++ Library/LibraryView/FormSecond.resx | 63 +++++ Library/LibraryView/LibraryView.csproj | 8 + Library/LibraryView/People.cs | 46 ++++ Library/LibraryView/Program.cs | 2 +- 33 files changed, 1831 insertions(+), 170 deletions(-) create mode 100644 Library/CustomComponents/BigTextComponent.Designer.cs create mode 100644 Library/CustomComponents/BigTextComponent.cs create mode 100644 Library/CustomComponents/CustomComponents.csproj create mode 100644 Library/CustomComponents/DateTextBox.Designer.cs create mode 100644 Library/CustomComponents/DateTextBox.cs create mode 100644 Library/CustomComponents/DateTextBox.resx create mode 100644 Library/CustomComponents/DiagramComponent.Designer.cs create mode 100644 Library/CustomComponents/DiagramComponent.cs create mode 100644 Library/CustomComponents/DropDownList.Designer.cs create mode 100644 Library/CustomComponents/DropDownList.cs create mode 100644 Library/CustomComponents/DropDownList.resx create mode 100644 Library/CustomComponents/LegendPosition.cs create mode 100644 Library/CustomComponents/LineChartConfig.cs create mode 100644 Library/CustomComponents/ListBoxObjects.Designer.cs create mode 100644 Library/CustomComponents/ListBoxObjects.cs create mode 100644 Library/CustomComponents/ListBoxObjects.resx create mode 100644 Library/CustomComponents/MergeCells.cs create mode 100644 Library/CustomComponents/Objects/Person.cs create mode 100644 Library/CustomComponents/TableComponent.Designer.cs create mode 100644 Library/CustomComponents/TableComponent.cs delete mode 100644 Library/LibraryView/Form1.Designer.cs delete mode 100644 Library/LibraryView/Form1.cs delete mode 100644 Library/LibraryView/Form1.resx create mode 100644 Library/LibraryView/FormLibrary.Designer.cs create mode 100644 Library/LibraryView/FormLibrary.cs create mode 100644 Library/LibraryView/FormLibrary.resx create mode 100644 Library/LibraryView/FormSecond.Designer.cs create mode 100644 Library/LibraryView/FormSecond.cs create mode 100644 Library/LibraryView/FormSecond.resx create mode 100644 Library/LibraryView/People.cs diff --git a/Library/CustomComponents/BigTextComponent.Designer.cs b/Library/CustomComponents/BigTextComponent.Designer.cs new file mode 100644 index 0000000..8b08de8 --- /dev/null +++ b/Library/CustomComponents/BigTextComponent.Designer.cs @@ -0,0 +1,36 @@ +namespace CustomComponents +{ + partial class BigTextComponent + { + /// + /// Обязательная переменная конструктора. + /// + 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/Library/CustomComponents/BigTextComponent.cs b/Library/CustomComponents/BigTextComponent.cs new file mode 100644 index 0000000..401be2a --- /dev/null +++ b/Library/CustomComponents/BigTextComponent.cs @@ -0,0 +1,53 @@ +using System.ComponentModel; +using System.Runtime.InteropServices; +using Excel = Microsoft.Office.Interop.Excel; + +namespace CustomComponents +{ + public partial class BigTextComponent : Component + { + + public BigTextComponent() + { + InitializeComponent(); + } + + public BigTextComponent(IContainer container) + { + container.Add(this); + + InitializeComponent(); + } + + public void CreateExcel(string file, string title, string[] text) + { + if (string.IsNullOrEmpty(file)) + throw new ArgumentException("Не указан путь к файлу"); + + if (string.IsNullOrEmpty(title)) + throw new ArgumentException("Не указан заголовок документа"); + + if (text == null || text.Length == 0) + throw new ArgumentException("Массив с текстом пуст либо null"); + if (File.Exists(file)) { File.Delete(file); } + + var xlApp = new Excel.Application(); + Excel.Workbook xlWorkBook = xlApp.Workbooks.Add(); + Excel.Worksheet xlWorkSheet = (Excel.Worksheet)xlWorkBook.Sheets[1]; + xlWorkSheet.Cells[1, 1] = title; + + for (int i = 0; i < text.Length; i++) + { + xlWorkSheet.Cells[i + 3, 1] = text[i]; + } + + xlApp.Application.ActiveWorkbook.SaveAs(file); + xlWorkBook.Close(true); + xlApp.Quit(); + + Marshal.ReleaseComObject(xlApp); + + MessageBox.Show("Документ успешно создан!"); + } + } +} diff --git a/Library/CustomComponents/CustomComponents.csproj b/Library/CustomComponents/CustomComponents.csproj new file mode 100644 index 0000000..844a19c --- /dev/null +++ b/Library/CustomComponents/CustomComponents.csproj @@ -0,0 +1,15 @@ + + + + net6.0-windows + enable + true + enable + + + + + + + + diff --git a/Library/CustomComponents/DateTextBox.Designer.cs b/Library/CustomComponents/DateTextBox.Designer.cs new file mode 100644 index 0000000..5cd2948 --- /dev/null +++ b/Library/CustomComponents/DateTextBox.Designer.cs @@ -0,0 +1,70 @@ +namespace CustomComponents +{ + partial class DateTextBox + { + /// + /// Обязательная переменная конструктора. + /// + 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() + { + textBox = new TextBox(); + labelDate = new Label(); + SuspendLayout(); + // + // textBox + // + textBox.Location = new Point(12, 35); + textBox.Name = "textBox"; + textBox.Size = new Size(125, 27); + textBox.TabIndex = 0; + textBox.TextChanged += textBox_TextChanged; + textBox.Enter += textBox_Enter; + // + // labelDate + // + labelDate.AutoSize = true; + labelDate.Location = new Point(50, 12); + labelDate.Name = "labelDate"; + labelDate.Size = new Size(41, 20); + labelDate.TabIndex = 1; + labelDate.Text = "Дата"; + // + // DateTextBox + // + AutoScaleDimensions = new SizeF(8F, 20F); + AutoScaleMode = AutoScaleMode.Font; + Controls.Add(labelDate); + Controls.Add(textBox); + Name = "DateTextBox"; + Size = new Size(150, 92); + ResumeLayout(false); + PerformLayout(); + } + + #endregion + + private TextBox textBox; + private Label labelDate; + } +} diff --git a/Library/CustomComponents/DateTextBox.cs b/Library/CustomComponents/DateTextBox.cs new file mode 100644 index 0000000..3d32be3 --- /dev/null +++ b/Library/CustomComponents/DateTextBox.cs @@ -0,0 +1,99 @@ +using System.Text.RegularExpressions; +using ToolTip = System.Windows.Forms.ToolTip; + +namespace CustomComponents +{ + public partial class DateTextBox : UserControl + { + + private string? pattern; + + private string example = "22.09.2023"; + public DateTextBox() + { + InitializeComponent(); + } + + public string? Pattern + { + get { return pattern; } + set { pattern = value; } + } + + public string? TextBoxValue + { + get + { + if (pattern == null) + { + Error = "pattern is null"; + return null; + } + Regex regex = new Regex(Pattern); + bool isValid = regex.IsMatch(textBox.Text); + if (isValid) + { + return textBox.Text; + } + else + { + Error = "Uncorrect"; + return null; + } + } + set + { + Regex regex = new Regex(Pattern); + bool isValid = regex.IsMatch(value); + if (isValid) + { + textBox.Text = value; + } + else + { + Error = "Uncorrect"; + } + } + } + + public string Error { get; private set; } + + public void setExample(string str) + { + Regex regex = new Regex(Pattern); + bool isValid = regex.IsMatch(str); + if (isValid) + { + example = str; + } + + } + + private void textBox_Enter(object sender, EventArgs e) + { + int VisibleTime = 3000; + + ToolTip tt = new ToolTip(); + tt.Show(example, textBox, 30, -20, VisibleTime); + } + + private EventHandler _explicitEvent; + + public event EventHandler ExplicitEvent + { + add + { + _explicitEvent += value; + } + remove + { + _explicitEvent -= value; + } + } + + private void textBox_TextChanged(object sender, EventArgs e) + { + _explicitEvent?.Invoke(sender, e); + } + } +} diff --git a/Library/CustomComponents/DateTextBox.resx b/Library/CustomComponents/DateTextBox.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/Library/CustomComponents/DateTextBox.resx @@ -0,0 +1,60 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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/Library/CustomComponents/DiagramComponent.Designer.cs b/Library/CustomComponents/DiagramComponent.Designer.cs new file mode 100644 index 0000000..d26fb15 --- /dev/null +++ b/Library/CustomComponents/DiagramComponent.Designer.cs @@ -0,0 +1,36 @@ +namespace CustomComponents +{ + partial class DiagramComponent + { + /// + /// Обязательная переменная конструктора. + /// + 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/Library/CustomComponents/DiagramComponent.cs b/Library/CustomComponents/DiagramComponent.cs new file mode 100644 index 0000000..31ded74 --- /dev/null +++ b/Library/CustomComponents/DiagramComponent.cs @@ -0,0 +1,98 @@ +using System.ComponentModel; +using System.IO; +using System.Runtime.InteropServices; +using Excel = Microsoft.Office.Interop.Excel; + +namespace CustomComponents +{ + public partial class DiagramComponent : Component + { + public DiagramComponent() + { + InitializeComponent(); + } + + public DiagramComponent(IContainer container) + { + container.Add(this); + + InitializeComponent(); + } + + public void CreateExcel(LineChartConfig config) + { + if (string.IsNullOrEmpty(config.FilePath)) + throw new ArgumentException("Файл не задан"); + + if (string.IsNullOrEmpty(config.Header)) + throw new ArgumentException("Название документа не задано"); + + if (string.IsNullOrEmpty(config.ChartTitle)) + throw new ArgumentException("Название диаграммы не задано"); + + if (config.Values == null || config.Values.Count == 0) + throw new ArgumentException("Значения серий не заданы"); + + var xlApp = new Excel.Application(); + Excel.Workbook xlWorkBook = xlApp.Workbooks.Add(); + Excel.Worksheet xlWorkSheet = (Excel.Worksheet)xlWorkBook.Sheets[1]; + xlWorkSheet.Cells[1, 1] = config.Header; + + // Создание диаграммы + Excel.ChartObjects chartObjs = (Excel.ChartObjects)xlWorkSheet.ChartObjects(); + Excel.ChartObject chartObj = chartObjs.Add(5, 50, 300, 300); + Excel.Chart xlChart = chartObj.Chart; + xlChart.ChartType = Excel.XlChartType.xlLine; + + // Запись данных в Excel, сохранение Ranges + Excel.Range[] valuesRange = new Excel.Range[config.Values.Count]; + int leftTopI = 2, leftTopJ = 1; + for (int i = 0; i < config.Values.Count; i++) + { + string key = config.Values.Keys.ToList()[i]; + for (int j = 0; j < config.Values[key].Count; j++) + { + xlWorkSheet.Cells[leftTopI + i, leftTopJ + j] = config.Values[key][j]; + } + valuesRange[i] = xlWorkSheet.Range + [xlWorkSheet.Cells[leftTopI + i, leftTopJ], + xlWorkSheet.Cells[leftTopI + i, leftTopJ + config.Values[key].Count - 1]]; + } + // Задание данных + Excel.SeriesCollection seriesCollection = (Excel.SeriesCollection)xlChart.SeriesCollection(); + for (int i = 0; i < config.Values.Keys.Count; i++) + { + Excel.Series series = seriesCollection.NewSeries(); + series.Name = config.Values.Keys.ToList()[i]; + series.Values = valuesRange[i]; + } + //Задание заголовка + xlChart.HasTitle = true; + xlChart.ChartTitle.Text = config.ChartTitle; + // Задание легенды + xlChart.HasLegend = true; + switch (config.LegendPosition) + { + case LegendPosition.Left: + xlChart.Legend.Position = Excel.XlLegendPosition.xlLegendPositionLeft; + break; + case LegendPosition.Top: + xlChart.Legend.Position = Excel.XlLegendPosition.xlLegendPositionTop; + break; + case LegendPosition.Right: + xlChart.Legend.Position = Excel.XlLegendPosition.xlLegendPositionRight; + break; + case LegendPosition.Botton: + xlChart.Legend.Position = Excel.XlLegendPosition.xlLegendPositionBottom; + break; + } + + if (File.Exists(config.FilePath)) { File.Delete(config.FilePath); } + xlApp.Application.ActiveWorkbook.SaveAs(config.FilePath); + xlWorkBook.Close(true); + xlApp.Quit(); + + Marshal.ReleaseComObject(xlApp); + } + } +} diff --git a/Library/CustomComponents/DropDownList.Designer.cs b/Library/CustomComponents/DropDownList.Designer.cs new file mode 100644 index 0000000..6741879 --- /dev/null +++ b/Library/CustomComponents/DropDownList.Designer.cs @@ -0,0 +1,71 @@ +namespace CustomComponents +{ + partial class DropDownList + { + /// + /// Обязательная переменная конструктора. + /// + 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() + { + comboBox = new ComboBox(); + label = new Label(); + SuspendLayout(); + // + // comboBox + // + comboBox.DropDownStyle = ComboBoxStyle.DropDownList; + comboBox.FormattingEnabled = true; + comboBox.Location = new Point(13, 34); + comboBox.Name = "comboBox"; + comboBox.Size = new Size(151, 28); + comboBox.TabIndex = 0; + comboBox.SelectedValueChanged += comboBox_SelectedValueChanged; + // + // label + // + label.AutoSize = true; + label.Location = new Point(8, 11); + label.Name = "label"; + label.Size = new Size(156, 20); + label.TabIndex = 1; + label.Text = "Выпадающий список"; + // + // DropDownList + // + AutoScaleDimensions = new SizeF(8F, 20F); + AutoScaleMode = AutoScaleMode.Font; + Controls.Add(label); + Controls.Add(comboBox); + Name = "DropDownList"; + Size = new Size(180, 80); + ResumeLayout(false); + PerformLayout(); + } + + #endregion + + private ComboBox comboBox; + private Label label; + } +} diff --git a/Library/CustomComponents/DropDownList.cs b/Library/CustomComponents/DropDownList.cs new file mode 100644 index 0000000..a845888 --- /dev/null +++ b/Library/CustomComponents/DropDownList.cs @@ -0,0 +1,66 @@ +namespace CustomComponents +{ + public partial class DropDownList : UserControl + { + public DropDownList() + { + InitializeComponent(); + } + + public void AddingToList(string Value) + { + if (Value == null) + { + return; + } + comboBox.Items.Add(Value); + } + + public void Clear() + { + comboBox.Items.Clear(); + } + + public string Selected + { + get + { + if (comboBox.Items.Count == 0) + { + return ""; + } + if (comboBox.SelectedItem == null) + { + return ""; + } + return comboBox.SelectedItem.ToString()!; + } + set + { + if (comboBox.Items.Contains(value)) + { + comboBox.SelectedItem = value; + } + + } + } + + private EventHandler _explicitEvent; + + public event EventHandler ExplicitEvent + { + add + { + _explicitEvent += value; + } + remove + { + _explicitEvent -= value; + } + } + private void comboBox_SelectedValueChanged(object sender, EventArgs e) + { + _explicitEvent?.Invoke(sender, e); + } + } +} diff --git a/Library/CustomComponents/DropDownList.resx b/Library/CustomComponents/DropDownList.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/Library/CustomComponents/DropDownList.resx @@ -0,0 +1,60 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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/Library/CustomComponents/LegendPosition.cs b/Library/CustomComponents/LegendPosition.cs new file mode 100644 index 0000000..6d087e5 --- /dev/null +++ b/Library/CustomComponents/LegendPosition.cs @@ -0,0 +1,10 @@ +namespace CustomComponents +{ + public enum LegendPosition + { + Left, + Top, + Right, + Botton, + } +} \ No newline at end of file diff --git a/Library/CustomComponents/LineChartConfig.cs b/Library/CustomComponents/LineChartConfig.cs new file mode 100644 index 0000000..2de6ab0 --- /dev/null +++ b/Library/CustomComponents/LineChartConfig.cs @@ -0,0 +1,17 @@ +using Microsoft.Office.Interop.Excel; + +namespace CustomComponents +{ + public class LineChartConfig + { + public string FilePath { get; set; } + + public string Header { get; set; } + + public string ChartTitle { get; set; } + + public Dictionary> Values { get; set; } + + public LegendPosition LegendPosition { get; set; } + } +} \ No newline at end of file diff --git a/Library/CustomComponents/ListBoxObjects.Designer.cs b/Library/CustomComponents/ListBoxObjects.Designer.cs new file mode 100644 index 0000000..0a3fd4a --- /dev/null +++ b/Library/CustomComponents/ListBoxObjects.Designer.cs @@ -0,0 +1,58 @@ +namespace CustomComponents +{ + partial class ListBoxObjects + { + /// + /// Обязательная переменная конструктора. + /// + 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() + { + this.listBox = new System.Windows.Forms.ListBox(); + this.SuspendLayout(); + // + // listBox + // + this.listBox.FormattingEnabled = true; + this.listBox.ItemHeight = 20; + this.listBox.Location = new System.Drawing.Point(3, 3); + this.listBox.Name = "listBox"; + this.listBox.Size = new System.Drawing.Size(452, 144); + this.listBox.TabIndex = 0; + // + // ListBoxObjects + // + this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.Controls.Add(this.listBox); + this.Name = "ListBoxObjects"; + this.Size = new System.Drawing.Size(458, 156); + this.ResumeLayout(false); + + } + + #endregion + + private ListBox listBox; + } +} diff --git a/Library/CustomComponents/ListBoxObjects.cs b/Library/CustomComponents/ListBoxObjects.cs new file mode 100644 index 0000000..d1c8ddd --- /dev/null +++ b/Library/CustomComponents/ListBoxObjects.cs @@ -0,0 +1,98 @@ +using System.Text; + +namespace CustomComponents +{ + public partial class ListBoxObjects : UserControl + { + + private string layoutString; + + private string startSymbol; + + private string endSymbol; + public ListBoxObjects() + { + InitializeComponent(); + } + + + public void SetLayoutInfo(string layout, string startS, string endS) + { + if (layout == null || startS == null || endS == null) + { + return; + } + layoutString = layout; + startSymbol = startS; + endSymbol = endS; + } + + + public int SelectedIndex + { + get { + if (listBox.SelectedIndex == -1) + { + return -1; + } + return listBox.SelectedIndex; + } + set { + if (listBox.SelectedItems.Count != 0) + { + listBox.SelectedIndex = value; + } + } + } + + public T GetObjectFromStr() where T : class, new() + { + string selStr = ""; + if (listBox.SelectedIndex != -1) + { + selStr = listBox.SelectedItem.ToString()!; + } + T curObject = new T(); + foreach (var property in typeof(T).GetProperties()) + { + if (!property.CanWrite) + { + continue; + } + int borderOne = selStr.IndexOf(startSymbol); + StringBuilder sb = new StringBuilder(selStr); + sb[borderOne] = 'z'; + selStr = sb.ToString(); + int borderTwo = selStr.IndexOf(endSymbol); + if (borderOne == -1 || borderTwo == -1) break; + string propertyValue = selStr.Substring(borderOne + 1, borderTwo - borderOne - 1); + selStr = selStr.Substring(borderTwo + 1); + property.SetValue(curObject, Convert.ChangeType(propertyValue,property.PropertyType)); + } + return curObject; + } + + public void AddInListBox(T entity) + { + if (layoutString == null || startSymbol == null || endSymbol == null) + { + throw new Exception("Заполните макетную строку"); + } + + if (!layoutString.Contains(startSymbol) || !layoutString.Contains(endSymbol)) + { + throw new Exception("Макетная строка не содержит нужные элементы"); + } + + string str = layoutString; + + foreach (var prop in entity.GetType().GetProperties()) + { + string str1 = $"{startSymbol}" + $"{prop.Name}" + $"{endSymbol}"; + str = str.Replace(str1, $"{startSymbol}" + prop.GetValue(entity).ToString() + $"{endSymbol}"); + } + + listBox.Items.Add(str); + } + } +} diff --git a/Library/CustomComponents/ListBoxObjects.resx b/Library/CustomComponents/ListBoxObjects.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/Library/CustomComponents/ListBoxObjects.resx @@ -0,0 +1,60 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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/Library/CustomComponents/MergeCells.cs b/Library/CustomComponents/MergeCells.cs new file mode 100644 index 0000000..efe8802 --- /dev/null +++ b/Library/CustomComponents/MergeCells.cs @@ -0,0 +1,14 @@ +namespace CustomComponents +{ + public class MergeCells + { + public string Heading; + public int[] CellIndexes; + + public MergeCells(string heading, int[] cellIndexes) + { + Heading = heading; + CellIndexes = cellIndexes; + } + } +} \ No newline at end of file diff --git a/Library/CustomComponents/Objects/Person.cs b/Library/CustomComponents/Objects/Person.cs new file mode 100644 index 0000000..3820004 --- /dev/null +++ b/Library/CustomComponents/Objects/Person.cs @@ -0,0 +1,19 @@ +namespace CustomComponents.Objects +{ + public class Person + { + public string Name { get; set; } + + public string Surname { get; set; } + + public Person(string name, string surname) + { + Name = name; + Surname = surname; + } + + public Person() + { + } + } +} diff --git a/Library/CustomComponents/TableComponent.Designer.cs b/Library/CustomComponents/TableComponent.Designer.cs new file mode 100644 index 0000000..fd27d14 --- /dev/null +++ b/Library/CustomComponents/TableComponent.Designer.cs @@ -0,0 +1,36 @@ +namespace CustomComponents +{ + partial class TableComponent + { + /// + /// Обязательная переменная конструктора. + /// + 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/Library/CustomComponents/TableComponent.cs b/Library/CustomComponents/TableComponent.cs new file mode 100644 index 0000000..8d35652 --- /dev/null +++ b/Library/CustomComponents/TableComponent.cs @@ -0,0 +1,166 @@ +using System.ComponentModel; +using Excel = Microsoft.Office.Interop.Excel; + +namespace CustomComponents +{ + public partial class TableComponent : Component + { + char[] colIndex = { 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z' }; + + //порядок столбцов + //public List columnsName = new List(); + + public TableComponent() + { + InitializeComponent(); + } + + public TableComponent(IContainer container) + { + container.Add(this); + + InitializeComponent(); + } + + public bool CreateTableExcel(string path, string title, List mergeCells, int[] colsWidth, string[] headings, List columnsName, List data) where T : class, new() + { + if (path != string.Empty && title != string.Empty && mergeCells != null && colsWidth != null && headings != null && data != null) + { + if (columnsName == null) + { + throw new Exception("Не заполнены названия колонок"); + } + + var excelApp = new Excel.Application(); + + excelApp.SheetsInNewWorkbook = 1; + + excelApp.Workbooks.Add(); + + Excel._Worksheet workSheet = (Excel.Worksheet)excelApp.Worksheets.get_Item(1); + + workSheet.Cells[1, "A"] = title; + + //Добавление заголовков + if (colsWidth.Length == headings.Length) + { + for (int j = 1; j <= headings.Length; j++) + { + if (!headings[j - 1].Equals(string.Empty)) + { + workSheet.Cells[2, j] = headings[j - 1]; + workSheet.Columns[j].ColumnWidth = colsWidth[j - 1]; + workSheet.Cells[2, j].HorizontalAlignment = Excel.XlHAlign.xlHAlignCenter; + workSheet.Cells[2, j].VerticalAlignment = Excel.XlHAlign.xlHAlignCenter; + workSheet.Cells[2, j].Font.Bold = true; + } + else + { + throw new Exception("Не все заголовки имеют данные"); + } + } + } + else + { + throw new Exception("Кол-во заголовков не соответствует кол-ву размеров столбцов"); + } + + List mergeInds = new List(); + + //Объединение ячеек по столбцам + foreach (var merge in mergeCells) + { + mergeInds.AddRange(merge.CellIndexes); + + Excel.Range rangeToCopy = workSheet.get_Range + ($"{colIndex[merge.CellIndexes[0]]}2", $"{colIndex[merge.CellIndexes[merge.CellIndexes.Length - 1]]}2").Cells; + Excel.Range rangeToInsert = workSheet.get_Range + ($"{colIndex[merge.CellIndexes[0]]}3", $"{colIndex[merge.CellIndexes[merge.CellIndexes.Length - 1]]}3").Cells; + rangeToInsert.Insert(Excel.XlInsertShiftDirection.xlShiftToRight, rangeToCopy.Cut()); + + Excel.Range rangeMerge = workSheet.get_Range + ($"{colIndex[merge.CellIndexes[0]]}2", $"{colIndex[merge.CellIndexes[merge.CellIndexes.Length - 1]]}2").Cells; + rangeMerge.Merge(); + workSheet.Cells[2, merge.CellIndexes[0] + 1] = merge.Heading; + workSheet.Cells[2, merge.CellIndexes[0] + 1].HorizontalAlignment = Excel.XlHAlign.xlHAlignCenter; + workSheet.Cells[2, merge.CellIndexes[0] + 1].VerticalAlignment = Excel.XlHAlign.xlHAlignCenter; + workSheet.Cells[2, merge.CellIndexes[0] + 1].Font.Bold = true; + } + + //Объединение ячеек по строкам, которые не объединяются по столбцам + for (int j = 1; j <= headings.Length; j++) + { + if (!mergeInds.Contains(j - 1)) + { + Excel.Range range = workSheet.get_Range($"{colIndex[j - 1]}2", $"{colIndex[j - 1]}3").Cells; + range.Merge(); + } + } + + //Заполение данными + int i = 4; + foreach (var item in data) + { + var fields = item.GetType().GetProperties(); + if (fields.Count() == columnsName.Count()) + { + for (int j = 0; j < fields.Count(); j++) + { + int colIndex = 0; + var field = item.GetType().GetProperties()[j]; + var value = field.GetValue(item); + if (value != null) + { + foreach (var column in columnsName) + { + if (column == field.Name) + { + colIndex = columnsName.IndexOf(column) + 1; + break; + } + } + if (colIndex != 0) + { + workSheet.Cells[i, colIndex] = value; + } + else + { + throw new Exception($"Соответствующая колонка в таблице для поля {field.Name} = {value} не найдена"); + } + } + else + { + throw new Exception("Поле имеет пустое значение"); + } + } + i++; + } + else + { + throw new Exception("Кол-во полей объекта не соответствует кол-ву столбцов в таблице"); + } + } + + //границы у таблицы + for (int str = 2; str <= (data.Count() + 3); str++) + { + for (int j = 1; j < headings.Length + 1; j++) + { + workSheet.Cells[str, j].BorderAround(true); + } + } + + if(File.Exists(path)) { File.Delete(path); } + excelApp.Application.ActiveWorkbook.SaveAs(path); + excelApp.Workbooks.Close(); + excelApp.Quit(); + return true; + + } + else + { + return false; + } + } + } +} diff --git a/Library/Library.sln b/Library/Library.sln index 51f7d2a..57ade83 100644 --- a/Library/Library.sln +++ b/Library/Library.sln @@ -5,6 +5,8 @@ VisualStudioVersion = 17.5.33530.505 MinimumVisualStudioVersion = 10.0.40219.1 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LibraryView", "LibraryView\LibraryView.csproj", "{50CEADA7-BB8C-41AB-BAB5-F29DF48E581F}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CustomComponents", "CustomComponents\CustomComponents.csproj", "{F6B42349-8FB3-4D68-8757-D26DAD2F0992}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -15,6 +17,10 @@ Global {50CEADA7-BB8C-41AB-BAB5-F29DF48E581F}.Debug|Any CPU.Build.0 = Debug|Any CPU {50CEADA7-BB8C-41AB-BAB5-F29DF48E581F}.Release|Any CPU.ActiveCfg = Release|Any CPU {50CEADA7-BB8C-41AB-BAB5-F29DF48E581F}.Release|Any CPU.Build.0 = Release|Any CPU + {F6B42349-8FB3-4D68-8757-D26DAD2F0992}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {F6B42349-8FB3-4D68-8757-D26DAD2F0992}.Debug|Any CPU.Build.0 = Debug|Any CPU + {F6B42349-8FB3-4D68-8757-D26DAD2F0992}.Release|Any CPU.ActiveCfg = Release|Any CPU + {F6B42349-8FB3-4D68-8757-D26DAD2F0992}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/Library/LibraryView/Form1.Designer.cs b/Library/LibraryView/Form1.Designer.cs deleted file mode 100644 index a224212..0000000 --- a/Library/LibraryView/Form1.Designer.cs +++ /dev/null @@ -1,39 +0,0 @@ -namespace LibraryView -{ - 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() - { - this.components = new System.ComponentModel.Container(); - this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(800, 450); - this.Text = "Form1"; - } - - #endregion - } -} \ No newline at end of file diff --git a/Library/LibraryView/Form1.cs b/Library/LibraryView/Form1.cs deleted file mode 100644 index ee87606..0000000 --- a/Library/LibraryView/Form1.cs +++ /dev/null @@ -1,10 +0,0 @@ -namespace LibraryView -{ - public partial class Form1 : Form - { - public Form1() - { - InitializeComponent(); - } - } -} \ No newline at end of file diff --git a/Library/LibraryView/Form1.resx b/Library/LibraryView/Form1.resx deleted file mode 100644 index 1af7de1..0000000 --- a/Library/LibraryView/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/Library/LibraryView/FormLibrary.Designer.cs b/Library/LibraryView/FormLibrary.Designer.cs new file mode 100644 index 0000000..33ad2f4 --- /dev/null +++ b/Library/LibraryView/FormLibrary.Designer.cs @@ -0,0 +1,257 @@ +namespace LibraryView +{ + partial class FormLibrary + { + /// + /// 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() + { + dropDownList = new CustomComponents.DropDownList(); + buttonAdd = new Button(); + buttonShowElement = new Button(); + labelShow = new Label(); + buttonClear = new Button(); + dateTextBox1 = new CustomComponents.DateTextBox(); + groupBoxFirst = new GroupBox(); + groupBoxSecond = new GroupBox(); + labelShowTB = new Label(); + buttonShowTextBox = new Button(); + buttonSetExample = new Button(); + labelExample = new Label(); + textBoxExample = new TextBox(); + listBoxObjects1 = new CustomComponents.ListBoxObjects(); + buttonAddObjects = new Button(); + buttonShowItem = new Button(); + labelShowInput = new Label(); + groupBoxFirst.SuspendLayout(); + groupBoxSecond.SuspendLayout(); + SuspendLayout(); + // + // dropDownList + // + dropDownList.Location = new Point(51, 34); + dropDownList.Name = "dropDownList"; + dropDownList.Selected = ""; + dropDownList.Size = new Size(180, 100); + dropDownList.TabIndex = 0; + // + // buttonAdd + // + buttonAdd.Location = new Point(27, 156); + buttonAdd.Name = "buttonAdd"; + buttonAdd.Size = new Size(94, 52); + buttonAdd.TabIndex = 1; + buttonAdd.Text = "Добавить"; + buttonAdd.UseVisualStyleBackColor = true; + buttonAdd.Click += buttonAdd_Click; + // + // buttonShowElement + // + buttonShowElement.Location = new Point(88, 288); + buttonShowElement.Name = "buttonShowElement"; + buttonShowElement.Size = new Size(94, 29); + buttonShowElement.TabIndex = 2; + buttonShowElement.Text = "Проверка"; + buttonShowElement.UseVisualStyleBackColor = true; + buttonShowElement.Click += buttonShowElement_Click; + // + // labelShow + // + labelShow.AutoSize = true; + labelShow.Location = new Point(60, 245); + labelShow.Name = "labelShow"; + labelShow.Size = new Size(157, 20); + labelShow.TabIndex = 3; + labelShow.Text = "Выбранный элемент:"; + // + // buttonClear + // + buttonClear.Location = new Point(158, 156); + buttonClear.Name = "buttonClear"; + buttonClear.Size = new Size(92, 52); + buttonClear.TabIndex = 4; + buttonClear.Text = "Очистить"; + buttonClear.UseVisualStyleBackColor = true; + buttonClear.Click += buttonClear_Click; + // + // dateTextBox1 + // + dateTextBox1.Location = new Point(55, 34); + dateTextBox1.Name = "dateTextBox1"; + dateTextBox1.Pattern = null; + dateTextBox1.Size = new Size(148, 115); + dateTextBox1.TabIndex = 5; + // + // groupBoxFirst + // + groupBoxFirst.Controls.Add(dropDownList); + groupBoxFirst.Controls.Add(buttonAdd); + groupBoxFirst.Controls.Add(buttonShowElement); + groupBoxFirst.Controls.Add(labelShow); + groupBoxFirst.Controls.Add(buttonClear); + groupBoxFirst.Location = new Point(12, 18); + groupBoxFirst.Name = "groupBoxFirst"; + groupBoxFirst.Size = new Size(305, 420); + groupBoxFirst.TabIndex = 6; + groupBoxFirst.TabStop = false; + // + // groupBoxSecond + // + groupBoxSecond.Controls.Add(labelShowTB); + groupBoxSecond.Controls.Add(buttonShowTextBox); + groupBoxSecond.Controls.Add(buttonSetExample); + groupBoxSecond.Controls.Add(labelExample); + groupBoxSecond.Controls.Add(textBoxExample); + groupBoxSecond.Controls.Add(dateTextBox1); + groupBoxSecond.Location = new Point(323, 18); + groupBoxSecond.Name = "groupBoxSecond"; + groupBoxSecond.Size = new Size(250, 420); + groupBoxSecond.TabIndex = 5; + groupBoxSecond.TabStop = false; + // + // labelShowTB + // + labelShowTB.AutoSize = true; + labelShowTB.Location = new Point(87, 152); + labelShowTB.Name = "labelShowTB"; + labelShowTB.Size = new Size(81, 20); + labelShowTB.TabIndex = 10; + labelShowTB.Text = "Проверка:"; + // + // buttonShowTextBox + // + buttonShowTextBox.Location = new Point(77, 175); + buttonShowTextBox.Name = "buttonShowTextBox"; + buttonShowTextBox.Size = new Size(100, 29); + buttonShowTextBox.TabIndex = 9; + buttonShowTextBox.Text = "Проверка"; + buttonShowTextBox.UseVisualStyleBackColor = true; + buttonShowTextBox.Click += buttonShowTextBox_Click; + // + // buttonSetExample + // + buttonSetExample.Location = new Point(29, 310); + buttonSetExample.Name = "buttonSetExample"; + buttonSetExample.Size = new Size(188, 29); + buttonSetExample.TabIndex = 8; + buttonSetExample.Text = "Поменять пример"; + buttonSetExample.UseVisualStyleBackColor = true; + buttonSetExample.Click += buttonSetExample_Click; + // + // labelExample + // + labelExample.AutoSize = true; + labelExample.Location = new Point(64, 254); + labelExample.Name = "labelExample"; + labelExample.Size = new Size(113, 20); + labelExample.TabIndex = 7; + labelExample.Text = "Ввод примера:"; + // + // textBoxExample + // + textBoxExample.Location = new Point(29, 277); + textBoxExample.Name = "textBoxExample"; + textBoxExample.Size = new Size(188, 27); + textBoxExample.TabIndex = 6; + // + // listBoxObjects1 + // + listBoxObjects1.Location = new Point(612, 31); + listBoxObjects1.Name = "listBoxObjects1"; + listBoxObjects1.SelectedIndex = -1; + listBoxObjects1.Size = new Size(458, 195); + listBoxObjects1.TabIndex = 7; + // + // buttonAddObjects + // + buttonAddObjects.Location = new Point(659, 232); + buttonAddObjects.Name = "buttonAddObjects"; + buttonAddObjects.Size = new Size(380, 29); + buttonAddObjects.TabIndex = 8; + buttonAddObjects.Text = "Добавить"; + buttonAddObjects.UseVisualStyleBackColor = true; + buttonAddObjects.Click += buttonAddObjects_Click; + // + // buttonShowItem + // + buttonShowItem.Location = new Point(659, 363); + buttonShowItem.Name = "buttonShowItem"; + buttonShowItem.Size = new Size(380, 29); + buttonShowItem.TabIndex = 9; + buttonShowItem.Text = "Получить"; + buttonShowItem.UseVisualStyleBackColor = true; + buttonShowItem.Click += buttonShowItem_Click; + // + // labelShowInput + // + labelShowInput.AutoSize = true; + labelShowInput.Location = new Point(659, 326); + labelShowInput.Name = "labelShowInput"; + labelShowInput.Size = new Size(54, 20); + labelShowInput.TabIndex = 10; + labelShowInput.Text = "Вывод"; + // + // FormLibrary + // + AutoScaleDimensions = new SizeF(8F, 20F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(1082, 450); + Controls.Add(labelShowInput); + Controls.Add(buttonShowItem); + Controls.Add(buttonAddObjects); + Controls.Add(listBoxObjects1); + Controls.Add(groupBoxSecond); + Controls.Add(groupBoxFirst); + Name = "FormLibrary"; + Text = "TestForm"; + groupBoxFirst.ResumeLayout(false); + groupBoxFirst.PerformLayout(); + groupBoxSecond.ResumeLayout(false); + groupBoxSecond.PerformLayout(); + ResumeLayout(false); + PerformLayout(); + } + + #endregion + + private CustomComponents.DropDownList dropDownList; + private Button buttonAdd; + private Button buttonShowElement; + private Label labelShow; + private Button buttonClear; + private CustomComponents.DateTextBox dateTextBox1; + private GroupBox groupBoxFirst; + private GroupBox groupBoxSecond; + private TextBox textBoxExample; + private Label labelExample; + private Button buttonSetExample; + private Label labelShowTB; + private Button buttonShowTextBox; + private CustomComponents.ListBoxObjects listBoxObjects1; + private Button buttonAddObjects; + private Button buttonShowItem; + private Label labelShowInput; + } +} \ No newline at end of file diff --git a/Library/LibraryView/FormLibrary.cs b/Library/LibraryView/FormLibrary.cs new file mode 100644 index 0000000..ed5dffb --- /dev/null +++ b/Library/LibraryView/FormLibrary.cs @@ -0,0 +1,82 @@ +using CustomComponents.Objects; + +namespace LibraryView +{ + public partial class FormLibrary : Form + { + Person person1 = new Person("Иван", "Иванов"); + Person person2 = new Person("Максим", "Петров"); + public FormLibrary() + { + InitializeComponent(); + dateTextBox1.Pattern = @"^(\d{2}.\d{2}.\d{4})$"; + listBoxObjects1.SetLayoutInfo("Имя *Name* Фамилия *Surname*", "*", "*"); + dropDownList.AddingToList("info1"); + dropDownList.AddingToList("info2"); + dropDownList.AddingToList("info3"); + } + + private void buttonAdd_Click(object sender, EventArgs e) + { + dropDownList.AddingToList("info11"); + dropDownList.AddingToList("info12"); + dropDownList.AddingToList("info13"); + } + + private void Event_Test() + { + MessageBox.Show("Изменено"); + } + + private void buttonShowElement_Click(object sender, EventArgs e) + { + labelShow.Text = dropDownList.Selected; + } + + private void buttonClear_Click(object sender, EventArgs e) + { + dropDownList.Clear(); + } + + + private void buttonSetExample_Click(object sender, EventArgs e) + { + if (textBoxExample.Text == String.Empty) + { + return; + } + dateTextBox1.setExample(textBoxExample.Text); + } + + private void buttonShowTextBox_Click(object sender, EventArgs e) + { + try + { + if (dateTextBox1.TextBoxValue != null) + { + labelShowTB.Text = "true"; + } + } + catch (Exception ex) + { + MessageBox.Show(ex.Message); + } + + + } + + private void buttonAddObjects_Click(object sender, EventArgs e) + { + listBoxObjects1.AddInListBox(person1); + listBoxObjects1.AddInListBox(person2); + } + + private void buttonShowItem_Click(object sender, EventArgs e) + { + string str = listBoxObjects1.GetObjectFromStr() + .Name + " " + listBoxObjects1.GetObjectFromStr() + .Surname; + labelShowInput.Text = str; + } + } +} diff --git a/Library/LibraryView/FormLibrary.resx b/Library/LibraryView/FormLibrary.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/Library/LibraryView/FormLibrary.resx @@ -0,0 +1,60 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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/Library/LibraryView/FormSecond.Designer.cs b/Library/LibraryView/FormSecond.Designer.cs new file mode 100644 index 0000000..4b636c0 --- /dev/null +++ b/Library/LibraryView/FormSecond.Designer.cs @@ -0,0 +1,89 @@ +namespace LibraryView +{ + partial class FormSecond + { + /// + /// 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() + { + components = new System.ComponentModel.Container(); + bigTextComponent1 = new CustomComponents.BigTextComponent(components); + buttonCreateExDoc = new Button(); + buttonCreateTable = new Button(); + buttonCreateDiagram = new Button(); + SuspendLayout(); + // + // buttonCreateExDoc + // + buttonCreateExDoc.Location = new Point(32, 56); + buttonCreateExDoc.Name = "buttonCreateExDoc"; + buttonCreateExDoc.Size = new Size(200, 64); + buttonCreateExDoc.TabIndex = 1; + buttonCreateExDoc.Text = "Создать документ с текстом"; + buttonCreateExDoc.UseVisualStyleBackColor = true; + buttonCreateExDoc.Click += buttonCreateExDoc_Click; + // + // buttonCreateTable + // + buttonCreateTable.Location = new Point(284, 56); + buttonCreateTable.Name = "buttonCreateTable"; + buttonCreateTable.Size = new Size(200, 64); + buttonCreateTable.TabIndex = 2; + buttonCreateTable.Text = "Создать таблицу"; + buttonCreateTable.UseVisualStyleBackColor = true; + buttonCreateTable.Click += buttonCreateTable_Click; + // + // buttonCreateDiagram + // + buttonCreateDiagram.Location = new Point(559, 56); + buttonCreateDiagram.Name = "buttonCreateDiagram"; + buttonCreateDiagram.Size = new Size(197, 64); + buttonCreateDiagram.TabIndex = 3; + buttonCreateDiagram.Text = "Создать диаграмму"; + buttonCreateDiagram.UseVisualStyleBackColor = true; + buttonCreateDiagram.Click += buttonCreateDiagram_Click; + // + // FormSecond + // + AutoScaleDimensions = new SizeF(8F, 20F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(799, 175); + Controls.Add(buttonCreateDiagram); + Controls.Add(buttonCreateTable); + Controls.Add(buttonCreateExDoc); + Name = "FormSecond"; + Text = "FormSecond"; + ResumeLayout(false); + } + + #endregion + + private CustomComponents.BigTextComponent bigTextComponent1; + private RichTextBox richTextBoxText; + private Button buttonCreateExDoc; + private Button buttonCreateTable; + private Button buttonCreateDiagram; + } +} \ No newline at end of file diff --git a/Library/LibraryView/FormSecond.cs b/Library/LibraryView/FormSecond.cs new file mode 100644 index 0000000..e42f6ea --- /dev/null +++ b/Library/LibraryView/FormSecond.cs @@ -0,0 +1,77 @@ +using CustomComponents; +using Microsoft.VisualBasic; + +namespace LibraryView +{ + public partial class FormSecond : Form + { + public FormSecond() + { + InitializeComponent(); + } + + private void buttonCreateExDoc_Click(object sender, EventArgs e) + { + string[] text = { "Некий текст 1", "Ещё один некий текст", "Текст" }; + + BigTextComponent bigText = new BigTextComponent(); + + bigText.CreateExcel("D:\\Papka\\КОП\\ExcelDoc.xls", "Документ", text); + } + + private void buttonCreateTable_Click(object sender, EventArgs e) + { + TableComponent table = new TableComponent(); + var dict = new List(); + //table.columnsName = new List() { "ID", "Status", "Name", "Surname", "Age", "Kid", "Division", "Post", "Prize" }; + var columnsName = new List() { "ID", "Status", "Name", "Surname", "Age", "Kid", "Division", "Post", "Prize" }; + int[] arrayHeight = { 30, 30, 20, 20, 30, 40, 20, 20, 20 }; + string[] arrayHeaderAL = { "Идентификатор", "Статус", "Имя", "Фамилия", "Возраст", "Дети", "Подразделение", "Должность", "Премия" }; + var listPeople = new List() { new People(1, "Женат", "Иван", "Иванов", 31, 2, "One", "One", 25000), + new People(2, "Не женат", "Андрей", "Петров", 26, 1, "One", "One", 31000), + new People(3, "Замужем", "Наталья", "Беляева", 21, 0, "One", "One", 20000), + new People(4, "Не женат", "Константин", "Рогов", 28, 1, "One", "One", 29000) }; + + dict.Add(new MergeCells("Личные данные", new int[] { 2, 3, 4 })); + dict.Add(new MergeCells("Работа", new int[] { 6, 7 })); + table.CreateTableExcel("D:\\Papka\\КОП\\ExcelTab.xls", "Люди", dict, arrayHeight, arrayHeaderAL, columnsName, listPeople); + + } + + private List<(double, double)> GenerateRandomData(int count) + { + Random random = new Random(); + var data = new List<(double, double)>(); + for (int i = 1; i <= count; i++) + { + data.Add((i, random.NextDouble() * 50)); + } + return data; + } + + private void buttonCreateDiagram_Click(object sender, EventArgs e) + { + LineChartConfig data = new LineChartConfig(); + data.FilePath = "D:\\Papka\\КОП\\ExcelDiagram.xls"; + data.Header = "MyDiagram"; + data.ChartTitle = "Diagram"; + string[] Names = { "Первая", "Вторая" }; + + var list2D = new Dictionary>(); + + for (var i = 0; i < 2; i++) + { + var row = new List(); + for (var j = 0; j < 5; j++) + row.Add(5 * i + j + 1); + + list2D.Add(Names[i], row); + } + + data.Values = list2D; + + DiagramComponent diagram = new DiagramComponent(); + diagram.CreateExcel(data); + } + } +} diff --git a/Library/LibraryView/FormSecond.resx b/Library/LibraryView/FormSecond.resx new file mode 100644 index 0000000..8e89b0f --- /dev/null +++ b/Library/LibraryView/FormSecond.resx @@ -0,0 +1,63 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + 17, 17 + + \ No newline at end of file diff --git a/Library/LibraryView/LibraryView.csproj b/Library/LibraryView/LibraryView.csproj index b57c89e..6136776 100644 --- a/Library/LibraryView/LibraryView.csproj +++ b/Library/LibraryView/LibraryView.csproj @@ -8,4 +8,12 @@ enable + + + + + + + + \ No newline at end of file diff --git a/Library/LibraryView/People.cs b/Library/LibraryView/People.cs new file mode 100644 index 0000000..d7775ac --- /dev/null +++ b/Library/LibraryView/People.cs @@ -0,0 +1,46 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace LibraryView +{ + public class People + { + public int ID { get; set; } + + public string Status { get; set; } + + public string Name { get; set; } + + public string Surname { get; set; } + + public int Age { get; set; } + + public int Kid { get; set; } + + public string Division { get; set; } + + public string Post { get; set; } + + public int Prize { get; set; } + + public People() + { + } + + public People(int ID, string Status, string Name, string Surname, int Age, int Kid, string Division, string Post, int Prize) + { + this.ID = ID; + this.Status = Status; + this.Name = Name; + this.Surname = Surname; + this.Age = Age; + this.Kid = Kid; + this.Division = Division; + this.Post = Post; + this.Prize = Prize; + } + } +} diff --git a/Library/LibraryView/Program.cs b/Library/LibraryView/Program.cs index 6a2fcd2..f18829b 100644 --- a/Library/LibraryView/Program.cs +++ b/Library/LibraryView/Program.cs @@ -11,7 +11,7 @@ namespace LibraryView // To customize application configuration such as set high DPI settings or default font, // see https://aka.ms/applicationconfiguration. ApplicationConfiguration.Initialize(); - Application.Run(new Form1()); + Application.Run(new FormSecond()); } } } \ No newline at end of file