SQL Server配置用户权限

1.功能视图(调用数据库的数据来配置权限)

在这里插入图片描述

2.数据库在这里插入图片描述

在这里插入图片描述

3.控制器

/// <summary>
        /// 查询未配置的权限
        /// </summary>
        /// <param name="ManagerID"></param>
        /// <returns></returns>
        public ActionResult SelectMarketingCaseByID(int ManagerID)
        {

            //查询出所有的营销案例
            var listCase = (from tbManager in myModels.S_Manager
                            这张表(S_Manager)下的任意外键
                            join tbBasicType in myModels.P_UpManager on tbManager.UpManagerID equals tbBasicType.UpManagerID  
                            where tbBasicType.UpManagerID == 2
                            select new ManagerVO
                            {
                                ManagerID = tbManager.ManagerID,
                                Jurisdiction = tbManager.Jurisdiction                  
                            }).ToList();
            //查询出配置的营销案例
            var listMark = (from tbManager in myModels.S_Manager       
                            join tbBasicType in myModels.P_UpManager on tbManager.UpManagerID equals tbBasicType.UpManagerID
                                                join tbPlanCase in myModels.P_PlanCase on tbManager.ManagerID equals tbPlanCase.ManagerID
                            where tbPlanCase.ManagerID == ManagerID
                            select new ManagerVO
                            {
                                ManagerID = tbPlanCase.ManagerDeplaID,
                                Jurisdiction = tbManager.Jurisdiction
                            }).ToList();
            List<ManagerVO> lisCase = new List<ManagerVO>();
            //遍历所有数据,查询出不相同的数据
            if (listCase.Count() > 0)
            {
                for (int i = 0; i < listCase.Count(); i++)
                {
                    if (listMark.Count() > 0)
                    {
                        for (int x = 0; x < listMark.Count(); x++)
                        {
                            if (listCase[i].ManagerID != listMark[x].ManagerID)
                            {
                                lisCase.Add(listCase[i]);
                            }
                        }
                    }
                    else
                    {
                        lisCase.Add(listCase[i]);
                    }

                }
                //去重复
                lisCase = lisCase.Distinct().ToList();

                if (listMark.Count() > 0)
                {
                    for (int x = 0; x < listMark.Count(); x++)
                    {
                        for (int i = 0; i < lisCase.Count(); i++)
                        {
                            if (lisCase[i].ManagerID == listMark[x].ManagerID)
                            {
                                lisCase.Remove(lisCase[i]);
                            }
                        }
                    }
                }
            }

            return Json(lisCase, JsonRequestBehavior.AllowGet);

        }

        /// <summary>
        /// 查询已配置的权限
        /// </summary>
        /// <param name="ManagerID"></param>
        /// <returns></returns>
        public ActionResult SelectMarketingSchemeByID(int ManagerID)
        {
            //查询出所有的营销案例
            var listCase = (from tbManager in myModels.S_Manager
                            select new ManagerVO
                            {
                                ManagerID = tbManager.ManagerID,
                                Jurisdiction = tbManager.Jurisdiction
                            }).ToList();
            //查询出配置的营销案例
            var listMark = (from tbManager in myModels.S_Manager
                            join tbPlanCase in myModels.P_PlanCase on tbManager.ManagerID equals tbPlanCase.ManagerID
                            where tbPlanCase.ManagerID == ManagerID
                            select new ManagerVO
                            {
                                ManagerID = tbPlanCase.ManagerDeplaID,
                                Jurisdiction = tbManager.Jurisdiction
                            }).ToList();
            if (listMark.Count() > 0)
            {
                for (int i = 0; i < listCase.Count(); i++)
                {
                    for (int x = 0; x < listMark.Count(); x++)
                    {
                        if (listCase[i].ManagerID == listMark[x].ManagerID)
                        {
                            listMark[x].Jurisdiction = listCase[i].Jurisdiction;
                        }
                    }
                }
            }

            return Json(listMark, JsonRequestBehavior.AllowGet);
        }

        /// <summary>
        /// 添加权限
        /// </summary>
        /// <param name="ID"></param>
        /// <param name="ManageID"></param>
        /// <returns></returns>
        public ActionResult AddCase(int ID, int ManageID)
        {
            string strMsg = "添加失败!";
            //实例化
            P_PlanCase planCase = new P_PlanCase();
            planCase.ManagerID = ManageID;
            planCase.ManagerDeplaID = ID;
            myModels.P_PlanCase.Add(planCase);
            if (myModels.SaveChanges() > 0)
            {
                strMsg = "success";
            }
            return Json(strMsg, JsonRequestBehavior.AllowGet);
        }

        /// <summary>
        /// 删除权限
        /// </summary>
        /// <param name="ID"></param>
        /// <param name="ManageID"></param>
        /// <returns></returns>
        public ActionResult RemoveCase(int ID, int ManageID)
        {
            string strMsg = "删除失败!";
            var list = (from tbPlanCase in myModels.P_PlanCase
                        where tbPlanCase.ManagerDeplaID == ID && tbPlanCase.ManagerID == ManageID
                        select tbPlanCase).Single();
            myModels.P_PlanCase.Remove(list);
            if (myModels.SaveChanges() > 0)
            {
                strMsg = "success";
            }
            return Json(strMsg, JsonRequestBehavior.AllowGet);
        }

4.视图

@*权限配置模态框*@
    <div class="row">
        <div class="modal bs-example-modal-sm" id="modUpdeteInfor">
            <div class="modal-dialog">
                <div class="modal-content">
                    <div class="modal-header alert-success">
                        <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>
                        <h4 class="modal-title"><span class="glyphicon glyphicon-th-list "></span>权限配置</h4>
                    </div>
                    <div class="modal-body">
                        <form id="formWork" method="post" action="UpdeteWork" class="form-horizontal" role="form">
                           <input type="hidden" id="ManagerID" name="ManagerID" />
                            <input type="hidden" id="ID" name="ID" />
                             <div class="form-group">
                                <div class="col-lg-12 col-md-12 col-sm-12 text-right" style="margin-top:10px;">
                                    <div class="col-lg-2 col-md-2 col-sm-2">
                                        <label>选择下级配置权限</label>
                                    </div>
                                    <div class="col-lg-4 col-md-4 col-sm-4">
                                        <input class="form-control" type="text" id="ManagerName" name="ManagerName" />
                                    </div>
                                </div>
                                <div class="col-lg-12 col-md-12 col-sm-12 text-right" style="margin-top:10px;">
                                    <div class="col-lg-2 col-md-2 col-sm-2" style="margin-left:20px;">
                                        <button type="button" id="" class="btn btn-group">已配置的权限</button>
                                    </div>
                                    <div class="col-lg-2 col-md-2 col-sm-2" style="margin-left:415px;">
                                        <button type="button" id="" class="btn btn-group">未配置的权限</button>
                                    </div>
                                </div>
                                <div class="col-lg-12 col-md-12 col-sm-12 text-right" style="margin-top:10px;margin-left:50px;">
                                    <div class="col-lg-4 col-md-4 col-sm-4">
                                        @*已配置*@
                                        <div class="MarketingScheme" id="marketingScheme" style="text-align:left;">
                                                                         
                                        </div>
                                    </div>
                                    <div class="col-lg-3 col-md-3 col-sm-3 text-center">
                                        <button type="button" id="Addition" class="btn btn-group" style="margin-top:70px;">《添加权限</button>
                                        <button type="button" id="Alladd" class="btn btn-group" style="margin-top:40px;">《添加全部权限</button>
                                        <button type="button" id="" class="btn btn-group" style="margin-top:40px;">《 只对当前用户有效</button>
                                        <button type="button" id="RemoveCase" class="btn btn-group" style="margin-top:40px;">删除权限 》</button>
                                        <button type="button" id="DeleteAll" class="btn btn-group" style="margin-top:40px;">删除全部权限 》</button>
                                        <button type="button" id="" class="btn btn-group" style="margin-top:40px;margin-bottom:50px;">只对当前用户有效 》</button>
                                    </div>
                                    <div class="col-lg-4 col-md-4 col-sm-4">
                                        @*未配置*@
                                        <div class="DeployCase" id="deployCase" style="text-align:left;">

                                        </div>
                                    </div>
                                </div>
                            </div>
                        </form>
                    </div>
                </div>
            </div>
        </div>
    </div>

5.视图js代码

//配置权限
        $("#DeployScript").click(function () {
            var selectRowIndex = tbJurisd.getSelectedRowIndex();//获取选中行的索引值
            if (selectRowIndex >= 0) {
                var ManagerID = tbJurisd.getColumnValue(selectRowIndex, "ManagerID");//获取选中行的类型明细id
                //数据回填   只要回填给指定配置权限的姓名就可以
                $.post("SelectJurisdById", { ManagerID: ManagerID }, function (data) {
                    $("#ID").val(data.ManagerID);              隐藏的ID
                    $("#ManagerName").val(data.ManagerName);
                });
                //查询出该方案未配置的案例
                $.post("SelectMarketingCaseByID", { ManagerID: ManagerID }, function (josn) {
                    $("#deployCase").empty();      未配置中的id
                    for (k in josn) {
                        $("#deployCase").append('<input type="checkbox" value="' + josn[k].ManagerID + '"/>' + josn[k].Jurisdiction + "</br>");
                    }
                });
                //查询出该方案已配置的案例
                $.post("SelectMarketingSchemeByID", { ManagerID: ManagerID }, function (Data) {
                    $("#marketingScheme").empty();     已配置的id
                    for (x in Data) {
                        $("#marketingScheme").append('<input type="checkbox" value="' + Data[x].ManagerID + '"/>' + Data[x].Jurisdiction + "</br>");
                    }
                });
               
            $("#modUpdeteInfor").modal("show");//弹出模态框
            }
            else {
                layer.msg("请选择需要配置的营销方案!", { icon: 0, title: "提示", offset: '200px' });
            }
        });

        //添加权限
        $("#Addition").click(function () {
            //控制器中添加权限函数中的两个ID
            var ManageID = $("#ID").val();
            var check = $("#deployCase input[type=checkbox]:checked");//获取选中行
            var ReturnLength = 0; //声明变量用来存储添加数据条数
            //console.log(check.val());
            if (check.length > 0) {
                for (var i = 0; i < check.length; i++) {
                    $.ajax({
                        //拼接ID
                        url: "AddCase?ID=" + check[i].value + "&ManageID=" + ManageID,
                        type: "post",//数据传输通道的类型
                        async: false,
                        dataType: "json",//传输的数据的类型
                        success: function (data) {//直接理解为回调函数
                            if (data == "success") {
                                ReturnLength++;
                                if (ReturnLength == check.length) {
                                    //if外的长度:ReturnLength==1;

                                    layer.alert("添加成功 ^-^ ", { icon: 1, title: "提示", offset: "200px" });
                                }
                                else {
                                    layer.alert("选择" + check.length + "条信息,其中添加成功" + ReturnLength + "条,失败" + check.length - ReturnLength + "条!", { icon: 1, title: '提示', offset: "200px" });
                                }
                            }
                            else {
                                //引用第三方对话框。
                                layer.alert(data, { icon: 0, title: '提示', offset: "200px" });


                            }
                        }
                    });
                }
                //刷新
                //查询出该方案未配置的案例
                $.post("SelectMarketingCaseByID", { ManagerID: ManageID }, function (josn) {
                    $("#deployCase").empty();
                    for (k in josn) {
                        $("#deployCase").append('<input type="checkbox" value="' + josn[k].ManagerID + '"/>' + josn[k].Jurisdiction + "</br>");
                    }
                });
                //查询出该方案已配置的案例
                $.post("SelectMarketingSchemeByID", { ManagerID: ManageID }, function (Data) {
                    $("#marketingScheme").empty();
                    for (x in Data) {
                        $("#marketingScheme").append('<input type="checkbox" value="' + Data[x].ManagerID + '"/>' + Data[x].Jurisdiction + "</br>");
                    }
                });
            }
            else {
                layer.alert("请选择要添加的营销案例!", { icon: 0, title: '提示 ', offset: "200px" });
            }
        });

        //全部添加
        $("#Alladd").click(function () {
            var ManageID = $("#ID").val();
            var check = $("#deployCase input[type=checkbox]");//获取选中行
            var ReturnLength = 0; //声明变量用来存储添加数据条数
            //console.log(check.val());
            if (check.length > 0) {
                for (var i = 0; i < check.length; i++) {
                    $.ajax({
                        url: "AddCase?ID=" + check[i].value + "&ManageID=" + ManageID,
                        type: "post",//数据传输通道的类型
                        async: false,
                        dataType: "json",//传输的数据的类型
                        success: function (data) {//直接理解为回调函数
                            if (data == "success") {
                                ReturnLength++;
                                if (ReturnLength == check.length) {
                                    //if外的长度:ReturnLength==1;

                                    layer.alert("添加成功 ^-^ ", { icon: 1, title: "提示", offset: "200px" });
                                }
                                else {
                                    layer.alert("选择" + check.length + "条信息,其中添加成功" + ReturnLength + "条,失败" + check.length - ReturnLength + "条!", { icon: 1, title: '提示', offset: "200px" });
                                }
                            }
                            else {
                                //引用第三方对话框。
                                layer.alert(data, { icon: 0, title: '提示', offset: "200px" });
                            }
                        }
                    });
                }
                //刷新
                //查询出该方案未配置的案例
                $.post("SelectMarketingCaseByID", { ManagerID: ManageID }, function (josn) {
                    $("#deployCase").empty();
                    for (k in josn) {
                        $("#deployCase").append('<input type="checkbox" value="' + josn[k].ManagerID + '"/>' + josn[k].Jurisdiction + "</br>");
                    }
                });
                //查询出该方案已配置的案例
                $.post("SelectMarketingSchemeByID", { ManagerID: ManageID }, function (Data) {
                    $("#marketingScheme").empty();
                    for (x in Data) {
                        $("#marketingScheme").append('<input type="checkbox" value="' + Data[x].ManagerID + '"/>' + Data[x].Jurisdiction + "</br>");
                    }
                });
            }
            else {
                layer.alert("请选择要添加的营销案例!", { icon: 0, title: '提示 ', offset: "200px" });
            }
        });

        //删除
        $("#RemoveCase").click(function () {
            var ManageID = $("#ID").val();
            var check = $("#marketingScheme input[type=checkbox]:checked");//获取选中行
            //console.log(check.val());
            var ReturnLength = 0; //声明变量用来存储添加数据条数
            //console.log(check.val());
            if (check.length > 0) {
                for (var i = 0; i < check.length; i++) {
                    $.ajax({
                        url: "RemoveCase?ID=" + check[i].value + "&ManageID=" + ManageID,
                        type: "post",//数据传输通道的类型
                        async: false,
                        dataType: "json",//传输的数据的类型
                        success: function (data) {//直接理解为回调函数
                            if (data == "success") {
                                ReturnLength++;
                                if (ReturnLength == check.length) {
                                    //if外的长度:ReturnLength==1;
                                    layer.alert("删除成功 ^-^ ", { icon: 1, title: "提示", offset: "200px" });
                                }
                                else {
                                    tbJurisd.refreshPage();//刷新
                                    layer.alert("选择" + check.length + "条信息,其中删除成功" + ReturnLength + "条,失败" + check.length - ReturnLength + "条!", { icon: 1, title: '提示', offset: "200px" });
                                }
                            }
                            else {
                                //引用第三方对话框。
                                layer.alert(data, { icon: 0, title: '提示', offset: "200px" });
                            }
                        }
                    });
                }
                //刷新
                //查询出该方案未配置的案例
                $.post("SelectMarketingCaseByID", { ManagerID: ManageID }, function (josn) {
                    $("#deployCase").empty();
                    for (k in josn) {
                        $("#deployCase").append('<input type="checkbox" value="' + josn[k].ManagerID + '"/>' + josn[k].Jurisdiction + "</br>");
                    }
                });
                //查询出该方案已配置的案例
                $.post("SelectMarketingSchemeByID", { ManagerID: ManageID }, function (Data) {
                    $("#marketingScheme").empty();
                    for (x in Data) {
                        $("#marketingScheme").append('<input type="checkbox" value="' + Data[x].ManagerID + '"/>' + Data[x].Jurisdiction + "</br>");
                    }
                });
            }
            else {
                layer.alert("请选择要添加的营销案例!", { icon: 0, title: '提示 ', offset: "200px" });
            }
        });

        //全部删除
        $("#DeleteAll").click(function () {
            var ManageID = $("#ID").val();
            var check = $("#marketingScheme input[type=checkbox]");//获取选中行
            //console.log(check.val());
            var ReturnLength = 0; //声明变量用来存储添加数据条数
            //console.log(check.val());
            if (check.length > 0) {
                for (var i = 0; i < check.length; i++) {
                    $.ajax({
                        url: "RemoveCase?ID=" + check[i].value + "&ManageID=" + ManageID,
                        type: "post",//数据传输通道的类型
                        async: false,
                        dataType: "json",//传输的数据的类型
                        success: function (data) {//直接理解为回调函数
                            if (data == "success") {
                                ReturnLength++;
                                if (ReturnLength == check.length) {
                                    //if外的长度:ReturnLength==1;
                                    layer.alert("删除成功 ^-^ ", { icon: 1, title: "提示", offset: "200px" });
                                }
                                else {
                                    tbJurisd.refreshPage();//刷新
                                    layer.alert("选择" + check.length + "条信息,其中删除成功" + ReturnLength + "条,失败" + check.length - ReturnLength + "条!", { icon: 1, title: '提示', offset: "200px" });
                                }
                            }
                            else {
                                //引用第三方对话框。
                                layer.alert(data, { icon: 0, title: '提示', offset: "200px" });
                            }
                        }
                    });
                }
                //刷新
                //查询出该方案未配置的案例
                $.post("SelectMarketingCaseByID", { ManagerID: ManageID }, function (josn) {
                    $("#deployCase").empty();
                    for (k in josn) {
                        $("#deployCase").append('<input type="checkbox" value="' + josn[k].ManagerID + '"/>' + josn[k].Jurisdiction + "</br>");
                    }
                });
                //查询出该方案已配置的案例
                $.post("SelectMarketingSchemeByID", { ManagerID: ManageID }, function (Data) {
                    $("#marketingScheme").empty();
                    for (x in Data) {
                        $("#marketingScheme").append('<input type="checkbox" value="' + Data[x].ManagerID + '"/>' + Data[x].Jurisdiction + "</br>");
                    }
                });
            }
            else {
                layer.alert("请选择要添加的营销案例!", { icon: 0, title: '提示 ', offset: "200px" });
            }
        });

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值