示例#1
0
        /// <summary>
        /// 风向标数据标页面
        /// </summary>
        /// <param name="tag"></param>
        private void directionFragment(Tag tag)
        {
            object collection = null;
            string clsid      = ((StringLiteral)tag.AttributeValue("clsid")).Content;
            string dataId     = ((StringLiteral)tag.AttributeValue("id")).Content;
            //int count = int.Parse(((StringLiteral)tag.AttributeValue("count")).Content);
            //if (count.ToString() == null)
            //{
            //    count = 1;
            //}
            DirectionBLL directionBLL = Factory.BusinessFactory.CreateBll <DirectionBLL>();

            SqlWhereList where = new SqlWhereList();
            where.Add("TypeId", clsid);
            List <Direction> list = directionBLL.GetAll(where);

            // NewsBLL newsBll = Factory.BusinessFactory.CreateBll<NewsBLL>();
            // List<News> list = newsBll.GetNewsOneInfo(clsid, count);

            SetValue(dataId, list);
            collection = list;

            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();
                }
            }
            IEnumerator ienum = ((IEnumerable)collection).GetEnumerator();
            int         index = 0;

            while (ienum.MoveNext())
            {
                index++;
                object value = ienum.Current;
                variables[varname] = value;
                if (indexname != null)
                {
                    variables[indexname] = index;
                }

                ProcessElements(tag.InnerElements);
            }
        }