/// <summary> /// 获取属性列表 /// </summary> /// <param name="properties">业务对象属性模式</param> /// <param name="publishedSchema">数据模型</param> /// <param name="parentPropertyPath">父级路径</param> /// <returns>数据模型属性列表</returns> private List <PropertySchemaViewModel> GetBizObjectChildren(DataModel.PropertySchema[] properties, DataModel.BizObjectSchema publishedSchema, string parentPropertyPath = "") { //排序 //properties = properties.OrderBy(p => p.Seq).ToArray(); List <PropertySchemaViewModel> list = new List <PropertySchemaViewModel>(); string parentProperty; DataModel.BizObjectSchema chirenSchema = null; DataModel.PropertySchema publishedProperty = null; foreach (DataModel.PropertySchema item in properties) { if (this.Schema.GetAssociation(item.Name) == null) { parentProperty = parentPropertyPath + "\\" + item.Name; //全局变量 var logicType = item.SourceType == SourceType.Metadata ? OThinker.H3.Data.DataLogicType.GlobalData : item.LogicType; PropertySchemaViewModel model = new PropertySchemaViewModel() { ParentProperty = parentProperty, ParentItemName = parentPropertyPath, ItemName = item.Name, LogicType = logicType.ToString(), LogicTypeName = Data.DataLogicTypeConvertor.ToLogicTypeName((Data.DataLogicType)logicType), ChildSchemaCode = item.ChildSchema == null ? null : item.ChildSchema.SchemaCode, DisplayName = string.Format("{0} [{1}]", item.DisplayName, item.Name), DefaultValue = item.DefaultValue == null ? null : item.DefaultValue.ToString(), Trackable = item.Trackable, Indexed = item.Indexed, Searchable = item.Searchable, Abstract = item.Abstract, IsReserved = DataModel.BizObjectSchema.IsReservedProperty(item.Name) }; //判断是否发布 publishedProperty = publishedSchema != null?publishedSchema.GetProperty(item.Name) : null; if (publishedProperty != null && publishedProperty.LogicType == item.LogicType) { model.IsPublished = true; chirenSchema = publishedSchema.GetProperty(item.Name).ChildSchema; } else { model.IsPublished = false; } if (item.ChildSchema != null && item.ChildSchema.Properties != null) { model.children = GetBizObjectChildren(item.ChildSchema.Properties, chirenSchema, parentProperty); } list.Add(model); } } return(list); }
/// <summary> /// 执行保存 /// </summary> /// <returns>是否保存成功</returns> private bool SaveBizObjectSchemaProperty(BizObjectSchemaPropertyViewModel model, out ActionResult actionResult) { actionResult = new ActionResult(); string propertyName = model.PropertyName; string displayName = string.IsNullOrWhiteSpace(model.DisplayName) ? propertyName : model.DisplayName; // 检查选中的参数 Data.DataLogicType logicType = (Data.DataLogicType)Enum.Parse(typeof(Data.DataLogicType), model.LogicType); object defaultValue;//默认值 if (model.DefaultValue == string.Empty) { defaultValue = null; } else if (!DataValidator(model, propertyName, logicType, out defaultValue, out actionResult)) {//数据校验 return(false); } // 校验编码规范 System.Text.RegularExpressions.Regex regex = new System.Text.RegularExpressions.Regex(BizObjectSchema.CodeRegex); if (!regex.IsMatch(propertyName)) { actionResult.Success = false; actionResult.Message = "EditBizObjectSchemaProperty.Msg2"; return(false); } DataModel.PropertySchema newItem = null; if (logicType == Data.DataLogicType.BizObject || logicType == Data.DataLogicType.BizObjectArray) { //业务对象或业务对象数组 H3.DataModel.BizObjectSchema childSchema = CreateChildSchema(model.PropertyName); newItem = new DataModel.PropertySchema( propertyName, displayName, logicType, childSchema); } else { PropertySerializeMethod method = PropertySerializeMethod.None; int maxLength = 0; if (!model.VirtualField) { DataLogicTypeConvertor.GetSerializeMethod(logicType, ref method, ref maxLength); if (logicType == DataLogicType.Attachment && this.RootSchema.SchemaCode != this.CurrentSchema.SchemaCode) { method = PropertySerializeMethod.Xml; } } SourceType sourceType = logicType == DataLogicType.GlobalData ? SourceType.Metadata : SourceType.Normal; newItem = new DataModel.PropertySchema( propertyName, sourceType, method, model.Global, model.Indexed, displayName, logicType == DataLogicType.GlobalData ? DataLogicType.ShortString : logicType, maxLength, defaultValue, model.Formula, string.Empty, //this.txtDisplayValueFormula.Text, // 显示值公式没有实际作用,已注释 model.RecordTrail, model.Searchable, false, // this.chkAbstract.Checked // 摘要没有实际作用,已注释 false ); } bool result = true; if (!string.IsNullOrEmpty(this.SelectedProperty)) {//更新 DataModel.PropertySchema oldPropertySchema = this.CurrentSchema.GetProperty(this.SelectedProperty); DataModel.BizObjectSchema published = this.Engine.BizObjectManager.GetPublishedSchema(this.RootSchema.SchemaCode); if (published != null && published.GetProperty(propertyName) != null && !Data.DataLogicTypeConvertor.CanConvert(oldPropertySchema.LogicType, newItem.LogicType)) { actionResult.Success = false; actionResult.Message = "EditBizObjectSchemaProperty.Msg1"; return(false); } result = this.CurrentSchema.UpdateProperty(this.SelectedProperty, newItem); } else { result = this.CurrentSchema.AddProperty(newItem); } if (!result) { // 保存失败 actionResult.Success = false; actionResult.Message = "EditBizObjectSchemaProperty.Msg9"; return(false); } // 保存 if (!this.Engine.BizObjectManager.UpdateDraftSchema(this.RootSchema)) { // 保存失败 actionResult.Success = false; actionResult.Message = "msgGlobalString.SaveFailed"; return(false); } return(true); }