Ejemplo n.º 1
0
        private void getDetails()
        {
            RecipeEntity category = logic.recipe.getById(id);
            txt_Name.Text = category.Name;
            txt_Sort.Text = category.Sort.ToString();
            drp_ParentCategory.SelectedIndex = drp_ParentCategory.Items.IndexOf(drp_ParentCategory.Items.FindByValue(category.Rcid.ToString()));
            chx_isShow.Checked = category.IsShow;
            hdCurrentSource.Value = category.Source;
            hdCurrentDishName.Value = category.Name;
            chkRecommend.Checked = category.IsRecommend;
            txtDescrption.Text = category.Description;
            DataTable dt = logic.recipeItem.listRecipeItemByRecipeId(id);
            List<ProductItem> recipeItems = new List<ProductItem>();

            foreach (DataRow row in dt.Rows)
            {
                ProductItem product = new ProductItem() { ProductId = Convert.ToInt32(row["productId"]), ProductName = row["name"].ToString() };
                recipeItems.Add(product);
            }

            hdProductSotre.Value = JsonConvert.SerializeObject(recipeItems);
        }
Ejemplo n.º 2
0
        // 添加到菜谱
        protected void lbn_AddTo_Click(object sender, EventArgs e)
        {
            List<ProductItem> selectedProduct = null;
            if (!string.IsNullOrEmpty(hdProductSotre.Value))
            {
                selectedProduct = JsonConvert.DeserializeObject<List<ProductItem>>(hdProductSotre.Value);
            }
            else
            {
                selectedProduct = new List<ProductItem>();
            }

            foreach (RepeaterItem item in rpt_Products.Items)
            {
                if (item.ItemType == ListItemType.AlternatingItem || item.ItemType == ListItemType.Item)
                {
                    CheckBox chk = item.FindControl("cbx_isSelect") as CheckBox;

                    if (chk != null && chk.Checked)
                    {
                        ProductItem product = new ProductItem();
                        product.ProductId = Convert.ToInt32(chk.Attributes["ProductId"]);
                        product.ProductName = chk.Attributes["Name"];

                        // 匿名方法查找
                        //ProductItem current = selectedProduct.Find(delegate(ProductItem productItem) { return productItem.ProductId == product.ProductId; });
                        // lamdba表达式
                        ProductItem current = selectedProduct.Find(productItem => productItem.ProductId == product.ProductId);
                        if (current == null)
                        {
                            selectedProduct.Add(product);
                        }
                    }
                }
            }

            hdProductSotre.Value = JsonConvert.SerializeObject(selectedProduct);
            BindSelectedProduct();
        }