PIbd-31_Rodionov.I.A._COP_28/COP/WinForms/FormTest.cs

208 lines
10 KiB
C#

using RodionovLibrary.NonVisualComponents.HelperEnums;
using RodionovLibrary.NonVisualComponents.HelperModels;
namespace WinForms
{
public partial class FormTest : Form
{
public FormTest()
{
InitializeComponent();
comboBoxControl.AddItems(new List<string> { "Çíà÷åíèå 1", "Çíà÷åíèå 2", "Çíà÷åíèå 3", "Çíà÷åíèå 4", "Çíà÷åíèå 5" });
textBoxControl.Pattern = @"^[a-z0-9._%+-]+\@([a-z0-9-]+\.)+[a-z]{2,4}$";
textBoxControl.SetTooltipText("example@gmail.com");
listBoxControl.SetParams("Èìÿ: {FirstName}, ôàìèëèÿ: {LastName}. {Gender} ({Age}) ëåò.", '{', '}');
listBoxControl.AddItems(new List<Person> { new() { FirstName = "Êèðèëë", LastName = "Ïåòðîâ", Age = 23, Gender = "ìóæ" },
new() { FirstName = "Ìàðèÿ", LastName = "Èâàíîâà", Age = 18, Gender = "æåí" },
new() { FirstName = "Åâà", LastName = "Ïàíôèëîâà", Age = 40, Gender = "æåí" } });
}
private void ButtonClear_Click(object sender, EventArgs e)
{
comboBoxControl.Clear();
}
private void ButtonGetComboBox_Click(object sender, EventArgs e)
{
MessageBox.Show(comboBoxControl.SelectedValue, "Ïîëó÷åííîå çíà÷åíèå");
}
private void ButtonSetComboBox_Click(object sender, EventArgs e)
{
comboBoxControl.SelectedValue = "Çíà÷åíèå 3";
}
private void ButtonGetTextBox_Click(object sender, EventArgs e)
{
MessageBox.Show(textBoxControl.Value, "Ïîëó÷åííîå çíà÷åíèå");
}
private void ButtonSetTextBox_Click(object sender, EventArgs e)
{
textBoxControl.Value = "forum98761@gmail.com";
}
private void ButtonSetWrongTextBox_Click(object sender, EventArgs e)
{
textBoxControl.Value = "smth";
}
private void ButtonGetObject_Click(object sender, EventArgs e)
{
Person? selectedPerson = listBoxControl.GetObject<Person>();
if (selectedPerson == null)
MessageBox.Show("Îáüåêò ïóñòîé");
MessageBox.Show($"Èìÿ: {selectedPerson?.FirstName}, Ôàìèëèÿ: {selectedPerson?.LastName}, " +
$"Âîçðàñò: {selectedPerson?.Age}, Ïîë: {selectedPerson?.Gender}");
}
private void ButtonGetIndex_Click(object sender, EventArgs e)
{
MessageBox.Show(listBoxControl.SelectedIndex.ToString(), "Ïîëó÷åííîå çíà÷åíèå");
}
private void ButtonSetIndex_Click(object sender, EventArgs e)
{
listBoxControl.SelectedIndex = 0;
}
private void ButtonWordText_Click(object sender, EventArgs e)
{
using var dialog = new SaveFileDialog
{
Filter = "docx|*.docx"
};
if (dialog.ShowDialog() == DialogResult.OK)
{
try
{
wordLongTextComponent.CreateWordText(new WordLongTextInfo()
{
FileName = dialog.FileName,
Title = "ÃËÀÂÀ 1. Íåæäàííûå ãîñòè",
Paragraphs = new string[] { "Æèë-áûë â íîðå ïîä çåìëåé õîááèò. Íå â êàêîé-òî òàì ìåðçêîé ãðÿçíîé ñûðîé íîðå, ãäå ñî âñåõ ñòîðîí òîð÷àò õâîñòû ÷åðâåé è ïðîòèâíî ïàõíåò ïëåñåíüþ, íî è íå â ñóõîé ïåñ÷àíîé ãîëîé íîðå, ãäå íå íà ÷òî ñåñòü è íå÷åãî ñúåñòü. Íåò, íîðà áûëà õîááè÷üÿ, à çíà÷èò — áëàãîóñòðîåííàÿ.",
"Îíà íà÷èíàëàñü èäåàëüíî êðóãëîé, êàê èëëþìèíàòîð, äâåðüþ, âûêðàøåííîé çåëåíîé êðàñêîé, ñ ñèÿþùåé ìåäíîé ðó÷êîé òî÷íî ïîñåðåäèíå. Äâåðü îòâîðÿëàñü âíóòðü, â äëèííûé êîðèäîð, ïîõîæèé íà æåëåçíîäîðîæíûé òóííåëü, íî òóííåëü áåç ãàðè è áåç äûìà è òîæå î÷åíü áëàãîóñòðîåííûé: ñòåíû òàì áûëè îáøèòû ïàíåëÿìè, ïîë âûëîæåí ïëèòêàìè è óñòëàí êîâðîì, âäîëü ñòåí ñòîÿëè ïîëèðîâàííûå ñòóëüÿ, è âñþäó áûëè ïðèáèòû êðþ÷î÷êè äëÿ øëÿï è ïàëüòî, òàê êàê õîááèò ëþáèë ãîñòåé.",
"Òóííåëü âèëñÿ âñå äàëüøå è äàëüøå è çàõîäèë äîâîëüíî ãëóáîêî, íî íå â ñàìóþ ãëóáèíó Õîëìà, êàê åãî èìåíîâàëè æèòåëè íà ìíîãî ìèëü â îêðóæíîñòè. Ïî îáåèì ñòîðîíàì òóííåëÿ øëè äâåðè — ìíîãî-ìíîãî êðóãëûõ äâåðåé. Õîááèò íå ïðèçíàâàë âîñõîæäåíèé ïî ëåñòíèöàì: ñïàëüíè, âàííûå, ïîãðåáà, êëàäîâûå (öåëàÿ êó÷à êëàäîâûõ), ãàðäåðîáíûå (õîááèò îòâåë íåñêîëüêî êîìíàò ïîä õðàíåíèå îäåæäû), êóõíè, ñòîëîâûå ðàñïîëàãàëèñü â îäíîì ýòàæå è, áîëåå òîãî, â îäíîì è òîì æå êîðèäîðå.",
"Ëó÷øèå êîìíàòû íàõîäèëèñü ïî ëåâóþ ðóêó, è òîëüêî â íèõ èìåëèñü îêíà — ãëóáîêî ñèäÿùèå êðóãëûå îêîøå÷êè ñ âèäîì íà ñàä è íà äàëüíèå ëóãà, ñïóñêàâøèåñÿ ê ðåêå."}
});
MessageBox.Show("Ãîòîâî!");
}
catch (Exception ex)
{
MessageBox.Show("Ïðîèçîøëà îøèáêà: " + ex.Message, "Îøèáêà", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
private void ButtonWordTable_Click(object sender, EventArgs e)
{
using var dialog = new SaveFileDialog
{
Filter = "docx|*.docx"
};
if (dialog.ShowDialog() == DialogResult.OK)
{
try
{
var columns = new List<ColumnParameters>
{
new() { FirstRowHeader = "Èäåíò", PropertyName = "Id", Width = 1.3 },
new() { FirstRowHeader = "Ñòàòóñ", PropertyName = "Status", Width = 1.3 },
new() { FirstRowHeader = "Ëè÷íûå äàííûå", SecondRowHeader = "Èìÿ", PropertyName = "FirstName", Width = 1.7 },
new() { FirstRowHeader = "Ëè÷íûå äàííûå", SecondRowHeader = "Ôàìèëèÿ", PropertyName = "LastName", Width = 1.7 },
new() { FirstRowHeader = "Ëè÷íûå äàííûå", SecondRowHeader = "Âîçðàñò", PropertyName = "Age", Width = 1.7 },
new() { FirstRowHeader = "Äåòè", PropertyName = "Children", Width = 1.3 },
new() { FirstRowHeader = "Ìàøèíà", PropertyName = "Car", Width = 1.7 },
new() { FirstRowHeader = "Ðàáîòà", SecondRowHeader = "Ïîäðàçäåëåíèå", PropertyName = "Department", Width = 2.4 },
new() { FirstRowHeader = "Ðàáîòà", SecondRowHeader = "Äîëæíîñòü", PropertyName = "Position", Width = 2.4 },
new() { FirstRowHeader = "Ïðåìèÿ", PropertyName = "Bonus", Width = 2 }
};
var employees = new List<Employee>
{
new() { Id = 1, Status = "íåò", FirstName = "Èâàí", LastName = "Èâàíîâ", Age = 34, Children = "íåò", Car = "åñòü", Department = "Äåïàðòàìåíò 1", Position = "Èíæåíåð", Bonus = 2000.1 },
new() { Id = 2, Status = "íåò", FirstName = "Ïåòð", LastName = "Ïåòðîâ", Age = 44, Children = "åñòü", Car = "åñòü", Department = "Äåïàðòàìåíò 1", Position = "Èíæåíåð", Bonus = 2000.1 },
new() { Id = 3, Status = "äà", FirstName = "Ñåðãåé", LastName = "Ñåðãååâ", Age = 55, Children = "íåò", Car = "íåò", Department = "Äåïàðòàìåíò 1", Position = "Ðóêîâîäèòåëü", Bonus = 5000.5 },
new() { Id = 4, Status = "íåò", FirstName = "Îëüãà", LastName = "Èâàíîâà", Age = 34, Children = "åñòü", Car = "íåò", Department = "Áóõãàëòåðèÿ", Position = "Áóõãàëòåð", Bonus = 2000.1 },
new() { Id = 5, Status = "äà", FirstName = "Òàòüÿíà", LastName = "Ïåòðîâà", Age = 44, Children = "íåò", Car = "íåò", Department = "Áóõãàëòåðèÿ", Position = "Ñòàðøèé áóõãàëòåð", Bonus = 7000.6 }
};
var mergedColumns = new List<(int, int)>
{
(2, 4),
(7, 8)
};
var tableInfo = new WordTableInfo<Employee>
{
FileName = dialog.FileName,
Title = "Çàãîëîâîê",
ColumnParameters = columns,
Items = employees,
MergedColumns = mergedColumns
};
wordTableComponent.CreateTable(tableInfo);
MessageBox.Show("Ãîòîâî!");
}
catch (Exception ex)
{
MessageBox.Show("Ïðîèçîøëà îøèáêà: " + ex.Message, "Îøèáêà", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
private void ButtonWordDiagram_Click(object sender, EventArgs e)
{
using var dialog = new SaveFileDialog
{
Filter = "docx|*.docx"
};
if (dialog.ShowDialog() == DialogResult.OK)
{
try
{
var series = new List<SeriesParameters>
{
new() {
SeriesName = "Ñåðèÿ 1",
ValuesY = new List<double> { 10, 15, 20 },
Color = Color.FromArgb(255, 165, 0)
},
new() {
SeriesName = "Ñåðèÿ 2",
ValuesY = new List<double> { 45, 34, 18 },
Color = Color.FromArgb(105, 105, 105)
},
new() {
SeriesName = "Ñåðèÿ 3",
ValuesY = new List<double> { 25, 2, 7 },
Color = Color.FromArgb(255, 255, 0)
}
};
wordDiagramComponent.CreateDiagramDocument(new WordDiagramInfo()
{
FileName = dialog.FileName,
DocumentTitle = "Çàãîëîâîê",
DiagramTitle = "Òåñòîâàÿ äèàãðàììà",
LegendLayout = DiagramLegendLayout.Bottom,
CategoriesX = new List<string> { "ßíâàðü", "Ôåâðàëü", "Ìàðò" },
SeriesParameters = series
});
MessageBox.Show("Ãîòîâî!");
}
catch (Exception ex)
{
MessageBox.Show("Ïðîèçîøëà îøèáêà: " + ex.Message, "Îøèáêà", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
}
}