天津投入产出系统后端
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.

914 lines
35 KiB

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using QMFrameWork.Data;
using QMAPP.Entity.Sys;
using System.Data;
using QMFrameWork.Common.Encrypt;
namespace QMAPP.DAL.Sys
{
/// <summary>
/// 用户信息管理
/// 创建者:郭佳伟
/// 创建日期:2013.1.16
/// </summary>
public class UserManageDAL:BaseDAL
{
#region 获取用户信息列表
/// <summary>
/// 获取全部用户
/// </summary>
/// <param name="condition">获取条件</param>
/// <returns>用户信息列表</returns>
public List<User> GetAllUser(User condition)
{
string sql = null;
List<User> list = null;
try
{
using (IDataSession session = AppDataFactory.CreateMainSession())
{
sql = "SELECT USERID,LOGINUSERID,USERNAME FROM T_QM_USER WHERE ACTIVATEFLG = '1'";
list = session.GetList<User>(sql, new List<DataParameter>().ToArray()).ToList();
}
return list;
}
catch (Exception ex)
{
throw;
}
}
/// <summary>
/// 获取用户信息列表
/// </summary>
/// <param name="condition">条件</param>
/// <param name="page">数据页</param>
/// <returns>数据页</returns>
public DataPage GetList(User condition, DataPage page)
{
string sql = null;
List<DataParameter> parameters = new List<DataParameter>();
try
{
sql = this.GetQuerySql(condition, ref parameters);
//分页关键字段及排序
page.KeyName = "LOGINUSERID";
if (string.IsNullOrEmpty(page.SortExpression))
{
page.SortExpression = "UPDATEDATE DESC";
}
if (page.SortExpression.IndexOf("CreateTime") > -1)
{
page.SortExpression = page.SortExpression.Replace("CreateTime", "CREATEDATE");
}
if (page.SortExpression.IndexOf("UpdateTime") > -1)
{
page.SortExpression = page.SortExpression.Replace("UpdateTime", "UPDATEDATE");
}
using (IDataSession session = AppDataFactory.CreateMainSession())
{
sql = this.ChangeSqlByDB(sql, session);
page = session.GetDataPage<User>(sql, parameters.ToArray(), page);
}
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)
{
List<User> users = null;
string sql = null;
List<DataParameter> parameters=new List<DataParameter>();
try
{
sql = this.GetQuerySql(condition, ref parameters);
using (IDataSession session = AppDataFactory.CreateMainSession())
{
sql = this.ChangeSqlByDB(sql, session);
users = session.GetList<User>(sql, parameters.ToArray()).ToList();
}
return users;
}
catch (Exception ex)
{
throw ex;
}
}
/// <summary>
/// 获取查询语句
/// </summary>
/// <param name="condition">查询条件</param>
/// <param name="parameters">查询</param>
/// <returns>查询语句</returns>
private string GetQuerySql(User condition, ref List<DataParameter> parameters)
{
string sql = null;
StringBuilder whereBuilder = new StringBuilder();
sql= @" SELECT A.USERID,
A.LOGINUSERID,A.EMPLOYEENO,A.USERNAME,A.PASSWORD,A.TEL,B.ORGADESC,
A.MOBILETEL,A.EMAIL,A.CREATEUSER,A.CREATEDATE,A.UPDATEUSER,A.UPDATEDATE,A.USERTYPE,
A.FLGDEL,(CASE WHEN A.ACTIVATEFLG ='0' THEN '否' else '是' end) as ACTIVATEFLG
FROM T_QM_USER A
LEFT OUTER JOIN T_QM_ORGANIZATION B ON A.ORGANID = B.ORGAID
WHERE A.FLGDEL ='0'";
//查询条件
if (string.IsNullOrEmpty(condition.ActivateFlg) == false)
{
whereBuilder.Append(" AND A.ACTIVATEFLG = @ACTIVATEFLG");
parameters.Add(new DataParameter { ParameterName = "ACTIVATEFLG", DataType = DbType.String, Value = condition.ActivateFlg });
}
if (string.IsNullOrEmpty(condition.UserID) == false)
{
whereBuilder.Append(" AND A.UserID = @UserID");
parameters.Add(new DataParameter { ParameterName = "UserID", DataType = DbType.String, Value = condition.UserID });
}
if (string.IsNullOrEmpty(condition.OrgaID) == false)
{
whereBuilder.Append(" AND A.ORGANID = @ORGANID");
parameters.Add(new DataParameter { ParameterName = "ORGANID", DataType = DbType.String, Value = condition.OrgaID });
}
if (string.IsNullOrEmpty(condition.LoginUserID) == false)
{
whereBuilder.Append(" AND A.LOGINUSERID LIKE @LOGINUSERID");
parameters.Add(new DataParameter { ParameterName = "LOGINUSERID", DataType = DbType.String, Value = "%" + condition.LoginUserID + "%" });
}
if (string.IsNullOrEmpty(condition.UserName) == false)
{
whereBuilder.Append(" AND A.USERNAME LIKE @USERNAME");
parameters.Add(new DataParameter { ParameterName = "USERNAME", DataType = DbType.String, Value = "%" + condition.UserName + "%" });
}
if (whereBuilder.Length > 0)
{
sql+=whereBuilder.ToString();
}
return sql;
}
#endregion
#region 获取用户信息
/// <summary>
/// 获取用户信息信息
/// </summary>
/// <param name="user">条件</param>
/// <returns>用户信息信息</returns>
public User Get(User user)
{
StringBuilder sqlBuilder = new StringBuilder();
string sql = null;
List<DataParameter> parameters = new List<DataParameter>();
User tmpuser = new User();
try
{
using (IDataSession session = AppDataFactory.CreateMainSession())
{
//获取用户信息
sqlBuilder.Append(" SELECT USERID, ");
sqlBuilder.Append(" LOGINUSERID,EMPLOYEENO,USERNAME,ORGANID,USERTYPE,PASSWORD,TEL, ");
sqlBuilder.Append(" MOBILETEL,EMAIL,CREATEUSER,CREATEDATE,UPDATEUSER,UPDATEDATE, ");
sqlBuilder.Append(" FLGDEL,ACTIVATEFLG ");
sqlBuilder.Append(" FROM T_QM_USER A WHERE UserID = @UserID");
parameters.Add(new DataParameter { ParameterName = "UserID", DataType = DbType.String, Value = user.UserID });
sql = this.ChangeSqlByDB(sqlBuilder.ToString(), session);
tmpuser = session.Get<User>(sql, parameters.ToArray());
if (tmpuser == null)
return null;
if (string.IsNullOrEmpty(tmpuser.PassWord)==false)
tmpuser.PassWord = DESEncrypt.Decrypt(tmpuser.PassWord);
//获取用户所有角色信息
sqlBuilder.Remove(0, sqlBuilder.Length);
parameters = new List<DataParameter>();
sqlBuilder.Append("SELECT USERID,ROLEID,(SELECT ROLEDESC FROM T_QM_ROLE WHERE ROLEID=T_QM_USERROLE.ROLEID) AS ROLEDESC FROM T_QM_USERROLE WHERE USERID=@USERID");
parameters.Add(new DataParameter { ParameterName = "USERID", DataType = DbType.String, Value= user.UserID });
sql = this.ChangeSqlByDB(sqlBuilder.ToString(), session);
tmpuser.Roles = session.GetList<UserRole>(sql, parameters.ToArray()).ToList();
//获取用户所有权限信息
sqlBuilder.Remove(0, sqlBuilder.Length);
parameters = new List<DataParameter>();
sqlBuilder.Append("SELECT AUTHORITYID FROM T_QM_USERAUTHORITY WHERE USERID=@USERID ");
parameters.Add(new DataParameter { ParameterName = "USERID", DataType = DbType.String, Value = user.UserID });
sql = this.ChangeSqlByDB(sqlBuilder.ToString(), session);
tmpuser.OptionAuthority = session.GetList<UserAuthority>(sql, parameters.ToArray()).ToList();
//获取用户所有全部权限信息
sqlBuilder.Remove(0, sqlBuilder.Length);
parameters = new List<DataParameter>();
sqlBuilder.Append("SELECT AUTHORITYID FROM T_QM_USERAUTHORITY WHERE USERID=@USERID ");
sqlBuilder.Append(" UNION ");
sqlBuilder.Append(" SELECT AUTHORITYID FROM T_QM_ROLEAUTHORITY ");
sqlBuilder.Append(" WHERE EXISTS (SELECT * from T_QM_USERROLE WHERE T_QM_ROLEAUTHORITY.ROLEID ");
sqlBuilder.Append(" =T_QM_USERROLE.ROLEID and T_QM_USERROLE.USERID =@USERID)");
sqlBuilder.Append(" UNION ");
sqlBuilder.Append("SELECT AUTHORITYID FROM T_QM_ORGAIZATIONAUTHORITY ");
sqlBuilder.Append(" WHERE EXISTS (SELECT * FROM T_QM_USERORGAIZATION WHERE T_QM_ORGAIZATIONAUTHORITY.ORGAID ");
sqlBuilder.Append(" =T_QM_USERORGAIZATION.ORGAID AND T_QM_USERORGAIZATION.USERID =@USERID)");
parameters.Add(new DataParameter { ParameterName = "USERID", DataType = DbType.String, Value = user.UserID });
sql = this.ChangeSqlByDB(sqlBuilder.ToString(), session);
tmpuser.Authoritys = session.GetList<UserAuthority>(sql, parameters.ToArray()).ToList();
//获取用户所属的组织机构
sqlBuilder.Remove(0, sqlBuilder.Length);
parameters = new List<DataParameter>();
sqlBuilder.Append("SELECT * FROM T_QM_USERORGAIZATION WHERE USERID=@USERID");
parameters.Add(new DataParameter { ParameterName = "USERID", DataType = DbType.String, Value = user.UserID });
sql = this.ChangeSqlByDB(sqlBuilder.ToString(), session);
tmpuser.Orgas = session.GetList<UserOrgaization>(sql, parameters.ToArray()).ToList();
}
return tmpuser;
}
catch (Exception ex)
{
throw ex;
}
}
#endregion
#region 手持登录获取用户信息
/// <summary>
/// 手持获取用户信息信息
/// </summary>
/// <param name="user">条件</param>
/// <returns>用户信息信息</returns>
public User GetBaseInfo(User user)
{
StringBuilder sqlBuilder = new StringBuilder();
string sql = null;
List<DataParameter> parameters = new List<DataParameter>();
User tmpuser = new User();
try
{
using (IDataSession session = AppDataFactory.CreateMainSession())
{
//获取用户信息
sqlBuilder.Append(" SELECT USERID, ");
sqlBuilder.Append(" LOGINUSERID,USERNAME,ORGANID,USERTYPE,PASSWORD,TEL, ");
sqlBuilder.Append(" MOBILETEL,EMAIL,CREATEUSER,CREATEDATE,UPDATEUSER,UPDATEDATE, ");
sqlBuilder.Append(" FLGDEL,ACTIVATEFLG ");
sqlBuilder.Append(" FROM T_QM_USER A WHERE UserID = @UserID");
parameters.Add(new DataParameter { ParameterName = "UserID", DataType = DbType.String, Value = user.UserID });
sql = this.ChangeSqlByDB(sqlBuilder.ToString(), session);
tmpuser = session.Get<User>(sql, parameters.ToArray());
}
return tmpuser;
}
catch (Exception ex)
{
throw ex;
}
}
#endregion
#region 判断登陆账户是否重复
/// <summary>
/// 判断登陆账户是否重复
/// </summary>
/// <param name="user">条件</param>
/// <returns>用户信息信息</returns>
public User GetLoginUser(User user)
{
StringBuilder sqlBuilder = new StringBuilder();
string sql = null;
List<DataParameter> parameters = new List<DataParameter>();
User tmpuser = new User();
try
{
using (IDataSession session = AppDataFactory.CreateMainSession())
{
//获取用户信息
sqlBuilder.Append(" SELECT USERID, ");
sqlBuilder.Append(" LOGINUSERID,USERNAME,PASSWORD,TEL, ");
sqlBuilder.Append(" MOBILETEL,EMAIL,CREATEUSER,CREATEDATE,UPDATEUSER,UPDATEDATE ");
sqlBuilder.Append(" FLGDEL,ACTIVATEFLG ");
sqlBuilder.Append(" FROM T_QM_USER WHERE LOGINUSERID = @LOGINUSERID AND FLGDEL = '0'");
parameters.Add(new DataParameter { ParameterName = "LOGINUSERID", DataType = DbType.String, Value = user.LoginUserID });
sql = this.ChangeSqlByDB(sqlBuilder.ToString(), session);
tmpuser = session.Get<User>(sql, parameters.ToArray());
}
return tmpuser;
}
catch (Exception ex)
{
throw ex;
}
}
#endregion
#region 获取组织机构下人员列表
/// <summary>
/// 获取组织机构下人员列表
/// </summary>
/// <param name="condition">条件</param>
/// <returns>同级别菜单列表</returns>
public List<User> GetOrgaUserList(string orgaID)
{
try
{
List<DataParameter> parameters = new List<DataParameter>();
List<User> list = null;
using (IDataSession session = AppDataFactory.CreateMainSession())
{
string sql = " SELECT USERID,USERNAME,ORGANID AS ORGAID," +
" (SELECT ORGADESC FROM T_QM_ORGANIZATION WHERE U.ORGANID=T_QM_ORGANIZATION.ORGAID) AS ORGADESC " +
" FROM T_QM_USER U WHERE U.ORGANID=@ORGAID";
parameters.Add(new DataParameter { ParameterName = "ORGAID", DataType = DbType.String, Value = orgaID });
sql = this.ChangeSqlByDB(sql, session);
list = session.GetList<User>(sql, parameters.ToArray()).ToList();
}
return list;
}
catch (Exception ex)
{
throw ex;
}
}
#endregion
#region 获取人员所属的组织机构列表
/// <summary>
/// 获取人员所属的组织机构列表
/// </summary>
/// <param name="condition">条件</param>
/// <returns>同级别菜单列表</returns>
public List<Orgaization> GetUserOrgaList(string userID)
{
try
{
StringBuilder sqlBuilder = new StringBuilder();
string sql = null;
List<DataParameter> parameters = new List<DataParameter>();
List<Orgaization> list = null;
using (IDataSession session = AppDataFactory.CreateMainSession())
{
if (userID != "")
{
sqlBuilder.Append("SELECT ORGAID,(SELECT ORGADESC FROM T_QM_ORGANIZATION WHERE ");
sqlBuilder.Append(" ORGAID = T_QM_USERORGAIZATION.ORGAID AND FLGDEL='0') AS ORGADESC FROM ");
sqlBuilder.Append(" T_QM_USERORGAIZATION WHERE USERID=@USERIDA AND ACTIVATEFLG = '1'");
sqlBuilder.Append(" UNION ");
sqlBuilder.Append("SELECT ORGAID,ORGADESC FROM T_QM_ORGANIZATION WHERE ");
sqlBuilder.Append(" CREATEUSER = @USERIDB AND FLGDEL = '0' AND ACTIVATEFLG = '1'");
parameters.Add(new DataParameter { ParameterName = "USERIDA", DataType = DbType.String, Value = userID });
parameters.Add(new DataParameter { ParameterName = "USERIDB", DataType = DbType.String, Value = userID });
}
else
{
sqlBuilder.Append("SELECT ORGAID, ORGADESC FROM T_QM_ORGANIZATION WHERE ");
sqlBuilder.Append(" FLGDEL='0' AND ACTIVATEFLG = '1'");
}
sql = this.ChangeSqlByDB(sqlBuilder.ToString(), session);
list = session.GetList<Orgaization>(sql, parameters.ToArray()).ToList();
}
return list;
}
catch (Exception ex)
{
throw ex;
}
}
#endregion
#region 插入用户信息信息
/// <summary>
/// 插入用户信息信息
/// </summary>
/// <param name="user">用户信息信息</param>
/// <returns>插入数</returns>
public int Insert(User user)
{
int count = 0;
try
{
using (IDataSession session = AppDataFactory.CreateMainSession())
{
session.OpenTs();
//插入基本信息
session.Insert<User>(user);
//插入用户角色信息
if (user.Roles != null)
{
foreach (UserRole ur in user.Roles)
{
ur.UserID = user.UserID;
}
//插入角色信息
session.Insert<UserRole>(user.Roles);
}
//插入用户权限信息
if (user.Authoritys != null)
{
foreach (UserAuthority ur in user.Authoritys)
{
ur.UserID = user.UserID;
ur.OrgaID = user.OrgaID;
}
//插入权限信息
session.Insert<UserAuthority>(user.Authoritys);
}
session.CommitTs();
}
return count;
}
catch (Exception ex)
{
throw ex;
}
}
#endregion
#region 删除用户信息信息
/// <summary>
/// 删除用户信息信息
/// </summary>
/// <param name="user">用户信息信息</param>
/// <returns>删除个数</returns>
public int Delete(User user)
{
int count = 0;
string sql = null;
try
{
using (IDataSession session = AppDataFactory.CreateMainSession())
{
//校验是否为激活状态
string activateFlg = "";
sql = "SELECT ACTIVATEFLG FROM T_QM_USER WHERE USERID = @USERID";
sql = this.ChangeSqlByDB(sql, session);
activateFlg = (string)session.ExecuteSqlScalar(sql, new DataParameter { ParameterName = "UserID", DataType = DbType.String, Value = user.UserID });
if (activateFlg == "1")
return 0;
session.OpenTs();
//删除用户所有角色信息
sql = "DELETE T_QM_USERROLE WHERE USERID=@USERID";
sql = this.ChangeSqlByDB(sql, session);
count = session.ExecuteSql(sql, new DataParameter { ParameterName = "USERID", DataType = DbType.String, Value = user.UserID });
//删除用户所有权限信息
sql = "DELETE T_QM_USERAUTHORITY WHERE USERID=@USERID";
sql = this.ChangeSqlByDB(sql, session);
count = session.ExecuteSql(sql, new DataParameter { ParameterName = "USERID", DataType = DbType.String, Value = user.UserID });
//删除用户所有组织机构信息
sql = "DELETE T_QM_USERORGAIZATION WHERE USERID=@USERID";
sql = this.ChangeSqlByDB(sql, session);
count = session.ExecuteSql(sql, new DataParameter { ParameterName = "USERID", DataType = DbType.String, Value = user.UserID });
//删除用户信息信息
sql = "UPDATE T_QM_USER SET FLGDEL = '1' WHERE USERID=@USERID";
sql = this.ChangeSqlByDB(sql, session);
count = session.ExecuteSql(sql, new DataParameter { ParameterName = "USERID", DataType = DbType.String, Value = user.UserID });
session.CommitTs();
}
return count;
}
catch (Exception ex)
{
throw ex;
}
}
#endregion
#region 更新用户信息
/// <summary>
/// 更新用户信息
/// </summary>
/// <param name="user">用户信息</param>
/// <returns>更新个数</returns>
public int Update(User user)
{
int count = 0;
string sql = null;
try
{
using (IDataSession session = AppDataFactory.CreateMainSession())
{
session.OpenTs();
user.DelFlag = "0";
user.PassWord = DESEncrypt.Encrypt(user.PassWord);
//更新基本信息
count = session.Update<User>(user);
//更新角色信息
sql = "DELETE FROM T_QM_USERROLE WHERE USERID=@USERID";
sql = this.ChangeSqlByDB(sql, session);
session.ExecuteSql(sql, new DataParameter { ParameterName = "USERID", DataType = DbType.String, Value = user.UserID });
if (user.Roles != null)
session.Insert<UserRole>(user.Roles);
//更新权限信息
sql = "DELETE FROM T_QM_USERAUTHORITY WHERE USERID=@USERID";
sql = this.ChangeSqlByDB(sql, session);
session.ExecuteSql(sql, new DataParameter { ParameterName = "USERID", DataType = DbType.String, Value = user.UserID });
if (user.Authoritys != null)
session.Insert<UserAuthority>(user.Authoritys);
session.CommitTs();
}
return count;
}
catch (Exception ex)
{
throw ex;
}
}
#endregion
#region 设置密码
/// <summary>
/// 设置密码
/// </summary>
/// <param name="info">用户信息</param>
/// <returns>影响行数</returns>
public int SetPassWord(User info)
{
int count = 0;
string sql = null;
try
{
sql = "UPDATE T_QM_USER SET PASSWORD=@PASSWORD,UPDATEUSER=@UPDATEUSER,UPDATEDATE=@UPDATETIME WHERE USERID=@USERID";
using (IDataSession session = AppDataFactory.CreateMainSession())
{
sql = this.ChangeSqlByDB(sql, session);
count = session.ExecuteSql(sql
, new DataParameter("PASSWORD", info.PassWord)
, new DataParameter("UPDATEUSER", info.UpdateUser)
, new DataParameter("USERID", info.UserID), new DataParameter("UPDATETIME", info.UpdateTime));
}
return count;
}
catch (Exception ex)
{
throw ex;
}
}
#endregion
#region 获取业务权限信息
/// <summary>
/// 获取业务权限信息
/// </summary>
/// <param name="userPower">获取条件</param>
/// <returns>业务权限信息</returns>
public UserBusinessPower GetBusinessPower(UserBusinessPower userPower)
{
string sql = null;
List<DataParameter> parameters = new List<DataParameter>();
try
{
using (IDataSession session = AppDataFactory.CreateMainSession())
{
//获取用户基本信息
sql = "SELECT USERID,LOGINUSERID,USERNAME,EMPLOYEENO,UPDATEDATE,ALLLINES FROM T_QM_USER WHERE USERID=@USERID";
sql = this.ChangeSqlByDB(sql, session);
userPower = session.Get<UserBusinessPower>(sql, new DataParameter("USERID", userPower.UserID));
//获取仓库权限
sql = "SELECT T1.ID,T2.CORPID,T2.CORPCODE,T2.CORPNAME FROM T_BD_EMPLOYEECORP T1 "
+ "INNER JOIN T_BD_CORP T2 ON T1.CORPID=T2.CORPID "
+ "WHERE T1.USERID=@USERID";
parameters.Clear();
parameters.Add(new DataParameter("USERID", userPower.UserID));
sql = this.ChangeSqlByDB(sql, session);
userPower.CorpPowers = session.GetList<UserCorpPower>(sql, parameters.ToArray()).ToList();
//获取路线权限
sql = "SELECT T1.ID,T2.LINEID,T2.LINENO,T2.LINENAME,T2.CORPID,T3.CORPNAME FROM T_BD_EMPLOYEELINE T1 "
+ "INNER JOIN T_BD_LINE T2 ON T1.LINEID=T2.LINEID "
+ "INNER JOIN T_BD_CORP T3 ON T2.CORPID=T3.CORPID "
+ "WHERE T1.USERID=@USERID";
parameters.Clear();
parameters.Add(new DataParameter("USERID", userPower.UserID));
sql = this.ChangeSqlByDB(sql, session);
userPower.LinePowers = session.GetList<UserLinePower>(sql, parameters.ToArray()).ToList();
//获取零件类别权限
sql = "SELECT T1.ID,T2.MATSORTID,T2.MATSORTNO,T2.SORTNAME AS MATSORTNAME FROM T_BD_EMPLOYEEMATSORT T1 "
+ "INNER JOIN T_BD_MATERIALSORT T2 ON T1.MATSORTID=T2.MATSORTID "
+ "WHERE T1.USERID=@USERID";
parameters.Clear();
parameters.Add(new DataParameter("USERID", userPower.UserID));
sql = this.ChangeSqlByDB(sql, session);
userPower.MatSortPowers = session.GetList<UserMatSortPower>(sql, parameters.ToArray()).ToList();
//获取要货地权限
sql = "SELECT T1.ID,T2.PLACEDISID,T2.PLACEDISNO,T2.DESCRIBE_SITE AS DESCRIBE_SITE FROM T_BD_EMPLOYEEREQPLACE T1 "
+ "INNER JOIN T_BD_PLACEDISCHARGE T2 ON T1.PLACEDISID=T2.PLACEDISID "
+ "WHERE T1.USERID=@USERID";
parameters.Clear();
parameters.Add(new DataParameter("USERID", userPower.UserID));
sql = this.ChangeSqlByDB(sql, session);
userPower.ReqPlacePowers = session.GetList<UserReqPlacePower>(sql, parameters.ToArray()).ToList();
//获发要货地权限
sql = "SELECT T1.ID,T2.SENDPLACEID,T2.SENDPLACENO,T2.SENDPLACENAME AS SENDPLACENAME FROM T_BD_EMPLOYEESENDPLACE T1 "
+ "INNER JOIN T_BD_HMATSENDPLACE T2 ON T1.SENDPLACEID=T2.SENDPLACEID "
+ "WHERE T1.USERID=@USERID";
parameters.Clear();
parameters.Add(new DataParameter("USERID", userPower.UserID));
sql = this.ChangeSqlByDB(sql, session);
userPower.SendPlacePowers = session.GetList<UserSendPlacePower>(sql, parameters.ToArray()).ToList();
}
return userPower;
}
catch (Exception ex)
{
throw ex;
}
}
#endregion
#region 保存业务权限信息
/// <summary>
/// 保存业务权限信息
/// </summary>
/// <param name="userPower">业务权限信息</param>
public void SaveBusinessPower(UserBusinessPower userPower)
{
string sql = null;
try
{
using (IDataSession session = AppDataFactory.CreateMainSession())
{
session.OpenTs();
//保存基本信息
session.Update<UserBusinessPower>(userPower);
//保存仓库权限
sql = "DELETE FROM T_BD_EMPLOYEECORP WHERE USERID=:USERID";
session.ExecuteSql(sql, new DataParameter("USERID", userPower.UserID));
session.Insert<UserCorpPower>(userPower.CorpPowers);
//保存路线信息
sql = "DELETE FROM T_BD_EMPLOYEELINE WHERE USERID=:USERID";
session.ExecuteSql(sql, new DataParameter("USERID", userPower.UserID));
session.Insert<UserLinePower>(userPower.LinePowers);
//保存零件类别信息
sql = "DELETE FROM T_BD_EMPLOYEEMATSORT WHERE USERID=:USERID";
session.ExecuteSql(sql, new DataParameter("USERID", userPower.UserID));
session.Insert<UserMatSortPower>(userPower.MatSortPowers);
//保存要货地信息
sql = "DELETE FROM T_BD_EMPLOYEEREQPLACE WHERE USERID =:USERID";
session.ExecuteSql(sql, new DataParameter("USERID", userPower.UserID));
session.Insert<UserReqPlacePower>(userPower.ReqPlacePowers);
//保存发货地信息
sql = "DELETE FROM T_BD_EMPLOYEESENDPLACE WHERE USERID =:USERID";
session.ExecuteSql(sql, new DataParameter("USERID", userPower.UserID));
session.Insert<UserSendPlacePower>(userPower.SendPlacePowers);
session.CommitTs();
}
}
catch (Exception ex)
{
throw ex;
}
}
#endregion
#region 获取导出的数据
/// <summary>
/// 获取导出的数据
/// </summary>
/// <param name="condition">查询条件</param>
/// <returns>数据</returns>
public DataTable GetExportData(User condition)
{
StringBuilder sqlBuilder = new StringBuilder();
StringBuilder whereBuilder = new StringBuilder();
DataTable dt = null;
string sql = null;
List<DataParameter> parameters = new List<DataParameter>();
try
{
//构成查询语句
sql = this.GetQuerySql(condition, ref parameters);
sql += " ORDER BY UPDATEDATE DESC ";
using (IDataSession session = AppDataFactory.CreateMainSession())
{
sql = this.ChangeSqlByDB(sql, session);
dt = session.GetTable(sql, parameters.ToArray());
dt.TableName = "T_QM_USER";
}
return dt;
}
catch (Exception ex)
{
throw;
}
}
#endregion
#region 导入
/// <summary>
/// 导入
/// </summary>
/// <param name="list">数据列表</param>
/// <returns>导入记录数</returns>
public int ImportData(List<User> list)
{
int count = 0;
List<User> inserts = null;
List<User> updates = null;
try
{
//获取新增信息
inserts = list.Where(p => p.UserID != null && p.IsNewInfo == true).ToList();
//获取修改信息
updates = list.Where(p => p.UserID != null && p.IsNewInfo == false).ToList();
this.BaseSession.OpenTs();
this.BaseSession.Insert<User>(inserts);
this.BaseSession.Update<User>(updates);
this.BaseSession.CommitTs();
count = list.Count;
return count;
}
catch (Exception ex)
{
throw ex;
}
}
#endregion
#region 获取用户信息
/// <summary>
/// 获取用户信息信息
/// </summary>
/// <param name="user">条件</param>
/// <returns>用户信息信息</returns>
public User Get(string LoginUserID)
{
StringBuilder sqlBuilder = new StringBuilder();
string sql = null;
List<DataParameter> parameters = new List<DataParameter>();
User tmpuser = new User();
try
{
//获取用户信息
sqlBuilder.Append(" SELECT USERID, ");
sqlBuilder.Append(" LOGINUSERID,EMPLOYEENO,USERNAME,ORGANID,USERTYPE,PASSWORD,TEL, ");
sqlBuilder.Append(" MOBILETEL,EMAIL,CREATEUSER,CREATEDATE,UPDATEUSER,UPDATEDATE, ");
sqlBuilder.Append(" FLGDEL,ACTIVATEFLG ");
sqlBuilder.Append(" FROM T_QM_USER A WHERE LOGINUSERID = @LOGINUSERID");
parameters.Add(new DataParameter { ParameterName = "LOGINUSERID", DataType = DbType.String, Value = LoginUserID });
sql = this.ChangeSqlByDB(sqlBuilder.ToString(), this.BaseSession);
tmpuser = this.BaseSession.Get<User>(sql, parameters.ToArray());
return tmpuser;
}
catch (Exception ex)
{
throw ex;
}
}
#endregion
#region 获取人员下拉框
/// <summary>
/// 获取人员下拉框
/// </summary>
/// <param name="condition">条件</param>
/// <returns>同级别菜单列表</returns>
public List<User> GetUserComboxSource()
{
try
{
List<DataParameter> parameters = new List<DataParameter>();
List<User> list = null;
using (IDataSession session = AppDataFactory.CreateMainSession())
{
string sql = " SELECT * FROM T_QM_USER ";
sql = this.ChangeSqlByDB(sql, session);
list = session.GetList<User>(sql, parameters.ToArray()).ToList();
}
return list;
}
catch (Exception ex)
{
throw ex;
}
}
#endregion
}
}