public void PlaceOrderClicked(object obj) { foreach (Object cartObject in Parent.CartContents) { if (cartObject is Pets) { Pets pet = cartObject as Pets; int difference = pet.Stock - pet.PurchasedAmount; if (difference >= 0) { pet.Stock -= pet.PurchasedAmount; } else { MessageBox.Show(string.Format("Not enough items in stock to purchase, Total Items for purchase: {0}", pet.Stock)); } } else if (cartObject is Supplies) { Supplies supply = cartObject as Supplies; int difference = supply.Stock - supply.PurchasedAmount; if (difference >= 0) { supply.Stock -= supply.PurchasedAmount; } else { MessageBox.Show(string.Format("Not enough items in stock to purchase, Total Items for purchase: {0}", supply.Stock)); } } } }
//adds selected pet and specified quantity // to user shopping cart. private void AddToCartClicked(object obj) { ContentControl cc = selectedControl.Content as ContentControl; ListBox lb = cc.Content as ListBox; int purchasedAmount = int.Parse(Quantity); if (selectedControl.Header.ToString() == "Pets") { Pets selectedPet = lb.SelectedItem as Pets; if (selectedPet.Stock - purchasedAmount >= 0) { selectedPet.Stock -= purchasedAmount; selectedPet.PurchasedAmount = purchasedAmount; CartContents.Add(selectedPet as object); TotalCost += double.Parse(selectedPet.Price.ToString().Replace("$", "")) * purchasedAmount; } else { MessageBox.Show("Not enough items in stock to purchase"); } } else { Supplies selectedItem = lb.SelectedItem as Supplies; if (selectedItem.Stock - purchasedAmount >= 0) { selectedItem.Stock -= purchasedAmount; selectedItem.PurchasedAmount = purchasedAmount; CartContents.Add(selectedItem as object); TotalCost += double.Parse(selectedItem.Price.ToString().Replace("$", "")) * purchasedAmount; } else { MessageBox.Show("Not enough items in stock to purchase"); } } }