/// <summary>
        /// 获取词汇表信息
        /// </summary>
        /// <param name="ruleCode"></param>
        /// <returns></returns>
        public JsonResult GetGlossary(string ruleCode)
        {
            return(ExecuteFunctionRun(() => {
                var pageindex = Request["PageIndex"];

                List <Dictionary <string, object> > dataList = new List <Dictionary <string, object> >();
                OThinker.H3.BizBus.BizRule.BizRuleTable Rule = this.Engine.BizBus.GetBizRule(ruleCode);
                List <BizRuleGlossaryViewModel> lists = new List <BizRuleGlossaryViewModel>();
                if (Rule.DataElements != null)
                {
                    foreach (OThinker.H3.BizBus.BizRule.BizRuleDataElement item in Rule.DataElements)
                    {
                        BizRuleGlossaryViewModel model = new BizRuleGlossaryViewModel();

                        model.ElementName = item.ElementName;
                        model.DisplayName = item.DisplayName;
                        model.LogicType = item.LogicType.ToString();

                        model.ParamType = item.ParamType.ToString();

                        model.DefaultValue = item.DefaultValue == null ? "" : item.DefaultValue.ToString();

                        lists.Add(model);
                    }
                }

                //返回符合liegerUIGrid格式的分页数据
                var griddata = CreateLigerUIGridData(lists.ToArray());

                return Json(griddata, JsonRequestBehavior.AllowGet);
            }));
        }
Ejemplo n.º 2
0
        public JsonResult SaveBizRuleTable(string ruleCode, string matrixCode, string cellString)
        {
            return(ExecuteFunctionRun(() => {
                List <List <MatrixCellViewModel> > cells = JsonConvert.DeserializeObject <List <List <MatrixCellViewModel> > >(cellString);

                ActionResult result = new ActionResult(false, "BizRule.DeletedOrNotExists");

                #region 获取对应的业务规则和决策表
                OThinker.H3.BizBus.BizRule.BizRuleTable Rule = null;
                OThinker.H3.BizBus.BizRule.BizRuleDecisionMatrix Matrix = null;

                Rule = this.Engine.BizBus.GetBizRule(ruleCode);
                if (Rule == null)
                {
                    return Json(result);
                }

                Matrix = Rule.GetDecisionMatrix(matrixCode);
                if (Matrix == null)
                {
                    return Json(result);
                }
                #endregion

                if (Matrix.Cells != null)
                {
                    try {
                        int rowLength = Matrix.Cells.Length;
                        for (int i = 0; i < rowLength; i++)
                        {
                            int colLength = Matrix.Cells[i].Length;
                            for (int j = 0; j < colLength; j++)
                            {
                                Matrix.Cells[i][j].CellValue = cells[i][j].Value;
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        result.Message = "msgGlobalString.SaveFailed";
                        result.Extend = ex.Message;
                    }
                }
                this.Engine.BizBus.UpdateBizRule(Rule);

                result.Success = true;
                result.Message = "msgGlobalString.SaveSucced";
                return Json(result);
            }));
        }
        /// <summary>
        /// 获取业务规则信息
        /// </summary>
        /// <param name="ruleCode"></param>
        /// <returns></returns>
        public JsonResult GetBizRule(string ruleCode)
        {
            return(ExecuteFunctionRun(() => {
                OThinker.H3.BizBus.BizRule.BizRuleTable Rule = this.Engine.BizBus.GetBizRule(ruleCode);

                BizRuleViewModel model = new BizRuleViewModel();
                if (Rule != null)
                {
                    model.ObjectID = "-";//随便赋值一个值,用于判断是否为新增
                    model.Code = Rule.Code;
                    model.DisplayName = Rule.DisplayName;
                    model.Description = Rule.Description;
                }

                return Json(model, JsonRequestBehavior.AllowGet);
            }));
        }
        /// <summary>
        /// 删除词汇信息
        /// </summary>
        /// <param name="ruleCode"></param>
        /// <param name="elementNames"></param>
        /// <returns></returns>
        public JsonResult DeleteGlossary(string ruleCode, string elementNames)
        {
            return(ExecuteFunctionRun(() =>
            {
                ActionResult result = new ActionResult();
                OThinker.H3.BizBus.BizRule.BizRuleTable Rule = this.Engine.BizBus.GetBizRule(ruleCode);
                string[] elements = elementNames.Split(';');
                foreach (string elementName in elements)
                {
                    Rule.RemoveDataElement(elementName);
                }
                result.Success = this.Engine.BizBus.UpdateBizRule(Rule);

                if (!result.Success)
                {
                    result.Message = "msgGlobalString.DeleteFailed";
                }

                return Json(result);
            }));
        }
        /// <summary>
        /// 移除业务规则词汇
        /// </summary>
        /// <param name="ruleCode"></param>
        /// <param name="elementName"></param>
        /// <returns></returns>
        public JsonResult RemoveElement(string ruleCode, string elementName)
        {
            return(ExecuteFunctionRun(() => {
                ActionResult result = new ActionResult(true, "");
                OThinker.H3.BizBus.BizRule.BizRuleTable Rule = this.Engine.BizBus.GetBizRule(ruleCode);
                Rule.RemoveDataElement(elementName);
                result.Success = this.Engine.BizBus.UpdateBizRule(Rule);
                if (!result.Success)
                {
                    //删除失败
                    result.Message = "msgGlobalString.DeleteFailed";
                    //this.ShowWarningMessage(this.PortalResource.GetString("EditBizRuleTableDataElement_RemoveFailed"));
                }
                else
                {
                    result.Message = "msgGlobalString.DeleteSucced";
                    //this.ReLoadCurrentTabPage();
                }

                return Json(result);
            }));
        }
Ejemplo n.º 6
0
        public override object CreatePortalTree(string ruleID, string ruleCode)
        {
            List <PortalTreeNode> decisionList = new List <PortalTreeNode>();

            OThinker.H3.BizBus.BizRule.BizRuleTable rule = this.controller.Engine.BizBus.GetBizRule(ruleCode);
            if (rule != null && rule.DecisionMatrixes != null)
            {
                foreach (OThinker.H3.BizBus.BizRule.BizRuleDecisionMatrix matrix in rule.DecisionMatrixes)
                {
                    decisionList.Add(new PortalTreeNode()
                    {
                        ObjectID    = Guid.NewGuid().ToString(),
                        Code        = matrix.Code,
                        Text        = "_" + (string.IsNullOrWhiteSpace(matrix.DisplayName) ? matrix.Code : matrix.DisplayName),
                        IsLeaf      = true,
                        ParentID    = ruleID,
                        ShowPageUrl = this.controller.PortalRoot + ConstantString.PagePath_EditBizRuleDecisionMatrix + "&" + ConstantString.Param_RuleCode + "=" + ruleCode + "&" + ConstantString.Param_DecisionMatrixCode + "=" + matrix.Code + "&ParentID=" + ruleID,
                        Icon        = "fa icon-menu"
                    });
                }
            }
            return(decisionList);
        }
        /// <summary>
        /// 获取业务规则词汇
        /// </summary>
        /// <param name="ruleCode"></param>
        /// <param name="elementName"></param>
        /// <returns></returns>
        public JsonResult GetRuleElement(string ruleCode, string elementName)
        {
            return(ExecuteFunctionRun(() =>
            {
                OThinker.H3.BizBus.BizRule.BizRuleTable Rule = this.Engine.BizBus.GetBizRule(ruleCode);
                OThinker.H3.BizBus.BizRule.BizRuleDataElement Element;
                BizRuleGlossaryViewModel rElement = new BizRuleGlossaryViewModel();
                if (Rule != null)
                {
                    Element = Rule.GetDataElement(elementName);

                    rElement.ElementName = Element.ElementName;
                    rElement.RuleCode = ruleCode;
                    rElement.DisplayName = Element.DisplayName;
                    rElement.Description = Element.Description;
                    rElement.LogicType = Element.LogicType.ToString();
                    rElement.ParamType = Element.ParamType.ToString();
                    rElement.DefaultValue = Element.DefaultValue == null?"":Element.DefaultValue.ToString();
                    rElement.ObjectID = Element.GetHashCode().ToString();//判定是否为新增使用,不为空即可
                }

                return Json(rElement, JsonRequestBehavior.AllowGet);
            }));
        }
Ejemplo n.º 8
0
        public JsonResult GeBizRuleTalbe(string ruleCode, string matrixCode, bool isView)
        {
            return(ExecuteFunctionRun(() => {
                if (string.IsNullOrEmpty(ruleCode) || string.IsNullOrEmpty(matrixCode))
                {
                    return null;
                }


                #region 获取对应的业务规则和决策表
                OThinker.H3.BizBus.BizRule.BizRuleTable Rule = null;
                OThinker.H3.BizBus.BizRule.BizRuleDecisionMatrix Matrix = null;

                Rule = this.Engine.BizBus.GetBizRule(ruleCode);
                if (Rule == null)
                {
                    return null;
                }

                Matrix = Rule.GetDecisionMatrix(matrixCode);
                if (Matrix == null)
                {
                    return null;
                }
                #endregion


                BizRuleTableViewModel model = new BizRuleTableViewModel();

                #region 基本信息
                model.RuleCode = ruleCode;
                model.MatrixCode = matrixCode;
                model.IsView = isView;
                model.MatrixType = Matrix.MatrixType.ToString();
                model.HorizontalCellCount = Matrix.HorizontalCellCount;
                model.VerticalCellCount = Matrix.VerticalCellCount;
                model.RowDepth = Matrix.RowDepth;
                model.ColumnDepth = Matrix.ColumnDepth;
                #endregion

                #region  列集合

                model.Columns = GetMatrixData(Matrix.Columns);

                #endregion

                #region  行集合

                model.Rows = GetMatrixData(Matrix.Rows);

                #endregion

                #region  单元格集合

                int rowLength = Matrix.Cells.Length;

                List <List <MatrixCellViewModel> > listCellcells = new List <List <MatrixCellViewModel> >();

                for (int i = 0; i < rowLength; i++)
                {
                    List <MatrixCellViewModel> listCells = new List <MatrixCellViewModel>();
                    int colLength = Matrix.Cells[i].Length;
                    for (int j = 0; j < colLength; j++)
                    {
                        MatrixCellViewModel cell = new MatrixCellViewModel();
                        cell.RowIndex = i;
                        cell.ColumnIndex = j;
                        cell.Value = Matrix.Cells[i][j].CellValue;

                        listCells.Add(cell);
                    }
                    listCellcells.Add(listCells);
                }
                model.Cells = listCellcells;

                #endregion

                return Json(model, JsonRequestBehavior.AllowGet);
            }));
        }
Ejemplo n.º 9
0
        public JsonResult ExportToExcel(string ruleCode, string matrixCode, string tableDataString)
        {
            return(ExecuteFunctionRun(() =>
            {
                tableDataString = Server.HtmlDecode(tableDataString.Replace('\"', '"'));

                if (string.IsNullOrEmpty(ruleCode) || string.IsNullOrEmpty(matrixCode))
                {
                    return null;
                }

                #region 获取对应的业务规则和决策表
                OThinker.H3.BizBus.BizRule.BizRuleTable Rule = null;
                OThinker.H3.BizBus.BizRule.BizRuleDecisionMatrix Matrix = null;

                Rule = this.Engine.BizBus.GetBizRule(ruleCode);
                if (Rule == null)
                {
                    return null;
                }

                Matrix = Rule.GetDecisionMatrix(matrixCode);
                if (Matrix == null)
                {
                    return null;
                }
                #endregion

                List <List <MatrixCellExcelViewModel> > TableData = JsonConvert.DeserializeObject <List <List <MatrixCellExcelViewModel> > >(tableDataString);

                IWorkbook workbook = new HSSFWorkbook();
                ISheet sheet = workbook.CreateSheet();

                for (int rowIndex = 0; rowIndex < TableData.Count; rowIndex++)
                {
                    List <MatrixCellExcelViewModel> tableRow = TableData[rowIndex];
                    IRow row = sheet.GetRow(rowIndex);
                    if (row == null)
                    {
                        row = sheet.CreateRow(rowIndex);
                    }
                    for (int colIndex = 0; colIndex < tableRow.Count; colIndex++)
                    {
                        MatrixCellExcelViewModel tableCell = tableRow[colIndex];

                        int colIndex2 = 0;
                        while (row.GetCell(colIndex2) != null)
                        {
                            colIndex2++;
                        }

                        if (tableCell.ColSpan > 1)
                        {
                            for (int i = colIndex2; i < colIndex2 + tableCell.ColSpan; i++)
                            {
                                row.CreateCell(i);
                            }
                            setCellRangeAddress(sheet, rowIndex, rowIndex, colIndex2, colIndex2 + tableCell.ColSpan - 1);
                        }
                        else
                        {
                            row.CreateCell(colIndex2);
                        }

                        if (tableCell.RowSpan > 1)
                        {
                            for (int i = rowIndex + 1; i < rowIndex + tableCell.RowSpan; i++)
                            {
                                IRow row2 = sheet.GetRow(i);
                                if (row2 == null)
                                {
                                    row2 = sheet.CreateRow(i);
                                }
                                if (tableCell.ColSpan > 1)
                                {
                                    for (int j = colIndex2; j < colIndex2 + tableCell.ColSpan; j++)
                                    {
                                        row2.CreateCell(j);
                                    }
                                }
                                else
                                {
                                    row2.CreateCell(colIndex2);
                                }
                            }
                            setCellRangeAddress(sheet, rowIndex, rowIndex + tableCell.RowSpan - 1, colIndex2, colIndex2);
                        }

                        //给单元格赋值
                        row.GetCell(colIndex2).SetCellValue(tableCell.Value);
                        //给单元格添加样式
                        ICellStyle cellStyle = workbook.CreateCellStyle();
                        cellStyle.Alignment = HorizontalAlignment.Center;
                        cellStyle.VerticalAlignment = VerticalAlignment.Center;
                        row.GetCell(colIndex2).CellStyle = cellStyle;
                    }
                }

                string virtualPath = this.PortalRoot + "/TempImages/" + Matrix.DisplayName + DateTime.Now.ToString("yyyy-MM-dd") + ".xls";
                string FilePath = Server.MapPath(this.PortalRoot + "/TempImages/" + Matrix.DisplayName + DateTime.Now.ToString("yyyy-MM-dd") + ".xls");

                using (FileStream ms = System.IO.File.Create(FilePath))
                {
                    workbook.Write(ms);
                }
                string FileUrl = virtualPath;

                ActionResult result = new ActionResult();
                result.Success = true;
                result.Message = FileUrl;

                return Json(result);
            }));
        }
        /// <summary>
        /// 保存规则
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public JsonResult SaveBizRule(BizRuleViewModel model)
        {
            return(ExecuteFunctionRun(() => {
                ActionResult result = new ActionResult();
                OThinker.H3.BizBus.BizRule.BizRuleTable Rule = null;
                bool IsCreate = string.IsNullOrEmpty(model.ObjectID);
                if (!BizRuleAuthorized)
                {
                    result.Success = false;
                    result.Message = "BizRule.NotAuthorized";
                    return Json(result);
                }
                if (IsCreate)
                {
                    if (string.IsNullOrEmpty(model.Code) || string.IsNullOrEmpty(model.Code.Trim()))
                    {
                        //ShowWarningMessage(PortalResource.GetString("EditBizRuleTable_InvalidCode"));
                        result.Success = false;
                        result.Message = "msgGlobalString.InvalidCode";
                        return Json(result);
                    }

                    //业务规则必须以字母开始,不让创建到数据库表字段时报错
                    System.Text.RegularExpressions.Regex regex = new System.Text.RegularExpressions.Regex("^[a-zA-Z\\u4e00-\\u9fa5][0-9a-zA-Z\\u4e00-\\u9fa5_]*$");
                    if (!regex.Match(model.Code).Success)
                    {
                        result.Success = false;
                        result.Message = "EditBizObjectSchemaProperty.Msg4";
                        return Json(result);
                    }

                    Rule = new OThinker.H3.BizBus.BizRule.BizRuleTable(model.Code.Trim());
                    Rule.DisplayName = model.DisplayName;
                    Rule.Description = model.Description;


                    if (Engine.BizBus.GetBizRule(Rule.Code) != null)
                    {
                        //ShowWarningMessage(PortalResource.GetString("EditBizRuleTable_CodeExisted"));
                        result.Success = false;
                        result.Message = "msgGlobalString.CodeExisted";
                        return Json(result);
                    }

                    if (Engine.BizBus.AddBizRule(Rule, model.ParentCode))
                    {
                        result.Success = true;
                        //ReLoadParentTreeNode(ParentID);
                    }
                }
                else
                {
                    Rule = this.Engine.BizBus.GetBizRule(model.Code);
                    Rule.DisplayName = model.DisplayName;
                    Rule.Description = model.Description;
                    result.Success = this.Engine.BizBus.UpdateBizRule(Rule);
                }

                if (result.Success)
                {
                    result.Message = "msgGlobalString.SaveSucced";
                    return Json(result);
                }
                else
                {
                    result.Message = "msgGlobalString.SaveFailed";
                    return Json(result);
                }
            }));
        }
        /// <summary>
        /// 创建公式编辑器左边树
        /// </summary>
        /// <param name="functionID"></param>
        /// <param name="nodes"></param>
        /// <returns></returns>
        protected List <FormulaTreeNode> GetFormulaTree(string SchemaCode, string RuleCode)
        {
            List <FormulaTreeNode> treeNodeList = new List <FormulaTreeNode>();

            #region 输入
            string          InputObjectID = Guid.NewGuid().ToString();//构造一个ObjectID
            FormulaTreeNode InputNode     = new FormulaTreeNode()
            {
                ObjectID    = InputObjectID,
                Text        = "FormulaEditor.FormulaEditor_Input",                               //显示
                Icon        = this.PortalRoot + "/WFRes/_Content/designer/image/formula/in.png", //图标
                IsLeaf      = true,
                LoadDataUrl = "",                                                                //加载数据,组织结构时使用
                FormulaType = FormulaType.Input.ToString(),                                      //判断类型
                Value       = "",                                                                //存储值,点击时传递该值
                ParentID    = ""
            };
            treeNodeList.Add(InputNode);
            #endregion

            #region 常量

            string          BlockObjectID = Guid.NewGuid().ToString();//构造一个ObjectID
            FormulaTreeNode BlockNode     = new FormulaTreeNode()
            {
                ObjectID    = BlockObjectID,
                Text        = "FormulaEditor.FormulaEditor_Constant",                                   //显示
                Icon        = this.PortalRoot + "/WFRes/_Content/designer/image/formula/folder_16.png", //图标
                IsLeaf      = false,
                LoadDataUrl = "",                                                                       //加载数据,组织结构时使用
                FormulaType = FormulaType.Input.ToString(),                                             //判断类型
                Value       = "",                                                                       //存储值,点击时传递该值
                ParentID    = ""
            };

            treeNodeList.Add(BlockNode);

            List <string> BlockValus = new List <string>();
            BlockValus.Add("True");
            BlockValus.Add("False");
            BlockValus.Add("null");

            foreach (string block in BlockValus)
            {
                FormulaTreeNode constNode = new FormulaTreeNode()
                {
                    ObjectID    = Guid.NewGuid().ToString(),
                    Text        = block,                                                                //显示
                    Icon        = this.PortalRoot + "/WFRes/_Content/designer/image/formula/const.png", //图标
                    IsLeaf      = true,
                    LoadDataUrl = "",                                                                   //加载数据,组织结构时使用
                    FormulaType = FormulaType.Block.ToString(),                                         //判断类型
                    Value       = block,                                                                //存储值,点击时传递该值
                    ParentID    = BlockObjectID
                };

                treeNodeList.Add(constNode);
            }

            #endregion

            #region 函数

            var             FunctionRootID     = Guid.NewGuid().ToString();
            FormulaTreeNode FunctionParentNode = new FormulaTreeNode()
            {
                ObjectID    = FunctionRootID,
                Text        = "FormulaEditor.FormulaEditor_Funciton",
                Value       = "",
                ParentID    = "",
                LoadDataUrl = "",
                IsLeaf      = false,
                FormulaType = FormulaType.Function.ToString(),
                Icon        = this.PortalRoot + "/WFRes/_Content/designer/image/formula/folder_16.png" //图标
            };
            treeNodeList.Add(FunctionParentNode);

            #endregion

            #region 参与者函数

            List <object> lstParticipantFunctions = new List <object>();
            foreach (OThinker.H3.Math.Function Function in OThinker.H3.Math.FunctionFactory.Create(this.Engine.Organization, this.Engine.BizBus))
            {
                if (Function is OThinker.H3.Math.Function)
                {
                    //ERROR:这两个函数名称不是Public所以不能访问,下行代码写死了函数名称
                    //以下两个函数不显示
                    if (Function.FunctionName == "OrgCodeToID" || Function.FunctionName == "OrgIDToCode")
                    {
                        continue;
                    }

                    OThinker.H3.Math.Parameter returns = Function.GetHelper().Return;
                    //构造脚本
                    lstParticipantFunctions.Add(new
                    {
                        FunctionName = Function.FunctionName,
                        Helper       = ((OThinker.H3.Math.Function)Function).GetHelper(),
                        ReturnType   = returns == null ? null : returns.LogicTypes
                    });

                    //构造树节点
                    FormulaTreeNode FunctionNode = new FormulaTreeNode()
                    {
                        ObjectID    = Guid.NewGuid().ToString(),
                        Text        = Function.FunctionName,
                        Value       = Function.FunctionName,
                        ParentID    = FunctionRootID,
                        LoadDataUrl = "",
                        IsLeaf      = true,
                        FormulaType = FormulaType.ParticipantFunction.ToString(),
                        Icon        = this.PortalRoot + "/WFRes/_Content/designer/image/formula/pf.png" //图标
                    };
                    treeNodeList.Add(FunctionNode);
                }
            }

            #endregion

            #region 参数类型

            // <Key,{Name,DisplayName}>
            Dictionary <string, object> LogicTypeDictionary = new Dictionary <string, object>();
            foreach (Data.DataLogicType LogicType in Enum.GetValues(typeof(Data.DataLogicType)))
            {
                LogicTypeDictionary.Add(((int)LogicType).ToString(), new { Name = LogicType.ToString(), DisplayName = Data.DataLogicTypeConvertor.ToLogicTypeName(LogicType) });
            }
            //TODO
            //ScriptManager.RegisterClientScriptBlock(this.Page, Page.GetType(), "LogicTypes", "var LogicTypes=" + this.JSSerializer.Serialize(LogicTypeDictionary) + ";", true);

            #endregion

            #region 规则环境

            if (!string.IsNullOrWhiteSpace(RuleCode))
            {
                OThinker.H3.BizBus.BizRule.BizRuleTable rule = this.Engine.BizBus.GetBizRule(RuleCode);
                if (rule != null)
                {
                    string          RuleRootID   = Guid.NewGuid().ToString();
                    bool            isleaf       = rule.DataElements == null;
                    FormulaTreeNode RuleRootNode = new FormulaTreeNode()
                    {
                        ObjectID    = RuleRootID,
                        Text        = "FormulaEditor.FormulaEditor_Vocabulary",
                        Value       = "",
                        ParentID    = "",
                        LoadDataUrl = "",
                        IsLeaf      = isleaf,
                        FormulaType = FormulaType.RuleElement.ToString(),
                        Icon        = this.PortalRoot + "/WFRes/_Content/designer/image/formula/folder_16.png" //图标
                    };

                    treeNodeList.Add(RuleRootNode);

                    if (rule.DataElements != null)
                    {
                        foreach (OThinker.H3.BizBus.BizRule.BizRuleDataElement RuleElement in rule.DataElements)
                        {
                            //词汇表
                            FormulaTreeNode RuleElementNode = new FormulaTreeNode()
                            {
                                ObjectID    = Guid.NewGuid().ToString(),
                                Text        = RuleElement.DisplayName + "[" + RuleElement.ElementName + "]",
                                Value       = RuleElement.ElementName,
                                ParentID    = RuleRootID,
                                LoadDataUrl = "",
                                IsLeaf      = true,
                                FormulaType = FormulaType.RuleElement.ToString(),
                                Icon        = this.PortalRoot + "/WFRes/_Content/designer/image/formula/di.png" //图标
                            };

                            treeNodeList.Add(RuleElementNode);
                        }
                    }
                }
            }

            #endregion

            #region 流程环境

            if (!string.IsNullOrEmpty(SchemaCode))
            {
                //系统数据
                List <FormulaTreeNode> listSystemDatas = GetSystemDataItemNode("");

                treeNodeList.AddRange(listSystemDatas);
            }

            #endregion

            #region 数据模型环境
            if (!string.IsNullOrEmpty(SchemaCode))
            {
                DataModel.BizObjectSchema BizSchema = this.Engine.BizObjectManager.GetDraftSchema(SchemaCode);
                //如果 BizShceMa为空,把SchemaCode 作为流程编码查询对应的SchemaCode然后再查询
                if (BizSchema == null)
                {
                    WorkflowTemplate.WorkflowClause clause = this.Engine.WorkflowManager.GetClause(SchemaCode);
                    {
                        if (clause != null)
                        {
                            BizSchema = this.Engine.BizObjectManager.GetDraftSchema(clause.BizSchemaCode);
                        }
                    }
                }


                if (BizSchema != null)
                {
                    if (BizSchema.IsQuotePacket)
                    {
                        BizSchema = this.Engine.BizObjectManager.GetDraftSchema(BizSchema.BindPacket);
                    }
                    string          SchemaRootID   = Guid.NewGuid().ToString();
                    FormulaTreeNode SchemaRootNode = new FormulaTreeNode()
                    {
                        ObjectID    = SchemaRootID,
                        Text        = "FormulaEditor.FormulaEditor_BusinessPorperty",
                        Value       = "",
                        ParentID    = "",
                        LoadDataUrl = "",
                        IsLeaf      = false,
                        FormulaType = FormulaType.BizObjectSchema.ToString(),
                        Icon        = this.PortalRoot + "/WFRes/_Content/designer/image/formula/folder_16.png" //图标
                    };



                    if (BizSchema != null && BizSchema.Properties != null)
                    {
                        List <object> lstDataItems = new List <object>();
                        foreach (DataModel.PropertySchema Property in BizSchema.Properties)
                        {
                            //不显示保留数据项
                            if (!DataModel.BizObjectSchema.IsReservedProperty(Property.Name))
                            {
                                lstDataItems.Add(new
                                {
                                    Name        = Property.Name,
                                    DisplayName = Property.DisplayName,
                                    LogicType   = Property.LogicType
                                });
                                TreeNode DataItemNode = new TreeNode(Property.FullName, Property.Name);
                                DataItemNode.NavigateUrl = "javascript:FormulaSettings.InsertVariable('" + Property.Name + "')";
                                DataItemNode.ImageUrl    = "../../WFRes/_Content/designer/image/formula/di.png";
                                FormulaTreeNode SchemaNode = new FormulaTreeNode()
                                {
                                    ObjectID    = Guid.NewGuid().ToString(),
                                    Text        = Property.DisplayName + "[" + Property.Name + "]",
                                    Value       = Property.Name,
                                    ParentID    = SchemaRootID,
                                    LoadDataUrl = "",
                                    IsLeaf      = true,
                                    FormulaType = FormulaType.BizObjectSchema.ToString(),
                                    Icon        = this.PortalRoot + "/WFRes/_Content/designer/image/formula/di.png" //图标
                                };

                                treeNodeList.Add(SchemaNode);
                            }
                        }

                        if (lstDataItems.Count == 0)
                        {
                            SchemaRootNode.IsLeaf = true;
                        }
                        treeNodeList.Add(SchemaRootNode);

                        //ScriptManager.RegisterClientScriptBlock(this.Page, Page.GetType(), "FunctionNames", "var DataItems=" + this.JSSerializer.Serialize(lstDataItems) + ";", true);
                    }
                }
            }

            #endregion

            #region 符号

            string          OperatorRootID   = Guid.NewGuid().ToString();
            FormulaTreeNode OperatorRootNode = new FormulaTreeNode()
            {
                ObjectID    = OperatorRootID,
                Text        = "FormulaEditor.FormulaEditor_Symbol",
                Value       = "",
                ParentID    = "",
                LoadDataUrl = "",
                IsLeaf      = false,
                FormulaType = FormulaType.Operator.ToString(),
                Icon        = this.PortalRoot + "/WFRes/_Content/designer/image/formula/folder_16.png" //图标
            };

            treeNodeList.Add(OperatorRootNode);

            //加减乘除
            treeNodeList.Add(new FormulaTreeNode()
            {
                ObjectID = Guid.NewGuid().ToString(), ParentID = OperatorRootID, IsLeaf = true, Text = Enum.GetName(typeof(OThinker.H3.Math.Operator), OThinker.H3.Math.Operator.Plus) + " +", Value = "+", Icon = this.PortalRoot + "/WFRes/_Content/designer//image/formula/op.png", FormulaType = FormulaType.Operator.ToString()
            });
            treeNodeList.Add(new FormulaTreeNode()
            {
                ObjectID = Guid.NewGuid().ToString(), ParentID = OperatorRootID, IsLeaf = true, Text = Enum.GetName(typeof(OThinker.H3.Math.Operator), OThinker.H3.Math.Operator.Minus) + " -", Value = "-", Icon = this.PortalRoot + "/WFRes/_Content/designer//image/formula/op.png", FormulaType = FormulaType.Operator.ToString()
            });
            treeNodeList.Add(new FormulaTreeNode()
            {
                ObjectID = Guid.NewGuid().ToString(), ParentID = OperatorRootID, IsLeaf = true, Text = Enum.GetName(typeof(OThinker.H3.Math.Operator), OThinker.H3.Math.Operator.Mul) + " *", Value = "*", Icon = this.PortalRoot + "/WFRes/_Content/designer//image/formula/op.png", FormulaType = FormulaType.Operator.ToString()
            });
            treeNodeList.Add(new FormulaTreeNode()
            {
                ObjectID = Guid.NewGuid().ToString(), ParentID = OperatorRootID, IsLeaf = true, Text = Enum.GetName(typeof(OThinker.H3.Math.Operator), OThinker.H3.Math.Operator.Div) + " /", Value = "/", Icon = this.PortalRoot + "/WFRes/_Content/designer//image/formula/op.png", FormulaType = FormulaType.Operator.ToString()
            });
            treeNodeList.Add(new FormulaTreeNode()
            {
                ObjectID = Guid.NewGuid().ToString(), ParentID = OperatorRootID, IsLeaf = true, Text = Enum.GetName(typeof(OThinker.H3.Math.Operator), OThinker.H3.Math.Operator.Set) + " =", Value = "=", Icon = this.PortalRoot + "/WFRes/_Content/designer//image/formula/op.png", FormulaType = FormulaType.Operator.ToString()
            });

            //大小等于
            treeNodeList.Add(new FormulaTreeNode()
            {
                ObjectID = Guid.NewGuid().ToString(), ParentID = OperatorRootID, IsLeaf = true, Text = Enum.GetName(typeof(OThinker.H3.Math.Operator), OThinker.H3.Math.Operator.Gr) + " >", Value = ">", Icon = this.PortalRoot + "/WFRes/_Content/designer//image/formula/op.png", FormulaType = FormulaType.Operator.ToString()
            });
            treeNodeList.Add(new FormulaTreeNode()
            {
                ObjectID = Guid.NewGuid().ToString(), ParentID = OperatorRootID, IsLeaf = true, Text = Enum.GetName(typeof(OThinker.H3.Math.Operator), OThinker.H3.Math.Operator.GrEq) + " >=", Value = ">=", Icon = this.PortalRoot + "/WFRes/_Content/designer//image/formula/op.png", FormulaType = FormulaType.Operator.ToString()
            });

            treeNodeList.Add(new FormulaTreeNode()
            {
                ObjectID = Guid.NewGuid().ToString(), ParentID = OperatorRootID, IsLeaf = true, Text = Enum.GetName(typeof(OThinker.H3.Math.Operator), OThinker.H3.Math.Operator.Ls) + " <", Value = "<", Icon = this.PortalRoot + "/WFRes/_Content/designer//image/formula/op.png", FormulaType = FormulaType.Operator.ToString()
            });
            treeNodeList.Add(new FormulaTreeNode()
            {
                ObjectID = Guid.NewGuid().ToString(), ParentID = OperatorRootID, IsLeaf = true, Text = Enum.GetName(typeof(OThinker.H3.Math.Operator), OThinker.H3.Math.Operator.LsEq) + " <=", Value = "<=", Icon = this.PortalRoot + "/WFRes/_Content/designer//image/formula/op.png", FormulaType = FormulaType.Operator.ToString()
            });
            treeNodeList.Add(new FormulaTreeNode()
            {
                ObjectID = Guid.NewGuid().ToString(), ParentID = OperatorRootID, IsLeaf = true, Text = Enum.GetName(typeof(OThinker.H3.Math.Operator), OThinker.H3.Math.Operator.Eq) + " ==", Value = "==", Icon = this.PortalRoot + "/WFRes/_Content/designer//image/formula/op.png", FormulaType = FormulaType.Operator.ToString()
            });
            treeNodeList.Add(new FormulaTreeNode()
            {
                ObjectID = Guid.NewGuid().ToString(), ParentID = OperatorRootID, IsLeaf = true, Text = Enum.GetName(typeof(OThinker.H3.Math.Operator), OThinker.H3.Math.Operator.NtEq) + " !=", Value = "!=", Icon = this.PortalRoot + "/WFRes/_Content/designer//image/formula/op.png", FormulaType = FormulaType.Operator.ToString()
            });

            //与或非
            treeNodeList.Add(new FormulaTreeNode()
            {
                ObjectID = Guid.NewGuid().ToString(), ParentID = OperatorRootID, IsLeaf = true, Text = Enum.GetName(typeof(OThinker.H3.Math.Operator), OThinker.H3.Math.Operator.And) + " &&", Value = "&&", Icon = this.PortalRoot + "/WFRes/_Content/designer//image/formula/op.png", FormulaType = FormulaType.Operator.ToString()
            });
            treeNodeList.Add(new FormulaTreeNode()
            {
                ObjectID = Guid.NewGuid().ToString(), ParentID = OperatorRootID, IsLeaf = true, Text = Enum.GetName(typeof(OThinker.H3.Math.Operator), OThinker.H3.Math.Operator.Or) + " ||", Value = "||", Icon = this.PortalRoot + "/WFRes/_Content/designer//image/formula/op.png", FormulaType = FormulaType.Operator.ToString()
            });
            treeNodeList.Add(new FormulaTreeNode()
            {
                ObjectID = Guid.NewGuid().ToString(), ParentID = OperatorRootID, IsLeaf = true, Text = Enum.GetName(typeof(OThinker.H3.Math.Operator), OThinker.H3.Math.Operator.Not) + " !", Value = "!", Icon = this.PortalRoot + "/WFRes/_Content/designer//image/formula/op.png", FormulaType = FormulaType.Operator.ToString()
            });

            //左/右括号
            treeNodeList.Add(new FormulaTreeNode()
            {
                ObjectID = Guid.NewGuid().ToString(), ParentID = OperatorRootID, IsLeaf = true, Text = Enum.GetName(typeof(OThinker.H3.Math.Operator), OThinker.H3.Math.Operator.LeftPar) + " (", Value = "(", Icon = this.PortalRoot + "/WFRes/_Content/designer//image/formula/op.png", FormulaType = FormulaType.Operator.ToString()
            });
            treeNodeList.Add(new FormulaTreeNode()
            {
                ObjectID = Guid.NewGuid().ToString(), ParentID = OperatorRootID, IsLeaf = true, Text = Enum.GetName(typeof(OThinker.H3.Math.Operator), OThinker.H3.Math.Operator.RightPar) + " )", Value = ")", Icon = this.PortalRoot + "/WFRes/_Content/designer//image/formula/op.png", FormulaType = FormulaType.Operator.ToString()
            });

            #endregion

            #region 组织架构

            var             OrgRootID   = this.Engine.Organization.RootUnit.ObjectID;
            FormulaTreeNode OrgRootNode = new FormulaTreeNode()
            {
                ObjectID    = OrgRootID,
                Text        = this.Engine.Organization.RootUnit.Name,
                Value       = OrgRootID,
                ParentID    = "",
                LoadDataUrl = this.PortalRoot + "/Formula/LoadTreeData?unitID=" + OrgRootID,
                IsLeaf      = false,
                FormulaType = FormulaType.Organization.ToString(),
                Icon        = this.PortalRoot + "/WFRes/_Content/designer/image/formula/folder_16.png" //图标
            };

            treeNodeList.Add(OrgRootNode);

            ////选中事件,前台处理
            //if (!string.IsNullOrEmpty(Company.Code))
            //    UserTree.NavigateUrl = "javascript:FormulaSettings.InsertUser(" + JSSerializer.Serialize(UserTree.Text) + "," + JSSerializer.Serialize(Company.Code) + ")";
            //else
            //    UserTree.NavigateUrl = "javascript:FormulaSettings.InsertUser(" + JSSerializer.Serialize(UserTree.Text) + ",'" + JSSerializer.Serialize(Company.ObjectID) + "')";

            #endregion

            return(treeNodeList);
        }
        /// <summary>
        /// 验证公式
        /// </summary>
        /// <param name="Formula"></param>
        /// <param name="SchemaCode">流程模板编码</param>
        /// <param name="RuleCode"></param>
        /// <returns></returns>
        public JsonResult Validate(string Formula, string SchemaCode, string RuleCode)
        {
            return(ExecuteFunctionRun(() =>
            {
                //校验结果
                ActionResult result = new ActionResult(true, "");

                Formula = Server.HtmlDecode(Formula);
                //错误项
                string[] errorItems = null;
                //错误信息
                List <string> Errors = new List <string>();

                if (!string.IsNullOrEmpty(Formula))
                {
                    // 所有数据项的名称
                    Dictionary <string, string> formulaItemNames = new Dictionary <string, string>();
                    string formulaId = Guid.NewGuid().ToString();
                    formulaItemNames.Add(formulaId, Formula);

                    //所有项名称:数据项、流程关键字
                    List <string> allItemNames = new List <string>();

                    //流程关键字
                    string[] words = OThinker.H3.Instance.Keywords.ParserFactory.GetKeywords();
                    allItemNames.AddRange(words);

                    //业务模型数据项
                    //string SchemaCode = CurrentParams[ConstantString.Param_SchemaCode];
                    if (!string.IsNullOrEmpty(SchemaCode))
                    {
                        DataModel.BizObjectSchema Schema = this.Engine.BizObjectManager.GetDraftSchema(SchemaCode);
                        //如果一个流程包含有多个流程模板的时候,需要重新计算一下shcema
                        if (Schema == null)
                        {
                            WorkflowTemplate.WorkflowClause clause = this.Engine.WorkflowManager.GetClause(SchemaCode);
                            if (clause != null)
                            {
                                Schema = this.Engine.BizObjectManager.GetDraftSchema(clause.BizSchemaCode);
                            }
                        }
                        if (Schema != null)
                        {
                            if (Schema.IsQuotePacket)
                            {
                                Schema = this.Engine.BizObjectManager.GetDraftSchema(Schema.BindPacket);
                            }
                            foreach (DataModel.PropertySchema item in Schema.Properties)
                            {
                                allItemNames.Add(item.Name);
                            }
                        }
                    }

                    //string RuleCode = CurrentContext.Request[ConstantString.Param_RuleCode];
                    // 业务规则数据项
                    if (!string.IsNullOrEmpty(RuleCode))
                    {
                        OThinker.H3.BizBus.BizRule.BizRuleTable rule = this.Engine.BizBus.GetBizRule(RuleCode);
                        if (rule != null)
                        {
                            if (rule.DataElements != null)
                            {
                                foreach (OThinker.H3.BizBus.BizRule.BizRuleDataElement RuleElement in rule.DataElements)
                                {
                                    allItemNames.Add(RuleElement.ElementName);
                                }
                            }
                        }
                    }

                    Function[] fs = FunctionFactory.Create(this.Engine.Organization, this.Engine.BizBus);
                    Dictionary <string, Function> fDic = new Dictionary <string, Function>();
                    if (fs != null)
                    {
                        foreach (OThinker.H3.Math.Function f in fs)
                        {
                            fDic.Add(f.FunctionName, f);
                        }
                    }

                    result.Success = FormulaParser.Validate(Formula, fDic, allItemNames, ref Errors);

                    result.Message = string.Join(";", Errors);
                }
                return Json(result, JsonRequestBehavior.AllowGet);
            }));
        }
        /// <summary>
        /// 获取提示信息
        /// </summary>
        /// <param name="SchemaCode"></param>
        /// <param name="RuleCode"></param>
        /// <returns></returns>
        public JsonResult GetFormulaTips(string SchemaCode, string RuleCode)
        {
            return(ExecuteFunctionRun(() =>
            {
                FormulaTipViewModel model = new FormulaTipViewModel();

                #region 参与者函数

                List <object> lstParticipantFunctions = new List <object>();
                foreach (OThinker.H3.Math.Function Function in OThinker.H3.Math.FunctionFactory.Create(this.Engine.Organization, this.Engine.BizBus))
                {
                    if (Function is OThinker.H3.Math.Function)
                    {
                        //ERROR:这两个函数名称不是Public所以不能访问,下行代码写死了函数名称
                        //以下两个函数不显示
                        if (Function.FunctionName == "OrgCodeToID" || Function.FunctionName == "OrgIDToCode")
                        {
                            continue;
                        }

                        OThinker.H3.Math.Parameter returns = Function.GetHelper().Return;
                        //构造脚本
                        lstParticipantFunctions.Add(new
                        {
                            FunctionName = Function.FunctionName,
                            Helper = ((OThinker.H3.Math.Function)Function).GetHelper(),
                            ReturnType = returns == null ? null : returns.LogicTypes
                        });
                    }
                }
                model.ParticipantFunctions = lstParticipantFunctions;

                #endregion

                #region 参数类型

                // <Key,{Name,DisplayName}>
                Dictionary <string, object> LogicTypeDictionary = new Dictionary <string, object>();
                foreach (Data.DataLogicType LogicType in Enum.GetValues(typeof(Data.DataLogicType)))
                {
                    LogicTypeDictionary.Add(((int)LogicType).ToString(), new { Name = LogicType.ToString(), DisplayName = Data.DataLogicTypeConvertor.ToLogicTypeName(LogicType) });
                }
                model.LogicTypes = LogicTypeDictionary;
                #endregion

                #region 规则环境

                if (!string.IsNullOrWhiteSpace(RuleCode))
                {
                    OThinker.H3.BizBus.BizRule.BizRuleTable rule = this.Engine.BizBus.GetBizRule(RuleCode);
                    List <object> lstRuleElement = new List <object>();
                    if (rule != null)
                    {
                        if (rule.DataElements != null)
                        {
                            foreach (OThinker.H3.BizBus.BizRule.BizRuleDataElement RuleElement in rule.DataElements)
                            {
                                //词汇表
                                lstRuleElement.Add(new
                                {
                                    Name = RuleElement.ElementName,
                                    DisplayName = RuleElement.DisplayName,
                                    LogicType = RuleElement.LogicType
                                });
                            }
                        }
                    }

                    model.RuleElement = lstRuleElement;
                }

                #endregion

                #region 流程环境

                if (!string.IsNullOrEmpty(SchemaCode))
                {
                    ////系统数据
                    List <FormulaTreeNode> listSystemDatas = GetSystemDataItemNode("");

                    ////获取所有节点的文本集合,供智能感知
                    List <string> lstNodeStrings = new List <string>();
                    AddTreeString(listSystemDatas, lstNodeStrings);

                    model.InstanceVariables = lstNodeStrings;
                }

                #endregion

                #region 数据模型环境
                if (!string.IsNullOrEmpty(SchemaCode))
                {
                    DataModel.BizObjectSchema BizSchema = this.Engine.BizObjectManager.GetDraftSchema(SchemaCode);

                    if (BizSchema != null)
                    {
                        if (BizSchema != null && BizSchema.Properties != null)
                        {
                            List <object> lstDataItems = new List <object>();
                            foreach (DataModel.PropertySchema Property in BizSchema.Properties)
                            {
                                //不显示保留数据项
                                if (!DataModel.BizObjectSchema.IsReservedProperty(Property.Name))
                                {
                                    lstDataItems.Add(new
                                    {
                                        Name = Property.Name,
                                        DisplayName = Property.DisplayName,
                                        LogicType = Property.LogicType
                                    });
                                    ;
                                }
                            }

                            model.DataItems = lstDataItems;
                        }
                    }
                }

                #endregion

                return Json(model, JsonRequestBehavior.AllowGet);
            }));
        }
        /// <summary>
        /// 保存业务规则词汇
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public JsonResult Save(BizRuleGlossaryViewModel model)
        {
            Data.DataLogicType logicType    = (Data.DataLogicType)Enum.Parse(typeof(Data.DataLogicType), model.LogicType);
            string             defaultValue = string.IsNullOrEmpty(model.DefaultValue)?"":model.DefaultValue;
            bool IsCreate = string.IsNullOrEmpty(model.ObjectID);

            ActionResult result = ValidateData(logicType, model);

            if (!result.Success)
            {
                return(Json(result));
            }
            OThinker.H3.BizBus.BizRule.BizRuleDataElement Element;
            OThinker.H3.BizBus.BizRule.BizRuleTable       Rule = this.Engine.BizBus.GetBizRule(model.RuleCode);


            if (IsCreate)
            {
                // 数据项必须以字母开始,不让创建到数据库表字段时报错
                // System.Text.RegularExpressions.Regex regex = new System.Text.RegularExpressions.Regex("^[A-Za-z][A-Za-z0-9_]*$");
                System.Text.RegularExpressions.Regex regex = new System.Text.RegularExpressions.Regex("^[a-zA-Z\\u4e00-\\u9fa5][0-9a-zA-Z\\u4e00-\\u9fa5_]*$");
                if (!regex.Match(model.ElementName).Success)
                {
                    result.Success = false;
                    result.Message = "EditBizObjectSchemaProperty.Msg4";
                    return(Json(result));
                }

                //检测是否重名
                if (Rule.GetDataElement(model.ElementName) != null)
                {
                    result.Success = false;
                    result.Message = "msgGlobalString.CodeDuplicate";
                    return(Json(result));
                }

                Element              = new OThinker.H3.BizBus.BizRule.BizRuleDataElement();
                Element.ElementName  = model.ElementName;
                Element.DisplayName  = model.DisplayName;
                Element.Description  = model.Description;
                Element.LogicType    = logicType;
                Element.ParamType    = (H3.BizBus.BizRule.InOutType)Enum.Parse(typeof(H3.BizBus.BizRule.InOutType), model.ParamType);
                Element.DefaultValue = defaultValue;

                if (!Rule.AddDataElement(Element))
                {
                    result.Success = false;
                    result.Message = "msgGlobalString.SaveFailed";
                    return(Json(result));
                }
            }
            else
            {
                Element              = Rule.GetDataElement(model.ElementName);
                Element.DisplayName  = model.DisplayName;
                Element.Description  = model.Description;
                Element.LogicType    = logicType;
                Element.ParamType    = (H3.BizBus.BizRule.InOutType)Enum.Parse(typeof(H3.BizBus.BizRule.InOutType), model.ParamType);
                Element.DefaultValue = defaultValue;
            }

            if (!Engine.BizBus.UpdateBizRule(Rule))
            {
                //ShowWarningMessage(PortalResource.GetString("EditBizRuleTableDataElement_SaveFailed"));
                result.Success = false;
                result.Message = "msgGlobalString.SaveFailed";
                return(Json(result));
            }

            result.Success = true;
            result.Message = "msgGlobalString.SaveSucced";
            return(Json(result));
        }