private void ParseParams(string instanceId, string itemName, string workItemID) { // 基本参数 this.InstanceId = instanceId; this.ItemName = System.Web.HttpUtility.UrlDecode(itemName); this.WorkItemID = workItemID; // 验证参数 if (string.IsNullOrEmpty(this.InstanceId) && string.IsNullOrEmpty(this.WorkItemID)) { throw new ArgumentNullException("Param InstanceId and WorkItemID can NOT be null at the same time."); } // 获得流程或者任务对象 if (!string.IsNullOrEmpty(this.InstanceId)) { this.InstanceContext = this.Engine.InstanceManager.GetInstanceContext(this.InstanceId); if (this.InstanceContext == null) { throw new ArgumentNullException("InstanceID invalid."); } } if (!string.IsNullOrEmpty(this.WorkItemID)) { this.WorkItem = this.Engine.WorkItemManager.GetWorkItem(this.WorkItemID); this.CirculateItem = this.Engine.WorkItemManager.GetCirculateItem(this.WorkItemID); if (this.WorkItem == null && this.CirculateItem == null) { throw new ArgumentNullException("WorkItemID invalid."); } } // 获得流程模板 this.Workflow = this.Engine.WorkflowManager.GetPublishedTemplate(this.InstanceContext.WorkflowCode, this.InstanceContext.WorkflowVersion); // this.Workflow = this.Engine.WorkflowManager.GetWorkflow(this.InstanceContext.WorkflowPackage, this.InstanceContext.WorkflowName, this.InstanceContext.WorkflowVersion); if (this.Workflow == null) { throw new ArgumentNullException("Workflow Template invalid."); } // 获得数据定义 this.WorkflowDataItems = this.Engine.BizObjectManager.GetPublishedSchema(this.Workflow.BizObjectSchemaCode).Properties; //this.Workflow.GetDataItem(this.ItemName); foreach (DataModel.PropertySchema p in this.WorkflowDataItems) { if (this.ItemName == p.Name) { this.WorkflowDataItem = p; break; } } if (this.WorkflowDataItem == null) { throw new ArgumentNullException("Workflow Data Item invalid."); } }
/// <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> /// <param name="Schema"></param> /// <returns></returns> private List <ReportSourceColumn> CreateColumnsBySchema(DataModel.BizObjectSchema Schema, string parentName = "") { List <ReportSourceColumn> ReportSourceColumns = new List <ReportSourceColumn>(); if (Schema.Properties != null) { for (int i = 0, j = Schema.Properties.Length; i < j; i++) { DataModel.PropertySchema p = Schema.Properties[i]; if (p.LogicType == Data.DataLogicType.Comment || p.LogicType == Data.DataLogicType.Attachment || p.LogicType == Data.DataLogicType.BizObject || p.LogicType == Data.DataLogicType.BoolArray || p.LogicType == Data.DataLogicType.ByteArray || p.LogicType == Data.DataLogicType.BizObjectArray ) { continue; } DataType DataType = DataType.String; switch (p.LogicType) { case DataLogicType.Decimal: case DataLogicType.Int: case DataLogicType.Double: case DataLogicType.Long: DataType = DataType.Numeric; break; case DataLogicType.DateTime: DataType = DataType.DateTime; break; default: DataType = DataType.String; break; } ReportSourceColumns.Add(new ReportSourceColumn() { ColumnCode = p.Name, ColumnName = p.Name, DisplayName = p.DisplayName, ReportSourceColumnType = ReportSourceColumnType.TableColumn, //DataRuleText = GetPropertySchemaRule(p), DataType = DataType, FunctionType = Function.Sum }); } } return(ReportSourceColumns); }
private List <Item> GetItemNames(ObjectSchemaAssociationViewModel model) { List <Item> list = new List <Item>(); OThinker.H3.DataModel.BizObjectSchema associatedSchema = this.Engine.BizObjectManager.GetDraftSchema(model.WorkflowID); if (associatedSchema == null) { return(list); } OThinker.H3.DataModel.BizObjectAssociation asso = new DataModel.BizObjectAssociation( model.RelationName ?? "", model.DisplayName ?? "", (H3.DataModel.AssociationType)Enum.Parse(typeof(AssociationType), model.Type ?? ""), associatedSchema, model.FilterMethod ?? ""); OThinker.H3.DataModel.DataMap[] maps = asso.Maps.ToArray(); ServiceMethodMap[] methodMaps = associatedSchema.GetMethod("GetList").MethodMaps; if (methodMaps != null && methodMaps.Length > 0) { DataMapCollection paramMaps = associatedSchema.GetMethod("GetList").MethodMaps[0].ParamMaps; string[] paramNames = paramMaps.GetParamNames(); foreach (string propertyName in paramNames) { DataMap map = paramMaps.GetMap(propertyName); string mapProperty = map.MapTo; if (!string.IsNullOrEmpty(mapProperty)) { DataModel.PropertySchema item = associatedSchema.GetProperty(map.ItemName); if (item != null) { list.Add(new Item(item.FullName, item.Name)); } } } } else { foreach (OThinker.H3.DataModel.DataMap map in maps) { DataModel.PropertySchema item = associatedSchema.GetProperty(map.ItemName); list.Add(new Item(item.FullName, item.Name)); } } return(list); }
/// <summary> /// 创建子对象 /// </summary> /// <param name="propertyName">属性名称</param> /// <returns>子对象</returns> private DataModel.BizObjectSchema CreateChildSchema(string propertyName) { DataModel.PropertySchema oldPropertySchema = this.CurrentSchema.GetProperty(this.SelectedProperty); H3.DataModel.BizObjectSchema childSchema = null; if (oldPropertySchema == null || (oldPropertySchema != null && oldPropertySchema.ChildSchema == null)) { childSchema = new DataModel.BizObjectSchema( this.CurrentSchema.StorageType == DataModel.StorageType.PureServiceBased ? DataModel.StorageType.PureServiceBased : DataModel.StorageType.DataList, propertyName, //this.txtChildSchemaCode.Text, false); } else { childSchema = oldPropertySchema.ChildSchema; childSchema.SchemaCode = propertyName; } return(childSchema); }
/// <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); }