///// <summary> ///// loopPage分页标签的匹配替换 ///// </summary> ///// <param name="template">模板内容</param> public string loopPage(string template) { string Attributes = ""; string Text = ""; string AllText = ""; Regex r = new Regex(@"(\[SG:loopPage\s+(?<attributes>[^\]]*?)\](?<text>[\s\S]*?)\[/SG:loopPage\])", RegexOptions.Compiled | RegexOptions.IgnoreCase); foreach (Match m in r.Matches(template)) { Attributes = m.Groups["attributes"].ToString(); //循环属性集 Text = m.Groups["text"].ToString(); //循环的内容不包含SG:Loop AllText = m.Groups[0].Value.ToString(); //整个匹配的内容包含SG:Loop #region 取得相关属性 string NewsCount = null; //调用数量 string TitleNum = null; //新闻标题的显示字符数量 string ding = null; string tuijian = null; string NewsType = null; //调用新闻的类型 string Templet = null; // 模板ID string Pagesize = null; // string SQL = null; NewsCount = TagVal(Attributes, "NewsCount"); if (NewsCount == null) { NewsCount = "1000"; } TitleNum = TagVal(Attributes, "TitleNum"); if (TitleNum == null) { TitleNum = "100"; } ding = TagVal(Attributes, "ding"); if (ding == null) { ding = "false"; } tuijian = TagVal(Attributes, "tuijian"); if (tuijian == null) { tuijian = "false"; } NewsType = TagVal(Attributes, "NewsType"); if (NewsType == null) { NewsType = "0"; } if (this.classs != null) { NewsType = this.classs; } Templet = TagVal(Attributes, "Templet"); Pagesize = TagVal(Attributes, "Pagesize"); if (Pagesize == null) { Pagesize = "30"; } SQL = TagVal(Attributes, "SQL"); #endregion #region 构造 查询SQL语句 //SQL语句拼接 string strWher = ""; StringBuilder strSql = new StringBuilder(); if (SQL == null) { strWher = "classname='" + NewsType + "'"; strSql.Append("select top "); strSql.Append(NewsCount); strSql.Append(" * from [" + config.date_prefix + "news] where "); strSql.Append(strWher); strSql.Append(" AND switchs='0'"); if (ding == "true") { strSql.Append(" AND ding='0'"); } if (tuijian == "true") { strSql.Append(" AND tuijian='0'"); } strSql.Append(" order by switchs,bh DESC"); } else { strSql.Append(SQL); } #endregion #region 对循环的内容进行替换 string content = ""; DataSet Pa = Bll.GetDataSet(strSql.ToString()); int PageContent = Pa.Tables[0].Rows.Count;//数据总数 分页用 int PS = Convert.ToInt32(Pagesize); int p = Convert.ToInt32(pageNum == null ? "1" : pageNum) - 1; DataTable dt = new DataTable(); dt = Pa.Tables[0]; if (dt.Rows.Count > 0) { int rowsCount = p * PS + PS; if ((p * PS + PS) - dt.Rows.Count > 0) { rowsCount = dt.Rows.Count; } for (int n = p * PS; n < rowsCount; n++) { string str = Text; str = Replace(str, @"\[SG:Title\]", ROYcms.Common.input.GetSubString(dt.Rows[n]["title"].ToString(), Convert.ToInt32(TitleNum))); str = Replace(str, @"\[SG:Id\]", dt.Rows[n]["bh"].ToString()); str = Replace(str, @"\[SG:Url\]", dt.Rows[n]["url"].ToString()); str = Replace(str, @"\[SG:Link\]", dt.Rows[n]["jumpurl"].ToString() == "" ? (config.web_host + TemplateZone.Zpath(this.pageHost) + "show" + Templet + "-" + dt.Rows[n]["bh"].ToString() + "-" + Convert.ToDateTime(dt.Rows[n]["time"]).ToString("yyyyMM") + config.web_forge) : dt.Rows[n]["jumpurl"].ToString()); str = Replace(str, @"\[SG:_Link\]", dt.Rows[n]["jumpurl"].ToString() == "" ? ("show-" + dt.Rows[n]["bh"].ToString() + "-" + Convert.ToDateTime(dt.Rows[n]["time"]).ToString("yyyyMM") + config.web_forge) : dt.Rows[n]["jumpurl"].ToString()); str = Replace(str, @"\[SG:Pic\]", dt.Rows[n]["pic"].ToString()); str = Replace(str, @"\[SG:Zhaiyao\]", dt.Rows[n]["zhaiyao"].ToString()); str = Replace(str, @"\[SG:Keyword\]", dt.Rows[n]["keyword"].ToString()); str = Replace(str, @"\[SG:classname\]", dt.Rows[n]["classname"].ToString()); str = Replace(str, @"\[SG:Content\]", dt.Rows[n]["contents"].ToString()); str = Replace(str, @"\[SG:Infor\]", dt.Rows[n]["infor"].ToString()); str = Replace(str, @"\[SG:Author\]", dt.Rows[n]["author"].ToString()); str = Replace(str, @"\[SG:Tag\]", dt.Rows[n]["tag"].ToString()); str = Replace(str, @"\[SG:Dig\]", dt.Rows[n]["dig"].ToString()); str = Replace(str, @"\[SG:Hits\]", dt.Rows[n]["hits"].ToString()); str = Replace(str, @"\[SG:Time\]", dt.Rows[n]["time"].ToString()); str = Replace(str, @"\[SG:Year\]", Convert.ToDateTime(dt.Rows[n]["time"]).Date.Year.ToString()); str = Replace(str, @"\[SG:Month\]", Convert.ToDateTime(dt.Rows[n]["time"]).Date.Month.ToString()); str = Replace(str, @"\[SG:Day\]", Convert.ToDateTime(dt.Rows[n]["time"]).Date.Day.ToString()); content += str; } } else { content = ""; } #endregion template = template.Replace(AllText, content); template = template.Replace(@"[SG:Page]", PageContent.ToString()); if (this.classs != null) { ROYcms.Sys.BLL.ROYcms_class ROYcms_classBLL = new ROYcms.Sys.BLL.ROYcms_class(); template = template.Replace(@"[SG:ClassTitle]", ROYcms_classBLL.GetClassTitle(Convert.ToInt32(this.classs))); } } return(template); }
// 获取类的名称 public string GetClassTitle(int id) { return(ROYcms_class_Bll.GetClassTitle(id)); }