using System.Windows.Forms; using ComponentsLibrary.entities; 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 mergedColumns = new() { new int[] { 1, 5 }, new int[] { 6, 7 }, }; var columns = new List { 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 { 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 info = new(dialog.FileName, "Задание 2", columns, employees, mergedColumns); componentTable.CreateTable(info); MessageBox.Show("Сохранено успешно", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Information); } catch (Exception ex) { MessageBox.Show(ex.Message, "Ошибка!", MessageBoxButtons.OK, MessageBoxIcon.Error); } } } } }