Первый компонентик есть ^.^
This commit is contained in:
parent
d8ad4d290a
commit
2caa860fb5
@ -7,4 +7,8 @@
|
|||||||
<ImplicitUsings>enable</ImplicitUsings>
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<PackageReference Include="PDFsharp-MigraDoc-GDI" Version="6.1.1" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
|
36
ComponentProgramming/ComponentProgramming/Components/testComp.Designer.cs
generated
Normal file
36
ComponentProgramming/ComponentProgramming/Components/testComp.Designer.cs
generated
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
namespace ComponentProgramming
|
||||||
|
{
|
||||||
|
partial class testComp
|
||||||
|
{
|
||||||
|
/// <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
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,67 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.ComponentModel;
|
||||||
|
using System.Diagnostics;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace ComponentProgramming
|
||||||
|
{
|
||||||
|
public partial class testComp : Component
|
||||||
|
{
|
||||||
|
|
||||||
|
private string _fileName;
|
||||||
|
|
||||||
|
public string FileName
|
||||||
|
{
|
||||||
|
set
|
||||||
|
{
|
||||||
|
if (string.IsNullOrEmpty(value)) return;
|
||||||
|
if (!value.EndsWith(".txt"))
|
||||||
|
{
|
||||||
|
throw new ArgumentException("No txt file");
|
||||||
|
}
|
||||||
|
_fileName = value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public testComp()
|
||||||
|
{
|
||||||
|
InitializeComponent();
|
||||||
|
_fileName = string.Empty;
|
||||||
|
}
|
||||||
|
|
||||||
|
public testComp(IContainer container)
|
||||||
|
{
|
||||||
|
container.Add(this);
|
||||||
|
|
||||||
|
InitializeComponent();
|
||||||
|
_fileName = string.Empty;
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool saveToFile(string[] texts)
|
||||||
|
{
|
||||||
|
CheckFileExist();
|
||||||
|
using var writer = new StreamWriter(_fileName, true);
|
||||||
|
foreach (var text in texts)
|
||||||
|
{
|
||||||
|
writer.WriteLine(text);
|
||||||
|
}
|
||||||
|
writer.Flush();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void CheckFileExist()
|
||||||
|
{
|
||||||
|
if (string.IsNullOrEmpty(_fileName))
|
||||||
|
{
|
||||||
|
throw new ArgumentNullException(_fileName);
|
||||||
|
}
|
||||||
|
if(!File.Exists("../"+_fileName))
|
||||||
|
{
|
||||||
|
throw new FileNotFoundException(_fileName);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -1,4 +1,4 @@
|
|||||||
using ComponentProgramming.Exceptions;
|
using ComponentProgramming.Control.Exceptions;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.ComponentModel;
|
using System.ComponentModel;
|
@ -4,7 +4,7 @@ using System.Linq;
|
|||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
namespace ComponentProgramming.Exceptions
|
namespace ComponentProgramming.Control.Exceptions
|
||||||
{
|
{
|
||||||
public class NumberException : Exception
|
public class NumberException : Exception
|
||||||
{
|
{
|
@ -4,7 +4,7 @@ using System.Linq;
|
|||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
namespace Forms
|
namespace ComponentProgramming.Control
|
||||||
{
|
{
|
||||||
public class Person
|
public class Person
|
||||||
{
|
{
|
||||||
@ -14,8 +14,8 @@ namespace Forms
|
|||||||
|
|
||||||
public Person() { }
|
public Person() { }
|
||||||
|
|
||||||
public Person(int id, string name, string surname)
|
public Person(int id, string name, string surname)
|
||||||
{
|
{
|
||||||
Name = name;
|
Name = name;
|
||||||
Id = id;
|
Id = id;
|
||||||
Surname = surname;
|
Surname = surname;
|
36
ComponentProgramming/ComponentProgramming/LargeTextComponent.Designer.cs
generated
Normal file
36
ComponentProgramming/ComponentProgramming/LargeTextComponent.Designer.cs
generated
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
namespace ComponentProgramming.Components
|
||||||
|
{
|
||||||
|
partial class LargeTextComponent
|
||||||
|
{
|
||||||
|
/// <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
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,63 @@
|
|||||||
|
using System.ComponentModel;
|
||||||
|
using MigraDoc.DocumentObjectModel;
|
||||||
|
using MigraDoc.DocumentObjectModel.Tables;
|
||||||
|
using MigraDoc.Rendering;
|
||||||
|
|
||||||
|
namespace ComponentProgramming.Components
|
||||||
|
{
|
||||||
|
public partial class LargeTextComponent : Component
|
||||||
|
{
|
||||||
|
|
||||||
|
private Document? _document;
|
||||||
|
|
||||||
|
private Section? _section;
|
||||||
|
|
||||||
|
public LargeTextComponent()
|
||||||
|
{
|
||||||
|
InitializeComponent();
|
||||||
|
}
|
||||||
|
|
||||||
|
public LargeTextComponent(IContainer container)
|
||||||
|
{
|
||||||
|
container.Add(this);
|
||||||
|
|
||||||
|
InitializeComponent();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void CreateDocument(string docPath, string title, string[] rows)
|
||||||
|
{
|
||||||
|
if(string.IsNullOrEmpty(docPath))
|
||||||
|
{
|
||||||
|
throw new ArgumentNullException("Введите путь до файла!");
|
||||||
|
}
|
||||||
|
if(string.IsNullOrEmpty(title))
|
||||||
|
{
|
||||||
|
throw new ArgumentNullException("Введите заголовок");
|
||||||
|
}
|
||||||
|
if(rows.Length <= 0)
|
||||||
|
{
|
||||||
|
throw new ArgumentNullException("Нету данных для сохранения");
|
||||||
|
}
|
||||||
|
|
||||||
|
_document = new Document();
|
||||||
|
var style = _document.Styles["Normal"];
|
||||||
|
style.Font.Name = "Times New Roman";
|
||||||
|
style.Font.Size = 14;
|
||||||
|
|
||||||
|
_section = _document.AddSection();
|
||||||
|
|
||||||
|
var paragraph = _section.AddParagraph(title);
|
||||||
|
paragraph.Format.SpaceAfter = "0.1cm";
|
||||||
|
paragraph.Format.Font.Bold = true;
|
||||||
|
foreach (var row in rows)
|
||||||
|
{
|
||||||
|
_section.AddParagraph(row);
|
||||||
|
}
|
||||||
|
|
||||||
|
var renderer = new PdfDocumentRenderer(true);
|
||||||
|
renderer.Document = _document;
|
||||||
|
renderer.RenderDocument();
|
||||||
|
renderer.PdfDocument.Save(docPath);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
36
ComponentProgramming/Forms/Form.Designer.cs
generated
36
ComponentProgramming/Forms/Form.Designer.cs
generated
@ -28,13 +28,13 @@
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
private void InitializeComponent()
|
private void InitializeComponent()
|
||||||
{
|
{
|
||||||
|
components = new System.ComponentModel.Container();
|
||||||
controlComboBox = new ComponentProgramming.ControlComboBox();
|
controlComboBox = new ComponentProgramming.ControlComboBox();
|
||||||
controlTextBox = new ComponentProgramming.ControlTextBox();
|
controlTextBox = new ComponentProgramming.ControlTextBox();
|
||||||
buttonGetObj = new Button();
|
buttonGetObj = new Button();
|
||||||
buttonClear = new Button();
|
|
||||||
buttonEnter = new Button();
|
buttonEnter = new Button();
|
||||||
buttonAdd = new Button();
|
|
||||||
controlListBox = new ComponentProgramming.ControlListBox();
|
controlListBox = new ComponentProgramming.ControlListBox();
|
||||||
|
largeTextComponent = new ComponentProgramming.Components.LargeTextComponent(components);
|
||||||
SuspendLayout();
|
SuspendLayout();
|
||||||
//
|
//
|
||||||
// controlComboBox
|
// controlComboBox
|
||||||
@ -58,7 +58,7 @@
|
|||||||
//
|
//
|
||||||
// buttonGetObj
|
// buttonGetObj
|
||||||
//
|
//
|
||||||
buttonGetObj.Location = new Point(23, 415);
|
buttonGetObj.Location = new Point(12, 415);
|
||||||
buttonGetObj.Name = "buttonGetObj";
|
buttonGetObj.Name = "buttonGetObj";
|
||||||
buttonGetObj.Size = new Size(126, 23);
|
buttonGetObj.Size = new Size(126, 23);
|
||||||
buttonGetObj.TabIndex = 3;
|
buttonGetObj.TabIndex = 3;
|
||||||
@ -66,16 +66,6 @@
|
|||||||
buttonGetObj.UseVisualStyleBackColor = true;
|
buttonGetObj.UseVisualStyleBackColor = true;
|
||||||
buttonGetObj.Click += buttonGetObj_Click;
|
buttonGetObj.Click += buttonGetObj_Click;
|
||||||
//
|
//
|
||||||
// buttonClear
|
|
||||||
//
|
|
||||||
buttonClear.Location = new Point(654, 415);
|
|
||||||
buttonClear.Name = "buttonClear";
|
|
||||||
buttonClear.Size = new Size(134, 26);
|
|
||||||
buttonClear.TabIndex = 4;
|
|
||||||
buttonClear.Text = "Очистить объекты";
|
|
||||||
buttonClear.UseVisualStyleBackColor = true;
|
|
||||||
buttonClear.Click += buttonClear_Click;
|
|
||||||
//
|
|
||||||
// buttonEnter
|
// buttonEnter
|
||||||
//
|
//
|
||||||
buttonEnter.Location = new Point(272, 36);
|
buttonEnter.Location = new Point(272, 36);
|
||||||
@ -87,34 +77,21 @@
|
|||||||
buttonEnter.UseVisualStyleBackColor = true;
|
buttonEnter.UseVisualStyleBackColor = true;
|
||||||
buttonEnter.Click += buttonEnter_Click;
|
buttonEnter.Click += buttonEnter_Click;
|
||||||
//
|
//
|
||||||
// buttonAdd
|
|
||||||
//
|
|
||||||
buttonAdd.Location = new Point(331, 415);
|
|
||||||
buttonAdd.Margin = new Padding(3, 2, 3, 2);
|
|
||||||
buttonAdd.Name = "buttonAdd";
|
|
||||||
buttonAdd.Size = new Size(147, 23);
|
|
||||||
buttonAdd.TabIndex = 6;
|
|
||||||
buttonAdd.Text = "Добавить значение";
|
|
||||||
buttonAdd.UseVisualStyleBackColor = true;
|
|
||||||
buttonAdd.Click += buttonAdd_Click;
|
|
||||||
//
|
|
||||||
// controlListBox
|
// controlListBox
|
||||||
//
|
//
|
||||||
controlListBox.GetIndex = -1;
|
controlListBox.GetIndex = -1;
|
||||||
controlListBox.Location = new Point(12, 65);
|
controlListBox.Location = new Point(12, 65);
|
||||||
controlListBox.Name = "controlListBox";
|
controlListBox.Name = "controlListBox";
|
||||||
controlListBox.Size = new Size(776, 344);
|
controlListBox.Size = new Size(334, 344);
|
||||||
controlListBox.TabIndex = 7;
|
controlListBox.TabIndex = 7;
|
||||||
//
|
//
|
||||||
// Form
|
// Form
|
||||||
//
|
//
|
||||||
AutoScaleDimensions = new SizeF(7F, 15F);
|
AutoScaleDimensions = new SizeF(7F, 15F);
|
||||||
AutoScaleMode = AutoScaleMode.Font;
|
AutoScaleMode = AutoScaleMode.Font;
|
||||||
ClientSize = new Size(800, 450);
|
ClientSize = new Size(759, 450);
|
||||||
Controls.Add(controlListBox);
|
Controls.Add(controlListBox);
|
||||||
Controls.Add(buttonAdd);
|
|
||||||
Controls.Add(buttonEnter);
|
Controls.Add(buttonEnter);
|
||||||
Controls.Add(buttonClear);
|
|
||||||
Controls.Add(buttonGetObj);
|
Controls.Add(buttonGetObj);
|
||||||
Controls.Add(controlTextBox);
|
Controls.Add(controlTextBox);
|
||||||
Controls.Add(controlComboBox);
|
Controls.Add(controlComboBox);
|
||||||
@ -129,9 +106,8 @@
|
|||||||
private ComponentProgramming.ControlComboBox controlComboBox;
|
private ComponentProgramming.ControlComboBox controlComboBox;
|
||||||
private ComponentProgramming.ControlTextBox controlTextBox;
|
private ComponentProgramming.ControlTextBox controlTextBox;
|
||||||
private Button buttonGetObj;
|
private Button buttonGetObj;
|
||||||
private Button buttonClear;
|
|
||||||
private Button buttonEnter;
|
private Button buttonEnter;
|
||||||
private Button buttonAdd;
|
|
||||||
private ComponentProgramming.ControlListBox controlListBox;
|
private ComponentProgramming.ControlListBox controlListBox;
|
||||||
|
private ComponentProgramming.Components.LargeTextComponent largeTextComponent;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -8,6 +8,8 @@ namespace Forms
|
|||||||
FillBox();
|
FillBox();
|
||||||
FillTextBox();
|
FillTextBox();
|
||||||
FillList();
|
FillList();
|
||||||
|
string[] strings = new string[] { "У компонента должен быть публичный метод, который должен принимать на вход имя файла (включая путь до файла)", "название документа (заголовок в документе) и массив строк (каждая строка – абзац текста в выходном документе или текст в ячейке для табличного документа)" };
|
||||||
|
largeTextComponent.CreateDocument("C:\\Users\\shotb\\source\\repos\\KOP\\ComponentProgramming\\Forms\\text.pdf", "Заголовок", strings);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void FillBox()
|
private void FillBox()
|
||||||
@ -53,21 +55,10 @@ namespace Forms
|
|||||||
var obj = controlListBox.GetSelectedObject<Person>();
|
var obj = controlListBox.GetSelectedObject<Person>();
|
||||||
MessageBox.Show($"{obj.Name} {obj.Surname}");
|
MessageBox.Show($"{obj.Name} {obj.Surname}");
|
||||||
}
|
}
|
||||||
|
|
||||||
private void buttonClear_Click(object sender, EventArgs e)
|
|
||||||
{
|
|
||||||
//controlDataGrid.ClearData();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void buttonEnter_Click(object sender, EventArgs e)
|
private void buttonEnter_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
var val = controlTextBox.text;
|
var val = controlTextBox.text;
|
||||||
MessageBox.Show($"Ââåäåíî {val}");
|
MessageBox.Show($"Ââåäåíî {val}");
|
||||||
}
|
}
|
||||||
|
|
||||||
private void buttonAdd_Click(object sender, EventArgs e)
|
|
||||||
{
|
|
||||||
//controlDataGrid.SetData<Person>(new Person(1, "asdasdas", "asdasd1asd"), 2, 3);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -117,4 +117,7 @@
|
|||||||
<resheader name="writer">
|
<resheader name="writer">
|
||||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||||
</resheader>
|
</resheader>
|
||||||
|
<metadata name="largeTextComponent.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
|
||||||
|
<value>17, 17</value>
|
||||||
|
</metadata>
|
||||||
</root>
|
</root>
|
@ -8,6 +8,10 @@
|
|||||||
<ImplicitUsings>enable</ImplicitUsings>
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<PackageReference Include="PDFsharp-MigraDoc-GDI" Version="6.1.1" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ProjectReference Include="..\ComponentProgramming\ComponentProgramming.csproj" />
|
<ProjectReference Include="..\ComponentProgramming\ComponentProgramming.csproj" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
BIN
ComponentProgramming/Forms/text.pdf
Normal file
BIN
ComponentProgramming/Forms/text.pdf
Normal file
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user