PIbd-33_Abazov_A.A._KOP_29/AbazovApp/AbazovAppView/FormTest.cs

181 lines
7.4 KiB
C#
Raw Normal View History

2023-09-19 22:32:09 +04:00
using AbazovViewComponents.Components;
2023-09-21 18:50:11 +04:00
using AbazovViewComponents.Exceptions;
2023-10-15 15:18:36 +04:00
using AbazovViewComponents.LogicalComponents;
2023-09-19 22:32:09 +04:00
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
2023-10-15 15:18:36 +04:00
using System.Reflection;
2023-09-19 22:32:09 +04:00
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace AbazovAppView
{
public partial class FormTest : Form
{
public FormTest()
{
InitializeComponent();
}
private void buttonAdd_Click(object sender, EventArgs e)
{
Random random = new Random();
List<string> items = new List<string>();
for (int i = 0; i < 3; i++)
{
items.Add("item" + random.Next(0, 10000));
}
abazovCheckedListBox.addItems(items);
abazovCheckedListBox.selectedItem = items[1];
}
private void abazovCheckedListBox_SelectedItemChange(string obj)
{
MessageBox.Show(obj, "Select event");
}
private void buttonClear_Click(object sender, EventArgs e)
{
abazovCheckedListBox.clear();
}
private void buttonSelected_Click(object sender, EventArgs e)
{
MessageBox.Show(abazovCheckedListBox.selectedItem ?? "null", "By getter");
}
2023-09-21 18:50:11 +04:00
private void buttonBoundries_Click(object sender, EventArgs e)
{
abazovDatePicker.dateFrom = new DateTime(1970, 01, 01);
abazovDatePicker.dateTo = new DateTime(2010, 01, 01);
}
private void buttonSetDate_Click(object sender, EventArgs e)
{
var result = MessageBox.Show("Установить значение в границах?", "Выбор", MessageBoxButtons.YesNo);
if (result == DialogResult.Yes)
{
abazovDatePicker.Value = new DateTime(2000, 01, 01);
}
else
{
abazovDatePicker.Value = new DateTime(1900, 01, 01);
}
}
private void abazovDatePicker_DateChange(object sender, EventArgs e)
{
MessageBox.Show("ok");
}
private void abazovDatePicker_DateChange(DateTime obj)
{
MessageBox.Show(obj.ToShortDateString(), "Date change event");
}
private void buttonGetDate_Click(object sender, EventArgs e)
{
try
{
2023-09-25 20:52:43 +04:00
DateTime? date = abazovDatePicker.Value;
2023-09-21 18:50:11 +04:00
MessageBox.Show(date.ToString(), "Через свойство");
}
catch (DateBoundsNotSetException ex)
{
MessageBox.Show(ex.Message);
}
catch (DateOutOfBoundsException ex)
{
MessageBox.Show(ex.Message);
}
}
2023-09-21 21:05:38 +04:00
private void buttonSetHierarchy_Click(object sender, EventArgs e)
{
abazovTreeView.setHierarchy(new List<(string, bool)>() { ("department", false), ("groupNumber", false), ("name", true) });
}
private void buttonAddWorkers_Click(object sender, EventArgs e)
{
List<Worker> workers = new List<Worker>();
workers.Add(new Worker("Отдел 1", 1, "Иванов"));
workers.Add(new Worker("Отдел 1", 1, "Петров"));
workers.Add(new Worker("Отдел 1", 1, "Иванов"));
workers.Add(new Worker("Отдел 1", 2, "Иванов"));
workers.Add(new Worker("Отдел 2", 1, "Иванов"));
workers.Add(new Worker("Отдел 2", 1, "Иванов"));
workers.Add(new Worker("Отдел 2", 1, "Петров"));
workers.Add(new Worker("Отдел 2", 2, "Иванов"));
abazovTreeView.addItems(workers);
}
private void buttonGetValue_Click(object sender, EventArgs e)
{
Worker? worker = abazovTreeView.getSelecetedNodeValue<Worker>();
2023-09-21 21:05:38 +04:00
if (worker == null) return;
MessageBox.Show(worker.department + ", номер группы: " + worker.groupNumber + ", " + worker.name);
}
private void buttonGetIndex_Click(object sender, EventArgs e)
{
MessageBox.Show(abazovTreeView.SelectedNodeIndex.ToString());
}
private void buttonSetIndex_Click(object sender, EventArgs e)
{
abazovTreeView.SelectedNodeIndex = 0;
}
2023-10-15 15:18:36 +04:00
private void buttonExcelImages_Click(object sender, EventArgs e)
{
var res = openFileDialog.ShowDialog(this);
if (res != DialogResult.OK) return;
var files = openFileDialog.FileNames;
openFileDialog.Dispose();
List<Bitmap> images = new List<Bitmap>();
string path = AppDomain.CurrentDomain.BaseDirectory + "test.xlsx";
2023-10-19 22:11:11 +04:00
if (excelImagesComponent.createWithImages(path, "Header", files)) MessageBox.Show("Успех!");
2023-10-15 15:18:36 +04:00
else MessageBox.Show("Ошибка, проверьте консоль");
}
2023-10-15 18:07:28 +04:00
private void buttonExcelTable_Click(object sender, EventArgs e)
{
List<OfficeWorker> workers = new List<OfficeWorker>();
workers.Add(new OfficeWorker(1, "Иванов", "Иван", 20, "Отдел продаж", "Бухгалтер", 25, "+7(834)234-03-49"));
workers.Add(new OfficeWorker(1, "Петров", "Петр", 25, "Отдел продаж", "Менеджер", 20, "+7(834)123-03-49"));
workers.Add(new OfficeWorker(1, "Сидоров", "Сергей", 27, "Отдел кадров", "HR", 2, "+7(834)593-03-49", true));
string path = AppDomain.CurrentDomain.BaseDirectory + "test.xlsx";
List<(int, int)> merges = new List<(int, int)>();
merges.Add((1, 3));
merges.Add((4, 6));
List<int> heights = Enumerable.Repeat(20, 9).ToList();
List<(string, string)> headers = new List<(string, string)> { ("id", "id"), ("", "Личные данные"),
("lastName", "Фамилия"), ("firstName", "Имя"),
("age", "Возраст"), ("", "Работа"),
("department", "Отдел"), ("position", "Должность"),
("boxNumber", "Номер бокса"), ("phoneNumber", "Телефон"),
("isInVacation", "В отпуске"), };
if (excelTableComponent.createWithTable(path, "test", merges, heights, headers, workers)) MessageBox.Show("Успех");
}
2023-10-19 22:07:56 +04:00
private void buttonExcelDiagram_Click(object sender, EventArgs e)
{
List<Department> departments = new List<Department>();
departments.Add(new Department("Dep 1", 330));
departments.Add(new Department("Dep 2", 500));
departments.Add(new Department("Dep 3", 170));
string path = AppDomain.CurrentDomain.BaseDirectory + "test.xlsx";
if (excelDiagramComponent.createWithDiagram(path, "test", "Продажи", DiagramLegendEnum.TopRight, departments, "name", "sells")) MessageBox.Show("Успех");
else MessageBox.Show("Fail :(");
}
2023-09-19 22:32:09 +04:00
}
}