PIbd-31_Kryukov.A.I._COP_9/COP/Test/Form1.cs

172 lines
5.6 KiB
C#
Raw Normal View History

2024-10-06 14:23:43 +04:00
using KryukovLib.Models;
2024-09-22 10:42:52 +04:00
using KryukovLib;
using Microsoft.VisualBasic.Devices;
namespace Test
{
public partial class Form1 : Form
{
private bool EmptyFill = false;
readonly List<Car> cars = new()
{
2024-10-06 14:23:43 +04:00
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 }
2024-09-22 10:42:52 +04:00
};
public Form1()
{
InitializeComponent();
CreateList();
}
2024-10-06 14:23:43 +04:00
2024-09-22 10:42:52 +04:00
private void CreateList()
{
2024-10-06 14:23:43 +04:00
for (int i = 0; i < 10; i++)
{
customListBox1.ItemCollection.Add($"Item-{i}");
}
2024-09-22 10:42:52 +04:00
}
private void CreateTable()
{
2024-10-06 14:23:43 +04:00
customDataGridView1.ClearDataGrid();
customDataGridView1.ConfigColumn(new ColumnsConfiguratoin
2024-09-22 10:42:52 +04:00
{
ColumnsCount = 4,
NameColumn = new string[] { "Id", "marka", "weight", "maxSpeed" },
2024-10-06 14:23:43 +04:00
Width = new int[] { 50, 150, 150, 150 },
Visible = new bool[] { true, true, true, true },
2024-09-22 10:42:52 +04:00
PropertiesObject = new string[] { "Id", "marka", "weight", "maxSpeed" }
});
2024-10-06 14:23:43 +04:00
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
2024-09-22 10:42:52 +04:00
foreach (Car car in cars)
{
2024-10-06 14:23:43 +04:00
customDataGridView1.AddItem(car, customDataGridView1.Rows.Count);
2024-09-22 10:42:52 +04:00
}
}
2024-10-06 14:23:43 +04:00
private void ButtonListClear_Click(object sender, EventArgs e)
2024-09-22 10:42:52 +04:00
{
customListBox1.ClearList();
}
2024-10-06 14:23:43 +04:00
private void ButtonLoadList_Click(object sender, EventArgs e)
2024-09-22 10:42:52 +04:00
{
CreateList();
}
2024-10-06 14:23:43 +04:00
private void CustomListBox_ChangeEvent(object sender, EventArgs e)
2024-09-22 10:42:52 +04:00
{
2024-10-06 14:23:43 +04:00
object? selectedItem = customListBox1.SelectedValue;
MessageBox.Show($"Change selected item {selectedItem?.ToString()}");
2024-09-22 10:42:52 +04:00
}
2024-10-06 14:23:43 +04:00
private void ButtonGetValue_Click(object sender, EventArgs e)
2024-09-22 10:42:52 +04:00
{
MessageBox.Show($"Value is {dateBoxWithNull1.Value}");
}
2024-10-06 14:23:43 +04:00
private void ButtonSetValue_Click(object sender, EventArgs e)
2024-09-22 10:42:52 +04:00
{
if (EmptyFill)
{
dateBoxWithNull1.Value = DateTime.Now;
}
else
{
dateBoxWithNull1.Value = null;
}
EmptyFill = !EmptyFill;
}
2024-10-06 14:23:43 +04:00
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()) };
2024-10-06 14:23:43 +04:00
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 }
2024-10-06 14:23:43 +04:00
}
});
(sender as Control).BackColor = Color.Green;
}
2024-09-22 10:42:52 +04:00
}
}