public ContentResult Rows(string TableName, ListTypes ListType, string ListName) { MetadataTable mt = SqlBuilder.DefaultMetadata.FindTable(TableName); SqlBuilder Builder = mt.ToSqlBuilder(ListType != ListTypes.Custom ? ListType.ToString() : ListName); ResultTable result = Builder.Execute(30, false, ResultTable.DateHandlingEnum.ConvertToDate); return(Content(SerializationExtensions.ToJson <dynamic>(result), "application/json")); }
public PartialViewResult Edit(string Id, string Table, ListTypes ListType, string ListName) { MetadataTable table = SqlBuilder.DefaultMetadata.FindTable(Table); // SqlBuilder builder = table.ToSqlBuilder(ListType != ListTypes.Custom ? ListType.ToString() : ListName); SqlBuilder builder = table.ToSqlBuilder(""); builder.BaseTable().WithMetadata().WherePrimaryKey(new object[] { (object)Id }); ResultTable result = builder.Execute(); Form model = FormFactory.Default.BuildForm(builder); model.Initialize(result.First()); return(PartialView(model.EditDialogViewUrl, model)); }
public ListBuilder BuildList(string TableName, ListTypes ListType, string ListTitle = null, string CustomListName = null) { ListBuilder list = null; bool InCache = false; MetadataTable Table = SqlBuilder.DefaultMetadata.FindTable(TableName); if (Table == null) { throw new ArgumentException(string.Format("The table '{0}' was not found in metadata", TableName), "TableName"); } switch (ListType) { case ListTypes.Primary: InCache = PrimaryLists.TryGetValue(Table.Fullname, out list); break; case ListTypes.Secondary: InCache = SecondaryLists.TryGetValue(Table.Fullname, out list); break; case ListTypes.Integrated: InCache = IntegratedLists.TryGetValue(Table.Fullname, out list); break; case ListTypes.Lookup: InCache = LookupLists.TryGetValue(Table.Fullname, out list); break; case ListTypes.Custom: if (string.IsNullOrEmpty(CustomListName)) { throw new ArgumentException("Custom List name must be specified to load a custom list", "CustomListName"); } List <ListBuilder> custom = null; if (CustomLists.TryGetValue(Table.Fullname, out custom)) { InCache = custom.Any(x => x.CustomName.Equals(CustomListName, StringComparison.OrdinalIgnoreCase)); if (InCache) { list = custom.First(x => x.CustomName.Equals(CustomListName, StringComparison.OrdinalIgnoreCase)); } } break; default: break; } if (list != null) { return(list); } list = new ListBuilder() { ListType = ListType, TableName = Table.Fullname, Title = string.IsNullOrEmpty(ListTitle) ? Table.DisplayName : ListTitle, CustomName = CustomListName, }; list.AllowNew = list.AllowEdit = list.AllowDelete = ListType != ListTypes.Lookup; string ListName = ListType != ListTypes.Custom ? ListType.ToString() : CustomListName; List <MetadataColumn> columns = new List <MetadataColumn>(Table.PrimaryKey.Columns); List <string> columnDef = null; if (!Table.ListDefinitions.TryGetValue(ListName, out columnDef)) { // No standard specified columnDef = new List <string>(Table.Columns.Values.Where(x => x.IsPrimaryKey == false && x.IsRowGuid == false).Select(x => x.Name)); } foreach (MetadataColumn column in columns) { list.Columns.Add(new ListColumn() { ColumnName = column.Name, DisplayName = column.DisplayName, IsVisible = true, ColumnDataType = ListColumn.GetColumnDataType(column.SqlDataType) }); } list.Builder = Table.ToSqlBuilder(list.ListType != ListTypes.Custom ? list.ListType.ToString() : CustomListName); foreach (string cdef in columnDef) { MetadataColumn mc; SqlDbType type = SqlDbType.NVarChar; string Display = cdef; string ColName = cdef; if (cdef.IndexOf('=') > 0) { ColName = cdef.Split('=')[0]; Display = cdef.Split('=')[1]; } if (!Table.Columns.TryGetValue(ColName, out mc)) { Field f = list.Builder.Tables.SelectMany(x => x.FieldList).FirstOrDefault(x => x.Alias != null && x.Alias.Equals(ColName)); if (f != null) { type = f.SqlDataType; //MetadataTable mtRelated = SqlBuilder.DefaultMetadata.FindTable((f.Table.Schema != null ? f.Table.Schema + "." : "") + f.Table.Name); //MetadataColumn mcRelated; //if (mtRelated.Columns.TryGetValue(f.Name, out mcRelated)) //{ // Display = mcRelated.DisplayName; //} } } else { Display = mc.DisplayName; ColName = mc.Name; type = mc.SqlDataType; } list.Columns.Add(new ListColumn() { ColumnName = ColName, DisplayName = Display, IsVisible = mc != null ? !mc.IsForeignKey : true, ColumnDataType = ListColumn.GetColumnDataType(type) }); } //columns.AddRange( // Table.Columns.Values.Where(x => columnDef.Contains(x.Name)) // ); ToCache(list, ListType, CustomListName); return(list); }