private string AccumulateFormViewOptions(FormViewOptions formView)
        {
            if (formView == null) return NewLine(6) + "{}";
            var sb = new StringBuilder();
            sb.AppendLine().PadLeft(6);
            sb.Append("{");
            //properties
            sb.AppendNonNullOrEmpty("top: {0}, ", formView.Top);
            sb.AppendNonNullOrEmpty("left: {0}, ", formView.Left);
            sb.AppendNonNullOrEmpty("width: {0}, ", formView.Width);
            sb.AppendNonNullOrEmpty("height: {0}, ", formView.Height);
            sb.AppendNonNullOrEmpty("dataheight: {0}, ", formView.DataHeight);
            sb.AppendNonNullOrEmpty("modal: {0}, ", ToLowerString(formView.Modal));
            sb.AppendNonNullOrEmpty("drag: {0}, ", ToLowerString(formView.Drag));
            sb.AppendNonNullOrEmpty("resize: {0}, ", ToLowerString(formView.Resize));
            sb.AppendNonNullOrEmpty("jqModal: {0}, ", ToLowerString(formView.JqModal));
            sb.AppendNonNullOrEmpty("topinfo: {0}, ", Asq(formView.TopInfo));
            sb.AppendNonNullOrEmpty("bottominfo: {0}, ", Asq(formView.BottomInfo));
            sb.AppendNonNullOrEmpty("closeicon: {0}, ", Asq(formView.CloseIcon));
            sb.AppendNonNullOrEmpty("navkeys: {0}, ", formView.NavKeys);
            sb.AppendNonNullOrEmpty("closeOnEscape: {0}, ", ToLowerString(formView.CloseOnEscape));
            sb.AppendNonNullOrEmpty("viewPagerButtons: {0}, ", ToLowerString(formView.ViewPagerButtons));
            sb.AppendNonNullOrEmpty("labelswidth: {0}, ", Asq(formView.LabelsWidth));
            sb.AppendNonNullOrEmpty("zIndex: {0}, ", formView.ZIndex);
            //events
            sb.AppendNonNullOrEmpty("beforeShowForm: {0}, ", formView.BeforeShowForm);
            sb.AppendNonNullOrEmpty("onClose: {0}, ", formView.OnClose);

            sb.RemoveLast(COMMA);
            sb.Append("}");
            return sb.ToString();
        }
        public string ToScript()
        {
            if (_gridOptions.Columns == null) return string.Empty;
            var sb = new StringBuilder();
            string colNames = _gridOptions.Columns.Aggregate(string.Empty, (current, jqGridColumn) => current + Asq(jqGridColumn.Header) + ", ");
            colNames = colNames.Remove(colNames.LastIndexOf(','));
            sb.AppendFormat("colNames: [{0}], {1}", colNames, NewLine(PadLeftTo));

            sb.AppendFormat("colModel: [ {0}", NewLine(9));
            for (int i = 0; i < _gridOptions.Columns.Count; i++)
            {
                var item = _gridOptions.Columns[i];
                sb.AppendFormat("{{ name: {0}, ", Asq(item.Name));
                sb.AppendNonNullOrEmpty("index: {0}, ", Asq(item.Index));
                sb.AppendNonNullOrEmpty("width: {0}, ", item.Width);
                sb.AppendNonNullOrEmpty("align: {0}, ", Asq(GetAlignValue(item.Align)));
                sb.AppendNonNullOrEmpty("editable: {0}, ", ToLowerString(item.Editable));
                sb.Append(new ColumnFormOptionsToScript(item.FormOptions).ToScript());
                sb.AppendNonNullOrEmpty("sortable: {0}, ", ToLowerString(item.Sortable));
                sb.AppendNonNullOrEmpty("sorttype: {0}, ", Asq(GetColumnSortTypeValue(item.SortType)));
                sb.AppendNonNullOrEmpty("firstsortorder: {0}, ", Asq(item.FirstSortOrder));
                sb.AppendNonNullOrEmpty("search: {0}, ", ToLowerString(item.Search));
                sb.Append(new ColumnSearchOptionsToScript(item.SearchOptions).ToScript());
                sb.Append(new ColumnSearchRulesToScript(item.SearchRules).ToScript());
                sb.AppendNonNullOrEmpty("stype: {0}, ", Asq(item.SearchType));
                sb.AppendNonNullOrEmpty("surl: {0}, ", Asq(item.SUrl));
                sb.AppendNonNullOrEmpty("cellattr: {0}, ", item.CellAttribute);
                sb.AppendNonNullOrEmpty("classes: {0}, ", Asq(item.Classes));
                sb.AppendNonNullOrEmpty("datefmt: {0}, ", Asq(item.DateFormat));
                sb.AppendNonNullOrEmpty("defval: {0}, ", Asq(item.DefaultValue));
                sb.AppendNonNullOrEmpty("fixed: {0}, ", ToLowerString(item.Fixed));
                sb.AppendNonNullOrEmpty("formatoptions: {0}, ", item.FormatOptions);
                sb.AppendNonNullOrEmpty("formatter: {0}, ", item.Formatter);
                sb.AppendNonNullOrEmpty("hidedlg: {0}, ", ToLowerString(item.HideInDialog));
                sb.AppendNonNullOrEmpty("hidden: {0}, ", ToLowerString(item.Hidden));
                sb.AppendNonNullOrEmpty("fixed: {0}, ", ToLowerString(item.Fixed));
                sb.AppendNonNullOrEmpty("jsonmap: {0}, ", Asq(item.JsonMap));
                sb.AppendNonNullOrEmpty("key: {0}, ", ToLowerString(item.Key));
                sb.AppendNonNullOrEmpty("label: {0}, ", Asq(item.Label));
                sb.AppendNonNullOrEmpty("resizable: {0}, ", ToLowerString(item.Resizable));
                sb.AppendNonNullOrEmpty("template: {0}, ", item.Template);
                sb.AppendNonNullOrEmpty("title: {0}, ", ToLowerString(item.TitleOnHover));
                sb.AppendNonNullOrEmpty("xmlmap: {0}, ", item.XmlMap);
                sb.AppendNonNullOrEmpty("unformat: {0}, ", item.UnFormat);
                sb.AppendNonNullOrEmpty("viewable: {0}, ", ToLowerString(item.Viewable));
                sb.Append(new ColumnEditToScript(item.EditOptions).ToScript());
                sb.Append(new ColumnEditRulesToScript(item.EditRules).ToScript());

                //Cut off the last comma
                sb.RemoveLast(COMMA);
                sb.Append("}");
                if (i == _gridOptions.Columns.Count - 1) continue;
                sb.AppendFormat(",{0}", NewLine(9));
            }

            sb.AppendFormat("], {0}", NewLine(PadLeftTo));

            return sb.ToString();
        }
        private string AccumulateFormAddEditOptions(FormEditOptions formEdit)
        {

            if (formEdit == null) return NewLine(6) + "{}";
            var sb = new StringBuilder();
            sb.AppendLine().PadLeft(6);
            sb.Append("{");
            //properties
            sb.AppendNonNullOrEmpty("top: {0}, ", formEdit.Top);
            sb.AppendNonNullOrEmpty("left: {0}, ", formEdit.Left);
            sb.AppendNonNullOrEmpty("width: {0}, ", formEdit.Width);
            sb.AppendNonNullOrEmpty("height: {0}, ", formEdit.Height);
            sb.AppendNonNullOrEmpty("dataheight: {0}, ", formEdit.DataHeight);
            sb.AppendNonNullOrEmpty("modal: {0}, ", ToLowerString(formEdit.Modal));
            sb.AppendNonNullOrEmpty("drag: {0}, ", ToLowerString(formEdit.Drag));
            sb.AppendNonNullOrEmpty("resize: {0}, ", ToLowerString(formEdit.Resize));
            sb.AppendNonNullOrEmpty("url: {0}, ", Asq(formEdit.Url));
            sb.AppendNonNullOrEmpty("mtype: {0}, ", Asq(formEdit.MType));
            sb.AppendNonNullOrEmpty("editData: {0}, ", Asq(formEdit.EditData));
            sb.AppendNonNullOrEmpty("recreateForm: {0}, ", ToLowerString(formEdit.RecreateForm));
            sb.AppendNonNullOrEmpty("jqModal: {0}, ", ToLowerString(formEdit.JqModal));
            sb.AppendNonNullOrEmpty("addedrow: {0}, ", Asq(formEdit.Addedrow));
            sb.AppendNonNullOrEmpty("topinfo: {0}, ", Asq(formEdit.TopInfo));
            sb.AppendNonNullOrEmpty("bottominfo: {0}, ", Asq(formEdit.BottomInfo));
            sb.AppendNonNullOrEmpty("saveicon: {0}, ", Asq(formEdit.SaveIcon));
            sb.AppendNonNullOrEmpty("closeicon: {0}, ", Asq(formEdit.CloseIcon));
            sb.AppendNonNullOrEmpty("savekey: {0}, ", formEdit.SaveKey);
            sb.AppendNonNullOrEmpty("navkeys: {0}, ", formEdit.NavKeys);
            sb.AppendNonNullOrEmpty("checkOnSubmit: {0}, ", ToLowerString(formEdit.CheckOnSubmit));
            sb.AppendNonNullOrEmpty("checkOnUpdate: {0}, ", ToLowerString(formEdit.CheckOnUpdate));
            sb.AppendNonNullOrEmpty("closeAfterAdd: {0}, ", ToLowerString(formEdit.CloseAfterAdd));
            sb.AppendNonNullOrEmpty("clearAfterAdd: {0}, ", ToLowerString(formEdit.ClearAfterAdd));
            sb.AppendNonNullOrEmpty("closeAfterEdit: {0}, ", ToLowerString(formEdit.CloseAfterEdit));
            sb.AppendNonNullOrEmpty("reloadAfterSubmit: {0}, ", ToLowerString(formEdit.ReloadAfterSubmit));
            sb.AppendNonNullOrEmpty("closeOnEscape: {0}, ", ToLowerString(formEdit.CloseOnEscape));
            sb.AppendNonNullOrEmpty("ajaxEditOptions: {0}, ", Asq(formEdit.AjaxEditOptions));
            sb.AppendNonNullOrEmpty("viewPagerButtons: {0}, ", ToLowerString(formEdit.ViewPagerButtons));
            sb.AppendNonNullOrEmpty("zIndex: {0}, ", formEdit.ZIndex);
            //events
            sb.AppendNonNullOrEmpty("afterclickPgButtons: {0}, ", formEdit.AfterClickPgButtons);
            sb.AppendNonNullOrEmpty("afterComplete: {0}, ", formEdit.AfterComplete);
            sb.AppendNonNullOrEmpty("afterShowForm: {0}, ", formEdit.AfterShowForm);
            sb.AppendNonNullOrEmpty("afterSubmit: {0}, ", formEdit.AfterSubmit);
            sb.AppendNonNullOrEmpty("beforeCheckValues: {0}, ", formEdit.BeforeCheckValues);
            sb.AppendNonNullOrEmpty("beforeInitData: {0}, ", formEdit.BeforeInitData);
            sb.AppendNonNullOrEmpty("beforeShowForm: {0}, ", formEdit.BeforeShowForm);
            sb.AppendNonNullOrEmpty("beforeSubmit: {0}, ", formEdit.BeforeSubmit);
            sb.AppendNonNullOrEmpty("onclickPgButtons: {0}, ", formEdit.OnclickPgButtons);
            sb.AppendNonNullOrEmpty("onclickSubmit: {0}, ", formEdit.OnclickSubmit);
            sb.AppendNonNullOrEmpty("onInitializeForm: {0}, ", formEdit.OnInitializeForm);
            sb.AppendNonNullOrEmpty("onClose: {0}, ", formEdit.OnClose);
            sb.AppendNonNullOrEmpty("errorTextFormat: {0}, ", formEdit.ErrorTextFormat);
            sb.AppendNonNullOrEmpty("serializeEditData: {0}, ", formEdit.SerializeEditData);

            //Cut off the last comma
            sb.RemoveLast(COMMA);
            sb.Append("}");
            return sb.ToString();
        }
 private void ToButtonOption(ref StringBuilder sb, ColumnEditOptions columnEditOptions)
 {
     string value = columnEditOptions.Value.ToString();
     var buttonOptions = new StringBuilder();
     buttonOptions.AppendNonNullOrEmpty("value: {0}, ", Asq(value));
     AddCommonAttr(columnEditOptions, ref buttonOptions);
     buttonOptions.RemoveLast(COMMA);
     sb.AppendNonNullOrEmpty("edittype:'button', editoptions: {{{0}}}, ", buttonOptions);
 }
 private void ToCheckOption(ref StringBuilder sb, ColumnEditOptions columnEditOptions)
 {
     string value = (columnEditOptions.Value != null && (bool)columnEditOptions.Value != false)
                        ? "Yes:No"
                        : string.Empty;
     var checkOptions = new StringBuilder();
     checkOptions.AppendNonNullOrEmpty("value: {0}, ", value);
     AddCommonAttr(columnEditOptions, ref checkOptions);
     checkOptions.RemoveLast(COMMA);
     sb.AppendNonNullOrEmpty("edittype:'checkbox', editoptions: {{{0}}}, ", checkOptions);
 }
 public string ToScript()
 {
     if (_formOptions == null) return string.Empty;
     var sb = new StringBuilder();
     sb.AppendFormat("formoptions:{{ ");
     sb.AppendFormat("elmprefix: {0}, ", Asq(_formOptions.ElementPrefix));
     sb.AppendFormat("elmsuffix: {0}, ", Asq(_formOptions.ElementSuffix));
     sb.AppendFormat("label: {0}, ", Asq(_formOptions.Label));
     sb.AppendFormat("rowpos: {0}, ", _formOptions.RowPosition);
     sb.AppendFormat("colpos: {0}, ", _formOptions.ColumnPosition);
     
     sb.RemoveLast(COMMA);
     sb.AppendFormat("}}, ");
     return sb.ToString();
 }
        public string ToScript()
        {
            if (_searchRules == null) return string.Empty;
            var sb = new StringBuilder();
            sb.AppendFormat("searchrules:{{ ");
            sb.AppendFormat("required: {0}, ", ToLowerString(_searchRules.Required));
            sb.AppendFormat("number: {0}, ", ToLowerString(_searchRules.Number));
            sb.AppendFormat("integer: {0}, ", ToLowerString(_searchRules.Integer));
            sb.AppendFormat("minValue: {0}, ", _searchRules.MinValue);
            sb.AppendFormat("maxValue: {0}, ", _searchRules.MaxValue);
            sb.AppendFormat("email: {0}, ", ToLowerString(_searchRules.Email));
            sb.AppendFormat("url: {0}, ", ToLowerString(_searchRules.Url));
            sb.AppendFormat("date: {0}, ", ToLowerString(_searchRules.Date));
            sb.AppendFormat("time: {0}, ", ToLowerString(_searchRules.Time));
            sb.AppendFormat("custom: {0}, ", ToLowerString(_searchRules.Custom));
            sb.AppendFormat("custom_func: {0}, ", _searchRules.CustomFunc);

            sb.RemoveLast(COMMA);
            sb.AppendFormat("}}, ");
            return sb.ToString();
        } 
 private string GetEditRules(ColumnEditRules editRules)
 {
     if (editRules == null) return string.Empty;
     var sb = new StringBuilder();
     sb.AppendFormat("editrules:{{ ");
     sb.AppendNonNullOrEmpty("edithidden: {0}, ", ToLowerString(editRules.EditHidden));
     sb.AppendNonNullOrEmpty("required: {0}, ", ToLowerString(editRules.Required));
     sb.AppendNonNullOrEmpty("number: {0}, ", ToLowerString(editRules.Number));
     sb.AppendNonNullOrEmpty("integer: {0}, ", ToLowerString(editRules.Integer));
     sb.AppendNonNullOrEmpty("minValue: {0}, ", editRules.MinValue);
     sb.AppendNonNullOrEmpty("maxValue: {0}, ", editRules.MaxValue);
     sb.AppendNonNullOrEmpty("email: {0}, ", ToLowerString(editRules.Email));
     sb.AppendNonNullOrEmpty("url: {0}, ", ToLowerString(editRules.Url));
     sb.AppendNonNullOrEmpty("date: {0}, ", ToLowerString(editRules.Date));
     sb.AppendNonNullOrEmpty("time: {0}, ", ToLowerString(editRules.Time));
     sb.AppendNonNullOrEmpty("custom: {0}, ", ToLowerString(editRules.Custom));
     sb.AppendNonNullOrEmpty("custom_func: {0}, ", editRules.CustomFunction);
     sb.RemoveLast(COMMA);
     sb.AppendFormat("}}, ");
     return sb.ToString();
 }
        private string AccumulateFormDeleteOptions(FormDeleteOptions formDelete)
        {
            if (formDelete == null) return NewLine(6) + "{}";
            var sb = new StringBuilder();
            sb.AppendLine().PadLeft(6);
            sb.Append("{");
            //properties
            sb.AppendNonNullOrEmpty("top: {0}, ", formDelete.Top);
            sb.AppendNonNullOrEmpty("left: {0}, ", formDelete.Left);
            sb.AppendNonNullOrEmpty("width: {0}, ", formDelete.Width);
            sb.AppendNonNullOrEmpty("height: {0}, ", formDelete.Height);
            sb.AppendNonNullOrEmpty("dataheight: {0}, ", formDelete.DataHeight);
            sb.AppendNonNullOrEmpty("modal: {0}, ", ToLowerString(formDelete.Modal));
            sb.AppendNonNullOrEmpty("drag: {0}, ", ToLowerString(formDelete.Drag));
            sb.AppendNonNullOrEmpty("resize: {0}, ", ToLowerString(formDelete.Resize));
            sb.AppendNonNullOrEmpty("url: {0}, ", Asq(formDelete.Url));
            sb.AppendNonNullOrEmpty("mtype: {0}, ", Asq(formDelete.MType));
            sb.AppendNonNullOrEmpty("delData: {0}, ", Asq(formDelete.DelData));
            sb.AppendNonNullOrEmpty("jqModal: {0}, ", ToLowerString(formDelete.JqModal));
            sb.AppendNonNullOrEmpty("delicon: {0}, ", Asq(formDelete.DelIcon));
            sb.AppendNonNullOrEmpty("cancelicon: {0}, ", Asq(formDelete.CancelIcon));
            sb.AppendNonNullOrEmpty("reloadAfterSubmit: {0}, ", ToLowerString(formDelete.ReloadAfterSubmit));
            sb.AppendNonNullOrEmpty("closeOnEscape: {0}, ", ToLowerString(formDelete.CloseOnEscape));
            sb.AppendNonNullOrEmpty("ajaxDelOptions: {0}, ", Asq(formDelete.AjaxDelOptions));
            sb.AppendNonNullOrEmpty("zIndex: {0}, ", formDelete.ZIndex);
            //events
            sb.AppendNonNullOrEmpty("afterComplete: {0}, ", Asq(formDelete.AfterComplete));
            sb.AppendNonNullOrEmpty("afterShowForm: {0}, ", Asq(formDelete.AfterShowForm));
            sb.AppendNonNullOrEmpty("afterSubmit: {0}, ", Asq(formDelete.AfterSubmit));
            sb.AppendNonNullOrEmpty("beforeShowForm: {0}, ", Asq(formDelete.BeforeShowForm));
            sb.AppendNonNullOrEmpty("beforeSubmit: {0}, ", Asq(formDelete.BeforeSubmit));
            sb.AppendNonNullOrEmpty("onclickSubmit: {0}, ", Asq(formDelete.OnclickSubmit));
            sb.AppendNonNullOrEmpty("onClose: {0}, ", Asq(formDelete.OnClose));
            sb.AppendNonNullOrEmpty("errorTextFormat: {0}, ", Asq(formDelete.ErrorTextFormat));
            sb.AppendNonNullOrEmpty("serializeDelData: {0}, ", Asq(formDelete.SerializeDelData));

            sb.RemoveLast(COMMA);
            sb.Append("}");
            return sb.ToString();
        }
 private void ToImageOption(ref StringBuilder sb, ColumnEditOptions columnEditOptions)
 {
     var imageOptions = new StringBuilder();
     imageOptions.AppendNonNullOrEmpty("src: {0}, ", columnEditOptions.ImageSrc);
     AddCommonAttr(columnEditOptions, ref imageOptions);
     imageOptions.RemoveLast(COMMA);
     sb.AppendNonNullOrEmpty("edittype:'image', editoptions: {{{0}}}, ", imageOptions);
 }
 private void ToTextareaOption(ref StringBuilder sb, ColumnEditOptions columnEditOptions)
 {
     int rows = columnEditOptions.Rows ?? 2;
     int cols = columnEditOptions.Cols ?? 20;
     var textOptions = new StringBuilder();
     textOptions.AppendNonNullOrEmpty("rows: {0}, cols: {1}, ", rows, cols, 0);
     AddCommonAttr(columnEditOptions, ref textOptions);
     textOptions.RemoveLast(COMMA);
     sb.AppendNonNullOrEmpty("edittype:'textarea', editoptions: {{{0}}}, ", textOptions);
 }
 private void ToPasswordOption(ref StringBuilder sb, ColumnEditOptions columnEditOptions)
 {
     var passwordOptions = new StringBuilder();
     passwordOptions.AppendNonNullOrEmpty("size: {0}, ", columnEditOptions.Size);
     passwordOptions.AppendNonNullOrEmpty("maxlength: {0}, ", columnEditOptions.MaxLength);
     passwordOptions.AppendNonNullOrEmpty("readonly: {0}, ", ToLowerString(columnEditOptions.ReadOnly));
     AddCommonAttr(columnEditOptions, ref passwordOptions);
     passwordOptions.RemoveLast(COMMA);
     sb.AppendNonNullOrEmpty("edittype:'password', editoptions: {{{0}}}, ", passwordOptions);
 }
 private void ToTextOption(ref StringBuilder sb, ColumnEditOptions columnEditOptions)
 {
     var textOptions = new StringBuilder();
     textOptions.AppendNonNullOrEmpty("size: {0}, ", columnEditOptions.Size);
     textOptions.AppendNonNullOrEmpty("maxlength: {0}, ", columnEditOptions.MaxLength);
     textOptions.AppendNonNullOrEmpty("readonly: {0}, ", ToLowerString(columnEditOptions.ReadOnly));
     AddCommonAttr(columnEditOptions, ref textOptions);
     textOptions.RemoveLast(COMMA);
     string result = textOptions.ToString();
     sb.AppendNonNullOrEmpty("edittype:'text', editoptions: {{{0}}}, ", textOptions);
 }
 private void ToSelectOption(ref StringBuilder sb, ColumnEditOptions columnEditOptions)
 {
     var selectOptions = new StringBuilder();
     string selectValues = GetSelectValues(columnEditOptions);
     selectOptions.AppendNonNullOrEmpty("dataUrl: {0}, ", Asq(columnEditOptions.DataUrl));
     selectOptions.AppendNonNullOrEmpty("buildSelect: {0}, ", columnEditOptions.BuildSelect);
     selectOptions.AppendNonNullOrEmpty("value: {0}, ", selectValues);
     AddCommonAttr(columnEditOptions, ref selectOptions);
     selectOptions.RemoveLast(COMMA);
     sb.AppendNonNullOrEmpty("edittype:'select', editoptions: {{{0}}}, ", selectOptions);
 }