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

387 lines
15 KiB

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;
using System.Text;
using System.Collections;
using System.Reflection;
using System.Web.Script.Serialization;
using FangYar.Model.TBL;
namespace FangYar.WebUI.ashx
{
/// <summary>
/// BaseMenuHandler 的摘要说明
/// </summary>
public class BaseMenuHandler : IHttpHandler
{
private FangYar.BLL.TBL.BaseMenuBLL bll = new BLL.TBL.BaseMenuBLL();
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 "menuList":
returnstr = GetmenuList(context);
break;
case "List":
returnstr = GetModel(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;
}
context.Response.Write(returnstr);
}
//查询
private string GetModel(HttpContext context)
{
string returnstr = "";
try
{
string keyword = context.Request.Params["keywords"];
string page = context.Request.Params["page"];
string limit = context.Request.Params["limit"];
int pageIndex = 1;
int pageSize = 10;//
if (!string.IsNullOrEmpty(page)) { pageIndex = int.Parse(page); }
if (!string.IsNullOrEmpty(limit)) { pageSize = int.Parse(limit); }
string where = null;
if (!string.IsNullOrEmpty(keyword))
{
where = "MENU_CODE like '" + keyword + "' or MENU_TITLE like '" + keyword + "' ";
}
returnstr = "{\"code\":0,\"msg\":\"\",";
int count = bll.Count(where);
returnstr += "\"count\":" + count + ",\"data\":";
if (count == 0)
{
returnstr += "[]";
}
else
{
List<FangYar.Model.TBL.TBL_BASE_MENU_Model> list = bll.QueryList(pageIndex, pageSize, where, null);
returnstr += FangYar.Common.JsonHelper.ToJson(list);
}
returnstr += "}";
}
catch (Exception e)
{
returnstr = "{\"code\":0,\"msg\":\"error\",\"count\":0,\"data\":[]";
// 记录操作日志
BLL.SysOperationLogHelp.AddSysOperationLog(context, Common.EnumOperationLogType.Error, "基础菜单请求", "查询异常:" + e);
}
// 记录操作日志
BLL.SysOperationLogHelp.AddSysOperationLog(context, Common.EnumOperationLogType.Query, "基础菜单请求", "查询");
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))
{
msg = "删除成功!";
code = 1;
}
else
{
msg = "删除失败!";
}
}
catch (Exception e)
{
msg = "删除失败!";
// 记录操作日志
BLL.SysOperationLogHelp.AddSysOperationLog(context, Common.EnumOperationLogType.Error, "基础菜单请求", "删除异常:" + e);
}
returnstr = "{\"code\":" + code + ",\"msg\":\"" + msg + "\"}";
// 记录操作日志
BLL.SysOperationLogHelp.AddSysOperationLog(context, Common.EnumOperationLogType.Delete, "基础菜单请求", "删除");
return returnstr;
}
//添加
private string AddModel(HttpContext context)
{
string returnstr = "";
int code = -1;
string msg = "";
try
{
string menuCode = context.Request.Params["menuCode"];
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(menuCode))
{
msg = "菜单标示CODE不能为空";
}
else if (string.IsNullOrEmpty(menuTitle))
{
msg = "菜单名称不能为空";
}
else
{
FangYar.Model.TBL.TBL_BASE_MENU_Model model = new Model.TBL.TBL_BASE_MENU_Model();
model.ID = Guid.NewGuid().ToString("N");
model.MENU_CODE = menuCode;
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 = menuOrder;
if (bll.Add(model))
{
msg = "添加成功!";
code = 1;
}
else { msg = "添加失败!"; }
}
}
catch (Exception e)
{
msg = "添加失败!";
// 记录操作日志
BLL.SysOperationLogHelp.AddSysOperationLog(context, Common.EnumOperationLogType.Error, "基础菜单请求", "添加异常:" + e);
}
returnstr = "{\"msg\":\"" + msg + "\",\"code\":" + code + "}";
// 记录操作日志
BLL.SysOperationLogHelp.AddSysOperationLog(context, Common.EnumOperationLogType.Add, "基础菜单请求", "添加");
return returnstr;
}
//修改
private string EditModel(HttpContext context)
{
string returnstr = "";
int code = -1;
string msg = "";
try
{
string ID = context.Request.Params["ID"];
string menuCode = context.Request.Params["menuCode"];
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_BASE_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 = menuOrder;
if (bll.Edit(model))
{
msg = "修改成功!";
code = 1;
}
else { msg = "修改失败"; }
}
}
catch (Exception e)
{
msg = "修改失败!";
// 记录操作日志
BLL.SysOperationLogHelp.AddSysOperationLog(context, Common.EnumOperationLogType.Error, "基础菜单请求", "修改异常:" + e);
}
returnstr = "{\"code\":" + code + ",\"msg\":\"" + msg + "\"}";
// 记录操作日志
BLL.SysOperationLogHelp.AddSysOperationLog(context, Common.EnumOperationLogType.Update, "基础菜单请求", "修改");
return returnstr;
}
//更改状态
private string EditFlag(HttpContext context)
{
string returnstr = "";
int code = -1;
string msg = "";
try
{
string id = context.Request.Params["ID"];
string menuType = context.Request.Params["menuFlag"];
FangYar.Model.TBL.TBL_BASE_MENU_Model model = bll.GetModelByID(id);
if (model == null)
{
msg = "该记录不存在";
}
else
{
if (menuType == "0")
{
model.MENU_FLAG = "1";
}
else if (menuType == "1")
{
model.MENU_FLAG = "0";
}
if (bll.Edit(model))
{
msg = "修改成功!";
code = 1;
}
else
{
msg = "修改失败!";
}
}
}
catch (Exception e)
{
msg = "修改失败!";
// 记录操作日志
BLL.SysOperationLogHelp.AddSysOperationLog(context, Common.EnumOperationLogType.Error, "基础菜单请求", "更改状态异常:" + e);
}
returnstr = "{\"code\":" + code + ",\"msg\":\"" + msg + "\"}";
// 记录操作日志
BLL.SysOperationLogHelp.AddSysOperationLog(context, Common.EnumOperationLogType.Update, "基础菜单请求", "更改状态");
return returnstr;
}
//数据库查询生成菜单
private string GetmenuList(HttpContext context)
{
string teturnstr = "";
try
{
FangYar.Model.BaseUserModel model = new Model.BaseUserModel();
List<FangYar.Model.TBL.TBL_BASE_MENU_Model> list = bll.QueryWhere(null);
List<MenuJsonModel> listParent = new List<MenuJsonModel>();
for (int i = 0; i < list.Count; i++)
{
if (list[i].MENU_PARENT == "-1")
{
MenuJsonModel returnobj = new MenuJsonModel();
returnobj.title = list[i].MENU_TITLE;
returnobj.icon = "iconfont " + list[i].MENU_ICON;
returnobj.href = "";
returnobj.spread = true;
returnobj.id = list[i].ID;
returnobj.order = int.Parse(list[i].MENU_ORDER);
listParent.Add(returnobj);
}
}
listParent = listParent.OrderBy(a => a.order).ToList();//排序
for (int j = 0; j < listParent.Count; j++)
{
listParent[j].children = new List<MenuJsonModel>();
for (int k = 0; k < list.Count; k++)
{
if (list[k].MENU_PARENT == listParent[j].id)
{
MenuJsonModel returnChild = new MenuJsonModel();
returnChild.title = list[k].MENU_TITLE;
returnChild.icon = "iconfont " + list[k].MENU_ICON;
returnChild.href = list[k].MENU_URL;
returnChild.spread = false;
returnChild.id = list[k].ID;
returnChild.order = int.Parse(list[k].MENU_ORDER);
listParent[j].children.Add(returnChild);
}
}
listParent[j].children.OrderBy(a => a.order).ToList();
}
teturnstr = tojson(listParent);
}
catch (Exception e)
{
// 记录操作日志
BLL.SysOperationLogHelp.AddSysOperationLog(context, Common.EnumOperationLogType.Error, "基础菜单请求", "数据库查询生成菜单异常:" + e);
}
// 记录操作日志
BLL.SysOperationLogHelp.AddSysOperationLog(context, Common.EnumOperationLogType.Query, "基础菜单请求", "数据库查询生成菜单");
return teturnstr;
}
//转json
public string tojson(List<MenuJsonModel> obj)
{
try
{
StringBuilder stringBuilder = new StringBuilder();
JavaScriptSerializer json = new JavaScriptSerializer();
json.Serialize(obj, stringBuilder);
return stringBuilder.ToString();
}
catch (Exception e)
{
string str = "基础菜单请求—转json异常:" + e;
FangYar.Common.MyLogHelper.WriteMsg(new FangYar.Common.LogInfoMo() { message = str, msgType = FangYar.Common.EnumLogMsgTypeEnum.Error, path = "BaseMenuHandler" });
}
return "{}";
}
public bool IsReusable
{
get
{
return false;
}
}
}
}