string RenderHTML() { if (_Cache.ContainsKey(_CategoryID)) { return(_Cache[_CategoryID]); } List <ProductCategory> pcs = ProductCategories.GetCategories(); StringBuilder sb = new StringBuilder(); if (_CategoryID == 0) { return("<div class=\"" + _CssClass + "\"><span>暂无子分类信息!</span></div>"); } else { string _catId = string.Empty; ProductCategory curCat = null; List <ProductCategory> subCats = ProductCategories.GetChidCategories(_CategoryID); if (subCats == null || subCats.Count == 0) { return("<div class=\"" + _CssClass + "\"><span>暂无子分类信息!</span></div>"); } sb.Append("<div class=\"" + _CssClass + "\">"); ProductQuery query; int count = 0; PagingDataSet <Product> __ps = null; for (int i = 0; i < subCats.Count; i++) { curCat = subCats[i]; count = 0; query = new ProductQuery(); query.CategoryID = curCat.CategoryID; __ps = Products.GetProducts(query); if (__ps != null && __ps.Records != null) { count = Products.GetProducts(query).Records.Count; } sb.AppendFormat(_href, GlobalSettings.Encrypt(curCat.CategoryID.ToString()), curCat.CategoryName + "(" + count + ")"); } sb.Append("</div>"); if (!_Cache.ContainsKey(_CategoryID)) { lock (_lock) { if (!_Cache.ContainsKey(_CategoryID)) { _Cache.Add(_CategoryID, sb.ToString()); } } } } return(sb.ToString()); }
string GenerateCategory(ref bool result) { List <ProductCategory> cats = ProductCategories.GetCategories(); SiteMapBuilder smb = new SiteMapBuilder(); foreach (ProductCategory cat in cats) { smb.AddLocalUrl("pages/view.aspx?product-category&ID=" + GlobalSettings.Encrypt(cat.CategoryID.ToString()), DateTime.Now); } smb.Save(GlobalSettings.MapPath("~/sitemap/categories.xml")); result = true; return("成功生成/更新【产品分类】地图!"); }
string GetCategories(int pId) { List <ProductCategory> pcs = ProductCategories.GetCategories(); List <ProductCategory> _pcs = new List <ProductCategory>(); foreach (ProductCategory pc in pcs) { if (pc.ParentID == pId) { _pcs.Add(pc); } } return(Newtonsoft.Json.JavaScriptConvert.SerializeObject(_pcs)); }
string RenderHTML() { if (_Cache.ContainsKey(_CategoryID)) { return(_Cache[_CategoryID]); } List <ProductCategory> pcs = ProductCategories.GetCategories(); StringBuilder sb = new StringBuilder(); if (_CategoryID == 0) { return("无"); } else { List <ProductProperty> props = ProductProperties.GetAllPropertyByCategoryID(_CategoryID); if (props == null || props.Count == 0) { return("无"); } sb.Append("<div class=\"" + _CssClass + "\">"); for (int i = 0; i < props.Count; i++) { sb.AppendFormat(_href, GlobalSettings.Encrypt(_CategoryID.ToString()), GlobalSettings.Encrypt(props[i].PropertyID.ToString()), props[i].PropertyName); } sb.Append("</div>"); if (!_Cache.ContainsKey(_CategoryID)) { lock (_lock) { if (!_Cache.ContainsKey(_CategoryID)) { _Cache.Add(_CategoryID, sb.ToString()); } } } } return(sb.ToString()); }
private void InitialDataBind() { SiteSettings ss = HHContext.Current.SiteSettings; ltCopyRight.Text = ss.Copyright; StringBuilder sbItems = new StringBuilder(); List <ProductBrand> brands = ProductBrands.GetProductBrands(); foreach (ProductBrand item in brands) { sbItems.AppendFormat("<li><a href=\"http://www.ehuaho.com/pages/view.aspx?product-brand&ID={0}\" target=\"_blank\" title=\"{2}\">{1}</a></li>", GlobalSettings.Encrypt(item.BrandID.ToString()), GlobalSettings.SubString(item.BrandName, 10), item.BrandName); } ltBrand.Text = sbItems.ToString(); List <ProductIndustry> inds = ProductIndustries.GetProductIndustries(); sbItems.Remove(0, sbItems.Length); foreach (ProductIndustry item in inds) { sbItems.AppendFormat("<li><a href=\"http://www.ehuaho.com/pages/view.aspx?product-industry&ID={0}\" target=\"_blank\" title=\"{2}\">{1}</a></li>", GlobalSettings.Encrypt(item.IndustryID.ToString()), GlobalSettings.SubString(item.IndustryName, 10), item.IndustryName); } ltIndustry.Text = sbItems.ToString(); ProductQuery q = new ProductQuery(); q.PageIndex = 0; q.PageSize = int.MaxValue; q.HasPublished = true; List <Product> ps = Products.GetProductList(q); sbItems.Remove(0, sbItems.Length); foreach (Product item in ps) { sbItems.AppendFormat("<li><a href=\"http://www.ehuaho.com/pages/view.aspx?product-product&ID={0}\" target=\"_blank\" title=\"{2}\">{1}</a></li>", GlobalSettings.Encrypt(item.ProductID.ToString()), GlobalSettings.SubString(item.ProductName, 17), item.ProductName); } ltProduct.Text = sbItems.ToString(); List <ProductCategory> cats = ProductCategories.GetCategories(); sbItems.Remove(0, sbItems.Length); foreach (ProductCategory item in cats) { sbItems.AppendFormat("<li><a href=\"http://www.ehuaho.com/pages/view.aspx?product-category&ID={0}\" target=\"_blank\" title=\"{2}\">{1}</a></li>", GlobalSettings.Encrypt(item.CategoryID.ToString()), GlobalSettings.SubString(item.CategoryName, 10), item.CategoryName); } ltCategory.Text = sbItems.ToString(); List <Article> ars = ArticleManager.GetAllArticles(); sbItems.Remove(0, sbItems.Length); foreach (Article item in ars) { sbItems.AppendFormat("<li><a href=\"http://www.ehuaho.com/pages/view.aspx?news-newsdetail&ID={0}\" target=\"_blank\" title=\"{2}\">{1}</a></li>", GlobalSettings.Encrypt(item.ID.ToString()), GlobalSettings.SubString(item.Title, 10), item.Title); } ltNews.Text = sbItems.ToString(); //ltCategory; ltIndustry; ltNews; ltProduct; }
public override void OnPageLoaded() { string catName = string.Empty, catRelated = string.Empty; StringBuilder sbRelated = new StringBuilder(); string id = Request.QueryString["ID"]; ProductCategory pc = null; if (!string.IsNullOrEmpty(id)) { int catId = int.Parse(GlobalSettings.Decrypt(id)); pc = ProductCategories.GetCategory(catId); if (pc != null) { catName = pc.CategoryName; } } if (!string.IsNullOrEmpty(catName)) { //获取子分类 List <ProductCategory> childCategories = ProductCategories.GetChidCategories(pc.CategoryID); if (null == childCategories || 0 == childCategories.Count) { } else { foreach (ProductCategory pcChild in childCategories) { sbRelated.AppendFormat("{0},", pcChild.CategoryName); } } //获取相关分类 List <ProductCategory> relateCategories = ProductCategories.GetChidCategories(pc.ParentID); if (null == relateCategories || 0 == relateCategories.Count) { } else { foreach (ProductCategory pcRelate in relateCategories) { sbRelated.AppendFormat("{0},", pcRelate.CategoryName); } } catRelated = sbRelated.ToString().TrimEnd(','); } else { List <ProductCategory> relateCategories = ProductCategories.GetCategories(); if (null == relateCategories || 0 == relateCategories.Count) { } else { foreach (ProductCategory pcRelate in relateCategories) { if (pcRelate.ParentID > 0) { continue; } sbRelated.AppendFormat("{0},", pcRelate.CategoryName); } } catRelated = sbRelated.ToString().TrimEnd(','); } if (string.IsNullOrEmpty(catName)) { catName = "所有分类"; this.AddKeywords(catName + "," + catRelated); this.AddDescription("显示所有一级和二级产品分类,选择产品分类导航到对应分类的产品列表。" + string.Format(" 关键字: {0},{1}", catName, catRelated)); this.ShortTitle = catName; } else { this.AddKeywords(string.Format("{0},{1}", catName, catRelated)); this.AddDescription(string.Format("显示{0}分类的产品列表。{1}", catName, string.Format(" 关键字: {0},{1}", catName, catRelated))); this.ShortTitle = catName + " - " + catRelated; } this.SetTitle(); this.AddJavaScriptInclude("scripts/pages/sortby.aspx.js", false, false); }
public string RenderHTML() { if (pcs == null) { pcs = ProductCategories.GetCategories(); } string nav = GlobalSettings.RelativeWebRoot + "pages/view.aspx?product-category"; if (pcs == null || pcs.Count == 0) { return("<div><span>没有可用的分类信息!</span></div>"); } StringBuilder sb = new StringBuilder(); List <ProductCategory> pcList = new List <ProductCategory>(); ProductCategory pc = null; for (int i = 0; i < pcs.Count; i++) { pc = pcs[i]; if (pc.ParentID == 0) { pcList.Add(pc); } } int curCount = pcList.Count; pcList = pcList.GetRange(0, Math.Min(curCount, _Max)); sb.AppendLine("<table cellpadding=\"0\" cellspacing=\"0\" class=\"" + _CssClass + "\">"); StringBuilder sbLeft = new StringBuilder(); StringBuilder sbRight = new StringBuilder(); string catId = string.Empty; int length = pcList.Count; int dev = length / _Columns; int left = length % _Columns; if (dev != length) { for (int i = 0; i < dev; i++) { pc = pcList[i]; sbLeft.Append(BindCategory(pc, nav)); pc = pcList[i + dev + left]; sbRight.Append(BindCategory(pc, nav)); } } else { for (int i = 0; i < length; i++) { pc = pcList[i]; sbLeft.Append("<div>"); sbLeft.Append(BindCategory(pc, nav)); sbLeft.Append("</div>"); } } if (left > 0) { for (int j = left; j > 0; j--) { pc = pcList[j + dev - left]; sbLeft.Append(BindCategory(pc, nav)); } } #region -Ignore- /* * for (int i = 0; i < pcList.Count; i++) * { * pc = pcList[i]; * if (i % _Columns == 0) * sb.AppendLine("<tr>"); * catId = GlobalSettings.Encrypt(pc.CategoryID.ToString()); * sb.AppendLine("<td>"); * sb.AppendLine("<div><a href=\"" + nav + "&ID=" + catId + "\" target=\"_blank\">" + pc.CategoryName + "</a></div>"); * pcSubList = GetSubCategories(pc.CategoryID); * for (int j = 0; j < pcSubList.Count; j++) * { * pc = pcSubList[j]; * catId = GlobalSettings.Encrypt(pc.CategoryID.ToString()); * sb.AppendLine("<a href=\"" + nav + "&ID=" + catId + "\" target=\"_blank\">" + pc.CategoryName + "</a>"); * if (j != pcSubList.Count - 1) * { * sb.Append(" | "); * } * } * sb.AppendLine("</td>"); * * if (i % _Columns == 1) * sb.AppendLine("</tr>"); * * } * */ #endregion sb.AppendLine("<tr>"); sb.AppendLine("<td>"); sb.AppendLine(sbLeft.ToString()); sb.AppendLine("</td>"); if (!string.IsNullOrEmpty(sbRight.ToString())) { sb.AppendLine("<td>"); sb.AppendLine(sbRight.ToString()); sb.AppendLine("</td>"); } sb.AppendLine("</tr>"); sb.AppendLine("</table>"); if (curCount > _Max) { sb.Append("<div class=\"list-more\"><a href=\"" + GlobalSettings.RelativeWebRoot + "pages/view.aspx?product-category\" title=\"查看全部。。。\"></a></div>"); } return(sb.ToString()); }