public static string GridSchema(int pageTemplateId) { if (pageTemplateId == 0) { return(""); } GridSchemaColumns GridSchemaColumns = PageService.GetGridSchemaAndColumn(pageTemplateId); return(GridSchemaColumns.GridSchema); }
public static GridSchemaColumns GetGridSchemaAndColumn(int pageTemplateId) { if (SessionService.IsLocal) { HttpContext.Current.Session["sec.GridSchemaColumns" + pageTemplateId] = null; //xxx } if (HttpContext.Current.Session["sec.GridSchemaColumns" + pageTemplateId] == null) { var pageTemplate = SessionService.PageTemplate(pageTemplateId); var columnDefs = SessionService.ColumnDefs(pageTemplateId); var tableName = pageTemplate.TableName; var primaryKey = pageTemplate.PrimaryKey; StringBuilder sbSchema = new StringBuilder(); StringBuilder sbColumns = new StringBuilder(); StringBuilder sbGridScripts = new StringBuilder(); if (SessionService.DataType(pageTemplateId, primaryKey) == "TEXT" || SessionService.DataType(pageTemplateId, primaryKey) == "GUID") { sbSchema.AppendLine(primaryKey + ": { type: \"string\", editable: false }"); } else { sbSchema.AppendLine(primaryKey + ": { type: \"number\", editable: false }"); } var gridWidth = ""; // checkbox for delete if (pageTemplate.PageType != "gridonly") { sbColumns.AppendLine("{ title: \"<input type='checkbox' value='0' id='chkAll_" + pageTemplateId + "' />\", width: 25, template: '<input type=\"checkbox\" value=\"#= " + primaryKey + " #\" class=\"chk_" + pageTemplateId + "\" />' },"); } using (SourceControlEntities Db = new SourceControlEntities()) { var gridColumns = Db.GridColumns.Where(w => w.PageTemplateId == pageTemplateId).OrderBy(o => o.SortOrder); foreach (var gridColumn in gridColumns) { var columnDef = columnDefs.Where(w => w.ColumnDefId == gridColumn.ColumnDefId).FirstOrDefault(); if (columnDef == null) { continue; } gridWidth = ""; if (columnDef.GridWidth.Length > 0) { gridWidth = ", width: \"" + columnDef.GridWidth + "\""; } if (columnDef.ElementType == "DropdownCustomOption") { sbSchema.AppendLine(",\r\n" + columnDef.ColumnName + "_: { type: \"string\" }"); sbColumns.AppendLine("{ field: \"" + columnDef.ColumnName + "_lco\", title: \"" + columnDef.DisplayName + "\", attributes: { \"style\": \"white-space:nowrap;\" } " + gridWidth + " "); } else if (columnDef.ElementType == "DropdownSimple") { sbSchema.AppendLine(",\r\n" + columnDef.ColumnName + "_: { type: \"string\" }"); sbColumns.AppendLine("{ field: \"" + columnDef.ColumnName + "_tbl\", title: \"" + columnDef.DisplayName + "\" " + gridWidth + " "); } else if (columnDef.ElementType == "DisplayOnly") { sbColumns.AppendLine("{ template: \" #= " + columnDef.ColumnName + " #\", title: \"" + columnDef.DisplayName + "\", attributes: { \"style\": \"white-space:nowrap;\" } " + gridWidth + " "); } else if (columnDef.DataType == "DATE") { sbSchema.AppendLine(",\r\n" + columnDef.ColumnName + ": { type: \"date\", format: \"{0:MM/dd/yyyy}\" }"); sbColumns.AppendLine("{ field: \"" + columnDef.ColumnName + "\", title: \"" + columnDef.DisplayName + "\", attributes: { \"style\": \"white-space:nowrap;\" }, type:\"date\", format:\"{0:MM/dd/yyyy}\" " + gridWidth + " "); } else if (columnDef.DataType == "DATETIME") { sbSchema.AppendLine(",\r\n" + columnDef.ColumnName + ": { type: \"date\", format: \"{0:MM/dd/yyyy hh:mm tt }\" }"); sbColumns.AppendLine("{ field: \"" + columnDef.ColumnName + "\", title: \"" + columnDef.DisplayName + "\", attributes: { \"style\": \"white-space:nowrap;\" }, type:\"date\", format: \"{0:MM/dd/yyyy hh:mm tt }\" " + gridWidth + " "); } else if (columnDef.DataType == "NUMBER") { sbSchema.AppendLine(",\r\n" + columnDef.ColumnName + ": { type: \"number\" }"); sbColumns.AppendLine("{ field: \"" + columnDef.ColumnName + "\", title: \"" + columnDef.DisplayName + "\", attributes: { \"style\": \"white-space:nowrap;\" } " + gridWidth + " "); } else if (columnDef.DataType == "BOOLEAN") { sbSchema.AppendLine(",\r\n" + columnDef.ColumnName + ": { type: \"string\" }"); if (columnDef.ElementType == "CheckboxYesNo") { sbColumns.AppendLine("{ field: \"" + columnDef.ColumnName + "\", title: \"" + columnDef.DisplayName + "\", template:\"#= GetBooleanYesNo(" + columnDef.ColumnName + ") #\" " + gridWidth + " "); } else { sbColumns.AppendLine("{ field: \"" + columnDef.ColumnName + "\", title: \"" + columnDef.DisplayName + "\", template:\"#= GetBooleanTrueFalse(" + columnDef.ColumnName + ") #\" " + gridWidth + " "); } } else if (columnDef.ElementType == "HyperLink") { sbSchema.AppendLine(",\r\n" + columnDef.ColumnName + ": { type: \"string\" }"); sbColumns.AppendLine("{ field: \"" + columnDef.ColumnName + "\", title: \"" + columnDef.DisplayName + "\", template:\"#= GetHyperLink(" + columnDef.ColumnName + ") #\", encoded: false, attributes: { \"style\": \"white-space:nowrap;\" } " + gridWidth + " "); } else if (columnDef.ElementType == "Textarea") { sbSchema.AppendLine(",\r\n" + columnDef.ColumnName + ": { type: \"string\" }"); sbColumns.AppendLine("{ field: \"" + columnDef.ColumnName + "\", title: \"" + columnDef.DisplayName + "\", template:\"#= GetComment(" + columnDef.ColumnName + ") #\" " + gridWidth + " "); } else { sbSchema.AppendLine(",\r\n" + columnDef.ColumnName + ": { type: \"string\" }"); sbColumns.AppendLine("{ field: \"" + columnDef.ColumnName + "\", title: \"" + columnDef.DisplayName + "\", encoded: false, attributes: { \"style\": \"white-space:nowrap;\" } " + gridWidth + " "); } // add multiple checkbox select if ((bool)columnDef.IsMultiSelect) { sbColumns.AppendLine(",filterable: {"); sbColumns.AppendLine(" multi: true,"); sbColumns.AppendLine(" dataSource: {"); sbColumns.AppendLine(" transport: {"); sbColumns.AppendLine(" read: {"); sbColumns.AppendLine(" url: \"Data/GetMultiSelect\","); sbColumns.AppendLine(" dataType: \"json\","); sbColumns.AppendLine(" data: {"); sbColumns.AppendLine(" pageTemplateId: \"" + columnDef.PageTemplateId + "\", columnDefId: " + columnDef.ColumnDefId + ""); sbColumns.AppendLine(" }"); sbColumns.AppendLine(" }"); sbColumns.AppendLine(" }"); sbColumns.AppendLine(" },"); sbColumns.AppendLine(" itemTemplate: function(e) {"); sbColumns.AppendLine(" if (e.field == \"all\") {"); sbColumns.AppendLine(" return \"<div><label><strong><input type='checkbox' />Select All</strong></label></div>\";"); sbColumns.AppendLine(" } else {"); sbColumns.AppendLine(" return \"<div><input type='checkbox' name='\" + e.field + \"' value='#=ValueField#'/><span>#= TextField #</span></div>\""); sbColumns.AppendLine(" }"); sbColumns.AppendLine(" }"); sbColumns.AppendLine("}"); } sbColumns.Append("},"); } } var gridColumns_ = sbColumns.ToString(); if (gridColumns_.Length > 2) { gridColumns_ = gridColumns_.Substring(0, gridColumns_.Length - 1); } GridSchemaColumns gridSchemaColumns = new GridSchemaColumns { GridSchema = sbSchema.ToString(), GridColumns = gridColumns_, GridScripts = sbGridScripts.ToString() }; HttpContext.Current.Session["sec.GridSchemaColumns" + pageTemplateId] = gridSchemaColumns; } return((GridSchemaColumns)HttpContext.Current.Session["sec.GridSchemaColumns" + pageTemplateId]); }