PIbd-33_Abazov_A.A._KOP_29/AbazovApp/AbazovAppView/FormTest.cs
2023-10-15 15:18:36 +04:00

147 lines
5.1 KiB
C#

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";
MessageBox.Show(path);
if (excelImagesComponent.createWithImages(new ExcelImageInfo(path, "Header", files))) MessageBox.Show("Успех!");
else MessageBox.Show("Ошибка, проверьте консоль");
}
}
}