Esempio n. 1
0
        public static FieldListOrder FromJson(string json)
        {
            TkDebug.AssertArgumentNullOrEmpty(json, "json", null);

            FieldListOrder result = new FieldListOrder();

            result.ReadJson(json);
            return(result);
        }
Esempio n. 2
0
        private FieldListOrder ParseSortParams2(IInputData input)
        {
            string         jsonOrder = input.QueryString["JsonOrder"];
            FieldListOrder order;

            if (input.IsPost || string.IsNullOrEmpty(jsonOrder))
            {
                if (!string.IsNullOrEmpty(OrderBy))
                {
                    order = FieldListOrder.FromSqlString(MainResolver, OrderBy);
                }
                else
                {
                    order = new FieldListOrder();
                }
            }
            else
            {
                order = FieldListOrder.FromJson(jsonOrder);
            }

            return(order);
        }
Esempio n. 3
0
        public static FieldListOrder FromSqlString(TableSelector selector, string orderBy)
        {
            FieldListOrder result = new FieldListOrder();

            if (string.IsNullOrEmpty(orderBy))
            {
                return(result);
            }

            orderBy = orderBy.Trim();
            if (orderBy.StartsWith("order by", StringComparison.OrdinalIgnoreCase))
            {
                orderBy = orderBy.Substring(8).Trim();
            }
            string[] items     = orderBy.Split(',');
            var      fieldList = selector.FieldList;

            foreach (var item in items)
            {
                var fieldInfo = fieldList.FirstOrDefault(field =>
                                                         item.IndexOf(field.FieldName, StringComparison.Ordinal) != -1);
                if (fieldInfo != null)
                {
                    DbOrder order;
                    if (item.IndexOf("DESC", StringComparison.OrdinalIgnoreCase) != -1)
                    {
                        order = DbOrder.Desc;
                    }
                    else
                    {
                        order = DbOrder.Asc;
                    }
                    result.FieldList.Add(new FieldOrder(fieldInfo.NickName, order));
                }
            }
            return(result);
        }