Labs 1 & 2

This commit is contained in:
Максим Сергунов 2023-11-16 19:05:42 +04:00
parent 0c6577512f
commit 07ccf1e048
33 changed files with 1831 additions and 170 deletions

View File

@ -0,0 +1,36 @@
namespace CustomComponents
{
partial class BigTextComponent
{
/// <summary>
/// Обязательная переменная конструктора.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Освободить все используемые ресурсы.
/// </summary>
/// <param name="disposing">истинно, если управляемый ресурс должен быть удален; иначе ложно.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Код, автоматически созданный конструктором компонентов
/// <summary>
/// Требуемый метод для поддержки конструктора — не изменяйте
/// содержимое этого метода с помощью редактора кода.
/// </summary>
private void InitializeComponent()
{
components = new System.ComponentModel.Container();
}
#endregion
}
}

View File

@ -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("Документ успешно создан!");
}
}
}

View File

@ -0,0 +1,15 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0-windows</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<UseWindowsForms>true</UseWindowsForms>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Excel-DNA.Interop" Version="15.0.1" />
<PackageReference Include="Microsoft.Office.Excel" Version="14.0.4760.1000" />
</ItemGroup>
</Project>

View File

@ -0,0 +1,70 @@
namespace CustomComponents
{
partial class DateTextBox
{
/// <summary>
/// Обязательная переменная конструктора.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Освободить все используемые ресурсы.
/// </summary>
/// <param name="disposing">истинно, если управляемый ресурс должен быть удален; иначе ложно.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Код, автоматически созданный конструктором компонентов
/// <summary>
/// Требуемый метод для поддержки конструктора — не изменяйте
/// содержимое этого метода с помощью редактора кода.
/// </summary>
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;
}
}

View File

@ -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);
}
}
}

View File

@ -0,0 +1,60 @@
<root>
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
</root>

View File

@ -0,0 +1,36 @@
namespace CustomComponents
{
partial class DiagramComponent
{
/// <summary>
/// Обязательная переменная конструктора.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Освободить все используемые ресурсы.
/// </summary>
/// <param name="disposing">истинно, если управляемый ресурс должен быть удален; иначе ложно.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Код, автоматически созданный конструктором компонентов
/// <summary>
/// Требуемый метод для поддержки конструктора — не изменяйте
/// содержимое этого метода с помощью редактора кода.
/// </summary>
private void InitializeComponent()
{
components = new System.ComponentModel.Container();
}
#endregion
}
}

View File

@ -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);
}
}
}

View File

@ -0,0 +1,71 @@
namespace CustomComponents
{
partial class DropDownList
{
/// <summary>
/// Обязательная переменная конструктора.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Освободить все используемые ресурсы.
/// </summary>
/// <param name="disposing">истинно, если управляемый ресурс должен быть удален; иначе ложно.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Код, автоматически созданный конструктором компонентов
/// <summary>
/// Требуемый метод для поддержки конструктора — не изменяйте
/// содержимое этого метода с помощью редактора кода.
/// </summary>
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;
}
}

View File

@ -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);
}
}
}

View File

@ -0,0 +1,60 @@
<root>
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
</root>

View File

@ -0,0 +1,10 @@
namespace CustomComponents
{
public enum LegendPosition
{
Left,
Top,
Right,
Botton,
}
}

View File

@ -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<string, List<int>> Values { get; set; }
public LegendPosition LegendPosition { get; set; }
}
}

View File

@ -0,0 +1,58 @@
namespace CustomComponents
{
partial class ListBoxObjects
{
/// <summary>
/// Обязательная переменная конструктора.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Освободить все используемые ресурсы.
/// </summary>
/// <param name="disposing">истинно, если управляемый ресурс должен быть удален; иначе ложно.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Код, автоматически созданный конструктором компонентов
/// <summary>
/// Требуемый метод для поддержки конструктора — не изменяйте
/// содержимое этого метода с помощью редактора кода.
/// </summary>
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;
}
}

View File

@ -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<T>() 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>(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);
}
}
}

View File

@ -0,0 +1,60 @@
<root>
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
</root>

View File

@ -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;
}
}
}

View File

@ -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()
{
}
}
}

View File

@ -0,0 +1,36 @@
namespace CustomComponents
{
partial class TableComponent
{
/// <summary>
/// Обязательная переменная конструктора.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Освободить все используемые ресурсы.
/// </summary>
/// <param name="disposing">истинно, если управляемый ресурс должен быть удален; иначе ложно.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Код, автоматически созданный конструктором компонентов
/// <summary>
/// Требуемый метод для поддержки конструктора — не изменяйте
/// содержимое этого метода с помощью редактора кода.
/// </summary>
private void InitializeComponent()
{
components = new System.ComponentModel.Container();
}
#endregion
}
}

View File

@ -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<string> columnsName = new List<string>();
public TableComponent()
{
InitializeComponent();
}
public TableComponent(IContainer container)
{
container.Add(this);
InitializeComponent();
}
public bool CreateTableExcel<T>(string path, string title, List<MergeCells> mergeCells, int[] colsWidth, string[] headings, List<string> columnsName, List<T> 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<int> mergeInds = new List<int>();
//Объединение ячеек по столбцам
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;
}
}
}
}

View File

@ -5,6 +5,8 @@ VisualStudioVersion = 17.5.33530.505
MinimumVisualStudioVersion = 10.0.40219.1 MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LibraryView", "LibraryView\LibraryView.csproj", "{50CEADA7-BB8C-41AB-BAB5-F29DF48E581F}" Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LibraryView", "LibraryView\LibraryView.csproj", "{50CEADA7-BB8C-41AB-BAB5-F29DF48E581F}"
EndProject EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CustomComponents", "CustomComponents\CustomComponents.csproj", "{F6B42349-8FB3-4D68-8757-D26DAD2F0992}"
EndProject
Global Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU 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}.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.ActiveCfg = Release|Any CPU
{50CEADA7-BB8C-41AB-BAB5-F29DF48E581F}.Release|Any CPU.Build.0 = 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 EndGlobalSection
GlobalSection(SolutionProperties) = preSolution GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE HideSolutionNode = FALSE

View File

@ -1,39 +0,0 @@
namespace LibraryView
{
partial class Form1
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
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
}
}

View File

@ -1,10 +0,0 @@
namespace LibraryView
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
}
}

View File

@ -1,120 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
</root>

View File

@ -0,0 +1,257 @@
namespace LibraryView
{
partial class FormLibrary
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
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;
}
}

View File

@ -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<Person>(person1);
listBoxObjects1.AddInListBox<Person>(person2);
}
private void buttonShowItem_Click(object sender, EventArgs e)
{
string str = listBoxObjects1.GetObjectFromStr<Person>()
.Name + " " + listBoxObjects1.GetObjectFromStr<Person>()
.Surname;
labelShowInput.Text = str;
}
}
}

View File

@ -0,0 +1,60 @@
<root>
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
</root>

View File

@ -0,0 +1,89 @@
namespace LibraryView
{
partial class FormSecond
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
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;
}
}

View File

@ -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<MergeCells>();
//table.columnsName = new List<string>() { "ID", "Status", "Name", "Surname", "Age", "Kid", "Division", "Post", "Prize" };
var columnsName = new List<string>() { "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<People>() { 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<string, List<int>>();
for (var i = 0; i < 2; i++)
{
var row = new List<int>();
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);
}
}
}

View File

@ -0,0 +1,63 @@
<root>
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<metadata name="bigTextComponent1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>17, 17</value>
</metadata>
</root>

View File

@ -8,4 +8,12 @@
<ImplicitUsings>enable</ImplicitUsings> <ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup> </PropertyGroup>
<ItemGroup>
<PackageReference Include="Aspose.Cells" Version="23.9.0" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\CustomComponents\CustomComponents.csproj" />
</ItemGroup>
</Project> </Project>

View File

@ -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;
}
}
}

View File

@ -11,7 +11,7 @@ namespace LibraryView
// To customize application configuration such as set high DPI settings or default font, // To customize application configuration such as set high DPI settings or default font,
// see https://aka.ms/applicationconfiguration. // see https://aka.ms/applicationconfiguration.
ApplicationConfiguration.Initialize(); ApplicationConfiguration.Initialize();
Application.Run(new Form1()); Application.Run(new FormSecond());
} }
} }
} }