1 Commits

Author SHA1 Message Date
Alenka
6408057918 Почти doneeee 2024-09-12 00:38:58 +04:00
34 changed files with 2933 additions and 0 deletions

View File

@@ -0,0 +1,25 @@
<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>
<PackageReference Include="DocumentFormat.OpenXml" Version="2.20.0" />
<PackageReference Include="Microsoft.Win32.SystemEvents" Version="7.0.0" />
<PackageReference Include="PdfSharp.MigraDoc.Standard" Version="1.51.15" />
<PackageReference Include="PdfSharp.MigraDoc.Standard.DocumentObjectModel" Version="1.51.15" />
<PackageReference Include="PDFSharp.Standard" Version="1.51.15" />
<PackageReference Include="PDFSharp.Standard.Charting" Version="1.51.15" />
<PackageReference Include="System.Drawing.Common" Version="7.0.0" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\MyCustomComponents\MyCustomComponents.csproj" />
</ItemGroup>
</Project>

View File

@@ -0,0 +1,434 @@
namespace DesktopWithMyVisualComponents
{
partial class FormMain
{
/// <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.customInputRangeNumber = new MyCustomComponents.CustomInputRangeNumber();
this.buttonCheck = new System.Windows.Forms.Button();
this.labelCheckValue = new System.Windows.Forms.Label();
this.groupBoxInput = new System.Windows.Forms.GroupBox();
this.groupBoxSelected = new System.Windows.Forms.GroupBox();
this.buttonGetSelected = new System.Windows.Forms.Button();
this.labelSelectedValue = new System.Windows.Forms.Label();
this.buttonClear = new System.Windows.Forms.Button();
this.buttonAdd = new System.Windows.Forms.Button();
this.textBoxAdd = new System.Windows.Forms.TextBox();
this.customSelectedCheckedListBoxProperty = new MyCustomComponents.CustomSelectedCheckedListBoxProperty();
this.groupBoxData = new System.Windows.Forms.GroupBox();
this.labelTransportType = new System.Windows.Forms.Label();
this.labelModel = new System.Windows.Forms.Label();
this.labelRegNum = new System.Windows.Forms.Label();
this.buttonGetFromTree = new System.Windows.Forms.Button();
this.buttonAddToTree = new System.Windows.Forms.Button();
this.comboBoxTransportType = new System.Windows.Forms.ComboBox();
this.textBoxModel = new System.Windows.Forms.TextBox();
this.textBoxRegNumber = new System.Windows.Forms.TextBox();
this.customTreeCell = new MyCustomComponents.CustomTreeCell();
this.tabControl = new System.Windows.Forms.TabControl();
this.Visual = new System.Windows.Forms.TabPage();
this.Docs = new System.Windows.Forms.TabPage();
this.buttonWordWithDiagram = new System.Windows.Forms.Button();
this.buttonWordWithTable = new System.Windows.Forms.Button();
this.buttonWordWithImage = new System.Windows.Forms.Button();
this.wordWithImages = new MyCustomComponents.WordWithImages(this.components);
this.wordWithTable = new MyCustomComponents.WordWithTable(this.components);
this.wordWithDiagram = new MyCustomComponents.WordWithDiagram(this.components);
this.groupBoxInput.SuspendLayout();
this.groupBoxSelected.SuspendLayout();
this.groupBoxData.SuspendLayout();
this.tabControl.SuspendLayout();
this.Visual.SuspendLayout();
this.Docs.SuspendLayout();
this.SuspendLayout();
//
// customInputRangeNumber
//
this.customInputRangeNumber.AutoValidate = System.Windows.Forms.AutoValidate.Disable;
this.customInputRangeNumber.CausesValidation = false;
this.customInputRangeNumber.Location = new System.Drawing.Point(34, 25);
this.customInputRangeNumber.Margin = new System.Windows.Forms.Padding(3, 5, 3, 5);
this.customInputRangeNumber.MaxValue = new decimal(new int[] {
-1,
-1,
-1,
0});
this.customInputRangeNumber.MinValue = new decimal(new int[] {
-1,
-1,
-1,
-2147483648});
this.customInputRangeNumber.Name = "customInputRangeNumber";
this.customInputRangeNumber.Size = new System.Drawing.Size(144, 40);
this.customInputRangeNumber.TabIndex = 0;
this.customInputRangeNumber.Value = new decimal(new int[] {
0,
0,
0,
0});
//
// buttonCheck
//
this.buttonCheck.Location = new System.Drawing.Point(193, 29);
this.buttonCheck.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
this.buttonCheck.Name = "buttonCheck";
this.buttonCheck.Size = new System.Drawing.Size(144, 31);
this.buttonCheck.TabIndex = 1;
this.buttonCheck.Text = "Check";
this.buttonCheck.UseVisualStyleBackColor = true;
this.buttonCheck.Click += new System.EventHandler(this.buttonCheck_Click);
//
// labelCheckValue
//
this.labelCheckValue.AutoSize = true;
this.labelCheckValue.Location = new System.Drawing.Point(34, 148);
this.labelCheckValue.Name = "labelCheckValue";
this.labelCheckValue.Size = new System.Drawing.Size(82, 20);
this.labelCheckValue.TabIndex = 2;
this.labelCheckValue.Text = "Enter value";
//
// groupBoxInput
//
this.groupBoxInput.Controls.Add(this.customInputRangeNumber);
this.groupBoxInput.Controls.Add(this.labelCheckValue);
this.groupBoxInput.Controls.Add(this.buttonCheck);
this.groupBoxInput.Location = new System.Drawing.Point(7, 8);
this.groupBoxInput.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
this.groupBoxInput.Name = "groupBoxInput";
this.groupBoxInput.Padding = new System.Windows.Forms.Padding(3, 4, 3, 4);
this.groupBoxInput.Size = new System.Drawing.Size(355, 253);
this.groupBoxInput.TabIndex = 9;
this.groupBoxInput.TabStop = false;
this.groupBoxInput.Text = "Input";
//
// groupBoxSelected
//
this.groupBoxSelected.Controls.Add(this.buttonGetSelected);
this.groupBoxSelected.Controls.Add(this.labelSelectedValue);
this.groupBoxSelected.Controls.Add(this.buttonClear);
this.groupBoxSelected.Controls.Add(this.buttonAdd);
this.groupBoxSelected.Controls.Add(this.textBoxAdd);
this.groupBoxSelected.Controls.Add(this.customSelectedCheckedListBoxProperty);
this.groupBoxSelected.Location = new System.Drawing.Point(370, 8);
this.groupBoxSelected.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
this.groupBoxSelected.Name = "groupBoxSelected";
this.groupBoxSelected.Padding = new System.Windows.Forms.Padding(3, 4, 3, 4);
this.groupBoxSelected.Size = new System.Drawing.Size(355, 253);
this.groupBoxSelected.TabIndex = 10;
this.groupBoxSelected.TabStop = false;
this.groupBoxSelected.Text = "Selected";
//
// buttonGetSelected
//
this.buttonGetSelected.Location = new System.Drawing.Point(219, 192);
this.buttonGetSelected.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
this.buttonGetSelected.Name = "buttonGetSelected";
this.buttonGetSelected.Size = new System.Drawing.Size(114, 31);
this.buttonGetSelected.TabIndex = 14;
this.buttonGetSelected.Text = "Get Selected";
this.buttonGetSelected.UseVisualStyleBackColor = true;
this.buttonGetSelected.Click += new System.EventHandler(this.buttonGetSelected_Click);
//
// labelSelectedValue
//
this.labelSelectedValue.AutoSize = true;
this.labelSelectedValue.Location = new System.Drawing.Point(219, 148);
this.labelSelectedValue.Name = "labelSelectedValue";
this.labelSelectedValue.Size = new System.Drawing.Size(105, 20);
this.labelSelectedValue.TabIndex = 11;
this.labelSelectedValue.Text = "Selected value";
//
// buttonClear
//
this.buttonClear.Location = new System.Drawing.Point(219, 108);
this.buttonClear.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
this.buttonClear.Name = "buttonClear";
this.buttonClear.Size = new System.Drawing.Size(114, 31);
this.buttonClear.TabIndex = 13;
this.buttonClear.Text = "Clear";
this.buttonClear.UseVisualStyleBackColor = true;
this.buttonClear.Click += new System.EventHandler(this.buttonClear_Click);
//
// buttonAdd
//
this.buttonAdd.Location = new System.Drawing.Point(219, 69);
this.buttonAdd.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
this.buttonAdd.Name = "buttonAdd";
this.buttonAdd.Size = new System.Drawing.Size(114, 31);
this.buttonAdd.TabIndex = 12;
this.buttonAdd.Text = "Add or Select";
this.buttonAdd.UseVisualStyleBackColor = true;
this.buttonAdd.Click += new System.EventHandler(this.buttonAdd_Click);
//
// textBoxAdd
//
this.textBoxAdd.Location = new System.Drawing.Point(219, 31);
this.textBoxAdd.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
this.textBoxAdd.Name = "textBoxAdd";
this.textBoxAdd.Size = new System.Drawing.Size(114, 27);
this.textBoxAdd.TabIndex = 11;
//
// customSelectedCheckedListBoxProperty
//
this.customSelectedCheckedListBoxProperty.Location = new System.Drawing.Point(41, 25);
this.customSelectedCheckedListBoxProperty.Margin = new System.Windows.Forms.Padding(3, 5, 3, 5);
this.customSelectedCheckedListBoxProperty.Name = "customSelectedCheckedListBoxProperty";
this.customSelectedCheckedListBoxProperty.SelectedElement = "";
this.customSelectedCheckedListBoxProperty.Size = new System.Drawing.Size(171, 209);
this.customSelectedCheckedListBoxProperty.TabIndex = 0;
//
// groupBoxData
//
this.groupBoxData.Controls.Add(this.labelTransportType);
this.groupBoxData.Controls.Add(this.labelModel);
this.groupBoxData.Controls.Add(this.labelRegNum);
this.groupBoxData.Controls.Add(this.buttonGetFromTree);
this.groupBoxData.Controls.Add(this.buttonAddToTree);
this.groupBoxData.Controls.Add(this.comboBoxTransportType);
this.groupBoxData.Controls.Add(this.textBoxModel);
this.groupBoxData.Controls.Add(this.textBoxRegNumber);
this.groupBoxData.Controls.Add(this.customTreeCell);
this.groupBoxData.Location = new System.Drawing.Point(7, 269);
this.groupBoxData.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
this.groupBoxData.Name = "groupBoxData";
this.groupBoxData.Padding = new System.Windows.Forms.Padding(3, 4, 3, 4);
this.groupBoxData.Size = new System.Drawing.Size(719, 307);
this.groupBoxData.TabIndex = 11;
this.groupBoxData.TabStop = false;
this.groupBoxData.Text = "Data";
//
// labelTransportType
//
this.labelTransportType.AutoSize = true;
this.labelTransportType.Location = new System.Drawing.Point(494, 155);
this.labelTransportType.Name = "labelTransportType";
this.labelTransportType.Size = new System.Drawing.Size(119, 20);
this.labelTransportType.TabIndex = 8;
this.labelTransportType.Text = "Тип транспорта";
//
// labelModel
//
this.labelModel.AutoSize = true;
this.labelModel.Location = new System.Drawing.Point(494, 96);
this.labelModel.Name = "labelModel";
this.labelModel.Size = new System.Drawing.Size(63, 20);
this.labelModel.TabIndex = 7;
this.labelModel.Text = "Модель";
//
// labelRegNum
//
this.labelRegNum.AutoSize = true;
this.labelRegNum.Location = new System.Drawing.Point(494, 37);
this.labelRegNum.Name = "labelRegNum";
this.labelRegNum.Size = new System.Drawing.Size(185, 20);
this.labelRegNum.TabIndex = 6;
this.labelRegNum.Text = "Регистрационный номер";
//
// buttonGetFromTree
//
this.buttonGetFromTree.Location = new System.Drawing.Point(494, 260);
this.buttonGetFromTree.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
this.buttonGetFromTree.Name = "buttonGetFromTree";
this.buttonGetFromTree.Size = new System.Drawing.Size(215, 31);
this.buttonGetFromTree.TabIndex = 5;
this.buttonGetFromTree.Text = "Get Selected";
this.buttonGetFromTree.UseVisualStyleBackColor = true;
this.buttonGetFromTree.Click += new System.EventHandler(this.buttonGetFromTree_Click);
//
// buttonAddToTree
//
this.buttonAddToTree.Location = new System.Drawing.Point(494, 221);
this.buttonAddToTree.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
this.buttonAddToTree.Name = "buttonAddToTree";
this.buttonAddToTree.Size = new System.Drawing.Size(215, 31);
this.buttonAddToTree.TabIndex = 4;
this.buttonAddToTree.Text = "Add";
this.buttonAddToTree.UseVisualStyleBackColor = true;
this.buttonAddToTree.Click += new System.EventHandler(this.buttonAddToTree_Click);
//
// comboBoxTransportType
//
this.comboBoxTransportType.FormattingEnabled = true;
this.comboBoxTransportType.Location = new System.Drawing.Point(494, 179);
this.comboBoxTransportType.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
this.comboBoxTransportType.Name = "comboBoxTransportType";
this.comboBoxTransportType.Size = new System.Drawing.Size(214, 28);
this.comboBoxTransportType.TabIndex = 3;
//
// textBoxModel
//
this.textBoxModel.Location = new System.Drawing.Point(494, 120);
this.textBoxModel.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
this.textBoxModel.Name = "textBoxModel";
this.textBoxModel.Size = new System.Drawing.Size(214, 27);
this.textBoxModel.TabIndex = 2;
//
// textBoxRegNumber
//
this.textBoxRegNumber.Location = new System.Drawing.Point(494, 61);
this.textBoxRegNumber.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
this.textBoxRegNumber.Name = "textBoxRegNumber";
this.textBoxRegNumber.Size = new System.Drawing.Size(214, 27);
this.textBoxRegNumber.TabIndex = 1;
//
// customTreeCell
//
this.customTreeCell.Location = new System.Drawing.Point(17, 29);
this.customTreeCell.Margin = new System.Windows.Forms.Padding(3, 5, 3, 5);
this.customTreeCell.Name = "customTreeCell";
this.customTreeCell.Size = new System.Drawing.Size(455, 269);
this.customTreeCell.TabIndex = 0;
//
// tabControl
//
this.tabControl.Controls.Add(this.Visual);
this.tabControl.Controls.Add(this.Docs);
this.tabControl.Location = new System.Drawing.Point(14, 16);
this.tabControl.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
this.tabControl.Name = "tabControl";
this.tabControl.SelectedIndex = 0;
this.tabControl.Size = new System.Drawing.Size(746, 621);
this.tabControl.TabIndex = 12;
//
// Visual
//
this.Visual.Controls.Add(this.groupBoxData);
this.Visual.Controls.Add(this.groupBoxInput);
this.Visual.Controls.Add(this.groupBoxSelected);
this.Visual.Location = new System.Drawing.Point(4, 29);
this.Visual.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
this.Visual.Name = "Visual";
this.Visual.Padding = new System.Windows.Forms.Padding(3, 4, 3, 4);
this.Visual.Size = new System.Drawing.Size(738, 588);
this.Visual.TabIndex = 0;
this.Visual.Text = "Visual";
this.Visual.UseVisualStyleBackColor = true;
//
// Docs
//
this.Docs.Controls.Add(this.buttonWordWithDiagram);
this.Docs.Controls.Add(this.buttonWordWithTable);
this.Docs.Controls.Add(this.buttonWordWithImage);
this.Docs.Location = new System.Drawing.Point(4, 29);
this.Docs.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
this.Docs.Name = "Docs";
this.Docs.Padding = new System.Windows.Forms.Padding(3, 4, 3, 4);
this.Docs.Size = new System.Drawing.Size(738, 588);
this.Docs.TabIndex = 1;
this.Docs.Text = "Docs";
this.Docs.UseVisualStyleBackColor = true;
//
// buttonWordWithDiagram
//
this.buttonWordWithDiagram.Location = new System.Drawing.Point(490, 223);
this.buttonWordWithDiagram.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
this.buttonWordWithDiagram.Name = "buttonWordWithDiagram";
this.buttonWordWithDiagram.Size = new System.Drawing.Size(227, 97);
this.buttonWordWithDiagram.TabIndex = 13;
this.buttonWordWithDiagram.Text = "Word With Diagram";
this.buttonWordWithDiagram.UseVisualStyleBackColor = true;
this.buttonWordWithDiagram.Click += new System.EventHandler(this.buttonWordWithDiagram_Click);
//
// buttonWordWithTable
//
this.buttonWordWithTable.Location = new System.Drawing.Point(256, 223);
this.buttonWordWithTable.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
this.buttonWordWithTable.Name = "buttonWordWithTable";
this.buttonWordWithTable.Size = new System.Drawing.Size(227, 97);
this.buttonWordWithTable.TabIndex = 14;
this.buttonWordWithTable.Text = "Word With Table";
this.buttonWordWithTable.UseVisualStyleBackColor = true;
this.buttonWordWithTable.Click += new System.EventHandler(this.buttonWordWithTable_Click);
//
// buttonWordWithImage
//
this.buttonWordWithImage.Location = new System.Drawing.Point(22, 223);
this.buttonWordWithImage.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
this.buttonWordWithImage.Name = "buttonWordWithImage";
this.buttonWordWithImage.Size = new System.Drawing.Size(227, 97);
this.buttonWordWithImage.TabIndex = 13;
this.buttonWordWithImage.Text = "Word With Image";
this.buttonWordWithImage.UseVisualStyleBackColor = true;
this.buttonWordWithImage.Click += new System.EventHandler(this.buttonWordWithImage_Click);
//
// FormMain
//
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(771, 648);
this.Controls.Add(this.tabControl);
this.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
this.Name = "FormMain";
this.Text = "FormMain";
this.groupBoxInput.ResumeLayout(false);
this.groupBoxInput.PerformLayout();
this.groupBoxSelected.ResumeLayout(false);
this.groupBoxSelected.PerformLayout();
this.groupBoxData.ResumeLayout(false);
this.groupBoxData.PerformLayout();
this.tabControl.ResumeLayout(false);
this.Visual.ResumeLayout(false);
this.Docs.ResumeLayout(false);
this.ResumeLayout(false);
}
#endregion
private MyCustomComponents.CustomInputRangeNumber customInputRangeNumber;
private Button buttonCheck;
private Label labelCheckValue;
private GroupBox groupBoxInput;
private GroupBox groupBoxSelected;
private Button buttonGetSelected;
private Label labelSelectedValue;
private Button buttonClear;
private Button buttonAdd;
private TextBox textBoxAdd;
private MyCustomComponents.CustomSelectedCheckedListBoxProperty customSelectedCheckedListBoxProperty;
private GroupBox groupBoxData;
private MyCustomComponents.CustomTreeCell customTreeCell;
private Button buttonGetFromTree;
private Button buttonAddToTree;
private ComboBox comboBoxTransportType;
private TextBox textBoxModel;
private TextBox textBoxRegNumber;
private Label labelTransportType;
private Label labelModel;
private Label labelRegNum;
private TabControl tabControl;
private TabPage Visual;
private TabPage Docs;
private Button buttonWordWithImage;
private MyCustomComponents.WordWithImages wordWithImages;
private Button buttonWordWithTable;
private MyCustomComponents.WordWithTable wordWithTable;
private Button buttonWordWithDiagram;
private MyCustomComponents.WordWithDiagram wordWithDiagram;
}
}

View File

@@ -0,0 +1,204 @@
using MyCustomComponents;
using MyCustomComponents.Models;
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 DesktopWithMyVisualComponents
{
public partial class FormMain : Form
{
readonly List<Transport> transports = new()
{
new Transport { Id = 1, Fuel="Авиакеросин", Mileage=239000, Owner="Аэрофлот", Price=70000000, State="Эксплуатируется", RegNumber = "EW-009EC", TransportType = "Воздушный транспорт", Model = "Ан-30" },
new Transport { Id = 2, Fuel="Авиакеросин", Mileage=452005, Owner="Азимут", Price=95000000, State="Не эксплуатируется", RegNumber = "EW-987ZY", TransportType = "Воздушный транспорт", Model = "Ан-28" },
new Transport { Id = 3, Fuel="Мазут", Mileage=790222, Owner="ВМФ США", Price=100000000, State="Эксплуатируется", RegNumber = "SSH-988", TransportType = "Морской транспорт", Model = "авианосец 'Нимиц'" },
new Transport { Id = 4, Fuel="92", Mileage=105777, Owner="Ползунова Татьяна Михайловна",State="Не эксплуатируется", Price=400000, RegNumber = "B901AУ74", TransportType = "Наземный транспорт", Model = "Renault Logan" },
new Transport { Id = 5, Fuel="Газ", Mileage=66782, Owner="Аветесян Сергей Георгиевич", State="Эксплуатируется", Price=160000, RegNumber = "Р187КН73", TransportType = "Наземный транспорт", Model = "Daewoo Matiz" },
};
public FormMain()
{
InitializeComponent();
var list = new List<string>() { "Значение 1", "Значение 2", "Значение 3", "Значение 4", "Значение 5" };
customSelectedCheckedListBoxProperty.Items.AddRange(list.ToArray());
comboBoxTransportType.Items.Add("Наземный транспорт");
comboBoxTransportType.Items.Add("Воздушный транспорт");
comboBoxTransportType.Items.Add("Морской транспорт");
var nodeNames = new Queue<string>();
nodeNames.Enqueue("TransportType");
nodeNames.Enqueue("Model");
nodeNames.Enqueue("RegNumber");
var treeConfig = new DataTreeNodeConfig { NodeNames = nodeNames };
customTreeCell.LoadConfig(treeConfig);
int counter = 0;
foreach (var transport in transports)
{
customTreeCell.AddCell(0, transport);
customTreeCell.AddCell(1, transport);
customTreeCell.AddCell(2, transport);
customTreeCell.AddCell(3, transport);
counter++;
}
}
private void buttonCheck_Click(object sender, EventArgs e)
{
labelCheckValue.Text = customInputRangeNumber.Value.ToString();
if (labelCheckValue.Text == "")
{
labelCheckValue.Text = customInputRangeNumber.Error;
}
}
private void buttonSetBorders_Click(object sender, EventArgs e)
{
/*if (!customInputRangeNumber.SetBorders(textBoxMin.Text, textBoxMax.Text))
{
labelCheckValue.Text = customInputRangeNumber.Error;
return;
}
labelCheckValue.Text = "Граница установлена";
customInputRangeNumber.SetBorders(textBoxMin.Text, textBoxMax.Text);*/
}
private void textBoxMin_KeyPress(object sender, KeyPressEventArgs e)
{
char ch = e.KeyChar;
if (!Char.IsDigit(ch) && ch != 8 && ch != 45)
{
e.Handled = true;
}
}
private void textBoxMax_KeyPress(object sender, KeyPressEventArgs e)
{
char ch = e.KeyChar;
if (!Char.IsDigit(ch) && ch != 8 && ch != 45)
{
e.Handled = true;
}
}
private void buttonAdd_Click(object sender, EventArgs e)
{
if (textBoxAdd.Text != "" && !customSelectedCheckedListBoxProperty.Items.Contains(textBoxAdd.Text))
customSelectedCheckedListBoxProperty.Items.Add(textBoxAdd.Text);
else if (customSelectedCheckedListBoxProperty.Items.Contains(textBoxAdd.Text))
customSelectedCheckedListBoxProperty.SelectedElement = textBoxAdd.Text;
}
private void buttonClear_Click(object sender, EventArgs e)
{
customSelectedCheckedListBoxProperty.Clear();
}
private void buttonGetSelected_Click(object sender, EventArgs e)
{
labelSelectedValue.Text = customSelectedCheckedListBoxProperty.SelectedElement;
if (labelSelectedValue.Text == "")
{
labelSelectedValue.Text = "Значение \nне выбрано";
}
}
private void buttonAddToTree_Click(object sender, EventArgs e)
{
if (textBoxRegNumber.Text == null || textBoxModel.Text == null || comboBoxTransportType.SelectedItem == null)
{
return;
}
customTreeCell.AddCell<Transport>(2, new(textBoxRegNumber.Text, comboBoxTransportType.SelectedItem.ToString(), textBoxModel.Text));
customTreeCell.Update();
}
private void buttonGetFromTree_Click(object sender, EventArgs e)
{
Transport tp = customTreeCell.GetSelectedObject<Transport>();
if (tp == null)
{
return;
}
textBoxRegNumber.Text = tp.RegNumber;
textBoxModel.Text = tp.Model;
comboBoxTransportType.SelectedItem = tp.TransportType;
}
private void buttonWordWithImage_Click(object sender, EventArgs e)
{
var openFileDialog = new OpenFileDialog();
bool flag = true;
var images = new List<byte[]>();
while (flag)
{
if (openFileDialog.ShowDialog() == DialogResult.OK)
{
images.Add(File.ReadAllBytes(openFileDialog.FileName));
}
else
{
flag = false;
}
}
wordWithImages.CreateDoc(new WordWithImageConfig
{
FilePath = "WordWithImageDocx.docx",
Header = "Картинки:",
Images = images
});
}
private void buttonWordWithTable_Click(object sender, EventArgs e)
{
wordWithTable.CreateDoc(new WordWithTableDataConfig<Transport>
{
FilePath = "WordWithTableDocx.docx",
Header = "Таблица:",
UseUnion = true,
ColumnsRowsWidth = new List<(int, int)> { (0, 5), (0, 5), (0, 10), (0, 10), (0, 7), (0, 7), (0, 10), (0, 10), (0, 8) },
ColumnUnion = new List<(int StartIndex, int Count)> { (2, 3), (5, 3) },
Headers = new List<(int ColumnIndex, int RowIndex, string Header, string PropertyName)>
{
(0, 0, "Номер", "Id"),
(1, 0, "Статус", "State"),
(2, 0, "Личные данные", ""),
(2, 1, "Регистрационный номер", "RegNumber"),
(3, 1, "Пробег", "Mileage"),
(4, 1, "Владелец", "Owner"),
(5, 0, "Общие данные", ""),
(5, 1, "Топливо", "Fuel"),
(6, 1, "Тип транспорта", "TransportType"),
(7, 1, "Модель", "Model"),
(8, 0, "Стоимость", "Price"),
},
Data = transports
});
}
private void buttonWordWithDiagram_Click(object sender, EventArgs e)
{
wordWithDiagram.CreateDoc(new WordWithDiagramConfig
{
FilePath = "WordWithDiagramDocx.docx",
Header = "Диаграмма",
ChartTitle = "Круговая диаграмма",
LegendLocation = MyCustomComponents.Models.Location.Bottom,
Data = new Dictionary<string, List<(int Date, double Value)>>
{
{ "Серия 1", new List<(int Date, double Value)> { (1, 20), (2, 30), (3, 50) } }
}
});
}
}
}

View File

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

View File

@@ -0,0 +1,17 @@
namespace DesktopWithMyVisualComponents
{
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 FormMain());
}
}
}

View File

@@ -0,0 +1,37 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace DesktopWithMyVisualComponents
{
public class Transport
{
public int Id { get; set; }
public string RegNumber { get; set; }
public string State { get; set; }
public int Mileage { get; set; }
public int Price { get; set; }
public string TransportType { get; set; }
public string Model { get; set; }
public string Owner { get; set; }
public string Fuel { get; set; }
public Transport(string regNumber, string transportType, string model)
{
RegNumber = regNumber;
TransportType = transportType;
Model = model;
}
public Transport() { }
}
}

31
KOP/Lab_Panina.sln Normal file
View File

@@ -0,0 +1,31 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.3.32825.248
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MyCustomComponents", "MyCustomComponents\MyCustomComponents.csproj", "{5BE962EA-6280-48C0-A67A-3BD08482991D}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DesktopWithMyVisualComponents", "DesktopWithMyVisualComponents\DesktopWithMyVisualComponents.csproj", "{27626D80-816E-49A2-8401-FA84D3F757EE}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{5BE962EA-6280-48C0-A67A-3BD08482991D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{5BE962EA-6280-48C0-A67A-3BD08482991D}.Debug|Any CPU.Build.0 = Debug|Any CPU
{5BE962EA-6280-48C0-A67A-3BD08482991D}.Release|Any CPU.ActiveCfg = Release|Any CPU
{5BE962EA-6280-48C0-A67A-3BD08482991D}.Release|Any CPU.Build.0 = Release|Any CPU
{27626D80-816E-49A2-8401-FA84D3F757EE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{27626D80-816E-49A2-8401-FA84D3F757EE}.Debug|Any CPU.Build.0 = Debug|Any CPU
{27626D80-816E-49A2-8401-FA84D3F757EE}.Release|Any CPU.ActiveCfg = Release|Any CPU
{27626D80-816E-49A2-8401-FA84D3F757EE}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {D7CBBD72-50DC-484F-BC0F-1BD3E3AA2A33}
EndGlobalSection
EndGlobal

View File

@@ -0,0 +1,83 @@
namespace MyCustomComponents
{
partial class CustomInputRangeNumber
{
/// <summary>
/// Обязательная переменная конструктора.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Освободить все используемые ресурсы.
/// </summary>
/// <param name="disposing">истинно, если управляемый ресурс должен быть удален; иначе ложно.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Код, автоматически созданный конструктором компонентов
/// <summary>
/// Требуемый метод для поддержки конструктора — не изменяйте
/// содержимое этого метода с помощью редактора кода.
/// </summary>
private void InitializeComponent()
{
this.numericUpDown = new System.Windows.Forms.NumericUpDown();
((System.ComponentModel.ISupportInitialize)(this.numericUpDown)).BeginInit();
this.SuspendLayout();
//
// numericUpDown
//
this.numericUpDown.BackColor = System.Drawing.Color.White;
this.numericUpDown.Increment = new decimal(new int[] {
5,
0,
0,
0});
this.numericUpDown.Location = new System.Drawing.Point(3, 3);
this.numericUpDown.Maximum = new decimal(new int[] {
536870912,
-1282231782,
-137,
0});
this.numericUpDown.Minimum = new decimal(new int[] {
536870912,
-1282231782,
-137,
-2147483648});
this.numericUpDown.Name = "numericUpDown";
this.numericUpDown.Size = new System.Drawing.Size(120, 23);
this.numericUpDown.TabIndex = 0;
this.numericUpDown.Value = new decimal(new int[] {
100,
0,
0,
0});
this.numericUpDown.ValueChanged += new System.EventHandler(this.numericUpDown_ValueChanged);
this.numericUpDown.Enter += new System.EventHandler(this.numericUpDown_Enter);
//
// CustomInputRangeNumber
//
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.AutoValidate = System.Windows.Forms.AutoValidate.Disable;
this.CausesValidation = false;
this.Controls.Add(this.numericUpDown);
this.Name = "CustomInputRangeNumber";
this.Size = new System.Drawing.Size(126, 30);
((System.ComponentModel.ISupportInitialize)(this.numericUpDown)).EndInit();
this.ResumeLayout(false);
}
#endregion
protected NumericUpDown numericUpDown;
}
}

View File

@@ -0,0 +1,95 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using System.Windows.Forms;
using static System.Windows.Forms.VisualStyles.VisualStyleElement;
using ToolTip = System.Windows.Forms.ToolTip;
namespace MyCustomComponents
{
public partial class CustomInputRangeNumber : UserControl
{
//Диапазон
private string example = "Введите значение от "+ decimal.MinValue + " до " + decimal.MaxValue;
//В случае ошибки
public string Error { get; protected set; } = string.Empty;
//2 публичных поля для настройки границ диапазона
public decimal? MinValue { get; set; }
public decimal? MaxValue { get; set; }
//Публичное свойство для установки и получения введенного значения(set, get). При получении проводиться проверка,
//если введенное значение не входит в диапазон, возвращать
//значение null, а в отдельное поле выводить текст ошибки.При
//установке должна проводиться проверка, если передаваемое
//значение не входит в диапазон, то не заполнять поле компонента.
public decimal? Value
{
get
{
if (MinValue == null || MaxValue == null)
{
Error = "Диапазон не задан";
return null;
}
if (numericUpDown.Value >= MinValue && numericUpDown.Value <= MaxValue)
{
return numericUpDown.Value;
}
Error = "Введенное значение" + " лежит \n вне диапазона " + MinValue + " - " + MaxValue;
return null;
}
set
{
if (MinValue == null || MaxValue == null)
{
Error = "Диапазон не задан";
}
if (value >= MinValue && value <= MaxValue && value.HasValue)
{
numericUpDown.Value = value.Value;
}
}
}
public CustomInputRangeNumber()
{
InitializeComponent();
}
private void numericUpDown_Enter(object sender, EventArgs e)
{
ToolTip tt = new ToolTip();
tt.Show(example, numericUpDown, 30, -20, 1000);
}
private void numericUpDown_ValueChanged(object sender, EventArgs e)
{
_changeEvent?.Invoke(sender, e);
}
private EventHandler _changeEvent;
//Cобытие, вызываемое при смене значения.
public event EventHandler ChangeEvent
{
add
{
_changeEvent += value;
}
remove
{
_changeEvent -= value;
}
}
}
}

View File

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

View File

@@ -0,0 +1,59 @@
namespace MyCustomComponents
{
partial class CustomSelectedCheckedListBoxProperty
{
/// <summary>
/// Обязательная переменная конструктора.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Освободить все используемые ресурсы.
/// </summary>
/// <param name="disposing">истинно, если управляемый ресурс должен быть удален; иначе ложно.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Код, автоматически созданный конструктором компонентов
/// <summary>
/// Требуемый метод для поддержки конструктора — не изменяйте
/// содержимое этого метода с помощью редактора кода.
/// </summary>
private void InitializeComponent()
{
this.checkedListBox = new System.Windows.Forms.CheckedListBox();
this.SuspendLayout();
//
// checkedListBox
//
this.checkedListBox.FormattingEnabled = true;
this.checkedListBox.Location = new System.Drawing.Point(3, 3);
this.checkedListBox.Name = "checkedListBox";
this.checkedListBox.Size = new System.Drawing.Size(144, 148);
this.checkedListBox.TabIndex = 0;
this.checkedListBox.ItemCheck += new System.Windows.Forms.ItemCheckEventHandler(this.checkedListBox_ItemCheck);
this.checkedListBox.SelectedIndexChanged += new System.EventHandler(this.checkedListBox_SelectedIndexChanged);
//
// CustomSelectedCheckedListBoxProperty
//
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.Controls.Add(this.checkedListBox);
this.Name = "CustomSelectedCheckedListBoxProperty";
this.Size = new System.Drawing.Size(150, 157);
this.ResumeLayout(false);
}
#endregion
private CheckedListBox checkedListBox;
}
}

View File

@@ -0,0 +1,77 @@
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 MyCustomComponents
{
public partial class CustomSelectedCheckedListBoxProperty : UserControl
{
//Публичное свойство, которое передает ссылку на
//свойство Items элемента ComboBox, через которое и идет
//заполнение
public CheckedListBox.ObjectCollection Items => checkedListBox.Items;
public CustomSelectedCheckedListBoxProperty()
{
InitializeComponent();
}
//Отдельный публичный метод отчистки списка.
public void Clear()
{
checkedListBox.Items.Clear();
}
private EventHandler _changeEvent;
private void checkedListBox_SelectedIndexChanged(object sender, EventArgs e)
{
_changeEvent?.Invoke(sender, e);
}
//Cобытие, вызываемое при смене значения в CheckedListBox
public event EventHandler ChangeEvent
{
add
{
_changeEvent += value;
}
remove
{
_changeEvent -= value;
}
}
//Публичное свойство (set, get) для установки и получения выбранного значения (возвращает пустую строку, если нет выбранного значения)
public string SelectedElement
{
get
{
return (checkedListBox.SelectedIndex > -1 && checkedListBox.GetItemChecked(checkedListBox.SelectedIndex)) ? checkedListBox.SelectedItem.ToString() : string.Empty;
}
set
{
if (checkedListBox.Items.Contains(value))
{
checkedListBox.SelectedItem = value;
}
}
}
private void checkedListBox_ItemCheck(object sender, ItemCheckEventArgs e)
{
if (e.NewValue == CheckState.Checked && checkedListBox.CheckedItems.Count > 0)
{
checkedListBox.ItemCheck -= checkedListBox_ItemCheck;
checkedListBox.SetItemChecked(checkedListBox.CheckedIndices[0], value: false);
checkedListBox.ItemCheck += checkedListBox_ItemCheck;
}
}
}
}

View File

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

View File

@@ -0,0 +1,56 @@
namespace MyCustomComponents
{
partial class CustomTreeCell
{
/// <summary>
/// Обязательная переменная конструктора.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Освободить все используемые ресурсы.
/// </summary>
/// <param name="disposing">истинно, если управляемый ресурс должен быть удален; иначе ложно.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Код, автоматически созданный конструктором компонентов
/// <summary>
/// Требуемый метод для поддержки конструктора — не изменяйте
/// содержимое этого метода с помощью редактора кода.
/// </summary>
private void InitializeComponent()
{
this.treeView = new System.Windows.Forms.TreeView();
this.SuspendLayout();
//
// treeView
//
this.treeView.Location = new System.Drawing.Point(3, 3);
this.treeView.Name = "treeView";
this.treeView.Size = new System.Drawing.Size(453, 195);
this.treeView.TabIndex = 0;
//
// CustomTreeCell
//
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.Controls.Add(this.treeView);
this.Name = "CustomTreeCell";
this.Size = new System.Drawing.Size(459, 202);
this.ResumeLayout(false);
}
#endregion
private TreeView treeView;
}
}

View File

@@ -0,0 +1,102 @@
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 MyCustomComponents
{
public partial class CustomTreeCell : UserControl
{
public void Clear()
{
treeView.Nodes.Clear();
}
//Публичное свойство для установки и получения индекса выбранной ветки(set, get).
protected DataTreeNodeConfig Levels { get; set; }
public void LoadConfig(DataTreeNodeConfig levels)
{
if (levels != null)
{
Levels = levels;
}
}
//Публичный метод для получения выбранной записи(для конечного элемента дерева)
public T GetSelectedObject<T>() where T : class, new()
{
if (treeView.SelectedNode == null || Levels == null || treeView.SelectedNode.Nodes.Count > 0)
{
return null;
}
Stack<string> stack = new Stack<string>();
for (TreeNode treeNode = treeView.SelectedNode; treeNode != null; treeNode = treeNode.Parent)
{
stack.Push(treeNode.Text);
}
if (stack.Count != Levels.NodeNames.Count)
{
return null;
}
T val = new T();
foreach (string nodeName in Levels.NodeNames)
{
PropertyInfo property = val.GetType().GetProperty(nodeName);
string value = stack.Pop();
property?.SetValue(val, Convert.ChangeType(value, property?.PropertyType));
}
return val;
}
//параметризованный метод, у которого в
//передаваемых параметрах идет объект какого-то класса, и
//имя свойства/поля, до которого согласно иерархии, следует
//сформировать ветки.
public void AddCell<T>(int columnIndex, T element)
{
if (Levels == null || element == null || columnIndex < 0 || columnIndex >= Levels.NodeNames.Count)
{
return;
}
TreeNodeCollection treeNodeCollection = treeView.Nodes;
int num = 0;
foreach (string nodeName in Levels.NodeNames)
{
string text = element.GetType().GetProperty(nodeName)?.GetValue(element, null)?.ToString() ?? nodeName;
TreeNode treeNode = null;
foreach (TreeNode item in treeNodeCollection)
{
if (item.Text == text)
{
treeNode = item;
}
}
treeNodeCollection = ((treeNode == null) ? treeNodeCollection.Add(text).Nodes : treeNode.Nodes);
if (num >= columnIndex)
{
break;
}
num++;
}
}
public CustomTreeCell()
{
InitializeComponent();
}
}
}

View File

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

View File

@@ -0,0 +1,13 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace MyCustomComponents
{
public class DataTreeNodeConfig
{
public Queue<string> NodeNames { get; set; }
}
}

View File

@@ -0,0 +1,216 @@
using System.Collections.Generic;
using System.Linq;
using DocumentFormat.OpenXml;
using DocumentFormat.OpenXml.Drawing;
using DocumentFormat.OpenXml.Drawing.Charts;
using MyCustomComponents.Models;
namespace MyCustomComponents.Helpers
{
public class CreatorDiagram
{
private static uint order = 0u;
private static uint index = 1u;
public static DocumentFormat.OpenXml.Drawing.Charts.Chart GeneratePieChart(WordWithDiagramConfig config)
{
PieChart pieChart = new PieChart();
pieChart.Append(GeneratePieChartSeries(config.Data.First().Key, config.Data.First().Value));
PlotArea plotArea = new PlotArea();
plotArea.Append(new Layout());
plotArea.Append(pieChart);
return GenerateChart(config.ChartTitle, plotArea, config.LegendLocation);
}
private static DocumentFormat.OpenXml.Drawing.Charts.Chart GenerateChart(string titleText, PlotArea plotArea, Location legendLocation)
{
DocumentFormat.OpenXml.Drawing.Charts.Chart chart = new DocumentFormat.OpenXml.Drawing.Charts.Chart();
if (titleText.HaveText())
{
chart.Append(GenerateTitle(titleText));
}
else
{
chart.Append(new AutoTitleDeleted
{
Val = (BooleanValue)true
});
}
LegendPositionValues position = legendLocation switch
{
Location.Top => LegendPositionValues.Top,
Location.Rigth => LegendPositionValues.Right,
Location.Left => LegendPositionValues.Left,
_ => LegendPositionValues.Bottom,
};
chart.Append(plotArea);
chart.Append(GenerateLegend(position));
chart.Append(new PlotVisibleOnly
{
Val = (BooleanValue)true
});
return chart;
}
private static Legend GenerateLegend(LegendPositionValues position)
{
ParagraphProperties paragraphProperties = new ParagraphProperties();
paragraphProperties.Append(new DefaultRunProperties());
Paragraph paragraph = new Paragraph();
paragraph.Append(paragraphProperties);
paragraph.Append(new EndParagraphRunProperties());
TextProperties textProperties = new TextProperties();
textProperties.Append(new BodyProperties());
textProperties.Append(new ListStyle());
textProperties.Append(paragraph);
Legend legend = new Legend();
legend.Append(new LegendPosition
{
Val = (EnumValue<LegendPositionValues>)position
});
legend.Append(new Layout());
legend.Append(new Overlay
{
Val = (BooleanValue)false
});
legend.Append(textProperties);
return legend;
}
private static Title GenerateTitle(string titleText)
{
Run run = new Run();
run.Append(new RunProperties
{
FontSize = (Int32Value)1100
});
run.Append(new Text(titleText));
ParagraphProperties paragraphProperties = new ParagraphProperties();
paragraphProperties.Append(new DefaultRunProperties
{
FontSize = (Int32Value)1100
});
Paragraph paragraph = new Paragraph();
paragraph.Append(paragraphProperties);
paragraph.Append(run);
RichText richText = new RichText();
richText.Append(new BodyProperties());
richText.Append(new ListStyle());
richText.Append(paragraph);
ChartText chartText = new ChartText();
chartText.Append(richText);
Title title = new Title();
title.Append(chartText);
title.Append(new Layout());
title.Append(new Overlay
{
Val = (BooleanValue)false
});
return title;
}
private static SeriesText GenerateSeriesText(string seriesName)
{
StringPoint stringPoint = new StringPoint
{
Index = (UInt32Value)0u
};
stringPoint.Append(new NumericValue
{
Text = seriesName
});
StringCache stringCache = new StringCache();
stringCache.Append(new PointCount
{
Val = (UInt32Value)1u
});
stringCache.Append(stringPoint);
StringReference stringReference = new StringReference();
stringReference.Append(stringCache);
SeriesText seriesText = new SeriesText();
seriesText.Append(stringReference);
return seriesText;
}
private static CategoryAxisData GenerateCategoryAxisData(string[] data)
{
uint num = (uint)data.Length;
NumberingCache numberingCache = GenerateNumberingCache(num);
for (uint num2 = 0u; num2 < num; num2++)
{
numberingCache.Append(GenerateNumericPoint(num2, data[num2].ToString()));
}
NumberReference numberReference = new NumberReference();
numberReference.Append(numberingCache);
CategoryAxisData categoryAxisData = new CategoryAxisData();
categoryAxisData.Append(numberReference);
return categoryAxisData;
}
private static Values GenerateValues(double[] data)
{
uint num = (uint)data.Length;
NumberingCache numberingCache = GenerateNumberingCache(num);
for (uint num2 = 0u; num2 < num; num2++)
{
numberingCache.Append(GenerateNumericPoint(num2, data[num2].ToString()));
}
NumberReference numberReference = new NumberReference();
numberReference.Append(numberingCache);
Values values = new Values();
values.Append(numberReference);
return values;
}
private static NumberingCache GenerateNumberingCache(uint numPoints)
{
NumberingCache numberingCache = new NumberingCache();
numberingCache.Append(new FormatCode
{
Text = "General"
});
numberingCache.Append(new PointCount
{
Val = (UInt32Value)numPoints
});
return numberingCache;
}
private static NumericPoint GenerateNumericPoint(UInt32Value idx, string text)
{
NumericPoint numericPoint = new NumericPoint
{
Index = idx
};
numericPoint.Append(new NumericValue
{
Text = text
});
return numericPoint;
}
private static PieChartSeries GeneratePieChartSeries(string seriesName, List<(int Date, double Value)> data)
{
PieChartSeries pieChartSeries = new PieChartSeries();
pieChartSeries.Append(new DocumentFormat.OpenXml.Drawing.Charts.Index
{
Val = (UInt32Value)index
});
pieChartSeries.Append(new Order
{
Val = (UInt32Value)order
});
pieChartSeries.Append(GenerateSeriesText(seriesName));
pieChartSeries.Append(GenerateCategoryAxisData(data.Select(((int Date, double Value) c) => c.Date.ToString()).ToArray()));
pieChartSeries.Append(GenerateValues(data.Select(((int Date, double Value) v) => v.Value).ToArray()));
index++;
order++;
return pieChartSeries;
}
}
}

View File

@@ -0,0 +1,179 @@
using MyCustomComponents.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading.Tasks;
namespace MyCustomComponents.Helpers
{
public static class ExtensionConfig
{
public static void CheckFields(this WordConfig config)
{
if (config.FilePath.IsEmpty())
{
throw new ArgumentNullException("Имя файла не задано");
}
if (config.Header.IsEmpty())
{
throw new ArgumentNullException("Заголовок документа не задан");
}
}
public static void CheckFields(this WordWithDiagramConfig config)
{
((WordConfig)config).CheckFields();
if (config.ChartTitle.IsEmpty())
{
throw new ArgumentNullException("Заголовок диаграммы не задан");
}
if (config.Data == null || config.Data.Count == 0 || config.Data.Any<KeyValuePair<string, List<(int, double)>>>((KeyValuePair<string, List<(int Date, double Value)>> x) => x.Key.IsEmpty() || x.Value == null || x.Value.Count == 0))
{
throw new ArgumentNullException("Нет данных для заполнения диаграммы");
}
}
public static void CheckFields(this WordWithImageConfig config)
{
((WordConfig)config).CheckFields();
if (config.Images == null || config.Images.Count == 0 || config.Images.All((byte[] x) => x == null || x.Length == 0))
{
throw new ArgumentNullException("Нет изображений для вставки в документ");
}
}
public static void CheckFields<T>(this WordWithTableDataConfig<T> config)
{
WordWithTableDataConfig<T> config2 = config;
((WordConfig)config2).CheckFields();
if (config2.ColumnsRowsWidth == null || config2.ColumnsRowsWidth.Count == 0)
{
throw new ArgumentNullException("Нет данных по ширине колонок таблицы");
}
if (config2.UseUnion && (config2.ColumnUnion == null || config2.ColumnUnion.Count == 0))
{
throw new ArgumentNullException("Нет данных по объединению колонок таблицы");
}
if (config2.Headers == null || config2.Headers.Count == 0 || config2.Headers.Any<(int, int, string, string)>(((int ColumnIndex, int RowIndex, string Header, string PropertyName) x) => x.Header.IsEmpty()))
{
throw new ArgumentNullException("Нет данных по заголовкам таблицы");
}
if (config2.Data == null || config2.Data.Count == 0)
{
throw new ArgumentNullException("Нет данных для заполнения таблицы");
}
if (!config2.UseUnion)
{
return;
}
if (config2.ColumnsRowsWidth.Count < config2.ColumnUnion[config2.ColumnUnion.Count - 1].StartIndex + config2.ColumnUnion[config2.ColumnUnion.Count - 1].Count - 1)
{
throw new IndexOutOfRangeException("Последнее объединение ячеек выходит за границы таблицы");
}
int k;
for (k = 0; k < config2.ColumnUnion[0].StartIndex; k++)
{
int num = config2.Headers.Where<(int, int, string, string)>(((int ColumnIndex, int RowIndex, string Header, string PropertyName) x) => x.ColumnIndex == k).Count();
if (num == 0)
{
DefaultInterpolatedStringHandler defaultInterpolatedStringHandler = new DefaultInterpolatedStringHandler(34, 1);
defaultInterpolatedStringHandler.AppendLiteral("Для ");
defaultInterpolatedStringHandler.AppendFormatted(k);
defaultInterpolatedStringHandler.AppendLiteral(" колонки отсутствует заголовок");
throw new ArgumentNullException(defaultInterpolatedStringHandler.ToStringAndClear());
}
if (num > 1)
{
DefaultInterpolatedStringHandler defaultInterpolatedStringHandler = new DefaultInterpolatedStringHandler(37, 1);
defaultInterpolatedStringHandler.AppendLiteral("Для ");
defaultInterpolatedStringHandler.AppendFormatted(k);
defaultInterpolatedStringHandler.AppendLiteral(" колонки задано более 1 заголовка");
throw new ArgumentNullException(defaultInterpolatedStringHandler.ToStringAndClear());
}
}
int j;
for (j = 0; j < config2.ColumnUnion.Count; j++)
{
if (j < config2.ColumnUnion.Count - 1 && config2.ColumnUnion[j].StartIndex + config2.ColumnUnion[j].Count - 1 > config2.ColumnUnion[j + 1].StartIndex)
{
throw new IndexOutOfRangeException("Имеется накладка в объединении ячеек");
}
int num2 = config2.Headers.Where<(int, int, string, string)>(((int ColumnIndex, int RowIndex, string Header, string PropertyName) x) => x.ColumnIndex >= config2.ColumnUnion[j].StartIndex && x.ColumnIndex <= config2.ColumnUnion[j].StartIndex + config2.ColumnUnion[j].Count - 1 && x.RowIndex == 0).Count();
if (num2 == 0)
{
throw new ArgumentNullException("Для колонок 0 строки отсутствует заголовок");
}
if (num2 > 1)
{
throw new ArgumentNullException("Для колонок 0 строки задано более 1 заголовка");
}
num2 = config2.Headers.Where<(int, int, string, string)>(((int ColumnIndex, int RowIndex, string Header, string PropertyName) x) => x.ColumnIndex >= config2.ColumnUnion[j].StartIndex && x.ColumnIndex <= config2.ColumnUnion[j].StartIndex + config2.ColumnUnion[j].Count - 1 && x.RowIndex == 1).Count();
if (num2 < config2.ColumnUnion[j].Count)
{
throw new ArgumentNullException("Для колонок 1 строки не хватает заголовков");
}
if (num2 > config2.ColumnUnion[j].Count)
{
throw new ArgumentNullException("Для колонок 1 строки задано более требуемого числа заголовков");
}
if (j < config2.ColumnUnion.Count - 1)
{
num2 = config2.Headers.Where<(int, int, string, string)>(((int ColumnIndex, int RowIndex, string Header, string PropertyName) x) => x.ColumnIndex >= config2.ColumnUnion[j].StartIndex + config2.ColumnUnion[j].Count && x.ColumnIndex < config2.ColumnUnion[j + 1].StartIndex && x.RowIndex == 0).Count();
if (num2 < config2.ColumnUnion[j + 1].StartIndex - (config2.ColumnUnion[j].StartIndex + config2.ColumnUnion[j].Count))
{
throw new ArgumentNullException("Для колонок не хватает заголовков");
}
if (num2 > config2.ColumnUnion[j + 1].StartIndex - (config2.ColumnUnion[j].StartIndex + config2.ColumnUnion[j].Count))
{
throw new ArgumentNullException("Для колонок задано более требуемого числа заголовков");
}
num2 = config2.Headers.Where<(int, int, string, string)>(((int ColumnIndex, int RowIndex, string Header, string PropertyName) x) => x.ColumnIndex >= config2.ColumnUnion[j].StartIndex + config2.ColumnUnion[j].Count && x.ColumnIndex < config2.ColumnUnion[j + 1].StartIndex && x.RowIndex == 1).Count();
if (num2 > 0)
{
throw new ArgumentNullException("Для колонок заданы заголовки 2 уровня, чего быть не должно");
}
}
int i;
for (i = config2.ColumnUnion[config2.ColumnUnion.Count - 1].StartIndex + config2.ColumnUnion[config2.ColumnUnion.Count - 1].Count; i < config2.ColumnsRowsWidth.Count; i++)
{
int num3 = config2.Headers.Where<(int, int, string, string)>(((int ColumnIndex, int RowIndex, string Header, string PropertyName) x) => x.ColumnIndex == i).Count();
if (num3 == 0)
{
DefaultInterpolatedStringHandler defaultInterpolatedStringHandler = new DefaultInterpolatedStringHandler(34, 1);
defaultInterpolatedStringHandler.AppendLiteral("Для ");
defaultInterpolatedStringHandler.AppendFormatted(i);
defaultInterpolatedStringHandler.AppendLiteral(" колонки отсутствует заголовок");
throw new ArgumentNullException(defaultInterpolatedStringHandler.ToStringAndClear());
}
if (num3 > 1)
{
DefaultInterpolatedStringHandler defaultInterpolatedStringHandler = new DefaultInterpolatedStringHandler(37, 1);
defaultInterpolatedStringHandler.AppendLiteral("Для ");
defaultInterpolatedStringHandler.AppendFormatted(i);
defaultInterpolatedStringHandler.AppendLiteral(" колонки задано более 1 заголовка");
throw new ArgumentNullException(defaultInterpolatedStringHandler.ToStringAndClear());
}
}
}
}
}
}

View File

@@ -0,0 +1,21 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace MyCustomComponents.Helpers
{
public static class ExtensionString
{
public static bool HaveText(this string str)
{
return !string.IsNullOrEmpty(str);
}
public static bool IsEmpty(this string str)
{
return string.IsNullOrEmpty(str);
}
}
}

View File

@@ -0,0 +1,16 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace MyCustomComponents.Models
{
public enum Location
{
Left,
Rigth,
Top,
Bottom
}
}

View File

@@ -0,0 +1,15 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace MyCustomComponents.Models
{
public class WordConfig
{
public string FilePath { get; set; }
public string Header { get; set; }
}
}

View File

@@ -0,0 +1,18 @@
using DocumentFormat.OpenXml.Spreadsheet;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace MyCustomComponents.Models
{
public class WordWithDiagramConfig : WordConfig
{
public string ChartTitle { get; set; }
public Location LegendLocation { get; set; }
public Dictionary<string, List<(int Date, double Value)>> Data { get; set; }
}
}

View File

@@ -0,0 +1,13 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace MyCustomComponents.Models
{
public class WordWithImageConfig : WordConfig
{
public List<byte[]> Images { get; set; }
}
}

View File

@@ -0,0 +1,21 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace MyCustomComponents.Models
{
public class WordWithTableConfig : WordConfig
{
public bool UseUnion { get; set; }
public (int Columns, int Rows) ColumnsRowsDataCount { get; set; }
public List<(int Column, int Row)> ColumnsRowsWidth { get; set; }
public List<(int StartIndex, int Count)> ColumnUnion { get; set; }
public List<(int ColumnIndex, int RowIndex, string Header, string PropertyName)> Headers { get; set; }
}
}

View File

@@ -0,0 +1,13 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace MyCustomComponents.Models
{
public class WordWithTableDataConfig<T> : WordWithTableConfig
{
public List<T> Data { get; set; }
}
}

View File

@@ -0,0 +1,20 @@
<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="2.20.0" />
<PackageReference Include="Microsoft.Win32.SystemEvents" Version="7.0.0" />
<PackageReference Include="PdfSharp.MigraDoc.Standard" Version="1.51.15" />
<PackageReference Include="PdfSharp.MigraDoc.Standard.DocumentObjectModel" Version="1.51.15" />
<PackageReference Include="PDFSharp.Standard" Version="1.51.15" />
<PackageReference Include="PDFSharp.Standard.Charting" Version="1.51.15" />
<PackageReference Include="System.Drawing.Common" Version="7.0.0" />
</ItemGroup>
</Project>

View File

@@ -0,0 +1,36 @@
namespace MyCustomComponents
{
partial class WordWithDiagram
{
/// <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,160 @@
using DocumentFormat.OpenXml.Drawing.Charts;
using DocumentFormat.OpenXml.Drawing;
using DocumentFormat.OpenXml.Packaging;
using DocumentFormat.OpenXml;
using DocumentFormat.OpenXml.Wordprocessing;
using MyCustomComponents.Helpers;
using MyCustomComponents.Models;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using DocumentFormat.OpenXml.Drawing.Wordprocessing;
namespace MyCustomComponents
{
public partial class WordWithDiagram : Component
{
private Document _document = null;
private Body _body = null;
private DocumentFormat.OpenXml.Drawing.Charts.Chart _chart;
private Document Document
{
get
{
if (_document == null)
{
_document = new Document();
}
return _document;
}
}
private Body Body
{
get
{
if (_body == null)
{
_body = Document.AppendChild(new Body());
}
return _body;
}
}
public void CreateHeader(string header)
{
DocumentFormat.OpenXml.Wordprocessing.Paragraph paragraph = Body.AppendChild(new DocumentFormat.OpenXml.Wordprocessing.Paragraph());
DocumentFormat.OpenXml.Wordprocessing.Run run = paragraph.AppendChild(new DocumentFormat.OpenXml.Wordprocessing.Run());
run.AppendChild(new DocumentFormat.OpenXml.Wordprocessing.RunProperties(new Bold()));
run.AppendChild(new DocumentFormat.OpenXml.Wordprocessing.Text(header));
}
public WordWithDiagram()
{
InitializeComponent();
}
public WordWithDiagram(IContainer container)
{
container.Add(this);
InitializeComponent();
}
public void CreateDoc(WordWithDiagramConfig config)
{
config.CheckFields();
CreateHeader(config.Header);
CreatePieChart(config);
SaveDoc(config.FilePath);
}
public void SaveDoc(string filepath)
{
if (filepath.IsEmpty())
{
throw new ArgumentNullException("Имя файла не задано");
}
if (_document == null || _body == null)
{
throw new ArgumentNullException("Документ не сформирован, сохранять нечего");
}
using WordprocessingDocument wordprocessingDocument = WordprocessingDocument.Create(filepath, WordprocessingDocumentType.Document);
MainDocumentPart mainDocumentPart = wordprocessingDocument.AddMainDocumentPart();
mainDocumentPart.Document = Document;
if (_chart != null)
{
ChartPart chartPart = mainDocumentPart.AddNewPart<ChartPart>("rId110");
ChartSpace chartSpace = new ChartSpace();
chartSpace.Append(new EditingLanguage
{
Val = (StringValue)"en-us"
});
chartSpace.Append(_chart);
ChartShapeProperties chartShapeProperties = new ChartShapeProperties();
DocumentFormat.OpenXml.Drawing.Outline outline = new DocumentFormat.OpenXml.Drawing.Outline();
outline.Append(new NoFill());
chartShapeProperties.Append(outline);
chartSpace.Append(chartShapeProperties);
chartPart.ChartSpace = chartSpace;
GeneratePartContent(mainDocumentPart);
}
}
private static void GeneratePartContent(MainDocumentPart mainPart)
{
DocumentFormat.OpenXml.Wordprocessing.Paragraph paragraph = new DocumentFormat.OpenXml.Wordprocessing.Paragraph
{
RsidParagraphAddition = (HexBinaryValue)"00C75AEB",
RsidRunAdditionDefault = (HexBinaryValue)"000F3EFF"
};
DocumentFormat.OpenXml.Wordprocessing.Run run = new DocumentFormat.OpenXml.Wordprocessing.Run();
Drawing drawing = new Drawing();
Inline inline = new Inline();
inline.Append(new Extent
{
Cx = (Int64Value)5274310L,
Cy = (Int64Value)3076575L
});
DocProperties docProperties = new DocProperties
{
Id = (UInt32Value)1u,
Name = (StringValue)"Chart 1"
};
inline.Append(docProperties);
Graphic graphic = new Graphic();
GraphicData graphicData = new GraphicData
{
Uri = (StringValue)"http://schemas.openxmlformats.org/drawingml/2006/chart"
};
ChartReference chartReference = new ChartReference
{
Id = (StringValue)"rId110"
};
graphicData.Append(chartReference);
graphic.Append(graphicData);
inline.Append(graphic);
drawing.Append(inline);
run.Append(drawing);
paragraph.Append(run);
mainPart.Document.Body!.Append(paragraph);
}
public void CreatePieChart(WordWithDiagramConfig config)
{
_chart = CreatorDiagram.GeneratePieChart(config);
}
}
}

View File

@@ -0,0 +1,36 @@
namespace MyCustomComponents
{
partial class WordWithImages
{
/// <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,231 @@
using DocumentFormat.OpenXml.Drawing.Charts;
using DocumentFormat.OpenXml.Drawing;
using DocumentFormat.OpenXml.Packaging;
using DocumentFormat.OpenXml;
using MyCustomComponents.Helpers;
using MyCustomComponents.Models;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using DocumentFormat.OpenXml.Drawing.Wordprocessing;
using System.Runtime.CompilerServices;
using System.IO;
using DocumentFormat.OpenXml.Drawing.Pictures;
using DocumentFormat.OpenXml.Wordprocessing;
namespace MyCustomComponents
{
public partial class WordWithImages : Component
{
private Document _document = null;
private Body _body = null;
private List<byte[]> _images = null;
private Document Document
{
get
{
if (_document == null)
{
_document = new Document();
}
return _document;
}
}
private Body Body
{
get
{
if (_body == null)
{
_body = Document.AppendChild(new Body());
}
return _body;
}
}
private List<byte[]> Images
{
get
{
if (_images == null)
{
_images = new List<byte[]>();
}
return _images;
}
}
public WordWithImages()
{
InitializeComponent();
}
public WordWithImages(IContainer container)
{
container.Add(this);
InitializeComponent();
}
public void CreateDoc(WordWithImageConfig config)
{
config.CheckFields();
CreateHeader(config.Header);
foreach (byte[] image in config.Images)
{
CreateImage(image);
}
SaveDoc(config.FilePath);
}
public void CreateHeader(string header)
{
DocumentFormat.OpenXml.Wordprocessing.Paragraph paragraph = Body.AppendChild(new DocumentFormat.OpenXml.Wordprocessing.Paragraph());
DocumentFormat.OpenXml.Wordprocessing.Run run = paragraph.AppendChild(new DocumentFormat.OpenXml.Wordprocessing.Run());
run.AppendChild(new DocumentFormat.OpenXml.Wordprocessing.RunProperties(new Bold()));
run.AppendChild(new DocumentFormat.OpenXml.Wordprocessing.Text(header));
}
public void SaveDoc(string filepath)
{
if (filepath.IsEmpty())
{
throw new ArgumentNullException("Имя файла не задано");
}
if (_document == null || _body == null)
{
throw new ArgumentNullException("Документ не сформирован, сохранять нечего");
}
using WordprocessingDocument wordprocessingDocument = WordprocessingDocument.Create(filepath, WordprocessingDocumentType.Document);
MainDocumentPart mainDocumentPart = wordprocessingDocument.AddMainDocumentPart();
mainDocumentPart.Document = Document;
if (_images != null)
{
int num = 0;
foreach (byte[] image in _images)
{
ImagePart imagePart = mainDocumentPart.AddImagePart(ImagePartType.Jpeg);
using (MemoryStream memoryStream = new MemoryStream(image))
{
memoryStream.Position = 0L;
imagePart.FeedData(memoryStream);
}
AddImageToBody(mainDocumentPart.GetIdOfPart(imagePart), ++num);
}
}
}
public void CreateImage(byte[] image)
{
if (image == null || image.Length == 0)
{
throw new ArgumentNullException("Картинка не загружена");
}
Images.Add(image);
}
private void AddImageToBody(string relationshipId, int index)
{
OpenXmlElement[] array = new OpenXmlElement[1];
OpenXmlElement[] obj = new OpenXmlElement[5]
{
new Extent
{
Cx = (Int64Value)3000000L,
Cy = (Int64Value)3000000L
},
new EffectExtent
{
LeftEdge = (Int64Value)0L,
TopEdge = (Int64Value)0L,
RightEdge = (Int64Value)0L,
BottomEdge = (Int64Value)0L
},
null,
null,
null
};
DocProperties obj2 = new DocProperties
{
Id = (UInt32Value)1u
};
DefaultInterpolatedStringHandler defaultInterpolatedStringHandler = new DefaultInterpolatedStringHandler(8, 1);
defaultInterpolatedStringHandler.AppendLiteral("Picture ");
defaultInterpolatedStringHandler.AppendFormatted(index);
obj2.Name = (StringValue)defaultInterpolatedStringHandler.ToStringAndClear();
obj[2] = obj2;
obj[3] = new DocumentFormat.OpenXml.Drawing.Wordprocessing.NonVisualGraphicFrameDrawingProperties(new GraphicFrameLocks
{
NoChangeAspect = (BooleanValue)true
});
OpenXmlElement[] array2 = new OpenXmlElement[1];
OpenXmlElement[] array3 = new OpenXmlElement[1];
OpenXmlElement[] array4 = new OpenXmlElement[3];
OpenXmlElement[] array5 = new OpenXmlElement[2];
DocumentFormat.OpenXml.Drawing.Pictures.NonVisualDrawingProperties obj3 = new DocumentFormat.OpenXml.Drawing.Pictures.NonVisualDrawingProperties
{
Id = (UInt32Value)0u
};
defaultInterpolatedStringHandler = new DefaultInterpolatedStringHandler(16, 1);
defaultInterpolatedStringHandler.AppendLiteral("New Picture ");
defaultInterpolatedStringHandler.AppendFormatted(index);
defaultInterpolatedStringHandler.AppendLiteral(".jpg");
obj3.Name = (StringValue)defaultInterpolatedStringHandler.ToStringAndClear();
array5[0] = obj3;
array5[1] = new DocumentFormat.OpenXml.Drawing.Pictures.NonVisualPictureDrawingProperties();
array4[0] = new DocumentFormat.OpenXml.Drawing.Pictures.NonVisualPictureProperties(array5);
array4[1] = new DocumentFormat.OpenXml.Drawing.Pictures.BlipFill(new Blip(new BlipExtensionList(new BlipExtension
{
Uri = (StringValue)"{28A0092B-C50C-407E-A947-70E740481C1C}"
}))
{
Embed = (StringValue)relationshipId,
CompressionState = (EnumValue<BlipCompressionValues>)BlipCompressionValues.Print
}, new Stretch(new FillRectangle()));
array4[2] = new DocumentFormat.OpenXml.Drawing.Pictures.ShapeProperties(new Transform2D(new Offset
{
X = (Int64Value)0L,
Y = (Int64Value)0L
}, new Extents
{
Cx = (Int64Value)990000L,
Cy = (Int64Value)792000L
}), new PresetGeometry(new AdjustValueList())
{
Preset = (EnumValue<ShapeTypeValues>)ShapeTypeValues.Rectangle
});
array3[0] = new DocumentFormat.OpenXml.Drawing.Pictures.Picture(array4);
array2[0] = new GraphicData(array3)
{
Uri = (StringValue)"http://schemas.openxmlformats.org/drawingml/2006/picture"
};
obj[4] = new Graphic(array2);
array[0] = new Inline(obj)
{
DistanceFromTop = (UInt32Value)0u,
DistanceFromBottom = (UInt32Value)0u,
DistanceFromLeft = (UInt32Value)0u,
DistanceFromRight = (UInt32Value)0u,
EditId = (HexBinaryValue)"50D07946"
};
Drawing drawing = new Drawing(array);
Body.AppendChild(new DocumentFormat.OpenXml.Wordprocessing.Paragraph(new DocumentFormat.OpenXml.Wordprocessing.Run(drawing)));
}
}
}

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,36 @@
namespace MyCustomComponents
{
partial class WordWithTable
{
/// <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,300 @@
using DocumentFormat.OpenXml;
using DocumentFormat.OpenXml.Drawing.Charts;
using DocumentFormat.OpenXml.Drawing;
using DocumentFormat.OpenXml.Packaging;
using DocumentFormat.OpenXml.Wordprocessing;
using MyCustomComponents.Helpers;
using MyCustomComponents.Models;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace MyCustomComponents
{
public partial class WordWithTable : Component
{
private Document _document = null;
private Body _body = null;
private DocumentFormat.OpenXml.Wordprocessing.Table _table = null;
private Document Document
{
get
{
if (_document == null)
{
_document = new Document();
}
return _document;
}
}
private Body Body
{
get
{
if (_body == null)
{
_body = Document.AppendChild(new Body());
}
return _body;
}
}
private DocumentFormat.OpenXml.Wordprocessing.Table Table
{
get
{
if (_table == null)
{
_table = new DocumentFormat.OpenXml.Wordprocessing.Table();
}
return _table;
}
}
public WordWithTable()
{
InitializeComponent();
}
public WordWithTable(IContainer container)
{
container.Add(this);
InitializeComponent();
}
public void CreateDoc<T>(WordWithTableDataConfig<T> config)
{
config.CheckFields();
config.ColumnsRowsDataCount = (config.Data.Count + 2, config.ColumnsRowsWidth.Count);
CreateHeader(config.Header);
CreateTableWithHeader();
CreateColumnHeader(config);
string[,] array = new string[config.ColumnsRowsWidth.Count, config.Data.Count];
for (int j = 0; j < config.Data.Count; j++)
{
int i;
for (i = 0; i < config.ColumnsRowsWidth.Count; i++)
{
(int, int, string, string) tuple = config.Headers.FirstOrDefault<(int, int, string, string)>(((int ColumnIndex, int RowIndex, string Header, string PropertyName) x) => x.ColumnIndex == i && x.RowIndex == 1);
if (tuple.Equals(default((int, int, string, string))))
{
tuple = config.Headers.FirstOrDefault<(int, int, string, string)>(((int ColumnIndex, int RowIndex, string Header, string PropertyName) x) => x.ColumnIndex == i && x.RowIndex == 0);
}
array[i, j] = config.Data[j].GetType().GetProperty(tuple.Item4)!.GetValue(config.Data[j], null)!.ToString();
}
}
LoadDataToTableWithColumnHeader(array);
SaveDoc(config.FilePath);
}
public void SaveDoc(string filepath)
{
if (filepath.IsEmpty())
{
throw new ArgumentNullException("Имя файла не задано");
}
if (_document == null || _body == null)
{
throw new ArgumentNullException("Документ не сформирован, сохранять нечего");
}
if (_table != null)
{
Body.Append(Table);
}
using WordprocessingDocument wordprocessingDocument = WordprocessingDocument.Create(filepath, WordprocessingDocumentType.Document);
MainDocumentPart mainDocumentPart = wordprocessingDocument.AddMainDocumentPart();
mainDocumentPart.Document = Document;
}
public void LoadDataToTableWithColumnHeader(string[,] data)
{
for (int i = 0; i < data.GetLength(0); i++)
{
DocumentFormat.OpenXml.Wordprocessing.TableRow tableRow = Table.Elements<DocumentFormat.OpenXml.Wordprocessing.TableRow>().ElementAt(i);
for (int j = 0; j < data.GetLength(1); j++)
{
DocumentFormat.OpenXml.Wordprocessing.TableCell tableCell = new DocumentFormat.OpenXml.Wordprocessing.TableCell();
tableCell.Append(new DocumentFormat.OpenXml.Wordprocessing.Paragraph(new DocumentFormat.OpenXml.Wordprocessing.Run(new DocumentFormat.OpenXml.Wordprocessing.Text(data[i, j]))));
tableRow.Append(tableCell);
}
}
}
private void AddColumnHeaderCellMergeByCols(string header, int rowHeight)
{
DocumentFormat.OpenXml.Wordprocessing.TableRow tableRow = new DocumentFormat.OpenXml.Wordprocessing.TableRow();
int? rowHeight2 = rowHeight;
DocumentFormat.OpenXml.Wordprocessing.TableCell tableCell = CreateCell(header, null, rowHeight2);
tableCell.Append(new HorizontalMerge
{
Val = (EnumValue<MergedCellValues>)MergedCellValues.Restart
});
tableRow.Append(tableCell);
tableCell = new DocumentFormat.OpenXml.Wordprocessing.TableCell(new DocumentFormat.OpenXml.Wordprocessing.Paragraph());
tableCell.Append(new HorizontalMerge
{
Val = (EnumValue<MergedCellValues>)MergedCellValues.Continue
});
tableRow.Append(tableCell);
Table.Append(tableRow);
}
private static DocumentFormat.OpenXml.Wordprocessing.TableCell CreateCell(string header, int? columnWidth = null, int? rowHeight = null)
{
DocumentFormat.OpenXml.Wordprocessing.TableCell tableCell = new DocumentFormat.OpenXml.Wordprocessing.TableCell();
DocumentFormat.OpenXml.Wordprocessing.TableCellProperties tableCellProperties = new DocumentFormat.OpenXml.Wordprocessing.TableCellProperties();
if (rowHeight.HasValue)
{
tableCellProperties.Append(new TableRowHeight
{
Val = (UInt32Value)Convert.ToUInt32(rowHeight)
});
}
if (columnWidth.HasValue)
{
tableCellProperties.Append(new TableCellWidth
{
Width = (StringValue)columnWidth.Value.ToString()
});
}
tableCellProperties.Append(new TableCellVerticalAlignment
{
Val = (EnumValue<TableVerticalAlignmentValues>)TableVerticalAlignmentValues.Center
});
tableCell.Append(tableCellProperties);
DocumentFormat.OpenXml.Wordprocessing.Paragraph paragraph = new DocumentFormat.OpenXml.Wordprocessing.Paragraph();
DocumentFormat.OpenXml.Wordprocessing.ParagraphProperties paragraphProperties = new DocumentFormat.OpenXml.Wordprocessing.ParagraphProperties();
paragraphProperties.Append(new Justification
{
Val = (EnumValue<JustificationValues>)JustificationValues.Center
});
paragraph.Append(paragraphProperties);
if (header.HaveText())
{
DocumentFormat.OpenXml.Wordprocessing.Run run = new DocumentFormat.OpenXml.Wordprocessing.Run();
run.AppendChild(new DocumentFormat.OpenXml.Wordprocessing.RunProperties(new Bold()));
run.AppendChild(new DocumentFormat.OpenXml.Wordprocessing.Text(header));
paragraph.Append(run);
}
tableCell.Append(paragraph);
return tableCell;
}
public void CreateColumnHeader(WordWithTableConfig config)
{
int k;
for (k = 0; k < config.ColumnUnion[0].StartIndex; k++)
{
AddColumnHeaderCellMergeByCols(config.Headers.FirstOrDefault<(int, int, string, string)>(((int ColumnIndex, int RowIndex, string Header, string PropertyName) x) => x.ColumnIndex == k).Item3, config.ColumnsRowsWidth[k].Row);
}
int j;
for (j = 0; j < config.ColumnUnion.Count; j++)
{
int l;
for (l = config.ColumnUnion[j].StartIndex; l < config.ColumnUnion[j].StartIndex + config.ColumnUnion[j].Count; l++)
{
DocumentFormat.OpenXml.Wordprocessing.TableRow tableRow = new DocumentFormat.OpenXml.Wordprocessing.TableRow();
if (l == config.ColumnUnion[j].StartIndex)
{
DocumentFormat.OpenXml.Wordprocessing.TableCell tableCell = CreateCell(config.Headers.FirstOrDefault<(int, int, string, string)>(((int ColumnIndex, int RowIndex, string Header, string PropertyName) x) => x.ColumnIndex == l && x.RowIndex == 0).Item3);
tableCell.Append(new VerticalMerge
{
Val = (EnumValue<MergedCellValues>)MergedCellValues.Restart
});
tableRow.Append(tableCell);
}
else
{
DocumentFormat.OpenXml.Wordprocessing.TableCell tableCell2 = new DocumentFormat.OpenXml.Wordprocessing.TableCell(new DocumentFormat.OpenXml.Wordprocessing.Paragraph());
tableCell2.Append(new VerticalMerge
{
Val = (EnumValue<MergedCellValues>)MergedCellValues.Continue
});
tableRow.Append(tableCell2);
}
OpenXmlElement[] array = new OpenXmlElement[1];
string item = config.Headers.FirstOrDefault<(int, int, string, string)>(((int ColumnIndex, int RowIndex, string Header, string PropertyName) x) => x.ColumnIndex == l && x.RowIndex == 1).Item3;
int? rowHeight = config.ColumnsRowsWidth[l].Row;
array[0] = CreateCell(item, null, rowHeight);
tableRow.Append(array);
Table.Append(tableRow);
}
if (j >= config.ColumnUnion.Count - 1)
{
continue;
}
for (int m = config.ColumnUnion[j].StartIndex + config.ColumnUnion[j].Count; m < config.ColumnUnion[j + 1].StartIndex; m++)
{
AddColumnHeaderCellMergeByCols(config.Headers.FirstOrDefault<(int, int, string, string)>(((int ColumnIndex, int RowIndex, string Header, string PropertyName) x) => x.ColumnIndex == j).Item3, config.ColumnsRowsWidth[j].Row);
}
}
int i;
for (i = config.ColumnUnion[config.ColumnUnion.Count - 1].StartIndex + config.ColumnUnion[config.ColumnUnion.Count - 1].Count; i < config.ColumnsRowsWidth.Count; i++)
{
AddColumnHeaderCellMergeByCols(config.Headers.FirstOrDefault<(int, int, string, string)>(((int ColumnIndex, int RowIndex, string Header, string PropertyName) x) => x.ColumnIndex == i).Item3, config.ColumnsRowsWidth[i].Row);
}
}
public void CreateTableWithHeader()
{
Table.AppendChild(new DocumentFormat.OpenXml.Wordprocessing.TableProperties(new TableBorders(new DocumentFormat.OpenXml.Wordprocessing.TopBorder
{
Val = new EnumValue<BorderValues>(BorderValues.Single),
Size = (UInt32Value)12u
}, new DocumentFormat.OpenXml.Wordprocessing.BottomBorder
{
Val = new EnumValue<BorderValues>(BorderValues.Single),
Size = (UInt32Value)12u
}, new DocumentFormat.OpenXml.Wordprocessing.LeftBorder
{
Val = new EnumValue<BorderValues>(BorderValues.Single),
Size = (UInt32Value)12u
}, new DocumentFormat.OpenXml.Wordprocessing.RightBorder
{
Val = new EnumValue<BorderValues>(BorderValues.Single),
Size = (UInt32Value)12u
}, new DocumentFormat.OpenXml.Wordprocessing.InsideHorizontalBorder
{
Val = new EnumValue<BorderValues>(BorderValues.Single),
Size = (UInt32Value)12u
}, new DocumentFormat.OpenXml.Wordprocessing.InsideVerticalBorder
{
Val = new EnumValue<BorderValues>(BorderValues.Single),
Size = (UInt32Value)12u
})));
}
public void CreateHeader(string header)
{
DocumentFormat.OpenXml.Wordprocessing.Paragraph paragraph = Body.AppendChild(new DocumentFormat.OpenXml.Wordprocessing.Paragraph());
DocumentFormat.OpenXml.Wordprocessing.Run run = paragraph.AppendChild(new DocumentFormat.OpenXml.Wordprocessing.Run());
run.AppendChild(new DocumentFormat.OpenXml.Wordprocessing.RunProperties(new Bold()));
run.AppendChild(new DocumentFormat.OpenXml.Wordprocessing.Text(header));
}
}
}