172 lines
5.6 KiB
C#
172 lines
5.6 KiB
C#
using KryukovLib.Models;
|
|
using KryukovLib;
|
|
using Microsoft.VisualBasic.Devices;
|
|
|
|
namespace Test
|
|
{
|
|
public partial class Form1 : Form
|
|
{
|
|
private bool EmptyFill = false;
|
|
readonly List<Car> cars = new()
|
|
{
|
|
new Car { Id = 0, marka = "Nissan", weight = 1500, maxSpeed = 150 },
|
|
new Car { Id = 1, marka = "Cadillac", weight = 1600, maxSpeed = 200 },
|
|
new Car { Id = 2, marka = "Toyota", weight = 1700, maxSpeed = 180 },
|
|
new Car { Id = 3, marka = "Opel", weight = 1200, maxSpeed = 160 },
|
|
new Car { Id = 4, marka = "Audi", weight = 1300, maxSpeed = 280 }
|
|
};
|
|
|
|
public Form1()
|
|
{
|
|
InitializeComponent();
|
|
CreateList();
|
|
}
|
|
|
|
private void CreateList()
|
|
{
|
|
for (int i = 0; i < 10; i++)
|
|
{
|
|
customListBox1.ItemCollection.Add($"Item-{i}");
|
|
}
|
|
}
|
|
|
|
private void CreateTable()
|
|
{
|
|
customDataGridView1.ClearDataGrid();
|
|
|
|
customDataGridView1.ConfigColumn(new ColumnsConfiguratoin
|
|
{
|
|
ColumnsCount = 4,
|
|
NameColumn = new string[] { "Id", "marka", "weight", "maxSpeed" },
|
|
Width = new int[] { 50, 150, 150, 150 },
|
|
Visible = new bool[] { true, true, true, true },
|
|
PropertiesObject = new string[] { "Id", "marka", "weight", "maxSpeed" }
|
|
});
|
|
|
|
// Äîáàâëÿåì äàííûå äëÿ êàæäîé ìàøèíû
|
|
foreach (Car car in cars)
|
|
{
|
|
customDataGridView1.AddItem(car, customDataGridView1.Rows.Count);
|
|
}
|
|
}
|
|
|
|
|
|
private void ButtonListClear_Click(object sender, EventArgs e)
|
|
{
|
|
customListBox1.ClearList();
|
|
}
|
|
|
|
private void ButtonLoadList_Click(object sender, EventArgs e)
|
|
{
|
|
CreateList();
|
|
}
|
|
|
|
private void CustomListBox_ChangeEvent(object sender, EventArgs e)
|
|
{
|
|
object? selectedItem = customListBox1.SelectedValue;
|
|
MessageBox.Show($"Change selected item {selectedItem?.ToString()}");
|
|
}
|
|
|
|
private void ButtonGetValue_Click(object sender, EventArgs e)
|
|
{
|
|
MessageBox.Show($"Value is {dateBoxWithNull1.Value}");
|
|
}
|
|
|
|
private void ButtonSetValue_Click(object sender, EventArgs e)
|
|
{
|
|
if (EmptyFill)
|
|
{
|
|
dateBoxWithNull1.Value = DateTime.Now;
|
|
}
|
|
else
|
|
{
|
|
dateBoxWithNull1.Value = null;
|
|
}
|
|
EmptyFill = !EmptyFill;
|
|
}
|
|
|
|
private void ButtonAdd_Click(object sender, EventArgs e)
|
|
{
|
|
CreateTable();
|
|
}
|
|
|
|
private void ButtonClear_Click(object sender, EventArgs e)
|
|
{
|
|
customDataGridView1.ClearDataGrid();
|
|
}
|
|
|
|
private void ButtonSel_Click(object sender, EventArgs e)
|
|
{
|
|
Car? car = customDataGridView1.GetSelectedObjectInRow<Car>();
|
|
if (car is null) return;
|
|
MessageBox.Show($"{car.Id}-{car.marka}-{car.weight}-{car.maxSpeed}");
|
|
}
|
|
|
|
private void buttonExcel_Click(object sender, EventArgs e)
|
|
{
|
|
(sender as Control).BackColor = Color.White;
|
|
excelTable1.CreateDoc(new KryukovLib.Models.TableConfig
|
|
{
|
|
FilePath = "table.xlsx",
|
|
Header = "Example",
|
|
Data = new List<string[,]>
|
|
{
|
|
new string[,] {
|
|
{ "1", "1", "1" },
|
|
{ "1", "2", "2" },
|
|
{ "1", "3", "3" }
|
|
},
|
|
new string[,] { { "\n",} },
|
|
new string[,] {
|
|
{ "2", "3", "3" },
|
|
{ "3", "4", "4" },
|
|
{ "4", "5", "5" },
|
|
}
|
|
}
|
|
|
|
});
|
|
|
|
(sender as Control).BackColor = Color.Green;
|
|
}
|
|
|
|
private void excelSaveHeader_Click(object sender, EventArgs e)
|
|
{
|
|
(sender as Control).BackColor = Color.White;
|
|
excelWithCustomTable1.CreateDoc(new KryukovLib.Models.TableWithHeaderConfig<Car>
|
|
{
|
|
FilePath = "header.xlsx",
|
|
Header = "Cars",
|
|
ColumnsRowsWidth = new List<(int Column, int Row)> { (5, 5), (10, 5), (10, 0), (5, 0), (7, 0) },
|
|
Headers = new List<(int ColumnIndex, string Header, string PropertyName)>
|
|
{
|
|
(0, "Id", "Id"),
|
|
(1, "marka", "marka"),
|
|
(2, "weight", "weight"),
|
|
(3, "maxSpeed", "maxSpeed"),
|
|
},
|
|
Data = cars,
|
|
});
|
|
(sender as Control).BackColor = Color.Green;
|
|
}
|
|
|
|
private void SaveBar_Click(object sender, EventArgs e)
|
|
{
|
|
(sender as Control).BackColor = Color.White;
|
|
var rnd = new Random();
|
|
var list2d = new List<(string Name, double value)>() { ("Series 2", rnd.Next()), ("Series 3", rnd.Next()), ("Series 52", rnd.Next()) };
|
|
excelGistogram1.CreateDoc(new ChartConfig
|
|
{
|
|
FilePath = "bar.xlsx",
|
|
Header = "Chart",
|
|
ChartTitle = "BarChart",
|
|
LegendLocation = KryukovLib.Models.Location.Top,
|
|
Data = new Dictionary<string, List<(string Name, double Value)>>
|
|
{
|
|
{ "Series 1", list2d }
|
|
}
|
|
});
|
|
(sender as Control).BackColor = Color.Green;
|
|
}
|
|
}
|
|
}
|