private string GetOutput(CoreGrid grid, List <Hashtable> data)
        {
            StringBuilder stringBuilder = new StringBuilder();

            if (ExportSettings.ExportHeaders)
            {
                foreach (CoreColumn column in grid.Columns)
                {
                    stringBuilder.AppendFormat("{0}{1}", QuoteText(column.DataField), ExportSettings.CSVSeparator);
                }
            }
            stringBuilder.Append("\n");
            for (int i = 0; i < data.Count; i++)
            {
                for (int j = 0; j < Columns.Count; j++)
                {
                    if (Columns[j].Visible)
                    {
                        CoreColumn coreColumn = grid.Columns[j];
                        string     text       = (!string.IsNullOrEmpty(coreColumn.DataField) && !string.IsNullOrEmpty(coreColumn.DataFormatString)) ? coreColumn.FormatDataValue(data[i][coreColumn.DataField], coreColumn.HtmlEncode) : (data[i][coreColumn.DataField] as string);
                        stringBuilder.AppendFormat("{0}{1}", data[i][coreColumn.DataField], ExportSettings.CSVSeparator);
                    }
                }
                stringBuilder.Append("\n");
            }
            return(stringBuilder.ToString());
        }
 private string GetColNames(CoreGrid grid)
 {
     string[] array = new string[grid.Columns.Count];
     for (int i = 0; i < grid.Columns.Count; i++)
     {
         CoreColumn coreColumn = grid.Columns[i];
         array[i] = (string.IsNullOrEmpty(coreColumn.HeaderText) ? coreColumn.DataField : coreColumn.HeaderText);
     }
     return(JsonConvert.SerializeObject((object)array));
 }
        private string GetHtmlTable(CoreGrid grid, List <Hashtable> data)
        {
            StringBuilder stringBuilder = new StringBuilder();

            stringBuilder.Append(
                "<html><head><style> table, td {border:1px solid black} table { border-collapse:collapse; background:transparent}</style></head> ");

            stringBuilder.Append("<table>");
            stringBuilder.Append("<tr>");
            foreach (CoreColumn column in grid.Columns)
            {
                if (column.Visible)
                {
                    string arg       = string.IsNullOrEmpty(column.HeaderText) ? column.DataField : column.HeaderText;
                    string sizeRowPx = column.ExcelWidthRowPx != 0 ? column.ExcelWidthRowPx + "px;" : "";
                    if (!string.IsNullOrWhiteSpace(sizeRowPx))
                    {
                        stringBuilder.AppendFormat("<td style=\"width: {0}\">{1}</td>", sizeRowPx, arg);
                    }
                    else
                    {
                        stringBuilder.AppendFormat("<td>{0}</td>", arg);
                    }
                }
            }
            stringBuilder.Append("</tr>");
            for (int i = 0; i < data.Count; i++)
            {
                stringBuilder.Append("<tr>");
                for (int j = 0; j < grid.Columns.Count; j++)
                {
                    CoreColumn coreColumn = grid.Columns[j];
                    if (coreColumn.Visible)
                    {
                        string arg2 =
                            (!string.IsNullOrEmpty(coreColumn.DataField) &&
                             !string.IsNullOrEmpty(coreColumn.DataFormatString))
                                                ? coreColumn.FormatDataValue(data[i][coreColumn.DataField], coreColumn.HtmlEncode)
                                                : (data[i][coreColumn.DataField]?.ToString());
                        stringBuilder.AppendFormat("<td>{0}</td>", arg2);
                    }
                }

                stringBuilder.Append("</tr>");
            }
            stringBuilder.Append("</table>");
            return(stringBuilder.ToString());
        }
 internal static JsonTreeResponse PrepareJsonTreeResponse(JsonTreeResponse response, CoreGrid grid, List <Hashtable> data)
 {
     for (int i = 0; i < data.Count; i++)
     {
         for (int j = 0; j < grid.Columns.Count; j++)
         {
             CoreColumn coreColumn = grid.Columns[j];
             if (!string.IsNullOrEmpty(coreColumn.DataField) && !string.IsNullOrEmpty(coreColumn.DataFormatString))
             {
                 data[i][coreColumn.DataField] = coreColumn.FormatDataValue(data[i][coreColumn.DataField], coreColumn.HtmlEncode);
             }
         }
         response.rows[i] = data[i];
     }
     return(response);
 }
        public void FromColumn(CoreColumn column)
        {
            object obj2 = _jsonValues["index"] = (_jsonValues["name"] = column.DataField);

            if (column.Width != 150)
            {
                _jsonValues["width"] = column.Width;
            }
            if (!column.Sortable)
            {
                _jsonValues["sortable"] = false;
            }
            if (column.PrimaryKey)
            {
                _jsonValues["key"] = true;
            }


            if (!column.Visible)
            {
                _jsonValues["hidden"] = true;
            }
            if (!column.Searchable)
            {
                _jsonValues["search"] = false;
            }
            if (column.TextAlign != 0)
            {
                _jsonValues["align"] = column.TextAlign.ToString().ToLower();
            }
            if (!column.Resizable)
            {
                _jsonValues["resizable"] = false;
            }
            if (column.Frozen)
            {
                _jsonValues["frozen"] = true;
            }
            if (!string.IsNullOrEmpty(column.CssClass))
            {
                _jsonValues["classes"] = column.CssClass;
            }
            if (column.Fixed)
            {
                _jsonValues["fixed"] = true;
            }
            if (column.ShowColumnMenu)
            {
                _jsonValues["colmenu"] = true;

                if (column.ColumnMenuOptions != null)
                {
                    Hashtable hashtable = new Hashtable();
                    hashtable["sorting"]           = column.ColumnMenuOptions.Sorting;
                    hashtable["columns"]           = column.ColumnMenuOptions.Columns;
                    hashtable["filtering"]         = column.ColumnMenuOptions.Filtering;
                    hashtable["seraching"]         = column.ColumnMenuOptions.Searching;
                    hashtable["grouping"]          = column.ColumnMenuOptions.Grouping;
                    hashtable["freeze"]            = column.ColumnMenuOptions.Freezing;
                    this._jsonValues["coloptions"] = hashtable;
                }
            }
            else
            {
                _jsonValues["colmenu"] = false;
            }
            if (column.GroupSummaryType != 0)
            {
                switch (column.GroupSummaryType)
                {
                case GroupSummaryType.Avg:
                    _jsonValues["summaryType"] = "avg";
                    break;

                case GroupSummaryType.Count:
                    _jsonValues["summaryType"] = "count";
                    break;

                case GroupSummaryType.Max:
                    _jsonValues["summaryType"] = "max";
                    break;

                case GroupSummaryType.Min:
                    _jsonValues["summaryType"] = "min";
                    break;

                case GroupSummaryType.Sum:
                    _jsonValues["summaryType"] = "sum";
                    break;
                }
            }
            if (!string.IsNullOrEmpty(column.GroupTemplate))
            {
                _jsonValues["summaryTpl"] = column.GroupTemplate;
            }
            if (column.Formatter != null || column.EditActionIconsColumn)
            {
                ApplyFormatterOptions(column);
            }
            if (column.EditActionIconsColumn)
            {
                _jsonValues["formatter"] = "actions";
            }
            if (_grid.TreeGridSettings.Enabled && column.DataType != null)
            {
                if (column.DataType == typeof(string))
                {
                    _jsonValues["sorttype"] = "string";
                }
                if (column.DataType == typeof(int))
                {
                    _jsonValues["sorttype"] = "int";
                }
                if (column.DataType == typeof(float) || column.DataType == typeof(decimal))
                {
                    _jsonValues["sorttype"] = "float";
                }
                if (column.DataType == typeof(DateTime))
                {
                    _jsonValues["sorttype"] = "date";
                }
            }
            if (column.Searchable)
            {
                Hashtable hashtable = new Hashtable();
                if (column.SearchType == SearchType.DropDown)
                {
                    _jsonValues["stype"] = "select";
                }
                if (!column.Visible)
                {
                    hashtable["searchhidden"] = true;
                }
                if (column.SearchList.Count() > 0)
                {
                    StringBuilder stringBuilder = new StringBuilder();
                    int           num           = 0;
                    foreach (SelectListItem search in column.SearchList)
                    {
                        stringBuilder.AppendFormat("{0}:{1}", search.Value, search.Text);
                        num++;
                        if (num < column.SearchList.Count())
                        {
                            stringBuilder.Append(";");
                        }
                        if (search.Selected)
                        {
                            hashtable["defaultValue"] = search.Value;
                        }
                    }
                    hashtable["value"] = stringBuilder.ToString();
                }
                if (column.SearchType == SearchType.DatePicker || column.SearchType == SearchType.AutoComplete)
                {
                    hashtable["dataInit"] = "attachSearchControlsScript" + column.DataField;
                }
                if (column.SearchOptions.Count > 0)
                {
                    hashtable["sopt"] = GetSearchOptionsArray(column.SearchOptions);
                }
                if (!column.ClearSearch)
                {
                    hashtable["clearSearch"] = false;
                }

                hashtable["searchOperators"] = column.ShowSearchOperators;

                _jsonValues["searchoptions"] = hashtable;
            }
            if (column.Editable)
            {
                Hashtable hashtable2 = new Hashtable();
                _jsonValues["editable"] = true;
                if (column.EditType == EditType.CheckBox)
                {
                    hashtable2["value"] = "True:False";
                }
                if (column.EditType != EditType.TextBox)
                {
                    _jsonValues["edittype"] = GetEditType(column.EditType);
                }
                if (column.EditType == EditType.Custom)
                {
                    Guard.IsNotNullOrEmpty(column.EditTypeCustomCreateElement, "CoreGridColumn.EditTypeCustomCreateElement", " should be set to the name of the javascript function creating the element when EditType = EditType.Custom");
                    Guard.IsNotNullOrEmpty(column.EditTypeCustomGetValue, "CoreGridColumn.EditTypeCustomGetValue", " should be set to the name of the javascript function getting the value from the element when EditType = EditType.Custom");
                    hashtable2["custom_element"] = column.EditTypeCustomCreateElement;
                    hashtable2["custom_value"]   = column.EditTypeCustomGetValue;
                }
                foreach (CoreGridEditFieldAttribute editFieldAttribute in column.EditFieldAttributes)
                {
                    hashtable2[editFieldAttribute.Name] = editFieldAttribute.Value;
                }
                if (column.EditType == EditType.DatePicker || column.EditType == EditType.AutoComplete)
                {
                    hashtable2["dataInit"] = "attachEditControlsScript" + column.DataField;
                }
                if (column.EditList.Count > 0)
                {
                    StringBuilder stringBuilder2 = new StringBuilder();
                    int           num2           = 0;
                    foreach (SelectListItem edit in column.EditList)
                    {
                        stringBuilder2.AppendFormat("{0}:{1}", edit.Value, edit.Text);
                        num2++;
                        if (num2 < column.EditList.Count())
                        {
                            stringBuilder2.Append(";");
                        }
                    }
                    hashtable2["value"] = stringBuilder2.ToString();
                }
                if (hashtable2.Count > 0)
                {
                    _jsonValues["editoptions"] = hashtable2;
                }
                Hashtable hashtable3 = new Hashtable();
                if (column.EditDialogColumnPosition != 0)
                {
                    hashtable3["colpos"] = column.EditDialogColumnPosition;
                }
                if (column.EditDialogRowPosition != 0)
                {
                    hashtable3["rowpos"] = column.EditDialogRowPosition;
                }
                if (!string.IsNullOrEmpty(column.EditDialogLabel))
                {
                    hashtable3["label"] = column.EditDialogLabel;
                }
                if (!string.IsNullOrEmpty(column.EditDialogFieldPrefix))
                {
                    hashtable3["elmprefix"] = column.EditDialogFieldPrefix;
                }
                if (!string.IsNullOrEmpty(column.EditDialogFieldSuffix))
                {
                    hashtable3["elmsuffix"] = column.EditDialogFieldSuffix;
                }
                if (hashtable3.Count > 0)
                {
                    _jsonValues["formoptions"] = hashtable3;
                }
                Hashtable hashtable4 = new Hashtable();
                if (!column.Visible && column.Editable)
                {
                    hashtable4["edithidden"] = true;
                }
                if (column.EditClientSideValidators != null)
                {
                    foreach (CoreGridEditClientSideValidator editClientSideValidator in column.EditClientSideValidators)
                    {
                        if (editClientSideValidator is DateValidator)
                        {
                            hashtable4["date"] = true;
                        }
                        if (editClientSideValidator is EmailValidator)
                        {
                            hashtable4["email"] = true;
                        }
                        if (editClientSideValidator is IntegerValidator)
                        {
                            hashtable4["integer"] = true;
                        }
                        if (editClientSideValidator is MaxValueValidator)
                        {
                            hashtable4["maxValue"] = ((MaxValueValidator)editClientSideValidator).MaxValue;
                        }
                        if (editClientSideValidator is MinValueValidator)
                        {
                            hashtable4["minValue"] = ((MinValueValidator)editClientSideValidator).MinValue;
                        }
                        if (editClientSideValidator is NumberValidator)
                        {
                            hashtable4["number"] = true;
                        }
                        if (editClientSideValidator is RequiredValidator)
                        {
                            hashtable4["required"] = true;
                        }
                        if (editClientSideValidator is TimeValidator)
                        {
                            hashtable4["time"] = true;
                        }
                        if (editClientSideValidator is UrlValidator)
                        {
                            hashtable4["url"] = true;
                        }
                        if (editClientSideValidator is CustomValidator)
                        {
                            hashtable4["custom"]      = true;
                            hashtable4["custom_func"] = ((CustomValidator)editClientSideValidator).ValidationFunction;
                        }
                    }
                }
                if (hashtable4.Count > 0)
                {
                    _jsonValues["editrules"] = hashtable4;
                }
            }
        }
        private void ApplyFormatterOptions(CoreColumn column)
        {
            Hashtable hashtable = new Hashtable();

            if (column.EditActionIconsColumn)
            {
                hashtable["keys"]       = column.EditActionIconsSettings.SaveOnEnterKeyPress;
                hashtable["editbutton"] = column.EditActionIconsSettings.ShowEditIcon;
                hashtable["delbutton"]  = column.EditActionIconsSettings.ShowDeleteIcon;
            }
            if (column.Formatter != null)
            {
                CoreGridColumnFormatter formatter = column.Formatter;
                if (formatter is LinkFormatter)
                {
                    LinkFormatter linkFormatter = (LinkFormatter)formatter;
                    _jsonValues["formatter"] = "link";
                    if (!string.IsNullOrEmpty(linkFormatter.Target))
                    {
                        hashtable["target"] = linkFormatter.Target;
                    }
                }
                if (formatter is EmailFormatter)
                {
                    _jsonValues["formatter"] = "email";
                }
                if (formatter is IntegerFormatter)
                {
                    IntegerFormatter integerFormatter = (IntegerFormatter)formatter;
                    _jsonValues["formatter"] = "integer";
                    if (!string.IsNullOrEmpty(integerFormatter.ThousandsSeparator))
                    {
                        hashtable["thousandsSeparator"] = integerFormatter.ThousandsSeparator;
                    }
                    if (!string.IsNullOrEmpty(integerFormatter.DefaultValue))
                    {
                        hashtable["defaultValue"] = integerFormatter.DefaultValue;
                    }
                }
                if (formatter is NumberFormatter)
                {
                    NumberFormatter numberFormatter = (NumberFormatter)formatter;
                    _jsonValues["formatter"] = "integer";
                    if (!string.IsNullOrEmpty(numberFormatter.ThousandsSeparator))
                    {
                        hashtable["thousandsSeparator"] = numberFormatter.ThousandsSeparator;
                    }
                    if (!string.IsNullOrEmpty(numberFormatter.DefaultValue))
                    {
                        hashtable["defaultValue"] = numberFormatter.DefaultValue;
                    }
                    if (!string.IsNullOrEmpty(numberFormatter.DecimalSeparator))
                    {
                        hashtable["decimalSeparator"] = numberFormatter.DecimalSeparator;
                    }
                    if (numberFormatter.DecimalPlaces != -1)
                    {
                        hashtable["decimalPlaces"] = numberFormatter.DecimalPlaces;
                    }
                }
                if (formatter is CurrencyFormatter)
                {
                    CurrencyFormatter currencyFormatter = (CurrencyFormatter)formatter;
                    _jsonValues["formatter"] = "currency";
                    if (!string.IsNullOrEmpty(currencyFormatter.ThousandsSeparator))
                    {
                        hashtable["thousandsSeparator"] = currencyFormatter.ThousandsSeparator;
                    }
                    if (!string.IsNullOrEmpty(currencyFormatter.DefaultValue))
                    {
                        hashtable["defaultValue"] = currencyFormatter.DefaultValue;
                    }
                    if (!string.IsNullOrEmpty(currencyFormatter.DecimalSeparator))
                    {
                        hashtable["decimalSeparator"] = currencyFormatter.DecimalSeparator;
                    }
                    if (currencyFormatter.DecimalPlaces != -1)
                    {
                        hashtable["decimalPlaces"] = currencyFormatter.DecimalPlaces;
                    }
                    if (!string.IsNullOrEmpty(currencyFormatter.Prefix))
                    {
                        hashtable["prefix"] = currencyFormatter.Prefix;
                    }
                    if (!string.IsNullOrEmpty(currencyFormatter.Prefix))
                    {
                        hashtable["suffix"] = currencyFormatter.Suffix;
                    }
                }
                if (formatter is CheckBoxFormatter)
                {
                    CheckBoxFormatter checkBoxFormatter = (CheckBoxFormatter)formatter;
                    _jsonValues["formatter"] = "checkbox";
                    if (checkBoxFormatter.Enabled)
                    {
                        hashtable["disabled"] = false;
                    }
                }
                if (formatter is CustomFormatter)
                {
                    CustomFormatter customFormatter = (CustomFormatter)formatter;
                    if (!string.IsNullOrEmpty(customFormatter.FormatFunction))
                    {
                        _jsonValues["formatter"] = customFormatter.FormatFunction;
                    }
                    if (!string.IsNullOrEmpty(customFormatter.UnFormatFunction))
                    {
                        _jsonValues["unformat"] = customFormatter.UnFormatFunction;
                    }
                    if (!string.IsNullOrEmpty(customFormatter.SetAttributesFunction))
                    {
                        _jsonValues["cellattr"] = customFormatter.SetAttributesFunction;
                    }
                }
            }
            if (hashtable.Count > 0)
            {
                _jsonValues["formatoptions"] = hashtable;
            }
        }
 public JsonColModel(CoreColumn column, CoreGrid grid)
     : this(grid)
 {
     FromColumn(column);
 }