PIbd-33_Abazov_A.A._KOP_29/AbazovApp/AbazovAppView/FormTest.cs
2023-10-19 22:11:11 +04:00

181 lines
7.4 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using AbazovViewComponents.Components;
using AbazovViewComponents.Exceptions;
using AbazovViewComponents.LogicalComponents;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Reflection;
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");
}
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
{
DateTime? date = abazovDatePicker.Value;
MessageBox.Show(date.ToString(), "Через свойство");
}
catch (DateBoundsNotSetException ex)
{
MessageBox.Show(ex.Message);
}
catch (DateOutOfBoundsException ex)
{
MessageBox.Show(ex.Message);
}
}
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>();
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;
}
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";
if (excelImagesComponent.createWithImages(path, "Header", files)) MessageBox.Show("Успех!");
else MessageBox.Show("Ошибка, проверьте консоль");
}
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("Успех");
}
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 :(");
}
}
}