private void AddIngredientButtonClicked(object sender, RoutedEventArgs e) { if (!String.IsNullOrEmpty(NewIngredientReader.Text)) { IngredientsCategoryViewModel cat = (IngredientsCategoryViewModel)CategoryListView.SelectedItem; IngredientsSubcategoryViewModel subcat = (IngredientsSubcategoryViewModel)SubcategoryListView.SelectedItem; if (cat != null && subcat != null) { connection = new SqlConnection(Settings.connectionString); connection.Open(); string sql = "select name from IngredientsList where name = N\'" + NewIngredientReader.Text + "\'"; command = new SqlCommand(sql, connection); try { reader = command.ExecuteReader(); while (reader.Read()) { if (reader.GetString(0) != null) { connection.Close(); return; } } connection.Close(); } catch (Exception ex) { MessageBox.Show("Błąd połączenia: " + ex.ToString()); } sql = "Insert into IngredientsList values (N\'" + NewIngredientReader.Text + "\', N\'" + cat.Name + "\', N\'" + subcat.Name + "\');"; connection.Open(); command = new SqlCommand(sql, connection); List <string> ingredientsCategoryList = new List <string>(); try { reader = command.ExecuteReader(); connection.Close(); RefreshButtonClicked(sender, e); NewIngredientReader.Text = ""; } catch (Exception ex) { MessageBox.Show("Błąd połączenia: " + ex.ToString()); } } } }//
private void DeleteButtonClicked(object sender, RoutedEventArgs e) { IngredientsSubcategoryViewModel cat = (IngredientsSubcategoryViewModel)SubcategoryListView.SelectedItem; string sql = "Delete from IngredientsSubcategory where name = N\'" + cat.Name + "\';"; connection = new SqlConnection(Settings.connectionString); connection.Open(); command = new SqlCommand(sql, connection); try { reader = command.ExecuteReader(); connection.Close(); LoadIngredientsList(); } catch (Exception ex) { MessageBox.Show("Błąd połączenia: " + ex.ToString()); } }