224 lines
7.4 KiB
C#
224 lines
7.4 KiB
C#
using MyUserControls;
|
|
using MyUserControls.Components.office_package.Implements;
|
|
using MyUserControls.Components.PdfDiagram;
|
|
using MyUserControls.Components.PdfImage;
|
|
using MyUserControls.Components.PdfTable;
|
|
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()
|
|
{
|
|
|
|
smartCheckedListBox1.AddItem("Ýëåìåíò 1");
|
|
smartCheckedListBox1.AddItem("Ýëåìåíò 2");
|
|
smartCheckedListBox1.AddItem("Ýëåìåíò 3");
|
|
|
|
smartCheckedListBox1.SelectedValue = "Ýëåìåíò 3";
|
|
}
|
|
|
|
private void InitialSmartTextBox()
|
|
{
|
|
|
|
smartTextBox1.MinLength = 0;
|
|
smartTextBox1.MaxLength = 1000;
|
|
smartTextBox1.InputText = "jjjjj";
|
|
}
|
|
|
|
private void InitialTree()
|
|
{
|
|
var obj1 = new SampleClass { Name = "Item1", Category = "Category1", SubCategory = "SubCategory1" };
|
|
var obj2 = new SampleClass { Name = "Item2", Category = "Category1", SubCategory = "SubCategory2" };
|
|
|
|
List<string> properties = new List<string>
|
|
{
|
|
"Name",
|
|
"Category",
|
|
"SubCategory"
|
|
};
|
|
|
|
hierarchicalTreeView.SetPropertyHierarchy(properties);
|
|
|
|
hierarchicalTreeView.AddObject(obj1);
|
|
hierarchicalTreeView.AddObject(obj2);
|
|
|
|
hierarchicalTreeView.SelectNode(1, "SubCategory2");
|
|
|
|
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);
|
|
}
|
|
}
|
|
|
|
private void createTable_Click(object sender, EventArgs e)
|
|
{
|
|
try
|
|
{
|
|
List<TreeNode> headers = new List<TreeNode>
|
|
{
|
|
new TreeNode
|
|
{
|
|
Text = "Name",
|
|
Tag = "Name",
|
|
},
|
|
new TreeNode("Info", new TreeNode[]
|
|
{
|
|
new TreeNode
|
|
{
|
|
Text = "Category",
|
|
Tag = "Category"
|
|
},
|
|
new TreeNode
|
|
{
|
|
Text = "SubCategory",
|
|
Tag = "SubCategory"
|
|
}
|
|
})
|
|
};
|
|
List<SampleClass> data = new List<SampleClass>
|
|
{
|
|
new SampleClass("a1", "d1", "f1"),
|
|
new SampleClass("a2", "d2", "f2"),
|
|
new SampleClass("a3", "d3", "f3")
|
|
};
|
|
string currentDirectory = Directory.GetCurrentDirectory();
|
|
|
|
string filePath = Path.Combine(currentDirectory, @"..\..\..\Documents\PdfWithTable.pdf");
|
|
|
|
var info = new PdfTableInfo<SampleClass>
|
|
{
|
|
FileName = filePath,
|
|
Title = "Title",
|
|
Headers = headers,
|
|
Data = data
|
|
};
|
|
pdfTable.CreatePdf(info);
|
|
MessageBox.Show("PDF ñîçäàí óñïåøíî!", "ïäô ñîçäàí", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
MessageBox.Show(ex.Message);
|
|
}
|
|
}
|
|
|
|
|
|
private void createDiagram_Click(object sender, EventArgs e)
|
|
{
|
|
try
|
|
{
|
|
string currentDirectory = Directory.GetCurrentDirectory();
|
|
|
|
string filePath = Path.Combine(currentDirectory, @"..\..\..\Documents\PdfWithPieDiagram.pdf");
|
|
|
|
pdfDiagram.CreateDiagram(new PdfDiagramInfo
|
|
{
|
|
FileName = filePath,
|
|
Title = "Title",
|
|
ChartTitle = "OS 2024",
|
|
LegendLocation = MyUserControls.Components.office_package.HelperEnums.PdfDiagramLegendLocation.Bottom,
|
|
Series = new MyUserControls.Components.office_package.HelperModels.PdfDiagramSeries
|
|
{
|
|
SeriesName = "DesctopOperatingSystemAugust2024",
|
|
Data = new Dictionary<string, double>
|
|
{
|
|
{ "Windows", 71.5 },
|
|
{ "OS X", 15.5 },
|
|
{ "Linux", 4.5 },
|
|
{ "Others", 8.5 },
|
|
}
|
|
}
|
|
});
|
|
MessageBox.Show("PDF óñïåøíî ñîçäàí!", "ïäô ñîçäàí");
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
MessageBox.Show($"íå óäàëîñü ñîçäàòü ïäô: {ex.Message}");
|
|
}
|
|
}
|
|
|
|
}
|
|
}
|