Пример #1
0
        public static string RemoveQuotesForJavaScriptMethods(string input, JQGrid grid)
        {
            string text = input;

            foreach (JQGridColumn current in grid.Columns)
            {
                if (current.EditActionIconsColumn)
                {
                    string oldValue = string.Format("\"afterSave\":\"{0}\"", current.EditActionIconsSettings.Events.AfterSave ?? "");
                    string newValue = string.Format("\"afterSave\":{0}", current.EditActionIconsSettings.Events.AfterSave ?? "");
                    text     = text.Replace(oldValue, newValue);
                    oldValue = string.Format("\"onSuccess\":\"{0}\"", current.EditActionIconsSettings.Events.OnSuccess ?? "");
                    newValue = string.Format("\"onSuccess\":{0}", current.EditActionIconsSettings.Events.OnSuccess ?? "");
                    text     = text.Replace(oldValue, newValue);
                    oldValue = string.Format("\"onError\":\"{0}\"", current.EditActionIconsSettings.Events.OnError ?? "");
                    newValue = string.Format("\"onError\":{0}", current.EditActionIconsSettings.Events.OnError ?? "");
                    text     = text.Replace(oldValue, newValue);
                }
                if (current.Formatter != null)
                {
                    JQGridColumnFormatter formatter = current.Formatter;
                    if (formatter is CustomFormatter)
                    {
                        CustomFormatter customFormatter = (CustomFormatter)formatter;
                        string          oldValue        = string.Format("\"formatter\":\"{0}\"", customFormatter.FormatFunction);
                        string          newValue        = string.Format("\"formatter\":{0}", customFormatter.FormatFunction);
                        text     = text.Replace(oldValue, newValue);
                        oldValue = string.Format("\"unformat\":\"{0}\"", customFormatter.UnFormatFunction);
                        newValue = string.Format("\"unformat\":{0}", customFormatter.UnFormatFunction);
                        text     = text.Replace(oldValue, newValue);
                    }
                }
                foreach (JQGridEditClientSideValidator current2 in current.EditClientSideValidators)
                {
                    if (current2 is CustomValidator)
                    {
                        CustomValidator customValidator = (CustomValidator)current2;
                        string          oldValue2       = string.Format("\"custom_func\":\"{0}\"", customValidator.ValidationFunction);
                        string          newValue2       = string.Format("\"custom_func\":{0}", customValidator.ValidationFunction);
                        text = text.Replace(oldValue2, newValue2);
                    }
                }
                if (current.EditType == EditType.Custom)
                {
                    string oldValue3 = string.Format("\"custom_element\":\"{0}\"", current.EditTypeCustomCreateElement);
                    string newValue3 = string.Format("\"custom_element\":{0}", current.EditTypeCustomCreateElement);
                    text      = text.Replace(oldValue3, newValue3);
                    oldValue3 = string.Format("\"custom_value\":\"{0}\"", current.EditTypeCustomGetValue);
                    newValue3 = string.Format("\"custom_value\":{0}", current.EditTypeCustomGetValue);
                    text      = text.Replace(oldValue3, newValue3);
                }
                if ((current.Editable && current.EditType == EditType.DatePicker) || current.EditType == EditType.AutoComplete)
                {
                    string attachEditorsFunction = GridUtil.GetAttachEditorsFunction(grid, current.EditType.ToString().ToLower(), current.EditorControlID);
                    text = text.Replace(string.Concat(new object[]
                    {
                        '"',
                        "attachEditControlsScript",
                        current.DataField,
                        '"'
                    }), attachEditorsFunction);
                    text = text.Replace('"' + "dataInit" + '"', "dataInit");
                }
                if ((current.Searchable && current.SearchType == SearchType.DatePicker) || current.SearchType == SearchType.AutoComplete)
                {
                    string attachEditorsFunction2 = GridUtil.GetAttachEditorsFunction(grid, current.SearchType.ToString().ToLower(), current.SearchControlID);
                    text = text.Replace(string.Concat(new object[]
                    {
                        '"',
                        "attachSearchControlsScript",
                        current.DataField,
                        '"'
                    }), attachEditorsFunction2);
                    text = text.Replace('"' + "dataInit" + '"', "dataInit");
                }
            }
            return(text);
        }
Пример #2
0
 public JsonColModel(JQGrid grid)
 {
     this._jsonValues = new Hashtable();
     this._grid       = grid;
 }
Пример #3
0
 public JsonColModel(JQGridColumn column, JQGrid grid) : this(grid)
 {
     this.FromColumn(column);
 }
        private string GetSearchOptions(JQGrid grid)
        {
            JsonSearchDialog jsonSearchDialog = new JsonSearchDialog(grid);

            return(jsonSearchDialog.Process());
        }
        private string GetStartupOptions(JQGrid grid, bool subGrid)
        {
            StringBuilder stringBuilder   = new StringBuilder();
            string        arg             = subGrid ? "jQuery('#' + subgrid_table_id)" : string.Format("jQuery('#{0}')", grid.ID);
            string        arg2            = subGrid ? "jQuery('#' + pager_id)" : string.Format("jQuery('#{0}')", grid.ID + "_pager");
            string        pagerSelectorID = subGrid ? "'#' + pager_id" : string.Format("'#{0}'", grid.ID + "_pager");
            string        text            = subGrid ? "&parentRowID=' + row_id + '" : string.Empty;
            string        text2           = (grid.DataUrl.IndexOf("?") > 0) ? "&" : "?";
            string        text3           = (grid.EditUrl.IndexOf("?") > 0) ? "&" : "?";
            string        arg3            = string.Format("{0}{1}jqGridID={2}{3}", new object[]
            {
                grid.DataUrl,
                text2,
                grid.ID,
                text
            });
            string arg4 = string.Format("{0}{1}jqGridID={2}&editMode=1{3}", new object[]
            {
                grid.EditUrl,
                text3,
                grid.ID,
                text
            });

            stringBuilder.AppendFormat("{0}.jqGrid({{", arg);
            stringBuilder.AppendFormat("url: '{0}'", arg3);
            if (grid.PostData != null)
            {
                stringBuilder.AppendFormat(",postData: {0}", Json.Serialize(grid.PostData, true));
            }
            stringBuilder.AppendFormat(",editurl: '{0}'", arg4);
            stringBuilder.AppendFormat(",mtype: 'POST'", new object[0]);
            stringBuilder.AppendFormat(",datatype: 'json'", new object[0]);
            stringBuilder.AppendFormat(",page: {0}", grid.PagerSettings.CurrentPage);
            stringBuilder.AppendFormat(",colNames: {0}", this.GetColNames(grid));
            stringBuilder.AppendFormat(",colModel: {0}", this.GetColModel(grid));
            stringBuilder.AppendFormat(",viewrecords: true", new object[0]);
            stringBuilder.AppendFormat(",scrollrows: false", new object[0]);
            stringBuilder.AppendFormat(",prmNames: {{ id: \"{0}\" }}", Util.GetPrimaryKeyField(grid));
            if (grid.LoadOnce)
            {
                stringBuilder.AppendLine(",loadonce: true");
            }
            if (grid.AppearanceSettings.ShowFooter)
            {
                stringBuilder.AppendLine(",footerrow: true");
                stringBuilder.AppendLine(",userDataOnFooter: true");
            }
            if (!grid.AppearanceSettings.ShrinkToFit)
            {
                stringBuilder.AppendLine(",shrinkToFit: false");
            }
            if (grid.ColumnReordering)
            {
                stringBuilder.AppendLine(",sortable: true");
            }
            if (grid.AppearanceSettings.ScrollBarOffset != 18)
            {
                stringBuilder.AppendFormat(",scrollOffset: {0}", grid.AppearanceSettings.ScrollBarOffset);
            }
            if (grid.AppearanceSettings.RightToLeft)
            {
                stringBuilder.AppendLine(",direction: 'rtl'");
            }
            if (grid.AutoWidth)
            {
                stringBuilder.AppendLine(",autowidth: true");
            }
            if (!grid.ShrinkToFit)
            {
                stringBuilder.AppendLine(",shrinkToFit: false");
            }
            if (grid.ToolBarSettings.ToolBarPosition == ToolBarPosition.Bottom || grid.ToolBarSettings.ToolBarPosition == ToolBarPosition.TopAndBottom)
            {
                stringBuilder.AppendFormat(",pager: {0}", arg2);
            }
            if (grid.ToolBarSettings.ToolBarPosition == ToolBarPosition.Top || grid.ToolBarSettings.ToolBarPosition == ToolBarPosition.TopAndBottom)
            {
                stringBuilder.AppendLine(",toppager: true");
            }
            if (grid.RenderingMode == RenderingMode.Optimized)
            {
                if (grid.HierarchySettings.HierarchyMode != HierarchyMode.None)
                {
                    throw new Exception("Optimized rendering is not compatible with hierarchy.");
                }
                stringBuilder.AppendLine(",gridview: true");
            }
            if (grid.HierarchySettings.HierarchyMode == HierarchyMode.Parent || grid.HierarchySettings.HierarchyMode == HierarchyMode.ParentAndChild)
            {
                stringBuilder.AppendLine(",subGrid: true");
                stringBuilder.AppendFormat(",subGridOptions: {0}", grid.HierarchySettings.ToJSON());
            }
            if (!string.IsNullOrEmpty(grid.ClientSideEvents.SubGridRowExpanded))
            {
                stringBuilder.AppendFormat(",subGridRowExpanded: {0}", grid.ClientSideEvents.SubGridRowExpanded);
            }
            if (!string.IsNullOrEmpty(grid.ClientSideEvents.ServerError))
            {
                stringBuilder.AppendFormat(",errorCell: {0}", grid.ClientSideEvents.ServerError);
            }
            if (!string.IsNullOrEmpty(grid.ClientSideEvents.RowSelect))
            {
                stringBuilder.AppendFormat(",onSelectRow: {0}", grid.ClientSideEvents.RowSelect);
            }
            if (!string.IsNullOrEmpty(grid.ClientSideEvents.ColumnSort))
            {
                stringBuilder.AppendFormat(",onSortCol: {0}", grid.ClientSideEvents.ColumnSort);
            }
            if (!string.IsNullOrEmpty(grid.ClientSideEvents.RowDoubleClick))
            {
                stringBuilder.AppendFormat(",ondblClickRow: {0}", grid.ClientSideEvents.RowDoubleClick);
            }
            if (!string.IsNullOrEmpty(grid.ClientSideEvents.RowRightClick))
            {
                stringBuilder.AppendFormat(",onRightClickRow: {0}", grid.ClientSideEvents.RowRightClick);
            }
            if (!string.IsNullOrEmpty(grid.ClientSideEvents.LoadDataError))
            {
                stringBuilder.AppendFormat(",loadError: {0}", grid.ClientSideEvents.LoadDataError);
            }
            else
            {
                stringBuilder.AppendFormat(",loadError: {0}", "jqGrid_aspnet_loadErrorHandler");
            }
            if (!string.IsNullOrEmpty(grid.ClientSideEvents.GridInitialized))
            {
                stringBuilder.AppendFormat(",gridComplete: {0}", grid.ClientSideEvents.GridInitialized);
            }
            if (!string.IsNullOrEmpty(grid.ClientSideEvents.BeforeAjaxRequest))
            {
                stringBuilder.AppendFormat(",beforeRequest: {0}", grid.ClientSideEvents.BeforeAjaxRequest);
            }
            if (!string.IsNullOrEmpty(grid.ClientSideEvents.AfterAjaxRequest))
            {
                stringBuilder.AppendFormat(",loadComplete: {0}", grid.ClientSideEvents.AfterAjaxRequest);
            }
            if (grid.TreeGridSettings.Enabled)
            {
                stringBuilder.AppendFormat(",treeGrid: true", new object[0]);
                stringBuilder.AppendFormat(",treedatatype: 'json'", new object[0]);
                stringBuilder.AppendFormat(",treeGridModel: 'adjacency'", new object[0]);
                string arg5 = "{ level_field: 'tree_level', parent_id_field: 'tree_parent', leaf_field: 'tree_leaf', expanded_field: 'tree_expanded', loaded: 'tree_loaded', icon_field: 'tree_icon' }";
                stringBuilder.AppendFormat(",treeReader: {0}", arg5);
                stringBuilder.AppendFormat(",ExpandColumn: '{0}'", this.GetFirstVisibleDataField(grid));
                Hashtable hashtable = new Hashtable();
                if (!string.IsNullOrEmpty(grid.TreeGridSettings.CollapsedIcon))
                {
                    hashtable.Add("plus", grid.TreeGridSettings.CollapsedIcon);
                }
                if (!string.IsNullOrEmpty(grid.TreeGridSettings.ExpandedIcon))
                {
                    hashtable.Add("minus", grid.TreeGridSettings.ExpandedIcon);
                }
                if (!string.IsNullOrEmpty(grid.TreeGridSettings.LeafIcon))
                {
                    hashtable.Add("leaf", grid.TreeGridSettings.LeafIcon);
                }
                if (hashtable.Count > 0)
                {
                    stringBuilder.AppendFormat(",treeIcons: {0}", new JavaScriptSerializer().Serialize(hashtable));
                }
            }
            if (!grid.AppearanceSettings.HighlightRowsOnHover)
            {
                stringBuilder.AppendLine(",hoverrows: false");
            }
            if (grid.AppearanceSettings.AlternateRowBackground)
            {
                stringBuilder.AppendLine(",altRows: true");
            }
            if (!String.IsNullOrEmpty(grid.AppearanceSettings.AlternateRowCssClass))
            {
                stringBuilder.AppendFormat(",altclass: '{0}'", grid.AppearanceSettings.AlternateRowCssClass);
            }
            if (grid.AppearanceSettings.ShowRowNumbers)
            {
                stringBuilder.AppendLine(",rownumbers: true");
            }
            if (grid.AppearanceSettings.RowNumbersColumnWidth != 25)
            {
                stringBuilder.AppendFormat(",rownumWidth: {0}", grid.AppearanceSettings.RowNumbersColumnWidth.ToString());
            }

            if (!grid.PagerSettings.ShowPagerButtons)               // !!! FDV
            {
                stringBuilder.AppendFormat(",pgbuttons: false", new object[0]);
            }
            if (!grid.PagerSettings.ShowPageInputBox)               // !!! FDV
            {
                stringBuilder.AppendFormat(",pginput: false", new object[0]);
            }
            if (grid.PagerSettings.ScrollBarPaging)
            {
                stringBuilder.AppendFormat(",scroll: 1", new object[0]);
            }
            stringBuilder.AppendFormat(",rowNum: {0}", grid.PagerSettings.PageSize.ToString());
            stringBuilder.AppendFormat(",rowList: {0}", grid.PagerSettings.PageSizeOptions.ToString());
            if (!string.IsNullOrEmpty(grid.PagerSettings.NoRowsMessage))
            {
                stringBuilder.AppendFormat(",emptyrecords: '{0}'", grid.PagerSettings.NoRowsMessage.ToString());
            }
            stringBuilder.AppendFormat(",editDialogOptions: {0}", this.GetEditOptions(grid));
            stringBuilder.AppendFormat(",addDialogOptions: {0}", this.GetAddOptions(grid));
            stringBuilder.AppendFormat(",delDialogOptions: {0}", this.GetDelOptions(grid));
            stringBuilder.AppendFormat(",searchDialogOptions: {0}", this.GetSearchOptions(grid));
            string format;

            if (grid.TreeGridSettings.Enabled)
            {
                format = ",jsonReader: {{ id: \"{0}\", repeatitems:false,subgrid:{{repeatitems:false}} }}";
            }
            else
            {
                format = ",jsonReader: {{ id: \"{0}\" }}";
            }
            stringBuilder.AppendFormat(format, grid.Columns[Util.GetPrimaryKeyIndex(grid)].DataField);
            if (!string.IsNullOrEmpty(grid.SortSettings.InitialSortColumn))
            {
                stringBuilder.AppendFormat(",sortname: '{0}'", grid.SortSettings.InitialSortColumn);
            }
            stringBuilder.AppendFormat(",sortorder: '{0}'", grid.SortSettings.InitialSortDirection.ToString().ToLower());
            if (grid.MultiSelect)
            {
                stringBuilder.AppendLine(",multiselect: true");
                if (grid.MultiSelectMode == MultiSelectMode.SelectOnCheckBoxClickOnly)
                {
                    stringBuilder.AppendFormat(",multiboxonly: true", grid.MultiSelect.ToString().ToLower());
                }
                if (grid.MultiSelectKey != MultiSelectKey.None)
                {
                    stringBuilder.AppendFormat(",multikey: '{0}'", this.GetMultiKeyString(grid.MultiSelectKey));
                }
            }
            if (!string.IsNullOrEmpty(grid.AppearanceSettings.Caption))
            {
                stringBuilder.AppendFormat(",caption: '{0}'", grid.AppearanceSettings.Caption);
            }
            if (!grid.Width.IsEmpty)
            {
                stringBuilder.AppendFormat(",width: '{0}'", grid.Width.ToString().Replace("px", ""));
            }
            if (!grid.Height.IsEmpty)
            {
                stringBuilder.AppendFormat(",height: '{0}'", grid.Height.ToString().Replace("px", ""));
            }
            if (grid.GroupSettings.GroupFields.Count > 0)
            {
                stringBuilder.AppendLine(",grouping:true");
                stringBuilder.AppendLine(",groupingView: {");
                stringBuilder.AppendFormat("groupField: ['{0}']", grid.GroupSettings.GroupFields[0].DataField);
                stringBuilder.AppendFormat(",groupColumnShow: [{0}]", grid.GroupSettings.GroupFields[0].ShowGroupColumn.ToString().ToLower());
                stringBuilder.AppendFormat(",groupText: ['{0}']", grid.GroupSettings.GroupFields[0].HeaderText);
                stringBuilder.AppendFormat(",groupOrder: ['{0}']", grid.GroupSettings.GroupFields[0].GroupSortDirection.ToString().ToLower());
                stringBuilder.AppendFormat(",groupSummary: [{0}]", grid.GroupSettings.GroupFields[0].ShowGroupSummary.ToString().ToLower());
                stringBuilder.AppendFormat(",groupCollapse: {0}", grid.GroupSettings.CollapseGroups.ToString().ToLower());
                stringBuilder.AppendFormat(",groupDataSorted: true", new object[0]);
                stringBuilder.Append("}");
            }
            stringBuilder.AppendFormat(",viewsortcols: [{0},'{1}',{2}]", "false", grid.SortSettings.SortIconsPosition.ToString().ToLower(), (grid.SortSettings.SortAction == SortAction.ClickOnHeader) ? "true" : "false");
            stringBuilder.AppendFormat("}})\r", new object[0]);
            stringBuilder.Append(this.GetToolBarOptions(grid, subGrid, pagerSelectorID));
            if (!grid.PagerSettings.ScrollBarPaging)
            {
                stringBuilder.AppendFormat(".bindKeys()", new object[0]);
            }
            stringBuilder.Append(";");
            stringBuilder.Append(this.GetLoadErrorHandler());
            stringBuilder.Append(";");
            if (grid.HeaderGroups.Count > 0)
            {
                List <Hashtable> list = new List <Hashtable>();
                foreach (JQGridHeaderGroup current in grid.HeaderGroups)
                {
                    list.Add(current.ToHashtable());
                }
                stringBuilder.AppendFormat("{0}.setGroupHeaders( {{ useColSpanStyle:true,groupHeaders:{1} }});", arg, new JavaScriptSerializer().Serialize(list));
            }
            if (grid.ToolBarSettings.ShowSearchToolBar)
            {
                stringBuilder.AppendFormat("{0}.filterToolbar({1});", arg, new JsonSearchToolBar(grid).Process());
            }
            return(stringBuilder.ToString());
        }
        private string GetEditOptions(JQGrid grid)
        {
            JsonEditDialog jsonEditDialog = new JsonEditDialog(grid);

            return(jsonEditDialog.Process());
        }
        private string GetDelOptions(JQGrid grid)
        {
            JsonDelDialog jsonDelDialog = new JsonDelDialog(grid);

            return(jsonDelDialog.Process());
        }
Пример #8
0
 public JsonSearchDialog(JQGrid grid)
 {
     this._jsonValues = new Hashtable();
     this._grid       = grid;
 }
Пример #9
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);
 }
Пример #10
0
        public static string GetPrimaryKeyField(JQGrid grid)
        {
            int primaryKeyIndex = Util.GetPrimaryKeyIndex(grid);

            return(grid.Columns[primaryKeyIndex].DataField);
        }
        private static DataTable ObtainDataTableFromIEnumerable(IEnumerable ien, JQGrid grid)
        {
            DataTable dataTable = new DataTable();

            foreach (object obj1 in ien)
            {
                if (obj1 is DbDataRecord)
                {
                    DbDataRecord dbDataRecord = obj1 as DbDataRecord;
                    if (dataTable.Columns.Count == 0)
                    {
                        foreach (JQGridColumn jqGridColumn in grid.Columns)
                        {
                            dataTable.Columns.Add(jqGridColumn.DataField);
                        }
                    }
                    DataRow row = dataTable.NewRow();
                    foreach (JQGridColumn jqGridColumn in grid.Columns)
                    {
                        row[jqGridColumn.DataField] = dbDataRecord[jqGridColumn.DataField];
                    }
                    dataTable.Rows.Add(row);
                }
                else if (obj1 is DataRow)
                {
                    DataRow dataRow = obj1 as DataRow;
                    if (dataTable.Columns.Count == 0)
                    {
                        foreach (JQGridColumn jqGridColumn in grid.Columns)
                        {
                            dataTable.Columns.Add(jqGridColumn.DataField);
                        }
                    }
                    DataRow row = dataTable.NewRow();
                    foreach (JQGridColumn jqGridColumn in grid.Columns)
                    {
                        row[jqGridColumn.DataField] = dataRow[jqGridColumn.DataField];
                    }
                    dataTable.Rows.Add(row);
                }
                else
                {
                    PropertyInfo[] properties = obj1.GetType().GetProperties();
                    if (dataTable.Columns.Count == 0)
                    {
                        foreach (PropertyInfo propertyInfo in properties)
                        {
                            Type type = propertyInfo.PropertyType;
                            if (type.IsGenericType && type.GetGenericTypeDefinition() == typeof(Nullable <>))
                            {
                                type = Nullable.GetUnderlyingType(type);
                            }
                            dataTable.Columns.Add(propertyInfo.Name, type);
                        }
                    }
                    DataRow row = dataTable.NewRow();
                    foreach (PropertyInfo propertyInfo in properties)
                    {
                        object obj2 = propertyInfo.GetValue(obj1, (object[])null);
                        row[propertyInfo.Name] = obj2 == null ? (object)DBNull.Value : obj2;
                    }
                    dataTable.Rows.Add(row);
                }
            }
            return(dataTable);
        }
Пример #12
0
 public JsonEditDialog(JQGrid grid)
 {
     this._json       = new JavaScriptSerializer();
     this._jsonValues = new Hashtable();
     this._grid       = grid;
 }