You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
294 lines
11 KiB
294 lines
11 KiB
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Web;
|
|
using System.Data;
|
|
|
|
namespace FangYar.WebUI.ashx
|
|
{
|
|
/// <summary>
|
|
/// RoleMenuHandler 的摘要说明
|
|
/// </summary>
|
|
public class RoleMenuHandler : IHttpHandler
|
|
{
|
|
private FangYar.BLL.TBL.SysRoleMenuBLL bll = new BLL.TBL.SysRoleMenuBLL();
|
|
public void ProcessRequest(HttpContext context)
|
|
{
|
|
|
|
// 记录操作日志
|
|
BLL.SysOperationLogHelp.AddSysOperationLog(context, Common.EnumOperationLogType.Other, "角色菜单操作请求", "");
|
|
|
|
context.Response.ContentType = "text/plain";
|
|
string action = context.Request.Params["Action"];
|
|
string returnstr = "";
|
|
switch (action)
|
|
{
|
|
case "showRoleMenu":
|
|
returnstr = showRoleMenu(context);
|
|
break;
|
|
case "showRoleMenuNot":
|
|
returnstr = showRoleMenuNot(context);
|
|
break;
|
|
case "SaveRoleChooseMenu":
|
|
returnstr = SaveRoleChooseMenu(context);
|
|
break;
|
|
case "SaveRoleChooseMenuNot":
|
|
returnstr = SaveRoleChooseMenuNot(context);
|
|
break;
|
|
}
|
|
context.Response.Write(returnstr);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 获取角色已选应用菜单
|
|
/// </summary>
|
|
/// <param name="context"></param>
|
|
/// <returns></returns>
|
|
private string showRoleMenu(HttpContext context)
|
|
{
|
|
string appId = context.Request.Params["appId"];
|
|
string roleId = context.Request.Params["roleId"];
|
|
string returnstr = "";
|
|
try
|
|
{
|
|
returnstr = "{\"code\":0,\"data\":";
|
|
DataTable dt = bll.queryDataTable(appId, roleId);
|
|
if (dt == null)
|
|
{
|
|
returnstr += "[]";
|
|
}
|
|
else if (dt.Rows.Count == 0)
|
|
{
|
|
returnstr += "[]";
|
|
}
|
|
else
|
|
{
|
|
returnstr += FangYar.Common.JsonHelper.ToJson(dt);
|
|
}
|
|
returnstr += "}";
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
returnstr = "{\"code\":-1,\"data\":[]}";
|
|
// 记录操作日志
|
|
BLL.SysOperationLogHelp.AddSysOperationLog(context, Common.EnumOperationLogType.Error, "角色菜单操作请求", "获取角色已选应用菜单异常:" + e);
|
|
|
|
}
|
|
|
|
// 记录操作日志
|
|
BLL.SysOperationLogHelp.AddSysOperationLog(context, Common.EnumOperationLogType.Query, "角色菜单操作请求", "获取角色已选应用菜单");
|
|
return returnstr;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 获取角色已选排除菜单
|
|
/// </summary>
|
|
/// <param name="context"></param>
|
|
/// <returns></returns>
|
|
private string showRoleMenuNot(HttpContext context)
|
|
{
|
|
string appId = context.Request.Params["appId"];
|
|
string roleId = context.Request.Params["roleId"];
|
|
string returnstr = "";
|
|
try
|
|
{
|
|
returnstr = "{\"code\":0,\"data\":";
|
|
DataTable dt = bll.queryDataTableNot(appId, roleId);
|
|
if (dt == null)
|
|
{
|
|
returnstr += "[]";
|
|
}
|
|
else if (dt.Rows.Count == 0)
|
|
{
|
|
returnstr += "[]";
|
|
}
|
|
else
|
|
{
|
|
returnstr += FangYar.Common.JsonHelper.ToJson(dt);
|
|
}
|
|
returnstr += "}";
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
returnstr = "{\"code\":-1,\"data\":[]}";
|
|
// 记录操作日志
|
|
BLL.SysOperationLogHelp.AddSysOperationLog(context, Common.EnumOperationLogType.Error, "角色菜单操作请求", "获取角色已选排除菜单异常:" + e);
|
|
|
|
}
|
|
// 记录操作日志
|
|
BLL.SysOperationLogHelp.AddSysOperationLog(context, Common.EnumOperationLogType.Query, "角色菜单操作请求", "获取角色已选排除菜单");
|
|
return returnstr;
|
|
}
|
|
|
|
|
|
//保存角色选择的菜单
|
|
private string SaveRoleChooseMenu(HttpContext context)
|
|
{
|
|
string returnstr = "";
|
|
int code = -1;
|
|
string msg = "";
|
|
int deleteCount = 0;
|
|
try
|
|
{
|
|
string appId = context.Request.Params["appId"];
|
|
string roleId = context.Request.Params["roleId"];
|
|
string menuIdList = context.Request.Params["menuIdList"];
|
|
menuIdList = menuIdList.Trim(','); ;
|
|
|
|
// menuIdList = menuIdList.Replace(",", "','");
|
|
string[] menuIdArry = menuIdList.Split(',');
|
|
var list1 = menuIdArry.ToList();
|
|
var list2 = list1.GroupBy(p => p.Trim());
|
|
menuIdArry = list2.Select(p => p.Key).ToArray();
|
|
string where = "ROLE_ID='" + roleId + "'";
|
|
int count = bll.Count(where);
|
|
if (count > 0)
|
|
{
|
|
bool isDelete = bll.Delete(roleId);//清空原来的权限
|
|
if (isDelete)
|
|
{
|
|
deleteCount = count;
|
|
}
|
|
|
|
}
|
|
//Guid.NewGuid().ToString("N")
|
|
if (menuIdArry.Length > 0)
|
|
{
|
|
string insSql = " insert into tbl_sys_rolemenu(ID,APP_ID,ROLE_ID,MENU_ID) ";
|
|
for (int i = 0; i < menuIdArry.Length; i++)
|
|
{
|
|
if (i > 0)
|
|
{
|
|
insSql += " UNION ";
|
|
}
|
|
insSql += " SELECT '" + Guid.NewGuid().ToString("N") + "','" + appId + "','" + roleId + "','" + menuIdArry[i] + "' ";
|
|
|
|
//FangYar.Model.TBL.TBL_SysRoleMenuModel model = new Model.TBL.TBL_SysRoleMenuModel();
|
|
//model.APP_ID = appId;
|
|
//model.MENU_ID = menuIdArry[i];
|
|
//model.ROLE_ID = roleId;
|
|
//bool isadd = bll.Add(model);
|
|
//if (!isadd)
|
|
//{
|
|
// msg = "设置失败";
|
|
// break;
|
|
//}
|
|
//else
|
|
//{
|
|
// msg = "设置成功!";
|
|
// code = 1;
|
|
//}
|
|
}
|
|
|
|
int j = FangYar.Common.MySqlHelper.ExecuteSql(insSql);
|
|
if (j > 0)
|
|
{
|
|
msg = "设置成功!";
|
|
code = 1;
|
|
}
|
|
else
|
|
{
|
|
msg = "设置失败";
|
|
}
|
|
}
|
|
else
|
|
{
|
|
msg = "设置成功!";
|
|
code = 1;
|
|
}
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
msg = "设置失败!";
|
|
// 记录操作日志
|
|
BLL.SysOperationLogHelp.AddSysOperationLog(context, Common.EnumOperationLogType.Error, "角色菜单操作请求", "保存角色选择的菜单异常:" + e);
|
|
|
|
}
|
|
returnstr = "{\"code\":" + code + ",\"deleteCount\":" + deleteCount + ",\"msg\":\"" + msg + "\"}";
|
|
// 记录操作日志
|
|
BLL.SysOperationLogHelp.AddSysOperationLog(context, Common.EnumOperationLogType.Update, "角色菜单操作请求", "保存角色选择的菜单");
|
|
|
|
return returnstr;
|
|
}
|
|
|
|
//保存角色选择的排除菜单
|
|
private string SaveRoleChooseMenuNot(HttpContext context)
|
|
{
|
|
string returnstr = "";
|
|
int code = -1;
|
|
string msg = "";
|
|
int deleteCount = 0;
|
|
try
|
|
{
|
|
string appId = context.Request.Params["appId"];
|
|
string roleId = context.Request.Params["roleId"];
|
|
string menuIdList = context.Request.Params["menuIdList"];
|
|
menuIdList = menuIdList.Trim(','); ;
|
|
|
|
// menuIdList = menuIdList.Replace(",", "','");
|
|
string[] menuIdArry = menuIdList.Split(',');
|
|
string where = "ROLE_ID='" + roleId + "'";
|
|
int count = bll.CountNot(where);
|
|
if (count > 0)
|
|
{
|
|
bool isDelete = bll.DeleteNot(roleId);//清空原来的权限
|
|
if (isDelete)
|
|
{
|
|
deleteCount = count;
|
|
}
|
|
|
|
}
|
|
//Guid.NewGuid().ToString("N")
|
|
if (menuIdArry.Length > 0)
|
|
{
|
|
string insSql = " insert into tbl_sys_rolemenu_not(ID,APP_ID,ROLE_ID,MENU_ID) ";
|
|
for (int i = 0; i < menuIdArry.Length; i++)
|
|
{
|
|
if (i > 0)
|
|
{
|
|
insSql += " UNION ";
|
|
}
|
|
insSql += " SELECT '" + Guid.NewGuid().ToString("N") + "','" + appId + "','" + roleId + "','" + menuIdArry[i] + "' ";
|
|
|
|
}
|
|
|
|
int j = FangYar.Common.MySqlHelper.ExecuteSql(insSql);
|
|
if (j > 0)
|
|
{
|
|
msg = "设置成功!";
|
|
code = 1;
|
|
}
|
|
else
|
|
{
|
|
msg = "设置失败";
|
|
}
|
|
}
|
|
else
|
|
{
|
|
msg = "设置成功!";
|
|
code = 1;
|
|
}
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
msg = "设置失败!";
|
|
// 记录操作日志
|
|
BLL.SysOperationLogHelp.AddSysOperationLog(context, Common.EnumOperationLogType.Error, "角色菜单操作请求", "保存角色选择的排除菜单异常:" + e);
|
|
|
|
}
|
|
returnstr = "{\"code\":" + code + ",\"deleteCount\":" + deleteCount + ",\"msg\":\"" + msg + "\"}";
|
|
// 记录操作日志
|
|
BLL.SysOperationLogHelp.AddSysOperationLog(context, Common.EnumOperationLogType.Update, "角色菜单操作请求", "保存角色选择的排除菜单");
|
|
|
|
return returnstr;
|
|
}
|
|
|
|
public bool IsReusable
|
|
{
|
|
get
|
|
{
|
|
return false;
|
|
}
|
|
}
|
|
}
|
|
}
|