Exemple #1
0
        /**
         * @ 获取枚举的字符串表现形式
         * */
        public static string GetEnumString(this SQLExpression.Order value)
        {
            if (value == SQLExpression.Order.ASC)
            {
                return("ASC");
            }

            return("DESC");
        }
Exemple #2
0
 /**
  * @ 设置排序
  * @ field 排序字段名称
  * @ order 指定排序方式
  * */
 public void SetOrderBy(string field, SQLExpression.Order direction)
 {
     orderBy = string.Format(" ORDER BY {0} {1}", field, direction);
 }
Exemple #3
0
        /**
         * @ 设置排序
         * @ tableFields 表字段集合,形如url参数key:数据库真实字段名称
         * @ orderby 客户端传回要排序的参数,形如:key,order,key即名称,order用int表示,具体参考LdfSQLExpression.Order,0:ASC,1:DESC
         * @ separator 客户端排序参数的分隔符号
         * @ defaultField 默认排序字段
         * @ defaultDirection 默认排序方式
         * */
        public string SetOrderBy(Dictionary <string, string> tableFields, string orderby, char separator, string defaultField, SQLExpression.Order defaultDirection = SQLExpression.Order.DESC)
        {
            if (defaultField.IsNullOrEmpty())
            {
                throw new ArgumentException("必须设置默认排序字段");
            }

            string orderField = defaultField;

            string[] orderValue = orderby.Split(separator);
            if (orderValue.IsNotNullAndEq(2))
            {
                string okey = orderValue[0];
                if (tableFields.ContainsKey(okey))
                {
                    defaultField = tableFields[okey];
                    string dire = orderValue[1];

                    if (dire.IsEnum <SQLExpression.Order, string>())
                    {
                        defaultDirection = dire.ToEnum <SQLExpression.Order>();
                    }
                }
            }

            SetOrderBy(defaultField, defaultDirection);

            return(orderField);
        }