private void AddSubcategoryButtonClicked(object sender, RoutedEventArgs e)
 {
     if (!String.IsNullOrEmpty(NewSubcategoryReader.Text))
     {
         IngredientsCategoryViewModel cat = (IngredientsCategoryViewModel)CategoryListView.SelectedItem;
         if (cat != null)
         {
             string sql = "Insert into IngredientsSubcategory values (N\'" + NewSubcategoryReader.Text + "\', N\'" + cat.Name + "\');";
             connection = new SqlConnection(Settings.connectionString);
             connection.Open();
             command = new SqlCommand(sql, connection);
             List <string> ingredientsCategoryList = new List <string>();
             try
             {
                 reader = command.ExecuteReader();
                 connection.Close();
                 LoadIngredientsList();
                 NewSubcategoryReader.Text = "";
             }
             catch (Exception ex)
             {
                 MessageBox.Show("Błąd połączenia: " + ex.ToString());
             }
         }
     }
 }//
Пример #2
0
        }//

        private void CategoryListViewChosen(object sender, MouseButtonEventArgs e)
        {
            cat = (IngredientsCategoryViewModel)CategoryListView.SelectedItem;
            if (cat.Name != null)
            {
                LoadSubcategoriesList(cat.Name);
            }
        }
Пример #3
0
        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());
                    }
                }
            }
        }//
Пример #4
0
        private void DeleteButtonClicked(object sender, RoutedEventArgs e)
        {
            IngredientsCategoryViewModel cat = (IngredientsCategoryViewModel)CategoryListView.SelectedItem;
            string sql = "Delete from IngredientsCategory 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());
            }
        }