private void RemoveIngredient_Click(object sender, RoutedEventArgs e) { try { WpfApplication1.FoodProjectDataSetTableAdapters.IngredientTableAdapter ita = new WpfApplication1.FoodProjectDataSetTableAdapters.IngredientTableAdapter(); WpfApplication1.FoodProjectDataSetTableAdapters.Recipe_IngredientTableAdapter rita = new FoodProjectDataSetTableAdapters.Recipe_IngredientTableAdapter(); DataRowView dv = (DataRowView)mainRecipeDetailsDataGrid.SelectedItem; if (dv != null) { int rid = (int)dv["rid"]; int iid = (int)ita.GetIidByName(dv["Ingredients"].ToString()); rita.RemoveIngredient(rid, iid); UpdateDataGrid(); MessageBox.Show("Hráefni fjarlægt úr uppskrift!"); } } catch (Exception) { } }
private void btnAddIngredient_Click(object sender, RoutedEventArgs e) { try { WpfApplication1.FoodProjectDataSetTableAdapters.IngredientTableAdapter ita = new WpfApplication1.FoodProjectDataSetTableAdapters.IngredientTableAdapter(); WpfApplication1.FoodProjectDataSetTableAdapters.Recipe_IngredientTableAdapter rita = new FoodProjectDataSetTableAdapters.Recipe_IngredientTableAdapter(); WpfApplication1.FoodProjectDataSetTableAdapters.MeasureTableAdapter mta = new FoodProjectDataSetTableAdapters.MeasureTableAdapter(); // Skilgreini DataRowView til þess að geta náð í measureID úr comboboxi DataRowView dv = (DataRowView)cbMeasure.SelectedItem; if (dv != null) { // Næ í iid, rid og mid fyrir Recipe_Ingredient Insert Query int iid = (int)ita.GetIidByName(txtIngredient.Text); int rid = (int)App.Current.Properties["rid"]; int mid = (int)dv["mid"]; rita.Insert(rid, iid, double.Parse(txtQuantity.Text), mid); UpdateDataGrid(); try { string root = AppDomain.CurrentDomain.BaseDirectory; // Bý til myndina BitmapImage imgC = new BitmapImage(); imgC.BeginInit(); imgC.UriSource = new Uri(root + @"\check20w.png"); imgC.DecodePixelWidth = 20; imgC.EndInit(); // Set myndina inn í rétt image í xamlinu og bæti texta í label imgCheck.Source = imgC; lblCheck.Content = "Hráefni hefur verið bætt við uppskrift."; // Kalla á timer sem núllstillir image og label TimerTest(); } catch (FileNotFoundException) { } } else { MessageBox.Show("Vinsamlegast veljið Mælieiningu."); } } catch (NullReferenceException) { MessageBox.Show("Vinsamlegast veljið hráefni."); } catch (InvalidOperationException) { MessageBox.Show("Vinsamlegast veljið hráefni."); } catch (FormatException) { MessageBox.Show("Vinamlegast sláið inn magn."); } catch (Exception) // Á að vera SQLException en það virkar ekki. { MessageBox.Show("Villa kom upp. Ekki tókst að skrá hráefni"); } }