using Data; using Data.Repositories; using View; using System.Windows.Forms; using Data.Models; namespace Laba3 { public partial class MainForm : Form { private readonly IProductRepository _productRepository; private readonly IManufacturerRepository _manufacturerRepository; public MainForm(IProductRepository productRepository, IManufacturerRepository manufacturerRepository) { InitializeComponent(); _productRepository = productRepository; _manufacturerRepository = manufacturerRepository; InitializeOutputTableResults(); LoadProducts(); } private void InitializeOutputTableResults() { outputTableResults.ConfigureColumns(new List { new Library15Gerimovich.ColumnInfo("", 0, false, "Id"), new Library15Gerimovich.ColumnInfo("Name", 150, true, "Name"), new Library15Gerimovich.ColumnInfo("ManufacturerNameManufacturerName", 150, true, "ManufacturerName"), new Library15Gerimovich.ColumnInfo("DeliveryDate", 50, true, "DeliveryDate"), }); } private void LoadProducts() { var products = _productRepository.GetAllProducts(); outputTableResults.ClearGrid(); foreach (var product in products) { outputTableResults.InsertValue(product); } } private void addToolStripMenuItem_Click(object sender, EventArgs e) { var productForm = new ProductForm(_productRepository, _manufacturerRepository); if (productForm.ShowDialog() == DialogResult.OK) { LoadProducts(); } } private void editToolStripMenuItem_Click(object sender, EventArgs e) { var selectedProductId = outputTableResults.GetSelectedObject().Id; var selectedProduct = _productRepository.GetProductById(selectedProductId); var productForm = new ProductForm(_productRepository, _manufacturerRepository, selectedProduct); if (productForm.ShowDialog() == DialogResult.OK) { LoadProducts(); } } private void deleteToolStripMenuItem_Click(object sender, EventArgs e) { var selectedProductId = outputTableResults.GetSelectedObject().Id; if (MessageBox.Show("Are you sure you want to delete this product?", "Confirm", MessageBoxButtons.YesNo) == DialogResult.Yes) { _productRepository.DeleteProduct(selectedProductId); LoadProducts(); } } private void manufacturersToolStripMenuItem_Click(object sender, EventArgs e) { var manufacturerForm = new ManufacturerForm(_manufacturerRepository); manufacturerForm.ShowDialog(); } } }