private void addToCart(Article article) { //Checks if the selected articles quantity is more than 0 //if true then try to add the article to the shopping cart if (int.Parse(article.getAttributeValue("quantity")) > 0) { var inventoryQTY = int.Parse(article.getAttributeValue("quantity")); //Checks if the article already exists in the shopping cart, //if true then increment its quantity by 1 if (cartList.articleExists(article.getAttributeValue("id"))) { var index = cartList.findArticleIndex(article.getAttributeValue("id")); var qty = cartList.articleList[index].getAttributeValue("quantity"); cartList.articleList[index].setAttributeValue("quantity", (int.Parse(qty) + 1).ToString()); } //else add the article to the shopping cart with a quantity of 1 else { cartList.addArticle(article); cartList.articleList.Last().setAttributeValue("quantity", "1"); } article.setAttributeValue("quantity", (inventoryQTY - 1).ToString()); var inventoryIndex = inventoryList.findArticleIndex(article.getAttributeValue("id")); inventoryList.articleList[inventoryIndex].setAttributeValue("quantity", (inventoryQTY - 1).ToString()); } else { MessageBox.Show("There is no more stock of that item."); } }
private void removeFromInventory(Article article) { if (int.Parse(article.getAttributeValue("quantity")) > 0) { var result = MessageBox.Show("You still have stock of this item. Are you sure you want to remove it from the inventory?", "Warning!", MessageBoxButtons.YesNo); if (result == DialogResult.Yes) { if (storeList.articleExists(article.getAttributeValue("id"))) { storeList.articleList.RemoveAt(storeList.findArticleIndex(article.getAttributeValue("id"))); } inventoryList.articleList.Remove(article); updateInventoryGridView(); radioButton1.Checked = false; radioButton2.Checked = false; radioButton3.Checked = false; quantityNumeric.Value = 0; quantityNumeric.Text = "0"; } } else { if (storeList.articleExists(article.getAttributeValue("id"))) { storeList.articleList.RemoveAt(storeList.findArticleIndex(article.getAttributeValue("id"))); } inventoryList.articleList.Remove(article); updateInventoryGridView(); radioButton1.Checked = false; radioButton2.Checked = false; radioButton3.Checked = false; quantityNumeric.Value = 0; quantityNumeric.Text = "0"; } }