Arkadiy Radaev a71399d55b lab 2 res
2024-10-28 19:28:12 +04:00

201 lines
5.2 KiB
C#

using DocumentFormat.OpenXml.Office2013.Excel;
using DocumentFormat.OpenXml.Spreadsheet;
using Microsoft.VisualBasic.Devices;
using System.Windows.Forms;
using Library15;
using Library15.Exceptions;
using Library15.OfficePackage.HelperModels;
namespace Form1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
InitializeSelectComponent();
InitializeInputComponent();
}
private void InitializeSelectComponent()
{
selectComponent.Input("Ðåñïåêò");
selectComponent.Input("Ñòóë");
selectComponent.Input("Êâàíò");
selectComponent.Input("Ìåõ");
}
private void SelectComponent_ItemSelected(object sender, EventArgs e)
{
MessageBox.Show(selectComponent.SelectedItem);
}
private void buttonAdd_Click(object sender, EventArgs e)
{
if (textBox.Text != "")
selectComponent.Input(textBox.Text);
}
private void buttonClearList_Click(object sender, EventArgs e)
{
selectComponent.ClearList();
}
private void InitializeInputComponent()
{
inputComponent.FloatValue = 12.3f;
}
private void buttonShowFloat_Click(object sender, EventArgs e)
{
try
{
float? Value = inputComponent.FloatValue;
if (Value != null)
{
MessageBox.Show($"Ââåäåííîå ÷èñëî: {Value}");
}
else
{
MessageBox.Show("Çíà÷åíèå - null");
}
}
catch (NotFloatException ex)
{
MessageBox.Show(ex.Message);
}
catch (EmptyValueException ex)
{
MessageBox.Show(ex.Message);
}
}
private void InitializeDataGridViewComponent()
{
listOutputComponent.ConfigColumn(new()
{
new ColumnInfo("", 0, false, "Id"),
new ColumnInfo("Ôàìèëèÿ", 150, true, "Name"),
new ColumnInfo("Èìÿ", 100, true, "Surname"),
new ColumnInfo("Âîçðàñò", 100, true, "Age"),
});
List<TestPerson> Persons = new()
{
new TestPerson(1, "Ñóñàíèí", "Ñóñàí", 21),
new TestPerson(2, "Ãðåêîâ", "Äîìàì", 33),
new TestPerson(3, "Òóëèí", "Ñìåð÷", 49),
};
foreach (TestPerson person in Persons)
{
listOutputComponent.AddItem(person);
}
}
private void buttonAddListOutput_Click(object sender, EventArgs e)
{
InitializeDataGridViewComponent();
}
private void buttonClearListOutput_Click(object sender, EventArgs e)
{
listOutputComponent.ClearDataGridView();
}
private void buttonGetListOutput_Click(object sender, EventArgs e)
{
var Test = listOutputComponent.GetSelectedObject<TestPerson>();
MessageBox.Show(Test.ToString());
}
#region ïðîñòàÿ òàáëèöàÿ
private void buttonSimpleTable_Click(object sender, EventArgs e)
{
List<string[,]> data = new List<string[,]>
{
new string[,]
{
{ "Ñòð 1 Êîë 1", "Ñòð 1 Êîë 2", "Ñòð 1 Êîë 3" },
{ "Ñòð 2 Êîë 1", "Ñòð 2 Êîë 2", "Ñòð 2 Êîë 3" },
{ "Ñòð 3 Êîë 1", "Ñòð 3 Êîë 2", "Ñòð 3 Êîë 3" },
},
new string[,]
{
{ "Ñòð 1 Êîë 1", "Ñòð 1 Êîë 2", "Ñòð 1 Êîë 3", "Ñòð 1 Êîë 4", "Ñòð 1 Êîë 5" },
{ "Ñòð 2 Êîë 1", "Ñòð 2 Êîë 2", "Ñòð 2 Êîë 3", "Ñòð 2 Êîë 4", "Ñòð 2 Êîë 5" },
{ "Ñòð 3 Êîë 1", "Ñòð 3 Êîë 2", "Ñòð 3 Êîë 3", "Ñòð 3 Êîë 4", "Ñòð 3 Êîë 5" },
{ "Ñòð 4 Êîë 1", "Ñòð 4 Êîë 2", "Ñòð 4 Êîë 3", "Ñòð 4 Êîë 4", "Ñòð 4 Êîë 5" },
}
};
var info = new WordTable
{
FileName = "C://Study/ULSTU/3_kurs/COP21.docx",
Title = "À ýòî çàãîëîâîê",
Table = data,
};
wordDocumentContext1.CreateWord(info);
MessageBox.Show("Word óñïåøíî ñîçäàí!", "Óñïåõ", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
#endregion
#region ñëîæíàÿ òàáëèöà
readonly List<PersonWordTable> PersonsWord = new()
{
new PersonWordTable("Âðà÷", "Ñóñàíèí", "Ñóñàí", 22, 120.12),
new PersonWordTable("Ãåíäèð", "Ãðåêîâ", "Äîìàì", 20, 300.83),
new PersonWordTable("Òîâàðùèê", "Òóëèí", "Ñìåð÷", 59, 601.3),
};
private void WordSaveHeaders_Click(object sender, EventArgs e)
{
wordDocumentTable1.CreateTable(new WordTableWithData<PersonWordTable>
{
FileName = "C://Study/ULSTU/3_kurs/COP22.docx",
Title = "À ýòî çàãîëîâîê",
ColumnsRowsWidth = new List<(int Column, int Row)> { (5, 5), (10, 5), (10, 0), (5, 0), (10,5) },
Headers = new List<(int ColumnIndex, int RowIndex, string Header, string PropertyName)>
{
(0, 0, "Äîëæíîñòü", "Id"),
(1, 0, "Ôàìèëèÿ", "Surname"),
(2, 0, "Èìÿ", "Name"),
(3, 0, "Âîçðàñò", "Age"),
(4, 0, "IQ", "Premia"),
},
Data = PersonsWord,
NullReplace = "null"
});
MessageBox.Show("Word äîêóìåíò ñ òàáëèöåé ñîçäàí!", "Óñïåõ");
}
#endregion
#region ðàáîòà ñ äèàãðàììîé
private void createDiagram_Click(object sender, EventArgs e)
{
try
{
wordDiagram.CreateDiagram(
new WordDiagramInfo
{
FileName = "C://Study/ULSTU/3_kurs/COP23.docx",
Title = "À ýòî çàãîëîâîê",
ChartTitle = "Ãèñòîãðàììà",
LegendLocation = Library15.OfficePackage.HelperEnum.WordDiagramLegendLocation.Top,
Series = new WordDiagramSeries
{
SeriesName = "Ãèñòîãðàììà",
Data = new Dictionary<string, double>
{
{ "Gelly", 21 },
{ "lada", 45.5 },
{ "Ford", 12.5 },
{ "Coca-cola", 7.5 },
}
}
});
MessageBox.Show("Word äîêóìåíò ñ äèàãðàììîé ñîçäàí!", "Õàëÿâà");
}
catch (Exception ex)
{
MessageBox.Show($"Îøèáêà: {ex.Message}");
}
}
#endregion
}
}