예제 #1
0
        }//

        //method to delete a category
        public void deleteCategory(String id)
        {
            if (MessageBox.Show("Are you sure to Delete this record?", "Delete Category", MessageBoxButtons.YesNo) == DialogResult.Yes)
            {
                using (DBEntities db = new DBEntities())
                {
                    //getting the object whichh need to be deleted
                    Fcategory = db.FoodCategories.Where(fc => fc.foodCategoryID == id).First();
                    //delete the object
                    db.FoodCategories.Remove(Fcategory);
                    try
                    {
                        db.SaveChanges();
                    }
                    catch (DbEntityValidationException ex)
                    {
                        foreach (var entityValidationErrors in ex.EntityValidationErrors)
                        {
                            foreach (var validationError in entityValidationErrors.ValidationErrors)
                            {
                                MessageBox.Show("Property: " + validationError.PropertyName + " Error: " + validationError.ErrorMessage);
                            }
                        }
                    }
                }
                MessageBox.Show("Category Removed Successfully!!!");
            }

            //refreshing......
            clearCatgoryList();
            loadFoodCategories();
        }//end of delete category method *******************
예제 #2
0
        //method to edit category details
        public void editcategory(String id)
        {
            //retreiving selected row
            using (DBEntities db = new DBEntities())
            {
                //setting status to update
                status       = "update";
                btnSave.Text = "Update";

                foodCategory = db.FoodCategories.Where(x => x.foodCategoryID == id).FirstOrDefault();
                MessageBox.Show(foodCategory.foodCategoryID);

                //storing values to the textboxes
                txtCategoryID.Text          = foodCategory.foodCategoryID;
                txtCategoryName.Text        = foodCategory.name;
                txtCategoryDescription.Text = foodCategory.description;
            }
        }//end of edit item category method
예제 #3
0
        }//end of the generate key method

        //method to get the selected categorie's id
        public static String getCategoryID(String tableName, String categoryName)
        {
            using (DBEntities db = new DBEntities())
            {
                if (tableName == "FoodCategory")
                {
                    fCategory  = db.FoodCategories.Where(fc => fc.name == categoryName).First();
                    categoryID = fCategory.foodCategoryID;
                }
                else if (tableName == "ItemCategory")
                {
                    ICategory  = db.ItemCategories.Where(fc => fc.categoryName == categoryName).First();
                    categoryID = ICategory.itemCategoryID;
                }
            }


            return(categoryID);; //if not found
        }// end of getCategory Function -------------------------------------------------