Exemple #1
0
        protected void Page_Load(object sender, EventArgs e)
        {
            int item_id = Convert.ToInt32(RouteData.Values["item_id"]);

            if (!IsPostBack)
            {
                if (item_id > 0)   // if there is an item id
                {
                    lbtnUpdate.Text = "Update";
                    MenuItemCS mt = new MenuItemCS(item_id);
                    txtName.Text              = mt.Item_Name;
                    txtDescription.Text       = mt.Item_Desc;
                    txtAllergens.Text         = mt.Item_Allergens;
                    txtPrice.Text             = mt.Item_Price.ToString();
                    ddlMenu.SelectedValue     = mt.Menu_Id.ToString();
                    ddlCategory.SelectedValue = mt.Cat_Id.ToString();
                    chkGluten_Free.Checked    = mt.Item_Gluten_Free;
                    chkIsActive.Checked       = mt.Item_Active;
                }
                else  // if no item id go to add
                {
                    lbtnUpdate.Text = "Add";
                    MenuItemCS mt = new MenuItemCS(item_id);
                    txtName.Text              = String.Empty;
                    txtDescription.Text       = String.Empty;
                    txtAllergens.Text         = String.Empty;
                    txtPrice.Text             = String.Empty;
                    ddlMenu.SelectedValue     = null;
                    ddlCategory.SelectedValue = null;
                    chkGluten_Free.Checked    = false;
                    chkIsActive.Checked       = false;
                }
            }
        }
Exemple #2
0
        protected void Page_Load(object sender, EventArgs e)
        {
            {
                // lblTableID.Text = RouteData.Values["tbl_id"].ToString();
                // int sect_id = Convert.ToInt32(RouteData.Values["sect_id"]);

                int        item_id = Convert.ToInt32(RouteData.Values["item_id"]);
                MenuItemCS mt      = new MenuItemCS(item_id);

                lblItem_ID.Text   = String.Concat("Item_ID: ", mt.Item_ID).ToString();
                lblMenu_Id.Text   = String.Concat("Menu_Id: ", mt.Menu_Id).ToString();
                lblCat_Id.Text    = String.Concat("Cat_Id: ", mt.Cat_Id).ToString();
                lblItem_Name.Text = String.Concat("Item_Name: ", mt.Item_Name).ToString();
                //  txtName.Text = String.Concat(mt.Item_Name);
                lblItem_Desc.Text        = String.Concat("Item_Desc: ", mt.Item_Desc).ToString();
                lblItem_Allergens.Text   = String.Concat("Item_Allergens: ", mt.Item_Allergens).ToString();
                lblItem_Price.Text       = String.Concat("Item_Price: ", mt.Item_Price).ToString();
                lblItem_Gluten_Free.Text = String.Concat("Item_Gluten_Free: ", mt.Item_Gluten_Free).ToString();
                lblItem_Active.Text      = String.Concat("Item_Active: ", mt.Item_Active).ToString();

                //         txtName.Text = String.Concat(mt.Item_Name);
                //        txtDescription.Text = String.Concat(mt.Item_Desc);
                //       txtAllergens.Text = String.Concat(mt.Item_Allergens);
                //       txtPrice.Text = String.Concat(mt.Item_Price);
                //        txtMenu.Text = String.Concat(mt.Menu_Name);
                //       txtCategory.Text = String.Concat(mt.Cat_Name);
            }
        }
Exemple #3
0
        public static bool UpdateMenuItems(MenuItemCS sr)
        {
            //declare return variable
            bool blnSuccess = false;
            //connection object -> ConfigurationManager namespace
            //access web.config setting -> connection strings & key values
            SqlConnection cn = new SqlConnection(
                ConfigurationManager.ConnectionStrings["SE256_MurilloConnectionString"].ConnectionString);
            SqlCommand cmd = new SqlCommand("menu_item_update", cn);

            // Mark the Command -> Stored Procedure
            cmd.CommandType = CommandType.StoredProcedure;

            // Add Parameters -> Stored Procedure
            cmd.Parameters.Add(
                "@item_id", SqlDbType.Int).Value = sr.Item_ID;
            cmd.Parameters.Add(
                "@menu_id", SqlDbType.Int).Value = sr.Menu_Id;
            cmd.Parameters.Add(
                "@cat_id", SqlDbType.Int).Value = sr.Cat_Id;
            cmd.Parameters.Add(
                "@item_name", SqlDbType.VarChar).Value = sr.Item_Name;
            cmd.Parameters.Add(
                "@item_desc", SqlDbType.VarChar).Value = sr.Item_Desc;
            cmd.Parameters.Add(
                "@item_allergens", SqlDbType.VarChar).Value = sr.Item_Allergens;
            cmd.Parameters.Add(
                "@item_price", SqlDbType.Decimal).Value = sr.Item_Price;
            cmd.Parameters.Add(
                "@item_gluten_free", SqlDbType.Bit).Value = sr.Item_Gluten_Free;
            cmd.Parameters.Add(
                "@item_active", SqlDbType.Bit).Value = sr.Item_Active;

            // Open database connection -> execute command
            try
            {
                cn.Open();
                cmd.ExecuteNonQuery();
                blnSuccess = true;
            }
            catch (Exception exc)
            {
                //error -> notify user
                exc.ToString();
                blnSuccess = false;
            }
            finally
            {
                cn.Close();
            }
            return(blnSuccess);
        }
Exemple #4
0
        protected void lbtnUpdate_Click(object sender, EventArgs e)
        {
            string updateBUTTON = lbtnUpdate.Text;

            if (updateBUTTON == "Update")    // update menu item
            {
                MenuItemCS sr = new MenuItemCS();
                if (RouteData.Values["item_id"] != null)
                {
                    bool success = false;
                    sr.Item_ID          = Convert.ToInt32(RouteData.Values["item_id"]);
                    sr.Menu_Id          = Convert.ToInt32(ddlMenu.SelectedValue);
                    sr.Cat_Id           = Convert.ToInt32(ddlCategory.SelectedValue);
                    sr.Item_Name        = txtName.Text.Trim();
                    sr.Item_Desc        = txtDescription.Text.Trim();
                    sr.Item_Allergens   = txtAllergens.Text.Trim();
                    sr.Item_Price       = Convert.ToDecimal(txtPrice.Text);
                    sr.Item_Gluten_Free = false;
                    sr.Item_Active      = chkIsActive.Checked;

                    success = MenuItemCS.UpdateMenuItems(sr);

                    if (success)  // if update menu is true
                    {
                        Response.Redirect("~/Admin/Menu-Items");
                    }
                }
            }

            else   // insert menu item
            {
                bool       success = false;
                MenuItemCS sr      = new MenuItemCS();
                sr.Item_ID          = Convert.ToInt32(RouteData.Values["item_id"]);
                sr.Menu_Id          = Convert.ToInt32(ddlMenu.SelectedValue);
                sr.Cat_Id           = Convert.ToInt32(ddlCategory.SelectedValue);
                sr.Item_Name        = txtName.Text.Trim();
                sr.Item_Desc        = txtDescription.Text.Trim();
                sr.Item_Allergens   = txtAllergens.Text.Trim();
                sr.Item_Price       = Convert.ToDecimal(txtPrice.Text);
                sr.Item_Gluten_Free = false;
                sr.Item_Active      = chkIsActive.Checked;

                success = MenuItemCS.InsertMenuItem(sr);

                if (success)  // if insert menu is true
                {
                    Response.Redirect("/Admin/Menu-Items");
                }
            }
        }