Exemple #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);
        }
Exemple #2
0
        private static List <MyExpress> GetExpressList(XmlNodeList expressList)
        {
            List <MyExpress> listExpress = new List <MyExpress>();

            if (expressList != null && expressList.Count > 0)
            {
                for (int j = 0; j < expressList.Count; j++)
                {
                    string   express    = expressList[j].InnerText;
                    string[] conditions = express.Split('♂');
                    if (conditions.Length < 3)
                    {
                        continue;
                    }
                    MyExpress myexpress = new MyExpress();
                    string    field     = conditions[0];
                    string    sign      = conditions[1];
                    string    values    = conditions[2];
                    myexpress.field = field;
                    myexpress.sign  = sign;

                    if (!string.IsNullOrWhiteSpace(values))
                    {
                        string[] arrValues = values.Split('♀');
                        List <Dictionary <string, string> > listValues = new List <Dictionary <string, string> >();
                        Dictionary <string, string>         kv         = new Dictionary <string, string>();
                        for (int m = 0; m < arrValues.Length; m++)
                        {
                            string[] value = arrValues[m].Split('*');
                            kv[value[0]] = value[1];
                        }
                        myexpress.dicConditions = kv;
                    }
                    listExpress.Add(myexpress);
                }
            }

            return(listExpress);
        }