Compare commits

...

5 Commits
main ... Lab2

35 changed files with 2614 additions and 0 deletions

31
KOP_Labs/KOP_Labs.sln Normal file
View File

@ -0,0 +1,31 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.7.34031.279
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Library_var_4_lab_1", "Library_var_4_lab_1\Library_var_4_lab_1.csproj", "{54FEDC65-63CA-474A-9D78-FCACE673AA3F}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TestProj", "TestProj\TestProj.csproj", "{0FF632B3-8D31-403E-AC25-61283C15D2C9}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{54FEDC65-63CA-474A-9D78-FCACE673AA3F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{54FEDC65-63CA-474A-9D78-FCACE673AA3F}.Debug|Any CPU.Build.0 = Debug|Any CPU
{54FEDC65-63CA-474A-9D78-FCACE673AA3F}.Release|Any CPU.ActiveCfg = Release|Any CPU
{54FEDC65-63CA-474A-9D78-FCACE673AA3F}.Release|Any CPU.Build.0 = Release|Any CPU
{0FF632B3-8D31-403E-AC25-61283C15D2C9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{0FF632B3-8D31-403E-AC25-61283C15D2C9}.Debug|Any CPU.Build.0 = Debug|Any CPU
{0FF632B3-8D31-403E-AC25-61283C15D2C9}.Release|Any CPU.ActiveCfg = Release|Any CPU
{0FF632B3-8D31-403E-AC25-61283C15D2C9}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {0115D661-19A6-4D29-9906-E1EA34CC92B2}
EndGlobalSection
EndGlobal

View File

@ -0,0 +1,36 @@
namespace Library_var_4_lab_1
{
partial class BigTextExcel
{
/// <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,43 @@
using OfficePackage.HelperModels;
using OfficePackage.Implements;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Library_var_4_lab_1
{
public partial class BigTextExcel : Component
{
SaveToExcel saveToExcel = new();
public BigTextExcel()
{
InitializeComponent();
}
public BigTextExcel(IContainer container)
{
container.Add(this);
InitializeComponent();
}
public void WriteToExcel(string path, string header, string[] text)
{
if (string.IsNullOrEmpty(path) || string.IsNullOrEmpty(header) || text == null)
{
throw new ArgumentNullException("Не все параметры введены");
}
ExcelInfo<object> info = new ExcelInfo<object>()
{
FileName = path,
Title = header,
Text = text
};
saveToExcel.WriteToFileBigText<object>(info);
}
}
}

View File

@ -0,0 +1,36 @@
namespace Library_var_4_lab_1
{
partial class ConfigurableTable
{
/// <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,45 @@
using DocumentFormat.OpenXml.Drawing;
using OfficePackage.HelperModels;
using OfficePackage.Implements;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Library_var_4_lab_1
{
public partial class ConfigurableTable : Component
{
SaveToExcel saveToExcel = new();
public ConfigurableTable()
{
InitializeComponent();
}
public ConfigurableTable(IContainer container)
{
container.Add(this);
InitializeComponent();
}
public void CreateTable<T>(string path, string header, List<TreeNode> tableHeadres, List<T> human)
{
if (string.IsNullOrEmpty(path) || string.IsNullOrEmpty(header)
|| tableHeadres == null || tableHeadres.Count == 0
|| human == null || human.Count == 0)
{
throw new ArgumentNullException("Не все параметры введены");
}
ExcelInfo<T> info = new ExcelInfo<T>();
info.FileName = path;
info.Title = header;
info.tableHeadres = tableHeadres;
info.TableData = human;
saveToExcel.WriteToFileConfigurableTable(info);
}
}
}

View File

@ -0,0 +1,57 @@
namespace Library_var_4_lab_1
{
partial class CustomListBox
{
/// <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()
{
listBox = new ListBox();
SuspendLayout();
//
// listBox
//
listBox.FormattingEnabled = true;
listBox.ItemHeight = 20;
listBox.Location = new Point(3, 3);
listBox.Name = "listBox";
listBox.Size = new Size(446, 144);
listBox.TabIndex = 0;
//
// CustomListBox
//
AutoScaleDimensions = new SizeF(8F, 20F);
AutoScaleMode = AutoScaleMode.Font;
Controls.Add(listBox);
Name = "CustomListBox";
Size = new Size(454, 188);
ResumeLayout(false);
}
#endregion
private ListBox listBox;
}
}

View File

@ -0,0 +1,107 @@
using System;
using System.CodeDom;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Library_var_4_lab_1
{
public partial class CustomListBox : UserControl
{
private List<string> properties = new();
string StartSimbol = string.Empty;
string EndSimbol = string.Empty;
private List<List<object>> values = new List<List<object>>();
private string Template = string.Empty;
private Regex Regex = new(string.Empty);
public CustomListBox()
{
InitializeComponent();
}
public void SetTemplate(string startSimbol, string endSimbol, string template)
{
string pattern = "\\" + startSimbol + "([^"+endSimbol+"]*)\\" + endSimbol;
Template = template;
StartSimbol = startSimbol;
EndSimbol = endSimbol;
Regex = new Regex(pattern);
properties.Clear();
listBox.Items.Clear();
values.Clear();
foreach (Match match in Regex.Matches(template))
properties.Add(match.Groups[1].Value);
for (int i = 0; i < properties.Count; i++)
{
values.Add(new List<object>());
}
}
public int SelectedIndex
{
get
{
return listBox.SelectedIndex;
}
set
{
listBox.SelectedIndex = value;
}
}
public void Add<T>(T Object)
{
var tmpTemplate = Template;
int i = 0;
foreach (var property in properties)
{
var tmpValue = typeof(T)?.GetProperty(property)?.GetValue(Object);
tmpTemplate = tmpTemplate.Replace(StartSimbol + property + EndSimbol, tmpValue?.ToString() ?? string.Empty);
values[i].Add(tmpValue ?? string.Empty);
i++;
}
listBox.Items.Add(tmpTemplate);
}
public T GetSelected<T>() where T : class, new()
{
string SelectedStr = "";
if (listBox.SelectedIndex != -1)
{
SelectedStr = listBox.SelectedItem.ToString();
}
T currentObject = new T();
Type objectType = typeof(T);
int rowIndex = listBox.SelectedIndex;
int colIndex = 0;
foreach (var prop in properties)
{
var field = objectType.GetProperty(prop);
if (!field?.CanWrite ?? false)
{
continue;
}
int startS = SelectedStr.IndexOf(values[colIndex][rowIndex].ToString());
if (startS == -1)
{
break;
}
string propValue = SelectedStr.Substring(startS, values[colIndex][rowIndex].ToString().Length);
if (SelectedStr.Length > startS + values[colIndex][rowIndex].ToString().Length + 1)
SelectedStr = SelectedStr.Substring(startS + values[colIndex][rowIndex].ToString().Length + 1);
field?.SetValue(currentObject, Convert.ChangeType(propValue, field.PropertyType));
colIndex++;
}
return currentObject;
}
}
}

View File

@ -0,0 +1,120 @@
<?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,61 @@
namespace Library_var_4_lab_1
{
partial class DateInputBox
{
/// <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();
textBoxDateInput = new TextBox();
toolTip1 = new ToolTip(components);
SuspendLayout();
//
// textBoxDateInput
//
textBoxDateInput.Location = new Point(3, 3);
textBoxDateInput.Name = "textBoxDateInput";
textBoxDateInput.Size = new Size(238, 27);
textBoxDateInput.TabIndex = 0;
textBoxDateInput.TextChanged += textBox_ValueChanged;
textBoxDateInput.MouseMove += textBox_MouseMove;
//
// DateInputBox
//
AutoScaleDimensions = new SizeF(8F, 20F);
AutoScaleMode = AutoScaleMode.Font;
Controls.Add(textBoxDateInput);
Name = "DateInputBox";
Size = new Size(246, 39);
ResumeLayout(false);
PerformLayout();
}
#endregion
private TextBox textBoxDateInput;
private ToolTip toolTip1;
}
}

View File

@ -0,0 +1,66 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using System.Windows.Forms;
using static System.Windows.Forms.VisualStyles.VisualStyleElement;
namespace Library_var_4_lab_1
{
public partial class DateInputBox : UserControl
{
public string Template = string.Empty;
private string Example = string.Empty;
public string Date
{
get
{
if (string.IsNullOrEmpty(Template))
throw new TemplateNotSetException();
Regex regex = new Regex(Template);
if (regex.IsMatch(textBoxDateInput.Text))
return textBoxDateInput.Text;
else throw new InvalidArgumentException();
}
set
{
Regex regex = new Regex(Template);
if (!string.IsNullOrEmpty(Template) && regex.IsMatch(value))
textBoxDateInput.Text = value;
}
}
private event EventHandler? _changeValue;
public event EventHandler ChangeValue
{
add => _changeValue += value;
remove => _changeValue -= value;
}
public DateInputBox()
{
InitializeComponent();
}
public void setExample(string example)
{
Example = example;
}
private void textBox_MouseMove(object sender, MouseEventArgs e)
{
toolTip1.SetToolTip(textBoxDateInput, Example);
}
private void textBox_ValueChanged(object sender, EventArgs e)
{
_changeValue?.Invoke(this, e);
}
}
}

View File

@ -0,0 +1,123 @@
<?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>
<metadata name="toolTip1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>17, 17</value>
</metadata>
</root>

View File

@ -0,0 +1,16 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Library_var_4_lab_1
{
public enum DiagramLegendLocation
{
Right,
Left,
Top,
Bottom
}
}

View File

@ -0,0 +1,59 @@
namespace Library_var_4_lab_1
{
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();
SuspendLayout();
//
// comboBox
//
comboBox.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
comboBox.DropDownStyle = ComboBoxStyle.DropDownList;
comboBox.FormattingEnabled = true;
comboBox.Location = new Point(3, 3);
comboBox.Name = "comboBox";
comboBox.Size = new Size(305, 28);
comboBox.TabIndex = 0;
comboBox.SelectedIndexChanged += comboBox_SelectedIndexChanged;
//
// DropDownList
//
AutoScaleDimensions = new SizeF(8F, 20F);
AutoScaleMode = AutoScaleMode.Font;
Controls.Add(comboBox);
Name = "DropDownList";
Size = new Size(311, 230);
ResumeLayout(false);
}
#endregion
private ComboBox comboBox;
}
}

View File

@ -0,0 +1,51 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Library_var_4_lab_1
{
public partial class DropDownList : UserControl
{
private event EventHandler? _changeIndex;
public event EventHandler ChangeIndex
{
add => _changeIndex += value;
remove => _changeIndex -= value;
}
public DropDownList()
{
InitializeComponent();
}
public string SelectedItem
{
get => comboBox.SelectedItem?.ToString() ?? string.Empty;
set => comboBox.SelectedIndex = comboBox.Items.IndexOf(value);
}
public void Input(string value)
{
if (string.IsNullOrEmpty(value))
throw new ArgumentNullException("value");
comboBox.Items.Add(value);
}
public void ClearList()
{
comboBox.Items.Clear();
}
private void comboBox_SelectedIndexChanged(object sender, EventArgs e)
{
_changeIndex?.Invoke(this, e);
}
}
}

View File

@ -0,0 +1,120 @@
<?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,18 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.Text;
using System.Threading.Tasks;
namespace Library_var_4_lab_1
{
[Serializable]
internal class InvalidArgumentException : ApplicationException
{
public InvalidArgumentException() : base("Значение не соответсвует шаблону") { }
public InvalidArgumentException(string message) : base(message) { }
public InvalidArgumentException(string message, Exception exception) : base(message, exception) { }
public InvalidArgumentException(SerializationInfo info, StreamingContext context) : base(info, context) { }
}
}

View File

@ -0,0 +1,15 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0-windows</TargetFramework>
<Nullable>enable</Nullable>
<UseWindowsForms>true</UseWindowsForms>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Aspose.Cells" Version="24.9.0" />
<PackageReference Include="DocumentFormat.OpenXml" Version="3.1.0" />
</ItemGroup>
</Project>

View File

@ -0,0 +1,36 @@
namespace Library_var_4_lab_1
{
partial class LineDiagram
{
/// <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,49 @@
using Library_var_4_lab_1.OfficePackage.HelperModels;
using OfficePackage.HelperModels;
using OfficePackage.Implements;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Library_var_4_lab_1
{
public partial class LineDiagram : Component
{
private LineDiagramCreation diagramCreation = new();
public LineDiagram()
{
InitializeComponent();
}
public LineDiagram(IContainer container)
{
container.Add(this);
InitializeComponent();
}
public void CreateDiagram(string path, string header, string diagramHeader, DiagramLegendLocation legendLocation, List<(string, List<(string Name, double Value)>)> data)
{
if (string.IsNullOrEmpty(path) || string.IsNullOrEmpty(header)
|| string.IsNullOrEmpty(diagramHeader)
|| data == null || data.Count == 0)
{
throw new ArgumentNullException(nameof(path));
}
DiagramInfo info = new()
{
path = path,
header = header,
diagramHeader = diagramHeader,
legendLocation = legendLocation,
data = data
};
LineDiagramCreation creation = new();
creation.Create(info);
}
}
}

View File

@ -0,0 +1,64 @@
using Aspose.Cells;
using Aspose.Cells.Charts;
using Library_var_4_lab_1.OfficePackage.HelperModels;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Library_var_4_lab_1
{
public class LineDiagramCreation
{
Workbook workbook = new Workbook();
Worksheet worksheet;
public string Alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
public void Create(DiagramInfo info)
{
worksheet = workbook.Worksheets[0];
worksheet.Cells["A1"].PutValue(info.header);
int rowIndex = 2;
foreach (var category in info.data[0].values)
{
worksheet.Cells[$"ZA{rowIndex}"].PutValue(category.Item1);
rowIndex++;
}
rowIndex = 2;
int columnIndex = 1;
foreach (var column in info.data)
{
worksheet.Cells[$"Z{Alphabet.ElementAt(columnIndex)}1"].PutValue(column.seriesName);
rowIndex = 2;
foreach (var row in column.values)
{
worksheet.Cells[$"Z{Alphabet.ElementAt(columnIndex)}{rowIndex}"].PutValue(row.Value);
rowIndex++;
}
columnIndex++;
}
int chartIndex = worksheet.Charts.Add(ChartType.Line, 5, 0, 15, 5);
Chart chart = worksheet.Charts[chartIndex];
chart.SetChartDataRange("ZA1:ZC4", true);
chart.Title.Text = info.diagramHeader;
switch (info.legendLocation)
{
case DiagramLegendLocation.Left:
chart.Legend.Position = LegendPositionType.Left;
break;
case DiagramLegendLocation.Right:
chart.Legend.Position = LegendPositionType.Right;
break;
case DiagramLegendLocation.Top:
chart.Legend.Position = LegendPositionType.Top;
break;
case DiagramLegendLocation.Bottom:
chart.Legend.Position = LegendPositionType.Bottom;
break;
}
workbook.Save("C:\\Users\\123\\Desktop\\Lab2_KOP2.xlsx");
}
}
}

View File

@ -0,0 +1,27 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Library_var_4_lab_1
{
public class LineDiagramInfo
{
public string FileName { get; set; } = string.Empty;
public string Title { get; set; } = string.Empty;
public string DiagramTitle { get; set; } = string.Empty;
public DiagramLegendLocation LegendLocation { get; set; } = DiagramLegendLocation.Right;
public List<Dictionary<string, List<(string Name, double Value)>>> Data { get; set; } = new();
public void CheckFields()
{
if (string.IsNullOrEmpty(FileName))
throw new ArgumentNullException(nameof(FileName), "File path and name cannot be null or empty.");
if (string.IsNullOrEmpty(Title))
throw new ArgumentNullException(nameof(Title), "Title cannot be null or empty.");
if (Data == null || !Data.Any())
throw new ArgumentNullException(nameof(Data), "DiagramData cannot be null or empty.");
}
}
}

View File

@ -0,0 +1,168 @@
using DocumentFormat.OpenXml.Drawing.Charts;
using DocumentFormat.OpenXml.Vml;
using DocumentFormat.OpenXml.Wordprocessing;
using OfficePackage.HelperEnums;
using OfficePackage.HelperModels;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace OfficePackage
{
public abstract class AbstractSaveToExcel
{
public string Alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
public List<string> properties = new List<string>();
/// <summary>
/// Создание отчета
/// </summary>
/// <param name="info"></param>
public void WriteToFileBigText<T>(ExcelInfo<T> info)
{
OpenExcel<T>(info);
InsertCellInWorksheet(new ExcelCellParameters
{
ColumnName = "A",
RowIndex = 1,
Text = info.Title,
StyleInfo = ExcelStyleInfoType.Title
});
uint rowIndex = 3;
foreach (string line in info.Text)
{
InsertCellInWorksheet(new ExcelCellParameters
{
ColumnName = "A",
RowIndex = rowIndex,
Text = line,
StyleInfo = ExcelStyleInfoType.Text
});
rowIndex++;
}
SaveExcel<T>(info);
}
public void WriteToFileConfigurableTable<T>(ExcelInfo<T> info)
{
OpenExcel(info);
InsertCellInWorksheet(new ExcelCellParameters
{
ColumnName = "A",
RowIndex = 1,
Text = info.Title,
StyleInfo = ExcelStyleInfoType.Title
});
int colIndex = 0;
foreach (var node in info.tableHeadres)
{
InsertCellInWorksheet(new ExcelCellParameters
{
ColumnName = Alphabet.ElementAt(colIndex).ToString(),
RowIndex = 2,
Text = node.Text,
StyleInfo = ExcelStyleInfoType.Title
});
if (node.Nodes.Count == 0)
properties.Add(node.Tag?.ToString() ?? string.Empty);
if (node.Nodes.Count > 0)
{
for (int i = 0; i < node.Nodes.Count; i++)
{
InsertCellInWorksheet(new ExcelCellParameters
{
ColumnName = Alphabet.ElementAt(colIndex + i).ToString(),
RowIndex = 3,
Text = node.Nodes[i].Text,
StyleInfo = ExcelStyleInfoType.Title
});
properties.Add(node.Nodes[i].Tag?.ToString() ?? string.Empty);
}
}
colIndex++;
}
colIndex = 0;
ExcelMergeParameters mergeParams = new ExcelMergeParameters();
foreach (var column in info.tableHeadres)
{
if (column.Nodes.Count == 0)
{
mergeParams.colIndex = colIndex;
mergeParams.isHorisontel = false;
mergeParams.count = 1;
MergeCells(mergeParams);
}
if (column.Nodes.Count > 0)
{
mergeParams.colIndex = colIndex;
mergeParams.isHorisontel = true;
mergeParams.count = column.Nodes.Count;
MergeCells(mergeParams);
}
colIndex++;
}
int rowIndex = 4;
foreach (var obj in info.TableData)
{
if (obj == null) continue;
for (int i = 0; i < properties.Count; i++)
{
string propertieName = properties[i];
var propertie = obj.GetType().GetProperty(propertieName);
if (propertie is null)
throw new ArgumentException($"Не удалось найти свойство {propertieName}");
var value = propertie.GetValue(obj)?.ToString();
if (value == null)
throw new ArgumentException($"Не удалось найти свойство {propertieName}");
InsertCellInWorksheet(new ExcelCellParameters()
{
Text = value,
ColumnName = Alphabet.ElementAt(i).ToString(),
RowIndex = (UInt32)rowIndex,
StyleInfo = ExcelStyleInfoType.TextWithBroder,
});
}
rowIndex++;
}
SaveExcel(info);
}
public void CreateDiagram(ExcelInfo<object> info)
{
OpenExcel(info);
InsertCellInWorksheet(new ExcelCellParameters
{
ColumnName = "A",
RowIndex = 1,
Text = info.Title,
StyleInfo = ExcelStyleInfoType.Title
});
}
/// <summary>
/// Создание excel-файла
/// </summary>
/// <param name="info"></param>
protected abstract void OpenExcel<T>(ExcelInfo<T> info);
/// <summary>
/// Добавляем новую ячейку в лист
/// </summary>
/// <param name="cellParameters"></param>
protected abstract void InsertCellInWorksheet(ExcelCellParameters
excelParams);
/// <summary>
/// Объединение ячеек
/// </summary>
/// <param name="mergeParameters"></param>
protected abstract void MergeCells(ExcelMergeParameters excelParams);
protected abstract void CreateLineDiagram(ExcelInfo<object> info);
/// <summary>
/// Сохранение файла
/// </summary>
/// <param name="info"></param>
protected abstract void SaveExcel<T>(ExcelInfo<T> info);
}
}

View File

@ -0,0 +1,15 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace OfficePackage.HelperEnums
{
public enum ExcelStyleInfoType
{
Title,
Text,
TextWithBroder
}
}

View File

@ -0,0 +1,17 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Library_var_4_lab_1.OfficePackage.HelperModels
{
public class DiagramInfo
{
public string path { get; set; } = string.Empty;
public string header { get; set; } = string.Empty;
public string diagramHeader { get; set; } = string.Empty;
public DiagramLegendLocation legendLocation { get; set; } = DiagramLegendLocation.Right;
public List<(string seriesName, List<(string Name, double Value)> values)> data { get; set; } = new();
}
}

View File

@ -0,0 +1,18 @@
using OfficePackage.HelperEnums;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace OfficePackage.HelperModels
{
public class ExcelCellParameters
{
public string ColumnName { get; set; } = string.Empty;
public uint RowIndex { get; set; }
public string Text { get; set; } = string.Empty;
public string CellReference => $"{ColumnName}{RowIndex}";
public ExcelStyleInfoType StyleInfo { get; set; }
}
}

View File

@ -0,0 +1,32 @@
using Library_var_4_lab_1;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace OfficePackage.HelperModels
{
public class ExcelInfo<T>
{
public string FileName { get; set; } = string.Empty;
public string Title { get; set; } = string.Empty;
public string[]? Text { get; set; }
public List<TreeNode> tableHeadres { get; set; }
public List<T> TableData { get; set; }
public string DiagramTitle { get; set; } = string.Empty;
public DiagramLegendLocation LegendLocation { get; set; } = DiagramLegendLocation.Right;
public List<Dictionary<string, List<(string Name, double Value)>>> DiagramData { get; set; } = new();
public void CheckFields()
{
if (string.IsNullOrEmpty(FileName))
throw new ArgumentNullException(nameof(FileName), "File path and name cannot be null or empty.");
if (string.IsNullOrEmpty(Title))
throw new ArgumentNullException(nameof(Title), "Title cannot be null or empty.");
if (DiagramData == null || !DiagramData.Any())
throw new ArgumentNullException(nameof(DiagramData), "DiagramData cannot be null or empty.");
}
}
}

View File

@ -0,0 +1,24 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace OfficePackage.HelperModels
{
public class ExcelMergeParameters
{
public string CellFromName { get; set; } = string.Empty;
public string CellToName { get; set; } = string.Empty;
public int? ColumnFromName { get; set; } = null;
public int? ColumnToName { get; set; } = null;
public string Merge => $"{CellFromName}:{CellToName}";
public string MergeColumns => $"{Alphabet.ElementAt(ColumnFromName ?? 0)}2:{Alphabet.ElementAt(ColumnToName ?? 0)}2";
public string Alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
public int colIndex { get; set; }
public bool isHorisontel = false;
public int count = 1;
}
}

View File

@ -0,0 +1,393 @@
using OfficePackage.HelperEnums;
using OfficePackage.HelperModels;
using DocumentFormat.OpenXml.Office2010.Excel;
using DocumentFormat.OpenXml.Office2013.Excel;
using DocumentFormat.OpenXml.Office2016.Excel;
using DocumentFormat.OpenXml.Packaging;
using DocumentFormat.OpenXml.Spreadsheet;
using DocumentFormat.OpenXml;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Font = DocumentFormat.OpenXml.Spreadsheet.Font;
using DocumentFormat.OpenXml.Drawing.Charts;
using DocumentFormat.OpenXml.Office2016.Drawing.ChartDrawing;
using Text = DocumentFormat.OpenXml.Spreadsheet.Text;
namespace OfficePackage.Implements
{
public class SaveToExcel : AbstractSaveToExcel
{
private SpreadsheetDocument? _spreadsheetDocument;
private SharedStringTablePart? _shareStringPart;
private Worksheet? _worksheet;
/// <summary>
/// Настройка стилей для файла
/// </summary>
/// <param name="workbookpart"></param>
private static void CreateStyles(WorkbookPart workbookpart)
{
var sp = workbookpart.AddNewPart<WorkbookStylesPart>();
sp.Stylesheet = new Stylesheet();
var fonts = new Fonts() { Count = 2U, KnownFonts = true };
var fontUsual = new Font();
fontUsual.Append(new FontSize() { Val = 12D });
fontUsual.Append(new DocumentFormat.OpenXml.Office2010.Excel.Color()
{ Theme = 1U });
fontUsual.Append(new FontName() { Val = "Times New Roman" });
fontUsual.Append(new FontFamilyNumbering() { Val = 2 });
fontUsual.Append(new FontScheme() { Val = FontSchemeValues.Minor });
var fontTitle = new Font();
fontTitle.Append(new Bold());
fontTitle.Append(new FontSize() { Val = 14D });
fontTitle.Append(new DocumentFormat.OpenXml.Office2010.Excel.Color()
{ Theme = 1U });
fontTitle.Append(new FontName() { Val = "Times New Roman" });
fontTitle.Append(new FontFamilyNumbering() { Val = 2 });
fontTitle.Append(new FontScheme() { Val = FontSchemeValues.Minor });
fonts.Append(fontUsual);
fonts.Append(fontTitle);
var fills = new Fills() { Count = 2U };
var fill1 = new Fill();
fill1.Append(new PatternFill() { PatternType = PatternValues.None });
var fill2 = new Fill();
fill2.Append(new PatternFill()
{
PatternType = PatternValues.Gray125
});
fills.Append(fill1);
fills.Append(fill2);
var borders = new Borders() { Count = 2U };
var borderNoBorder = new Border();
borderNoBorder.Append(new LeftBorder());
borderNoBorder.Append(new RightBorder());
borderNoBorder.Append(new TopBorder());
borderNoBorder.Append(new BottomBorder());
borderNoBorder.Append(new DiagonalBorder());
var borderThin = new Border();
var leftBorder = new LeftBorder() { Style = BorderStyleValues.Thin };
leftBorder.Append(new DocumentFormat.OpenXml.Office2010.Excel.Color()
{ Indexed = 64U });
var rightBorder = new RightBorder()
{
Style = BorderStyleValues.Thin
};
rightBorder.Append(new
DocumentFormat.OpenXml.Office2010.Excel.Color()
{ Indexed = 64U });
var topBorder = new TopBorder() { Style = BorderStyleValues.Thin };
topBorder.Append(new DocumentFormat.OpenXml.Office2010.Excel.Color()
{ Indexed = 64U });
var bottomBorder = new BottomBorder()
{
Style =
BorderStyleValues.Thin
};
bottomBorder.Append(new
DocumentFormat.OpenXml.Office2010.Excel.Color()
{ Indexed = 64U });
borderThin.Append(leftBorder);
borderThin.Append(rightBorder);
borderThin.Append(topBorder);
borderThin.Append(bottomBorder);
borderThin.Append(new DiagonalBorder());
borders.Append(borderNoBorder);
borders.Append(borderThin);
var cellStyleFormats = new CellStyleFormats() { Count = 1U };
var cellFormatStyle = new CellFormat()
{
NumberFormatId = 0U,
FontId = 0U,
FillId = 0U,
BorderId = 0U
};
cellStyleFormats.Append(cellFormatStyle);
var cellFormats = new CellFormats() { Count = 3U };
var cellFormatFont = new CellFormat()
{
NumberFormatId = 0U,
FontId = 0U,
FillId = 0U,
BorderId = 0U,
FormatId = 0U,
ApplyFont = true
};
var cellFormatFontAndBorder = new CellFormat()
{
NumberFormatId = 0U,
FontId = 0U,
FillId = 0U,
BorderId = 1U,
FormatId = 0U,
ApplyFont = true,
ApplyBorder = true
};
var cellFormatTitle = new CellFormat()
{
NumberFormatId = 0U,
FontId = 1U,
FillId = 0U,
BorderId = 0U,
FormatId = 0U,
Alignment = new Alignment()
{
Vertical = VerticalAlignmentValues.Center,
WrapText = false,
Horizontal = HorizontalAlignmentValues.Center
},
ApplyFont = true
};
cellFormats.Append(cellFormatFont);
cellFormats.Append(cellFormatFontAndBorder);
cellFormats.Append(cellFormatTitle);
var cellStyles = new CellStyles() { Count = 1U };
cellStyles.Append(new CellStyle()
{
Name = "Normal",
FormatId = 0U,
BuiltinId = 0U
});
var differentialFormats = new
DocumentFormat.OpenXml.Office2013.Excel.DifferentialFormats()
{ Count = 0U };
var tableStyles = new TableStyles()
{
Count = 0U,
DefaultTableStyle =
"TableStyleMedium2",
DefaultPivotStyle = "PivotStyleLight16"
};
var stylesheetExtensionList = new StylesheetExtensionList();
var stylesheetExtension1 = new StylesheetExtension()
{
Uri = "{EB79DEF2-80B8-43e5-95BD-54CBDDF9020C}"
};
stylesheetExtension1.AddNamespaceDeclaration("x14",
"http://schemas.microsoft.com/office/spreadsheetml/2009/9/main");
stylesheetExtension1.Append(new SlicerStyles()
{
DefaultSlicerStyle =
"SlicerStyleLight1"
});
var stylesheetExtension2 = new StylesheetExtension()
{
Uri =
"{9260A510-F301-46a8-8635-F512D64BE5F5}"
};
stylesheetExtension2.AddNamespaceDeclaration("x15",
"http://schemas.microsoft.com/office/spreadsheetml/2010/11/main");
stylesheetExtension2.Append(new TimelineStyles()
{
DefaultTimelineStyle = "TimeSlicerStyleLight1"
});
stylesheetExtensionList.Append(stylesheetExtension1);
stylesheetExtensionList.Append(stylesheetExtension2);
sp.Stylesheet.Append(fonts);
sp.Stylesheet.Append(fills);
sp.Stylesheet.Append(borders);
sp.Stylesheet.Append(cellStyleFormats);
sp.Stylesheet.Append(cellFormats);
sp.Stylesheet.Append(cellStyles);
sp.Stylesheet.Append(differentialFormats);
sp.Stylesheet.Append(tableStyles);
sp.Stylesheet.Append(stylesheetExtensionList);
}
/// <summary>
/// Получение номера стиля из типа
/// </summary>
/// <param name="styleInfo"></param>
/// <returns></returns>
private static uint GetStyleValue(ExcelStyleInfoType styleInfo)
{
return styleInfo switch
{
ExcelStyleInfoType.Title => 2U,
ExcelStyleInfoType.TextWithBroder => 1U,
ExcelStyleInfoType.Text => 0U,
_ => 0U,
};
}
protected override void OpenExcel<T>(ExcelInfo<T> info)
{
_spreadsheetDocument = SpreadsheetDocument.Create(info.FileName, SpreadsheetDocumentType.Workbook);
// Создаем книгу (в ней хранятся листы)
var workbookpart = _spreadsheetDocument.AddWorkbookPart();
workbookpart.Workbook = new Workbook();
CreateStyles(workbookpart);
// Получаем/создаем хранилище текстов для книги
_shareStringPart =
_spreadsheetDocument.WorkbookPart!.GetPartsOfType<SharedStringTablePart>().Any()
?
_spreadsheetDocument.WorkbookPart.GetPartsOfType<SharedStringTablePart>().First()
:
_spreadsheetDocument.WorkbookPart.AddNewPart<SharedStringTablePart>();
// Создаем SharedStringTable, если его нет
if (_shareStringPart.SharedStringTable == null)
{
_shareStringPart.SharedStringTable = new SharedStringTable();
}
// Создаем лист в книгу
var worksheetPart = workbookpart.AddNewPart<WorksheetPart>();
worksheetPart.Worksheet = new Worksheet();
if (info.tableHeadres != null)
{
Columns columns = new Columns();
for (int i = 0; i < info.tableHeadres.Count; i++)
{
if (info.tableHeadres[i].Nodes.Count == 0)
columns.Append(new Column() { Min = (UInt32)i + 1, Max = (UInt32)i + 1, Width = Convert.ToInt32(info.tableHeadres[i].Name), CustomWidth = true });
else
for (int j = 0; j < info.tableHeadres[i].Nodes.Count; j++)
{
columns.Append(new Column() { Min = (UInt32)i + 1 + (UInt32)j, Max = (UInt32)i + 1 + (UInt32)j, Width = Convert.ToInt32(info.tableHeadres[i].Nodes[j].Name), CustomWidth = true });
}
}
worksheetPart.Worksheet.AppendChild(columns);
}
worksheetPart.Worksheet.AppendChild(new SheetData());
// Добавляем лист в книгу
var sheets =
_spreadsheetDocument.WorkbookPart.Workbook.AppendChild(new Sheets());
var sheet = new Sheet()
{
Id = _spreadsheetDocument.WorkbookPart.GetIdOfPart(worksheetPart),
SheetId = 1,
Name = "Лист"
};
sheets.Append(sheet);
_worksheet = worksheetPart.Worksheet;
}
protected override void InsertCellInWorksheet(ExcelCellParameters
excelParams)
{
if (excelParams.ColumnName.Length != 1)
MessageBox.Show("Буков много" + excelParams.ColumnName.Length);
if (_worksheet == null || _shareStringPart == null)
{
return;
}
var sheetData = _worksheet.GetFirstChild<SheetData>();
if (sheetData == null)
{
return;
}
// Ищем строку, либо добавляем ее
Row row;
if (sheetData.Elements<Row>().Where(r => r.RowIndex! ==
excelParams.RowIndex).Any())
{
row = sheetData.Elements<Row>().Where(r => r.RowIndex! ==
excelParams.RowIndex).First();
}
else
{
row = new Row() { RowIndex = excelParams.RowIndex };
sheetData.Append(row);
}
// Ищем нужную ячейку
Cell cell;
if (row.Elements<Cell>().Where(c => c.CellReference!.Value ==
excelParams.CellReference).Any())
{
cell = row.Elements<Cell>().Where(c => c.CellReference!.Value ==
excelParams.CellReference).First();
}
else
{
// Все ячейки должны быть последовательно друг за другом расположены
// нужно определить, после какой вставлять
Cell? refCell = null;
foreach (Cell rowCell in row.Elements<Cell>())
{
if (string.Compare(rowCell.CellReference!.Value,
excelParams.CellReference, true) > 0)
{
refCell = rowCell;
break;
}
}
var newCell = new Cell()
{
CellReference =
excelParams.CellReference
};
row.InsertBefore(newCell, refCell);
cell = newCell;
}
// вставляем новый текст
_shareStringPart.SharedStringTable.AppendChild(new
SharedStringItem(new Text(excelParams.Text)));
_shareStringPart.SharedStringTable.Save();
cell.CellValue = new
CellValue((_shareStringPart.SharedStringTable.Elements<SharedStringItem>().Count(
) - 1).ToString());
cell.DataType = new EnumValue<CellValues>(CellValues.SharedString);
cell.StyleIndex = GetStyleValue(excelParams.StyleInfo);
}
protected override void MergeCells(ExcelMergeParameters excelParams)
{
if (_worksheet == null)
{
return;
}
MergeCells mergeCells;
if (_worksheet.Elements<MergeCells>().Any())
{
mergeCells = _worksheet.Elements<MergeCells>().First();
}
else
{
mergeCells = new MergeCells();
if (_worksheet.Elements<CustomSheetView>().Any())
{
_worksheet.InsertAfter(mergeCells,
_worksheet.Elements<CustomSheetView>().First());
}
else
{
_worksheet.InsertAfter(mergeCells,
_worksheet.Elements<SheetData>().First());
}
}
MergeCell mergeCell = new MergeCell();
if (excelParams.isHorisontel == false)
{
mergeCell = new MergeCell()
{
Reference = new StringValue($"{Alphabet.ElementAt(excelParams.colIndex)}2:{Alphabet.ElementAt(excelParams.colIndex)}3")
};
mergeCells.Append(mergeCell);
}
if (excelParams.isHorisontel == true)
{
mergeCell = new MergeCell()
{
Reference = new StringValue($"{Alphabet.ElementAt(excelParams.colIndex)}2:{Alphabet.ElementAt(excelParams.colIndex + excelParams.count-1)}2")
};
mergeCells.Append(mergeCell);
}
}
protected override void CreateLineDiagram(ExcelInfo<object> info)
{
//LineChart chart =
//foreach (var series in info.DiagramData)
//{
// chart.
//}
}
protected override void SaveExcel<T>(ExcelInfo<T> info)
{
if (_spreadsheetDocument == null)
{
return;
}
_spreadsheetDocument.WorkbookPart!.Workbook.Save();
_spreadsheetDocument.Dispose();
}
}
}

View File

@ -0,0 +1,14 @@
using Microsoft.VisualBasic;
using System.Runtime.Serialization;
namespace Library_var_4_lab_1
{
[Serializable]
internal class TemplateNotSetException : ApplicationException
{
public TemplateNotSetException() : base("Шаблон не задан") { }
public TemplateNotSetException(string message) : base(message) { }
public TemplateNotSetException(string message, Exception exception) : base(message, exception) { }
public TemplateNotSetException(SerializationInfo info, StreamingContext context) : base(info, context) { }
}
}

422
KOP_Labs/TestProj/Form1.Designer.cs generated Normal file
View File

@ -0,0 +1,422 @@
namespace TestProj
{
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()
{
components = new System.ComponentModel.Container();
dropDownList1 = new Library_var_4_lab_1.DropDownList();
textBox1 = new TextBox();
buttonAdd = new Button();
buttonGet = new Button();
buttonSet = new Button();
buttonClear = new Button();
checkBox = new CheckBox();
dateInputBox1 = new Library_var_4_lab_1.DateInputBox();
buttonSetDate = new Button();
buttonGetDate = new Button();
buttonSetExample = new Button();
buttonSetTemplate = new Button();
customListBox1 = new Library_var_4_lab_1.CustomListBox();
textBoxInput = new TextBox();
textBoxEndSimbol = new TextBox();
textBoxStartSimbol = new TextBox();
textBoxName = new TextBox();
textBoxAge = new TextBox();
textBoxSurName = new TextBox();
label1 = new Label();
label2 = new Label();
label3 = new Label();
buttonSetPattern = new Button();
buttonGetIndex = new Button();
buttonSetItem = new Button();
buttonGetObject = new Button();
buttonSetIndex = new Button();
richTextBox = new RichTextBox();
bigTextExcel = new Library_var_4_lab_1.BigTextExcel(components);
buttonWriteLinesToExcel = new Button();
configurableTable1 = new Library_var_4_lab_1.ConfigurableTable(components);
button1 = new Button();
button2 = new Button();
SuspendLayout();
//
// dropDownList1
//
dropDownList1.Location = new Point(12, 12);
dropDownList1.Name = "dropDownList1";
dropDownList1.SelectedItem = "";
dropDownList1.Size = new Size(329, 44);
dropDownList1.TabIndex = 0;
//
// textBox1
//
textBox1.Location = new Point(12, 62);
textBox1.Name = "textBox1";
textBox1.Size = new Size(314, 27);
textBox1.TabIndex = 1;
//
// buttonAdd
//
buttonAdd.Location = new Point(12, 108);
buttonAdd.Name = "buttonAdd";
buttonAdd.Size = new Size(94, 29);
buttonAdd.TabIndex = 2;
buttonAdd.Text = "Добавить";
buttonAdd.UseVisualStyleBackColor = true;
buttonAdd.Click += buttonAdd_OnClick;
//
// buttonGet
//
buttonGet.Location = new Point(121, 108);
buttonGet.Name = "buttonGet";
buttonGet.Size = new Size(94, 29);
buttonGet.TabIndex = 3;
buttonGet.Text = "Get";
buttonGet.UseVisualStyleBackColor = true;
buttonGet.Click += buttonGet_OnClick;
//
// buttonSet
//
buttonSet.Location = new Point(232, 108);
buttonSet.Name = "buttonSet";
buttonSet.Size = new Size(94, 29);
buttonSet.TabIndex = 4;
buttonSet.Text = "Set";
buttonSet.UseVisualStyleBackColor = true;
buttonSet.Click += buttonSet_OnClick;
//
// buttonClear
//
buttonClear.Location = new Point(12, 143);
buttonClear.Name = "buttonClear";
buttonClear.Size = new Size(94, 29);
buttonClear.TabIndex = 5;
buttonClear.Text = "Очистка";
buttonClear.UseVisualStyleBackColor = true;
buttonClear.Click += buttonClear_OnClick;
//
// checkBox
//
checkBox.AutoSize = true;
checkBox.Location = new Point(371, 56);
checkBox.Name = "checkBox";
checkBox.Size = new Size(93, 24);
checkBox.TabIndex = 6;
checkBox.Text = "checkBox";
checkBox.UseVisualStyleBackColor = true;
//
// dateInputBox1
//
dateInputBox1.Location = new Point(529, 12);
dateInputBox1.Name = "dateInputBox1";
dateInputBox1.Size = new Size(245, 49);
dateInputBox1.TabIndex = 7;
//
// buttonSetDate
//
buttonSetDate.Location = new Point(12, 230);
buttonSetDate.Name = "buttonSetDate";
buttonSetDate.Size = new Size(94, 29);
buttonSetDate.TabIndex = 8;
buttonSetDate.Text = "Ввод даты";
buttonSetDate.UseVisualStyleBackColor = true;
buttonSetDate.Click += buttonSetDate_OnClick;
//
// buttonGetDate
//
buttonGetDate.Location = new Point(142, 230);
buttonGetDate.Name = "buttonGetDate";
buttonGetDate.Size = new Size(109, 29);
buttonGetDate.TabIndex = 9;
buttonGetDate.Text = "Вывод даты";
buttonGetDate.UseVisualStyleBackColor = true;
buttonGetDate.Click += buttonGetDate_OnClick;
//
// buttonSetExample
//
buttonSetExample.Location = new Point(142, 195);
buttonSetExample.Name = "buttonSetExample";
buttonSetExample.Size = new Size(134, 29);
buttonSetExample.TabIndex = 10;
buttonSetExample.Text = "Ввод примера";
buttonSetExample.UseVisualStyleBackColor = true;
buttonSetExample.Click += buttonSetExample_OnClick;
//
// buttonSetTemplate
//
buttonSetTemplate.Location = new Point(12, 195);
buttonSetTemplate.Name = "buttonSetTemplate";
buttonSetTemplate.Size = new Size(124, 29);
buttonSetTemplate.TabIndex = 11;
buttonSetTemplate.Text = "Ввод шаблона";
buttonSetTemplate.UseVisualStyleBackColor = true;
buttonSetTemplate.Click += buttonSetTemplate_OnClick;
//
// customListBox1
//
customListBox1.Location = new Point(529, 83);
customListBox1.Name = "customListBox1";
customListBox1.SelectedIndex = -1;
customListBox1.Size = new Size(463, 176);
customListBox1.TabIndex = 12;
//
// textBoxInput
//
textBoxInput.Location = new Point(529, 255);
textBoxInput.Name = "textBoxInput";
textBoxInput.Size = new Size(450, 27);
textBoxInput.TabIndex = 13;
//
// textBoxEndSimbol
//
textBoxEndSimbol.Location = new Point(946, 298);
textBoxEndSimbol.Name = "textBoxEndSimbol";
textBoxEndSimbol.Size = new Size(33, 27);
textBoxEndSimbol.TabIndex = 14;
//
// textBoxStartSimbol
//
textBoxStartSimbol.Location = new Point(880, 298);
textBoxStartSimbol.Name = "textBoxStartSimbol";
textBoxStartSimbol.Size = new Size(33, 27);
textBoxStartSimbol.TabIndex = 15;
//
// textBoxName
//
textBoxName.Location = new Point(529, 345);
textBoxName.Name = "textBoxName";
textBoxName.Size = new Size(161, 27);
textBoxName.TabIndex = 16;
//
// textBoxAge
//
textBoxAge.Location = new Point(529, 448);
textBoxAge.Name = "textBoxAge";
textBoxAge.Size = new Size(161, 27);
textBoxAge.TabIndex = 17;
//
// textBoxSurName
//
textBoxSurName.Location = new Point(529, 395);
textBoxSurName.Name = "textBoxSurName";
textBoxSurName.Size = new Size(161, 27);
textBoxSurName.TabIndex = 18;
//
// label1
//
label1.AutoSize = true;
label1.Location = new Point(529, 322);
label1.Name = "label1";
label1.Size = new Size(39, 20);
label1.TabIndex = 19;
label1.Text = "Имя";
//
// label2
//
label2.AutoSize = true;
label2.Location = new Point(529, 375);
label2.Name = "label2";
label2.Size = new Size(73, 20);
label2.TabIndex = 20;
label2.Text = "Фамилия";
//
// label3
//
label3.AutoSize = true;
label3.Location = new Point(529, 425);
label3.Name = "label3";
label3.Size = new Size(64, 20);
label3.TabIndex = 21;
label3.Text = "Возраст";
//
// buttonSetPattern
//
buttonSetPattern.Location = new Point(701, 343);
buttonSetPattern.Name = "buttonSetPattern";
buttonSetPattern.Size = new Size(136, 29);
buttonSetPattern.TabIndex = 22;
buttonSetPattern.Text = "Задать шаблон";
buttonSetPattern.UseVisualStyleBackColor = true;
buttonSetPattern.Click += buttonSetPattern_OnClick;
//
// buttonGetIndex
//
buttonGetIndex.Location = new Point(843, 343);
buttonGetIndex.Name = "buttonGetIndex";
buttonGetIndex.Size = new Size(136, 29);
buttonGetIndex.TabIndex = 23;
buttonGetIndex.Text = "Получит индекс";
buttonGetIndex.UseVisualStyleBackColor = true;
buttonGetIndex.Click += buttonGetIndex_Click;
//
// buttonSetItem
//
buttonSetItem.Location = new Point(696, 446);
buttonSetItem.Name = "buttonSetItem";
buttonSetItem.Size = new Size(141, 29);
buttonSetItem.TabIndex = 24;
buttonSetItem.Text = "Добавить пункт";
buttonSetItem.UseVisualStyleBackColor = true;
buttonSetItem.Click += buttonSetObject_OnClick;
//
// buttonGetObject
//
buttonGetObject.Location = new Point(843, 446);
buttonGetObject.Name = "buttonGetObject";
buttonGetObject.Size = new Size(136, 29);
buttonGetObject.TabIndex = 25;
buttonGetObject.Text = "Получить объект";
buttonGetObject.UseVisualStyleBackColor = true;
buttonGetObject.Click += buttonGetObject_OnClick;
//
// buttonSetIndex
//
buttonSetIndex.Location = new Point(843, 378);
buttonSetIndex.Name = "buttonSetIndex";
buttonSetIndex.Size = new Size(136, 29);
buttonSetIndex.TabIndex = 26;
buttonSetIndex.Text = "Задать индекс";
buttonSetIndex.UseVisualStyleBackColor = true;
buttonSetIndex.Click += buttonSetIndex_Click;
//
// richTextBox
//
richTextBox.Location = new Point(1022, 12);
richTextBox.Name = "richTextBox";
richTextBox.Size = new Size(316, 229);
richTextBox.TabIndex = 27;
richTextBox.Text = "";
//
// buttonWriteLinesToExcel
//
buttonWriteLinesToExcel.Location = new Point(1022, 255);
buttonWriteLinesToExcel.Name = "buttonWriteLinesToExcel";
buttonWriteLinesToExcel.Size = new Size(316, 29);
buttonWriteLinesToExcel.TabIndex = 28;
buttonWriteLinesToExcel.Text = "Записать в Excel";
buttonWriteLinesToExcel.UseVisualStyleBackColor = true;
buttonWriteLinesToExcel.Click += buttonWriteLinesToExcel_Click;
//
// button1
//
button1.Location = new Point(1115, 320);
button1.Name = "button1";
button1.Size = new Size(94, 29);
button1.TabIndex = 29;
button1.Text = "button1";
button1.UseVisualStyleBackColor = true;
button1.Click += buttonConfigTable_Click;
//
// button2
//
button2.Location = new Point(1134, 428);
button2.Name = "button2";
button2.Size = new Size(94, 29);
button2.TabIndex = 30;
button2.Text = "button2";
button2.UseVisualStyleBackColor = true;
button2.Click += buttonDiagramCreate_Click;
//
// Form1
//
AutoScaleDimensions = new SizeF(8F, 20F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(1350, 549);
Controls.Add(button2);
Controls.Add(button1);
Controls.Add(buttonWriteLinesToExcel);
Controls.Add(richTextBox);
Controls.Add(buttonSetIndex);
Controls.Add(buttonGetObject);
Controls.Add(buttonSetItem);
Controls.Add(buttonGetIndex);
Controls.Add(buttonSetPattern);
Controls.Add(label3);
Controls.Add(label2);
Controls.Add(label1);
Controls.Add(textBoxSurName);
Controls.Add(textBoxAge);
Controls.Add(textBoxName);
Controls.Add(textBoxStartSimbol);
Controls.Add(textBoxEndSimbol);
Controls.Add(textBoxInput);
Controls.Add(customListBox1);
Controls.Add(buttonSetTemplate);
Controls.Add(buttonSetExample);
Controls.Add(buttonGetDate);
Controls.Add(buttonSetDate);
Controls.Add(dateInputBox1);
Controls.Add(checkBox);
Controls.Add(buttonClear);
Controls.Add(buttonSet);
Controls.Add(buttonGet);
Controls.Add(buttonAdd);
Controls.Add(textBox1);
Controls.Add(dropDownList1);
Name = "Form1";
Text = "Form1";
ResumeLayout(false);
PerformLayout();
}
#endregion
private Library_var_4_lab_1.DropDownList dropDownList1;
private TextBox textBox1;
private Button buttonAdd;
private Button buttonGet;
private Button buttonSet;
private Button buttonClear;
private CheckBox checkBox;
private Library_var_4_lab_1.DateInputBox dateInputBox1;
private Button buttonSetDate;
private Button buttonGetDate;
private Button buttonSetExample;
private Button buttonSetTemplate;
private Library_var_4_lab_1.CustomListBox customListBox1;
private TextBox textBoxInput;
private TextBox textBoxEndSimbol;
private TextBox textBoxStartSimbol;
private TextBox textBoxName;
private TextBox textBoxAge;
private TextBox textBoxSurName;
private Label label1;
private Label label2;
private Label label3;
private Button buttonSetPattern;
private Button buttonGetIndex;
private Button buttonSetItem;
private Button buttonGetObject;
private Button buttonSetIndex;
private RichTextBox richTextBox;
private Library_var_4_lab_1.BigTextExcel bigTextExcel;
private Button buttonWriteLinesToExcel;
private Library_var_4_lab_1.ConfigurableTable configurableTable1;
private Button button1;
private Button button2;
}
}

157
KOP_Labs/TestProj/Form1.cs Normal file
View File

@ -0,0 +1,157 @@
using Library_var_4_lab_1;
using OfficePackage.HelperModels;
namespace TestProj
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
dropDownList1.ChangeIndex += IsChanged;
dateInputBox1.ChangeValue += IsChanged;
}
//ïåðâàÿ òàñêà
private void buttonAdd_OnClick(object sender, EventArgs e)
{
try
{
dropDownList1.Input(textBox1.Text);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
private void buttonClear_OnClick(object sender, EventArgs e)
{
dropDownList1.ClearList();
}
private void buttonSet_OnClick(object sender, EventArgs e)
{
dropDownList1.SelectedItem = textBox1.Text;
}
private void buttonGet_OnClick(object sender, EventArgs e)
{
textBox1.Text = dropDownList1.SelectedItem;
}
private void IsChanged(object? sender, EventArgs e)
{
checkBox.Checked = true;
}
// âòîðàÿ òàñêà
private void buttonSetTemplate_OnClick(object sender, EventArgs e)
{
dateInputBox1.Template = textBox1.Text;
}
private void buttonSetExample_OnClick(object sender, EventArgs e)
{
dateInputBox1.setExample(textBox1.Text);
}
private void buttonSetDate_OnClick(object sender, EventArgs e)
{
dateInputBox1.Date = textBox1.Text;
}
private void buttonGetDate_OnClick(object sender, EventArgs e)
{
textBox1.Text = dateInputBox1.Date;
}
// òðåòüÿ òàñêà
private void buttonSetPattern_OnClick(object sender, EventArgs e)
{
customListBox1.SetTemplate(textBoxStartSimbol.Text, textBoxEndSimbol.Text, textBoxInput.Text);
}
private void buttonSetObject_OnClick(object sender, EventArgs e)
{
Human human = new Human();
human.Name = textBoxName.Text;
human.SurName = textBoxSurName.Text;
human.Age = Convert.ToInt32(textBoxAge.Text);
customListBox1.Add<Human>(human);
}
private void buttonGetObject_OnClick(object sender, EventArgs e)
{
Human human = customListBox1.GetSelected<Human>();
textBoxName.Text = human.Name;
textBoxSurName.Text = human.SurName;
textBoxAge.Text = human.Age.ToString();
}
private void buttonSetIndex_Click(object sender, EventArgs e)
{
customListBox1.SelectedIndex = Convert.ToInt32(textBoxInput.Text);
}
private void buttonGetIndex_Click(object sender, EventArgs e)
{
textBoxInput.Text = customListBox1.SelectedIndex.ToString();
}
// ëàáà 2
// òàñêà 1
private void buttonWriteLinesToExcel_Click(object sender, EventArgs e)
{
bigTextExcel.WriteToExcel("C:\\Users\\123\\Desktop\\Lab2_KOP.xlsx", "Çàãîëîâîê", richTextBox.Lines);
}
//òàñêà 2
private void buttonConfigTable_Click(object sender, EventArgs e)
{
List<TreeNode> headers = new List<TreeNode>();
headers.Add(new TreeNode()
{
Text = "Ãðóïïà",
Name = "20",
Tag = "Group",
});
TreeNode node1 = new();
node1.Text = "Èìÿ";
node1.Name = "20";
node1.Tag = "Name";
TreeNode node2 = new();
node2.Text = "Ôàìèëèÿ";
node2.Name = "40";
node2.Tag = "SurName";
TreeNode node3 = new();
node3.Text = "ÔÈÎ";
node3.Nodes.Add(node1);
node3.Nodes.Add(node2);
headers.Add(node3);
List<Human> people = new List<Human>();
people.Add(new Human() { Group = "ÏÈáä-33", Name = "Àðò¸ì", SurName = "ßøèí" });
people.Add(new Human() { Group = "ÏÈáä-33", Name = "Ðîñòèñëàâ", SurName = "Çàõàðîâ" });
people.Add(new Human() { Group = "ÏÈáä-33", Name = "Íèÿç", SurName = "Þíóñîâ" });
configurableTable1.CreateTable<Human>("C:\\Users\\123\\Desktop\\Lab2_KOP1.xlsx", "Çàãîëîâîê", headers, people);
}
public void buttonDiagramCreate_Click(object sender, EventArgs e)
{
LineDiagram lineDiagramCreation = new();
List<(string seriesName, List<(string Name, double Value)> values)> data = new();
List<(string Name, double Value)> values = new();
values.Add(("1", 30));
values.Add(("2", 40));
values.Add(("3", 60));
data.Add(("Ãðàôèê1", values));
values = new();
values.Add(("1", 60));
values.Add(("2", 40));
values.Add(("3", 30));
data.Add(("Ãðàôèê2", values));
lineDiagramCreation.CreateDiagram("C:\\Users\\123\\Desktop\\Lab2_KOP1.xlsx", "Çàãîëîâîê", "Diagram", DiagramLegendLocation.Right, data);
}
}
}

View File

@ -0,0 +1,126 @@
<?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>
<metadata name="bigTextExcel.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>17, 17</value>
</metadata>
<metadata name="configurableTable1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>156, 17</value>
</metadata>
</root>

View File

@ -0,0 +1,16 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace TestProj
{
public class Human
{
public string Name { get; set; } = string.Empty;
public string SurName { get; set; } = string.Empty;
public int Age { get; set; }
public string Group { get; set; } = string.Empty;
}
}

View File

@ -0,0 +1,17 @@
namespace TestProj
{
internal static class Program
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
// To customize application configuration such as set high DPI settings or default font,
// see https://aka.ms/applicationconfiguration.
ApplicationConfiguration.Initialize();
Application.Run(new Form1());
}
}
}

View File

@ -0,0 +1,15 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>WinExe</OutputType>
<TargetFramework>net6.0-windows</TargetFramework>
<Nullable>enable</Nullable>
<UseWindowsForms>true</UseWindowsForms>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\Library_var_4_lab_1\Library_var_4_lab_1.csproj" />
</ItemGroup>
</Project>