软测单独项目
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.
 
 
 
 
 
 

360 lines
12 KiB

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using FangYar.Model.TBL;
using System.Text;
using System.Web.Script.Serialization;
namespace FangYar.WebUI.ashx
{
/// <summary>
/// SysMenuHandler 的摘要说明
/// </summary>
public class ZYSysMenuHandler : IHttpHandler
{
private FangYar.BLL.TBL.SysMenuBLL bll = new BLL.TBL.SysMenuBLL();
private FangYar.BLL.ToTree_BLL blltree = new BLL.ToTree_BLL();
public void ProcessRequest(HttpContext context)
{
context.Response.ContentType = "text/plain";
string action = context.Request.Params["Action"];
string returnstr = "";
switch (action)
{
case "List":
returnstr = GetModelList(context);
break;
case "Del":
returnstr = DelModel(context);
break;
case "Add":
returnstr = AddModel(context);
break;
case "Edit":
returnstr = EditModel(context);
break;
case "EditFlag":
returnstr = EditFlag(context);
break;
case "getMenuTree":
returnstr = getMenuTree(context);
break;
case "getMenuTitile":
returnstr = getMenuTitile(context);
break;
}
context.Response.Write(returnstr);
}
//查询
private string GetModelList(HttpContext context)
{
string returnstr = "";
try
{
string keywords = context.Request.Params["keywords"];
string limit = context.Request.Params["limit"];
string page = context.Request.Params["page"];
string menuid = context.Request.Params["menuid"]; //点击菜单ID
int pageIndex = 1;
int pageSize = 10;
if (!string.IsNullOrEmpty(limit)) { pageIndex = int.Parse(page); }
if (!string.IsNullOrEmpty(page)) { pageSize = int.Parse(limit); }
string where = " 1=1 ";
//搜索
if (!string.IsNullOrEmpty(keywords))
{
where += " and (APP_ID like'%" + keywords + "%' or MENU_TITLE like'%" + keywords + "%') ";
}
//菜单树点击
if (!string.IsNullOrEmpty(menuid))
{
where += " and( ID like'%" + menuid.Replace(",", "") + "%' or MENU_PARENT like'%" + menuid.Replace(",", "") + "%') ";
}
where += "order by menu_order ";
returnstr = "{\"code\":0,\"msg\":\"\",";
int count = bll.Count(where);
returnstr += "\"count\":" + count + ",\"data\":";
if (count == 0)
{
returnstr += "[]";
}
else
{
List<FangYar.Model.TBL.TBL_SYS_MENU_Model> list = bll.QueryList(pageIndex, pageSize, where, null);
returnstr += FangYar.Common.JsonHelper.ToJson(list);
}
returnstr += "}";
}
catch
{
returnstr = "{\"code\":0,\"msg\":\"error\",\"count\":0,\"data\":[]}";
}
return returnstr;
}
//删除
private string DelModel(HttpContext context)
{
string returnstr = "";
int code = -1;
string msg = "";
try
{
string UIDList = context.Request.Params["UIDList"];
UIDList = UIDList.Replace(",", "','");
if (bll.Delete(UIDList))
{
bll.DeleteRoleMenu(UIDList);
msg = "删除成功!";
code = 1;
}
else
{
msg = "删除失败!";
}
}
catch
{
msg = "删除失败!";
}
returnstr = "{\"code\":" + code + ",\"msg\":\"" + msg + "\"}";
return returnstr;
}
//添加
private string AddModel(HttpContext context)
{
string returnstr = "";
int code = -1;
string msg = "";
try
{
string appID = context.Request.Params["appID"];
string menuTitle = context.Request.Params["menuTitle"];
string menuIcon = context.Request.Params["menuIcon"];
string menuUrl = context.Request.Params["menuUrl"];
string menuParent = context.Request.Params["menuParent"];
string menuType = context.Request.Params["menuType"];//菜单类型
string menuFlag = context.Request.Params["menuFlag"];//菜单状态
string menuLevel = context.Request.Params["menuLevel"];
string menuOrder = context.Request.Params["menuOrder"];
string menuMap = context.Request.Params["needmap"];
string menuAction = context.Request.Params["menuAction"];
if (string.IsNullOrEmpty(appID))
{
msg = "所属应用不能为空";
}
else if (string.IsNullOrEmpty(menuTitle))
{
msg = "菜单名称不能为空";
}
else
{
FangYar.Model.TBL.TBL_SYS_MENU_Model model = new Model.TBL.TBL_SYS_MENU_Model();
model.ID = Guid.NewGuid().ToString("N");
model.APP_ID = appID;
model.MENU_TITLE = menuTitle;
model.MENU_ICON = menuIcon;
model.MENU_URL = menuUrl;
model.MENU_PARENT = menuParent;
model.MENU_TYPE = menuType;
model.MENU_FLAG = menuFlag;
model.MENU_LEVEL = menuLevel;
model.MENU_ORDER = int.Parse(menuOrder);
model.MENU_MAP = menuMap;
model.MENU_ACTION = menuAction;
if (bll.Add(model))
{
msg = "添加成功!";
code = 1;
}
else { msg = "添加失败!"; }
}
}
catch
{
msg = "添加失败!";
}
returnstr = "{\"msg\":\"" + msg + "\",\"code\":" + code + "}";
return returnstr;
}
//修改
private string EditModel(HttpContext context)
{
string returnstr = "";
int code = -1;
string msg = "";
try
{
string ID = context.Request.Params["ID"];
string appID = context.Request.Params["appID"];
string menuTitle = context.Request.Params["menuTitle"];
string menuIcon = context.Request.Params["menuIcon"];
string menuUrl = context.Request.Params["menuUrl"];
string menuParent = context.Request.Params["menuParent"];
string menuType = context.Request.Params["menuType"];
string menuFlag = context.Request.Params["menuFlag"];
string menuLevel = context.Request.Params["menuLevel"];
string menuOrder = context.Request.Params["menuOrder"];
string menuMap = context.Request.Params["needmap"];
string menuAction = context.Request.Params["menuAction"];
FangYar.Model.TBL.TBL_SYS_MENU_Model model = bll.GetModelByID(ID);
if (model == null)
{
msg = "应用记录不存在!";
}
else
{
model.MENU_TITLE = menuTitle;
model.MENU_ICON = menuIcon;
model.MENU_URL = menuUrl;
model.MENU_PARENT = menuParent;
model.MENU_TYPE = menuType;
model.MENU_FLAG = menuFlag;
model.MENU_LEVEL = menuLevel;
model.MENU_ORDER = int.Parse(menuOrder);
model.MENU_MAP = menuMap;
model.MENU_ACTION = menuAction;
if (bll.Edit(model))
{
msg = "修改成功!";
code = 1;
}
else { msg = "修改失败"; }
}
}
catch
{
msg = "修改失败!";
}
returnstr = "{\"code\":" + code + ",\"msg\":\"" + msg + "\"}";
return returnstr;
}
//菜单状态,禁用与启用
private string EditFlag(HttpContext context)
{
string returnstr = "";
int code = -1;
string msg = "";
try
{
string id = context.Request.Params["ID"];
string menuFlag = context.Request.Params["menuFlag"];
FangYar.Model.TBL.TBL_SYS_MENU_Model model = bll.GetModelByID(id);
if (model == null)
{
msg = "该记录不存在";
}
else
{
if (menuFlag == "0")
{
model.MENU_FLAG = "1";
}
else if (menuFlag == "1")
{
model.MENU_FLAG = "0";
}
if (bll.Edit(model))
{
msg = "修改成功!";
code = 1;
}
else
{
msg = "修改失败!";
}
}
}
catch
{
msg = "修改失败!";
}
returnstr = "{\"code\":" + code + ",\"msg\":\"" + msg + "\"}";
return returnstr;
}
//菜单树
private string getMenuTree(HttpContext context)
{
string returnstr = "";
try
{
string treeid = context.Request.Params["treeid"];
string where = null;
if (!string.IsNullOrEmpty(treeid))
{
where = " ID = " + treeid;
}
List<FangYar.Model.TreeNodeModel> list = new List<Model.TreeNodeModel>();
list = blltree.GetTree("ID", "MENU_PARENT", "MENU_TITLE", "TBL_SYS_MENU", where, list);
returnstr = "{\"data\":";
if (list.Count == 0)
{
returnstr += "[]";
}
else
{
returnstr += FangYar.Common.JsonHelper.ToJson(list);
}
returnstr += "}";
}
catch
{
returnstr = "{\"data\":[]}";
}
return returnstr;
}
//查询一条记录
private string getMenuTitile(HttpContext context)
{
string returnstr = "";
try
{
string ID = context.Request.Params["ID"];
int count = bll.Count("ID ='" + ID + "'");
if (count > 0)
{
returnstr = "{\"code\":1,\"data\":";
FangYar.Model.TBL.TBL_SYS_MENU_Model model = bll.GetModelByID(ID);
returnstr += FangYar.Common.JsonHelper.ToJson(model);
returnstr += "}";
}
else
{
returnstr = "{\"code\":0,\"data\":[]}";
}
}
catch
{
returnstr = "{\"code\":0,\"data\":[]}";
}
return returnstr;
}
public bool IsReusable
{
get
{
return false;
}
}
}
}