Пример #1
0
        private void AddToInventoryButton_Click(object sender, EventArgs e)
        {
            if (orderListBox.SelectedIndex >= 0)
            {
                var article = orderList.getItemByName((string)orderListBox.SelectedItem);

                if (!inventoryList.articleExists(article.getAttributeValue("id")))
                {
                    if (radioButton1.Checked)
                    {
                        article.setAttributeValue("quantity", "1");
                    }
                    else if (radioButton2.Checked)
                    {
                        article.setAttributeValue("quantity", "5");
                    }
                    else if (radioButton3.Checked)
                    {
                        article.setAttributeValue("quantity", "10");
                    }
                    else
                    {
                        article.setAttributeValue("quantity", quantityNumeric.Value.ToString());
                    }
                    inventoryList.articleList.Add(article);
                    updateInventoryGridView();
                }
                radioButton1.Checked  = true;
                radioButton2.Checked  = false;
                radioButton3.Checked  = false;
                quantityNumeric.Text  = "0";
                quantityNumeric.Value = 0;
            }
        }
Пример #2
0
        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.");
            }
        }
Пример #3
0
        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";
            }
        }
Пример #4
0
        private bool checkValues()
        {
            for (int i = 0; i < 4; i++)
            {
                if (valueBoxList[i].Text == "")
                {
                    MessageBox.Show($"{labelBoxList[i].Text}-field is empty.");
                    return(false);
                }
            }

            int id;

            if (int.TryParse(newArticle.getAttributeValue("id"), out id))
            {
                if (orderList.articleExists(id.ToString()))
                {
                    MessageBox.Show("There already is a product with that ID.");
                    return(false);
                }
            }
            else
            {
                MessageBox.Show("Unaccepted value for ID. Only accept numbers.");
                return(false);
            }

            int price;

            if (int.TryParse(newArticle.getAttributeValue("price"), out price))
            {
                if (price <= 0)
                {
                    MessageBox.Show("Price cant be negative or 0.");
                    return(false);
                }
            }
            else
            {
                MessageBox.Show("Price can only be numbers.");
                return(false);
            }
            return(true);
        }