Beispiel #1
0
 internal static JsonResult ConvertToTreeJson(JsonTreeResponse response, JQGrid grid, DataTable dt)
 {
     return(new JsonResult
     {
         JsonRequestBehavior = JsonRequestBehavior.AllowGet,
         Data = Util.PrepareJsonTreeResponse(response, grid, dt)
     });
 }
Beispiel #2
0
 internal static JsonTreeResponse PrepareJsonTreeResponse(JsonTreeResponse response, JQGrid grid, DataTable dt)
 {
     for (int i = 0; i < dt.Rows.Count; i++)
     {
         response.rows[i] = new Hashtable();
         for (int j = 0; j < grid.Columns.Count; j++)
         {
             JQGridColumn jQGridColumn = grid.Columns[j];
             string       value        = "";
             if (!string.IsNullOrEmpty(jQGridColumn.DataField))
             {
                 int ordinal = dt.Columns[jQGridColumn.DataField].Ordinal;
                 value = (string.IsNullOrEmpty(jQGridColumn.DataFormatString) ? dt.Rows[i].ItemArray[ordinal].ToString() : jQGridColumn.FormatDataValue(dt.Rows[i].ItemArray[ordinal], jQGridColumn.HtmlEncode));
             }
             response.rows[i].Add(jQGridColumn.DataField, value);
         }
         try
         {
             response.rows[i].Add("tree_level", dt.Rows[i]["tree_level"] as int?);
         }
         catch
         {
         }
         try
         {
             response.rows[i].Add("tree_parent", Convert.ToString(dt.Rows[i]["tree_parent"]));
         }
         catch
         {
         }
         try
         {
             response.rows[i].Add("tree_leaf", dt.Rows[i]["tree_leaf"] as bool?);
         }
         catch
         {
         }
         try
         {
             response.rows[i].Add("tree_expanded", dt.Rows[i]["tree_expanded"] as bool?);
         }
         catch
         {
         }
         try
         {
             response.rows[i].Add("tree_loaded", dt.Rows[i]["tree_loaded"] as bool?);
         }
         catch
         {
         }
         try
         {
             response.rows[i].Add("tree_icon", dt.Rows[i]["tree_icon"] as string);
         }
         catch
         {
         }
     }
     return(response);
 }
Beispiel #3
0
 private JsonResult FilterDataSource(object dataSource, NameValueCollection queryString, out IQueryable iqueryable)
 {
     iqueryable = dataSource as IQueryable;
     Guard.IsNotNull(iqueryable, "DataSource", "should implement the IQueryable interface.");
     int pageIndex = this.GetPageIndex(queryString["page"]);
     int count = Convert.ToInt32(queryString["rows"]);
     string primaryKeyField = queryString["sidx"];
     string sortDirection = queryString["sord"];
     string text1 = queryString["parentRowID"];
     string str3 = queryString["_search"];
     string str4 = queryString["filters"];
     string str5 = queryString["searchField"];
     string searchString = queryString["searchString"];
     string searchOper = queryString["searchOper"];
     this.PagerSettings.CurrentPage = pageIndex;
     this.PagerSettings.PageSize = count;
     if (!string.IsNullOrEmpty(str3) && (str3 != "false"))
     {
         try
         {
             if (string.IsNullOrEmpty(str4) && !string.IsNullOrEmpty(str5))
             {
                 iqueryable = iqueryable.Where(Trirand.Web.Mvc.Util.GetWhereClause(this, str5, searchString, searchOper), new object[0]);
             }
             else if (!string.IsNullOrEmpty(str4))
             {
                 iqueryable = iqueryable.Where(Trirand.Web.Mvc.Util.GetWhereClause(this, str4), new object[0]);
             }
             else if (this.ToolBarSettings.ShowSearchToolBar || (str3 == "true"))
             {
                 iqueryable = iqueryable.Where(Trirand.Web.Mvc.Util.GetWhereClause(this, queryString), new object[0]);
             }
         }
         catch (DataTypeNotSetException exception)
         {
             throw exception;
         }
         catch (Exception)
         {
             return new JsonResult { Data = new object(), JsonRequestBehavior = JsonRequestBehavior.AllowGet };
         }
     }
     int totalRowCount = iqueryable.Count();
     int totalPagesCount = (int) Math.Ceiling((double) (((float) totalRowCount) / ((float) count)));
     if (string.IsNullOrEmpty(primaryKeyField) && this.SortSettings.AutoSortByPrimaryKey)
     {
         if (this.Columns.Count == 0)
         {
             throw new Exception("JQGrid must have at least one column defined.");
         }
         primaryKeyField = Trirand.Web.Mvc.Util.GetPrimaryKeyField(this);
         sortDirection = "asc";
     }
     if (!string.IsNullOrEmpty(primaryKeyField))
     {
         iqueryable = iqueryable.OrderBy(this.GetSortExpression(primaryKeyField, sortDirection), new object[0]);
     }
     iqueryable = iqueryable.Skip(((pageIndex - 1) * count)).Take(count);
     DataTable dt = iqueryable.ToDataTable(this);
     this.OnDataResolved(new JQGridDataResolvedEventArgs(this, iqueryable, this.DataSource as IQueryable));
     if (this.TreeGridSettings.Enabled)
     {
         JsonTreeResponse response = new JsonTreeResponse(pageIndex, totalPagesCount, totalRowCount, count, dt.Rows.Count, Trirand.Web.Mvc.Util.GetFooterInfo(this));
         return Trirand.Web.Mvc.Util.ConvertToTreeJson(response, this, dt);
     }
     JsonResponse response2 = new JsonResponse(pageIndex, totalPagesCount, totalRowCount, count, dt.Rows.Count, Trirand.Web.Mvc.Util.GetFooterInfo(this));
     return Trirand.Web.Mvc.Util.ConvertToJson(response2, this, dt);
 }
Beispiel #4
0
 internal static JsonTreeResponse PrepareJsonTreeResponse(JsonTreeResponse response, JQGrid grid, DataTable dt)
 {
     for (int i = 0; i < dt.Rows.Count; i++)
     {
         response.rows[i] = new Hashtable();
         for (int j = 0; j < grid.Columns.Count; j++)
         {
             JQGridColumn column = grid.Columns[j];
             string str = "";
             if (!string.IsNullOrEmpty(column.DataField))
             {
                 int ordinal = dt.Columns[column.DataField].Ordinal;
                 str = string.IsNullOrEmpty(column.DataFormatString) ? dt.Rows[i].ItemArray[ordinal].ToString() : column.FormatDataValue(dt.Rows[i].ItemArray[ordinal], column.HtmlEncode);
             }
             response.rows[i].Add(column.DataField, str);
         }
         try
         {
             response.rows[i].Add("tree_level", dt.Rows[i]["tree_level"] as int?);
         }
         catch
         {
         }
         try
         {
             string str2 = "";
             object obj2 = dt.Rows[i]["tree_parent"];
             if (obj2 is DBNull)
             {
                 str2 = "null";
             }
             else
             {
                 str2 = Convert.ToString(dt.Rows[i]["tree_parent"]);
             }
             response.rows[i].Add("tree_parent", str2);
         }
         catch
         {
         }
         try
         {
             response.rows[i].Add("tree_leaf", dt.Rows[i]["tree_leaf"] as bool?);
         }
         catch
         {
         }
         try
         {
             response.rows[i].Add("tree_expanded", dt.Rows[i]["tree_expanded"] as bool?);
         }
         catch
         {
         }
         try
         {
             response.rows[i].Add("tree_loaded", dt.Rows[i]["tree_loaded"] as bool?);
         }
         catch
         {
         }
         try
         {
             response.rows[i].Add("tree_icon", dt.Rows[i]["tree_icon"] as string);
         }
         catch
         {
         }
     }
     return response;
 }
Beispiel #5
0
 internal static JsonResult ConvertToTreeJson(JsonTreeResponse response, JQGrid grid, DataTable dt)
 {
     return new JsonResult { JsonRequestBehavior = JsonRequestBehavior.AllowGet, Data = PrepareJsonTreeResponse(response, grid, dt) };
 }
Beispiel #6
0
        //public ActionResult ShowEditValidationMessage(string errorMessage)
        //{
        //    HttpContext.Current.Response.Clear();
        //    HttpContext.Current.Response.StatusCode = 500;
        //    HttpContext.Current.Response.TrySkipIisCustomErrors = true;
        //    return new ContentResult
        //    {
        //        Content = errorMessage,
        //    };
        //}
        //private IQueryable FilterDataSource2(object dataSource, NameValueCollection queryString)
        //{

        //    IQueryable iqueryable = (dataSource as IQueryable);
        //    Guard.IsNotNull(iqueryable, "DataSource", "should implement the IQueryable interface.");
        //    int pageIndex = this.GetPageIndex(queryString["page"]);
        //    int num = Convert.ToInt32(queryString["rows"]);
        //    string text = queryString["sidx"];
        //    string str = queryString["sord"];
        //    string arg_5F_0 = queryString["parentRowID"];
        //    string text2 = queryString["_search"];
        //    string text3 = queryString["filters"];
        //    string text4 = queryString["searchField"];
        //    string searchString = queryString["searchString"];
        //    string searchOper = queryString["searchOper"];
        //    this.PagerSettings.CurrentPage = pageIndex;
        //    this.PagerSettings.PageSize = num;
        //    if (!string.IsNullOrEmpty(text2) && text2 != "false")
        //    {
        //        try
        //        {
        //            if (string.IsNullOrEmpty(text3) && !string.IsNullOrEmpty(text4))
        //            {
        //                iqueryable = iqueryable.Where(Util.GetWhereClause(this, text4, searchString, searchOper), new object[0]);
        //            }
        //            else
        //            {
        //                if (!string.IsNullOrEmpty(text3))
        //                {
        //                    iqueryable = iqueryable.Where(Util.GetWhereClause(this, text3), new object[0]);
        //                }
        //                else
        //                {
        //                    if (this.ToolBarSettings.ShowSearchToolBar || text2 == "true")
        //                    {
        //                        iqueryable = iqueryable.Where(Util.GetWhereClause(this, queryString), new object[0]);
        //                    }
        //                }
        //            }
        //        }
        //        catch (DataTypeNotSetException ex)
        //        {
        //            throw ex;
        //        }
        //        catch (ParseException pex)
        //        {
        //            throw pex;
        //        }
        //        catch (Exception ex)
        //        {
        //            throw ex;
        //        }
        //    }
        //    int num2 = iqueryable.Count();
        //    int totalPagesCount = (int)Math.Ceiling((double)((float)num2 / (float)num));
        //    if (string.IsNullOrEmpty(text) && this.SortSettings.AutoSortByPrimaryKey)
        //    {
        //        if (this.Columns.Count == 0)
        //        {
        //            throw new Exception("JQGrid must have at least one column defined.");
        //        }
        //        text = Util.GetPrimaryKeyField(this);
        //        str = "asc";
        //    }
        //    if (!string.IsNullOrEmpty(text))
        //    {
        //        string text5 = "";
        //        if (this.GroupSettings.GroupFields.Count > 0)
        //        {
        //            string str2 = text.Split(new char[]
        //            {
        //                ' '
        //            })[0];
        //            string str3 = text.Contains(" ") ? text.Split(new char[]
        //            {
        //                ' '
        //            })[1].Split(new char[]
        //            {
        //                ','
        //            })[0] : "asc";
        //            if (text.Contains(","))
        //            {
        //                text = text.Split(new char[]
        //                {
        //                    ','
        //                })[1];
        //            }
        //            text5 = str2 + " " + str3;
        //        }
        //        if (text != null && text == " ")
        //        {
        //            text = "";
        //        }
        //        if (!string.IsNullOrEmpty(text))
        //        {
        //            if (this.GroupSettings.GroupFields.Count > 0 && !text5.EndsWith(","))
        //            {
        //                text5 += ",";
        //            }
        //            text5 = text5 + text + " " + str;
        //        }
        //        iqueryable = iqueryable.OrderBy(text5, new object[0]);
        //    }
        //    return iqueryable;
        //}

        private JsonResult FilterDataSource(object dataSource, NameValueCollection queryString, out IQueryable iqueryable)
        {
            iqueryable = (dataSource as IQueryable);
            IQueryable ignoreFilterFieldData = iqueryable;

            Guard.IsNotNull(iqueryable, "DataSource", "should implement the IQueryable interface.");
            int    pageIndex = this.GetPageIndex(queryString["page"]);
            int    num       = Convert.ToInt32(queryString["rows"]);
            string text      = queryString["sidx"];
            string str       = queryString["sord"];
            string arg_5F_0  = queryString["parentRowID"];
            bool   isSearch  = false;
            string search    = queryString["_search"];

            if (!string.IsNullOrEmpty(search))
            {
                isSearch = search.ToLower() == "true";
            }
            //if(!string.IsNullOrEmpty(this.ClientSideEvents.SerializeGridData))
            //{
            //    text2 = "true";
            //}
            //if (!string.IsNullOrEmpty(this.ExcelExportSettings.Url))
            //{
            //    text2 = "true";
            //}
            string filters      = queryString["filters"];
            string searchFiled  = queryString["searchField"];
            string searchString = queryString["searchString"];
            string searchOper   = queryString["searchOper"];

            this.PagerSettings.CurrentPage = pageIndex;
            this.PagerSettings.PageSize    = num;
            if (isSearch)
            {
                try
                {
                    //search
                    if (!string.IsNullOrEmpty(searchFiled))
                    {
                        ignoreFilterFieldData = ignoreFilterFieldData.Where(Util.GetWhereClause(this, searchFiled, searchString, searchOper), new object[0]);
                        iqueryable            = iqueryable.Where(Util.GetWhereClause(this, searchFiled, searchString, searchOper), new object[0]);
                    }
                    //else
                    //{
                    //filters
                    if (!string.IsNullOrEmpty(filters))
                    {
                        ignoreFilterFieldData = ignoreFilterFieldData.Where(Util.GetWhereClause(this, filters, this.IgnoreFilterField), new object[0]);
                        iqueryable            = iqueryable.Where(Util.GetWhereClause(this, filters), new object[0]);
                    }
                    //else if (!string.IsNullOrEmpty(filters) && !string.IsNullOrEmpty(searchFiled))
                    //{
                    //    //filters+search
                    //    iqueryable = iqueryable.Where(Util.GetWhereClause(this, searchFiled, searchString, searchOper), new object[0]);
                    //    iqueryable = iqueryable.Where(Util.GetWhereClause(this, filters), new object[0]);
                    //}
                    //else
                    //{
                    //if (this.ToolBarSettings.ShowSearchToolBar || isSearch)
                    //{

                    string whereStr = Util.GetWhereClause(this, queryString);
                    if (!string.IsNullOrEmpty(whereStr))
                    {
                        ignoreFilterFieldData = ignoreFilterFieldData.Where(whereStr, new object[0]);
                        iqueryable            = iqueryable.Where(whereStr, new object[0]);
                    }
                    //}
                    //}
                    //}
                }
                catch (DataTypeNotSetException ex)
                {
                    throw ex;
                }
                catch (ParseException)
                {
                    return(new JsonResult
                    {
                        Data = new { Error = "表达式错误" },
                        JsonRequestBehavior = JsonRequestBehavior.AllowGet
                    });
                }
                catch (Exception)
                {
                    return(new JsonResult
                    {
                        Data = new object(),
                        JsonRequestBehavior = JsonRequestBehavior.AllowGet
                    });
                }
            }
            int num2            = iqueryable.Count();
            int totalPagesCount = (int)Math.Ceiling((double)((float)num2 / (float)num));

            if (string.IsNullOrEmpty(text) && this.SortSettings.AutoSortByPrimaryKey)
            {
                if (this.Columns.Count == 0)
                {
                    throw new Exception("JQGrid must have at least one column defined.");
                }
                text = Util.GetPrimaryKeyField(this);
                str  = "asc";
            }
            if (!string.IsNullOrEmpty(text))
            {
                string text5 = "";
                if (this.GroupSettings.GroupFields.Count > 0)
                {
                    string str2 = text.Split(new char[]
                    {
                        ' '
                    })[0];
                    string str3 = text.Contains(" ") ? text.Split(new char[]
                    {
                        ' '
                    })[1].Split(new char[]
                    {
                        ','
                    })[0] : "asc";
                    if (text.Contains(","))
                    {
                        text = text.Split(new char[]
                        {
                            ','
                        })[1];
                    }
                    text5 = str2 + " " + str3;
                }
                if (text != null && text == " ")
                {
                    text = "";
                }
                if (!string.IsNullOrEmpty(text))
                {
                    if (this.GroupSettings.GroupFields.Count > 0 && !text5.EndsWith(","))
                    {
                        text5 += ",";
                    }
                    text5 = text5 + text + " " + str;
                }
                iqueryable = iqueryable.OrderBy(text5, new object[0]);
            }
            IQueryable filterData = iqueryable;

            iqueryable = iqueryable.Skip((pageIndex - 1) * num).Take(num);
            DataTable dataTable = iqueryable.ToDataTable(this);

            this.OnDataResolved(new JQGridDataResolvedEventArgs(this, iqueryable, this.DataSource as IQueryable, filterData, ignoreFilterFieldData));
            if (this.TreeGridSettings.Enabled)
            {
                JsonTreeResponse response = new JsonTreeResponse(pageIndex, totalPagesCount, num2, num, dataTable.Rows.Count, Util.GetFooterInfo(this));
                return(Util.ConvertToTreeJson(response, this, dataTable));
            }
            JsonResponse response2 = new JsonResponse(pageIndex, totalPagesCount, num2, num, dataTable.Rows.Count, Util.GetFooterInfo(this));

            return(Util.ConvertToJson(response2, this, dataTable));
        }