Exemplo n.º 1
0
        /// <summary>
        /// 删除决策表行或列
        /// </summary>
        /// <param name="ruleCode"></param>
        /// <param name="matrixCode"></param>
        /// <param name="hasRightToDelete"></param>
        /// <param name="deleteType"></param>
        /// <param name="hasRightToDelete"></param>
        /// <param name="parentIndexes"></param>
        /// <param name="index"></param>
        /// <returns></returns>
        public JsonResult DeleteCell(string ruleCode, string matrixCode, bool hasRightToDelete, string deleteType, string parentIndexes, int index)
        {
            return(ExecuteFunctionRun(() =>
            {
                BizRuleTable Rule = Engine.BizBus.GetBizRule(ruleCode);
                BizRuleDecisionMatrix DecisionMatrix = Rule.GetDecisionMatrix(matrixCode);

                bool result = false;
                List <int> parentIndexs = GetPrentIndexes(parentIndexes);
                if (hasRightToDelete && !string.IsNullOrWhiteSpace(deleteType))
                {
                    if (deleteType == "Column")
                    {
                        DecisionMatrix.RemoveColumn(parentIndexs.ToArray <int>(), index);
                    }
                    else if (deleteType == "Row")
                    {
                        DecisionMatrix.RemoveRow(parentIndexs.ToArray(), index);
                    }
                    result = this.Engine.BizBus.UpdateBizRule(Rule);
                }

                return Json(result, JsonRequestBehavior.AllowGet);
            }));
        }
Exemplo n.º 2
0
        /// <summary>
        /// 加载行信息
        /// </summary>
        /// <param name="ruleCode"></param>
        /// <param name="matrixCode"></param>
        /// <param name="columnIndex"></param>
        /// <param name="parentIndexes"></param>
        /// <returns></returns>
        public JsonResult Load(string ruleCode, string matrixCode, int rowIndex, string parentIndexes)
        {
            return(ExecuteFunctionRun(() =>
            {
                ActionResult result = new ActionResult();
                BizRuleTable Rule = Engine.BizBus.GetBizRule(ruleCode);
                BizRuleDecisionMatrix DecisionMatrix = null;
                if (Rule != null)
                {
                    DecisionMatrix = Rule.GetDecisionMatrix(matrixCode);
                }

                Header Row = null;       // 当前行

                Header ParentRow = null; // 直接父级行
                List <int> ParentRowIndexes = GetPrentIndexes(parentIndexes);

                if (ParentRowIndexes.Count > 0)
                {//如果存在父节点,则逐步找到最后一个节点,也就是直接上级
                    foreach (int index in ParentRowIndexes)
                    {
                        if (ParentRow == null)
                        {
                            ParentRow = DecisionMatrix.Rows[index];
                        }
                        else
                        {
                            ParentRow = ParentRow.Children[index];
                        }
                    }
                }

                //如果存在当前行,则看有无直接上级
                if (ParentRow == null)
                {
                    Row = DecisionMatrix.Rows[rowIndex];
                }
                else
                {
                    Row = ParentRow.Children[rowIndex];
                }

                BizRuleDecisionMatrixItemViewModel model = new BizRuleDecisionMatrixItemViewModel();
                model.Index = rowIndex;
                if (Row != null)
                {
                    model.ObjectID = Row.GetHashCode().ToString();//做判断是否为新增使用,不为空表示为更新
                    model.DisplayName = Row.DisplayName;
                    model.Description = Row.Description;
                    model.EffectiveCondition = Row.Value;
                    model.IsDefault = Row.IsDefault;
                    model.SortKey = Row.SortKey;
                    model.RuleCode = ruleCode;
                    model.MatrixCode = matrixCode;
                }
                return Json(model, JsonRequestBehavior.AllowGet);
            }));
        }
Exemplo n.º 3
0
        /// <summary>
        /// 获取决策表列数据
        /// </summary>
        /// <param name="ruleCode"></param>
        /// <param name="matrixCode"></param>
        /// <returns></returns>
        public JsonResult GetColumnData(string ruleCode, string matrixCode)
        {
            return(ExecuteFunctionRun(() => {
                BizRuleTable Rule = Engine.BizBus.GetBizRule(ruleCode);
                BizRuleDecisionMatrix DecisionMatrix = Rule.GetDecisionMatrix(matrixCode);

                List <BizRuleDecisionMatrixItemViewModel> dataList = new List <BizRuleDecisionMatrixItemViewModel>();
                if (DecisionMatrix.Columns != null)
                {
                    dataList = GetMatrixData(DecisionMatrix.Columns);
                }
                var gridData = CreateLigerUIGridData(dataList.ToArray());

                return Json(gridData, JsonRequestBehavior.AllowGet);
            }));
        }
Exemplo n.º 4
0
 /// <summary>
 /// 决策表返回数据项
 /// </summary>
 /// <returns></returns>
 public JsonResult LoadResultFields(string ruleCode, string matrixCode)
 {
     return(ExecuteFunctionRun(() =>
     {
         List <OptionItem> list = new List <OptionItem>();
         BizRuleTable Rule = Engine.BizBus.GetBizRule(ruleCode);
         BizRuleDecisionMatrix DecisionMatrix = Rule.GetDecisionMatrix(matrixCode);
         // 保存结果的字段
         BizRuleDataElement[] dataElements = Rule.DataElements;
         if (dataElements != null)
         {
             bool isSelectiveOrSorted = false;
             if (DecisionMatrix != null)
             {
                 isSelectiveOrSorted = DecisionMatrix.MatrixType == DecisionMatrixType.SelectiveArray ||
                                       DecisionMatrix.MatrixType == DecisionMatrixType.SortedArray;
             }
             foreach (BizRuleDataElement dataElement in dataElements)
             {
                 // 选择和排序规则的返回值只允许选择参与者
                 if (isSelectiveOrSorted)
                 {
                     if (dataElement.LogicType == Data.DataLogicType.MultiParticipant ||
                         dataElement.LogicType == Data.DataLogicType.SingleParticipant)
                     {
                         list.Add(new OptionItem()
                         {
                             Text = dataElement.DisplayName2, Value = dataElement.ElementName
                         });
                     }
                 }
                 else
                 {
                     if (dataElement.RealType == typeof(string) || dataElement.RealType == typeof(string[]))
                     {
                         list.Add(new OptionItem()
                         {
                             Text = dataElement.DisplayName2, Value = dataElement.ElementName
                         });
                     }
                 }
             }
         }
         return Json(list, JsonRequestBehavior.AllowGet);
     }));
 }
Exemplo n.º 5
0
        /// <summary>
        /// 加载决策表信息
        /// </summary>
        /// <param name="ruleCode"></param>
        /// <param name="matrixCode"></param>
        /// <returns></returns>
        public JsonResult LoadDecisionMatrixInfo(string ruleCode, string matrixCode)
        {
            return(ExecuteFunctionRun(() =>
            {
                BizRuleTable Rule = Engine.BizBus.GetBizRule(ruleCode);
                BizRuleDecisionMatrix DecisionMatrix = Rule.GetDecisionMatrix(matrixCode);
                if (DecisionMatrix == null)
                {
                    return null;
                }

                BizRuleDecisionMatrixViewModel model = new BizRuleDecisionMatrixViewModel();
                model.ObjectID = DecisionMatrix.GetHashCode().ToString();//判断是否新增使用,可随便赋值
                model.Code = DecisionMatrix.Code;
                model.RuleCode = ruleCode;
                model.RowExecutionType = DecisionMatrix.RowExecutionType.ToString();
                model.ColumnExecutionType = DecisionMatrix.ColumnExecutionType.ToString();
                model.DisplayName = DecisionMatrix.DisplayName;
                model.Description = DecisionMatrix.Description;
                model.DecisionMatrixType = DecisionMatrix.MatrixType.ToString();
                model.Scope = DecisionMatrix.DecisionMatrixScope.ToString();
                switch (DecisionMatrix.MatrixType)
                {
                case DecisionMatrixType.Script:
                    model.ResultField = "";
                    break;

                case DecisionMatrixType.SelectiveArray:

                    model.ResultField = ((SelectiveArrayDecisionMatrix)DecisionMatrix).ResultElementData;
                    break;

                case DecisionMatrixType.SortedArray:

                    model.ResultField = ((SortedArrayDecisionMatrix)DecisionMatrix).ResultElementData;
                    break;

                default:
                    throw new NotImplementedException();
                }

                return Json(model, JsonRequestBehavior.AllowGet);
            }));
        }
Exemplo n.º 6
0
        /// <summary>
        /// 移除决策表
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public JsonResult RemoveDecisionMatrix(string ruleCode, string matrixCode)
        {
            return(ExecuteFunctionRun(() =>
            {
                BizRuleTable Rule = Engine.BizBus.GetBizRule(ruleCode);
                BizRuleDecisionMatrix DecisionMatrix = Rule.GetDecisionMatrix(matrixCode);

                ActionResult result = new ActionResult(false, "msgGlobalString.DeleteFailed");
                if (!Rule.RemoveDecisionMatrix(DecisionMatrix.Code))
                {
                    return Json(result);
                }
                string code = Rule.Code;
                if (!Engine.BizBus.UpdateBizRule(Rule))
                {
                    //删除失败
                    return Json(result);
                }

                result.Success = true;
                result.Message = "msgGlobalString.DeleteSucced";
                return Json(result);
            }));
        }
Exemplo n.º 7
0
        /// <summary>
        /// 更新决策表
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public JsonResult EditDecisionMatrix(BizRuleDecisionMatrixViewModel model)
        {
            return(ExecuteFunctionRun(() =>
            {
                ActionResult result = new ActionResult(false, "");

                BizRuleTable Rule = Engine.BizBus.GetBizRule(model.RuleCode);//业务规则


                if (string.IsNullOrEmpty(model.Code))
                {
                    result.Message = "msgGlobalString.InvalidCode";
                    return Json(result);
                }

                BizRuleDecisionMatrix matrix = Rule.GetDecisionMatrix(model.Code);//决策表

                //决策表名称不能含有特殊字符
                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.DisplayName).Success)
                {
                    result.Success = false;
                    result.Message = "msgGlobalString.NameInValid";
                    return Json(result);
                }

                matrix.DisplayName = model.DisplayName;
                matrix.Description = model.Description;
                //matrix.MatrixType = (DecisionMatrixType)Enum.Parse(typeof(DecisionMatrixType), model.DecisionMatrixType);

                matrix.RowExecutionType = (ExecutionType)Enum.Parse(typeof(ExecutionType), model.RowExecutionType);
                matrix.ColumnExecutionType = (ExecutionType)Enum.Parse(typeof(ExecutionType), model.ColumnExecutionType);
                matrix.DecisionMatrixScope = (DecisionMatrixScope)Enum.Parse(typeof(DecisionMatrixScope), model.Scope);
                // 保存结果的字段
                switch (matrix.MatrixType)
                {
                case DecisionMatrixType.Script:
                    break;

                case DecisionMatrixType.SelectiveArray:
                    ((SelectiveArrayDecisionMatrix)matrix).ResultElementData = model.ResultField;
                    break;

                case DecisionMatrixType.SortedArray:
                    ((SortedArrayDecisionMatrix)matrix).ResultElementData = model.ResultField;
                    break;

                default:
                    throw new NotImplementedException();
                }

                bool flag = this.Engine.BizBus.UpdateBizRule(Rule);
                if (flag)
                {
                    result.Success = true;
                    result.Message = "msgGlobalString.SaveSucced";
                }
                else
                {
                    result.Success = false;
                    result.Message = "msgGlobalString.SaveFailed";
                }
                return Json(result);
            }));
        }
Exemplo n.º 8
0
        /// <summary>
        /// 保存决策表列信息
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public JsonResult Save(BizRuleDecisionMatrixItemViewModel model)
        {
            return(ExecuteFunctionRun(() =>
            {
                ActionResult result = new ActionResult();
                //校验数据

                result = ValidateData(model);

                bool IsCreate = string.IsNullOrEmpty(model.ObjectID);
                BizRuleTable Rule = Engine.BizBus.GetBizRule(model.RuleCode);
                if (Rule == null)
                {
                    //业务对象模式不存在,或者已经被删除
                    result.Success = false;
                    result.Message = "BizRule.DeletedOrNotExists";
                    return Json(result);
                }

                BizRuleDecisionMatrix DecisionMatrix = Rule.GetDecisionMatrix(model.MatrixCode);
                if (DecisionMatrix == null)
                {
                    //业务对象模式不存在,或者已经被删除
                    result.Success = false;
                    result.Message = "BizRule.DeletedOrNotExists";
                    return Json(result);
                }

                if (!result.Success)
                {
                    return Json(result);
                }
                if (string.IsNullOrEmpty(model.EffectiveCondition) && !model.IsDefault)
                {
                    // this.ShowWarningMessage(this.PortalResource.GetString("EditBizRuleTableColumn_Mssg1"));
                    result.Success = false;
                    result.Message = "BizRule.SelectDefault";
                    return Json(result);
                }
                if (IsCreate)
                {
                    OThinker.H3.BizBus.BizRule.Header column = new H3.BizBus.BizRule.Header();
                    column.DisplayName = model.DisplayName;
                    column.Description = model.Description;
                    column.Value = model.EffectiveCondition;
                    column.IsDefault = model.IsDefault;
                    column.SortKey = model.SortKey;
                    DecisionMatrix.AddColumn(GetPrentIndexes(model.ParentStrIndexs).ToArray(), column);
                }
                else
                {
                    Header Column = null;       // 当前列

                    Header ParentColumn = null; // 直接父级列
                    List <int> ParentColumnIndexes = GetPrentIndexes(model.ParentStrIndexs);

                    if (ParentColumnIndexes.Count > 0)
                    {//如果存在父节点,则逐步找到最后一个节点,也就是直接上级
                        foreach (int index in ParentColumnIndexes)
                        {
                            if (ParentColumn == null)
                            {
                                ParentColumn = DecisionMatrix.Columns[index];
                            }
                            else
                            {
                                ParentColumn = ParentColumn.Children[index];
                            }
                        }
                    }

                    if (model.Index > -1)
                    {
                        //如果存在当前列,则看有无直接上级
                        if (ParentColumn == null)
                        {
                            Column = DecisionMatrix.Columns[model.Index];
                        }
                        else
                        {
                            Column = ParentColumn.Children[model.Index];
                        }
                    }

                    Column.DisplayName = model.DisplayName;
                    Column.Value = model.EffectiveCondition;
                    Column.Description = model.Description;
                    Column.IsDefault = model.IsDefault;
                    Column.SortKey = model.SortKey;

                    //DecisionMatrix.Resort();
                }
                if (this.Engine.BizBus.UpdateBizRule(Rule))
                {
                    result.Success = true;
                    result.Message = "msgGlobalString.SaveSucced";
                }
                else
                {
                    //this.ShowWarningMessage(this.PortalResource.GetString("EditBizRuleTableColumn_SaveFailed"));
                    result.Success = false;
                    result.Message = "msgGlobalString.SaveFailed";
                }

                return Json(result, JsonRequestBehavior.AllowGet);
            }));
        }