/// <summary> /// 专题列表 /// </summary> /// <param name="tag"></param> private void Topiclist(Tag tag) { object collection = null; PagedResult <Topic> result; string topictype = ((StringLiteral)tag.AttributeValue("topictype")).Content; string dataId = ((StringLiteral)tag.AttributeValue("id")).Content; // int count = int.Parse(((StringLiteral)tag.AttributeValue("count")).Content); int pagesize = int.Parse(((StringLiteral)tag.AttributeValue("pagesize")).Content); int pagecount = int.Parse(((StringLiteral)tag.AttributeValue("pagecount")).Content); //if (count.ToString() == null) //{ // count = 1; //} TopicBLL topicBLL = Factory.BusinessFactory.CreateBll <TopicBLL>(); result = topicBLL.GetTopicFrontList("", topictype, pagecount, pagesize); if (result.Result == null) { SetValue("total", 0); collection = new List <News>(); } else { SetValue("total", result.Result.Count); collection = result.Result; } if (pagecount > 1) { //数据库真实的总页数 int pageTotal = result.Total % pagesize > 0 ? result.Total / pagesize + 1 : result.Total / pagesize; if (pageTotal > 0 && pageTotal < pagecount) { pagecount = pageTotal; } if (pagecount > int.Parse(variables["pagecount"].ToString())) { SetValue("pagecount", pagecount.ToString()); } } SetValue(dataId, collection); Expression expVar = tag.AttributeValue("var"); if (expVar == null) { throw new TemplateRuntimeException("foreach 语法缺少 var 属性定义.", tag.Line, tag.Col); } object varObject = EvalExpression(expVar); if (varObject == null) { varObject = "foreach"; } string varname = varObject.ToString(); Expression expIndex = tag.AttributeValue("index"); string indexname = null; if (expIndex != null) { object obj = EvalExpression(expIndex); if (obj != null) { indexname = obj.ToString(); } } //判断是否循环的最后一条标识 Expression islastExp = tag.AttributeValue("islast"); string islast = null; if (islastExp != null) { object obj = EvalExpression(islastExp); if (obj != null) { islast = obj.ToString(); } } IEnumerator ienum = ((IEnumerable)collection).GetEnumerator(); int index = 0; if (islast != null) { variables[islast] = false; } while (ienum.MoveNext()) { index++; if (index == ((List <Topic>)collection).Count && islast != null) { variables[islast] = true; } object value = ienum.Current; variables[varname] = value; if (indexname != null) { variables[indexname] = index; } ProcessElements(tag.InnerElements); } }