/// <summary> /// 获取图片类别数据 /// </summary> /// <param name="typeID"> /// 类型编号(0:商品类别,1:商品品牌) /// </param> /// <param name="parent"> /// 父级对象 /// </param> /// <returns> /// 图片类别列表 /// </returns> public List<PictureCategory> GetPictureCategories(int typeID, PictureCategory parent) { var pictureCategories = new List<PictureCategory>(); this.productBrandService = new ProductBrandService(); this.productCategoryService = new ProductCategoryService(); object list; if (typeID == 0) { if (parent == null) { list = this.productCategoryService.QueryCategoryByParentID(0); var categories = list as List<Product_Category>; if (categories != null) { foreach (var category in categories) { pictureCategories.Add( new PictureCategory { ID = category.ID, Text = category.CategoryName, Url = string.Empty, Level = 1 }); } } } else { list = this.productCategoryService.QueryCategoryByParentID(parent.ID); var categories = list as List<Product_Category>; if (categories != null) { foreach (var category in categories) { pictureCategories.Add( new PictureCategory { ID = category.ID, Text = category.CategoryName, Url = string.Empty, Level = 2 }); } } } } if (typeID == 1 && parent != null) { if (parent.Level == 2) { list = this.productBrandService.QueryProductBrandByCategoryID(parent.ID, 0); var brands = list as List<Product_Brand>; if (brands != null) { foreach (var brand in brands) { pictureCategories.Add( new PictureCategory { ID = brand.ID, Text = brand.BrandName, Url = string.Empty, Level = 3 }); } } } if (parent.Level == 3) { list = this.productBrandService.QueryProductBrandByParentID(parent.ID); var brands = list as List<Product_Brand>; if (brands != null) { foreach (var brand in brands) { pictureCategories.Add( new PictureCategory { ID = brand.ID, Text = brand.BrandName, Url = "Picture/" + brand.ID, Level = 4 }); } } } } return pictureCategories; }
/// <summary> /// 获取商品类别列表下拉框. /// </summary> /// <returns> /// The <see cref="JsonResult"/>. /// </returns> public JsonResult QuerySelectListItems() { List<Product_Category> list; try { this.productCategoryService = new ProductCategoryService(); int totalCount; int pageCount; var paging = new Paging("[Product_Category]", null, "ID", "ParentID = 1", 1, 30); list = this.productCategoryService.Query(paging, out pageCount, out totalCount); } catch (Exception exception) { throw new Exception(exception.Message, exception); } if (list != null) { var selectListItems = new List<SelectListItem> { new SelectListItem { Value = "0", Text = "请选择" } }; foreach (var category in list) { var selectListItem = new SelectListItem { Value = category.ID.ToString(CultureInfo.InvariantCulture), Text = category.CategoryName, }; selectListItems.Add(selectListItem); } selectListItems[2].Selected = true; return this.Json(selectListItems, JsonRequestBehavior.AllowGet); } return this.Json(null); }
/// <summary> /// The query picture tree view. /// </summary> /// <param name="id"> /// The id. /// </param> /// <returns> /// The <see cref="JsonResult"/>. /// </returns> public JsonResult QueryPictureTreeView(int? id) { this.productCategoryService = new ProductCategoryService(); this.productBrandService = new ProductBrandService(); int totalCount; int pageCount; var modelList = new List<dynamic>(); if (id == null) { id = 0; var condition = string.Format("ParentID = {0} And Layer = 1 ", id); var paging = new Paging("[Product_Category]", null, "ID", condition, 1, 100); var list = this.productCategoryService.Query(paging, out pageCount, out totalCount); if (list != null) { foreach (var category in list) { modelList.Add( new { id = category.ID.ToString(), Name = category.CategoryName, hasChildren = true, type = 1 }); } } TempData["TreeviewType"] = 1; } else { if (Convert.ToInt32(TempData["TreeviewType"]) == 1) { var condition = string.Format("ParentID = {0} And Layer = 2 ", id); var paging = new Paging("[Product_Category]", null, "ID", condition, 1, 100); var list = this.productCategoryService.Query(paging, out pageCount, out totalCount); if (list != null) { foreach (var category in list) { modelList.Add( new { id = category.ID.ToString(), Name = category.CategoryName, hasChildren = true, type = 2 }); } } TempData["TreeviewType"] = 2; } else if (Convert.ToInt32(TempData["TreeviewType"]) == 2) { var condition = string.Format("ProductCategoryID = {0} And ParentID = 0 ", id); var paging = new Paging("[Product_Brand]", null, "ID", condition, 1, 100); var list = this.productBrandService.Query(paging, out pageCount, out totalCount); if (list != null) { foreach (var brand in list) { modelList.Add(new { id = brand.ID.ToString(), Name = brand.BrandName, hasChildren = true, type = 3 }); } } TempData["TreeviewType"] = 3; } else if (Convert.ToInt32(TempData["TreeviewType"]) == 3) { var condition = string.Format("ParentID = {0}", id); var paging = new Paging("[Product_Brand]", null, "ID", condition, 1, 100); var list = this.productBrandService.Query(paging, out pageCount, out totalCount); if (list != null) { foreach (var brand in list) { modelList.Add(new { id = brand.ID.ToString(), Name = brand.BrandName, hasChildren = false, type = 4 }); } } } } return this.Json(modelList, JsonRequestBehavior.AllowGet); }