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 获取用户信息列表
///
/// 获取全部用户
///
/// 获取条件
/// 用户信息列表
public List GetAllUser(User condition)
{
return new UserManageDAL().GetAllUser(condition);
}
///
/// 获取用户信息列表
///
/// 条件
/// 数据页
/// 数据页
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 list = page.Result as List;
//foreach (User info in list)
//{
// //替换用户类别显示值
// info.UserType = dictBll.GetDictValue(info.UserType);
//}
return page;
}
catch (Exception ex)
{
throw ex;
}
}
///
/// 获取用户信息列表
///
/// 条件
/// 数据页
/// 数据页
public List GetAllUsers(User condition)
{
try
{
return new UserManageDAL().GetAllUsers(condition);
}
catch (Exception ex)
{
throw ex;
}
}
//人员下拉框
public List GetUserComboxSource()
{
try
{
return new UserManageDAL().GetUserComboxSource();
}
catch (Exception ex)
{
throw ex;
}
}
#endregion
#region 获取用户信息
///
/// 获取用户信息
///
/// 条件
/// 用户信息
public User Get(User user)
{
try
{
return new UserManageDAL().Get(user);
}
catch (Exception ex)
{
throw ex;
}
}
#endregion
#region 获取输入的登陆账户是否存在
///
/// 获取输入的登陆账户是否存在
///
/// 条件
/// 用户信息信息
public User GetLoginUser(User user)
{
try
{
return new UserManageDAL().GetLoginUser(user);
}
catch (Exception ex)
{
throw ex;
}
}
#endregion
#region 获取组织机构下人员列表
///
/// 获取组织机构下人员列表
///
/// 条件
/// 同级别菜单列表
public List GetOrgaUserList(string orgaID)
{
try
{
return new UserManageDAL().GetOrgaUserList(orgaID);
}
catch (Exception ex)
{
throw ex;
}
}
#endregion
#region 获取人员所属的组织机构列表
///
/// 获取人员所属的组织机构列表
///
/// 条件
/// 同级别菜单列表
public List GetUserOrgaList(string userID)
{
try
{
return new UserManageDAL().GetUserOrgaList(userID);
}
catch (Exception ex)
{
throw ex;
}
}
#endregion
#region 插入用户信息信息
///
/// 插入用户信息
///
/// 用户信息信息
/// 插入数
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 删除用户信息
///
/// 删除用户信息信息
///
/// 用户信息信息
/// 删除个数
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;
}
}
///
/// 删除用户信息信息
///
/// 用户信息信息
/// 删除行数
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 更新用户信息
///
/// 更新用户信息
///
/// 用户信息信息
/// 更新个数
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 设置密码
///
/// 设置密码
///
/// 用户信息
/// 执行结果
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 获取业务权限信息
///
/// 获取业务权限信息
///
/// 获取条件
/// 业务权限信息
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 保存业务权限信息
///
/// 保存业务权限信息
///
/// 业务权限信息
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 获取导出的数据
///
/// 获取导出的数据
///
/// 查询条件
/// 数据
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 导入数据
///
///
///
///
///
public DataResult GetImportData(List list)
{
DataResult result = new DataResult();
UserManageDAL cmDal = new UserManageDAL();
DictManagerBLL dictBll = new DictManagerBLL();
OrgaizationManageDAL orgaDal = new OrgaizationManageDAL();
List userList = new List();
int index = 0;
try
{
result.Result = new ImportMessage();
result.Result.Errors = new List();
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 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
}
}