Compare commits

...

5 Commits
main ... Laba_2

Author SHA1 Message Date
5cf96bc97c 1&2 2024-09-19 15:21:49 +04:00
7a3c6571b0 dd 2024-09-05 15:38:40 +04:00
4794158d40 Done 2024-09-05 15:25:41 +04:00
079f196dcf Вроде 2024-09-05 15:05:04 +04:00
5a901fc072 In progres 2024-09-05 09:32:21 +04:00
32 changed files with 2152 additions and 0 deletions

View File

@ -0,0 +1,199 @@
namespace TestsComponents
{
partial class FormTestComponents
{
/// <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()
{
userCheckedListBox = new WinFormsLibrary1.UserCheckedListBox();
buttonClear = new Button();
ButtonShowItems = new Button();
textBoxItems = new TextBox();
userDateTimePicker = new COP.UserDateTimePicker();
textBoxShowDate = new TextBox();
ButtonShowDate = new Button();
ButtonRangeSet = new Button();
userTreeView = new COP.UserTreeView();
buttonSaveToExcel = new Button();
buttonSaveTable = new Button();
button1 = new Button();
SuspendLayout();
//
// userCheckedListBox
//
userCheckedListBox.Location = new Point(0, 0);
userCheckedListBox.Name = "userCheckedListBox";
userCheckedListBox.SelectedValue = "";
userCheckedListBox.Size = new Size(263, 171);
userCheckedListBox.TabIndex = 0;
userCheckedListBox.SelectedValueChanged += UserCheckedListBox_SelectedValueChanged;
//
// buttonClear
//
buttonClear.Location = new Point(0, 176);
buttonClear.Name = "buttonClear";
buttonClear.Size = new Size(263, 29);
buttonClear.TabIndex = 2;
buttonClear.Text = "Очистить";
buttonClear.UseVisualStyleBackColor = true;
buttonClear.Click += buttonClear_Click;
//
// ButtonShowItems
//
ButtonShowItems.Location = new Point(0, 211);
ButtonShowItems.Name = "ButtonShowItems";
ButtonShowItems.Size = new Size(263, 29);
ButtonShowItems.TabIndex = 3;
ButtonShowItems.Text = "Показать";
ButtonShowItems.UseVisualStyleBackColor = true;
ButtonShowItems.Click += ButtonShowItems_Click;
//
// textBoxItems
//
textBoxItems.Location = new Point(0, 245);
textBoxItems.Multiline = true;
textBoxItems.Name = "textBoxItems";
textBoxItems.Size = new Size(263, 87);
textBoxItems.TabIndex = 4;
//
// userDateTimePicker
//
userDateTimePicker.Location = new Point(295, 15);
userDateTimePicker.MaxValue = null;
userDateTimePicker.MinValue = null;
userDateTimePicker.Name = "userDateTimePicker";
userDateTimePicker.Size = new Size(254, 29);
userDateTimePicker.TabIndex = 5;
userDateTimePicker.ValueChanged += UserDateTimePicker_ValueChanged;
//
// textBoxShowDate
//
textBoxShowDate.Location = new Point(295, 77);
textBoxShowDate.Margin = new Padding(3, 4, 3, 4);
textBoxShowDate.Name = "textBoxShowDate";
textBoxShowDate.Size = new Size(253, 27);
textBoxShowDate.TabIndex = 6;
//
// ButtonShowDate
//
ButtonShowDate.Location = new Point(331, 140);
ButtonShowDate.Margin = new Padding(3, 4, 3, 4);
ButtonShowDate.Name = "ButtonShowDate";
ButtonShowDate.Size = new Size(192, 31);
ButtonShowDate.TabIndex = 7;
ButtonShowDate.Text = "Показать";
ButtonShowDate.UseVisualStyleBackColor = true;
ButtonShowDate.Click += ButtonShowDate_Click;
//
// ButtonRangeSet
//
ButtonRangeSet.Location = new Point(555, 63);
ButtonRangeSet.Margin = new Padding(3, 4, 3, 4);
ButtonRangeSet.Name = "ButtonRangeSet";
ButtonRangeSet.Size = new Size(150, 57);
ButtonRangeSet.TabIndex = 8;
ButtonRangeSet.Text = "Установить диапозон";
ButtonRangeSet.UseVisualStyleBackColor = true;
ButtonRangeSet.Click += ButtonRangeSet_Click;
//
// userTreeView
//
userTreeView.Location = new Point(570, 140);
userTreeView.Margin = new Padding(3, 5, 3, 5);
userTreeView.Name = "userTreeView";
userTreeView.Size = new Size(171, 127);
userTreeView.TabIndex = 9;
userTreeView.Load += UserTreeView_Load;
//
// buttonSaveToExcel
//
buttonSaveToExcel.Location = new Point(314, 303);
buttonSaveToExcel.Name = "buttonSaveToExcel";
buttonSaveToExcel.Size = new Size(96, 53);
buttonSaveToExcel.TabIndex = 10;
buttonSaveToExcel.Text = "Сохранить картинки";
buttonSaveToExcel.UseVisualStyleBackColor = true;
buttonSaveToExcel.Click += buttonSaveToExcel_Click;
//
// buttonSaveTable
//
buttonSaveTable.Location = new Point(454, 303);
buttonSaveTable.Name = "buttonSaveTable";
buttonSaveTable.Size = new Size(116, 53);
buttonSaveTable.TabIndex = 11;
buttonSaveTable.Text = "Сохранить таблицу";
buttonSaveTable.UseVisualStyleBackColor = true;
buttonSaveTable.Click += buttonSaveTable_Click;
//
// button1
//
button1.Location = new Point(340, 378);
button1.Name = "button1";
button1.Size = new Size(197, 29);
button1.TabIndex = 12;
button1.Text = "Сохранить диаграмму";
button1.UseVisualStyleBackColor = true;
button1.Click += buttonSaveChart_Click;
//
// FormTestComponents
//
AutoScaleDimensions = new SizeF(8F, 20F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(800, 451);
Controls.Add(button1);
Controls.Add(buttonSaveTable);
Controls.Add(buttonSaveToExcel);
Controls.Add(userTreeView);
Controls.Add(ButtonRangeSet);
Controls.Add(ButtonShowDate);
Controls.Add(textBoxShowDate);
Controls.Add(userDateTimePicker);
Controls.Add(textBoxItems);
Controls.Add(ButtonShowItems);
Controls.Add(buttonClear);
Controls.Add(userCheckedListBox);
Name = "FormTestComponents";
Text = "FormTestComponents ";
ResumeLayout(false);
PerformLayout();
}
#endregion
private WinFormsLibrary1.UserCheckedListBox userCheckedListBox;
private Button buttonClear;
private Button ButtonShowItems;
private TextBox textBoxItems;
private COP.UserDateTimePicker userDateTimePicker;
private TextBox textBoxShowDate;
private Button ButtonShowDate;
private Button ButtonRangeSet;
private COP.UserTreeView userTreeView;
private Button buttonSaveToExcel;
private Button buttonSaveTable;
private Button button1;
}
}

View File

@ -0,0 +1,174 @@
using COP;
using COP.Enums;
using COP.Info;
using static COP.ExcelComponent;
namespace TestsComponents
{
public partial class FormTestComponents : Form
{
public FormTestComponents()
{
InitializeComponent();
Fill();
}
public void Fill()
{
userCheckedListBox.append(new() { "items1", "dsdsf", "items3", "fgdg", "iit" });
}
private void UserCheckedListBox_SelectedValueChanged(object sender, EventArgs e)
{
MessageBox.Show("Selected value changed");
}
private void buttonClear_Click(object sender, EventArgs e)
{
userCheckedListBox.ClearList();
}
private void ButtonShowItems_Click(object sender, EventArgs e)
{
textBoxItems.Text = userCheckedListBox.SelectedValue;
}
private void ButtonShowDate_Click(object sender, EventArgs e)
{
try
{
textBoxShowDate.Clear();
textBoxShowDate.Text = userDateTimePicker.SelectedValue.ToString();
}
catch (Exception ex)
{
MessageBox.Show("Îøèáêà");
}
}
private void UserDateTimePicker_ValueChanged(object sender, EventArgs e)
{
MessageBox.Show("Value changed");
DateTime? selectedDate = userDateTimePicker.SelectedValue;
}
private void ButtonRangeSet_Click(object sender, EventArgs e)
{
userDateTimePicker.MaxValue = new DateTime(2024, 9, 20);
userDateTimePicker.MinValue = new DateTime(2024,8,10);
}
private void UserTreeView_Load(object sender, EventArgs e)
{
List<Employee> employees = new List<Employee>
{
new Employee { Department = "Îòäåë1", Position = "Äîëæíîñòü1", Name = "Ñîòðóäíèê1" },
new Employee { Department = "Îòäåë2", Position = "Äîëæíîñòü2", Name = "Ñîòðóäíèê2" },
new Employee { Department = "Îòäåë1", Position = "Äîëæíîñòü1", Name = "Ñîòðóäíèê3" },
new Employee { Department = "Îòäåë2", Position = "Äîëæíîñòü3", Name = "Ñîòðóäíèê4" },
};
var Hierarchy = new List<string> { "Department", "Position", "Name" };
foreach (var prop in employees[0].GetType().GetProperties())
{
userTreeView.Hierarchy.Add(prop.Name);
}
try
{
userTreeView.PopulateTree(employees);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
public class Employee
{
public string? Department { get; set; }
public string? Position { get; set; }
public string? Name { get; set; }
}
private void buttonSaveToExcel_Click(object sender, EventArgs e)
{
ExcelComponent excel = new();
List<ImageInfo> images = new()
{
new ImageInfo() { FilePath = "C:\\Users\\ogoro\\Documents\\image1.jpg" },
new ImageInfo() { FilePath = "C:\\Users\\ogoro\\Documents\\image2.jpg" },
new ImageInfo() { FilePath = "C:\\Users\\ogoro\\Documents\\image3.jpg" }
};
ExcelImageInfo info = new("C:\\Users\\ogoro\\Documents\\test.xlsx", "My Document", images);
try
{
excel.GenerateExcelWithImages(info);
MessageBox.Show("Ñîõàðíåíî óñïåøíî", "Ðåçóëüòàò", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Îøèáêà",
MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void buttonSaveTable_Click(object sender, EventArgs e)
{
ExcelTable table = new();
var data = new List<Employee2>
{
new Employee2 { Id = 1, Status = "Active", Name = "Îëåã", Surname = "Ñàëèí", Age = "20", Department = "IT", Position = "Senior" },
new Employee2 { Id = 2, Status = "Active", Name = "Àðòóð", Surname = "Íàñûðîâ", Age = "19", Department = "Design", Position = "Ñòàæ¸ð" },
};
Dictionary<string, (List<(string, string)>, List<int>)> headers = new()
{
{ "Èäåíòèôèêàòîð", (new List<(string, string)> { ("Id", "Èäåíòèôèêàòîð") }, new List<int> { 30 }) },
{ "Ëè÷íûå äàííûå", (new List<(string, string)> { ("Name", "Èìÿ"), ("Surname", "Ôàìèëèÿ"), ("Age", "Âîçðàñò") }, new List<int> { 25, 25, 25 }) },
{ "Ñòàòóñ", (new List<(string, string)> { ("Status", "Ñòàòóñ") }, new List<int> { 30 }) },
{ "Ðàáîòà", (new List<(string, string)> { ("Department", "Îòäåë"), ("Position", "Äîëæíîñòü") }, new List<int> { 25, 25 }) }
};
ExcelTableInfo<Employee2> info = new("C:\\Users\\ogoro\\Documents\\testtable.xlsx", "My Document", data, headers);
try
{
table.GenerateDocument(info);
MessageBox.Show("Ñîõàðíåíî óñïåøíî", "Ðåçóëüòàò", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Îøèáêà",
MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
public class Employee2
{
public int? Id { get; set; }
public string? Status { get; set; } = string.Empty;
public string? Name { get; set; } = string.Empty;
public string? Surname { get; set; } = string.Empty;
public string? Age { get; set; } = string.Empty;
public string? Department { get; set; } = string.Empty;
public string? Position { get; set; } = string.Empty;
}
private void buttonSaveChart_Click(object sender, EventArgs e)
{
PieChart chart = new();
LegendPosition legend = new();
var data = new List<DataItem>()
{
new DataItem() { Name = "Data 1", Value = 10 },
new DataItem() { Name = "Data 2", Value = 20 },
new DataItem() { Name = "Data 3", Value = 30 },
new DataItem() { Name = "Data 4", Value = 40 }
};
ExcelChartInfo info = new("C:\\Users\\ogoro\\Documents\\testchart.xlsx", "My Document", "My Chart", legend, data);
try
{
chart.GenerateDocument(info);
MessageBox.Show("Ñîõàðíåíî óñïåøíî", "Ðåçóëüòàò", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Îøèáêà",
MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
}

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,17 @@
namespace TestsComponents
{
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 FormTestComponents());
}
}
}

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="..\WinFormsLibrary1\COP.csproj" />
</ItemGroup>
</Project>

31
WinFormsLibrary1.sln Normal file
View File

@ -0,0 +1,31 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.10.35027.167
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "COP", "WinFormsLibrary1\COP.csproj", "{2A43B10F-50CB-4768-A95A-2E6B90D0AD41}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TestsComponents", "TestsComponents\TestsComponents.csproj", "{C720866B-F5B4-4063-931A-2DB4A35DD888}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{2A43B10F-50CB-4768-A95A-2E6B90D0AD41}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{2A43B10F-50CB-4768-A95A-2E6B90D0AD41}.Debug|Any CPU.Build.0 = Debug|Any CPU
{2A43B10F-50CB-4768-A95A-2E6B90D0AD41}.Release|Any CPU.ActiveCfg = Release|Any CPU
{2A43B10F-50CB-4768-A95A-2E6B90D0AD41}.Release|Any CPU.Build.0 = Release|Any CPU
{C720866B-F5B4-4063-931A-2DB4A35DD888}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{C720866B-F5B4-4063-931A-2DB4A35DD888}.Debug|Any CPU.Build.0 = Debug|Any CPU
{C720866B-F5B4-4063-931A-2DB4A35DD888}.Release|Any CPU.ActiveCfg = Release|Any CPU
{C720866B-F5B4-4063-931A-2DB4A35DD888}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {5428C310-3E76-48CB-A3D2-14609E3EA213}
EndGlobalSection
EndGlobal

View File

@ -0,0 +1,16 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0-windows</TargetFramework>
<Nullable>enable</Nullable>
<UseWindowsForms>true</UseWindowsForms>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="DocumentFormat.OpenXml" Version="3.1.0" />
<PackageReference Include="EPPlus" Version="7.3.2" />
<PackageReference Include="NPOI" Version="2.7.1" />
</ItemGroup>
</Project>

View File

@ -0,0 +1,10 @@
namespace COP.Enums
{
public enum LegendPosition
{
Top,
Bottom,
Left,
Right
}
}

View File

@ -0,0 +1,36 @@
namespace COP
{
partial class ExcelComponent
{
/// <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,73 @@
using COP.Info;
using NPOI.SS.UserModel;
using NPOI.XSSF.UserModel;
using System.ComponentModel;
namespace COP
{
public partial class ExcelComponent : Component
{
public ExcelComponent()
{
InitializeComponent();
}
public ExcelComponent(IContainer container)
{
container.Add(this);
InitializeComponent();
}
public void GenerateExcelWithImages(ExcelImageInfo info)
{
if (string.IsNullOrEmpty(info.fileName))
{
throw new ArgumentNullException(nameof(info.fileName), "File name cannot be null or empty.");
}
if (info.images == null || info.images.Count == 0)
{
throw new ArgumentException("At least one image must be provided.", nameof(info.images));
}
if (string.IsNullOrEmpty(info.documentTitle))
{
throw new ArgumentNullException(nameof(info.documentTitle), "Document title cannot be null or empty.");
}
var workbook = new XSSFWorkbook();
var sheet = workbook.CreateSheet("Sheet1");
sheet.CreateRow(0).CreateCell(0).SetCellValue(info.documentTitle);
int startRowIndex = 2;
var rowOffset = 1;
foreach (var imageInfo in info.images)
{
using var fs = new FileStream(imageInfo.FilePath, FileMode.Open, FileAccess.Read);
var imageBytes = new byte[fs.Length];
fs.Read(imageBytes, 0, imageBytes.Length);
var pictureIdx = workbook.AddPicture(imageBytes, PictureType.JPEG);
var drawing = sheet.CreateDrawingPatriarch();
var anchor = new XSSFClientAnchor(0, 0, 0, 0, 0, startRowIndex, 1, startRowIndex + 1);
var picture = drawing.CreatePicture(anchor, pictureIdx);
picture.Resize();
var pictureHeight = picture.GetImageDimension().Height / 20;
startRowIndex += pictureHeight + rowOffset;
}
using (var fs = new FileStream(info.fileName, FileMode.Create, FileAccess.Write))
{
workbook.Write(fs);
}
}
public class ImageInfo
{
public string? FilePath { get; set; }
}
}
}

36
WinFormsLibrary1/ExcelTable.Designer.cs generated Normal file
View File

@ -0,0 +1,36 @@
namespace COP
{
partial class ExcelTable
{
/// <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,178 @@
using COP.Info;
using DocumentFormat.OpenXml.EMMA;
using DocumentFormat.OpenXml.Office2010.Excel;
using DocumentFormat.OpenXml.Spreadsheet;
using NPOI.HSSF.Util;
using NPOI.SS.UserModel;
using NPOI.SS.Util;
using NPOI.XSSF.UserModel;
using System;
using System.ComponentModel;
using System.Windows.Forms.VisualStyles;
using BorderStyle = NPOI.SS.UserModel.BorderStyle;
using HorizontalAlignment = NPOI.SS.UserModel.HorizontalAlignment;
namespace COP
{
public partial class ExcelTable : Component
{
public ExcelTable()
{
InitializeComponent();
}
public ExcelTable(IContainer container)
{
container.Add(this);
InitializeComponent();
}
public void GenerateDocument<T>(ExcelTableInfo<T> info) where T : class
{
if (string.IsNullOrEmpty(info.FilePath))
{
throw new ArgumentException("File path is null or empty.");
}
if (string.IsNullOrEmpty(info.DocumentTitle))
{
throw new ArgumentException("Document title is null or empty.");
}
if (info.Data == null || info.Data.Count == 0)
{
throw new ArgumentException("Data is null or empty.");
}
var workbook = new XSSFWorkbook();
var sheet = workbook.CreateSheet("Sheet1");
sheet.CreateRow(0).CreateCell(0).SetCellValue(info.DocumentTitle);
int curRow = 1;
int curCol = 0;
List<string> headers = new();
var dataCellStyle = GetDataCellStyle(workbook);
var headerCellStyle = GetHeaderCellStyle(workbook);
// Проход по заголовкам
foreach (var header in info.Headers)
{
headers.Add(header.Key);
var currentRow = sheet.CreateRow(curRow);
var curCell = currentRow.CreateCell(curCol);
// Если несколько подзаголовков в одной категории
if (header.Value.Item1.Count > 1)
{
sheet.AddMergedRegion(new CellRangeAddress(curRow, curRow + header.Value.Item1.Count - 1, curCol, curCol));
curCol++;
foreach (var (key, displayName) in header.Value.Item1)
{
int id = header.Value.Item1.IndexOf((key, displayName));
var cellValue = currentRow.CreateCell(1);
cellValue.SetCellValue(displayName);
currentRow.Height = (short)(header.Value.Item2[id] * 20);
headers.Add(displayName);
cellValue.CellStyle = headerCellStyle;
currentRow = sheet.CreateRow(currentRow.RowNum + 1);
}
}
else
{
int id = header.Value.Item1.IndexOf(header.Value.Item1[0]);
sheet.AddMergedRegion(new CellRangeAddress(curRow, curRow, curCol, curCol + 1));
currentRow.Height = (short)(header.Value.Item2[id] * 20);
curRow++;
}
curCell.SetCellValue(header.Key);
curCell.CellStyle = headerCellStyle;
if (header.Value.Item1.Count > 1)
{
curCol--;
curRow += header.Value.Item1.Count;
}
}
curCol = 2;
foreach (var data in info.Data)
{
curRow = 1;
foreach (var header in info.Headers.Values)
{
foreach (var (key, _) in header.Item1)
{
var property = typeof(T).GetProperty(key);
var cellValue = sheet.GetRow(curRow)?.CreateCell(curCol);
if (cellValue != null && property != null)
{
var value = property?.GetValue(data)?.ToString();
var rowHeight = GetRowHeight(key, info);
var currentRow = sheet.GetRow(curRow);
if (rowHeight != null)
{
currentRow.Height = (short)(rowHeight.Value * 20);
}
cellValue.SetCellValue(value);
cellValue.CellStyle = dataCellStyle;
}
curRow++;
}
}
curCol++;
}
using var fs = new FileStream(info.FilePath, FileMode.Create, FileAccess.Write);
workbook.Write(fs);
}
private static int? GetRowHeight<T>(string header, ExcelTableInfo<T> info) where T : class
{
foreach (var item in info.Headers)
{
foreach (var (key, displayName) in item.Value.Item1)
{
int id = item.Value.Item1.IndexOf((key, displayName));
if (key == header)
return item.Value.Item2[id];
}
}
return 0;
}
private static ICellStyle GetHeaderCellStyle(IWorkbook workbook)
{
var style = workbook.CreateCellStyle();
style.BorderBottom = BorderStyle.Thin;
style.BorderLeft = BorderStyle.Thin;
style.BorderRight = BorderStyle.Thin;
style.BorderTop = BorderStyle.Thin;
var font = workbook.CreateFont();
font.Boldweight = (short)FontBoldWeight.Bold;
style.SetFont(font);
style.Alignment = HorizontalAlignment.Center;
style.VerticalAlignment = NPOI.SS.UserModel.VerticalAlignment.Center;
return style;
}
private static ICellStyle GetDataCellStyle(IWorkbook workbook)
{
var style = workbook.CreateCellStyle();
style.BorderBottom = BorderStyle.Thin;
style.BorderLeft = BorderStyle.Thin;
style.BorderRight = BorderStyle.Thin;
style.BorderTop = BorderStyle.Thin;
return style;
}
}
public class Property
{
public string? Name { get; set; }
}
}

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 COP.Exceptions
{
[Serializable]
public class NoRangeException : Exception
{
public NoRangeException() : base() { }
public NoRangeException(string message) : base(message) { }
public NoRangeException(string message, Exception exception) : base(message, exception) { }
protected NoRangeException(SerializationInfo info, StreamingContext contex) : base(info, contex) { }
}
}

View File

@ -0,0 +1,19 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.Text;
using System.Threading.Tasks;
namespace COP.Exceptions
{
[Serializable]
public class NotIncludedInRangeException: Exception
{
public NotIncludedInRangeException() : base() { }
public NotIncludedInRangeException(string message) : base(message) { }
public NotIncludedInRangeException(string message, Exception exception) : base(message, exception) { }
protected NotIncludedInRangeException(SerializationInfo info, StreamingContext contex) : base(info, contex) { }
}
}

View File

@ -0,0 +1,8 @@
namespace COP.Info
{
public class DataItem
{
public string Name { get; set; } = string.Empty;
public double Value { get; set; }
}
}

View File

@ -0,0 +1,22 @@
using COP.Enums;
namespace COP.Info
{
public class ExcelChartInfo
{
public string? filePath { get; set; } = string.Empty;
public string? documentTitle { get; set; } = string.Empty;
public string? chartTitle { get; set; } = string.Empty;
public LegendPosition legendPosition { get; set; }
public List<DataItem>? data { get; set; }
public ExcelChartInfo(string? filePath, string? documentTitle, string? chartTitle, LegendPosition legendPosition, List<DataItem>? data)
{
this.filePath = filePath;
this.documentTitle = documentTitle;
this.chartTitle = chartTitle;
this.legendPosition = legendPosition;
this.data = data;
}
}
}

View File

@ -0,0 +1,18 @@
using static COP.ExcelComponent;
namespace COP.Info
{
public class ExcelImageInfo
{
public string? fileName { get; set; } = string.Empty;
public string? documentTitle { get; set; } = string.Empty;
public List<ImageInfo>? images { get; set; }
public ExcelImageInfo (string? fileName, string? documentTitle, List<ImageInfo>? images)
{
this.fileName = fileName;
this.documentTitle = documentTitle;
this.images = images;
}
}
}

View File

@ -0,0 +1,18 @@
namespace COP.Info
{
public class ExcelTableInfo<T> where T: class
{
public string FilePath { get; set; } = string.Empty;
public string DocumentTitle { get; set; } = string.Empty;
public List<T>? Data;
public Dictionary<string, (List<(string, string)>, List<int>)> Headers { get; set; }
public ExcelTableInfo (string filePath, string documentTitle, List<T> data, Dictionary<string, (List<(string, string)>, List<int>)> headers)
{
FilePath = filePath;
DocumentTitle = documentTitle;
Data = data;
Headers = headers;
}
}
}

36
WinFormsLibrary1/PieChart.Designer.cs generated Normal file
View File

@ -0,0 +1,36 @@
namespace COP
{
partial class PieChart
{
/// <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,71 @@
using COP.Info;
using OfficeOpenXml;
using System.ComponentModel;
using LicenseContext = OfficeOpenXml.LicenseContext;
using OfficeOpenXml.Drawing.Chart;
namespace COP
{
public partial class PieChart : Component
{
public PieChart()
{
InitializeComponent();
}
public PieChart(IContainer container)
{
container.Add(this);
InitializeComponent();
}
public void GenerateDocument(ExcelChartInfo info)
{
if (string.IsNullOrEmpty(info.filePath))
{
throw new ArgumentException("File path is null or empty.");
}
if (string.IsNullOrEmpty(info.chartTitle))
{
throw new ArgumentException("Chart title is null or empty.");
}
if (string.IsNullOrEmpty(info.documentTitle))
{
throw new ArgumentException("Document title is null or empty.");
}
if (info.data == null || info.data.Count == 0)
{
throw new ArgumentException("Data is null or empty.");
}
ExcelPackage.LicenseContext = LicenseContext.NonCommercial;
using ExcelPackage excelPackage = new();
ExcelWorksheet worksheet = excelPackage.Workbook.Worksheets.Add("Sheet 1");
worksheet.Cells["A1"].Value = info.documentTitle;
int row = 2;
int startCol = 1;
int endCol = 1;
foreach (var data in info.data)
{
worksheet.Cells[row, endCol].Value = data.Name;
worksheet.Cells[row + 1, endCol].Value = data.Value;
endCol++;
}
ExcelPieChart? pieChart = worksheet.Drawings.AddChart(info.chartTitle, eChartType.Pie) as ExcelPieChart;
pieChart.Title.Text = info.chartTitle;
pieChart.Series.Add(ExcelCellBase.GetAddress(row + 1, startCol, row + 1, endCol - 1),
ExcelCellBase.GetAddress(row, startCol, row, endCol - 1));
pieChart.Legend.Position = (eLegendPosition)(int)info.legendPosition;
pieChart.DataLabel.ShowPercent = true;
pieChart.SetPosition(1, 0, 0, 0);
FileInfo fi = new(info.filePath);
excelPackage.SaveAs(fi);
}
}
}

View File

@ -0,0 +1,57 @@
namespace WinFormsLibrary1
{
partial class UserCheckedListBox
{
/// <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()
{
checkedListBox = new CheckedListBox();
SuspendLayout();
//
// checkedListBox
//
checkedListBox.FormattingEnabled = true;
checkedListBox.Location = new Point(0, 0);
checkedListBox.Name = "checkedListBox";
checkedListBox.Size = new Size(256, 158);
checkedListBox.TabIndex = 0;
checkedListBox.SelectedIndexChanged += CheckedListBox_SelectedIndexChanged;
//
// UserCheckedListBox
//
AutoScaleDimensions = new SizeF(8F, 20F);
AutoScaleMode = AutoScaleMode.Font;
Controls.Add(checkedListBox);
Name = "UserCheckedListBox";
Size = new Size(257, 155);
ResumeLayout(false);
}
#endregion
private CheckedListBox checkedListBox;
}
}

View File

@ -0,0 +1,75 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace WinFormsLibrary1
{
public partial class UserCheckedListBox : UserControl
{
private event EventHandler? _selectedValueChanged;
public UserCheckedListBox()
{
InitializeComponent();
}
public void append(List<String> items)
{
if (items.Count == 0 || items is null)
{
return;
}
checkedListBox.Items.AddRange(items.ToArray());
}
public void ClearList()
{
checkedListBox.Items.Clear();
}
public string SelectedValue
{
get
{
if (checkedListBox.SelectedItem != null)
{
return checkedListBox.SelectedItem.ToString();
}
else
{
return "";
}
}
set
{
for (int i = 0; i < checkedListBox.Items.Count; i++)
{
if (checkedListBox.Items[i].ToString() == value)
{
checkedListBox.SetItemChecked(i, true);
break;
}
}
}
}
public event EventHandler SelectedValueChanged
{
add { _selectedValueChanged += value; }
remove { _selectedValueChanged += value; }
}
private void CheckedListBox_SelectedIndexChanged(object sender, EventArgs e)
{
_selectedValueChanged?.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,56 @@
namespace COP
{
partial class UserDateTimePicker
{
/// <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()
{
dateTimePicker = new DateTimePicker();
SuspendLayout();
//
// dateTimePicker
//
dateTimePicker.Location = new Point(0, 0);
dateTimePicker.Name = "dateTimePicker";
dateTimePicker.Size = new Size(250, 27);
dateTimePicker.TabIndex = 0;
dateTimePicker.ValueChanged += DateTimePicker_ValueChanged;
//
// UserDateTimePickercs
//
AutoScaleDimensions = new SizeF(8F, 20F);
AutoScaleMode = AutoScaleMode.Font;
Controls.Add(dateTimePicker);
Name = "UserDateTimePickercs";
Size = new Size(254, 29);
ResumeLayout(false);
}
#endregion
private DateTimePicker dateTimePicker;
}
}

View File

@ -0,0 +1,79 @@
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;
using COP.Exceptions;
namespace COP
{
public partial class UserDateTimePicker : UserControl
{
private DateTime? minValue;
private DateTime? maxValue;
public event EventHandler? _valueChanged;
public UserDateTimePicker()
{
InitializeComponent();
}
public DateTime? MinValue
{
get { return minValue; }
set { minValue = value; }
}
public DateTime? MaxValue
{
get { return maxValue; }
set { maxValue = value; }
}
public DateTime? SelectedValue
{
get
{
if (!minValue.HasValue || !maxValue.HasValue)
{
throw new NoRangeException("Диапозон не был задан");
}
else if (dateTimePicker.Value < minValue ||
dateTimePicker.Value > maxValue)
{
throw new NotIncludedInRangeException("Selected value is out of range.");
}
return dateTimePicker.Value;
}
set
{
if (!minValue.HasValue || !maxValue.HasValue || value < minValue || value > maxValue)
{
return;
}
dateTimePicker.Value = value.Value;
}
}
public event EventHandler ValueChanged
{
add { _valueChanged += value; }
remove { _valueChanged -= value; }
}
private void DateTimePicker_ValueChanged(object sender, EventArgs e)
{
_valueChanged?.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,56 @@
namespace COP
{
partial class UserDateTimePickercs
{
/// <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()
{
dateTimePicker = new DateTimePicker();
SuspendLayout();
//
// dateTimePicker
//
dateTimePicker.Location = new Point(0, 0);
dateTimePicker.Name = "dateTimePicker";
dateTimePicker.Size = new Size(250, 27);
dateTimePicker.TabIndex = 0;
dateTimePicker.ValueChanged += DateTimePicker_ValueChanged;
//
// UserDateTimePickercs
//
AutoScaleDimensions = new SizeF(8F, 20F);
AutoScaleMode = AutoScaleMode.Font;
Controls.Add(dateTimePicker);
Name = "UserDateTimePickercs";
Size = new Size(254, 29);
ResumeLayout(false);
}
#endregion
private DateTimePicker dateTimePicker;
}
}

View File

@ -0,0 +1,83 @@
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;
using COP.Exceptions;
namespace COP
{
public partial class UserDateTimePickercs : UserControl
{
private DateTime? minValue;
private DateTime? maxValue;
public event EventHandler? _valueChanged;
public UserDateTimePickercs()
{
InitializeComponent();
}
public DateTime? MinValue
{
get { return minValue; }
set { minValue = value; }
}
public DateTime? MaxValue
{
get { return maxValue; }
set { maxValue = value; }
}
public DateTime? SelectedValue
{
get
{
if (!minValue.HasValue || !maxValue.HasValue)
{
throw new NoRangeException("Диапозон не был задан");
}
else if (dateTimePicker.Value < minValue ||
dateTimePicker.Value > maxValue)
{
return null;
}
return dateTimePicker.Value;
}
set
{
if (!minValue.HasValue || !maxValue.HasValue)
{
throw new NoRangeException("Диапозон не был задан");
}
if (value < minValue || value > maxValue)
{
throw new NotIncludedInRangeException("Selected value is out of range.");
}
dateTimePicker.Value = value.Value;
}
}
public event EventHandler ValueChanged
{
add { _valueChanged += value; }
remove { _valueChanged -= value; }
}
private void DateTimePicker_ValueChanged(object sender, EventArgs e)
{
_valueChanged?.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,55 @@
namespace COP
{
partial class UserTreeView
{
/// <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()
{
treeView = new TreeView();
SuspendLayout();
//
// treeView
//
treeView.Location = new Point(0, 0);
treeView.Name = "treeView";
treeView.Size = new Size(150, 97);
treeView.TabIndex = 0;
//
// UserTreeView
//
AutoScaleDimensions = new SizeF(7F, 15F);
AutoScaleMode = AutoScaleMode.Font;
Controls.Add(treeView);
Name = "UserTreeView";
Size = new Size(150, 95);
ResumeLayout(false);
}
#endregion
private TreeView treeView;
}
}

View File

@ -0,0 +1,96 @@
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 COP
{
public partial class UserTreeView : UserControl
{
public List<string> Hierarchy;
public UserTreeView()
{
InitializeComponent();
Hierarchy = new();
}
public int SelectedItemIndex
{
get
{
if (treeView.SelectedNode == null)
{
return -1;
}
return treeView.SelectedNode.Index;
}
}
public T? GetSelectedObject<T>() where T : class, new()
{
// параметризованный
//проверка есть или нет иерархии
TreeNode selectedNode = treeView.SelectedNode;
if (Hierarchy == null)
{
throw new Exception("Hierarchy is not set.");
}
if (selectedNode?.FirstNode != null)
{
throw new Exception("Not a last level node.");
}
T currentBranch = new T();
Hierarchy.Reverse();
foreach (var property in Hierarchy)
{
typeof(T).GetProperty(property).SetValue(currentBranch, Convert.ChangeType(selectedNode.Text, typeof(T).GetProperty(property).PropertyType));
selectedNode = selectedNode.Parent;
}
Hierarchy.Reverse();
return currentBranch;
}
//проверка что выбранный элем последний в ветке
public void PopulateTree<T>(List<T> items)
{
treeView.BeginUpdate();
treeView.Nodes.Clear();
if (items == null)
{
throw new ArgumentNullException(nameof(items));
}
if (Hierarchy == null)
{
throw new Exception("Hierarchy is not set.");
}
foreach (var item in items)
{
TreeNodeCollection treeViewNodes = treeView.Nodes;
foreach (var elem in Hierarchy)
{
bool flag = false;
for (int i = 0; i < treeViewNodes.Count; i++)
{
if (item.GetType().GetProperty(elem).GetValue(item).ToString() == treeViewNodes[i].Text)
{
treeViewNodes = treeViewNodes[i].Nodes;
flag = true;
break;
}
}
if (!flag)
{
var newNode = treeViewNodes.Add(item.GetType().GetProperty(elem).GetValue(item).ToString());
treeViewNodes = newNode.Nodes;
}
}
}
treeView.EndUpdate();
}
}
}

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>