PIbd-33_Dyakonov_R_R_COP_14/WinFormsApp1/Form1.cs

234 lines
6.6 KiB
C#
Raw Normal View History

2024-09-29 21:11:27 +04:00
using System.Security.Cryptography.Xml;
using WinFormsLibrary1;
2024-09-29 21:12:45 +04:00
using WinFormsLibrary1.Configs.Diagram;
using WinFormsLibrary1.Configs.Image;
2024-09-29 21:11:27 +04:00
using WinFormsLibrary1.Models;
2024-09-29 21:12:45 +04:00
using WinFormsLibrary1.Errors;
using WinFormsLibrary1.Configs.Diagram;
using WinFormsLibrary1.Configs.Table;
using PdfSharp.Pdf.Content.Objects;
2024-09-29 21:11:27 +04:00
namespace WinFormsApp1
{
public partial class Form1 : Form
{
2024-09-29 21:12:45 +04:00
private PdfWithImages pdfWithImages = new PdfWithImages();
private List<byte[]> selectedImages = new List<byte[]>();
private PdfWithTable pdfWithTable = new PdfWithTable();
private PdfWithDiagram pdfWithDiagram = new PdfWithDiagram();
2024-09-29 21:11:27 +04:00
public Form1()
{
InitializeComponent();
FillCustomCheckedListBox();
FillCustomDataTree();
}
private void FillCustomCheckedListBox()
{
List<string> list = new List<string>() { "<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> 1", "<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> 2", "<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> 3" };
for (int i = 0; i < list.Count; i++)
{
customCheckedListBox.AddItem(list[i]);
}
}
private void FillCustomDataTree()
{
departamentComboBox.Items.Add("<22><><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>");
departamentComboBox.Items.Add("<22><><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>");
departamentComboBox.Items.Add("IT <20><><EFBFBD><EFBFBD><EFBFBD>");
DataTreeNodeConfig config = new DataTreeNodeConfig(new List<string> { "Department", "Position", "Name" });
customDataTree.LoadConfig(config);
List<Employee> employees = new List<Employee>
{
new Employee("<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD>", "<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>", "<22><><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>"),
new Employee("<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD>", "<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>", "<22><><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>"),
new Employee("<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD>", "<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>", "<22><><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>"),
new Employee("<22><><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>", "<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>", "IT <20><><EFBFBD><EFBFBD><EFBFBD>"),
new Employee("<22><><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>", "<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>", "<22><><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>"),
};
foreach (var employee in employees)
{
customDataTree.AddObject(employee);
}
}
private void addInListboxItemButton_Click(object sender, EventArgs e)
{
string value = listboxItemValuetextBox.Text;
if (customCheckedListBox.Items.Contains(value)) customCheckedListBox.SelectedElement = value;
else customCheckedListBox.AddItem(value);
}
private void clearListboxButton_Click(object sender, EventArgs e)
{
customCheckedListBox.Clear();
}
private void getSelectedItemButton_Click(object sender, EventArgs e)
{
string value = customCheckedListBox.SelectedElement;
if (value == string.Empty) selectedItemLabel.Text = "Selected item: ~empty value~";
else selectedItemLabel.Text = "Selected item: " + value;
}
private void checkCustomTextBoxButton_Click(object sender, EventArgs e)
{
try
{
errorCustomTextBoxLabel.Text = customTextBox.Value == string.Empty ? "~empty value~" : customTextBox.Value;
}
catch (RangeNotSetException ex)
{
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>, <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><> <20><><EFBFBD><EFBFBD><EFBFBD>.
MessageBox.Show(ex.Message, "<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>", MessageBoxButtons.OK, MessageBoxIcon.Warning);
}
catch (TextLengthOutOfRangeException ex)
{
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>, <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>.
MessageBox.Show(ex.Message, "<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>", MessageBoxButtons.OK, MessageBoxIcon.Warning);
}
}
private void addEmployeeButton_Click(object sender, EventArgs e)
{
if (positionTextBox.Text == null || nameTextBox.Text == null || departamentComboBox.SelectedItem == null)
{
return;
}
customDataTree.AddObject<Employee>(new(nameTextBox.Text, positionTextBox.Text, departamentComboBox.SelectedItem.ToString()));
customDataTree.Update();
}
private void getSelectedTreeItemButton_Click(object sender, EventArgs e)
{
Employee employee = customDataTree.GetSelectedObject<Employee>();
if (employee == null)
{
return;
}
positionTextBox.Text = employee.Position;
nameTextBox.Text = employee.Name;
departamentComboBox.SelectedItem = employee.Department;
}
2024-09-29 21:12:45 +04:00
// PDF WITH IMAGE
private void button1_Click(object sender, EventArgs e)
{
using OpenFileDialog openFileDialog = new OpenFileDialog
{
Multiselect = true,
Filter = "<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>|*.jpg;*.jpeg;*.png;*.bmp"
};
if (openFileDialog.ShowDialog() == DialogResult.OK)
{
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
selectedImages.Clear();
listBoxImages.Items.Clear();
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
foreach (string filePath in openFileDialog.FileNames)
{
selectedImages.Add(File.ReadAllBytes(filePath));
listBoxImages.Items.Add(Path.GetFileName(filePath));
}
}
}
private void createPdfButton_Click(object sender, EventArgs e)
{
if (selectedImages.Count == 0)
{
MessageBox.Show("<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD> <20><> <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>!", "<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD> PDF-<2D><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
var config = new PdfWithImageConfig
{
FilePath = "PdfWithImage.pdf",
Header = "<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>",
Images = selectedImages
};
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> PDF <20><><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
pdfWithImages.CreatePdf(config);
MessageBox.Show("PDF <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>!", "<22><><EFBFBD><EFBFBD><EFBFBD>", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
// PDF WITH TABLE
private void pdfTableButton_Click(object sender, EventArgs e)
{
PdfWithTableConfig<Human> config = new PdfWithTableConfig<Human>
{
FileName = "PdfWithTable.pdf",
DocumentTitle = "<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>",
RowHeights = new List<double> { 1, 1, 1 },
Headers = new Dictionary<string, List<string>>
{
{ "<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>", new List<string> {"<22><><EFBFBD>", "<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>"} },
{ "<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>", new List<string>() }
},
PropertiesPerRow = new List<string> { "Name", "Surname", "Age" },
Data = new List<Human>
{
new Human("<22><><EFBFBD><EFBFBD>", "<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>", 30),
new Human("<22><><EFBFBD><EFBFBD>", "<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>", 25),
new Human("<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>", "<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>", 35)
}
};
try
{
// <20><><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> PDF
pdfWithTable.CreatePdf(config);
MessageBox.Show("PDF-<2D><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>!", "<22><><EFBFBD><EFBFBD><EFBFBD>", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
catch (Exception ex)
{
MessageBox.Show($"<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> PDF: {ex.Message}", "<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
// PDF TO DIAGRAM
private void pdfDiagramButton_Click(object sender, EventArgs e)
{
try
{
pdfWithDiagram.CreateDoc(new PdfWithDiagramConfig
{
FilePath = "PdfWithPieDiagram.pdf",
Header = "<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>",
ChartTitle = "<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>",
LegendLocation = WinFormsLibrary1.Configs.Diagram.Location.Bottom,
Data = new Dictionary<string, List<(string Name, double Value)>>
{
{
"Product A", new List<(string Name, double Value)>
{
("1111", 30.0),
("2", 20.0),
("3", 50.0)
}
}
}
});
MessageBox.Show("PDF <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>!", "<22><><EFBFBD><EFBFBD><EFBFBD>");
}
catch (Exception ex)
{
MessageBox.Show($"<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>: {ex.Message}");
}
}
2024-09-29 21:11:27 +04:00
}
}