1.功能视图(调用数据库的数据来配置权限)
2.数据库
3.控制器
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);
}
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);
}
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);
}
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">×</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");
$.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 () {
var ManageID = $("#ID").val();
var check = $("#deployCase input[type=checkbox]:checked");
var ReturnLength = 0;
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) {
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;
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) {
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");
var ReturnLength = 0;
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) {
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]");
var ReturnLength = 0;
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) {
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" });
}
});