コード例 #1
0
        /// <summary>
        /// 根据模板组装返回数据List的HTML内容
        /// </summary>
        /// <typeparam name="T">行数据类型</typeparam>
        /// <param name="list">数据列表</param>
        /// <param name="rowTemplate">行模板</param>
        /// <param name="listExpress"></param>
        /// <returns></returns>
        public static string GetListFromTemplate <T>(IEnumerable <T> list, string rowTemplate, List <MyExpress> listExpress)
        {
            string htmlTotal = null;

            PropertyInfo[] arrs = KTUtils.GetPropertyArray <T>();
            for (int i = 0; i < list.Count(); i++)
            {
                T      item    = list.ElementAt(i);
                string rowhtml = rowTemplate;
                // {字段}替换为值
                for (int j = 0; j < arrs.Length; j++)
                {
                    string pro = arrs[j].Name;

                    string value = KTUtils.GetObjectPropertyValue <T>(item, pro);
                    rowhtml = rowhtml.Replace("{" + pro.ToLower() + "}", value);

                    // 处理expressfield配置
                    if (listExpress != null && listExpress.Count > 0)
                    {
                        for (int m = 0; m < listExpress.Count; m++)
                        {
                            MyExpress obj = listExpress[m];
                            if (obj.sign == "equal")
                            {
                                // 目前只处理 等于情况 TODO:更多情况,如大小比较类
                                if (obj.field == pro)
                                {
                                    // 获取值对应的html
                                    if (obj.dicConditions.ContainsKey(value))
                                    {
                                        string v = obj.dicConditions[value];
                                        rowhtml = rowhtml.Replace("#" + pro.ToLower() + "#", v);
                                    }
                                }
                            }

                            if (j == arrs.Length - 1 && m == listExpress.Count - 1)
                            {
                                // 最后一个,替换掉默认的
                                rowhtml = rowhtml.Replace("#" + pro.ToLower() + "#", obj.dicConditions["else"]);
                            }
                        }
                    }
                }


                // 更新行号
                rowhtml    = rowhtml.Replace("#rowid#", i.ToString());
                htmlTotal += rowhtml;
            }


            return(htmlTotal);
        }
コード例 #2
0
        /// <summary>
        /// 根据模板组装返回数据List的HTML内容
        /// </summary>
        /// <typeparam name="T">行数据类型</typeparam>
        /// <param name="list">数据列表</param>
        /// <param name="rowTemplate">行模板</param>
        /// <returns></returns>
        public static string GetListFromTemplate <T>(IEnumerable <T> list, string rowTemplate)
        {
            string htmlTotal = null;

            PropertyInfo[] arrs = KTUtils.GetPropertyArray <T>();
            for (int i = 0; i < list.Count(); i++)
            {
                T      item    = list.ElementAt(i);
                string rowhtml = rowTemplate;
                for (int j = 0; j < arrs.Length; j++)
                {
                    string pro = arrs[j].Name;

                    string value = KTUtils.GetObjectPropertyValue <T>(item, pro);
                    rowhtml = rowhtml.Replace("{" + pro.ToLower() + "}", value);
                }
                // 更新行号
                rowhtml    = rowhtml.Replace("#rowid#", i.ToString());
                htmlTotal += rowhtml;
            }

            return(htmlTotal);
        }