Compare commits
2 Commits
main
...
LabWork_02
Author | SHA1 | Date | |
---|---|---|---|
|
a75923818e | ||
|
79a329d782 |
@ -3,7 +3,9 @@ Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
# Visual Studio Version 17
|
||||
VisualStudioVersion = 17.5.33424.131
|
||||
MinimumVisualStudioVersion = 10.0.40219.1
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WinForm", "WinForm\WinForm.csproj", "{79A863DB-93E6-44C2-AB0F-DE0D19BE72DC}"
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "WinForm", "WinForm\WinForm.csproj", "{79A863DB-93E6-44C2-AB0F-DE0D19BE72DC}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WinFormsLibrary", "WinFormsLibrary\WinFormsLibrary.csproj", "{B617E65D-B482-4120-BC74-66B760D66FEF}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
@ -15,6 +17,10 @@ Global
|
||||
{79A863DB-93E6-44C2-AB0F-DE0D19BE72DC}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{79A863DB-93E6-44C2-AB0F-DE0D19BE72DC}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{79A863DB-93E6-44C2-AB0F-DE0D19BE72DC}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{B617E65D-B482-4120-BC74-66B760D66FEF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{B617E65D-B482-4120-BC74-66B760D66FEF}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{B617E65D-B482-4120-BC74-66B760D66FEF}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{B617E65D-B482-4120-BC74-66B760D66FEF}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
|
24
WinForm/WinForm/ExampleClass.cs
Normal file
24
WinForm/WinForm/ExampleClass.cs
Normal file
@ -0,0 +1,24 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace WinForm
|
||||
{
|
||||
public class ExampleClass
|
||||
{
|
||||
public int Id { get; set; }
|
||||
public string Book { get; set; }
|
||||
public string Genre { get; set; }
|
||||
public string Author { get; set; }
|
||||
|
||||
public ExampleClass(int Id, string Book, string Genre, string Author)
|
||||
{
|
||||
this.Id = Id;
|
||||
this.Book = Book;
|
||||
this.Genre = Genre;
|
||||
this.Author = Author;
|
||||
}
|
||||
}
|
||||
}
|
39
WinForm/WinForm/Form1.Designer.cs
generated
39
WinForm/WinForm/Form1.Designer.cs
generated
@ -1,39 +0,0 @@
|
||||
namespace WinForm
|
||||
{
|
||||
partial class Form1
|
||||
{
|
||||
/// <summary>
|
||||
/// Required designer variable.
|
||||
/// </summary>
|
||||
private System.ComponentModel.IContainer components = null;
|
||||
|
||||
/// <summary>
|
||||
/// Clean up any resources being used.
|
||||
/// </summary>
|
||||
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing && (components != null))
|
||||
{
|
||||
components.Dispose();
|
||||
}
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
|
||||
#region Windows Form Designer generated code
|
||||
|
||||
/// <summary>
|
||||
/// Required method for Designer support - do not modify
|
||||
/// the contents of this method with the code editor.
|
||||
/// </summary>
|
||||
private void InitializeComponent()
|
||||
{
|
||||
this.components = new System.ComponentModel.Container();
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||
this.ClientSize = new System.Drawing.Size(800, 450);
|
||||
this.Text = "Form1";
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
@ -1,10 +0,0 @@
|
||||
namespace WinForm
|
||||
{
|
||||
public partial class Form1 : Form
|
||||
{
|
||||
public Form1()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
}
|
||||
}
|
153
WinForm/WinForm/FormNoGraphics.Designer.cs
generated
Normal file
153
WinForm/WinForm/FormNoGraphics.Designer.cs
generated
Normal file
@ -0,0 +1,153 @@
|
||||
namespace WinForm
|
||||
{
|
||||
partial class FormNoGraphics
|
||||
{
|
||||
/// <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();
|
||||
pdfGeneratorControl = new WinFormsLibrary.PdfGeneratorControl(components);
|
||||
groupBoxPdfText = new GroupBox();
|
||||
buttonSaveDiagram = new Button();
|
||||
buttonSaveTable = new Button();
|
||||
buttonSaveFile = new Button();
|
||||
richTextBox = new RichTextBox();
|
||||
labelBigText = new Label();
|
||||
labelTitle = new Label();
|
||||
textBoxTitle = new TextBox();
|
||||
pdfTableGenerator = new WinFormsLibrary.PdfTableGenerator(components);
|
||||
pdfGeneratorLinearDiagram = new WinFormsLibrary.PdfGeneratorLinearDiagram(components);
|
||||
groupBoxPdfText.SuspendLayout();
|
||||
SuspendLayout();
|
||||
//
|
||||
// groupBoxPdfText
|
||||
//
|
||||
groupBoxPdfText.Controls.Add(buttonSaveDiagram);
|
||||
groupBoxPdfText.Controls.Add(buttonSaveTable);
|
||||
groupBoxPdfText.Controls.Add(buttonSaveFile);
|
||||
groupBoxPdfText.Controls.Add(richTextBox);
|
||||
groupBoxPdfText.Controls.Add(labelBigText);
|
||||
groupBoxPdfText.Controls.Add(labelTitle);
|
||||
groupBoxPdfText.Controls.Add(textBoxTitle);
|
||||
groupBoxPdfText.Location = new Point(12, 12);
|
||||
groupBoxPdfText.Name = "groupBoxPdfText";
|
||||
groupBoxPdfText.Size = new Size(328, 369);
|
||||
groupBoxPdfText.TabIndex = 0;
|
||||
groupBoxPdfText.TabStop = false;
|
||||
groupBoxPdfText.Text = "Работа с большим текстом pdf";
|
||||
//
|
||||
// buttonSaveDiagram
|
||||
//
|
||||
buttonSaveDiagram.Location = new Point(41, 319);
|
||||
buttonSaveDiagram.Name = "buttonSaveDiagram";
|
||||
buttonSaveDiagram.Size = new Size(226, 23);
|
||||
buttonSaveDiagram.TabIndex = 7;
|
||||
buttonSaveDiagram.Text = "Сохранить Диаграмму в PDF";
|
||||
buttonSaveDiagram.UseVisualStyleBackColor = true;
|
||||
buttonSaveDiagram.Click += ButtonSaveDiagram_Click;
|
||||
//
|
||||
// buttonSaveTable
|
||||
//
|
||||
buttonSaveTable.Location = new Point(41, 290);
|
||||
buttonSaveTable.Name = "buttonSaveTable";
|
||||
buttonSaveTable.Size = new Size(226, 23);
|
||||
buttonSaveTable.TabIndex = 6;
|
||||
buttonSaveTable.Text = "Сохранить Таблицу в PDF";
|
||||
buttonSaveTable.UseVisualStyleBackColor = true;
|
||||
buttonSaveTable.Click += ButtonSaveTable_Click;
|
||||
//
|
||||
// buttonSaveFile
|
||||
//
|
||||
buttonSaveFile.Location = new Point(41, 261);
|
||||
buttonSaveFile.Name = "buttonSaveFile";
|
||||
buttonSaveFile.Size = new Size(226, 23);
|
||||
buttonSaveFile.TabIndex = 4;
|
||||
buttonSaveFile.Text = "Сохранить Текст в PDF";
|
||||
buttonSaveFile.UseVisualStyleBackColor = true;
|
||||
buttonSaveFile.Click += ButtonSaveFile_Click;
|
||||
//
|
||||
// richTextBox
|
||||
//
|
||||
richTextBox.Location = new Point(41, 56);
|
||||
richTextBox.Name = "richTextBox";
|
||||
richTextBox.Size = new Size(268, 199);
|
||||
richTextBox.TabIndex = 3;
|
||||
richTextBox.Text = "";
|
||||
//
|
||||
// labelBigText
|
||||
//
|
||||
labelBigText.AutoSize = true;
|
||||
labelBigText.Location = new Point(6, 56);
|
||||
labelBigText.Name = "labelBigText";
|
||||
labelBigText.Size = new Size(28, 15);
|
||||
labelBigText.TabIndex = 2;
|
||||
labelBigText.Text = "Text";
|
||||
//
|
||||
// labelTitle
|
||||
//
|
||||
labelTitle.AutoSize = true;
|
||||
labelTitle.Location = new Point(6, 25);
|
||||
labelTitle.Name = "labelTitle";
|
||||
labelTitle.Size = new Size(29, 15);
|
||||
labelTitle.TabIndex = 1;
|
||||
labelTitle.Text = "Title";
|
||||
//
|
||||
// textBoxTitle
|
||||
//
|
||||
textBoxTitle.Location = new Point(41, 22);
|
||||
textBoxTitle.Name = "textBoxTitle";
|
||||
textBoxTitle.Size = new Size(268, 23);
|
||||
textBoxTitle.TabIndex = 0;
|
||||
//
|
||||
// FormNoGraphics
|
||||
//
|
||||
AutoScaleDimensions = new SizeF(7F, 15F);
|
||||
AutoScaleMode = AutoScaleMode.Font;
|
||||
ClientSize = new Size(351, 393);
|
||||
Controls.Add(groupBoxPdfText);
|
||||
Name = "FormNoGraphics";
|
||||
StartPosition = FormStartPosition.CenterScreen;
|
||||
Text = "Form";
|
||||
groupBoxPdfText.ResumeLayout(false);
|
||||
groupBoxPdfText.PerformLayout();
|
||||
ResumeLayout(false);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private WinFormsLibrary.PdfGeneratorControl pdfGeneratorControl;
|
||||
private GroupBox groupBoxPdfText;
|
||||
private Label labelTitle;
|
||||
private TextBox textBoxTitle;
|
||||
private Button buttonSaveFile;
|
||||
private RichTextBox richTextBox;
|
||||
private Label labelBigText;
|
||||
private WinFormsLibrary.PdfTableGenerator pdfTableGenerator;
|
||||
private Button buttonSaveDiagram;
|
||||
private Button buttonSaveTable;
|
||||
private WinFormsLibrary.PdfGeneratorLinearDiagram pdfGeneratorLinearDiagram;
|
||||
}
|
||||
}
|
129
WinForm/WinForm/FormNoGraphics.cs
Normal file
129
WinForm/WinForm/FormNoGraphics.cs
Normal file
@ -0,0 +1,129 @@
|
||||
using WinFormsLibrary.Helpers;
|
||||
|
||||
namespace WinForm
|
||||
{
|
||||
public partial class FormNoGraphics : Form
|
||||
{
|
||||
public FormNoGraphics()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
private List<(double, double)> GenerateRandomData(int count)
|
||||
{
|
||||
Random random = new Random();
|
||||
var data = new List<(double, double)>();
|
||||
for (int i = 1; i <= count; i++)
|
||||
{
|
||||
data.Add((i, random.NextDouble() * 50));
|
||||
}
|
||||
return data;
|
||||
}
|
||||
|
||||
private List<ExampleClass> GenerateRandomClass(int count)
|
||||
{
|
||||
string chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
|
||||
Random random = new Random();
|
||||
List<ExampleClass> returnedList = new List<ExampleClass>();
|
||||
for (int i = 0; i < count; ++i)
|
||||
{
|
||||
char[] stringChars = new char[10];
|
||||
for (int j = 0; j < 10; ++j)
|
||||
{
|
||||
stringChars[j] = chars[random.Next(chars.Length)];
|
||||
}
|
||||
returnedList.Add(new ExampleClass(i, new string(stringChars), new string(stringChars), new string(stringChars)));
|
||||
}
|
||||
return returnedList;
|
||||
}
|
||||
|
||||
private string SavePath()
|
||||
{
|
||||
string filePath = string.Empty;
|
||||
SaveFileDialog saveFileDialog = new SaveFileDialog();
|
||||
saveFileDialog.Filter = "PDF Files|*.pdf";
|
||||
if (saveFileDialog.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
filePath = saveFileDialog.FileName;
|
||||
}
|
||||
return filePath;
|
||||
}
|
||||
|
||||
private void ButtonSaveFile_Click(object sender, EventArgs e)
|
||||
{
|
||||
System.Text.Encoding.RegisterProvider(System.Text.CodePagesEncodingProvider.Instance);
|
||||
pdfGeneratorControl.GeneratePdf(SavePath(), textBoxTitle.Text, richTextBox.Lines.ToList());
|
||||
MessageBox.Show("PDF-äîêóìåíò óñïåøíî ñîõðàíåí.", "Óñïåõ", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
||||
}
|
||||
|
||||
private void ButtonSaveTable_Click(object sender, EventArgs e)
|
||||
{
|
||||
System.Text.Encoding.RegisterProvider(System.Text.CodePagesEncodingProvider.Instance);
|
||||
PdfWithTableData<ExampleClass> tableData = new();
|
||||
List<PdfWithTableHeader> tableHeader = new()
|
||||
{
|
||||
new PdfWithTableHeader()
|
||||
{
|
||||
ColumnName="Id",
|
||||
ColumnWidth=50
|
||||
},
|
||||
new PdfWithTableHeader()
|
||||
{
|
||||
ColumnName="Book",
|
||||
ColumnWidth=100
|
||||
},
|
||||
new PdfWithTableHeader()
|
||||
{
|
||||
ColumnName="Params",
|
||||
ColumnWidth=250,
|
||||
SubColumns = new()
|
||||
{
|
||||
new (){ ColumnName="Genre", ColumnWidth=125},
|
||||
new (){ ColumnName="Author", ColumnWidth=125}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
tableData.TableHeader = tableHeader;
|
||||
tableData.Props = new List<string> { "Id", "Book", "Genre", "Author" };
|
||||
tableData.TableData = GenerateRandomClass(5);
|
||||
|
||||
tableData.DocumentTitle = textBoxTitle.Text;
|
||||
tableData.FilePath = SavePath();
|
||||
pdfTableGenerator.GeneratePdf(tableData);
|
||||
MessageBox.Show("PDF-äîêóìåíò óñïåøíî ñîõðàíåí.", "Óñïåõ", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
||||
}
|
||||
|
||||
private void ButtonSaveDiagram_Click(object sender, EventArgs e)
|
||||
{
|
||||
System.Text.Encoding.RegisterProvider(System.Text.CodePagesEncodingProvider.Instance);
|
||||
PdfWithDiagramData diagramData = new();
|
||||
|
||||
diagramData.DocumentTitle = textBoxTitle.Text;
|
||||
diagramData.DiagramName = textBoxTitle.Text;
|
||||
diagramData.LegendPosition = DiagramLegendPosition.BottomCenterOutside;
|
||||
diagramData.Series = new(){
|
||||
new()
|
||||
{
|
||||
Name = "Ðÿä-1",
|
||||
Data = GenerateRandomData(5)
|
||||
},
|
||||
new()
|
||||
{
|
||||
Name = "Ðÿä-2",
|
||||
Data = GenerateRandomData(5)
|
||||
}
|
||||
};
|
||||
diagramData.FilePath = SavePath();
|
||||
try
|
||||
{
|
||||
pdfGeneratorLinearDiagram.GeneratePdfDocumentWithChart(diagramData);
|
||||
MessageBox.Show("PDF-äîêóìåíò ñîçäàí.", "Óñïåõ", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
MessageBox.Show($"PDF-äîêóìåíòà íå ñîçäàí: {ex.Message}", "Îøèáêà", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -11,7 +11,7 @@ namespace WinForm
|
||||
// To customize application configuration such as set high DPI settings or default font,
|
||||
// see https://aka.ms/applicationconfiguration.
|
||||
ApplicationConfiguration.Initialize();
|
||||
Application.Run(new Form1());
|
||||
Application.Run(new FormNoGraphics());
|
||||
}
|
||||
}
|
||||
}
|
@ -8,4 +8,8 @@
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\WinFormsLibrary\WinFormsLibrary.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
71
WinForm/WinFormsLibrary/DropDownList.Designer.cs
generated
Normal file
71
WinForm/WinFormsLibrary/DropDownList.Designer.cs
generated
Normal file
@ -0,0 +1,71 @@
|
||||
namespace WinForm
|
||||
{
|
||||
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();
|
||||
labelTitle = new Label();
|
||||
SuspendLayout();
|
||||
//
|
||||
// comboBox
|
||||
//
|
||||
comboBox.FormattingEnabled = true;
|
||||
comboBox.Location = new Point(13, 39);
|
||||
comboBox.Name = "comboBox";
|
||||
comboBox.Size = new Size(232, 23);
|
||||
comboBox.TabIndex = 0;
|
||||
comboBox.SelectedValueChanged += ComboBox_SelectedValueChanged;
|
||||
//
|
||||
// labelTitle
|
||||
//
|
||||
labelTitle.AutoSize = true;
|
||||
labelTitle.Font = new Font("Segoe UI", 9F, FontStyle.Bold, GraphicsUnit.Point);
|
||||
labelTitle.Location = new Point(13, 11);
|
||||
labelTitle.Name = "labelTitle";
|
||||
labelTitle.Size = new Size(133, 15);
|
||||
labelTitle.TabIndex = 1;
|
||||
labelTitle.Text = "Выпадающий список";
|
||||
//
|
||||
// DropDownList
|
||||
//
|
||||
AutoScaleDimensions = new SizeF(7F, 15F);
|
||||
AutoScaleMode = AutoScaleMode.Font;
|
||||
Controls.Add(labelTitle);
|
||||
Controls.Add(comboBox);
|
||||
Name = "DropDownList";
|
||||
Size = new Size(260, 80);
|
||||
ResumeLayout(false);
|
||||
PerformLayout();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private ComboBox comboBox;
|
||||
private Label labelTitle;
|
||||
}
|
||||
}
|
72
WinForm/WinFormsLibrary/DropDownList.cs
Normal file
72
WinForm/WinFormsLibrary/DropDownList.cs
Normal file
@ -0,0 +1,72 @@
|
||||
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 WinForm
|
||||
{
|
||||
public partial class DropDownList : UserControl
|
||||
{
|
||||
public DropDownList()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
public void Clear()
|
||||
{
|
||||
comboBox.Items.Clear();
|
||||
}
|
||||
|
||||
public string Selected
|
||||
{
|
||||
get
|
||||
{
|
||||
if (comboBox.Items.Count == 0)
|
||||
{
|
||||
return "";
|
||||
}
|
||||
if (comboBox.SelectedItem == null)
|
||||
{
|
||||
return "";
|
||||
}
|
||||
return comboBox.SelectedItem.ToString()!;
|
||||
}
|
||||
set
|
||||
{
|
||||
if (comboBox.Items.Contains(value))
|
||||
{
|
||||
comboBox.SelectedItem = value;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public ComboBox.ObjectCollection ComboBoxItems
|
||||
{
|
||||
get { return comboBox.Items; }
|
||||
}
|
||||
|
||||
private EventHandler _explicitEvent;
|
||||
public event EventHandler ExplicitEvent
|
||||
{
|
||||
add
|
||||
{
|
||||
_explicitEvent += value;
|
||||
}
|
||||
remove
|
||||
{
|
||||
_explicitEvent -= value;
|
||||
}
|
||||
}
|
||||
|
||||
private void ComboBox_SelectedValueChanged(object sender, EventArgs e)
|
||||
{
|
||||
_explicitEvent?.Invoke(sender, e);
|
||||
}
|
||||
}
|
||||
}
|
60
WinForm/WinFormsLibrary/DropDownList.resx
Normal file
60
WinForm/WinFormsLibrary/DropDownList.resx
Normal file
@ -0,0 +1,60 @@
|
||||
<root>
|
||||
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
|
||||
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
|
||||
<xsd:element name="root" msdata:IsDataSet="true">
|
||||
<xsd:complexType>
|
||||
<xsd:choice maxOccurs="unbounded">
|
||||
<xsd:element name="metadata">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" use="required" type="xsd:string" />
|
||||
<xsd:attribute name="type" type="xsd:string" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="assembly">
|
||||
<xsd:complexType>
|
||||
<xsd:attribute name="alias" type="xsd:string" />
|
||||
<xsd:attribute name="name" type="xsd:string" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="data">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
|
||||
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="resheader">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:choice>
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:schema>
|
||||
<resheader name="resmimetype">
|
||||
<value>text/microsoft-resx</value>
|
||||
</resheader>
|
||||
<resheader name="version">
|
||||
<value>2.0</value>
|
||||
</resheader>
|
||||
<resheader name="reader">
|
||||
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<resheader name="writer">
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
</root>
|
57
WinForm/WinFormsLibrary/Helpers/DiagramLegendPosition.cs
Normal file
57
WinForm/WinFormsLibrary/Helpers/DiagramLegendPosition.cs
Normal file
@ -0,0 +1,57 @@
|
||||
using OxyPlot.Legends;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace WinFormsLibrary.Helpers
|
||||
{
|
||||
public class LegendSettingsAttribute : Attribute
|
||||
{
|
||||
public LegendPosition Position { get; }
|
||||
public LegendPlacement Placement { get; }
|
||||
|
||||
public LegendSettingsAttribute(LegendPosition position, LegendPlacement placement)
|
||||
{
|
||||
Position = position;
|
||||
Placement = placement;
|
||||
}
|
||||
}
|
||||
|
||||
public enum DiagramLegendPosition
|
||||
{
|
||||
[LegendSettings(LegendPosition.LeftTop, LegendPlacement.Outside)]
|
||||
TopLeftOutside,
|
||||
[LegendSettings(LegendPosition.TopCenter, LegendPlacement.Outside)]
|
||||
TopCenterOutside,
|
||||
[LegendSettings(LegendPosition.RightTop, LegendPlacement.Outside)]
|
||||
TopRightOutside,
|
||||
[LegendSettings(LegendPosition.LeftMiddle, LegendPlacement.Outside)]
|
||||
MiddleLeftOutside,
|
||||
[LegendSettings(LegendPosition.RightMiddle, LegendPlacement.Outside)]
|
||||
MiddleRightOutside,
|
||||
[LegendSettings(LegendPosition.BottomLeft, LegendPlacement.Outside)]
|
||||
BottomLeftOutside,
|
||||
[LegendSettings(LegendPosition.BottomCenter, LegendPlacement.Outside)]
|
||||
BottomCenterOutside,
|
||||
[LegendSettings(LegendPosition.BottomRight, LegendPlacement.Outside)]
|
||||
BottomRightOutside,
|
||||
[LegendSettings(LegendPosition.LeftTop, LegendPlacement.Inside)]
|
||||
TopLeftInside,
|
||||
[LegendSettings(LegendPosition.TopCenter, LegendPlacement.Inside)]
|
||||
TopCenterInside,
|
||||
[LegendSettings(LegendPosition.RightTop, LegendPlacement.Inside)]
|
||||
TopRightInside,
|
||||
[LegendSettings(LegendPosition.LeftMiddle, LegendPlacement.Inside)]
|
||||
MiddleLeftInside,
|
||||
[LegendSettings(LegendPosition.RightMiddle, LegendPlacement.Inside)]
|
||||
MiddleRightInside,
|
||||
[LegendSettings(LegendPosition.BottomLeft, LegendPlacement.Inside)]
|
||||
BottomLeftInside,
|
||||
[LegendSettings(LegendPosition.BottomCenter, LegendPlacement.Inside)]
|
||||
BottomCenterInside,
|
||||
[LegendSettings(LegendPosition.BottomRight, LegendPlacement.Inside)]
|
||||
BottomRightInside,
|
||||
}
|
||||
}
|
17
WinForm/WinFormsLibrary/Helpers/PdfWithDiagramData.cs
Normal file
17
WinForm/WinFormsLibrary/Helpers/PdfWithDiagramData.cs
Normal file
@ -0,0 +1,17 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace WinFormsLibrary.Helpers
|
||||
{
|
||||
public class PdfWithDiagramData
|
||||
{
|
||||
public string FilePath { get; set; } = string.Empty;
|
||||
public string DocumentTitle { get; set; } = string.Empty;
|
||||
public string DiagramName { get; set; } = string.Empty;
|
||||
public DiagramLegendPosition LegendPosition { get; set; } = DiagramLegendPosition.BottomCenterOutside;
|
||||
public List<PdfWithDiagramSeries> Series { get; set; } = new();
|
||||
}
|
||||
}
|
14
WinForm/WinFormsLibrary/Helpers/PdfWithDiagramSeries.cs
Normal file
14
WinForm/WinFormsLibrary/Helpers/PdfWithDiagramSeries.cs
Normal file
@ -0,0 +1,14 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace WinFormsLibrary.Helpers
|
||||
{
|
||||
public class PdfWithDiagramSeries
|
||||
{
|
||||
public string Name { get; set; } = string.Empty;
|
||||
public List<(double, double)> Data { get; set; } = new();
|
||||
}
|
||||
}
|
17
WinForm/WinFormsLibrary/Helpers/PdfWithTableData.cs
Normal file
17
WinForm/WinFormsLibrary/Helpers/PdfWithTableData.cs
Normal file
@ -0,0 +1,17 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace WinFormsLibrary.Helpers
|
||||
{
|
||||
public class PdfWithTableData<T>
|
||||
{
|
||||
public string FilePath { get; set; } = string.Empty;
|
||||
public string DocumentTitle { get; set; } = string.Empty;
|
||||
public List<PdfWithTableHeader> TableHeader { get; set; } = new();
|
||||
public List<T> TableData { get; set; } = new();
|
||||
public List<string> Props { get; set; } = new();
|
||||
}
|
||||
}
|
15
WinForm/WinFormsLibrary/Helpers/PdfWithTableHeader.cs
Normal file
15
WinForm/WinFormsLibrary/Helpers/PdfWithTableHeader.cs
Normal file
@ -0,0 +1,15 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace WinFormsLibrary.Helpers
|
||||
{
|
||||
public class PdfWithTableHeader
|
||||
{
|
||||
public string? ColumnName { get; set; } = string.Empty;
|
||||
public int ColumnWidth { get; set; } = 100;
|
||||
public List<PdfWithTableSubHeader> SubColumns { get; set; } = new List<PdfWithTableSubHeader>();
|
||||
}
|
||||
}
|
14
WinForm/WinFormsLibrary/Helpers/PdfWithTableSubHeader.cs
Normal file
14
WinForm/WinFormsLibrary/Helpers/PdfWithTableSubHeader.cs
Normal file
@ -0,0 +1,14 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace WinFormsLibrary.Helpers
|
||||
{
|
||||
public class PdfWithTableSubHeader
|
||||
{
|
||||
public string? ColumnName { get; set; } = string.Empty;
|
||||
public int ColumnWidth { get; set; } = 100;
|
||||
}
|
||||
}
|
71
WinForm/WinFormsLibrary/ListBoxValues.Designer.cs
generated
Normal file
71
WinForm/WinFormsLibrary/ListBoxValues.Designer.cs
generated
Normal file
@ -0,0 +1,71 @@
|
||||
namespace WinForm
|
||||
{
|
||||
partial class ListBoxValues
|
||||
{
|
||||
/// <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();
|
||||
componentTitleLabel = new Label();
|
||||
SuspendLayout();
|
||||
//
|
||||
// listBox
|
||||
//
|
||||
listBox.FormattingEnabled = true;
|
||||
listBox.ItemHeight = 15;
|
||||
listBox.Location = new Point(12, 39);
|
||||
listBox.Name = "listBox";
|
||||
listBox.Size = new Size(172, 154);
|
||||
listBox.TabIndex = 0;
|
||||
//
|
||||
// componentTitleLabel
|
||||
//
|
||||
componentTitleLabel.AutoSize = true;
|
||||
componentTitleLabel.Font = new Font("Segoe UI", 9F, FontStyle.Bold, GraphicsUnit.Point);
|
||||
componentTitleLabel.Location = new Point(12, 12);
|
||||
componentTitleLabel.Name = "componentTitleLabel";
|
||||
componentTitleLabel.Size = new Size(108, 15);
|
||||
componentTitleLabel.TabIndex = 1;
|
||||
componentTitleLabel.Text = "Список занчений";
|
||||
//
|
||||
// ListBoxValues
|
||||
//
|
||||
AutoScaleDimensions = new SizeF(7F, 15F);
|
||||
AutoScaleMode = AutoScaleMode.Font;
|
||||
Controls.Add(componentTitleLabel);
|
||||
Controls.Add(listBox);
|
||||
Name = "ListBoxValues";
|
||||
Size = new Size(200, 206);
|
||||
ResumeLayout(false);
|
||||
PerformLayout();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private ListBox listBox;
|
||||
private Label componentTitleLabel;
|
||||
}
|
||||
}
|
113
WinForm/WinFormsLibrary/ListBoxValues.cs
Normal file
113
WinForm/WinFormsLibrary/ListBoxValues.cs
Normal file
@ -0,0 +1,113 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Data;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace WinForm
|
||||
{
|
||||
public partial class ListBoxValues : UserControl
|
||||
{
|
||||
private string layoutString;
|
||||
private string startSymbol;
|
||||
private string endSymbol;
|
||||
|
||||
public ListBoxValues()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
public void SetLayoutInfo(string layout, string startS, string endS)
|
||||
{
|
||||
if (layout == null || startS == null || endS == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
layoutString = layout;
|
||||
startSymbol = startS;
|
||||
endSymbol = endS;
|
||||
}
|
||||
|
||||
public int SelectedIndex
|
||||
{
|
||||
get
|
||||
{
|
||||
if (listBox.SelectedIndex == -1)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
return listBox.SelectedIndex;
|
||||
}
|
||||
set
|
||||
{
|
||||
if (listBox.SelectedItems.Count != 0)
|
||||
{
|
||||
listBox.SelectedIndex = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public T GetObjectFromStr<T>() where T : class, new()
|
||||
{
|
||||
if (listBox.SelectedIndex == -1)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
string row = listBox.SelectedItem.ToString()!;
|
||||
T curObject = new T();
|
||||
StringBuilder sb = new StringBuilder(row);
|
||||
foreach (var property in typeof(T).GetProperties())
|
||||
{
|
||||
if (!property.CanWrite)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
int borderOne = sb.ToString().IndexOf(startSymbol);
|
||||
if (borderOne == -1)
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
int borderTwo = sb.ToString().IndexOf(endSymbol, borderOne + 1);
|
||||
if (borderTwo == -1)
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
string propertyValue = sb.ToString(borderOne + 1, borderTwo - borderOne - 1);
|
||||
sb.Remove(0, borderTwo + 1);
|
||||
property.SetValue(curObject, Convert.ChangeType(propertyValue, property.PropertyType));
|
||||
}
|
||||
return curObject;
|
||||
}
|
||||
|
||||
public void FillProperty<T>(T dataObject, int rowIndex, string propertyName)
|
||||
{
|
||||
if (layoutString == null || startSymbol == null || endSymbol == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
while (listBox.Items.Count <= rowIndex)
|
||||
{
|
||||
listBox.Items.Add(layoutString);
|
||||
}
|
||||
|
||||
string row = listBox.Items[rowIndex].ToString();
|
||||
PropertyInfo propertyInfo = dataObject.GetType().GetProperty(propertyName);
|
||||
|
||||
if (propertyInfo != null)
|
||||
{
|
||||
object propertyValue = propertyInfo.GetValue(dataObject);
|
||||
row = row.Replace($"{startSymbol}{propertyName}{endSymbol}", propertyValue.ToString());
|
||||
listBox.Items[rowIndex] = row;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
60
WinForm/WinFormsLibrary/ListBoxValues.resx
Normal file
60
WinForm/WinFormsLibrary/ListBoxValues.resx
Normal file
@ -0,0 +1,60 @@
|
||||
<root>
|
||||
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
|
||||
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
|
||||
<xsd:element name="root" msdata:IsDataSet="true">
|
||||
<xsd:complexType>
|
||||
<xsd:choice maxOccurs="unbounded">
|
||||
<xsd:element name="metadata">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" use="required" type="xsd:string" />
|
||||
<xsd:attribute name="type" type="xsd:string" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="assembly">
|
||||
<xsd:complexType>
|
||||
<xsd:attribute name="alias" type="xsd:string" />
|
||||
<xsd:attribute name="name" type="xsd:string" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="data">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
|
||||
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="resheader">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:choice>
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:schema>
|
||||
<resheader name="resmimetype">
|
||||
<value>text/microsoft-resx</value>
|
||||
</resheader>
|
||||
<resheader name="version">
|
||||
<value>2.0</value>
|
||||
</resheader>
|
||||
<resheader name="reader">
|
||||
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<resheader name="writer">
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
</root>
|
72
WinForm/WinFormsLibrary/NumberTextBox.Designer.cs
generated
Normal file
72
WinForm/WinFormsLibrary/NumberTextBox.Designer.cs
generated
Normal file
@ -0,0 +1,72 @@
|
||||
namespace WinForm
|
||||
{
|
||||
partial class NumberTextBox
|
||||
{
|
||||
/// <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()
|
||||
{
|
||||
componentTitleLabel = new Label();
|
||||
textBox = new TextBox();
|
||||
SuspendLayout();
|
||||
//
|
||||
// componentTitleLabel
|
||||
//
|
||||
componentTitleLabel.AutoSize = true;
|
||||
componentTitleLabel.Font = new Font("Segoe UI", 9F, FontStyle.Bold, GraphicsUnit.Point);
|
||||
componentTitleLabel.Location = new Point(13, 12);
|
||||
componentTitleLabel.Name = "componentTitleLabel";
|
||||
componentTitleLabel.Size = new Size(154, 15);
|
||||
componentTitleLabel.TabIndex = 1;
|
||||
componentTitleLabel.Text = "Введите номер телефона";
|
||||
//
|
||||
// textBox
|
||||
//
|
||||
textBox.Location = new Point(13, 41);
|
||||
textBox.Name = "textBox";
|
||||
textBox.Size = new Size(234, 23);
|
||||
textBox.TabIndex = 2;
|
||||
textBox.TextChanged += TextBox_TextChanged;
|
||||
textBox.Enter += TextBox_Enter;
|
||||
//
|
||||
// NumberTextBox
|
||||
//
|
||||
AutoScaleDimensions = new SizeF(7F, 15F);
|
||||
AutoScaleMode = AutoScaleMode.Font;
|
||||
Controls.Add(textBox);
|
||||
Controls.Add(componentTitleLabel);
|
||||
Name = "NumberTextBox";
|
||||
Size = new Size(260, 80);
|
||||
ResumeLayout(false);
|
||||
PerformLayout();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private TextBox numberTextBox;
|
||||
private Label componentTitleLabel;
|
||||
private TextBox textBox;
|
||||
}
|
||||
}
|
86
WinForm/WinFormsLibrary/NumberTextBox.cs
Normal file
86
WinForm/WinFormsLibrary/NumberTextBox.cs
Normal file
@ -0,0 +1,86 @@
|
||||
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;
|
||||
|
||||
namespace WinForm
|
||||
{
|
||||
public partial class NumberTextBox : UserControl
|
||||
{
|
||||
//Шаблон для textbox
|
||||
private string? pattern;
|
||||
private string example = "+7XXXXXXXXXX";
|
||||
|
||||
public NumberTextBox()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
//Публичное свойство для получения и заполнения шаблона
|
||||
public string? Pattern
|
||||
{
|
||||
get { return pattern; }
|
||||
set { pattern = value; }
|
||||
}
|
||||
|
||||
public string? TextBoxValue
|
||||
{
|
||||
get
|
||||
{
|
||||
if (new Regex(Pattern).IsMatch(textBox.Text))
|
||||
{
|
||||
return textBox.Text;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
set
|
||||
{
|
||||
if (new Regex(Pattern).IsMatch(value))
|
||||
{
|
||||
textBox.Text = value;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
//Метод для заполнения примера
|
||||
public void SetExample(string str)
|
||||
{
|
||||
if (new Regex(Pattern).IsMatch(str))
|
||||
{
|
||||
example = str;
|
||||
}
|
||||
}
|
||||
|
||||
private void TextBox_Enter(object sender, EventArgs e)
|
||||
{
|
||||
int VisibleTime = 3000;
|
||||
ToolTip tt = new ToolTip();
|
||||
tt.Show(example, textBox, 0, 25, VisibleTime);
|
||||
}
|
||||
|
||||
private EventHandler _explicitEvent;
|
||||
public event EventHandler ExplicitEvent
|
||||
{
|
||||
add
|
||||
{
|
||||
_explicitEvent += value;
|
||||
}
|
||||
remove
|
||||
{
|
||||
_explicitEvent -= value;
|
||||
}
|
||||
}
|
||||
|
||||
private void TextBox_TextChanged(object sender, EventArgs e)
|
||||
{
|
||||
_explicitEvent?.Invoke(sender, e);
|
||||
}
|
||||
}
|
||||
}
|
60
WinForm/WinFormsLibrary/NumberTextBox.resx
Normal file
60
WinForm/WinFormsLibrary/NumberTextBox.resx
Normal file
@ -0,0 +1,60 @@
|
||||
<root>
|
||||
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
|
||||
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
|
||||
<xsd:element name="root" msdata:IsDataSet="true">
|
||||
<xsd:complexType>
|
||||
<xsd:choice maxOccurs="unbounded">
|
||||
<xsd:element name="metadata">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" use="required" type="xsd:string" />
|
||||
<xsd:attribute name="type" type="xsd:string" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="assembly">
|
||||
<xsd:complexType>
|
||||
<xsd:attribute name="alias" type="xsd:string" />
|
||||
<xsd:attribute name="name" type="xsd:string" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="data">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
|
||||
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="resheader">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:choice>
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:schema>
|
||||
<resheader name="resmimetype">
|
||||
<value>text/microsoft-resx</value>
|
||||
</resheader>
|
||||
<resheader name="version">
|
||||
<value>2.0</value>
|
||||
</resheader>
|
||||
<resheader name="reader">
|
||||
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<resheader name="writer">
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
</root>
|
36
WinForm/WinFormsLibrary/PdfGeneratorControl.Designer.cs
generated
Normal file
36
WinForm/WinFormsLibrary/PdfGeneratorControl.Designer.cs
generated
Normal file
@ -0,0 +1,36 @@
|
||||
namespace WinFormsLibrary
|
||||
{
|
||||
partial class PdfGeneratorControl
|
||||
{
|
||||
/// <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
|
||||
}
|
||||
}
|
55
WinForm/WinFormsLibrary/PdfGeneratorControl.cs
Normal file
55
WinForm/WinFormsLibrary/PdfGeneratorControl.cs
Normal file
@ -0,0 +1,55 @@
|
||||
using MigraDoc.DocumentObjectModel;
|
||||
using MigraDoc.Rendering;
|
||||
using PdfSharp.Fonts;
|
||||
using PdfSharp.Pdf;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace WinFormsLibrary
|
||||
{
|
||||
public partial class PdfGeneratorControl : Component
|
||||
{
|
||||
public PdfGeneratorControl()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
public PdfGeneratorControl(IContainer container)
|
||||
{
|
||||
container.Add(this);
|
||||
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
public void GeneratePdf(string filePath, string documentTitle, List<string> textData)
|
||||
{
|
||||
if (string.IsNullOrEmpty(filePath) || string.IsNullOrEmpty(documentTitle) || textData == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Document document = new Document();
|
||||
|
||||
Section section = document.AddSection();
|
||||
|
||||
Paragraph title = section.AddParagraph(documentTitle);
|
||||
title.Format.Font.Bold = true;
|
||||
|
||||
foreach (var item in textData)
|
||||
{
|
||||
Paragraph paragraph = section.AddParagraph();
|
||||
paragraph.AddText(item);
|
||||
}
|
||||
|
||||
PdfDocumentRenderer pdfRenderer = new PdfDocumentRenderer(true, PdfFontEmbedding.Always);
|
||||
pdfRenderer.Document = document;
|
||||
pdfRenderer.RenderDocument();
|
||||
pdfRenderer.PdfDocument.Save(filePath);
|
||||
}
|
||||
}
|
||||
}
|
36
WinForm/WinFormsLibrary/PdfGeneratorLinearDiagram.Designer.cs
generated
Normal file
36
WinForm/WinFormsLibrary/PdfGeneratorLinearDiagram.Designer.cs
generated
Normal file
@ -0,0 +1,36 @@
|
||||
namespace WinFormsLibrary
|
||||
{
|
||||
partial class PdfGeneratorLinearDiagram
|
||||
{
|
||||
/// <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
|
||||
}
|
||||
}
|
84
WinForm/WinFormsLibrary/PdfGeneratorLinearDiagram.cs
Normal file
84
WinForm/WinFormsLibrary/PdfGeneratorLinearDiagram.cs
Normal file
@ -0,0 +1,84 @@
|
||||
using MigraDoc.DocumentObjectModel;
|
||||
using MigraDoc.Rendering;
|
||||
using OxyPlot;
|
||||
using OxyPlot.Axes;
|
||||
using OxyPlot.Legends;
|
||||
using OxyPlot.Series;
|
||||
using OxyPlot.WindowsForms;
|
||||
using System.ComponentModel;
|
||||
using System.Reflection;
|
||||
using WinFormsLibrary.Helpers;
|
||||
|
||||
namespace WinFormsLibrary
|
||||
{
|
||||
public partial class PdfGeneratorLinearDiagram : Component
|
||||
{
|
||||
public PdfGeneratorLinearDiagram()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
public PdfGeneratorLinearDiagram(IContainer container)
|
||||
{
|
||||
container.Add(this);
|
||||
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
public void GeneratePdfDocumentWithChart(PdfWithDiagramData pdfDiagram)
|
||||
{
|
||||
if (string.IsNullOrEmpty(pdfDiagram.FilePath) || string.IsNullOrEmpty(pdfDiagram.DocumentTitle)
|
||||
|| string.IsNullOrEmpty(pdfDiagram.DiagramName) || pdfDiagram.Series == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var plotModel = new PlotModel { Title = pdfDiagram.DiagramName };
|
||||
|
||||
var xAxis = new LinearAxis { Position = AxisPosition.Bottom };
|
||||
var yAxis = new LinearAxis { Position = AxisPosition.Left };
|
||||
plotModel.Axes.Add(xAxis);
|
||||
plotModel.Axes.Add(yAxis);
|
||||
|
||||
foreach (var item in pdfDiagram.Series)
|
||||
{
|
||||
var singleSeries = new LineSeries { Title = item.Name };
|
||||
foreach (var coordinates in item.Data)
|
||||
{
|
||||
singleSeries.Points.Add(new DataPoint(coordinates.Item1, coordinates.Item2));
|
||||
}
|
||||
plotModel.Series.Add(singleSeries);
|
||||
}
|
||||
|
||||
var fieldInfo = typeof(DiagramLegendPosition).GetField(pdfDiagram.LegendPosition.ToString());
|
||||
var attribute = fieldInfo?.GetCustomAttribute<LegendSettingsAttribute>();
|
||||
|
||||
plotModel.Legends.Add(new Legend()
|
||||
{
|
||||
LegendTitle = "Легенда",
|
||||
LegendPlacement = attribute.Placement,
|
||||
LegendPosition = attribute.Position,
|
||||
});
|
||||
plotModel.IsLegendVisible = true;
|
||||
|
||||
var document = new Document();
|
||||
document.Info.Title = pdfDiagram.DocumentTitle;
|
||||
|
||||
var section = document.AddSection();
|
||||
section.PageSetup.TopMargin = "1cm";
|
||||
|
||||
var image = new PngExporter { Width = 600, Height = 400 }.ExportToBitmap(plotModel);
|
||||
image.Save("temp.png");
|
||||
|
||||
var chartImage = section.AddImage("temp.png");
|
||||
chartImage.LockAspectRatio = true;
|
||||
chartImage.Width = "15cm";
|
||||
chartImage.Height = "10cm";
|
||||
|
||||
var pdfRenderer = new PdfDocumentRenderer(true);
|
||||
pdfRenderer.Document = document;
|
||||
pdfRenderer.RenderDocument();
|
||||
pdfRenderer.PdfDocument.Save(pdfDiagram.FilePath);
|
||||
}
|
||||
}
|
||||
}
|
36
WinForm/WinFormsLibrary/PdfTableGenerator.Designer.cs
generated
Normal file
36
WinForm/WinFormsLibrary/PdfTableGenerator.Designer.cs
generated
Normal file
@ -0,0 +1,36 @@
|
||||
namespace WinFormsLibrary
|
||||
{
|
||||
partial class PdfTableGenerator
|
||||
{
|
||||
/// <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
|
||||
}
|
||||
}
|
134
WinForm/WinFormsLibrary/PdfTableGenerator.cs
Normal file
134
WinForm/WinFormsLibrary/PdfTableGenerator.cs
Normal file
@ -0,0 +1,134 @@
|
||||
using PdfSharp.Pdf;
|
||||
using MigraDoc.DocumentObjectModel;
|
||||
using MigraDoc.DocumentObjectModel.Tables;
|
||||
using MigraDoc.Rendering;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using WinFormsLibrary.Helpers;
|
||||
|
||||
namespace WinFormsLibrary
|
||||
{
|
||||
public partial class PdfTableGenerator : Component
|
||||
{
|
||||
private int fontSize = 14;
|
||||
|
||||
public PdfTableGenerator()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
public PdfTableGenerator(IContainer container)
|
||||
{
|
||||
container.Add(this);
|
||||
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
public void GeneratePdf<T>(PdfWithTableData<T> pdfTable)
|
||||
{
|
||||
if (pdfTable == null || string.IsNullOrEmpty(pdfTable.FilePath)
|
||||
|| string.IsNullOrEmpty(pdfTable.DocumentTitle) || pdfTable.TableHeader == null)
|
||||
{
|
||||
throw new ArgumentException("Недостаточно данных для создания PDF-документа.");
|
||||
}
|
||||
Document document = new Document();
|
||||
Section section = document.AddSection();
|
||||
|
||||
Paragraph title = section.AddParagraph(pdfTable.DocumentTitle);
|
||||
title.Format.Font.Bold = true;
|
||||
title.Format.Alignment = ParagraphAlignment.Center;
|
||||
|
||||
Table table = section.AddTable();
|
||||
table.Borders.Visible = true;
|
||||
|
||||
foreach (var column in pdfTable.TableHeader)
|
||||
{
|
||||
if (column.SubColumns.Count > 0)
|
||||
{
|
||||
foreach(var sub in column.SubColumns)
|
||||
{
|
||||
Column newsub = table.AddColumn();
|
||||
newsub.Width = sub.ColumnWidth;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
Column newcolumn = table.AddColumn();
|
||||
newcolumn.Width = column.ColumnWidth;
|
||||
}
|
||||
|
||||
CreateTableHeader(table, pdfTable.TableHeader);
|
||||
|
||||
CreateTableData(table, pdfTable);
|
||||
|
||||
PdfDocumentRenderer pdfRenderer = new PdfDocumentRenderer(true);
|
||||
pdfRenderer.Document = document;
|
||||
pdfRenderer.RenderDocument();
|
||||
pdfRenderer.PdfDocument.Save(pdfTable.FilePath);
|
||||
}
|
||||
|
||||
public void CreateTableHeader(Table table, List<PdfWithTableHeader> headerInfo)
|
||||
{
|
||||
Row headerRow1 = table.AddRow();
|
||||
Row headerRow2 = table.AddRow();
|
||||
|
||||
foreach (Row headerRow in new Row[] { headerRow1, headerRow2 })
|
||||
{
|
||||
headerRow.HeadingFormat = true;
|
||||
headerRow.Format.Alignment = ParagraphAlignment.Center;
|
||||
headerRow.Format.Font.Bold = true;
|
||||
}
|
||||
|
||||
int i = 0;
|
||||
foreach (var column in headerInfo)
|
||||
{
|
||||
int rowSpan = Math.Max(1, column.SubColumns.Count);
|
||||
|
||||
if (column.SubColumns.Count > 0)
|
||||
{
|
||||
headerRow1.Cells[i].MergeRight = rowSpan - 1;
|
||||
|
||||
for (int j = 0; j < column.SubColumns.Count; j++)
|
||||
{
|
||||
headerRow2.Cells[i + j].AddParagraph(column.SubColumns[j].ColumnName);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
headerRow1.Cells[i].MergeDown = rowSpan;
|
||||
}
|
||||
|
||||
headerRow1.Cells[i].AddParagraph(column.ColumnName);
|
||||
i += rowSpan;
|
||||
}
|
||||
}
|
||||
|
||||
private void CreateTableData<T>(Table table, PdfWithTableData<T> data)
|
||||
{
|
||||
if (data == null || data.TableData == null)
|
||||
return;
|
||||
|
||||
foreach (var rowData in data.TableData)
|
||||
{
|
||||
Row newrow = table.AddRow();
|
||||
int i = 0;
|
||||
foreach (var column in data.Props)
|
||||
{
|
||||
try
|
||||
{
|
||||
object cellValue = typeof(T).GetProperty(column).GetValue(rowData);
|
||||
string cellText = cellValue?.ToString() ?? string.Empty;
|
||||
newrow.Cells[i].AddParagraph(cellText);
|
||||
++i;
|
||||
}
|
||||
catch { }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -7,4 +7,10 @@
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="OxyPlot.Core" Version="2.1.2" />
|
||||
<PackageReference Include="OxyPlot.WindowsForms" Version="2.1.2" />
|
||||
<PackageReference Include="PdfSharp.MigraDoc.Standard" Version="1.51.15" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
Loading…
Reference in New Issue
Block a user