KOP-PIbd-32-Katysheva-N-E/ComponentsView/FormComponents.cs
2024-09-30 23:54:03 +04:00

89 lines
2.5 KiB
C#

using System.Windows.Forms;
namespace ComponentsView
{
public partial class FormComponents : Form
{
public FormComponents()
{
InitializeComponent();
testComponent.FileName = "2.txt";
InitializeDataGridView();
}
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)
{
try
{
var docEntry = new DocumentSymple(@"C:\Users\Natalia\Desktop\5semestr\KOP\KOP-PIbd-32-Katysheva-N-E\docs", "Word.docx", richTextBoxWord.Lines);
componentBigText.SetText(docEntry.FileUrl, docEntry.FileName, docEntry.Text);
MessageBox.Show("Ñîõàðíåíî óñïåøíî", "Ðåçóëüòàò",
MessageBoxButtons.OK, MessageBoxIcon.Information);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Îøèáêà!",
MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void InitializeDataGridView()
{
dataGridViewTable.Columns.Add("Column1", "Íàçâàíèå");
dataGridViewTable.Columns.Add("Column2", "Çíà÷åíèå");
// Äîáàâüòå íåêîòîðûå òåñòîâûå äàííûå
dataGridViewTable.Rows.Add("Òåñò1", "Çíà÷åíèå1");
dataGridViewTable.Rows.Add("Òåñò2", "Çíà÷åíèå2");
}
private void buttonSaveTable_Click(object sender, EventArgs e)
{
try
{
List<string[]> data = new List<string[]>();
// Èçâëå÷åíèå äàííûõ èç DataGridView
foreach (DataGridViewRow row in dataGridViewTable.Rows)
{
if (row.IsNewRow) continue; // Ïðîïóñòèòü ïóñòóþ ñòðîêó
string[] rowData = new string[dataGridViewTable.Columns.Count];
for (int i = 0; i < dataGridViewTable.Columns.Count; i++)
{
rowData[i] = row.Cells[i].Value?.ToString() ?? string.Empty;
}
data.Add(rowData);
}
// Ñîçäàíèå äîêóìåíòà ñ äàííûìè èç òàáëèöû
var docEntry = new DocumentSymple(@"C:\Users\Natalia\Desktop\5semestr\KOP\KOP-PIbd-32-Katysheva-N-E\docs", "Table.docx", data.Select(row => string.Join("\t", row)).ToArray());
componentBigText.SetText(docEntry.FileUrl, docEntry.FileName, docEntry.Text);
MessageBox.Show("Ñîõðàíåíî óñïåøíî", "Ðåçóëüòàò",
MessageBoxButtons.OK, MessageBoxIcon.Information);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Îøèáêà!",
MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
}