Example #1
0
        /// <summary>
        /// Checks the input and saves it into Buchhaltung
        /// </summary>
        public void SaveProduct()
        {
            bool taxCheck   = false;
            bool closeCheck = false;

            try
            {
                //removes the % and € symbol from the input
                string tax = TaxOfProduct.Text, price = PriceOfProduct.Text;
                if (tax.Contains("%"))
                {
                    tax = tax.Replace("%", "");
                }
                if (price.Contains("€"))
                {
                    price = price.Replace("€", "");
                }
                if (tax.Contains("."))
                {
                    tax = tax.Replace(".", ",");
                }
                if (price.Contains("."))
                {
                    price = price.Replace(".", ",");
                }

                //trims them down
                tax   = tax.Trim();
                price = price.Trim();

                double dTax = Convert.ToDouble(tax);

                if (dTax > 0 && dTax < 101)
                {
                    taxCheck = true;
                }

                //adds the product (Checks the product id)
                if (Buchhaltung.Products.Max() != null && taxCheck)
                {
                    Product p = new Product(NameOfTheProdukt.Text, Convert.ToDouble(price), Convert.ToInt32(tax),
                                            Convert.ToDouble(AmountOfProduct.Text), KindOfAmount.Text, Buchhaltung.Products.Max().Id,
                                            Group.Text);

                    if (CheckIfProductExists(p))
                    {
                        if (Buchhaltung.ShowYesNoMessageBox(
                                "Das Produkt existiert bereits! Bist du sicher das du es trotzdem hinzufügen möchtest?",
                                "Produkt existiert schon"))
                        {
                            Buchhaltung.Products.Add(p);
                            closeCheck = true;
                        }
                    }
                    else
                    {
                        Buchhaltung.Products.Add(p);
                        closeCheck = true;
                    }
                }
                else if (taxCheck)
                {
                    Product p = new Product(NameOfTheProdukt.Text, Convert.ToDouble(price), Convert.ToInt32(tax),
                                            Convert.ToDouble(AmountOfProduct.Text), KindOfAmount.Text, 0, Group.Text);

                    if (CheckIfProductExists(p))
                    {
                        if (Buchhaltung.ShowYesNoMessageBox(
                                "Das Produkt existiert bereits! Bist du sicher das du es trotzdem hinzufügen möchtest?",
                                "Produkt existiert schon"))
                        {
                            Buchhaltung.Products.Add(p);
                            closeCheck = true;
                        }
                    }
                    else
                    {
                        Buchhaltung.Products.Add(p);
                        closeCheck = true;
                    }
                }

                if (taxCheck && closeCheck)
                {
                    Buchhaltung.SaveProducts();
                    Close();
                }
                else
                {
                    Buchhaltung.Log("Ungültige Prozente!");
                }
            }
            catch (Exception e)
            {
                Buchhaltung.Log(e.Message);
                Buchhaltung.SaveErrorMsg(e);
            }
        }