KOP-PIbd-32-Katysheva-N-E/ComponentsView/FormComponents.cs
2024-10-15 10:27:49 +03:00

92 lines
2.8 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(@"\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.Columns.Add("Column3", "Âòîðîå çíà÷åíèå");
dataGridViewTable.Rows.Add("Òåñò1", "Çíà÷åíèå1","2 Çíà÷åíèå1");
dataGridViewTable.Rows.Add("Òåñò2", "Çíà÷åíèå2", "2 Çíà÷åíèå2");
dataGridViewTable.Rows.Add("Òåñò3", "Çíà÷åíèå3", "2 Çíà÷åíèå3");
dataGridViewTable.Rows.Add("Òåñò4", "Çíà÷åíèå4", "2 Çíà÷åíèå4");
dataGridViewTable.Rows.Add("Òåñò5", "Çíà÷åíèå5", "2 Çíà÷åíèå5");
dataGridViewTable.Rows.Add("Òåñò6", "Çíà÷åíèå6", "2 Çíà÷åíèå6");
}
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(@"\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);
}
}
}
}