Compare commits

...

2 Commits

Author SHA1 Message Date
Kirill
c281e4e07b ну сделал один компонент 2024-11-17 17:05:03 +04:00
Kirill
a94ad17abc тестовый компонент работает 2024-11-17 14:18:00 +04:00
32 changed files with 901 additions and 189 deletions

0
1.txt Normal file
View File

View File

@ -0,0 +1,36 @@
namespace MyUserControls.Components.PdfImage
{
partial class PdfImage
{
/// <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,47 @@
using MyUserControls.Components.office_package;
using MyUserControls.Components.office_package.HelperEnums;
using MyUserControls.Components.office_package.HelperModels;
using MyUserControls.Components.office_package.Implements;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace MyUserControls.Components.PdfImage
{
public partial class PdfImage : Component
{
ISaveToPdf SaveToPdf = new SaveToPdf();
public PdfImage()
{
InitializeComponent();
}
public PdfImage(IContainer container)
{
container.Add(this);
InitializeComponent();
}
public void CreatePdf(PdfImageInfo info)
{
info.CheckFields();
SaveToPdf.CreatePdf(info);
SaveToPdf.CreateParagraph(new PdfParagraph
{
Text = info.Title,
Style = "NormalTitle",
ParagraphAlignment = PdfParagraphAlignmentType.Center
});
foreach (var image in info.Images)
{
SaveToPdf.CreateImage(image);
}
SaveToPdf.SavePdf(info);
}
}
}

View File

@ -0,0 +1,24 @@
using MyUserControls.Components.office_package.HelperModels;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace MyUserControls.Components.PdfImage
{
public class PdfImageInfo : IPdfInfo
{
public string FileName { get; set; } = string.Empty;
public string Title { get; set; } = string.Empty;
public List<byte[]> Images { get; set; } = new List<byte[]>();
public void CheckFields()
{
if (string.IsNullOrWhiteSpace(FileName) || string.IsNullOrWhiteSpace(Title) || Images == null || Images.Count == 0)
{
throw new ArgumentException("Все поля должны быть заполнены.");
}
}
}
}

View File

@ -0,0 +1,36 @@
namespace MyUserControls.Components.PdfTable
{
partial class PdfTable
{
/// <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,25 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace MyUserControls.Components.PdfTable
{
public partial class PdfTable : Component
{
public PdfTable()
{
InitializeComponent();
}
public PdfTable(IContainer container)
{
container.Add(this);
InitializeComponent();
}
}
}

View File

@ -0,0 +1,12 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace MyUserControls.Components.PdfTable
{
internal class PdfTableInfo
{
}
}

View File

@ -0,0 +1,14 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace MyUserControls.Components.office_package.HelperEnums
{
public enum PdfCellsMergeDirections
{
Down,
Right
}
}

View File

@ -0,0 +1,16 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace MyUserControls.Components.office_package.HelperEnums
{
public enum PdfDiagramLegendLocation
{
Left,
Right,
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 MyUserControls.Components.office_package.HelperEnums
{
public enum PdfParagraphAlignmentType
{
Center,
Left,
Right
}
}

View File

@ -0,0 +1,14 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace MyUserControls.Components.office_package.HelperModels
{
public interface IPdfInfo
{
public string FileName { get; }
public string Title { get; }
}
}

View File

@ -0,0 +1,16 @@
using MyUserControls.Components.office_package.HelperEnums;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace MyUserControls.Components.office_package.HelperModels
{
public interface IPdfPieChartParameters
{
public string ChartTitle { get; }
public PdfDiagramLegendLocation LegendLocation { get; }
public PdfDiagramSeries Series { get; }
}
}

View File

@ -0,0 +1,15 @@
using MyUserControls.Components.office_package.HelperEnums;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace MyUserControls.Components.office_package.HelperModels
{
public interface ITableTextParameters
{
public string Style { get; }
public PdfParagraphAlignmentType ParagraphAlignment { get; }
}
}

View File

@ -0,0 +1,16 @@
using MyUserControls.Components.office_package.HelperEnums;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace MyUserControls.Components.office_package.HelperModels
{
public class PdfCellParameters : ITableTextParameters
{
public string Text { get; set; } = string.Empty;
public string Style { get; set; } = string.Empty;
public PdfParagraphAlignmentType ParagraphAlignment { get; set; }
}
}

View File

@ -0,0 +1,17 @@
using MyUserControls.Components.office_package.HelperEnums;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace MyUserControls.Components.office_package.HelperModels
{
public class PdfCellsMergeParameters
{
public int RowIndex = 0;
public int ColumnIndex = 0;
public PdfCellsMergeDirections Direction;
public int CellNumber = 1;
}
}

View File

@ -0,0 +1,17 @@
using MyUserControls.Components.office_package.HelperEnums;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace MyUserControls.Components.office_package.HelperModels
{
public class PdfColumnParameters : ITableTextParameters
{
public List<string> Texts { get; set; } = new();
public string Style { get; set; } = string.Empty;
public int ColumnIndex = 0;
public PdfParagraphAlignmentType ParagraphAlignment { get; set; }
}
}

View File

@ -0,0 +1,14 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace MyUserControls.Components.office_package.HelperModels
{
public class PdfDiagramSeries
{
public string SeriesName { get; set; } = string.Empty;
public Dictionary<string, double> Data = new();
}
}

View File

@ -0,0 +1,16 @@
using MyUserControls.Components.office_package.HelperEnums;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace MyUserControls.Components.office_package.HelperModels
{
public class PdfParagraph
{
public string Text { get; set; } = string.Empty;
public string Style { get; set; } = string.Empty;
public PdfParagraphAlignmentType ParagraphAlignment { get; set; }
}
}

View File

@ -0,0 +1,16 @@
using MyUserControls.Components.office_package.HelperEnums;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace MyUserControls.Components.office_package.HelperModels
{
public class PdfRowParameters : ITableTextParameters
{
public List<string> Texts { get; set; } = new();
public string Style { get; set; } = string.Empty;
public PdfParagraphAlignmentType ParagraphAlignment { get; set; }
}
}

View File

@ -0,0 +1,66 @@
using MyUserControls.Components.office_package.HelperModels;
using MyUserControls.Components.PdfImage;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace MyUserControls.Components.office_package
{
public interface ISaveToPdf
{
/// <summary>
/// Создание doc-файла
/// </summary>
/// <param name="info"></param>
void CreatePdf(IPdfInfo info);
/// <summary>
/// Создание параграфа с текстом
/// </summary>
void CreateParagraph(PdfParagraph paragraph);
/// <summary>
/// Создание изображения в pdf файле
/// </summary>
void CreateImage(byte[] image);
/// <summary>
/// Создание таблицы
/// определенной ширины
/// </summary>
void CreateTable();
/// <summary>
/// Создание таблицы с заданным количеством столбцов
/// определенной ширины
/// </summary>
void CreateTableWithColumns(List<string> columns);
/// <summary>
/// Создание таблицы с заданным количеством столбцов
/// </summary>
void CreateTableWithColumns(int columnNumber);
/// <summary>
/// Создание и заполнение строки
/// </summary>
/// <param name="rowParameters"></param>
void CreateRow(PdfRowParameters rowParameters);
/// <summary>
/// Создание и заполнение столбца
/// </summary>
void InsertTextIntoColumn(PdfColumnParameters columnParameters);
/// <summary>
/// Создание и заполнение ячейки
/// </summary>
void InsertTextIntoCell(int rowIndex, int columnIndex, PdfCellParameters cellParameters);
/// <summary>
/// Создание и заполнение ячейки
/// </summary>
void MergeCells(PdfCellsMergeParameters parameters);
/// <summary>
/// Создание и заполнение круговой диаграммы
/// </summary>
void CreatePieChart(IPdfPieChartParameters parameters);
/// <summary>
/// Сохранение файла
/// </summary>
void SavePdf(IPdfInfo info);
}
}

View File

@ -0,0 +1,256 @@
using MigraDoc.DocumentObjectModel;
using MigraDoc.Rendering;
using MigraDoc.DocumentObjectModel.Tables;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Security.Cryptography;
using System.Reflection;
using System.Data.Common;
using MigraDoc.DocumentObjectModel.Shapes;
using MigraDoc.DocumentObjectModel.Shapes.Charts;
using MyUserControls.Components.office_package.HelperEnums;
using MyUserControls.Components.office_package.HelperModels;
namespace MyUserControls.Components.office_package.Implements
{
public class SaveToPdf : ISaveToPdf
{
private Document? _document;
private Section? _section;
private Table? _table;
private readonly Unit BORDER_WIDTH = 0.5;
private readonly Unit COLUMN_WIDTH = Unit.FromCentimeter(3.5);
private readonly Unit IMAGE_WIDTH = Unit.FromCentimeter(15);
public void CreatePdf(IPdfInfo info)
{
_document = new Document();
DefineStyles(_document);
_section = _document.AddSection();
}
public void SavePdf(IPdfInfo info)
{
if (string.IsNullOrWhiteSpace(info.FileName))
{
throw new ArgumentNullException("Имя файла не задано");
}
if (_document == null || _section == null)
{
throw new ArgumentNullException("Документ не сформирован, сохранять нечего");
}
var renderer = new PdfDocumentRenderer(true){
Document = _document
};
renderer.RenderDocument();
renderer.PdfDocument.Save(info.FileName);
}
private static ParagraphAlignment GetParagraphAlignment(
PdfParagraphAlignmentType type)
{
return type switch
{
PdfParagraphAlignmentType.Center => ParagraphAlignment.Center,
PdfParagraphAlignmentType.Left => ParagraphAlignment.Left,
PdfParagraphAlignmentType.Right => ParagraphAlignment.Right,
_ => ParagraphAlignment.Justify,
};
}
private static void DefineStyles(Document document)
{
var style = document.Styles["Normal"];
style.Font.Name = "Times New Roman";
style.Font.Size = 14;
style = document.Styles.AddStyle("NormalTitle", "Normal");
style.Font.Bold = true;
}
public void CreateParagraph(PdfParagraph pdfParagraph)
{
if (_document == null)
{
return;
}
if (_section == null)
{
_section = _document.AddSection();
}
var paragraph = _section.AddParagraph(pdfParagraph.Text);
paragraph.Format.SpaceAfter = "1cm";
paragraph.Format.Alignment = GetParagraphAlignment(pdfParagraph.ParagraphAlignment);
paragraph.Style = pdfParagraph.Style;
}
public void CreateImage(byte[] image)
{
if (image == null || image.Length == 0)
{
throw new ArgumentNullException("Картинка не загружена");
}
if (_document == null)
{
return;
}
if (_section == null)
{
_section = _document.AddSection();
}
var imageFileName = Path.GetTempFileName();
File.WriteAllBytes(imageFileName, image);
var img = _section.AddImage(imageFileName);
img.Width = IMAGE_WIDTH;
img.LockAspectRatio = true;
_section.AddParagraph();
}
public void CreateTable()
{
if (_document == null || _section == null)
{
return;
}
_table = _section.AddTable();
}
public void CreateTableWithColumns(List<string> columns)
{
if (_document == null || _section == null)
{
return;
}
_table = _section.AddTable();
foreach (var elem in columns)
{
_table.AddColumn(elem);
}
}
public void CreateTableWithColumns(int columnNumber)
{
if (_document == null || _section == null)
{
return;
}
_table = _section.AddTable();
for (int i = 0; i < columnNumber; i++)
{
_table.AddColumn(COLUMN_WIDTH);
}
}
public void CreateRow(PdfRowParameters rowParameters)
{
if (_table == null)
{
return;
}
var row = _table.AddRow();
for (int i = 0; i < rowParameters.Texts.Count; ++i)
{
if (!string.IsNullOrWhiteSpace(rowParameters.Texts[i]))
InsertTextIntoCell(row.Index, i, rowParameters, rowParameters.Texts[i]);
}
}
public void InsertTextIntoColumn(PdfColumnParameters columnParameters)
{
if (_table == null)
{
return;
}
for (int i = 0; i < columnParameters.Texts.Count; ++i)
{
if (!string.IsNullOrWhiteSpace(columnParameters.Texts[i]))
InsertTextIntoCell(i, columnParameters.ColumnIndex, columnParameters, columnParameters.Texts[i]);
}
}
public void InsertTextIntoCell(int rowIndex, int columnIndex, PdfCellParameters cellParameters)
{
InsertTextIntoCell(rowIndex, columnIndex, cellParameters, cellParameters.Text);
}
private void InsertTextIntoCell(int rowIndex, int columnIndex, ITableTextParameters parameters, string text)
{
if (_table == null)
{
return;
}
Cell cell = _table.Rows[rowIndex].Cells[columnIndex];
cell.AddParagraph(text);
if (!string.IsNullOrEmpty(parameters.Style))
{
cell.Style = parameters.Style;
}
cell.Borders.Left.Width = BORDER_WIDTH;
cell.Borders.Right.Width = BORDER_WIDTH;
cell.Borders.Top.Width = BORDER_WIDTH;
cell.Borders.Bottom.Width = BORDER_WIDTH;
cell.Format.Alignment = GetParagraphAlignment(
parameters.ParagraphAlignment);
cell.VerticalAlignment = VerticalAlignment.Center;
}
public void MergeCells(PdfCellsMergeParameters parameters)
{
if (_table == null)
{
return;
}
Cell cell = _table.Rows[parameters.RowIndex].Cells[parameters.ColumnIndex];
switch (parameters.Direction)
{
case PdfCellsMergeDirections.Down:
cell.MergeDown = parameters.CellNumber;
break;
case PdfCellsMergeDirections.Right:
cell.MergeRight = parameters.CellNumber;
break;
}
}
public void CreatePieChart(IPdfPieChartParameters parameters)
{
if (_document == null || _section == null)
throw new ArgumentNullException(nameof(_document), "Document is not created.");
Chart chart = new Chart(ChartType.Pie2D);
Series series = chart.SeriesCollection.AddSeries();
series.Name = parameters.Series.SeriesName;
series.Add(parameters.Series.Data.Select(x => x.Value).ToArray());
chart.XValues.AddXSeries().Add(parameters.Series.Data.Select(x => x.Key).ToArray());
ConfigChart(parameters, chart);
_section.Add(chart);
}
private void ConfigChart(IPdfPieChartParameters parameters, Chart chart)
{
chart.DataLabel.Type = DataLabelType.Percent;
chart.DataLabel.Position = DataLabelPosition.OutsideEnd;
chart.Width = Unit.FromCentimeter(16.0);
chart.Height = Unit.FromCentimeter(12.0);
chart.TopArea.AddParagraph(parameters.ChartTitle);
chart.XAxis.MajorTickMark = (TickMarkType)2;
chart.YAxis.MajorTickMark = (TickMarkType)2;
chart.YAxis.HasMajorGridlines = true;
chart.PlotArea.LineFormat.Width = new Unit(1);
chart.PlotArea.LineFormat.Visible = true;
switch (parameters.LegendLocation)
{
case PdfDiagramLegendLocation.Left:
chart.LeftArea.AddLegend();
break;
case PdfDiagramLegendLocation.Right:
chart.RightArea.AddLegend();
break;
case PdfDiagramLegendLocation.Top:
chart.TopArea.AddLegend();
break;
case PdfDiagramLegendLocation.Bottom:
chart.BottomArea.AddLegend();
break;
}
}
}
}

View File

@ -10,16 +10,54 @@ namespace MyUserControls.Components
{
public partial class testComponent : Component
{
private string _fileName;
public string FileName
{
set
{
if (string.IsNullOrEmpty(value)){
return;
}
if (!value.EndsWith(".txt"))
{
throw new ArgumentException("No txt file");
}
_fileName = value;
}
}
public testComponent()
{
InitializeComponent();
_fileName = string.Empty;
}
public testComponent(IContainer container)
{
container.Add(this);
InitializeComponent();
_fileName = string.Empty;
}
public bool SaveToFile(string[] texts)
{
CheckFileExsists();
using var writer = new StreamWriter(_fileName, true);
foreach (var text in texts)
{
writer.WriteLine(text);
}
writer.Flush();
return true;
}
private void CheckFileExsists()
{
if (string.IsNullOrEmpty(_fileName))
{
throw new ArgumentNullException(_fileName);
}
if (!File.Exists(_fileName))
{
throw new FileNotFoundException(_fileName);
}
}
}
}

View File

@ -7,4 +7,12 @@
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="PDFsharp-MigraDoc-GDI" Version="6.1.1" />
</ItemGroup>
<ItemGroup>
<Folder Include="Components\PdfDiagram\" />
</ItemGroup>
</Project>

View File

@ -4,7 +4,7 @@ using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace MyUserControls.VisualComponents
namespace MyUserControls
{
public class ValueOutOfRangeException : Exception
{

Binary file not shown.

View File

@ -28,14 +28,22 @@
/// </summary>
private void InitializeComponent()
{
components = new System.ComponentModel.Container();
smartCheckedListBox1 = new MyUserControls.SmartCheckedListBox();
smartTextBox1 = new MyUserControls.SmartTextBox();
hierarchicalTreeView = new MyUserControls.HierarchicalTreeView();
testComponent1 = new MyUserControls.Components.testComponent(components);
buttonSave = new Button();
richTextBoxText = new RichTextBox();
pdfImage = new MyUserControls.Components.PdfImage.PdfImage(components);
listBoxImages = new ListBox();
chooseImage = new Button();
createPdfImages = new Button();
SuspendLayout();
//
// smartCheckedListBox1
//
smartCheckedListBox1.Location = new Point(37, 12);
smartCheckedListBox1.Location = new Point(12, 12);
smartCheckedListBox1.Name = "smartCheckedListBox1";
smartCheckedListBox1.SelectedValue = "";
smartCheckedListBox1.Size = new Size(241, 182);
@ -43,25 +51,77 @@
//
// smartTextBox1
//
smartTextBox1.Location = new Point(12, 318);
smartTextBox1.Location = new Point(0, 329);
smartTextBox1.MaxLength = 100;
smartTextBox1.MinLength = 0;
smartTextBox1.Name = "smartTextBox1";
smartTextBox1.Size = new Size(312, 98);
smartTextBox1.Size = new Size(295, 98);
smartTextBox1.TabIndex = 2;
//
// hierarchicalTreeView
//
hierarchicalTreeView.Location = new Point(12, 163);
hierarchicalTreeView.Location = new Point(0, 162);
hierarchicalTreeView.Name = "hierarchicalTreeView";
hierarchicalTreeView.Size = new Size(266, 174);
hierarchicalTreeView.TabIndex = 3;
//
// buttonSave
//
buttonSave.Location = new Point(337, 111);
buttonSave.Name = "buttonSave";
buttonSave.Size = new Size(168, 32);
buttonSave.TabIndex = 4;
buttonSave.Text = "Сохранить";
buttonSave.UseVisualStyleBackColor = true;
buttonSave.Click += buttonSave_Click;
//
// richTextBoxText
//
richTextBoxText.Location = new Point(337, 26);
richTextBoxText.Name = "richTextBoxText";
richTextBoxText.Size = new Size(168, 70);
richTextBoxText.TabIndex = 5;
richTextBoxText.Text = "";
//
// listBoxImages
//
listBoxImages.FormattingEnabled = true;
listBoxImages.ItemHeight = 20;
listBoxImages.Location = new Point(330, 162);
listBoxImages.Name = "listBoxImages";
listBoxImages.Size = new Size(184, 64);
listBoxImages.TabIndex = 6;
//
// chooseImage
//
chooseImage.Location = new Point(331, 232);
chooseImage.Name = "chooseImage";
chooseImage.Size = new Size(183, 27);
chooseImage.TabIndex = 7;
chooseImage.Text = "Добавить картинку";
chooseImage.UseVisualStyleBackColor = true;
chooseImage.Click += chooseImage_Click;
//
// createPdfImages
//
createPdfImages.Location = new Point(330, 265);
createPdfImages.Name = "createPdfImages";
createPdfImages.Size = new Size(184, 29);
createPdfImages.TabIndex = 8;
createPdfImages.Text = "Создать пдф";
createPdfImages.UseVisualStyleBackColor = true;
createPdfImages.Click += createPdfImages_Click;
//
// Form1
//
AutoScaleDimensions = new SizeF(8F, 20F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(1120, 450);
ClientSize = new Size(1120, 474);
Controls.Add(createPdfImages);
Controls.Add(chooseImage);
Controls.Add(listBoxImages);
Controls.Add(richTextBoxText);
Controls.Add(buttonSave);
Controls.Add(hierarchicalTreeView);
Controls.Add(smartTextBox1);
Controls.Add(smartCheckedListBox1);
@ -75,5 +135,12 @@
private MyUserControls.SmartCheckedListBox smartCheckedListBox1;
private MyUserControls.SmartTextBox smartTextBox1;
private MyUserControls.HierarchicalTreeView hierarchicalTreeView;
private MyUserControls.Components.testComponent testComponent1;
private Button buttonSave;
private RichTextBox richTextBoxText;
private MyUserControls.Components.PdfImage.PdfImage pdfImage;
private ListBox listBoxImages;
private Button chooseImage;
private Button createPdfImages;
}
}

View File

@ -1,15 +1,21 @@
using MyUserControls;
using MyUserControls.Components.office_package.Implements;
using MyUserControls.Components.PdfImage;
using System.ComponentModel;
namespace WinFormsApp1
{
public partial class Form1 : Form
{
private List<byte[]> selectedImages = new List<byte[]>();
public Form1()
{
InitializeComponent();
InitialChekedListBox();
InitialSmartTextBox();
InitialTree();
testComponent1.FileName = "1.txt";
}
private void InitialChekedListBox()
@ -51,5 +57,79 @@ namespace WinFormsApp1
smartTextBox1.InputText = hierarchicalTreeView.GetSelectedItem<SampleClass>().ToString();
}
private void buttonSave_Click(object sender, EventArgs e)
{
try
{
testComponent1.SaveToFile(richTextBoxText.Lines);
MessageBox.Show("Ñîõàðíåíî óñïåøíî", "Ðåçóëüòàò",
MessageBoxButtons.OK, MessageBoxIcon.Information);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Îøèáêà",
MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void chooseImage_Click(object sender, EventArgs e)
{
try
{
using OpenFileDialog openFileDialog = new OpenFileDialog
{
Multiselect = true,
Filter = "Image Files|*.jpg;*.jpeg;*.png;*.bmp"
};
if (openFileDialog.ShowDialog() == DialogResult.OK)
{
selectedImages.Clear();
listBoxImages.Items.Clear();
foreach (string filePath in openFileDialog.FileNames)
{
selectedImages.Add(File.ReadAllBytes(filePath));
listBoxImages.Items.Add(Path.GetFileName(filePath));
}
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
private void createPdfImages_Click(object sender, EventArgs e)
{
try
{
if (selectedImages.Count == 0)
{
MessageBox.Show("Íåòó êàðòèíîê", "Îøèáêà", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
string currentDirectory = Directory.GetCurrentDirectory();
string filePath = Path.Combine(currentDirectory, @"..\..\..\Documents\PdfWithImage.pdf");
var info = new PdfImageInfo
{
FileName = filePath,
Title = "title",
Images = selectedImages
};
pdfImage.CreatePdf(info);
MessageBox.Show("Ïäô ñîçäàí óñïåøíî", "ôàéë ñîçäàí", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
}
}

View File

@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Microsoft ResX Schema
Version 2.0
@ -48,7 +48,7 @@
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
@ -117,4 +117,10 @@
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<metadata name="testComponent1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>17, 17</value>
</metadata>
<metadata name="pdfImage.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>183, 17</value>
</metadata>
</root>

View File

@ -1,39 +0,0 @@
namespace WinFormsApp1
{
partial class Form2
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.components = new System.ComponentModel.Container();
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(800, 450);
this.Text = "Form2";
}
#endregion
}
}

View File

@ -1,20 +0,0 @@
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 WinFormsApp1
{
public partial class Form2 : Form
{
public Form2()
{
InitializeComponent();
}
}
}

View File

@ -1,120 +0,0 @@
<?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

@ -12,4 +12,8 @@
<ProjectReference Include="..\CheckedListBoxLibrary\MyUserControls.csproj" />
</ItemGroup>
<ItemGroup>
<Folder Include="Documents\" />
</ItemGroup>
</Project>