public Search_Class() { this.Items.Clear(); this.Items.Add(new ListItem(this.NullToDisplay, string.Empty)); foreach (CategoryInfo info in CategoryBrowser.GetMainCategories()) { this.Items.Add(new ListItem(Globals.HtmlDecode(info.Name), info.CategoryId.ToString(CultureInfo.InvariantCulture))); } base.ID = "drop_Search_Class"; }
private void GetAllCategories(System.Web.HttpContext context) { System.Collections.Generic.IList <CategoryInfo> mainCategories = CategoryBrowser.GetMainCategories(); if (mainCategories == null || mainCategories.Count == 0) { context.Response.Write(this.GetErrorJosn(103, "没获取到相应的分类")); return; } System.Text.StringBuilder stringBuilder = new System.Text.StringBuilder(); stringBuilder.Append("{\"result\":["); foreach (CategoryInfo current in mainCategories) { stringBuilder.Append("{"); stringBuilder.AppendFormat("\"cid\":{0},", current.CategoryId); stringBuilder.AppendFormat("\"name\":\"{0}\",", current.Name); stringBuilder.AppendFormat("\"icon\":\"{0}\",", current.Icon); stringBuilder.AppendFormat("\"hasChildren\":\"{0}\",", current.HasChildren.ToString().ToLower()); stringBuilder.AppendFormat("\"description\":\"{0}\",", this.GetSubCategoryNames(current.CategoryId)); stringBuilder.Append("\"subs\":["); System.Collections.Generic.IList <CategoryInfo> subCategories = CategoryBrowser.GetSubCategories(current.CategoryId); if (subCategories != null && subCategories.Count > 0) { foreach (CategoryInfo current2 in subCategories) { stringBuilder.Append("{"); stringBuilder.AppendFormat("\"cid\":{0},", current2.CategoryId); stringBuilder.AppendFormat("\"name\":\"{0}\",", current2.Name); stringBuilder.AppendFormat("\"icon\":\"{0}\",", current2.Icon); stringBuilder.AppendFormat("\"hasChildren\":\"{0}\",", current2.HasChildren.ToString().ToLower()); stringBuilder.Append("\"subs\":["); System.Collections.Generic.IList <CategoryInfo> subCategories2 = CategoryBrowser.GetSubCategories(current2.CategoryId); if (subCategories2 != null && subCategories2.Count > 0) { foreach (CategoryInfo current3 in subCategories2) { stringBuilder.Append("{"); stringBuilder.AppendFormat("\"cid\":{0},", current3.CategoryId); stringBuilder.AppendFormat("\"name\":\"{0}\",", current3.Name); stringBuilder.AppendFormat("\"icon\":\"{0}\"", current3.Icon); stringBuilder.Append("},"); } stringBuilder.Remove(stringBuilder.Length - 1, 1); } stringBuilder.Append("]},"); } stringBuilder.Remove(stringBuilder.Length - 1, 1); } stringBuilder.Append("]},"); } stringBuilder.Remove(stringBuilder.Length - 1, 1); stringBuilder.Append("]}"); context.Response.Write(stringBuilder.ToString()); }
private void GetCategories(System.Web.HttpContext context) { string text = context.Request["pid"]; if (string.IsNullOrEmpty(text)) { context.Response.Write(this.GetErrorJosn(101, "缺少必填参数")); return; } int num = 0; if (!int.TryParse(text, out num)) { context.Response.Write(this.GetErrorJosn(102, "数字类型转换错误")); return; } System.Collections.Generic.IList <CategoryInfo> list; if (num == 0) { list = CategoryBrowser.GetMainCategories(); } else { list = CategoryBrowser.GetSubCategories(num); } if (list == null || list.Count == 0) { context.Response.Write(this.GetErrorJosn(103, "没获取到相应的分类")); return; } System.Text.StringBuilder stringBuilder = new System.Text.StringBuilder(); stringBuilder.Append("{\"result\":["); foreach (CategoryInfo current in list) { stringBuilder.Append("{"); stringBuilder.AppendFormat("\"cid\":{0},", current.CategoryId); stringBuilder.AppendFormat("\"name\":\"{0}\",", current.Name); stringBuilder.AppendFormat("\"icon\":\"{0}\",", current.Icon); stringBuilder.AppendFormat("\"hasChildren\":\"{0}\",", current.HasChildren.ToString().ToLower()); stringBuilder.AppendFormat("\"description\":\"{0}\"", this.GetSubCategoryNames(current.CategoryId)); stringBuilder.Append("},"); } stringBuilder.Remove(stringBuilder.Length - 1, 1); stringBuilder.Append("]}"); context.Response.Write(stringBuilder.ToString()); }
protected override void OnLoad(EventArgs e) { IList <CategoryInfo> mainCategories; int.TryParse(this.Page.Request.QueryString["categoryId"], out this.categoryId); if (this.categoryId > 0) { mainCategories = CategoryBrowser.SearchCategories(this.categoryId, null); if ((mainCategories == null) || (mainCategories.Count == 0)) { CategoryInfo category = CategoryBrowser.GetCategory(this.categoryId); if ((category != null) && category.ParentCategoryId.HasValue) { mainCategories = CategoryBrowser.SearchCategories(category.ParentCategoryId.Value, null); } } } else { mainCategories = CategoryBrowser.GetMainCategories(); } base.DataSource = mainCategories; base.DataBind(); }