示例#1
0
        /// <summary>
        /// Get all by condition
        /// </summary>
        /// <param name="keyword"></param>
        /// <param name="parentId"></param>
        /// <param name="isPanel"></param>
        /// <param name="group"></param>
        /// <param name="status"></param>
        /// <param name="userId"></param>
        /// <param name="isDeleted"></param>
        /// <param name="order"></param>
        /// <param name="limit"></param>
        /// <returns></returns>
        public static List <MenuModel> GetAll(string keyword, int?parentId, bool?isPanel, MenuGroup?group, MenuStatus?status, int?userId,
                                              bool?isDeleted, string order, int?limit)
        {
            // init condition
            var condition = "1=1";

            // keyword
            if (!string.IsNullOrEmpty(keyword))
            {
                condition += " AND ([MenuName] LIKE N'%{0}%' OR [TabName] LIKE N'%{0}%')".FormatWith(keyword.EscapeQuote());
            }

            // parent id
            if (parentId != null)
            {
                condition += " AND [ParentId]={0}".FormatWith(parentId.Value);
            }

            // is panel
            if (isPanel != null)
            {
                condition += " AND [IsPanel]={0}".FormatWith(isPanel.Value ? 1 : 0);
            }

            // group
            if (group != null)
            {
                condition += " AND [Group]={0}".FormatWith((int)group.Value);
            }

            // status
            if (status != null)
            {
                condition += " AND [Status]={0}".FormatWith((int)status.Value);
            }

            // userId
            if (userId != null)
            {
                condition += @" AND [Id] IN (" +
                             "      SELECT [MenuId] FROM [MenuRole] WHERE [RoleId] IN (" +
                             "          SELECT [RoleId] FROM [UserRole] WHERE [UserId]='{0}'))".FormatWith(userId.Value);
            }

            // deleted
            if (isDeleted != null)
            {
                condition += " AND [IsDeleted]={0}".FormatWith(isDeleted.Value ? 1 : 0);
            }

            // order
            if (string.IsNullOrEmpty(order))
            {
                order = @"[Order]";
            }

            // return
            return(MenuServices.GetAll(condition, order, limit).Select(e => new MenuModel(e)).ToList());
        }
示例#2
0
        /// <summary>
        /// Load root menu
        /// </summary>
        private void LoadMenu()
        {
            var rootMenus = MenuServices.GetAll(0, false, null, null, null, null);

            foreach (var menu in rootMenus)
            {
                ltrMenuTree.Text +=
                    "<li id='{0}'><div class='menuItemName'>{1}</div><div class='menuItemPermission'>| {2}</div>{3}</li>"
                    .FormatWith(
                        menu.Id, menu.MenuName, LoadMenuPermission(menu), LoadChildMenu(menu.Id));
            }
        }
示例#3
0
        /// <summary>
        /// Load child menu
        /// </summary>
        /// <param name="parentId"></param>
        /// <returns></returns>
        private string LoadChildMenu(int parentId)
        {
            var childMenus = MenuServices.GetAll(parentId, false, null, null, null, null);

            if (childMenus.Count == 0)
            {
                return(string.Empty);
            }

            var strChildMenu = string.Empty;

            foreach (var menu in childMenus)
            {
                strChildMenu +=
                    "<li id='{0}'><div class='menuItemName'>{1}</div><div class='menuItemPermission'>| {2}</div>{3}</li>"
                    .FormatWith(menu.Id, menu.MenuName, LoadMenuPermission(menu), LoadChildMenu(menu.Id));
            }

            return("<ul>{0}</ul>".FormatWith(strChildMenu));
        }