private void Add_Button_Click(object sender, RoutedEventArgs e) { try { if (dish.DishName == "" || dish.DishPrice == 0 || dish.DishSize == 0) { throw new Exception("Fill the fields Please"); } dish.PreparingTime = new TimeSpan(hours, minutes, 0); dish.DS = DishSituation.EXIST; bl.AddDish(dish); dishMessage.Visibility = Visibility.Visible; dish = new Dish(); this.DataContext = dish; this.kashrutLevelTextBox.ItemsSource = Enum.GetValues(typeof(Kashrut)); dishNameTextBox.Text = dish.DishName; dishPriceTextBox.Text = dish.DishPrice.ToString(); dishSizeTextBox.Text = dish.DishSize.ToString(); } catch (Exception exception) { MessageBox.Show(exception.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error); } }
/// <summary> /// Add a dish button /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void Add_Click(object sender, RoutedEventArgs e) { try { // add dish bl.AddDish(dish); // reinitalize data , data binding dish = new Dish(); this.DataContext = dish; } // in case we have an exception we catch it catch (Exception ex) { MessageBox.Show(ex.Message); } }