205 lines
5.6 KiB
C#
205 lines
5.6 KiB
C#
using DocumentFormat.OpenXml.Office2013.Excel;
|
|
using DocumentFormat.OpenXml.Spreadsheet;
|
|
using Microsoft.VisualBasic.Devices;
|
|
using System.Windows.Forms;
|
|
using YunusovComponentsLibrary;
|
|
using YunusovComponentsLibrary.Exceptions;
|
|
using YunusovComponentsLibrary.OfficePackage.HelperModels;
|
|
|
|
namespace Form1
|
|
{
|
|
public partial class Form1 : Form
|
|
{
|
|
public Form1()
|
|
{
|
|
InitializeComponent();
|
|
|
|
|
|
InitializeSelectComponent();
|
|
InitializeInputComponent();
|
|
|
|
}
|
|
private void InitializeSelectComponent()
|
|
{
|
|
selectComponent.Input("Çíà÷åíèå 1");
|
|
selectComponent.Input("Çíà÷åíèå 2");
|
|
selectComponent.Input("Çíà÷åíèå 3");
|
|
selectComponent.Input("Çíà÷åíèå 4");
|
|
selectComponent.Input("Çíà÷åíèå 5");
|
|
}
|
|
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, "Âÿ÷åñëàâ", "Èâàíîâ", 20),
|
|
new TestPerson(2, "Ðîñòèñëàâ", "Çàõàðîâ", 20),
|
|
new TestPerson(3, "Ñåðãåé", "Ñåðãååâ", 59),
|
|
new TestPerson(4, "Àðò¸ì", "ßøèí", 25),
|
|
new TestPerson(5, "Ëåâ", "ßøèí", 89),
|
|
};
|
|
|
|
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" }
|
|
},
|
|
new string[,]
|
|
{
|
|
{ "Ñòð 1 Êîë 1", "Ñòð 1 Êîë 2", "Ñòð 1 Êîë 3", "Ñòð 1 Êîë 4", "Ñòð 1 Êîë 5", "Ñòð 1 Êîë 6" },
|
|
{ "Ñòð 2 Êîë 1", "Ñòð 2 Êîë 2", "Ñòð 2 Êîë 3", "Ñòð 2 Êîë 4", "Ñòð 2 Êîë 5", "Ñòð 2 Êîë 6" },
|
|
{ "Ñòð 3 Êîë 1", "Ñòð 3 Êîë 2", "Ñòð 3 Êîë 3", "Ñòð 3 Êîë 4", "Ñòð 3 Êîë 5", "Ñòð 3 Êîë 6" },
|
|
{ "Ñòð 4 Êîë 1", "Ñòð 4 Êîë 2", "Ñòð 4 Êîë 3", "Ñòð 4 Êîë 4", "Ñòð 4 Êîë 5", "Ñòð 4 Êîë 6" },
|
|
}
|
|
};
|
|
var info = new WordSimpleTable
|
|
{
|
|
FileName = "C://Users//niyaz//WordSimpleTable.docx",
|
|
Title = "Çàãîëîâîê",
|
|
Table = data,
|
|
};
|
|
wordDocumentContext1.CreateWord(info);
|
|
MessageBox.Show("Word óñïåøíî ñîçäàí!", "Óñïåõ", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
|
|
|
}
|
|
#endregion
|
|
|
|
#region ñëîæíàÿ òàáëèöà
|
|
|
|
readonly List<PersonWordTable> PersonsWord = new()
|
|
{
|
|
new PersonWordTable("Äåïàðòàìåíò", "Âÿ÷åñëàâ", "Èâàíîâ", 20, 2000.1),
|
|
new PersonWordTable("Äåïàðòàìåíò", "Ðîñòèñëàâ", "Çàõàðîâ", 20, 3000.5),
|
|
new PersonWordTable("Äåïàðòàìåíò", "Ñåðãåé", "Ñåðãååâ", 59, 1001.3),
|
|
new PersonWordTable("Áóõãàëòåðèÿ", "Àðò¸ì", "ßøèí", 25, 1234.23),
|
|
new PersonWordTable("Áóõãàëòåðèÿ", "Ëåâ", "ßøèí", 89, 1457.34),
|
|
};
|
|
private void WordSaveHeaders_Click(object sender, EventArgs e)
|
|
{
|
|
wordDocumentTable1.CreateTable(new WordTableWithData<PersonWordTable>
|
|
{
|
|
FileName = "C://Users//niyaz//OneDrive//Äîêóìåíòû//HeaderTable.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, "Division", "Id"),
|
|
(1, 0, "Surname", "Surname"),
|
|
(2, 0, "Name", "Name"),
|
|
(3, 0, "Age", "Age"),
|
|
(4, 0, "Premia", "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://Users//niyaz//OneDrive//Äîêóìåíòû//Diagram.docx",
|
|
Title = "Çàãîëîâîê",
|
|
ChartTitle = "Ãèñòîãðàììà",
|
|
LegendLocation = YunusovComponentsLibrary.OfficePackage.HelperEnum.WordDiagramLegendLocation.Top,
|
|
Series = new WordDiagramSeries
|
|
{
|
|
SeriesName = "Ãèñòîãðàììà",
|
|
Data = new Dictionary<string, double>
|
|
{
|
|
{ "Windows", 71 },
|
|
{ "OS X", 15.5 },
|
|
{ "Linux", 4.5 },
|
|
{ "Others", 8.5 },
|
|
}
|
|
}
|
|
});
|
|
MessageBox.Show("Word äîêóìåíò ñ äèàãðàììîé ñîçäàí!", "Óñïåõ");
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
MessageBox.Show($"Îøèáêà: {ex.Message}");
|
|
}
|
|
}
|
|
#endregion
|
|
}
|
|
} |