//code for editing database fields private void ButtonEdit_Click(object sender, RoutedEventArgs e) { if (ButtonEdit.Content.ToString() == "Edit") { ingredient = (Ingredient)ListBoxIngredients.SelectedItem; TextBoxDescription.IsReadOnly = false; TextBoxQuantity.IsReadOnly = false; ButtonEdit.Content = "Save"; TextBoxDescription.Background = Brushes.White; TextBoxQuantity.Background = Brushes.White; } else { using (var db = new Shopping_ListEntities2()) { var ingredientToEdit = db.Ingredients.Find(ingredient.IngredientsId); ingredientToEdit.Ingredient1 = TextBoxDescription.Text; int.TryParse(TextBoxQuantity.Text, out int Quantity); db.SaveChanges(); } } if (ButtonEdit.Content.ToString() == "Edit") { equipment = (Equipment)ListBoxEquipments.SelectedItem; TextBoxDescription.IsReadOnly = false; TextBoxQuantity.IsReadOnly = false; ButtonEdit.Content = "Save"; TextBoxDescription.Background = Brushes.White; TextBoxQuantity.Background = Brushes.White; } else { using (var db = new Shopping_ListEntities2()) { var equipmentToEdit = db.Equipments.Find(equipment.Equipment1); equipmentToEdit.Equipment1 = TextBoxDescription.Text; int.TryParse(TextBoxQuantity.Text, out int Quantity); db.SaveChanges(); } } if (ButtonEdit.Content.ToString() == "Edit") { order = (OrderIngredient)ListBoxOrders.SelectedItem; TextBoxDescription.IsReadOnly = false; TextBoxQuantity.IsReadOnly = false; ButtonEdit.Content = "Save"; TextBoxDescription.Background = Brushes.White; TextBoxQuantity.Background = Brushes.White; } else { using (var db = new Shopping_ListEntities2()) { var orderToEdit = db.OrderIngredients.Find(order.Ingredient); orderToEdit.Ingredient = TextBoxDescription.Text; int.TryParse(TextBoxQuantity.Text, out int Quantity); db.SaveChanges(); } } }
private void ListBoxOrders_SelectionChanged(object sender, SelectionChangedEventArgs e) { order = (OrderIngredient)ListBoxOrders.SelectedItem; if (order != null) { TextBoxId.Text = order.OrderId.ToString(); TextBoxDescription.Text = order.Ingredient.ToString(); TextBoxQuantity.Text = order.Quantity.ToString(); TextBoxOrdered.Text = order.Orderd_On.ToString(); } }
private void ButtonAdd_Click(object sender, RoutedEventArgs e) { if (ButtonAdd.Content.ToString() == "Add") { ButtonAdd.Content = "Confirm"; TextBoxId.Background = Brushes.White; TextBoxDescription.Background = Brushes.White; TextBoxQuantity.Background = Brushes.White; TextBoxDescription.IsReadOnly = false; TextBoxQuantity.IsReadOnly = false; TextBoxId.IsReadOnly = true; TextBoxDescription.Text = ""; TextBoxQuantity.Text = ""; } else { ButtonAdd.Content = "Add"; ButtonAdd.IsEnabled = true; int.TryParse(TextBoxQuantity.Text, out int Quantity); var ingredientToAdd = new Ingredient() { Ingredient1 = TextBoxDescription.Text, Quantity = Quantity }; using (var db = new Shopping_ListEntities2()) { db.Ingredients.Add(ingredientToAdd); db.SaveChanges(); ListBoxIngredients.ItemsSource = null; ingredients = db.Ingredients.ToList(); ListBoxIngredients.ItemsSource = ingredients; } } if (ButtonAdd.Content.ToString() == "Add") { ButtonAdd.Content = "Confirm"; TextBoxId.Background = Brushes.White; TextBoxDescription.Background = Brushes.White; TextBoxDescription.IsReadOnly = false; TextBoxQuantity.IsReadOnly = false; TextBoxId.IsReadOnly = true; TextBoxDescription.Text = ""; TextBoxQuantity.Text = ""; } else { ButtonAdd.Content = "Add"; ButtonAdd.IsEnabled = true; int.TryParse(TextBoxQuantity.Text, out int Quantity); var equipmentToAdd = new Equipment() { Equipment1 = TextBoxDescription.Text, Quantity = Quantity }; using (var db = new Shopping_ListEntities2()) { db.Equipments.Add(equipmentToAdd); db.SaveChanges(); ListBoxEquipments.ItemsSource = null; equipments = db.Equipments.ToList(); ListBoxEquipments.ItemsSource = equipments; } } if (ButtonAdd.Content.ToString() == "Add") { ButtonAdd.Content = "Confrim"; TextBoxId.Background = Brushes.White; TextBoxDescription.Background = Brushes.White; TextBoxDescription.IsReadOnly = false; TextBoxQuantity.IsReadOnly = false; TextBoxId.IsReadOnly = true; TextBoxDescription.Text = ""; TextBoxQuantity.Text = ""; } else { ButtonAdd.Content = "Add"; ButtonAdd.IsEnabled = true; int.TryParse(TextBoxQuantity.Text, out int Quantity); var orderToAdd = new OrderIngredient() { Ingredient = TextBoxDescription.Text, Quantity = Quantity }; using (var db = new Shopping_ListEntities2()) { db.OrderIngredients.Add(orderToAdd); db.SaveChanges(); ListBoxOrders.ItemsSource = null; orders = db.OrderIngredients.ToList(); ListBoxOrders.ItemsSource = orders; } } }