TG.WXCRM.V4/WEB/Controllers/Base/MenuController.cs

237 lines
8.9 KiB
C#

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Web.Mvc;
using WX.CRM.Common;
using WX.CRM.IBLL.Base;
using WX.CRM.WebHelper;
namespace WX.CRM.WEB.Controllers.Base
{
public class MenuController : BaseController
{
private IBAS_LEFTMEMU leftMemuBiz;
private IBAS_LEFTMEMU_Q leftMemuBiz_Q;
private IBAS_MODULEMENU moduleMenuBiz;
private IBAS_MODULEMENU_Q moduleMenuBiz_Q;
ValidationErrors errors = new ValidationErrors();
public MenuController(IBAS_LEFTMEMU _leftMemuBiz, IBAS_LEFTMEMU_Q _leftMemuBiz_Q, IBAS_MODULEMENU _moduleMenuBiz, IBAS_MODULEMENU_Q _moduleMenuBiz_Q)
{
this.leftMemuBiz = _leftMemuBiz;
this.leftMemuBiz_Q = _leftMemuBiz_Q;
this.moduleMenuBiz = _moduleMenuBiz;
this.moduleMenuBiz_Q = _moduleMenuBiz_Q;
}
[AuthorizeRedirect(Roles = InitRights.CONST_菜单管理)]
public ActionResult Index()
{
//ToolBar
ToolBar tool = new ToolBar();
string[] toolbtn = new ToolButtonView().ToolButtonRight(InitRights., userRightId);
List<string> listBtn = new List<string>(toolbtn);
List<string> Buttons = new List<string>();
Buttons.Add("Other6");
Buttons.Add("Other7");
Buttons.Add("Other5");
Buttons.AddRange(listBtn);
tool.AllowButton(Buttons.ToArray());
// tool.AllowButton("Other4", "Other5", "Other6", "Other7", "Other3", "Other1", "Other2", "Edit", "Delete");
tool.AddOtherButton("Other1", "新增模块菜单", "icon-add", "AddBas_ModuleMenu_Click", true);
tool.AddOtherButton("Other2", "新增系统菜单", "icon-add", "AddBas_leftMemu_Click", true);
tool.AddOtherButton("Other5", "刷新", "icon-reload", "Reload_Click", true);
tool.AddOtherButton("Other6", "展开全部", "icon-flag", "ExpandAll_Click", true);
tool.AddOtherButton("Other7", "折叠全部", "icon-show", "CollapseAll_Click", true);
tool.AddOtherButton("Other3", "向上", "icon-up", "Up_Click", true);
tool.AddOtherButton("Other4", "向下", "icon-down", "Down_Click", true);
ViewBag.ToolBar = tool;
return View();
}
#region ModuleMenu编辑
[HttpGet]
[AuthorizeToolBar(InitRights.CONST_菜单管理, InitToolBar.CONST_Edit)]
public ActionResult ModuleEdit(string id)
{
WX.CRM.Model.Entity.BAS_MODULEMENU model = new WX.CRM.Model.Entity.BAS_MODULEMENU();
if (id != null)
{
model = moduleMenuBiz_Q.GetModel_ModuleMenu(Convert.ToDecimal(id));
if (model != null && model.RIGHTID != null)
model.RIGHTID = model.RIGHTID;
}
return View(model);
}
[HttpPost]
[AuthorizeToolBar(InitRights.CONST_菜单管理, InitToolBar.CONST_Edit)]
public JsonResult ModuleEdit(WX.CRM.Model.Entity.BAS_MODULEMENU model)
{
if (!ModelState.IsValid)
return JsonHandler.ValidateFailMessage();
if (model.RIGHTID != null)
model.RIGHTID = model.RIGHTID;
if (model.MODULEMENUID == 0)
{
model.CTIME = DateTime.Now;
bool result = moduleMenuBiz.Create_ModuleMenu(ref errors, model);
return JsonHandler.InsertMessage(errors, result);
}
else
{
bool result = moduleMenuBiz.Update_ModuleMenu(ref errors, model);
return JsonHandler.UpdateMessage(errors, result);
}
}
#endregion
#region ModuleMenu删除
[AuthorizeToolBar(InitRights.CONST_菜单管理, InitToolBar.CONST_Delete)]
public JsonResult ModuleDelete(string id)
{
if (string.IsNullOrWhiteSpace(id))
return JsonHandler.ManageMessage("参数不对", false);
bool result = moduleMenuBiz.Delete_ModuleMenu(ref errors, Convert.ToDecimal(id));
return JsonHandler.DeleteMessage(errors, result);
}
#endregion
#region ModuleMenu修改顺序
/// <summary>
/// 修改顺序
/// </summary>
/// <returns></returns>
public JsonResult ModuleSaveSortId(string ids, string sortIds)
{
bool result = moduleMenuBiz.Sort_ModuleMenu(ref errors, ids, sortIds);
return JsonHandler.ManageMessage(errors, result);
}
#endregion
#region LeftMenu编辑
[HttpGet]
[AuthorizeToolBar(InitRights.CONST_菜单管理, InitToolBar.CONST_Other2)]
public ActionResult LeftMenuEdit(string id)
{
WX.CRM.Model.Entity.BAS_LEFTMEMU model = new WX.CRM.Model.Entity.BAS_LEFTMEMU();
model.ISGROUP = 0;//设定默认
model.ISSHOW = 1;
if (Request.QueryString["fid"] != null)
model.PARENTID = Convert.ToDecimal(Request.QueryString["fid"]);
else
model.PARENTID = null;
if (id != null)
{
model = leftMemuBiz_Q.GetModel_leftMenu(Convert.ToDecimal(id));
if (model.PARENTID == 0)
model.PARENTID = -model.MODULEMENUID;
if (model.PARENTID != null)
model.PARENTID = model.PARENTID;
}
return View(model);
}
[HttpPost]
[AuthorizeToolBar(InitRights.CONST_菜单管理, InitToolBar.CONST_Other2)]
public JsonResult LeftMenuEdit(WX.CRM.Model.Entity.BAS_LEFTMEMU model)
{
if (!ModelState.IsValid)
{
return JsonHandler.ValidateFailMessage();
}
if (model.PARENTID < 0)
model.PARENTID = 0;
if (model.RIGHTID != null)
model.RIGHTID = model.RIGHTID;
if (model.MENUID == 0)
{
model.CTIME = DateTime.Now;
bool result = leftMemuBiz.Create_leftMemu(ref errors, model);
return JsonHandler.InsertMessage(errors, result);
}
else
{
bool result = leftMemuBiz.Update_leftMemu(ref errors, model);
return JsonHandler.UpdateMessage(errors, result);
}
}
#endregion
#region LeftMenu删除
[AuthorizeToolBar(InitRights.CONST_菜单管理, InitToolBar.CONST_Delete)]
public JsonResult LeftMenuDelete(string id)
{
if (string.IsNullOrWhiteSpace(id))
{
return JsonHandler.ManageMessage("参数不对!", false);
}
bool result = leftMemuBiz.Delete_leftMemu(ref errors, Convert.ToDecimal(id));
return JsonHandler.DeleteMessage(errors, result);
}
#endregion
#region LeftMenu修改顺序
/// <summary>
/// 修改顺序
/// </summary>
/// <returns></returns>
[AuthorizeToolBar(InitRights.CONST_菜单管理, InitToolBar.CONST_Other3)]
public JsonResult LeftMenuSaveSortId(string ids, string sortIds)
{
bool result = leftMemuBiz.Sort_leftMemu(ref errors, ids, sortIds);
return JsonHandler.ManageMessage(errors, result);
}
#endregion
#region
/// <summary>
/// 获取菜单的所有数据
/// </summary>
/// <returns></returns>
public JsonResult GetMenuTreeJson()
{
object leftMemuList = leftMemuBiz_Q.GetTreeList_leftMenu();
return Json(leftMemuList, JsonRequestBehavior.AllowGet);
}
/// <summary>
/// 获取菜单的所有数据 更新权限
/// </summary>
/// <returns></returns>
public JsonResult GetMenuTreeJsonByRight()
{
object leftMemuList = leftMemuBiz_Q.GetTreeList_leftMenu(userRightId);
return Json(leftMemuList, JsonRequestBehavior.AllowGet);
}
#endregion
#region
/// <summary>
/// 读取/Content/Menu 的所有模块图标
/// </summary>
/// <returns></returns>
public JsonResult GetMenuImg()
{
List<object> obj = new List<object>();
string[] imgExtension = new string[] { ".png", ".gif" };
string folder = Server.MapPath("~/Content/Images/Menu");
DirectoryInfo TheFolder = new DirectoryInfo(folder);
foreach (FileInfo info in TheFolder.GetFiles())
{
if (imgExtension.Contains(info.Extension))
{
obj.Add(new { name = info.Name, imgurl = "/Content/Images/Menu/" + info.Name });
}
}
return Json(obj, JsonRequestBehavior.AllowGet);
}
#endregion
}
}