PIbd-31_Shanygin.A.V._COP_27/ComponentOrientedProgramming/WinFormsTest/Form1.cs

209 lines
6.9 KiB
C#
Raw Normal View History

2024-09-09 22:02:46 +04:00
using CreateVisualComponent;
using Microsoft.VisualBasic.Devices;
2024-09-19 19:34:15 +04:00
using NotVisualComponent;
using NotVisualComponent.Models;
2024-09-09 22:02:46 +04:00
using static System.Windows.Forms.VisualStyles.VisualStyleElement.Header;
namespace WinFormsTest
{
public partial class Form1 : Form
{
private bool EmptyFill = false;
int count = 1;
public Form1()
{
InitializeComponent();
CreateList();
}
private void CreateList()
{
for (int i = 0; i < 10; i++)
{
SelectionComponent.Items.Add($"Food <20>{i}");
}
}
private void ButtonListClear_Click(object sender, EventArgs e)
{
SelectionComponent.Clear();
}
private void ButtonListLoad_Click(object sender, EventArgs e)
{
SelectionComponent.Clear();
CreateList();
}
private void SelectionComponent_ChangeEvent(object sender, EventArgs e)
{
object? selectedItem = SelectionComponent.SelectedElement;
MessageBox.Show($"Change selected {selectedItem?.ToString()}");
}
private void InputComponent_CheckBoxEvent(object sender, EventArgs e)
{
count++;
if (count % 2 == 0)
{
textBoxEvent.Text = "null";
}
else
{
textBoxEvent.Text = "not null";
}
}
private void ButtonGet_Click(object sender, EventArgs e)
{
try
{
if (InputComponent.Value == null)
{
2024-09-19 19:34:15 +04:00
MessageBox.Show($"Pressed Checkbox");
2024-09-09 22:02:46 +04:00
}
else
{
MessageBox.Show($"Date: {InputComponent.Value}");
}
}
catch (Exception ex)
{
MessageBox.Show($"Error: {ex.Message}");
}
}
private void ButtonSet_Click(object sender, EventArgs e)
{
if (EmptyFill)
{
InputComponent.Value = DateTime.Now;
}
else
{
InputComponent.Value = null;
}
EmptyFill = !EmptyFill;
}
readonly List<Delivery> delivers = new()
{
new Delivery { Id = 0, Name = "<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>", DeliveryStatus = "<22><><EFBFBD><EFBFBD><EFBFBD>", CountProduct = 5 },
new Delivery { Id = 1, Name = "<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>", DeliveryStatus = "<22><><EFBFBD><EFBFBD><EFBFBD>", CountProduct = 3 },
new Delivery { Id = 2, Name = "<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>", DeliveryStatus = "<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>", CountProduct = 7 },
new Delivery { Id = 3, Name = "<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>", DeliveryStatus = "<22> <20><><EFBFBD><EFBFBD>", CountProduct = 4 },
new Delivery { Id = 4, Name = "<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>", DeliveryStatus = "<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>", CountProduct = 5 }
};
private void CreateTable()
{
2024-10-13 16:15:32 +04:00
var config = new ColumnsConfiguratoin();
config.Columns.Add(new ColumnConfig
{
ColumnName = "Id",
Width = 10,
Visible = false,
PropertyObject = "Id"
});
config.Columns.Add(new ColumnConfig
{
ColumnName = "Name",
Width = 150,
Visible = true,
PropertyObject = "Name"
});
config.Columns.Add(new ColumnConfig
2024-09-09 22:02:46 +04:00
{
2024-10-13 16:15:32 +04:00
ColumnName = "DeliveryStatus",
Width = 250,
Visible = true,
PropertyObject = "DeliveryStatus"
});
config.Columns.Add(new ColumnConfig
{
ColumnName = "CountProduct",
Width = 200,
Visible = true,
PropertyObject = "CountProduct"
2024-09-09 22:02:46 +04:00
});
2024-10-13 16:15:32 +04:00
ListOutputComponent.ConfigColumn(config);
2024-09-09 22:02:46 +04:00
foreach (Delivery delivery in delivers)
{
for (int i = 0; i < 4; i++)
{
ListOutputComponent.AddItem(delivery, delivery.Id, i);
}
}
2024-10-13 16:15:32 +04:00
ListOutputComponent.Update();
2024-09-09 22:02:46 +04:00
}
private void ButtonShowTable_Click(object sender, EventArgs e)
{
CreateTable();
}
private void ButtonClearTable_Click(object sender, EventArgs e)
{
ListOutputComponent.ClearDataGrid();
}
private void ButtonGetString_Click(object sender, EventArgs e)
{
Delivery? delivery = ListOutputComponent.GetSelectedObjectInRow<Delivery>();
if (delivery is null) return;
MessageBox.Show($"{delivery.Id}-{delivery.Name}-{delivery.DeliveryStatus}-{delivery.CountProduct}");
}
2024-09-19 19:34:15 +04:00
private void buttonExcel_Click(object sender, EventArgs e)
{
excelTable.CreateDoc(new TableConfig
{
FilePath = "C:\\Users\\sshan\\OneDrive\\Desktop\\PathKOP\\Excel1.xlsx",
Header = "Example",
Data = new List<string[,]>
{
new string[,] {
{ "1", "1", "1" },
{ "1", "2", "2" },
{ "1", "3", "3" }
2024-10-13 16:15:32 +04:00
},
new string[,] {
{ "2", "1", "1" },
{ "2", "2", "2" },
{ "2", "3", "3" }
2024-09-19 19:34:15 +04:00
}
}
});
}
private void buttonHardExcelSave_Click(object sender, EventArgs e)
{
excelHardTable.CreateDoc(new TableWithHeaderConfig<Delivery>
{
FilePath = "C:\\Users\\sshan\\OneDrive\\Desktop\\PathKOP\\Excel2.xlsx",
2024-10-13 16:15:32 +04:00
Header = "Delivers",
2024-09-19 19:34:15 +04:00
ColumnsRowsWidth = new List<(int Column, int Row)> { (5, 5), (10, 5), (10, 0), (5, 0), (7, 0) },
Headers = new List<(int ColumnIndex, int RowIndex, string Header, string PropertyName)>
{
(0, 0, "Id", "Id"),
2024-10-13 16:15:32 +04:00
(1, 0, "Name", "Name"),
(2, 0, "DeliveryStatus", "DeliveryStatus"),
(3, 0, "CountProduct", "CountProduct"),
2024-09-19 19:34:15 +04:00
},
2024-10-13 16:15:32 +04:00
Data = delivers
2024-09-19 19:34:15 +04:00
});
}
private void buttonDiagramSave_Click(object sender, EventArgs e)
{
excelDiagram.CreateDoc(new ChartConfig
{
FilePath = "C:\\Users\\sshan\\OneDrive\\Desktop\\PathKOP\\Excel3.xlsx",
Header = "Chart",
2024-10-13 16:15:32 +04:00
ChartTitle = "Gistogram",
LegendLocation = NotVisualComponent.Models.Location.Bottom,
2024-09-19 19:34:15 +04:00
Data = new Dictionary<string, List<(string Name, double Value)>>
{
2024-10-13 16:15:32 +04:00
{ "Series 1", new() { ("Orange", 150), ("Apple", 200), ("Lime", 300) } }
2024-09-19 19:34:15 +04:00
}
});
}
2024-09-09 22:02:46 +04:00
}
}