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.
563 lines
18 KiB
563 lines
18 KiB
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Collections;
|
|
using QMFrameWork.Data;
|
|
using QMFrameWork.Common.Encrypt;
|
|
using QMAPP.Entity.Sys;
|
|
using QMAPP.DAL.Sys;
|
|
using QMAPP.BLL.Dict;
|
|
using QMAPP.Entity;
|
|
using System.Data;
|
|
|
|
namespace QMAPP.BLL.Sys
|
|
{
|
|
/// 用户信息管理
|
|
/// 创建者:郭佳伟
|
|
/// 创建日期:2013.1.24
|
|
public class UserManageBLL : BaseBLL
|
|
{
|
|
#region 获取用户信息列表
|
|
|
|
/// <summary>
|
|
/// 获取全部用户
|
|
/// </summary>
|
|
/// <param name="condition">获取条件</param>
|
|
/// <returns>用户信息列表</returns>
|
|
public List<User> GetAllUser(User condition)
|
|
{
|
|
return new UserManageDAL().GetAllUser(condition);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 获取用户信息列表
|
|
/// </summary>
|
|
/// <param name="condition">条件</param>
|
|
/// <param name="page">数据页</param>
|
|
/// <returns>数据页</returns>
|
|
public DataPage GetList(User condition, DataPage page)
|
|
{
|
|
try
|
|
{
|
|
condition.CreateUser = this.LoginUser.UserID;
|
|
page = new UserManageDAL().GetList(condition, page);
|
|
|
|
////处理字典信息
|
|
//DictManagerBLL dictBll = new DictManagerBLL(DictKind.UserType);
|
|
//List<User> list = page.Result as List<User>;
|
|
//foreach (User info in list)
|
|
//{
|
|
// //替换用户类别显示值
|
|
// info.UserType = dictBll.GetDictValue(info.UserType);
|
|
//}
|
|
return page;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw ex;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 获取用户信息列表
|
|
/// </summary>
|
|
/// <param name="condition">条件</param>
|
|
/// <param name="page">数据页</param>
|
|
/// <returns>数据页</returns>
|
|
public List<User> GetAllUsers(User condition)
|
|
{
|
|
try
|
|
{
|
|
return new UserManageDAL().GetAllUsers(condition);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw ex;
|
|
}
|
|
}
|
|
//人员下拉框
|
|
public List<User> GetUserComboxSource()
|
|
{
|
|
try
|
|
{
|
|
return new UserManageDAL().GetUserComboxSource();
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw ex;
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region 获取用户信息
|
|
|
|
/// <summary>
|
|
/// 获取用户信息
|
|
/// </summary>
|
|
/// <param name="user">条件</param>
|
|
/// <returns>用户信息</returns>
|
|
public User Get(User user)
|
|
{
|
|
try
|
|
{
|
|
return new UserManageDAL().Get(user);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw ex;
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region 获取输入的登陆账户是否存在
|
|
|
|
/// <summary>
|
|
/// 获取输入的登陆账户是否存在
|
|
/// </summary>
|
|
/// <param name="user">条件</param>
|
|
/// <returns>用户信息信息</returns>
|
|
public User GetLoginUser(User user)
|
|
{
|
|
try
|
|
{
|
|
return new UserManageDAL().GetLoginUser(user);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw ex;
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
#region 获取组织机构下人员列表
|
|
|
|
/// <summary>
|
|
/// 获取组织机构下人员列表
|
|
/// </summary>
|
|
/// <param name="condition">条件</param>
|
|
/// <returns>同级别菜单列表</returns>
|
|
public List<User> GetOrgaUserList(string orgaID)
|
|
{
|
|
try
|
|
{
|
|
return new UserManageDAL().GetOrgaUserList(orgaID);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw ex;
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region 获取人员所属的组织机构列表
|
|
|
|
/// <summary>
|
|
/// 获取人员所属的组织机构列表
|
|
/// </summary>
|
|
/// <param name="condition">条件</param>
|
|
/// <returns>同级别菜单列表</returns>
|
|
public List<Orgaization> GetUserOrgaList(string userID)
|
|
{
|
|
try
|
|
{
|
|
return new UserManageDAL().GetUserOrgaList(userID);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw ex;
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
#region 插入用户信息信息
|
|
|
|
/// <summary>
|
|
/// 插入用户信息
|
|
/// </summary>
|
|
/// <param name="user">用户信息信息</param>
|
|
/// <returns>插入数</returns>
|
|
public int Insert(User user)
|
|
{
|
|
try
|
|
{
|
|
user.UserID = Guid.NewGuid().ToString();
|
|
user.UserDes = user.UserName;
|
|
user.CreateUser = this.LoginUser.UserID;
|
|
user.UpdateUser = this.LoginUser.UserID;
|
|
user.PassWord = DESEncrypt.Encrypt(user.PassWord);
|
|
user.DelFlag = "0";
|
|
|
|
return new UserManageDAL().Insert(user);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw ex;
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region 删除用户信息
|
|
|
|
/// <summary>
|
|
/// 删除用户信息信息
|
|
/// </summary>
|
|
/// <param name="user">用户信息信息</param>
|
|
/// <returns>删除个数</returns>
|
|
public int BatchDelete(ArrayList users)
|
|
{
|
|
int count = 0;
|
|
try
|
|
{
|
|
foreach (string user in users)
|
|
{
|
|
count += this.Delete(new User { UserID = user });
|
|
}
|
|
|
|
return count;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw ex;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 删除用户信息信息
|
|
/// </summary>
|
|
/// <param name="user">用户信息信息</param>
|
|
/// <returns>删除行数</returns>
|
|
public int Delete(User user)
|
|
{
|
|
int count = 0;
|
|
|
|
try
|
|
{
|
|
user.UpdateUser = this.LoginUser.UserID;
|
|
count = new UserManageDAL().Delete(user);
|
|
return count;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw ex;
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region 更新用户信息
|
|
|
|
/// <summary>
|
|
/// 更新用户信息
|
|
/// </summary>
|
|
/// <param name="user">用户信息信息</param>
|
|
/// <returns>更新个数</returns>
|
|
public int Update(User user)
|
|
{
|
|
try
|
|
{
|
|
user.UserDes = user.UserName;
|
|
user.UpdateUser = this.LoginUser.UserID;
|
|
return new UserManageDAL().Update(user);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw ex;
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region 设置密码
|
|
|
|
/// <summary>
|
|
/// 设置密码
|
|
/// </summary>
|
|
/// <param name="info">用户信息</param>
|
|
/// <returns>执行结果</returns>
|
|
public void SetPassWord(User info)
|
|
{
|
|
try
|
|
{
|
|
info.PassWord = DESEncrypt.Encrypt(info.PassWord);
|
|
info.UpdateUser = this.LoginUser.UserID;
|
|
info.UpdateTime = DateTime.Now;
|
|
new UserManageDAL().SetPassWord(info);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw ex;
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region 获取业务权限信息
|
|
|
|
/// <summary>
|
|
/// 获取业务权限信息
|
|
/// </summary>
|
|
/// <param name="userPower">获取条件</param>
|
|
/// <returns>业务权限信息</returns>
|
|
public UserBusinessPower GetBusinessPower(UserBusinessPower userPower)
|
|
{
|
|
try
|
|
{
|
|
userPower = new UserManageDAL().GetBusinessPower(userPower);
|
|
|
|
if (userPower.AllLines == null || userPower.AllLines.ToLower() == "1")
|
|
{
|
|
userPower.AllLines = "true";
|
|
}
|
|
else
|
|
{
|
|
userPower.AllLines = "false";
|
|
}
|
|
|
|
return userPower;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw ex;
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region 保存业务权限信息
|
|
|
|
/// <summary>
|
|
/// 保存业务权限信息
|
|
/// </summary>
|
|
/// <param name="userPower">业务权限信息</param>
|
|
public void SaveBusinessPower(UserBusinessPower userPower)
|
|
{
|
|
try
|
|
{
|
|
userPower.UpdateUser = this.LoginUser.UserID;
|
|
|
|
if (userPower.AllLines.ToLower() == "true")
|
|
userPower.AllLines = "1";
|
|
else
|
|
userPower.AllLines = "0";
|
|
|
|
//仓库权限
|
|
foreach (UserCorpPower corp in userPower.CorpPowers)
|
|
{
|
|
corp.ID = Guid.NewGuid().ToString();
|
|
corp.USERID = userPower.UserID;
|
|
corp.CREATEUSER = this.LoginUser.UserID;
|
|
corp.CREATEDATE = DateTime.Now;
|
|
corp.UPDATEUSER = this.LoginUser.UserID;
|
|
corp.UPDATEDATE = corp.CREATEDATE;
|
|
}
|
|
|
|
//仓库路线权限
|
|
foreach (UserLinePower line in userPower.LinePowers)
|
|
{
|
|
line.ID = Guid.NewGuid().ToString();
|
|
line.USERID = userPower.UserID;
|
|
line.CREATEUSER = this.LoginUser.UserID;
|
|
line.CREATEDATE = DateTime.Now;
|
|
line.UPDATEUSER = this.LoginUser.UserID;
|
|
line.UPDATEDATE = line.CREATEDATE;
|
|
}
|
|
|
|
//零件类别权限
|
|
foreach (UserMatSortPower corp in userPower.MatSortPowers)
|
|
{
|
|
corp.ID = Guid.NewGuid().ToString();
|
|
corp.USERID = userPower.UserID;
|
|
corp.CREATEUSER = this.LoginUser.UserID;
|
|
corp.CREATEDATE = DateTime.Now;
|
|
corp.UPDATEUSER = this.LoginUser.UserID;
|
|
corp.UPDATEDATE = corp.CREATEDATE;
|
|
}
|
|
|
|
//要货地权限
|
|
foreach (UserReqPlacePower reqPlace in userPower.ReqPlacePowers)
|
|
{
|
|
reqPlace.ID = Guid.NewGuid().ToString();
|
|
reqPlace.USERID = userPower.UserID;
|
|
reqPlace.CREATEUSER = this.LoginUser.UserID;
|
|
reqPlace.CREATEDATE = DateTime.Now;
|
|
reqPlace.UPDATEUSER = this.LoginUser.UserID;
|
|
reqPlace.UPDATEDATE = reqPlace.CREATEDATE;
|
|
}
|
|
|
|
//发货地权限
|
|
foreach (UserSendPlacePower sendPlace in userPower.SendPlacePowers)
|
|
{
|
|
sendPlace.ID = Guid.NewGuid().ToString();
|
|
sendPlace.USERID = userPower.UserID;
|
|
sendPlace.CREATEUSER = this.LoginUser.UserID;
|
|
sendPlace.CREATEDATE = DateTime.Now;
|
|
sendPlace.UPDATEUSER = this.LoginUser.UserID;
|
|
sendPlace.UPDATEDATE = sendPlace.CREATEDATE;
|
|
}
|
|
|
|
new UserManageDAL().SaveBusinessPower(userPower);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw ex;
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region 获取导出的数据
|
|
/// <summary>
|
|
/// 获取导出的数据
|
|
/// </summary>
|
|
/// <param name="condition">查询条件</param>
|
|
/// <returns>数据</returns>
|
|
public DataTable GetExportData(User condition)
|
|
{
|
|
DataTable dt = new UserManageDAL().GetExportData(condition);
|
|
|
|
//处理字典信息
|
|
DictManagerBLL dictBll = new DictManagerBLL(DictKind.UserType);
|
|
|
|
foreach (DataRow dr in dt.Rows)
|
|
{
|
|
dr["UserType"] = dictBll.GetDictValue(dr["UserType"].ToString());
|
|
}
|
|
|
|
return dt;
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region 导入数据
|
|
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
/// <param name="list"></param>
|
|
/// <returns></returns>
|
|
public DataResult<ImportMessage> GetImportData(List<User> list)
|
|
{
|
|
DataResult<ImportMessage> result = new DataResult<ImportMessage>();
|
|
UserManageDAL cmDal = new UserManageDAL();
|
|
DictManagerBLL dictBll = new DictManagerBLL();
|
|
OrgaizationManageDAL orgaDal = new OrgaizationManageDAL();
|
|
List<User> userList = new List<User>();
|
|
int index = 0;
|
|
try
|
|
{
|
|
result.Result = new ImportMessage();
|
|
result.Result.Errors = new List<RowError>();
|
|
using (IDataSession session = AppDataFactory.CreateMainSession())
|
|
{
|
|
orgaDal.BaseSession = session;
|
|
cmDal.BaseSession = session;
|
|
//状态判断
|
|
foreach (User ma in list)
|
|
{
|
|
index++;
|
|
|
|
//验证组织机构是否存在
|
|
Orgaization orga = orgaDal.Get(ma.OrgaDESC);
|
|
if (orga == null || string.IsNullOrEmpty(orga.OrgaID))
|
|
{
|
|
//仓库编号无效
|
|
ma.UserID = null;
|
|
result.Result.failureNum += 1;
|
|
result.Result.Errors.Add(new RowError(index, "组织机构:机构无效"));
|
|
continue;
|
|
}
|
|
|
|
ma.OrgaID = orga.OrgaID;
|
|
|
|
//验证员工类型是否存在
|
|
Dictionary<string, string> dictList = dictBll.GetModelDictionary(DictKind.UserType);
|
|
bool resultBoll = false;
|
|
foreach (var item in dictList)
|
|
{
|
|
if (item.Value == ma.UserType)
|
|
{
|
|
resultBoll = true;
|
|
ma.UserType = item.Key;
|
|
break;
|
|
}
|
|
}
|
|
|
|
if (!resultBoll)
|
|
{
|
|
ma.UserID = null;
|
|
result.Result.failureNum += 1;
|
|
result.Result.Errors.Add(new RowError(index, "用户类型:用户类型不存在"));
|
|
continue;
|
|
}
|
|
|
|
//验证激活是否存在
|
|
if (string.IsNullOrEmpty(ma.ActivateFlg) || !(ma.ActivateFlg == "是" || ma.ActivateFlg == "否"))
|
|
{
|
|
ma.UserID = null;
|
|
result.Result.failureNum += 1;
|
|
result.Result.Errors.Add(new RowError(index, "激活状态:激活状态不存在"));
|
|
continue;
|
|
}
|
|
ma.ActivateFlg = ma.ActivateFlg == "是" ? "1" : "0";
|
|
|
|
User oldInfo = cmDal.Get(ma.LoginUserID);
|
|
|
|
if (oldInfo != null)
|
|
{
|
|
//更新
|
|
ma.UserID = oldInfo.UserID;
|
|
if (oldInfo.DelFlag == DelState.DEL)
|
|
{
|
|
ma.CreateUser = LoginUser.UserID;
|
|
ma.CreateTime = DateTime.Now;
|
|
result.Result.insertNum += 1;
|
|
}
|
|
else
|
|
{
|
|
ma.CreateUser = oldInfo.CreateUser;
|
|
ma.CreateTime = oldInfo.CreateTime;
|
|
result.Result.updateNum += 1;
|
|
}
|
|
ma.UpdateUser = this.LoginUser.UserID;
|
|
ma.UpdateTime = oldInfo.UpdateTime;
|
|
ma.DelFlag = DelState.UNDEL;
|
|
ma.IsNewInfo = false;
|
|
}
|
|
else
|
|
{
|
|
//新增
|
|
ma.UserID = Guid.NewGuid().ToString();
|
|
ma.PassWord = DESEncrypt.Encrypt("init1234");
|
|
ma.CreateUser = this.LoginUser.UserID;
|
|
ma.CreateTime = DateTime.Now;
|
|
ma.UpdateUser = ma.CreateUser;
|
|
ma.UpdateTime = ma.CreateTime;
|
|
ma.DelFlag = DelState.UNDEL;
|
|
ma.IsNewInfo = true;
|
|
result.Result.insertNum += 1;
|
|
}
|
|
|
|
userList.Add(ma);
|
|
}
|
|
}
|
|
//导入
|
|
cmDal.ImportData(userList);
|
|
result.MsgCode = ResourceCodeEnum.MsgImport.ToString();
|
|
result.IsSuccess = true;
|
|
return result;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
result.IsSuccess = false;
|
|
result.Ex = ex;
|
|
return result;
|
|
}
|
|
}
|
|
#endregion
|
|
}
|
|
}
|
|
|