Esempio n. 1
0
 private static void WrtieUserData(IJqGridJsonWriter writer, JqGridJsonReader jsonReader, JqGridResponse response)
 {
     if (response.UserData != null)
     {
         writer.WriteProperty(jsonReader.UserData, response.UserData);
     }
 }
Esempio n. 2
0
        private static void WritePagingProperties(IJqGridJsonWriter writer, JqGridJsonReader jsonReader, JqGridResponse response)
        {
            writer.WriteProperty(jsonReader.PageIndex, response.PageIndex + 1);

            writer.WriteProperty(jsonReader.TotalRecordsCount, response.TotalRecordsCount);

            writer.WriteProperty(jsonReader.TotalPagesCount, response.TotalPagesCount);
        }
 internal static bool IsDefault(this JqGridJsonReader jsonReader)
 {
     return((jsonReader.PageIndex == JqGridOptionsDefaults.Response.PageIndex) &&
            (jsonReader.RecordId == JqGridOptionsDefaults.Response.RecordId) &&
            (jsonReader.TotalPagesCount == JqGridOptionsDefaults.Response.TotalPagesCount) &&
            (jsonReader.TotalRecordsCount == JqGridOptionsDefaults.Response.TotalRecordsCount) &&
            (jsonReader.UserData == JqGridOptionsDefaults.Response.UserData) &&
            ((jsonReader.SubgridReader == null) || jsonReader.SubgridReader.IsDefault()) &&
            (jsonReader as JqGridJsonRecordsReader).IsDefault());
 }
        private static IList <object> SerializeValuesRecordAsList(JqGridJsonReader jsonReader, JqGridRecord record, bool isRecordIndexInt, int recordIdIndex, bool isSubgridResponse)
        {
            IList <object> recordValues = new List <object>();

            if (!isSubgridResponse && Convert.ToString(recordValues[recordIdIndex]) != record.Id)
            {
                recordValues.Add(record.Id);
            }

            return(AppendValuesToValuesList(recordValues, record, isSubgridResponse));
        }
        private static void WriteJqGridResponse(JsonWriter writer, JsonSerializer serializer, JqGridResponse response)
        {
            JqGridJsonReader jsonReader = (response.Reader == null) ? JqGridResponse.JsonReader : response.Reader;

            writer.WriteStartObject();

            if (!response.IsSubgridResponse)
            {
                WritePagingProperties(writer, jsonReader, response);
                WrtieUserData(writer, serializer, jsonReader, response);
            }

            WriteJqGridRecords(writer, serializer, response.IsSubgridResponse, jsonReader, response.Records);

            writer.WriteEnd();
        }
        private static IDictionary <string, object> SerializeValueRecordAsDictionary(JqGridJsonReader jsonReader, JqGridRecord record, bool isRecordIndexInt, int recordIdIndex, bool isSubgridResponse)
        {
            if (record.Value == null)
            {
                throw new InvalidOperationException("JqGridRecord.Value can't be null when JqGridJsonReader.RepeatItems is set to false.");
            }

            IDictionary <string, object> recordValues = record.GetValueAsDictionary();

            if (!isSubgridResponse && !isRecordIndexInt && !recordValues.ContainsKey(jsonReader.RecordId))
            {
                recordValues.Add(jsonReader.RecordId, record.Id);
            }

            if (!isSubgridResponse)
            {
                recordValues = AppendTreeGridValuesToValuesDictionary(recordValues, record);
            }

            return(recordValues);
        }
Esempio n. 7
0
 public MyJqGridHelper(string id = "Grid", string afterInsertRow = null, string afterEditCell = null, string afterRestoreCell = null, string afterSaveCell = null, string afterSubmitCell = null, string altClass = "ui-priority-secondary", bool altRows = false, bool autoEncode = false, bool autoWidth = true, string beforeRequest = null, string beforeSelectRow = null, string beforeEditCell = null, string beforeSaveCell = null, string beforeSubmitCell = null, string caption = null, int cellLayout = 5, bool cellEditingEnabled = false, JqGridCellEditingSubmitModes cellEditingSubmitMode = JqGridCellEditingSubmitModes.Remote, string cellEditingUrl = null, string dataString = null, JqGridDataTypes dataType = JqGridDataTypes.Json, bool deepEmpty = false, JqGridLanguageDirections direction = JqGridLanguageDirections.Ltr, JqGridDynamicScrollingModes dynamicScrollingMode = JqGridDynamicScrollingModes.Disabled, int dynamicScrollingTimeout = 200, string editingUrl = null, string emptyRecords = "No resultes found.", bool expandColumnClick = true, string expandColumn = null, int?height = null, string errorCell = null, string formatCell = null, bool footerEnabled = false, bool gridView = false, bool groupingEnabled = false, JqGridGroupingView groupingView = null, bool headerTitles = false, bool hidden = false, bool hiddenEnabled = true, bool ignoreCase = true, JqGridJsonReader jsonReader = null, string loadBeforeSend = null, string loadError = null, string loadComplete = null, bool loadOnce = true, JqGridMethodTypes methodType = JqGridMethodTypes.Get, JqGridMultiKeys?multiKey = null, bool multiBoxOnly = false, bool multiSelect = false, int multiSelectWidth = 20, bool multiSort = false, string gridComplete = null, string onCellSelect = null, string onDoubleClickRow = null, string onHeaderClick = null, string onInitGrid = null, string onPaging = null, string onRightClickRow = null, string onSelectAll = null, string onSelectCell = null, string onSelectRow = null, string onSortCol = null, bool pager = true, JqGridParametersNames parametersNames = null, object postData = null, string postDataScript = null, string resizeStart = null, string resizeStop = null, string rowAttributes = null, List <int> rowsList = null, int rowsNumber = 20, bool rowsNumbers = false, int rowsNumbersWidth = 25, bool shrinkToFit = true, int scrollOffset = 18, string serializeCellData = null, string serializeGridData = null, string serializeSubGridData = null, bool sortable = false, string sortingName = "", JqGridSortingOrders sortingOrder = JqGridSortingOrders.Asc, bool subgridEnabled = false, JqGridSubgridModel subgridModel = null, object subgridHelper = null, string subgridUrl = null, int subgridColumnWidth = 20, string subGridBeforeExpand = null, string subGridRowColapsed = null, string subGridRowExpanded = null, bool topPager = false, bool treeGridEnabled = false, JqGridTreeGridModels treeGridModel = JqGridTreeGridModels.Nested, string url = null, bool userDataOnFooter = false, bool viewRecords = true, int?width = null)
     : base(id, afterInsertRow, afterEditCell, afterRestoreCell, afterSaveCell, afterSubmitCell, altClass, altRows, autoEncode, autoWidth, beforeRequest, beforeSelectRow, beforeEditCell, beforeSaveCell, beforeSubmitCell, caption, cellLayout, cellEditingEnabled, cellEditingSubmitMode, cellEditingUrl, dataString, dataType, deepEmpty, direction, dynamicScrollingMode, dynamicScrollingTimeout, editingUrl, emptyRecords, expandColumnClick, expandColumn, height, errorCell, formatCell, footerEnabled, gridView, groupingEnabled, groupingView, headerTitles, hidden, hiddenEnabled, ignoreCase, jsonReader, loadBeforeSend, loadError, loadComplete, loadOnce, methodType, multiKey, multiBoxOnly, multiSelect, multiSelectWidth, multiSort, gridComplete, onCellSelect, onDoubleClickRow, onHeaderClick, onInitGrid, onPaging, onRightClickRow, onSelectAll, onSelectCell, onSelectRow, onSortCol, pager, parametersNames, postData, postDataScript, resizeStart, resizeStop, rowAttributes, rowsList, rowsNumber, rowsNumbers, rowsNumbersWidth, shrinkToFit, scrollOffset, serializeCellData, serializeGridData, serializeSubGridData, sortable, sortingName, sortingOrder, subgridEnabled, subgridModel, subgridHelper, subgridUrl, subgridColumnWidth, subGridBeforeExpand, subGridRowColapsed, subGridRowExpanded, topPager, treeGridEnabled, treeGridModel, url, userDataOnFooter, viewRecords, width)
 {
 }
        internal static StringBuilder AppendJsonReader(this StringBuilder javaScriptBuilder, JqGridJsonReader jsonReader)
        {
            jsonReader = jsonReader ?? JqGridResponse.JsonReader;

            if ((jsonReader != null) && !jsonReader.IsDefault())
            {
                javaScriptBuilder.AppendJavaScriptObjectFieldOpening(JqGridOptionsNames.JSON_READER)
                .AppendJavaScriptObjectStringField(JqGridOptionsNames.JsonReader.PAGE_INDEX, jsonReader.PageIndex, JqGridOptionsDefaults.Response.PageIndex)
                .AppendJavaScriptObjectStringField(JqGridOptionsNames.JsonReader.RECORD_ID, jsonReader.RecordId, JqGridOptionsDefaults.Response.RecordId)
                .AppendJavaScriptObjectStringField(JqGridOptionsNames.JsonReader.TOTAL_PAGES_COUNT, jsonReader.TotalPagesCount, JqGridOptionsDefaults.Response.TotalPagesCount)
                .AppendJavaScriptObjectStringField(JqGridOptionsNames.JsonReader.TOTAL_RECORDS_COUNT, jsonReader.TotalRecordsCount, JqGridOptionsDefaults.Response.TotalRecordsCount)
                .AppendJavaScriptObjectStringField(JqGridOptionsNames.JsonReader.USER_DATA, jsonReader.UserData, JqGridOptionsDefaults.Response.UserData)
                .AppendJsonRecordsReaderProperties(jsonReader)
                .AppendJsonRecordsReader(jsonReader.SubgridReader)
                .AppendJavaScriptObjectFieldClosing();
            }

            return(javaScriptBuilder);
        }
Esempio n. 9
0
 static JqGridResponse()
 {
     JsonReader = new JqGridJsonReader();
 }
Esempio n. 10
0
 static JqGridResponse()
 {
     JsonReader = new JqGridJsonReader();
 }
        private static IDictionary <string, object> SerializeValuesRecordAsDictionary(JqGridJsonReader jsonReader, JqGridRecord record, bool isRecordIndexInt, int recordIdIndex, bool isSubgridResponse)
        {
            IDictionary <string, object> recordValues = new Dictionary <string, object>();

            if (!isSubgridResponse)
            {
                recordValues.Add(jsonReader.RecordId, record.Id);
            }

            recordValues.Add(isSubgridResponse ? jsonReader.SubgridReader.RecordValues : jsonReader.RecordValues, AppendValuesToValuesList(new List <object>(), record, isSubgridResponse));

            return(recordValues);
        }
        private static void WriteJqGridRecords(JsonWriter writer, JsonSerializer serializer, bool isSubgridResponse, JqGridJsonReader jsonReader, IList <JqGridRecord> records)
        {
            int  recordIdIndex       = 0;
            bool isRecordIndexInt    = Int32.TryParse(jsonReader.RecordId, out recordIdIndex);
            bool isRecordValuesEmpty = String.IsNullOrWhiteSpace(jsonReader.RecordValues);
            bool repeatItems         = isSubgridResponse ? jsonReader.SubgridReader.RepeatItems : jsonReader.RepeatItems;

            if (!isSubgridResponse)
            {
                if (repeatItems && isRecordValuesEmpty && !isRecordIndexInt)
                {
                    throw new InvalidOperationException("JqGridJsonReader.RecordId must be a number when JqGridJsonReader.RepeatItems is set to true and JqGridJsonReader.RecordValues is set to empty string.");
                }

                if (repeatItems && !isRecordValuesEmpty && isRecordIndexInt)
                {
                    throw new InvalidOperationException("JqGridJsonReader.RecordValues can't be an empty string when JqGridJsonReader.RepeatItems is set to true and JqGridJsonReader.RecordId is a number.");
                }
            }

            Func <JqGridJsonReader, JqGridRecord, bool, int, bool, object> serializeRecordFunction = ChooseSerializeFunction(repeatItems, isRecordValuesEmpty);
            IList <object> serializedRecords = new List <object>(records.Select(record => serializeRecordFunction(jsonReader, record, isRecordIndexInt, recordIdIndex, isSubgridResponse)));

            writer.WritePropertyName(isSubgridResponse ? jsonReader.SubgridReader.Records : jsonReader.Records);
            serializer.Serialize(writer, serializedRecords);
        }
 private static void WrtieUserData(JsonWriter writer, JsonSerializer serializer, JqGridJsonReader jsonReader, JqGridResponse response)
 {
     if (response.UserData != null)
     {
         writer.WritePropertyName(jsonReader.UserData);
         serializer.Serialize(writer, response.UserData);
     }
 }