private void DeleteCuisine_Click(object sender, RoutedEventArgs e) { FoodProjectDataSetTableAdapters.CuisineTableAdapter cta = new FoodProjectDataSetTableAdapters.CuisineTableAdapter(); DataRowView dv = (DataRowView)nameListBox.SelectedItem; if (dv != null) { string cuisineName = (string)dv["name"]; MessageBoxResult res = MessageBox.Show("Ertu viss um að þú viljir eyða flokknum " + cuisineName + "?", "Eyða Flokk", MessageBoxButton.YesNo, MessageBoxImage.Warning, MessageBoxResult.No); if (res == MessageBoxResult.Yes) { try { int cuid = (int)dv["cuid"]; string name = (string)dv["name"]; cta.Delete(cuid, name); UpdateWindow(); } catch (Exception) { MessageBox.Show("Ekki er hægt að eyða flokkum \nsem þegar eru á uppskriftum.", "Villa!", MessageBoxButton.OK, MessageBoxImage.Error); } } } }
private void btnCreate_Click(object sender, RoutedEventArgs e) { FoodProjectDataSetTableAdapters.CuisineTableAdapter cta = new FoodProjectDataSetTableAdapters.CuisineTableAdapter(); if (String.IsNullOrWhiteSpace(txtName.Text) == false) { cta.Insert(txtName.Text.Trim()); string showMessage = "Flokknum " + txtName.Text.Trim() + " var bætt við"; MessageBox.Show(showMessage); this.Close(); } else { MessageBox.Show("Vinsamlegast sláið inn heiti."); } }