private void buyButton_Click(object sender, EventArgs e) { if (productsListBox.SelectedItem != null) { Item item = ForItemName(productsListBox.SelectedItem.ToString()); if (item == null) { errorShop.ForeColor = Color.Red; errorShop.Text = "This item has been sold out."; return; } int item_id = itemService.GetItemID(item.itemName); if (buy.BuyItem(loggedInUser.userId, item_id)) { AfterPurchase(); errorShop.Text = "Product succesfully bought."; errorShop.ForeColor = Color.Green; return; } if (loggedInUser.balance < item.price) { errorShop.ForeColor = Color.Red; errorShop.Text = "You don't have enough money to do that."; return; } errorShop.ForeColor = Color.Red; errorShop.Text = "This product is currently not available."; return; } errorShop.ForeColor = Color.Red; errorShop.Text = "Please select a product"; }