KOP-PIbd-32-Katysheva-N-E/ComponentsView/FormComponents.cs
2024-10-28 21:49:23 +04:00

155 lines
6.0 KiB
C#

using ComponentsLibrary.entities;
using ComponentsLibrary.entities.enums;
using DocumentFormat.OpenXml.Drawing;
namespace ComponentsView
{
public partial class FormComponents : Form
{
public FormComponents()
{
InitializeComponent();
testComponent.FileName = "2.txt";
}
private void buttonSaveText_Click(object sender, EventArgs e)
{
try
{
testComponent.SaveToFile(richTextBoxTest.Lines);
MessageBox.Show("Ñîõàðíåíî óñïåøíî", "Ðåçóëüòàò",
MessageBoxButtons.OK, MessageBoxIcon.Information);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Îøèáêà!",
MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void buttonSaveTextWord_Click(object sender, EventArgs e)
{
using var dialog = new SaveFileDialog
{
Filter = "docx|*.docx"
};
if (dialog.ShowDialog() == DialogResult.OK)
{
try
{
DocumentSymple doc = new(dialog.FileName, "Ïåðâûé êîìïîíåíò", richTextBoxWord.Lines);
componentBigText.CreateWordText(doc);
MessageBox.Show("Ñîõàðíåíî óñïåøíî", "Ðåçóëüòàò",
MessageBoxButtons.OK, MessageBoxIcon.Information);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Îøèáêà!",
MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
private void buttonSaveTable_Click(object sender, EventArgs e)
{
List<int[]> mergedColumns = new()
{
new int[] { 1, 5 },
new int[] { 6, 7 },
};
var columns = new List<ColumnParams>
{
new() { FirstRowHeader = "Ñòàòóñ", SecondRowHeader = "", PropertyName = "Status", Width = 1 },
new() { FirstRowHeader = "Ëè÷íûå äàííûå", SecondRowHeader = "Èìÿ",PropertyName = "Name", Width = 1 },
new() { FirstRowHeader = "Ëè÷íûå äàííûå", SecondRowHeader = "Ôàìèëèÿ", PropertyName = "Surname", Width = 1 },
new() { FirstRowHeader = "Ëè÷íûå äàííûå", SecondRowHeader = "Âîçðàñò", PropertyName = "Age", Width = 0.1 },
new() { FirstRowHeader = "Ëè÷íûå äàííûå", SecondRowHeader = "Äåòè", PropertyName = "Childrens", Width = 0.1 },
new() { FirstRowHeader = "Ëè÷íûå äàííûå", SecondRowHeader = "Ìàøèíà", PropertyName = "Car", Width = 1 },
new() { FirstRowHeader = "Ðàáîòà", SecondRowHeader = "Äîëæíîñòü", PropertyName = "Post", Width = 1 },
new() { FirstRowHeader = "Ðàáîòà", SecondRowHeader = "Ñòàæ", PropertyName = "Experience", Width = 1 },
new() { FirstRowHeader = "Ïðåìèÿ", SecondRowHeader = "", PropertyName = "Prize", Width = 1 },
};
var employees = new List<Employee>
{
new() { Status = "Active", Name = "John", Surname = "Doe", Age = "35", Childrens = "2", Car = "Toyota", Post = "Manager", Experience = "10 years", Prize = "5000" },
new() { Status = "On Leave", Name = "Alice", Surname = "Smith", Age = "28", Childrens = "1", Car = "Honda", Post = "Developer", Experience = "5 years", Prize = "3000" },
new() { Status = "Active", Name = "Bob", Surname = "Brown", Age = "40", Childrens = "3", Car = "Ford", Post = "Team Lead", Experience = "15 years", Prize = "7000" },
new() { Status = "Retired", Name = "Carol", Surname = "Johnson", Age = "65", Childrens = "4", Car = "None", Post = "Accountant", Experience = "30 years", Prize = "10000" },
new() { Status = "Active", Name = "David", Surname = "Wilson", Age = "45", Childrens = "2", Car = "Chevrolet", Post = "Designer", Experience = "20 years", Prize = "4000" },
new() { Status = "Active", Name = "Eve", Surname = "Davis", Age = "32", Childrens = "0", Car = "Tesla", Post = "Data Scientist", Experience = "8 years", Prize = "6000" },
new() { Status = "On Leave", Name = "Frank", Surname = "Miller", Age = "38", Childrens = "2", Car = "BMW", Post = "Product Manager", Experience = "12 years", Prize = "5500" },
new() { Status = "Active", Name = "Grace", Surname = "Taylor", Age = "29", Childrens = "1", Car = "Mercedes", Post = "QA Engineer", Experience = "6 years", Prize = "3500" },
new() { Status = "Resigned", Name = "Henry", Surname = "Anderson", Age = "50", Childrens = "3", Car = "Audi", Post = "CTO", Experience = "25 years", Prize = "12000" },
new() { Status = "Active", Name = "Ivy", Surname = "Thomas", Age = "27", Childrens = "0", Car = "Volkswagen", Post = "Intern", Experience = "1 year", Prize = "1000" }
};
using var dialog = new SaveFileDialog
{
Filter = "docx|*.docx"
};
if (dialog.ShowDialog() == DialogResult.OK)
{
try
{
DocumentTable<Employee> info = new(dialog.FileName, "Âòîðîé êîìïîíåíò", columns, employees, mergedColumns);
componentTable.CreateTable(info);
MessageBox.Show("Ñîõðàíåíî óñïåøíî", "Ðåçóëüòàò",
MessageBoxButtons.OK, MessageBoxIcon.Information);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Îøèáêà!",
MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
private void buttonSaveDiagram_Click(object sender, EventArgs e)
{
using var dialog = new SaveFileDialog
{
Filter = "docx|*.docx"
};
if (dialog.ShowDialog() == DialogResult.OK)
{
try
{
string[] cathegories = { "ßíâàðü", "Ôåâðàëü", "Ìàðò", "April", "May" };
(string, double)[] series1 = { ("Êàòåãîðèÿ 1", 100), ("Êàòåãîðèÿ 2", 300), ("Êàòåãîðèÿ 3", 400) };
(string, double)[] series2 = { ("Êàòåãîðèÿ 1", 400), ("Êàòåãîðèÿ 2", 300), ("Êàòåãîðèÿ 3", 100) };
(string, double)[] series3 = { ("Êàòåãîðèÿ 1", 200), ("Êàòåãîðèÿ 2", 500), ("Êàòåãîðèÿ 3", 900) };
string fileUrl = dialog.FileName;
string docHeader = "Òðåòèé êîìïîíåíò";
string diagramName = "Ëèíåéíàÿ äèàãðàìà";
List<DataLine> dataList = new List<DataLine> {
new DataLine("Ñåðèÿ 1", series1),
new DataLine("Ñåðèÿ 2", series2),
new DataLine("Ñåðèÿ 3", series3),
};
DocumentDiagram diagram = new(fileUrl, docHeader, diagramName, EnumAreaLegend.Right, dataList);
componentDiagram.AddDiagram(diagram);
MessageBox.Show("Ñîõðàíåíî óñïåøíî", "Ðåçóëüòàò",
MessageBoxButtons.OK, MessageBoxIcon.Information);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Îøèáêà!",
MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
}
}