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
{
///
/// 用户信息管理
/// 创建者:郭佳伟
/// 创建日期:2013.1.16
///
public class UserManageDAL:BaseDAL
{
#region 获取用户信息列表
///
/// 获取全部用户
///
/// 获取条件
/// 用户信息列表
public List GetAllUser(User condition)
{
string sql = null;
List list = null;
try
{
using (IDataSession session = AppDataFactory.CreateMainSession())
{
sql = "SELECT USERID,LOGINUSERID,USERNAME FROM T_QM_USER WHERE ACTIVATEFLG = '1'";
list = session.GetList(sql, new List().ToArray()).ToList();
}
return list;
}
catch (Exception ex)
{
throw;
}
}
///
/// 获取用户信息列表
///
/// 条件
/// 数据页
/// 数据页
public DataPage GetList(User condition, DataPage page)
{
string sql = null;
List parameters = new List();
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(sql, parameters.ToArray(), page);
}
return page;
}
catch (Exception ex)
{
throw ex;
}
}
///
/// 获取用户信息列表
///
/// 条件
/// 数据页
/// 数据页
public List GetAllUsers(User condition)
{
List users = null;
string sql = null;
List parameters=new List();
try
{
sql = this.GetQuerySql(condition, ref parameters);
using (IDataSession session = AppDataFactory.CreateMainSession())
{
sql = this.ChangeSqlByDB(sql, session);
users = session.GetList(sql, parameters.ToArray()).ToList();
}
return users;
}
catch (Exception ex)
{
throw ex;
}
}
///
/// 获取查询语句
///
/// 查询条件
/// 查询
/// 查询语句
private string GetQuerySql(User condition, ref List 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 获取用户信息
///
/// 获取用户信息信息
///
/// 条件
/// 用户信息信息
public User Get(User user)
{
StringBuilder sqlBuilder = new StringBuilder();
string sql = null;
List parameters = new List();
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(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();
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(sql, parameters.ToArray()).ToList();
//获取用户所有权限信息
sqlBuilder.Remove(0, sqlBuilder.Length);
parameters = new List();
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(sql, parameters.ToArray()).ToList();
//获取用户所有全部权限信息
sqlBuilder.Remove(0, sqlBuilder.Length);
parameters = new List();
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(sql, parameters.ToArray()).ToList();
//获取用户所属的组织机构
sqlBuilder.Remove(0, sqlBuilder.Length);
parameters = new List();
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(sql, parameters.ToArray()).ToList();
}
return tmpuser;
}
catch (Exception ex)
{
throw ex;
}
}
#endregion
#region 手持登录获取用户信息
///
/// 手持获取用户信息信息
///
/// 条件
/// 用户信息信息
public User GetBaseInfo(User user)
{
StringBuilder sqlBuilder = new StringBuilder();
string sql = null;
List parameters = new List();
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(sql, parameters.ToArray());
}
return tmpuser;
}
catch (Exception ex)
{
throw ex;
}
}
#endregion
#region 判断登陆账户是否重复
///
/// 判断登陆账户是否重复
///
/// 条件
/// 用户信息信息
public User GetLoginUser(User user)
{
StringBuilder sqlBuilder = new StringBuilder();
string sql = null;
List parameters = new List();
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(sql, parameters.ToArray());
}
return tmpuser;
}
catch (Exception ex)
{
throw ex;
}
}
#endregion
#region 获取组织机构下人员列表
///
/// 获取组织机构下人员列表
///
/// 条件
/// 同级别菜单列表
public List GetOrgaUserList(string orgaID)
{
try
{
List parameters = new List();
List 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(sql, parameters.ToArray()).ToList();
}
return list;
}
catch (Exception ex)
{
throw ex;
}
}
#endregion
#region 获取人员所属的组织机构列表
///
/// 获取人员所属的组织机构列表
///
/// 条件
/// 同级别菜单列表
public List GetUserOrgaList(string userID)
{
try
{
StringBuilder sqlBuilder = new StringBuilder();
string sql = null;
List parameters = new List();
List 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(sql, parameters.ToArray()).ToList();
}
return list;
}
catch (Exception ex)
{
throw ex;
}
}
#endregion
#region 插入用户信息信息
///
/// 插入用户信息信息
///
/// 用户信息信息
/// 插入数
public int Insert(User user)
{
int count = 0;
try
{
using (IDataSession session = AppDataFactory.CreateMainSession())
{
session.OpenTs();
//插入基本信息
session.Insert(user);
//插入用户角色信息
if (user.Roles != null)
{
foreach (UserRole ur in user.Roles)
{
ur.UserID = user.UserID;
}
//插入角色信息
session.Insert(user.Roles);
}
//插入用户权限信息
if (user.Authoritys != null)
{
foreach (UserAuthority ur in user.Authoritys)
{
ur.UserID = user.UserID;
ur.OrgaID = user.OrgaID;
}
//插入权限信息
session.Insert(user.Authoritys);
}
session.CommitTs();
}
return count;
}
catch (Exception ex)
{
throw ex;
}
}
#endregion
#region 删除用户信息信息
///
/// 删除用户信息信息
///
/// 用户信息信息
/// 删除个数
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 更新用户信息
///
/// 更新用户信息
///
/// 用户信息
/// 更新个数
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);
//更新角色信息
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(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(user.Authoritys);
session.CommitTs();
}
return count;
}
catch (Exception ex)
{
throw ex;
}
}
#endregion
#region 设置密码
///
/// 设置密码
///
/// 用户信息
/// 影响行数
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 获取业务权限信息
///
/// 获取业务权限信息
///
/// 获取条件
/// 业务权限信息
public UserBusinessPower GetBusinessPower(UserBusinessPower userPower)
{
string sql = null;
List parameters = new List();
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(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(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(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(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(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(sql, parameters.ToArray()).ToList();
}
return userPower;
}
catch (Exception ex)
{
throw ex;
}
}
#endregion
#region 保存业务权限信息
///
/// 保存业务权限信息
///
/// 业务权限信息
public void SaveBusinessPower(UserBusinessPower userPower)
{
string sql = null;
try
{
using (IDataSession session = AppDataFactory.CreateMainSession())
{
session.OpenTs();
//保存基本信息
session.Update(userPower);
//保存仓库权限
sql = "DELETE FROM T_BD_EMPLOYEECORP WHERE USERID=:USERID";
session.ExecuteSql(sql, new DataParameter("USERID", userPower.UserID));
session.Insert(userPower.CorpPowers);
//保存路线信息
sql = "DELETE FROM T_BD_EMPLOYEELINE WHERE USERID=:USERID";
session.ExecuteSql(sql, new DataParameter("USERID", userPower.UserID));
session.Insert(userPower.LinePowers);
//保存零件类别信息
sql = "DELETE FROM T_BD_EMPLOYEEMATSORT WHERE USERID=:USERID";
session.ExecuteSql(sql, new DataParameter("USERID", userPower.UserID));
session.Insert(userPower.MatSortPowers);
//保存要货地信息
sql = "DELETE FROM T_BD_EMPLOYEEREQPLACE WHERE USERID =:USERID";
session.ExecuteSql(sql, new DataParameter("USERID", userPower.UserID));
session.Insert(userPower.ReqPlacePowers);
//保存发货地信息
sql = "DELETE FROM T_BD_EMPLOYEESENDPLACE WHERE USERID =:USERID";
session.ExecuteSql(sql, new DataParameter("USERID", userPower.UserID));
session.Insert(userPower.SendPlacePowers);
session.CommitTs();
}
}
catch (Exception ex)
{
throw ex;
}
}
#endregion
#region 获取导出的数据
///
/// 获取导出的数据
///
/// 查询条件
/// 数据
public DataTable GetExportData(User condition)
{
StringBuilder sqlBuilder = new StringBuilder();
StringBuilder whereBuilder = new StringBuilder();
DataTable dt = null;
string sql = null;
List parameters = new List();
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 导入
///
/// 导入
///
/// 数据列表
/// 导入记录数
public int ImportData(List list)
{
int count = 0;
List inserts = null;
List 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(inserts);
this.BaseSession.Update(updates);
this.BaseSession.CommitTs();
count = list.Count;
return count;
}
catch (Exception ex)
{
throw ex;
}
}
#endregion
#region 获取用户信息
///
/// 获取用户信息信息
///
/// 条件
/// 用户信息信息
public User Get(string LoginUserID)
{
StringBuilder sqlBuilder = new StringBuilder();
string sql = null;
List parameters = new List();
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(sql, parameters.ToArray());
return tmpuser;
}
catch (Exception ex)
{
throw ex;
}
}
#endregion
#region 获取人员下拉框
///
/// 获取人员下拉框
///
/// 条件
/// 同级别菜单列表
public List GetUserComboxSource()
{
try
{
List parameters = new List();
List list = null;
using (IDataSession session = AppDataFactory.CreateMainSession())
{
string sql = " SELECT * FROM T_QM_USER ";
sql = this.ChangeSqlByDB(sql, session);
list = session.GetList(sql, parameters.ToArray()).ToList();
}
return list;
}
catch (Exception ex)
{
throw ex;
}
}
#endregion
}
}