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.
1113 lines
42 KiB
1113 lines
42 KiB
using System;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Web.Mvc;
|
|
using QMFrameWork.WebUI.Attribute;
|
|
using QMAPP.Web.Models.Sys;
|
|
using QMFrameWork.Data;
|
|
using QMAPP.Entity.Sys;
|
|
using QMAPP.Common.Web.Util;
|
|
using QMAPP.Common.Web.Controllers;
|
|
using QMFrameWork.WebUI.DataSource;
|
|
using QMAPP.ServicesAgent;
|
|
using QMFrameWork.Common.Serialization;
|
|
using QMAPP.Common.Web.Models;
|
|
using QMAPP.Entity;
|
|
using System.Data;
|
|
|
|
namespace QMAPP.Web.Controllers
|
|
{
|
|
/// <summary>
|
|
/// 用户管理
|
|
/// </summary>
|
|
[SessionState(System.Web.SessionState.SessionStateBehavior.ReadOnly)]
|
|
public class UserController : QController
|
|
{
|
|
#region 用户列表
|
|
|
|
/// <summary>
|
|
/// 加载用户列表
|
|
/// </summary>
|
|
/// <returns>结果</returns>
|
|
[HandleException]
|
|
public ActionResult UserList(bool? callBack)
|
|
{
|
|
string templateID = Request.QueryString["templateID"];
|
|
UserListModel seachModel = new UserListModel();
|
|
if (callBack == true)
|
|
TryGetSelectBuffer<UserListModel>(out seachModel);
|
|
else
|
|
seachModel.ActivateFlg = "1";
|
|
|
|
seachModel.rownumbers = false;
|
|
seachModel.url = "/User/GetList";
|
|
|
|
//#region 应用查询模板
|
|
|
|
//seachModel = this.ApplyQueryTemplate<UserListModel>("UserList", seachModel, templateID);
|
|
|
|
//#endregion
|
|
|
|
return View("UserList", seachModel);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 获取用户信息列表
|
|
/// </summary>
|
|
/// <param name="callBack">是否回调</param>
|
|
/// <returns>用户信息列表</returns>
|
|
[HandleException]
|
|
public ActionResult GetList(bool? callBack)
|
|
{
|
|
UserListModel seachModel = new UserListModel();
|
|
DataPage page = new DataPage();
|
|
|
|
User condition = null;
|
|
try
|
|
{
|
|
//获取查询对象
|
|
seachModel.ActivateFlg = "1";
|
|
seachModel = GetModel<UserListModel>(seachModel);
|
|
|
|
#region 获取缓存值
|
|
if (callBack != null)
|
|
{
|
|
TryGetSelectBuffer<UserListModel>(out seachModel);
|
|
}
|
|
else
|
|
{
|
|
//保存搜索条件
|
|
SetSelectBuffer<UserListModel>(seachModel);
|
|
}
|
|
|
|
#endregion
|
|
|
|
//获取前台分页控件的分页大小
|
|
page = this.GetDataPage(seachModel);
|
|
|
|
//获取数据
|
|
condition = CopyToModel<User, UserListModel>(seachModel);
|
|
QMAPP.ServicesAgent.ServiceAgent agent = this.GetServiceAgent();
|
|
page = agent.InvokeServiceFunction<DataPage>("UserManageBLL_GetList", condition, page);
|
|
|
|
//转换结果格式
|
|
DataGridResult<User> result = new DataGridResult<User>();
|
|
result.Total = page.RecordCount;
|
|
result.Rows = JsonConvertHelper.GetDeserialize<List<User>>(page.Result.ToString());
|
|
|
|
//显示用户类别名称
|
|
Dictionary<string, string> utDicts = null;
|
|
QMFrameWork.Common.Util.ModelDictionaryHandler.TryGetModelDictionary("UserType", out utDicts);
|
|
foreach (User u in result.Rows)
|
|
{
|
|
if (string.IsNullOrEmpty(u.UserType) == true)
|
|
continue;
|
|
if (utDicts.ContainsKey(u.UserType) == false)
|
|
continue;
|
|
|
|
u.UserType = utDicts[u.UserType];
|
|
}
|
|
|
|
return Content(result.GetJsonSource());
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw ex;
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region 编辑
|
|
|
|
/// <summary>
|
|
/// 编辑载入
|
|
/// </summary>
|
|
/// <returns>处理结果</returns>
|
|
[HandleException]
|
|
public ActionResult UserEdit()
|
|
{
|
|
UserModel model = new UserModel();
|
|
string UserID = Request.Params["UserID"];
|
|
User user = new User();
|
|
try
|
|
{
|
|
if (string.IsNullOrEmpty(UserID) == false)
|
|
{
|
|
//修改获取原数据
|
|
user.UserID = UserID;
|
|
|
|
QMAPP.ServicesAgent.ServiceAgent agent = this.GetServiceAgent();
|
|
user = agent.InvokeServiceFunction<User>("UserManageBLL_Get", user);
|
|
|
|
model = CopyToModel<UserModel, User>(user);
|
|
if (string.IsNullOrEmpty(model.OrgaID)==false)
|
|
model.OrgaID = model.OrgaID.Trim();
|
|
model.isEdit = "true";
|
|
|
|
model.CkActivateFlg = user.ActivateFlg == "1" ? true : false;
|
|
}
|
|
else
|
|
{
|
|
model.PassWord = "qm";
|
|
model.RepartPassWord = "qm";
|
|
model.UserType = "PU";
|
|
model.CkActivateFlg = true;
|
|
}
|
|
return View(model);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw ex;
|
|
}
|
|
}
|
|
|
|
#region 组织机构信息下拉菜单
|
|
|
|
public ActionResult GetOrgaList()
|
|
{
|
|
Orgaization orgaModel = new Orgaization();
|
|
List<Orgaization> list = new List<Orgaization>();
|
|
QMAPP.ServicesAgent.ServiceAgent agent = this.GetServiceAgent();
|
|
|
|
list = agent.InvokeServiceFunction<List<Orgaization>>("UserManageBLL_GetUserOrgaList", "");
|
|
|
|
ComboboxResult model = new ComboboxResult();
|
|
foreach (Orgaization o in list)
|
|
{
|
|
model.Add(new ComboboxItem { ID = o.OrgaID, Text = o.OrgaDESC });
|
|
}
|
|
|
|
return Content(model.ToString());
|
|
}
|
|
public ActionResult GetOrgaListNew()
|
|
{
|
|
Orgaization orgaModel = new Orgaization();
|
|
List<Orgaization> list = new List<Orgaization>();
|
|
QMAPP.ServicesAgent.ServiceAgent agent = this.GetServiceAgent();
|
|
|
|
list = agent.InvokeServiceFunction<List<Orgaization>>("UserManageBLL_GetUserOrgaList", "");
|
|
|
|
//ComboboxResult model = new ComboboxResult();
|
|
//foreach (Orgaization o in list)
|
|
//{
|
|
// model.Add(new ComboboxItem { ID = o.OrgaID, Text = o.OrgaDESC });
|
|
//}
|
|
|
|
//return Content(model.ToString());
|
|
return Content(QMFrameWork.Common.Serialization.JsonConvertHelper.GetSerializes(list));
|
|
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region 角色信息树
|
|
/// <summary>
|
|
/// 角色信息树
|
|
/// </summary>
|
|
/// <returns>处理结果</returns>
|
|
public ActionResult GetTreeRoles()
|
|
{
|
|
List<TreeNodeResult> list = new List<TreeNodeResult>();
|
|
Role role = new Role();
|
|
PowerUtil pu = new PowerUtil();
|
|
pu.OwnRoles = new List<Role>();
|
|
//选择的用户编号
|
|
string userID = Request.QueryString["userID"];
|
|
string organID = Request.QueryString["organID"];
|
|
try
|
|
{
|
|
if (string.IsNullOrEmpty(organID) == true)
|
|
{
|
|
return Content(TreeNodeResult.GetResultJosnS(list.ToArray()));
|
|
}
|
|
|
|
if (string.IsNullOrEmpty(userID) == true)
|
|
{
|
|
userID= AccountController.GetLoginInfo().UserID;
|
|
}
|
|
//获取角色信息
|
|
User user = new User();
|
|
user.UserID = userID;
|
|
|
|
QMAPP.ServicesAgent.ServiceAgent agent = this.GetServiceAgent();
|
|
user = agent.InvokeServiceFunction<User>("UserManageBLL_Get", user);
|
|
|
|
if (user != null)
|
|
{
|
|
foreach (UserRole userrole in user.Roles)
|
|
{
|
|
pu.OwnRoles.Add(new Role { RoleID = userrole.RoleID, RoleDESC = userrole.RoleDESC });
|
|
}
|
|
}
|
|
|
|
//获取所选机构对应角色
|
|
role.Roles = agent.InvokeServiceFunction<List<Role>>("RoleManageBLL_GetRolesByOrgan", organID);
|
|
|
|
foreach (Role singlerole in role.Roles)
|
|
{
|
|
TreeNodeResult node = new TreeNodeResult();
|
|
node.Tid = singlerole.RoleID;
|
|
node.Ttext = singlerole.RoleDESC;
|
|
//循环已经存在的角色,如果去的也页面是新建画面
|
|
if (string.IsNullOrEmpty(Request.Params["userID"]) != true)
|
|
{
|
|
foreach (Role selected in pu.OwnRoles)
|
|
{
|
|
//如果当前角色在选中范围内,结束循环,否者继续
|
|
if (selected.RoleID == singlerole.RoleID)
|
|
{
|
|
singlerole.Selected = true;
|
|
break;
|
|
}
|
|
else
|
|
{
|
|
singlerole.Selected = false;
|
|
}
|
|
}
|
|
}
|
|
node.TChecked = singlerole.Selected;
|
|
|
|
list.Add(node);
|
|
}
|
|
return Content(TreeNodeResult.GetResultJosnS(list.ToArray()));
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw ex;
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region 权限信息树
|
|
/// <summary>
|
|
/// 权限信息树
|
|
/// </summary>
|
|
/// <returns>处理结果</returns>
|
|
public ActionResult GetTreePowers()
|
|
{
|
|
List<TreeNodeResult> list = new List<TreeNodeResult>();
|
|
List<PowerInfo> powers = null;
|
|
PowerUtil pu = new PowerUtil();
|
|
pu.OwnPowers = new List<PowerInfo>();
|
|
string userID = Request.Params["userID"];
|
|
string powerFile = null;
|
|
string systemID = Request.QueryString["SystemID"];
|
|
try
|
|
{
|
|
if (string.IsNullOrEmpty(userID) == false)
|
|
{
|
|
//获取用户信息
|
|
User user = new User();
|
|
user.UserID = userID;
|
|
//UserManageBLL userBll = BLLFactory.CreateBLL<UserManageBLL>();
|
|
//user = userBll.Get(user);
|
|
QMAPP.ServicesAgent.ServiceAgent agent = this.GetServiceAgent();
|
|
user = agent.InvokeServiceFunction<User>("UserManageBLL_Get", user);
|
|
|
|
foreach (UserAuthority power in user.OptionAuthority)
|
|
{
|
|
pu.OwnPowers.Add(new PowerInfo { PowerID = power.AuthorityID });
|
|
}
|
|
}
|
|
|
|
//获取系统权限信息
|
|
if (systemID == null)
|
|
systemID = "Main";
|
|
powerFile = MvcApplication.PhysicsRootPath + @"App_Data\" + systemID + "Power.xml";
|
|
powers = pu.GetAllPowerInfos(powerFile);
|
|
|
|
|
|
foreach (PowerInfo info in powers)
|
|
{
|
|
TreeNodeResult node = new TreeNodeResult();
|
|
node.Tid = info.PowerID;
|
|
node.Ttext = info.PowerDes;
|
|
node.TChecked = info.Selected;
|
|
//添加子权限
|
|
this.BuildChildItems(node, info.ChildPowers, pu);
|
|
|
|
list.Add(node);
|
|
}
|
|
return Content(TreeNodeResult.GetResultJosnS(list.ToArray()));
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw ex;
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// 创建子权限
|
|
/// </summary>
|
|
/// <param name="parentNode">父节点</param>
|
|
/// <param name="childPowers">子权限</param>
|
|
/// <param name="pu">已经选中的权限列表</param>
|
|
private void BuildChildItems(TreeNodeResult parentNode, List<PowerInfo> childPowers, PowerUtil pu)
|
|
{
|
|
foreach (PowerInfo info in childPowers)
|
|
{
|
|
TreeNodeResult node = new TreeNodeResult();
|
|
node.Tid = info.PowerID;
|
|
node.Ttext = info.PowerDes;
|
|
node.TChecked = info.Selected;
|
|
if (info.ChildPowers != null)
|
|
{
|
|
//添加子权限
|
|
this.BuildChildItems(node, info.ChildPowers, pu);
|
|
}
|
|
parentNode.AddchildNode(node);
|
|
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region 当前用户所具有的权限信息树
|
|
/// <summary>
|
|
/// 当前用户所具有的权限信息树
|
|
/// </summary>
|
|
/// <returns>处理结果</returns>
|
|
public ActionResult GetTreeAllPowers()
|
|
{
|
|
List<TreeNodeResult> list = new List<TreeNodeResult>();
|
|
List<PowerInfo> powers = null;
|
|
PowerUtil pu = new PowerUtil();
|
|
pu.OwnPowers = new List<PowerInfo>();
|
|
string userID = Request.Params["userID"];
|
|
//ServiceAgent wcfAgent = this.GetServiceAgent();
|
|
try
|
|
{
|
|
if (string.IsNullOrEmpty(userID) == false)
|
|
{
|
|
//获取用户信息
|
|
User user = new User();
|
|
user.UserID = userID;
|
|
|
|
//UserManageBLL userBll = BLLFactory.CreateBLL<UserManageBLL>();
|
|
//user = userBll.Get(user);
|
|
QMAPP.ServicesAgent.ServiceAgent agent = this.GetServiceAgent();
|
|
user = agent.InvokeServiceFunction<User>("UserManageBLL_Get", user);
|
|
|
|
foreach (UserAuthority power in user.Authoritys)
|
|
{
|
|
//如果当前有权限,那么判断当前权限的上级是否在内存中,如果不在那么添加
|
|
//------------------2013.11.13 add start-------------------------
|
|
if (!pu.OwnPowers.Cast<PowerInfo>().Any(i => i.PowerID == power.AuthorityID.Substring(0, 2) + "000000"))
|
|
{
|
|
|
|
pu.OwnPowers.Add(new PowerInfo { PowerID = power.AuthorityID.Substring(0, 2) + "000000" });
|
|
}
|
|
if (!pu.OwnPowers.Cast<PowerInfo>().Any(i => i.PowerID == power.AuthorityID.Substring(0, 4) + "0000"))
|
|
{
|
|
pu.OwnPowers.Add(new PowerInfo { PowerID = power.AuthorityID.Substring(0, 4) + "0000" });
|
|
}
|
|
if (!pu.OwnPowers.Cast<PowerInfo>().Any(i => i.PowerID == power.AuthorityID.Substring(0, 6) + "00"))
|
|
{
|
|
pu.OwnPowers.Add(new PowerInfo { PowerID = power.AuthorityID.Substring(0, 6) + "00" });
|
|
}
|
|
//------------------2013.11.13 add end-------------------------
|
|
pu.OwnPowers.Add(new PowerInfo { PowerID = power.AuthorityID });
|
|
pu.OwnPowers = pu.OwnPowers.OrderBy(i => i.PowerID).ToList();
|
|
}
|
|
}
|
|
|
|
//获取当前登录系统的用户,全部权限信息
|
|
powers = pu.GetAllPowerInfos(MvcApplication.PhysicsRootPath + @"App_Data\Power.xml");
|
|
|
|
foreach (PowerInfo info in powers)
|
|
{
|
|
TreeNodeResult node = new TreeNodeResult();
|
|
node.Tid = info.PowerID;
|
|
node.Ttext = info.PowerDes;
|
|
node.TChecked = info.Selected;
|
|
//添加子权限
|
|
this.AllBuildChildItems(node, info.ChildPowers, pu);
|
|
|
|
//如果当前有子权限,那么选择上级权限
|
|
if (node.Tchildren.Length > 0)
|
|
{
|
|
list.Add(node);
|
|
}
|
|
}
|
|
return Content(TreeNodeResult.GetResultJosnS(list.ToArray()));
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw ex;
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// 创建当前用户所有的子权限
|
|
/// </summary>
|
|
/// <param name="parentNode">父节点</param>
|
|
/// <param name="childPowers">子权限</param>
|
|
/// <param name="pu">已经选中的权限列表</param>
|
|
private void AllBuildChildItems(TreeNodeResult parentNode, List<PowerInfo> childPowers, PowerUtil pu)
|
|
{
|
|
foreach (PowerInfo info in childPowers)
|
|
{
|
|
TreeNodeResult node = new TreeNodeResult();
|
|
node.Tid = info.PowerID;
|
|
node.Ttext = info.PowerDes;
|
|
//循环已经存在的权限,
|
|
foreach (PowerInfo selected in pu.OwnPowers)
|
|
{
|
|
//如果当前权限在选中范围内,结束循环,否者继续
|
|
if (selected.PowerID == info.PowerID)
|
|
{
|
|
info.Selected = true;
|
|
break;
|
|
}
|
|
else
|
|
{
|
|
info.Selected = false;
|
|
}
|
|
}
|
|
node.TChecked = info.Selected;
|
|
|
|
if (info.ChildPowers != null)
|
|
{
|
|
//添加子权限
|
|
this.AllBuildChildItems(node, info.ChildPowers, pu);
|
|
}
|
|
//如果当前子权限被选中,那么输出,否者不输出子权限。
|
|
if (node.TChecked)
|
|
{
|
|
parentNode.AddchildNode(node);
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
#endregion
|
|
|
|
#region 保存
|
|
|
|
/// <summary>
|
|
/// 保存
|
|
/// </summary>
|
|
/// <param name="model"></param>
|
|
/// <returns>处理结果</returns>
|
|
[HttpPost]
|
|
[HandleException]
|
|
public ActionResult UserSave(UserModel saveModel)
|
|
{
|
|
User user = null;
|
|
QMAPP.ServicesAgent.ServiceAgent agent = this.GetServiceAgent();
|
|
try
|
|
{
|
|
user = CopyToModel<User, UserModel>(saveModel);
|
|
user.ActivateFlg = saveModel.CkActivateFlg == true ? "1" : "0";
|
|
|
|
User tmpuser = new User();
|
|
if (string.IsNullOrEmpty(saveModel.isEdit) == true)
|
|
{
|
|
//tmpuser = userBll.GetLoginUser(user);
|
|
tmpuser = agent.InvokeServiceFunction<User>("UserManageBLL_GetLoginUser", user);
|
|
|
|
if (tmpuser != null && tmpuser.UserName != "")
|
|
{
|
|
SetMessage("当前保存的登陆账号已经存在,请修改!");
|
|
return View("UserEdit", saveModel);
|
|
}
|
|
|
|
}
|
|
//处理所选角色
|
|
string[] roles = null;
|
|
if (saveModel.SelectedRoles != null)
|
|
{
|
|
roles = saveModel.SelectedRoles.Split(":".ToArray());
|
|
user.Roles = new List<UserRole>();
|
|
foreach (string role in roles)
|
|
{
|
|
user.Roles.Add(new UserRole
|
|
{
|
|
UserID = user.UserID,
|
|
RoleID = role,
|
|
CreateTime = DateTime.Now,
|
|
UpdateTime = DateTime.Now,
|
|
CreateUser = AccountController.GetLoginInfo().UserID,
|
|
UpdateUser = AccountController.GetLoginInfo().UserID
|
|
});
|
|
}
|
|
}
|
|
|
|
string powerList = "";
|
|
powerList += string.IsNullOrEmpty(saveModel.SelectedPowers1) == false ? saveModel.SelectedPowers1 : "";
|
|
powerList += string.IsNullOrEmpty(saveModel.SelectedPowers2) == false ? ":" + saveModel.SelectedPowers2 : "";
|
|
powerList += string.IsNullOrEmpty(saveModel.SelectedPowers3) == false ? ":" + saveModel.SelectedPowers3 : "";
|
|
powerList += string.IsNullOrEmpty(saveModel.SelectedPowers4) == false ? ":" + saveModel.SelectedPowers4 : "";
|
|
powerList += string.IsNullOrEmpty(saveModel.SelectedPowers5) == false ? ":" + saveModel.SelectedPowers5 : "";
|
|
|
|
//处理所选权限
|
|
string[] Authoritys = null;
|
|
user.Authoritys = new List<UserAuthority>();
|
|
if (string.IsNullOrEmpty(powerList)==false)
|
|
{
|
|
Authoritys = powerList.Split(":".ToArray());
|
|
foreach (string authority in Authoritys)
|
|
{
|
|
if (string.IsNullOrEmpty(authority) == true)
|
|
{
|
|
continue;
|
|
}
|
|
|
|
bool isExists = user.Authoritys.Exists(p => p.AuthorityID == authority);
|
|
|
|
if (isExists == true)
|
|
continue;
|
|
|
|
user.Authoritys.Add(new UserAuthority
|
|
{
|
|
UserID = user.UserID,
|
|
AuthorityID = authority,
|
|
OrgaID = user.OrgaID,
|
|
CreateTime = DateTime.Now,
|
|
UpdateTime = DateTime.Now,
|
|
CreateUser = AccountController.GetLoginInfo().UserID,
|
|
UpdateUser = AccountController.GetLoginInfo().UserID
|
|
});
|
|
}
|
|
}
|
|
|
|
//保存
|
|
if (string.IsNullOrEmpty(saveModel.isEdit) == true)
|
|
{
|
|
//新增
|
|
agent.InvokeServiceFunction<int>("UserManageBLL_Insert", user);
|
|
}
|
|
else
|
|
{
|
|
//修改
|
|
agent.InvokeServiceFunction<int>("UserManageBLL_Update", user);
|
|
}
|
|
|
|
return this.GetJsViewResult(string.Format("parent.List(1);parent.showTitle('{0}');parent.closeAppWindow1();"
|
|
, AppResource.SaveMessge));
|
|
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw ex;
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
|
|
#endregion
|
|
|
|
#region 删除
|
|
|
|
/// <summary>
|
|
/// 删除用户信息
|
|
/// </summary>
|
|
/// <returns>结果</returns>
|
|
[HttpPost]
|
|
[HandleException]
|
|
public ActionResult UserDelete()
|
|
{
|
|
string selectKey = Request.Form["selectKey"];
|
|
string[] arraydata = selectKey.Split(":".ToCharArray());
|
|
//UserManageBLL userBll = null;
|
|
ArrayList alist = new ArrayList();
|
|
try
|
|
{
|
|
for (int i = 0; i < arraydata.Length; i++)
|
|
{
|
|
alist.Add(arraydata[i]);
|
|
}
|
|
QMAPP.ServicesAgent.ServiceAgent agent = this.GetServiceAgent();
|
|
int count = agent.InvokeServiceFunction<int>("UserManageBLL_BatchDelete", alist);
|
|
|
|
if (alist.Count != count)
|
|
{
|
|
if (count == 0)
|
|
{
|
|
SetMessage("选中的用户已激活,无法删除。");
|
|
}
|
|
else
|
|
{
|
|
SetMessage(string.Format("删除完成(其中存在{0}个已激活的用户,无法删除)。", alist.Count - count));
|
|
}
|
|
}
|
|
else
|
|
{
|
|
SetMessage(AppResource.DeleteMessage);
|
|
}
|
|
|
|
|
|
return UserList(true);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw ex;
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region 设置密码
|
|
|
|
/// <summary>
|
|
/// 设置密码载入
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
[HandleException]
|
|
public ActionResult SetPassword()
|
|
{
|
|
string userID = Request.QueryString["userID"];
|
|
UserModel model = new UserModel();
|
|
User user = new User();
|
|
List<UserRole> selectRoles = new List<UserRole>();
|
|
//UserManageBLL userBll = null;
|
|
try
|
|
{
|
|
if (string.IsNullOrEmpty(userID) == false)
|
|
{
|
|
//修改指定用户
|
|
user.UserID = userID;
|
|
}
|
|
else
|
|
{
|
|
//修改当前用户
|
|
user.UserID = AccountController.GetLoginInfo().UserID;
|
|
}
|
|
//获取原信息
|
|
//userBll = BLLFactory.CreateBLL<UserManageBLL>();
|
|
//user = userBll.Get(user);
|
|
QMAPP.ServicesAgent.ServiceAgent agent = this.GetServiceAgent();
|
|
user = agent.InvokeServiceFunction<User>("UserManageBLL_Get", user);
|
|
user.PassWord = null;
|
|
model = CopyToModel<UserModel, User>(user);
|
|
|
|
return View(model);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw ex;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 设置密码
|
|
/// </summary>
|
|
/// <param name="model">用户密码信息</param>
|
|
/// <returns></returns>
|
|
[HttpPost]
|
|
[HandleException]
|
|
public ActionResult SetPassword(UserModel model)
|
|
{
|
|
User user = null;
|
|
try
|
|
{
|
|
user = CopyToModel<User, UserModel>(model);
|
|
|
|
//userBll = BLLFactory.CreateBLL<UserManageBLL>();
|
|
//userBll.SetPassWord(user);
|
|
QMAPP.ServicesAgent.ServiceAgent agent = this.GetServiceAgent();
|
|
agent.InvokeServiceFunction<User>("UserManageBLL_SetPassWord", user);
|
|
|
|
return this.GetJsViewResult(string.Format("parent.showTitle('{0}');parent.closeAppWindow1();", "修改成功。"));
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw ex;
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region 获取用户列表
|
|
|
|
[HandleException]
|
|
public ActionResult GetUserList()
|
|
{
|
|
try
|
|
{
|
|
List<User> list = null;
|
|
|
|
QMAPP.ServicesAgent.ServiceAgent agent = this.GetServiceAgent();
|
|
list = agent.InvokeServiceFunction<List<User>>("UserManageBLL_GetAllUser",new User());
|
|
|
|
ComboboxResult model = new ComboboxResult();
|
|
foreach (User o in list)
|
|
{
|
|
model.Add(new ComboboxItem { ID = o.UserID, Text = o.UserName });
|
|
}
|
|
|
|
return Content(model.ToString());
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw ex;
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region 业务权限设置
|
|
|
|
[HandleException]
|
|
public ActionResult SetUserBusiPower()
|
|
{
|
|
UserPowerModel model = new UserPowerModel();
|
|
string userID = Request.Params["userID"];
|
|
ServiceAgent wcfAgent = this.GetServiceAgent();
|
|
UserBusinessPower info = new UserBusinessPower();
|
|
int seq = 0;
|
|
try
|
|
{
|
|
|
|
//调用服务获取数据
|
|
info.UserID = userID;
|
|
info = wcfAgent.InvokeServiceFunction<UserBusinessPower>("UserManageBLL_GetBusinessPower", info);
|
|
|
|
//绑定数据
|
|
model = CopyToModel<UserPowerModel,UserBusinessPower>(info);
|
|
|
|
//仓库权限
|
|
DateGridResult<UserCorpModel> corpResult = new DateGridResult<UserCorpModel>();
|
|
corpResult.Total = info.CorpPowers.Count;
|
|
corpResult.Rows = new List<UserCorpModel>();
|
|
seq = 1;
|
|
model.SelectedCorp = "";
|
|
foreach (UserCorpPower corp in info.CorpPowers)
|
|
{
|
|
model.SelectedCorp += "," + corp.CORPID;
|
|
corpResult.Rows.Add(new UserCorpModel { Seq = seq, CORPID = corp.CORPID, CORPCODE = corp.CORPCODE, CORPNAME = corp.CORPNAME, DeleteAction = "deleteCorp('" + corp.CORPID + "')" });
|
|
seq++;
|
|
}
|
|
if (model.SelectedCorp != "")
|
|
model.SelectedCorp = model.SelectedCorp.Substring(1);
|
|
model.CorpList = corpResult.GetJsonSource();
|
|
|
|
//路线权限
|
|
DateGridResult<UserLineModel> lineResult = new DateGridResult<UserLineModel>();
|
|
lineResult.Total = info.LinePowers.Count;
|
|
lineResult.Rows = new List<UserLineModel>();
|
|
seq = 1;
|
|
foreach (UserLinePower line in info.LinePowers)
|
|
{
|
|
lineResult.Rows.Add(new UserLineModel { Seq = seq, CORPID = line.CORPID, CORPNAME = line.CORPNAME, LINEID = line.LINEID, LINENO = line.LINENO, LINENAME = line.LINENAME, DeleteAction = "deleteLine('" + line.LINEID + "')" });
|
|
seq++;
|
|
}
|
|
model.LineList = lineResult.GetJsonSource();
|
|
|
|
//零件类别权限
|
|
DateGridResult<UserMatSortModel> matSortResult = new DateGridResult<UserMatSortModel>();
|
|
matSortResult.Total = info.MatSortPowers.Count;
|
|
matSortResult.Rows = new List<UserMatSortModel>();
|
|
seq = 1;
|
|
foreach (UserMatSortPower matSort in info.MatSortPowers)
|
|
{
|
|
matSortResult.Rows.Add(new UserMatSortModel { Seq = seq, MATSORTID = matSort.MATSORTID, MATSORTNO = matSort.MATSORTNO, MATSORTNAME = matSort.MATSORTNAME, DeleteAction = "deleteMatSort('" + matSort.MATSORTID + "')" });
|
|
seq++;
|
|
}
|
|
model.MatSortList = matSortResult.GetJsonSource();
|
|
|
|
//要货地权限
|
|
DateGridResult<UserReqPlaceModel> reqPlaceResult = new DateGridResult<UserReqPlaceModel>();
|
|
reqPlaceResult.Total = info.ReqPlacePowers.Count;
|
|
reqPlaceResult.Rows = new List<UserReqPlaceModel>();
|
|
seq = 1;
|
|
foreach (UserReqPlacePower reqPlace in info.ReqPlacePowers)
|
|
{
|
|
reqPlaceResult.Rows.Add(new UserReqPlaceModel { Seq = seq, PLACEDISID = reqPlace.PLACEDISID, PLACEDISNO = reqPlace.PLACEDISNO, DESCRIBE_SITE = reqPlace.DESCRIBE_SITE, DeleteAction = "deleteReqPlace('" + reqPlace.PLACEDISID + "')" });
|
|
seq++;
|
|
}
|
|
model.RequestPlaceList = reqPlaceResult.GetJsonSource();
|
|
|
|
//发货地权限
|
|
DateGridResult<UserSendPlaceModel> sendPlaceResult = new DateGridResult<UserSendPlaceModel>();
|
|
sendPlaceResult.Total = info.SendPlacePowers.Count;
|
|
sendPlaceResult.Rows = new List<UserSendPlaceModel>();
|
|
seq = 1;
|
|
foreach (UserSendPlacePower sendPlace in info.SendPlacePowers)
|
|
{
|
|
sendPlaceResult.Rows.Add(new UserSendPlaceModel { Seq = seq, SENDPLACEID = sendPlace.SENDPLACEID, SENDPLACENO = sendPlace.SENDPLACENO, SENDPLACENAME = sendPlace.SENDPLACENAME, DeleteAction = "deleteSendPlace('" + sendPlace.SENDPLACEID + "')" });
|
|
seq++;
|
|
}
|
|
model.SendPlaceList = sendPlaceResult.GetJsonSource();
|
|
|
|
return View(model);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw ex;
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region 保存业务权限
|
|
|
|
/// <summary>
|
|
/// 保存业务权限
|
|
/// </summary>
|
|
/// <param name="model">业务权限信息</param>
|
|
/// <returns></returns>
|
|
[ValidateInput(false)]
|
|
[HandleException]
|
|
public ActionResult UserBusiPowerSave(UserPowerModel model)
|
|
{
|
|
List<UserCorpModel> corps = null;
|
|
List<UserLineModel> lines = null;
|
|
List<UserMatSortModel> matSorts = null;
|
|
List<UserReqPlaceModel> reqPlaces = null;
|
|
List<UserSendPlaceModel> sendPlaces = null;
|
|
ServiceAgent wcfAgent = this.GetServiceAgent();
|
|
UserBusinessPower info = new UserBusinessPower();
|
|
try
|
|
{
|
|
info = CopyToModel<UserBusinessPower, UserPowerModel>(model);
|
|
|
|
//绑定仓库权限
|
|
corps = JsonConvertHelper.GetDeserialize<List<UserCorpModel>>(model.CorpList);
|
|
info.CorpPowers = new List<UserCorpPower>();
|
|
foreach (UserCorpModel corp in corps)
|
|
{
|
|
UserCorpPower c = new UserCorpPower();
|
|
c.CORPID = corp.CORPID;
|
|
info.CorpPowers.Add(c);
|
|
}
|
|
|
|
//绑定路线权限
|
|
lines = JsonConvertHelper.GetDeserialize<List<UserLineModel>>(model.LineList);
|
|
info.LinePowers = new List<UserLinePower>();
|
|
foreach (UserLineModel line in lines)
|
|
{
|
|
UserLinePower l = new UserLinePower();
|
|
l.LINEID = line.LINEID;
|
|
l.CORPID = line.CORPID;
|
|
info.LinePowers.Add(l);
|
|
}
|
|
|
|
//绑定零件类别权限
|
|
matSorts = JsonConvertHelper.GetDeserialize<List<UserMatSortModel>>(model.MatSortList);
|
|
info.MatSortPowers = new List<UserMatSortPower>();
|
|
foreach (UserMatSortModel matSort in matSorts)
|
|
{
|
|
UserMatSortPower m = new UserMatSortPower();
|
|
m.MATSORTID = matSort.MATSORTID;
|
|
info.MatSortPowers.Add(m);
|
|
}
|
|
|
|
|
|
//绑定要货地权限
|
|
reqPlaces = JsonConvertHelper.GetDeserialize<List<UserReqPlaceModel>>(model.RequestPlaceList);
|
|
info.ReqPlacePowers = new List<UserReqPlacePower>();
|
|
foreach (UserReqPlaceModel reqPlace in reqPlaces)
|
|
{
|
|
UserReqPlacePower m = new UserReqPlacePower();
|
|
m.PLACEDISID = reqPlace.PLACEDISID;
|
|
info.ReqPlacePowers.Add(m);
|
|
}
|
|
|
|
|
|
//绑定发货地权限
|
|
sendPlaces = JsonConvertHelper.GetDeserialize<List<UserSendPlaceModel>>(model.SendPlaceList);
|
|
info.SendPlacePowers = new List<UserSendPlacePower>();
|
|
foreach (UserSendPlaceModel sendPlace in sendPlaces)
|
|
{
|
|
UserSendPlacePower m = new UserSendPlacePower();
|
|
m.SENDPLACEID = sendPlace.SENDPLACEID;
|
|
info.SendPlacePowers.Add(m);
|
|
}
|
|
|
|
wcfAgent.InvokeServiceFunction("UserManageBLL_SaveBusinessPower", info);
|
|
|
|
return this.GetJsViewResult(string.Format("parent.List(1);parent.showTitle('{0}');parent.closeAppWindow1();"
|
|
, AppResource.SaveMessge));
|
|
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw ex;
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region 更新路线视图
|
|
|
|
/// <summary>
|
|
/// 更新路线视图
|
|
/// </summary>
|
|
/// <param name="corpID">仓库主键</param>
|
|
/// <returns></returns>
|
|
public ActionResult UpdateDivLine(string corpID)
|
|
{
|
|
UserPowerModel model = new UserPowerModel();
|
|
try
|
|
{
|
|
model.CorpID = corpID;
|
|
return PartialView("LineInputUserControl", model);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw ex;
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region 导出excel
|
|
|
|
/// <summary>
|
|
/// 导出excel
|
|
/// </summary>
|
|
/// <returns>结果</returns>
|
|
[HttpPost]
|
|
[HandleException]
|
|
public ActionResult ExportExcel()
|
|
{
|
|
UserListModel seachModel = null;
|
|
User condition = null;
|
|
DataTable exportDt = new DataTable();
|
|
QMAPP.ServicesAgent.ServiceAgent agent = this.GetServiceAgent();
|
|
PowerUtil pu = new PowerUtil();
|
|
string selectKey = Request.Form["selectKey"];
|
|
try
|
|
{
|
|
//获取查询对象
|
|
seachModel = GetModel<UserListModel>();
|
|
condition = CopyToModel<User, UserListModel>(seachModel);
|
|
|
|
//获取数据
|
|
exportDt = agent.InvokeServiceFunction<DataTable>("UserManageBLL_GetExportData", condition);
|
|
|
|
if (selectKey != "")
|
|
{
|
|
DataView dv = new DataView(exportDt);
|
|
string strWhere = "";
|
|
string[] list = selectKey.Split(":".ToCharArray());
|
|
foreach (string UserID in list)
|
|
{
|
|
strWhere += " UserID='" + UserID + "' or";
|
|
}
|
|
if (strWhere != "")
|
|
{
|
|
strWhere = strWhere.Remove((strWhere.Length - 2), 2);
|
|
}
|
|
dv.RowFilter = strWhere;
|
|
exportDt = dv.ToTable();
|
|
}
|
|
|
|
//导出
|
|
QMFrameWork.WebUI.Util.IEFileTool efTool = new QMFrameWork.WebUI.Util.IEFileTool();
|
|
return efTool.GetExcelFileResult("UserList", "用户信息.xls", exportDt);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw ex;
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
#region 导入excel
|
|
/// <summary>
|
|
/// 导入excel
|
|
/// </summary>
|
|
/// <returns>结果</returns>
|
|
[HttpPost]
|
|
[HandleException]
|
|
public ActionResult ImportExcel()
|
|
{
|
|
string fileName = Request.Form["fileName"];
|
|
ServiceAgent wcfAgent = this.GetServiceAgent();
|
|
ImportMessage dtResult = new ImportMessage();
|
|
List<User> list = new List<User>();
|
|
DataResult<ImportMessage> serviceResult = null;
|
|
DataTable tpdt = new DataTable();
|
|
try
|
|
{
|
|
QMFrameWork.WebUI.Util.IEFileTool efTool = new QMFrameWork.WebUI.Util.IEFileTool();
|
|
DataTable dt = null;
|
|
|
|
dt = this.GetTableByExcel("UserList", fileName, dt);
|
|
|
|
#region 去除重复
|
|
var query = from t in dt.AsEnumerable()
|
|
group t by new { t1 = t.Field<string>("LOGINUSERID") } into m
|
|
select new
|
|
{
|
|
LOGINUSERID = m.Key.t1,
|
|
EMPLOYEENO = m.Last().Field<string>("EMPLOYEENO"),
|
|
USERNAME = m.Last().Field<string>("USERNAME"),
|
|
ORGADESC = m.Last().Field<string>("ORGADESC"),
|
|
USERTYPE = m.Last().Field<string>("USERTYPE"),
|
|
ACTIVATEFLG = m.Last().Field<string>("ACTIVATEFLG"),
|
|
TEL = m.Last().Field<string>("TEL"),
|
|
EMAIL = m.Last().Field<string>("EMAIL"),
|
|
InfoError = m.Last().Field<string>("InfoError")
|
|
};
|
|
tpdt = dt.Clone();
|
|
foreach (var item in query.ToList())
|
|
{
|
|
DataRow dr = tpdt.NewRow();
|
|
dr["LOGINUSERID"] = item.LOGINUSERID;
|
|
dr["EMPLOYEENO"] = item.EMPLOYEENO;
|
|
dr["USERNAME"] = item.USERNAME;
|
|
dr["ORGADESC"] = item.ORGADESC;
|
|
dr["USERTYPE"] = item.USERTYPE;
|
|
dr["ACTIVATEFLG"] = item.ACTIVATEFLG;
|
|
dr["TEL"] = item.TEL;
|
|
dr["EMAIL"] = item.EMAIL;
|
|
dr["InfoError"] = item.InfoError;
|
|
tpdt.Rows.Add(dr);
|
|
}
|
|
#endregion
|
|
|
|
//转换格式
|
|
list = QMFrameWork.Common.Util.BindHelper.ConvertToList<User>(tpdt).ToList();
|
|
|
|
serviceResult = wcfAgent.InvokeServiceFunction<DataResult<ImportMessage>>("UserManageBLL_GetImportData", list);
|
|
|
|
if (serviceResult.Ex != null)
|
|
{
|
|
throw serviceResult.Ex;
|
|
}
|
|
|
|
if (serviceResult.Result.failureNum != 0)
|
|
{
|
|
|
|
foreach (RowError error in serviceResult.Result.Errors)
|
|
{
|
|
tpdt.Rows[error.Key - 1]["InfoError"] = error.Value;
|
|
}
|
|
|
|
ImportMessageModel model = new ImportMessageModel();
|
|
|
|
model.InfoName = "User";
|
|
model.ReturnUrl = "/User/UserList?callBack=true";
|
|
model.Message = serviceResult.Result;
|
|
model.ErrorDt = tpdt;
|
|
|
|
return new MessageOutputController().OutputImportMessage(model);
|
|
}
|
|
else
|
|
{
|
|
// 添加:通过消息代码获取资源文件值 李鹏飞 2015-03-20 开始
|
|
SetMessage(GetResourceValueByCode(serviceResult.MsgCode) + ",如下:<br/>"
|
|
+ "新增" + serviceResult.Result.insertNum + "条,"
|
|
+ "更新" + serviceResult.Result.updateNum + "条"
|
|
);
|
|
// 添加:通过消息代码获取资源文件值 李鹏飞 2015-03-20 结束
|
|
return UserList(true);
|
|
}
|
|
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw ex;
|
|
}
|
|
finally
|
|
{
|
|
System.IO.File.Delete(MvcApplication.TempPath + fileName);
|
|
}
|
|
}
|
|
#endregion
|
|
}
|
|
}
|
|
|