Exemplo n.º 1
0
        /// <summary>
        /// 从数据库生成操作菜单树。
        /// </summary>
        /// <returns></returns>
        protected static ActionDomainModel GetActionDomainModelFromDatabase()
        {
            ActionDomainModel tree = new ActionDomainModel();

            SetChildActionList(tree, "0", GetActionTableFromDatabase(), null);

            return(tree);
        }
Exemplo n.º 2
0
        public static ActionDomainModel GetMenuTreeByRoleId(string roleId)
        {
            ActionDomainModel tree = new ActionDomainModel();

            SetChildActionList(tree, "0", InitRolePermissions(false), roleId);

            return(tree);
        }
Exemplo n.º 3
0
        public void GetActionTableFromDatabaseTest()
        {
            PermissionService target   = new PermissionService(); // TODO: 初始化为适当的值
            ActionDomainModel expected = null;                    // TODO: 初始化为适当的值
            ActionDomainModel actual;

            actual = null; // target.GetActionTableFromDatabase();
            Assert.AreEqual(expected, actual);
            Assert.Inconclusive("验证此测试方法的正确性。");
        }
Exemplo n.º 4
0
        /// <summary>
        /// 设置操作菜单树。
        /// </summary>
        /// <param name="srcAction"></param>
        /// <param name="parentNode"></param>
        /// <param name="actionTable"></param>
        protected static void SetChildActionList(ActionDomainModel srcAction, string parentNode, DataTable actionTable, string roleId)
        {
            if (actionTable == null)
            {
                return;
            }

            string filterSQL   = null;
            string getGroupSQL = null;

            if (roleId != null)
            {
                filterSQL   = string.Format("ParentNode = '{0}' AND ActionType = 0 AND RoleId = '{1}'", parentNode, roleId);
                getGroupSQL = "ActionGroup = '{0}' AND ActionType = 1 AND RoleId = '" + roleId + "'";
            }
            else
            {
                filterSQL   = string.Format("ParentNode = '{0}' AND ActionType = 0", parentNode);
                getGroupSQL = "ActionGroup = '{0}' AND ActionType = 1";
            }

            DataRow[] hasRows   = actionTable.Select(filterSQL, "SortOrder ASC");
            DataRow[] groupRows = null;


            if (hasRows != null && hasRows.Length > 0)
            {
                srcAction.ChildActionList = new Dictionary <string, ActionDomainModel>();
                ActionDomainModel model     = null;
                ActionDomainModel groupItem = null;

                for (int i = 0; i < hasRows.Length; i++)
                {
                    model = GetActionDomainModelFromDataRow(hasRows[i]);
                    model.ActionGroupList = new Dictionary <string, ActionDomainModel>();
                    model.ActionGroupList.Add(model.ActionId, model);

                    groupRows = actionTable.Select(string.Format(getGroupSQL, model.ActionGroup));
                    if (groupRows != null && groupRows.Length > 0)
                    {
                        for (int j = 0; j < groupRows.Length; j++)
                        {
                            groupItem = GetActionDomainModelFromDataRow(groupRows[j]);
                            model.ActionGroupList.Add(groupItem.ActionId, groupItem);
                        }
                    }

                    SetChildActionList(model, model.NodeId, actionTable, roleId);

                    srcAction.ChildActionList.Add(model.ActionId, model);
                }
            }
        }
Exemplo n.º 5
0
        /// <summary>
        /// 根据数据行生成操作领域模型。
        /// </summary>
        /// <param name="row"></param>
        /// <returns></returns>
        protected static ActionDomainModel GetActionDomainModelFromDataRow(DataRow row)
        {
            ActionDomainModel model = new ActionDomainModel();

            model.ActionId       = row["ActionId"].ToString();
            model.NodeId         = row["NodeId"].ToString();
            model.ParentNode     = row["ParentNode"].ToString();
            model.ActionType     = Convert.ToInt32(row["ActionType"]);
            model.ActionName     = row["ActionName"].ToString();
            model.ActionGroup    = row["ActionGroup"].ToString();
            model.ControllerName = row["ControllerName"].ToString();
            model.DisplayName    = row["DisplayName"].ToString();
            model.SortOrder      = Convert.ToInt32(row["SortOrder"]);

            return(model);
        }
Exemplo n.º 6
0
        /// <summary>
        /// 获取完整菜单树。
        /// </summary>
        /// <param name="clear"></param>
        /// <returns></returns>
        public static ActionDomainModel GetMenuTree(bool clear)
        {
            string cacheKey = CacheKey.ACTION_TREE;

            ActionDomainModel tree = CacheUtil.Get <ActionDomainModel>(cacheKey);

            if (tree == null || clear)
            {
                tree = GetActionDomainModelFromDatabase();
                if (tree != null && tree.ChildActionList != null)
                {
                    CacheUtil.Set(cacheKey, tree);
                }
                else
                {
                    CacheUtil.Remove(cacheKey);
                }
            }

            return(tree);
        }
Exemplo n.º 7
0
        /// <summary>
        /// 获取指定操作的上级操作信息领域模型。
        /// </summary>
        /// <param name="actionId"></param>
        /// <param name="actionTable"></param>
        /// <param name="srcList"></param>
        public static void GetActionParentActionList(string actionId, string parentNode, DataTable actionTable, List <ActionDomainModel> srcList)
        {
            string filterSQL = (parentNode == null)
                ? string.Format("ActionId = '{0}' AND ActionType = 0", actionId)
                : string.Format("NodeId = '{0}' AND ActionType = 0 ", parentNode);

            DataRow[] hasRows = actionTable.Select(filterSQL);

            if (hasRows != null && hasRows.Length == 1)
            {
                ActionDomainModel currAction = GetActionDomainModelFromDataRow(hasRows[0]);
                if (srcList.Contains(currAction) == false)
                {
                    srcList.Add(currAction);
                }

                if (currAction.ParentNode != "0")
                {
                    GetActionParentActionList(currAction.ActionId, currAction.ParentNode, actionTable, srcList);
                }
            }
        }