private ActionResult ParseParam(string schemaCode)
        {
            ActionResult result = new ActionResult();

            this.SchemaCode = schemaCode;

            if (string.IsNullOrEmpty(this.SchemaCode))
            {
                //指定的参数不正确
                result.Message = "ListenerPolicy.Msg2";
                result.Success = false;
                return(result);
            }

            this.Schema = this.Engine.BizObjectManager.GetDraftSchema(this.SchemaCode);
            if (this.Schema == null)
            {
                //业务对象模式不存在
                result.Message = "ListenerPolicy.Msg1";
                result.Success = false;
                return(result);
            }
            result.Success = true;
            return(result);
        }
예제 #2
0
        /// <summary>
        /// 解析参数
        /// </summary>
        /// <param name="schemaCode">数据模型编码</param>
        /// <param name="id">定时任务ID</param>
        /// <returns>解析结果</returns>
        private ActionResult ParseParam(string schemaCode = "", string id = "")
        {
            ActionResult result = new ActionResult();

            this.InvokerId = id;
            if (string.IsNullOrEmpty(this.InvokerId))
            {
                // 新建模式
                this.Edit       = false;
                this.SchemaCode = schemaCode;

                if (string.IsNullOrEmpty(this.SchemaCode))
                {
                    //指定的参数不正确
                    result.Message = "ScheduleInvoker.Msg3";
                    result.Success = false;
                    return(result);
                }

                this.Schema = this.Engine.BizObjectManager.GetPublishedSchema(this.SchemaCode);
                if (this.Schema == null)
                {
                    //业务对象模式不存在
                    result.Message = "ScheduleInvoker.Msg4";
                    result.Success = false;
                    return(result);
                }
            }
            else
            {
                // 编辑模式
                this.Edit = true;

                this.Invoker = this.Engine.BizObjectManager.GetScheduleInvoker(this.InvokerId);
                if (this.Invoker == null)
                {
                    //该定期调用设置不存在
                    result.Message = "ScheduleInvoker.Msg5";
                    result.Success = false;
                    return(result);
                }

                this.Schema     = this.Engine.BizObjectManager.GetDraftSchema(this.Invoker.SchemaCode);
                this.SchemaCode = this.Invoker.SchemaCode;
                if (this.Schema == null)
                {
                    //业务对象模式不存在

                    result.Message = "ScheduleInvoker.Msg1";
                    result.Success = false;
                    return(result);
                }
            }
            result.Success = true;
            return(result);
        }
 /// <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);
        }
        public JsonResult SaveMasterPackage(MasterPackageViewModel model)
        {
            return(ExecuteFunctionRun(() =>
            {
                ActionResult result = new ActionResult();
                if (string.IsNullOrWhiteSpace(model.Code))
                {
                    result.Success = false;
                    result.Message = "EditBizObjectSchema.CodeNotNull";
                    return Json(result, JsonRequestBehavior.AllowGet);
                    //this.ShowErrorMessage(this.PortalResource.GetString("BizOperation_CodeNotNull"));
                }
                H3.DataModel.BizObjectSchema schema = null;
                if (model.IsImport)
                {
                    if (!string.IsNullOrEmpty(model.BizService))
                    {
                        schema = this.FromDbTableAdapter(model.Code, model.BizService);
                        schema.DisplayName = model.DisplayName ?? schema.SchemaCode;
                    }
                }
                else
                {
                    ////手工新建
                    //if (string.IsNullOrWhiteSpace(model.DisplayName))
                    //{
                    //    result.Success = false;
                    //    result.Message = "EditBizObjectSchema.DisplayNameNotNull";
                    //    return Json(result, JsonRequestBehavior.AllowGet);
                    //}
                    StorageType storageType = (StorageType)int.Parse(model.StorageType);
                    schema = new DataModel.BizObjectSchema(storageType,
                                                           model.Code.Trim(),
                                                           storageType != StorageType.PureServiceBased);
                    schema.DisplayName = model.DisplayName ?? schema.SchemaCode;
                }

                if (schema == null)
                {
                    result.Success = false;
                    result.Message = "msgGlobalString.CreateFailed";
                    return Json(result, JsonRequestBehavior.AllowGet);
                }

                //添加校验
                if (schema.SchemaCode.Length > BizObjectSchema.MaxCodeLength)
                {
                    result.Success = false;
                    result.Message = "EditBizObjectSchema.Msg1";
                    result.Extend = BizObjectSchema.MaxCodeLength;
                    return Json(result, JsonRequestBehavior.AllowGet);
                    //this.ShowWarningMessage(this.PortalResource.GetString("BizObjectSchema_Mssg1") + BizObjectSchema.MaxCodeLength);
                }

                //校验编码规范
                System.Text.RegularExpressions.Regex regex = new System.Text.RegularExpressions.Regex(BizObjectSchema.CodeRegex);
                if (!regex.IsMatch(schema.SchemaCode))
                {
                    result.Success = false;
                    result.Message = "EditBizObjectSchemaProperty.Msg2";
                    return Json(result, JsonRequestBehavior.AllowGet);
                    //this.ShowWarningMessage(this.PortalResource.GetString("BizObjectSchema_Mssg2"));
                }

                if (!this.Engine.BizObjectManager.AddDraftSchema(schema))
                {
                    //保存失败,可能是由于编码重复
                    result.Success = false;
                    result.Message = "EditBizObjectSchema.Msg3";
                    return Json(result, JsonRequestBehavior.AllowGet);
                }
                else
                {
                    // 添加成功,这里还是需要写入FuntionNode节点的,为了跟流程包里的数据模型节点区别
                    Acl.FunctionNode node = new Acl.FunctionNode
                                                (schema.SchemaCode,
                                                schema.DisplayName,
                                                "",
                                                "",
                                                FunctionNodeType.BizObject,
                                                model.ParentCode,
                                                0
                                                );

                    this.Engine.FunctionAclManager.AddFunctionNode(node);
                }

                result.Success = true;
                result.Message = "msgGlobalString.SaveSuccess";
                result.Extend = model.ParentId;
                return Json(result, JsonRequestBehavior.AllowGet);
            }));
        }