private Product createComputerProduct() { // pop a AddComputerDialog. If return is cancel, give up // if return is dialog ok, try to create a computer object // return that reference AddComputerProductDialog acpd = new AddComputerProductDialog(); DialogResult result; result = acpd.ShowDialog(); if (result != DialogResult.OK) { return(null); } Product p = new Computer(acpd.ProductName, acpd.ProductID, acpd.ProductCost, acpd.InitialQuantity, acpd.RamSize, acpd.CPUSpeed); return(p); }
private void EditComputerProduct(int index) { // create a dialog and configure for edit AddComputerProductDialog acpd = new AddComputerProductDialog(); acpd.EditMode = true; Computer c = (Computer)productInventory[index]; acpd.ProductName = c.ProductName; acpd.ProductID = c.ID; acpd.ProductCost = c.Cost; acpd.InitialQuantity = c.QuantityOnHand; acpd.RamSize = c.RamSize; acpd.CPUSpeed = c.CpuSpeed; // show the dialog and wait for an OK. DialogResult result = acpd.ShowDialog(); // if answer was OK update the product inventory with the new values and update display if (result != DialogResult.OK) { return; } Product p = new Computer(acpd.ProductName, acpd.ProductID, acpd.ProductCost, acpd.InitialQuantity, acpd.RamSize, acpd.CPUSpeed); productInventory[index] = p; productListListbox.Items[index] = p.ToFormattedString(); }