private void ModifyProductButton_Click(object sender, EventArgs e) { DataGridViewRow selectedRow = ProductsDataGrid.SelectedRows[0]; int productID = Convert.ToInt32(selectedRow.Cells["ProductID"].Value); Product product = Inventory.LookupProduct(productID); EditProduct productForm = new EditProduct(product) { MdiParent = this.MdiParent }; productForm.Show(); }
private void CreateDummyData() { // Dummy Data Inventory.AddPart(new Inhouse("Small Wheel", 5.00, 50, 0, 100, 1)); Inventory.AddPart(new Inhouse("Small Frame", 23.45, 40, 0, 300, 2)); Inventory.AddPart(new Outsourced("Handle Bars", 12.10, 75, 0, 200, "Acme Co.")); Inventory.AddPart(new Inhouse("Large Wheel", 10.00, 2, 0, 100, 1)); Inventory.AddPart(new Inhouse("Large Frame", 27.85, 40, 3, 300, 2)); Inventory.AddProduct(new Product("Kids Bike", 100.00, 37, 0, 100, new ArrayList())); Inventory.AddProduct(new Product("Adult Bike", 135.00, 67, 0, 100, new ArrayList())); Inventory.AddProduct(new Product("Repair Kit", 15, 15, 1, 25, new ArrayList())); Product p1 = Inventory.LookupProduct(0); Product p2 = Inventory.LookupProduct(1); p1.AddAssociatedPart(Inventory.LookupPart(0)); p1.AddAssociatedPart(Inventory.LookupPart(0)); p1.AddAssociatedPart(Inventory.LookupPart(1)); p1.AddAssociatedPart(Inventory.LookupPart(2)); p2.AddAssociatedPart(Inventory.LookupPart(3)); p2.AddAssociatedPart(Inventory.LookupPart(3)); p2.AddAssociatedPart(Inventory.LookupPart(4)); p2.AddAssociatedPart(Inventory.LookupPart(2)); }
private void DeleteProductButton_Click(object sender, EventArgs e) { DataGridViewRow selectedRow = ProductsDataGrid.SelectedRows[0]; int productID = Convert.ToInt32(selectedRow.Cells["ProductID"].Value); Product productToDelete = Inventory.LookupProduct(productID); try { if (productToDelete.GetAssociatedParts().Count > 0) { throw new Exception(); } Inventory.RemoveProduct(productID); RefreshDataGridViews(); } catch (Exception) { MessageBox.Show("Cannot delete product with parts associated"); return; } Inventory.RemoveProduct(productID); RefreshDataGridViews(); }