You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

239 lines
7.4 KiB
C#

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

using System.Collections;
using Microsoft.AspNetCore.Mvc;
using Estsh.Core.Services.IServices;
using Estsh.Core.Models;
using Estsh.Core.Controllers;
using Estsh.Core.Util;
/***************************************************************************************************
*
* 更新人sitong.dong
* 描述:角色模块控制类
* 修改时间2022.06.22
* 修改日志:系统迭代升级
*
**************************************************************************************************/
namespace Estsh.Core.Web.Controllers
{
/// <summary>
/// 角色管理模块的控制类
/// </summary>
public class RoleController : BaseController
{
private IRoleService service;
public RoleController(IRoleService _service)
{
service = _service;
}
//
// GET: /Role/
public ActionResult Index()
{
return View();
}
#region 角色管理
/// <summary>
/// 根据分页条件获取用户列表
/// </summary>
/// <param name="account"></param>
/// <param name="pager"></param>
/// <param name="direction"></param>
/// <param name="sort"></param>
/// <returns></returns>
public ActionResult getRoleListByPage(String roleName, Pager pager, String direction, String sort, String enabled = "Y")
{
Hashtable result = new Hashtable();
result.Add("pager.pageNo", pager.pageNo);
Hashtable dataHt = this.service.getRoleListByPage(roleName, pager, direction, sort, enabled);
result.Add("rows", dataHt["dataList"]);
result.Add("pager.totalRows", dataHt["totalCount"]);
result.Add("sort", sort);
result.Add("direction", direction);
return Json(result);
}
public ActionResult getRoleMenuTree(String roleId)
{
Hashtable result = new Hashtable();
ArrayList treeNodes = new ArrayList();
treeNodes = this.service.getRoleMenuTree(roleId);
result.Add("treeNodes", treeNodes);
return Json(result);
}
/// <summary>
/// 保存角色数据
/// </summary>
/// <returns></returns>
public ActionResult saveRoleInfo()
{
String editType = Request.Form["editType"].ToString();
String roleId = Request.Form["roleId"].ToString();
String roleName = Request.Form["roleName"].ToString();
String roleDesc = Request.Form["roleDesc"].ToString();
String enabled = Request.Form["enabled"].ToString();
String menuTree = Request.Form["menuTree1"].ToString();
String opMenuTree = Request.Form["opMenuTree"].ToString();
SysRole sysRole = new SysRole();
sysRole.RoleName = roleName;
sysRole.RoleDesc = roleDesc;
sysRole.Enabled = enabled;
String message = "";
String flag = "";
if (editType != null && editType.Trim().Equals("edit"))
{
try
{
sysRole.UpdateUserId = CurrentEmp.EmpId;
sysRole.RoleId =Convert.ToInt32( roleId);
int i = this.service.updateRoleInfo(sysRole, menuTree, opMenuTree);
if (i == 0)
{
message = "修改失败!";
flag = "Fail";
}
else
{
message = "修改成功!";
flag = "OK";
}
}
catch (Exception e)
{
message = "修改失败!";
flag = "Fail";
}
}
else
{
try
{
sysRole.CreateUserId = CurrentEmp.EmpId;
int i = this.service.saveRoleInfo(sysRole, menuTree, opMenuTree);
if (i == 2)
{
message = "角色:" +roleName +"已存在!";
flag = "Fail";
}
else if (i == 0)
{
message = "添加失败!";
flag = "Fail";
}
else
{
message = "添加成功!";
flag = "OK";
}
}
catch (Exception e)
{
message = "添加失败!";
flag = "Fail";
}
}
Hashtable result = new Hashtable();
result.Add("message", message);
result.Add("flag", flag);
return Json(result);
}
/// <summary>
/// 编辑角色信息
/// </summary>
/// <param name="ruid"></param>
/// <returns></returns>
public ActionResult editRoleInfo(String roleId)
{
if (!string.IsNullOrEmpty(roleId))
{
List<SysRole> roleInfo = this.service.getRoleDetail(roleId);
//Hashtable htRoleInfo = (Hashtable)roleInfo[0];
ViewData.Add("editType", "edit");
ViewData.Add("roleId", roleId);
ViewData.Add("roleName", roleInfo[0].RoleName);
ViewData.Add("roleDesc", roleInfo[0].RoleDesc);
ViewData.Add("enabled", roleInfo[0].Enabled);
}
else
{
ViewData.Add("editType", "new");
}
return View("editRole");
}
/// <summary>
/// 删除角色
/// </summary>
/// <param name="ids"></param>
/// <returns></returns>
public ActionResult deleteRole(String ids)
{
int delCount = 0;
try
{
delCount = this.service.deleteRole(ids);
}
catch (Exception e)
{
delCount = -1;
}
Hashtable result = new Hashtable();
result.Add("status", delCount);
return Json(result);
}
/// <summary>
/// 启用
/// </summary>
/// <param name="ids"></param>
/// <returns></returns>
public ActionResult onEnable(String ids)
{
int delCount = 0;
try
{
delCount = this.service.EnableData(ids);
}
catch (Exception e)
{
delCount = -1;
}
Hashtable result = new Hashtable();
result.Add("status", delCount);
return Json(result);
}
/// <summary>
/// 禁用
/// </summary>
/// <param name="ids"></param>
/// <returns></returns>
public ActionResult onDisable(String ids)
{
int delCount = 0;
try
{
delCount = this.service.DisableData(ids);
}
catch (Exception e)
{
delCount = -1;
}
Hashtable result = new Hashtable();
result.Add("status", delCount);
return Json(result);
}
#endregion
}
}