private GridConfig CreateGridConfig(WebEntityViewMeta evm) { GridConfig grid = new GridConfig(); var isTree = evm.EntityMeta.IsTreeEntity; var showInWhere = this.Option.isLookup ? ShowInWhere.DropDown : ShowInWhere.List; //使用list里面的属性生成每一列 foreach (WebEntityPropertyViewMeta property in evm.OrderedEntityProperties()) { if (property.CanShowIn(showInWhere)) { bool canEdit = !this.Option.isReadonly && !evm.NotAllowEdit && !property.IsReadonly; var column = new GridColumnConfig { header = property.Label, dataIndex = property.Name, //flex = 1, }; if (evm.LockedProperties.Contains(property)) { column.locked = true; } //对于引用属性需要分开来特殊处理 if (!property.IsReference) { column.dataIndex = property.Name; if (canEdit) { column.editor = ServerTypeHelper.GetTypeEditor(property); } } else { column.dataIndex = EntityModelGenerator.LabeledRefProperty(property.Name); if (canEdit) { column.editor = ServerTypeHelper.CreateComboList(property); } } grid.columns.Add(column); } } if (isTree && grid.columns.Count > 0) { grid.columns[0].xtype = "treecolumn"; } this.AddCommands(evm, grid.tbar); return(grid); }
private FormConfig CreateFormConfig(WebEntityViewMeta evm) { FormConfig form = new FormConfig(); //使用list里面的属性生成每一列 foreach (WebEntityPropertyViewMeta property in evm.OrderedEntityProperties()) { if (property.CanShowIn(ShowInWhere.Detail)) { bool isReadonly = this.Option.isReadonly || property.IsReadonly || evm.NotAllowEdit; FieldConfig field = null; //对于引用属性需要分开来特殊处理 if (!property.IsReference) { field = ServerTypeHelper.GetTypeEditor(property); field.name = property.Name; } else { field = ServerTypeHelper.CreateComboList(property); field.name = EntityModelGenerator.LabeledRefProperty(property.Name); } field.fieldLabel = property.Label; field.anchor = "100%"; field.isReadonly = isReadonly; if (property.VisibilityIndicator.IsDynamic) { field.visibilityIndicator = property.VisibilityIndicator.Property.Name; } form.items.Add(field); } } this.AddCommands(evm, form.tbar); return(form); }
private void ConvertToClientMeta(WebEntityViewMeta evm, ClientEntityViewMeta clientMeta, bool?isDetail) { clientMeta.model = ClientEntities.GetClientName(evm.EntityType); clientMeta.viewName = evm.ExtendView; clientMeta.label = evm.Label; if (isDetail.GetValueOrDefault(this.Option.isDetail)) { clientMeta.formConfig = CreateFormConfig(evm); } else { clientMeta.gridConfig = CreateGridConfig(evm); if (evm.EntityMeta.IsTreeEntity) { clientMeta.storeConfig = new TreeStoreConfig(); } else { var groupBy = evm.GroupBy; if (groupBy != null) { var n = groupBy.Name; if (groupBy.IsReference) { n = EntityModelGenerator.LabeledRefProperty(n); } clientMeta.groupBy = n; } clientMeta.storeConfig = new StoreConfig { pageSize = evm.PageSize }; } } }
public SubmitActionResponse GetSaveAction(RequestQueryString requestQuery, UIFormModel model) { var context = new EditFormContext(_AppContext, requestQuery.EntityId, requestQuery); context.Build(model); var generator = new EntityModelGenerator(context); generator.Generate(model); var response = new SubmitActionResponse(null); response.Status = SubmitStatus.Fail; if (generator.Status == AnyStatus.Success) { var recordModel = generator.RecordModel; var saveStatus = context.Entity.Save(_AppContext, recordModel); if (saveStatus == AnyStatus.Success) { response.Status = SubmitStatus.Success; response.RedirectUrl = AppLinkProvider.GetDetailPageLink(recordModel.EntityId, recordModel.ID).Url; return(response); } else if (saveStatus == AnyStatus.InvalidData) { PrepareErrorModel(recordModel, ref model); response.Model = model; return(response); } response.Message = saveStatus.Message; return(response); } response.Message = generator.Status.Message; return(response); }
internal static void EntityToJson(EntityViewMeta evm, Entity entity, EntityJson entityJson) { var isTree = evm.EntityMeta.IsTreeEntity; foreach (var propertyVM in evm.EntityProperties) { var property = propertyVM.PropertyMeta; var mp = property.ManagedProperty; if (mp != null) { //如果非树型实体,则需要排除树型实体的两个属性。 if (!isTree && (mp == Entity.TreeIndexProperty || mp == Entity.TreePIdProperty)) { continue; } //引用属性 if (propertyVM.IsReference) { var refMp = mp as IRefProperty; object value = string.Empty; var id = entity.GetRefNullableId(refMp.RefIdProperty); if (id != null) { value = id; } var idName = refMp.RefIdProperty.Name; entityJson.SetProperty(idName, value); //同时写入引用属性的视图属性,如 BookCategoryId_Display if (id != null && propertyVM.CanShowIn(ShowInWhere.List)) { var titleProperty = propertyVM.SelectionViewMeta.RefTypeDefaultView.TitleProperty; if (titleProperty != null) { var lazyRefEntity = entity.GetRefEntity(refMp.RefEntityProperty); var titleMp = titleProperty.PropertyMeta.ManagedProperty; if (titleMp != null) { value = lazyRefEntity.GetProperty(titleMp); } else { value = ObjectHelper.GetPropertyValue(lazyRefEntity, titleProperty.Name); } var name = EntityModelGenerator.LabeledRefProperty(idName); entityJson.SetProperty(name, value); } } } //一般托管属性 else { var pRuntimeType = property.PropertyType; var serverType = ServerTypeHelper.GetServerType(pRuntimeType); if (serverType.Name != SupportedServerType.Unknown) { var value = entity.GetProperty(mp); value = ToClientValue(pRuntimeType, value); entityJson.SetProperty(mp.Name, value); } } } //一般 CLR 属性 else { var pRuntimeType = property.PropertyType; var serverType = ServerTypeHelper.GetServerType(pRuntimeType); if (serverType.Name != SupportedServerType.Unknown) { var value = ObjectHelper.GetPropertyValue(entity, property.Name); value = ToClientValue(pRuntimeType, value); entityJson.SetProperty(property.Name, value); } } } }