Пример #1
0
        public int updateFoodItem(FoodMenuItem updateItem)
        {
            string updateQuery = "UPDATE MenuItem SET Item_name = @iName, Item_description = @iDesc, Item_image_url = @iImage, Item_price = @iPrice, Category_id = @iCat where id = @ID ";

            dbConnection.openConnection();
            SqlCommand cmd = new SqlCommand(updateQuery, dbConnection.getSQLDBConnection());

            dbConnection.getSQLDBConnection().Open();
            cmd.Parameters.AddWithValue("@iName", updateItem.itemName);
            cmd.Parameters.AddWithValue("@iDesc", updateItem.itemIngredients);
            cmd.Parameters.AddWithValue("@iImage", updateItem.itemImageUrl);
            cmd.Parameters.AddWithValue("@iPrice", updateItem.itemPrice);
            cmd.Parameters.AddWithValue("@iCat", updateItem.menuItemCategory.id);
            cmd.Parameters.AddWithValue("@ID", updateItem.id);
            try
            {
                if (cmd.ExecuteNonQuery() > 0)
                {
                    return(1);
                }
            }
            catch (SqlException ex)
            {
                if (ex.ErrorCode == 00001)
                {
                    return(0);
                }
                return(-1);
            }
            finally
            {
                dbConnection.CloseConnection();
            }
            return(-1);
        }
        protected void grdFoodItems_SelectedIndexChanged(object sender, EventArgs e)
        {
            int selectedRow = grdFoodItems.SelectedIndex;

            List <FoodMenuItem> menuItems        = (List <FoodMenuItem>)Session["FoodMenuItems"];
            FoodMenuItem        selectedFoodItem = menuItems.ElementAt(selectedRow);
            Cart newItemCart = new Cart();

            if (Session["CartItems"] != null)
            {
                List <Cart> cartItems = (List <Cart>)Session["CartItems"];
                Boolean     isFound   = false;

                foreach (Cart c in cartItems)
                {
                    if (c.itemId == selectedFoodItem.id)
                    {
                        isFound = true;
                        c.quantity++;
                        c.price = c.price + selectedFoodItem.itemPrice;
                        break;
                    }
                }

                if (!isFound)
                {
                    newItemCart.itemId    = selectedFoodItem.id;
                    newItemCart.dishName  = selectedFoodItem.itemName;
                    newItemCart.quantity  = 1;
                    newItemCart.price     = selectedFoodItem.itemPrice;
                    newItemCart.unitPrice = selectedFoodItem.itemPrice;
                    cartItems.Add(newItemCart);
                }

                Session["CartItems"] = cartItems;
            }
            else
            {
                List <Cart> cartItems = new List <Cart>();
                newItemCart.itemId    = selectedFoodItem.id;
                newItemCart.dishName  = selectedFoodItem.itemName;
                newItemCart.quantity  = 1;
                newItemCart.price     = selectedFoodItem.itemPrice;
                newItemCart.unitPrice = selectedFoodItem.itemPrice;
                cartItems.Add(newItemCart);
                Session["CartItems"] = cartItems;
            }

            grdCartItems.DataSource = GetCartItemsDataTable((List <Cart>)Session["CartItems"]);
            grdCartItems.DataBind();
        }// End of Selected Index Change Method
Пример #3
0
        public List <FoodMenuItem> getFoodItems(string _query)
        {
            List <FoodMenuItem> menuItems = new List <FoodMenuItem>();

            try
            {
                if (this.openConnection() == false)
                {
                    return(null);
                }
                this.dbConnection.Open();
                SqlCommand cmd = new SqlCommand(_query, this.dbConnection);
                //cmd.Parameters.AddWithValue("@mID", memberid);
                SqlDataReader reader = cmd.ExecuteReader();

                // Call Read before accessing data.
                while (reader.Read())
                {
                    FoodMenuItem fi = new FoodMenuItem();
                    fi.id = (int)reader[0];

                    fi.itemName        = reader[1].ToString();
                    fi.itemIngredients = reader[2].ToString();
                    fi.itemImageUrl    = reader[3].ToString();
                    float x;
                    float.TryParse(reader[4].ToString(), out x);
                    fi.itemPrice           = x;
                    fi.menuItemCategory.id = (int)reader[5];
                    menuItems.Add(fi);
                }

                // Call Close when done reading.
                reader.Close();
                return(menuItems);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                return(null);
            }
            finally
            {
                CloseConnection();
            }
        }
Пример #4
0
        protected void grdMenuItems_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            if (e.CommandName == "AddNew")
            {
                GridViewRow  row             = grdMenuItems.FooterRow;
                TextBox      itemName        = row.FindControl("txtItemName") as TextBox;
                TextBox      ingredients     = row.FindControl("txtDescription") as TextBox;
                TextBox      imageUrl        = row.FindControl("txtImageUrl") as TextBox;
                TextBox      itemPrice       = row.FindControl("itemPrice") as TextBox;
                DropDownList ddlItemCategory = row.FindControl("ddlItemCategory") as DropDownList;
                // Label1.Text = txt.Text;
                FoodMenuItem newItem = new FoodMenuItem();
                newItem.itemName        = itemName.Text;
                newItem.itemIngredients = ingredients.Text;
                newItem.itemImageUrl    = imageUrl.Text;
                float price = 0;
                float.TryParse(itemPrice.Text, out price);
                newItem.itemPrice = price;
                ItemCategory itemCategory = new ItemCategory();
                itemCategory.id           = Convert.ToInt32(ddlItemCategory.SelectedItem.Value);
                itemCategory.categoryName = ddlItemCategory.SelectedItem.Text;
                newItem.menuItemCategory  = itemCategory;

                List <FoodMenuItem> quesList = (List <FoodMenuItem>)Session["MenuItems"];
                int listInd = quesList.Count;
                newItem.id = quesList[listInd - 1].id;
                int oldId = newItem.id;
                //displayMsg(this,"OldID: " + oldId);
                oldId++;
                newItem.id = oldId;
                InsertHandler insertDB = new InsertHandler();
                if (insertDB.InsertIntoFoodMenu(newItem) > 0)
                {
                    Label1.Text = "New Item Added Successfully";
                }
                else
                {
                    Label1.Text = "Error Occur in Adding New Item";
                }
                InitGridView();
                ShowLabel(2000);
            }
        }
Пример #5
0
        protected void grdMenuItems_RowUpdating(object sender, GridViewUpdateEventArgs e)
        {
            GridViewRow  row             = (GridViewRow)grdMenuItems.Rows[e.RowIndex];
            TextBox      itemName        = row.FindControl("txtItemName") as TextBox;
            TextBox      ingredients     = row.FindControl("txtDescription") as TextBox;
            TextBox      imageUrl        = row.FindControl("txtImageUrl") as TextBox;
            TextBox      itemPrice       = row.FindControl("itemPrice") as TextBox;
            DropDownList ddlItemCategory = row.FindControl("ddlItemCategory") as DropDownList;

            int quesListInd = Convert.ToInt32(grdMenuItems.DataKeys[e.RowIndex].Value.ToString());
            List <FoodMenuItem> itemsList  = (List <FoodMenuItem>)Session["MenuItems"];
            FoodMenuItem        updateItem = itemsList[quesListInd - 1];

            updateItem.itemName        = itemName.Text;
            updateItem.itemIngredients = ingredients.Text;
            updateItem.itemImageUrl    = imageUrl.Text;
            float price = 0;

            float.TryParse(itemPrice.Text, out price);
            updateItem.itemPrice = price;
            ItemCategory itemCategory = new ItemCategory();

            itemCategory.id             = Convert.ToInt32(ddlItemCategory.SelectedItem.Value);
            itemCategory.categoryName   = ddlItemCategory.SelectedItem.Text;
            updateItem.menuItemCategory = itemCategory;

            InsertHandler updateDB = new InsertHandler();

            if (updateDB.updateFoodItem(updateItem) > 0)
            {
                Label1.Text = "Item is Updated Successfully";
            }
            else
            {
                Label1.Text = "Item is not Updated Successfully";
            }
            ShowLabel(2000);  // Showing Label for 2 Seconds...........
            grdMenuItems.EditIndex = -1;
            InitGridView();
        }
Пример #6
0
        private void btnNext_Click(object sender, EventArgs e)
        {
            Plate plate = new Plate();

            foreach (var item in lbPlate.Items)
            {
                FoodMenuItem foodItem = new FoodMenuItem();
                foodItem.ItemName = item.ToString();

                plate.PlateOrder.Add(foodItem);
                plate.PlateNumber = item.GetHashCode().ToString();
            }

            //Add Plate to order
            //order.plates.Add(plate);

            //Add order To lbOrder
            lbOrder.Items.AddRange(lbPlate.Items);

            //Clear items from lbPlate
            lbPlate.Items.Clear();
        }
Пример #7
0
        public int InsertIntoFoodMenu(FoodMenuItem newItem)
        {
            string insertQuery = "Insert into MenuItem " +
                                 "( Item_name , Item_description , Item_image_url, Item_price, Category_id) " +
                                 "Values ( @iName , @iDesc , @iImage , @iPrice,  @iCategory)";

            dbConnection.openConnection();
            SqlCommand cmd = new SqlCommand(insertQuery, dbConnection.getSQLDBConnection());

            dbConnection.getSQLDBConnection().Open();
            //cmd.Parameters.AddWithValue("@id", newItem.id);
            cmd.Parameters.AddWithValue("@iName", newItem.itemName);
            cmd.Parameters.AddWithValue("@iDesc", newItem.itemIngredients);
            cmd.Parameters.AddWithValue("@iImage", newItem.itemImageUrl);
            cmd.Parameters.AddWithValue("@iPrice", newItem.itemPrice);
            cmd.Parameters.AddWithValue("@iCategory", newItem.menuItemCategory.id);

            try
            {
                if (cmd.ExecuteNonQuery() > 0)
                {
                    return(1);
                }
            }
            catch (SqlException ex)
            {
                if (ex.ErrorCode == 00001)
                {
                    return(0);
                }
                return(-1);
            }
            finally
            {
                dbConnection.CloseConnection();
            }
            return(-1);
        }