EasyUI--权限管理(三)显示tab页上的按钮

效果图:

EasyUI--权限管理(三)显示tab页上的按钮

页面代码:

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="BuyBill.aspx.cs" Inherits="EasyUIWeb.Pages.BuyBill" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title></title> 
    <link href="../Script/jquery-easyui-1.7.0/themes/default/easyui.css" rel="stylesheet" />
    <link href="../css/wu.css" rel="stylesheet" />
    <link href="../css/icon.css" rel="stylesheet" /> 
    <script src="../Script/jquery-easyui-1.7.0/jquery.min.js"></script>
    <script src="../Script/jquery-easyui-1.7.0/jquery.easyui.min.js"></script> 
    <script src="../Script/jquery-easyui-1.7.0/locale/easyui-lang-zh_CN.js"></script>
    <script src="../Script/Public/valid-zh.js"></script>
    <script src="../Script/Public/Common.js"></script>

    <script type="text/javascript">
        $(function () {
            var userName = sessionStorage.getItem("userName"); 
            if (userName == null || userName == "") {
                window.top.location.href = "../Login.aspx";
            }

            var userId = sessionStorage.getItem("userID");
            var menuCode = sessionStorage.getItem("menuCode");

            $.ajax({
                type: 'post', 
                dataType: "json",
                url: "/Handlers/ButtonHandler.ashx?action=LoadButton&userId=" + userId + "&menuCode=buy ",
                success: function (data) {
                    $.each(data, function (i, n) {
                        $("#toolbar").append("<a class='easyui-linkbutton' id='btn" + n.menuCode + "' href='#' plain='true' iconcls='" + n.btnIcon + "'>" + n.btnName + "</a>");
                         $.parser.parse();   //渲染页面
                    })
                }
            })
        })
    </script>
</head>
<body>
    <h1>采购入库单</h1>
    <div id="toolbar"> 
    </div>
</body>
</html>

 

ButtonHandler.ashx、DAL、BLL代码

EasyUI--权限管理(三)显示tab页上的按钮
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Common.Web;
using Model;
using BLL;
using Newtonsoft.Json;

namespace EasyUIWeb.Handlers
{
    /// <summary>
    /// ButtonHandler 的摘要说明
    /// </summary>
    public class ButtonHandler : IHttpHandler
    {

        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
            var action = Request.GetQueryString("Action");
            try
            {
                switch (action)
                {
                    case "LoadButton":
                        this.LoadButton(context);
                        break;

                    default:

                        break;
                };
            }
            catch (Exception ex)
            {
                Response.OutResult(context, new MsgResult() { Success = false, Message = ex.ToString() });
            }
        }

        public void LoadButton(HttpContext context)
        {
            int userId = Request.GetQueryInt("userId", 0);
            string menuCode = Request.GetQueryString("menuCode");

            List<Model_tb_button> btnList = new BLL_Button().GetButtonByMenuAndUserID(userId, menuCode);

            string jsonStr = JsonConvert.SerializeObject(btnList);

            Response.WriteJson(context, jsonStr);
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}








using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using Common;
using DAL;
using Model;

namespace BLL
{
    public class BLL_Button
    {
        private readonly DAL_Button dal = new DAL_Button();
        /// <summary>
        /// 根据菜单名称和用户id查询菜单上应该显示的按钮
        /// </summary>
        /// <param name="userId"></param>
        /// <returns></returns>
        public List<Model_tb_button> GetButtonByMenuAndUserID(int userId, string menuCode)
        {
            DataSet ds = this.dal.GetButtonByMenuAndUserID(userId, menuCode);
            return ModelHandler<Model_tb_button>.FillModel(ds.Tables[0]);
        }
    }
}







using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using DBUtility;
using Model;

namespace DAL
{
    public class DAL_Button
    {
        /// <summary>
        /// 根据菜单名称和用户id查询菜单上应该显示的按钮
        /// </summary>
        /// <param name="userId"></param>
        /// <param name="menuCode"></param>
        /// <returns></returns>
        public DataSet GetButtonByMenuAndUserID(int userId, string menuCode)
        {
            string sql = @"SELECT b.* FROM dbo.tb_users u
                                        INNER JOIN dbo.tb_users_role ur ON u.userId = ur.userId
                                        INNER JOIN dbo.tb_role_menu_button rmb ON ur.roleId = rmb.roleId 
                                        INNER JOIN dbo.tb_button b ON rmb.btnId = b.btnId 
                                        INNER JOIN dbo.tb_menu m ON rmb.menuId = m.menuId
                                        WHERE u.userId="+userId+" AND m.menuCode='"+menuCode+"' ";

            return DbHelperSQL.Query(sql);
        }
    }
}
View Code

 

上一篇:雷林鹏分享jQuery EasyUI 布局 - 动态添加标签页(Tabs)


下一篇:jQuery EasyUI/TopJUI创建文本验证框(不写js,纯HTML实现!!!)