zoukankan      html  css  js  c++  java
  • PCB决策引擎:多维决策表转决策树

    准备设计一个PCB使用的决策引擎,需要用到决策表,而单维决策表不能满足业务要求,

    这里主要是为了实现:用户编辑的是决策表,实际底层存储的是树结构,树的的各个节点挂上业务决策逻辑.

    这里将多维决策表转决策树构思整理如下:

     一.决策表(多维表头结构UI编辑界面)

            用户可编辑的规则界面,规则决策表交由用户配制,可实现任意多表头结构的决策表。

    二.决策树(TreeNode 简易界面)

        TreeNode 是从决策表中转换过来的,可以实现节点决策控制,后续转换TreeNodeVIew用户可以附加属性编辑

                       左表头                                                                    上表头

    三.DB数据库存储结构

                   多表头结构:

                  

                 交叉行列号存储值表:

                 

    四.决策表转决策树 C#程序实现代码:

        /// <summary>
            /// 采用TreeNode做为树根结点做为起始点递归实现
            /// </summary>
            /// <param name="TreeNode_"></param>
            private void ExcelHeadToTreeNodes(TreeNode TreeNode_)
            {
                T_RuleTableRowColumnMultiExpression ModTableCell_ = (T_RuleTableRowColumnMultiExpression)TreeNode_.Tag;
                if (ModTableCell_ == null)
                    return;
    
                int StartColumnIndex = 0;
                int EndColumnIndex = 0;
                int ColumnCount = 0;
                int StartRowIndex = 0;
                if (ModTableCell_.DimensionNum == 1) //维度1  列
                {
                    ColumnCount = ModTableCell_.EndColumnIndex - ModTableCell_.StartColumnIndex + 1;
                    if (ColumnCount == 1) return;
                    StartColumnIndex = ModTableCell_.StartColumnIndex;
                    EndColumnIndex = ModTableCell_.EndColumnIndex;
                    StartRowIndex = ModTableCell_.StartRowIndex + 1;
                }
                else if (ModTableCell_.DimensionNum == 2)//维度1  行
                {
                    ColumnCount = ModTableCell_.EndRowIndex - ModTableCell_.StartRowIndex + 1;
                    if (ColumnCount == 1) return;
                    StartColumnIndex = ModTableCell_.StartRowIndex;
                    EndColumnIndex = ModTableCell_.EndRowIndex;
                    StartRowIndex = ModTableCell_.StartColumnIndex + 1;
                }
                else
                {
                    return;
                }
                int LayerIndexCurrent = ModTableCell_.LayerIndex + 1;
                int i = 1; //层次
                while (StartColumnIndex <= EndColumnIndex)
                {
                    Excel.Range cell;
                    int StartRowIndex_ = 0, StartColumnIndex_ = 0, EndRowIndex_ = 0, EndColumnIndex_ = 0, ColumnCount_ = 0;
                    string CellStringID_ = "", CellVal_ = "";
                    if (ModTableCell_.DimensionNum == 1) //维度1  列头
                    {
                        cell = ((Excel.Range)_WorkSheet.Cells[StartRowIndex, StartColumnIndex]);
                        var CellMergeArea = cell.MergeArea;
                        var CellRowsCount = CellMergeArea.Rows.Count;
                        var CellColumnsCount = CellMergeArea.Columns.Count;
                        CellVal_ = cell.Text.ToString();
                        StartRowIndex_ = ModTableCell_.EndRowIndex + 1;
                        StartColumnIndex_ = StartColumnIndex;
                        EndRowIndex_ = StartRowIndex_ + (CellRowsCount - 1);
                        EndColumnIndex_ = StartColumnIndex_ + (CellColumnsCount - 1);
                        ColumnCount_ = CellColumnsCount;
                        CellStringID_ = Convert.ToChar(StartColumnIndex_ + 64).ToString() + ((StartColumnIndex_ == EndColumnIndex_) ? "" : "_" + Convert.ToChar(EndColumnIndex_ + 64).ToString());
    
                    }
                    else if (ModTableCell_.DimensionNum == 2) //维度2  行头
                    {
                        cell = ((Excel.Range)_WorkSheet.Cells[StartColumnIndex, StartRowIndex]);
                        var CellMergeArea = cell.MergeArea;
                        var CellRowsCount = CellMergeArea.Rows.Count;
                        var CellColumnsCount = CellMergeArea.Columns.Count;
                        CellVal_ = cell.Text.ToString();
                        StartRowIndex_ = StartColumnIndex;
                        StartColumnIndex_ = ModTableCell_.EndColumnIndex + 1;
                        EndRowIndex_ = StartRowIndex_ + (CellRowsCount - 1);
                        EndColumnIndex_ = StartColumnIndex_ + (CellColumnsCount - 1);
                        ColumnCount_ = CellRowsCount;
                        CellStringID_ = StartRowIndex_.ToString() + ((StartRowIndex_ == EndRowIndex_) ? "" : "_" + EndRowIndex_.ToString());
                    }
    
                    T_RuleTableRowColumnMultiExpression ModTableCell_new = new T_RuleTableRowColumnMultiExpression();
                    ModTableCell_new.LayerIndex = LayerIndexCurrent;
                    ModTableCell_new.StartRowIndex = StartRowIndex_;
                    ModTableCell_new.StartColumnIndex = StartColumnIndex_;
                    ModTableCell_new.EndRowIndex = EndRowIndex_;
                    ModTableCell_new.EndColumnIndex = EndColumnIndex_;
                    ModTableCell_new.LayerOrder = i;
                    ModTableCell_new.CellStringID = CellStringID_;
                    ModTableCell_new.ParentCellStringID = ModTableCell_.CellStringID;
                    ModTableCell_new.DimensionNum = ModTableCell_.DimensionNum;
                    ModTableCell_new.TableNo = ModTableCell_.TableNo;
                    ModTableCell_new.Text = CellVal_;
                    ModTableCell_new.Value = CellVal_;
                    ModTableCell_new.Remark = CellVal_;
                    ModTableCell_new.Expression = CellVal_;
                    ModTableCell_new.DisplayName = CellVal_ + "________" + ModTableCell_new.CellStringID;
                    ModTableCell_new.AllOrder = ModTableCell_.AllOrder + 1;
                    TreeNode TreeNodeNew_ = new TreeNode(ModTableCell_new.DisplayName);
                    TreeNodeNew_.Tag = ModTableCell_new;
                    TreeNode_.Nodes.Add(TreeNodeNew_);
    
                    ExcelHeadToTreeNodes(TreeNodeNew_);
    
                    StartColumnIndex = StartColumnIndex + (ColumnCount_ - 1) + 1;
    
                    i++;
                }
    
            }
        /// <summary>
        /// 多维二维表结构
        /// </summary>
        public class T_RuleTableRowColumnMultiExpression
        {
            /// <summary>
            /// 规则表名ID
            /// </summary>
            public int TableNo { get; set; }
            /// <summary>
            /// 维度
            /// </summary>
            public int DimensionNum { get; set; }
            /// <summary>
            /// 层次深度
            /// </summary>
            public int LayerIndex { get; set; }
           /// <summary>
           /// 层次排序号
           /// </summary>
            public int LayerOrder { get; set; }
            /// <summary>
            /// 节点单元格值ID
            /// </summary>
            public string CellStringID { get; set; }
            /// <summary>
            /// 父节点单元格值ID
            /// </summary>
            public string ParentCellStringID { get; set; }
            /// <summary>
            /// 节点:显示名
            /// </summary>
            public string DisplayName { get; set; }
            /// <summary>
            /// 节点:表达式
            /// </summary>
            public string Expression { get; set; }
            /// <summary>
            /// 节点:文本内容
            /// </summary>
            public string Text { get; set; }
            /// <summary>
            /// 节点:值
            /// </summary>
            public string Value { get; set; }
            /// <summary>
            /// 节点:备注
            /// </summary>
            public string Remark { get; set; }
            /// <summary>
            /// 开始行号
            /// </summary>
            public int StartRowIndex { get; set; }
            /// <summary>
            /// 开始列号
            /// </summary>
            public int StartColumnIndex { get; set; }
            /// <summary>
            /// 终止行号
            /// </summary>
            public int EndRowIndex { get; set; }
            /// <summary>
            /// 终止列号
            /// </summary>
            public int EndColumnIndex { get; set; }
            /// <summary>
            /// 总排序
            /// </summary>
            public int AllOrder { get; set; }
        }
  • 相关阅读:
    Visio使用遇到的问题
    UML类图符号 各种关系说明以及举例
    测试人员与开发人员之间的关系如何?
    linux命令学习-复制(cp,scp)
    linux服务器报Too many open files的解决方法
    QTP学习一添加默认的注释及调用外部vbs文件
    关于JAVA应用中文字体显示小方框的问题解决
    web测试方法总结
    linux命令学习-su
    Oracle定义varchar2()类型存储汉字的长度问题
  • 原文地址:https://www.cnblogs.com/pcbren/p/9227032.html
Copyright © 2011-2022 走看看