示例#1
0
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                userName = (string)(Session["userName"]);
                EditModeLabel.Visible = false;

                // Assign session information to variables
                int clickedRecipe = (int)(Session["clickedRecipe"]);
                isOnFavorites = (bool)(Session["isOnFavorites"]);

                // Set text boxes to read only so they can't be modified unless they select update btn
                IngredientsBox.ReadOnly  = true;
                InstructionsBox.ReadOnly = true;
                LabelBox.ReadOnly        = true;
                SaveBtn.Visible          = false;
                CancelBtn.Visible        = false;

                // If else statements to display recipe from the correct database
                if (isOnFavorites)
                {
                    // Use favorite manager to display recipe from favorites list
                    FavoriteRecipeMgr favMgr = new FavoriteRecipeMgr();
                    list = favMgr.retrieveRecipes(userName);

                    // Hide Add to favorite button since user is currently viewing favorite recipe
                    AddToFavButton.Visible = false;

                    // Show Update button to allow users to modify their favorite recipes
                    UpdateBtn.Visible = true;

                    // Change the text of the delete button so user knows which database they're viewing
                    DeleteButton.Text = "Delete From Favorites";
                }
                else
                {
                    // Use recipe manager to display recipe from regular recipe list
                    RecipeMgr recipeMgr = new RecipeMgr();
                    list = recipeMgr.retrieveRecipes();

                    // Show favorite button since recipe can be added to favorites
                    AddToFavButton.Visible = true;

                    // Hide update button since users are not allowed to edit preloaded recipes
                    UpdateBtn.Visible = false;

                    // Change text of delete button
                    DeleteButton.Text = "Delete From Recipes";
                }

                // Retrieve desired recipe and display recipe information in text boxes
                recipeDisplayed      = list[clickedRecipe];
                LabelBox.Text        = list[clickedRecipe].RecipeName;
                IngredientsBox.Text  = list[clickedRecipe].RecipeIngredients;
                InstructionsBox.Text = list[clickedRecipe].RecipeInstructions;
                string strBase64 = Convert.ToBase64String(list[clickedRecipe].RecipeImage);

                RecipeImage.ImageUrl = "data:Image/jpg;base64," + strBase64;
            }
        }
示例#2
0
        protected void AddToFavButton_Click(object sender, EventArgs e)
        {
            FavoriteRecipeMgr favMgr    = new FavoriteRecipeMgr();
            RecipeMgr         recipeMgr = new RecipeMgr();

            isOnFavorites = (bool)(Session["isOnFavorites"]);
            int clickedRecipe = (int)(Session["clickedRecipe"]);

            userName = (string)(Session["userName"]);

            list            = recipeMgr.retrieveRecipes();
            recipeDisplayed = list[clickedRecipe];

            // Try to store recipe to favorite list and display success message
            try
            {
                favMgr.addRecipe(recipeDisplayed, userName);
                Page.ClientScript.RegisterStartupScript(this.GetType(), "Scripts", "<script>alert('Recipe Successfully added to Favorite List!!!');</script>");
            }

            // Catch exception for debugging purposes and display error message
            catch (Exception ex)
            {
                Debug.Write(ex.StackTrace);
                Debug.WriteLine(ex.ToString());
                Page.ClientScript.RegisterStartupScript(this.GetType(), "Scripts", "<script>alert('Error! Unable to save recipe to Favorite List!!!');</script>");
            }
        }
示例#3
0
        protected void DeleteButton_Click(object sender, EventArgs e)
        {
            isOnFavorites = (bool)(Session["isOnFavorites"]);
            int clickedRecipe = (int)(Session["clickedRecipe"]);

            userName = (string)(Session["userName"]);

            // If else statement to delete recipe from correct database
            if (isOnFavorites)
            {
                FavoriteRecipeMgr favMgr = new FavoriteRecipeMgr();
                list = favMgr.retrieveRecipes(userName);

                recipeDisplayed = list[clickedRecipe];
                // Try to delete recipe from favorites and redirect to favorites form
                try
                {
                    favMgr.deleteRecipe(recipeDisplayed.RecipeId, userName);
                    bool recipeDeleted = true;
                    Session.Add("recipeDeleted", recipeDeleted);
                    Server.Transfer("FavoriteListForm.aspx");
                }

                // Catch exception for debugging and display error message
                catch (Exception ex)
                {
                    Debug.Write(ex.StackTrace);
                    Debug.WriteLine(ex.ToString());
                    Page.ClientScript.RegisterStartupScript(this.GetType(), "Scripts", "<script>alert('Error! Unable to delete recipe from Favorite List!!!');</script>");
                }
            }
            else
            {
                RecipeMgr recipeMgr = new RecipeMgr();
                list            = recipeMgr.retrieveRecipes();
                recipeDisplayed = list[clickedRecipe];

                // Try to delete recipe from regular recipe list and redirect to recipe list form
                try
                {
                    recipeMgr.deleteRecipe(recipeDisplayed.RecipeId);
                    bool recipeDeleted = true;
                    Session.Add("recipeDeleted", recipeDeleted);
                    Server.Transfer("RecipeListForm.aspx");
                }

                // Catch exception for debugging and display error message
                catch (Exception ex)
                {
                    Debug.Write(ex.StackTrace);
                    Debug.WriteLine(ex.ToString());
                    Page.ClientScript.RegisterStartupScript(this.GetType(), "Scripts", "<script>alert('Error! Unable to delete recipe from Recipe List!!!');</script>");
                }
            }
        }