//Saves the product to Buchhaltung public void SaveProduct() { bool doIt = false; try { string tax = TaxOfProduct.Text, price = PriceOfProduct.Text; if (tax.Contains("%")) { tax = tax.Replace("%", ""); } if (price.Contains("€")) { price = price.Replace("€", ""); } tax = tax.Trim(); price = price.Trim(); double dTax = Convert.ToDouble(tax); if (dTax > 0 && dTax < 101) { doIt = true; } //adds the product if (Buchhaltung.Products.Max() != null && doIt) { Product p = new Product(NameOfTheProdukt.Text, Convert.ToDouble(price), Convert.ToInt32(tax), Convert.ToDouble(AmountOfProduct.Text), KindOfAmount.Text, Buchhaltung.Products.Max().Id); Buchhaltung.Products.Add(p); } else if (doIt) { Product p = new Product(NameOfTheProdukt.Text, Convert.ToDouble(price), Convert.ToInt32(tax), Convert.ToDouble(AmountOfProduct.Text), KindOfAmount.Text, 0); Buchhaltung.Products.Add(p); } if (doIt) { Buchhaltung.SaveProducts(); Close(); } else { Buchhaltung.Log("Prozente überschritten!"); } } catch (Exception e) { Buchhaltung.Log(e.Message); Buchhaltung.SaveErrorMsg(e); } }
//Saves the product to Buchhaltung public void SaveProduct() { try { string tax = TaxOfProduct.Text, price = PriceOfProduct.Text; if (tax.Contains("%")) { tax = tax.Replace("%", ""); } if (price.Contains("€")) { price = price.Replace("€", ""); } tax = tax.Trim(); price = price.Trim(); //adds the product if (Buchhaltung.products.Max() != null) { Product p = new Product(NameOfTheProdukt.Text, Convert.ToDouble(price), Convert.ToInt32(tax), Convert.ToDouble(AmountOfProduct.Text), KindOfAmount.Text, Buchhaltung.products.Max().ID); Buchhaltung.products.Add(p); } else { Product p = new Product(NameOfTheProdukt.Text, Convert.ToDouble(price), Convert.ToInt32(tax), Convert.ToDouble(AmountOfProduct.Text), KindOfAmount.Text, 0); Buchhaltung.products.Add(p); } Buchhaltung.SaveProducts(); MessageBox.Show("Erfolgreich gespeichert!"); this.Close(); } catch (Exception e) { Buchhaltung.Log(e.Message); Buchhaltung.SaveErrorMsg(e); } }
/// <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); } }