コード例 #1
0
        /// <summary>
        /// creates a new category
        /// checks to see if the category to be entered is already in the database
        /// if it doesn't exist it is created and added to the database
        /// </summary>
        protected void btnAddNewCategory(object sender, EventArgs e)
        {
            //Hides the error message
            lblCatAddError.Text = "";

            //If input is blank
            if (txtCategory.Text == "")
            {
                lblCatAddError.Text = "You have not entered a Category";
            }
            else
            {
                //Change View Over to ManageCategories View.
                containerView.ActiveViewIndex = 1;
                //populate grid

                TreasureLandDataClassesDataContext db = new TreasureLandDataClassesDataContext();

                var ing = from fdc in db.FoodDrinkCategories.Where(fdc => fdc.FoodDrinkCategoryName == txtCategory.Text)
                          select fdc;

                //checks to see if the item is in the database
                if (ing.Any())
                {
                    //If something exists, then don't add
                    //print error message
                    lblCatAddError.Text = "Category Is Already In the Hotel Restaurant";

                    //reset txtIngredient to " "
                    txtCategory.Text = "";
                }
                else
                {
                    //else if something exists
                    //add record to database
                    //USes an linq to sql to insert a guest into the guest table

                    FoodDrinkCategory addfdc = new FoodDrinkCategory();
                    addfdc.FoodDrinkCategoryName = txtCategory.Text;
                    addfdc.FoodDrinkCategoryTypeID = "F";
                    db.FoodDrinkCategories.InsertOnSubmit(addfdc);
                    db.SubmitChanges();
                }

                //repopulate dropdownlist
                ddlCategory.DataSource = getAllCategories();
                ddlCategory.DataBind();
                gvEditCategories.DataBind();
                ddlAddGetCategory.DataBind();

                txtCategory.Text = "";
            }
        }
 partial void InsertFoodDrinkCategory(FoodDrinkCategory instance);
 partial void UpdateFoodDrinkCategory(FoodDrinkCategory instance);
 partial void DeleteFoodDrinkCategory(FoodDrinkCategory instance);