using System;
using System.Data;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using QMFrameWork.Data;
using QMFrameWork.Common.Util;
using QMAPP.Entity.Sys;
namespace QMAPP.DAL.Sys
{
///
/// 登录管理
/// 创建者:李炳海
/// 创建日期:2013.1.29
///
public class LoginDAL:BaseDAL
{
#region 检验登录信息
///
/// 获取用户和密码是否正确
///
/// 条件
/// 用户信息
public LoginInfo IsLogin(LoginInfo login)
{
StringBuilder sqlBuilder = new StringBuilder();
DataTable powerDt = new DataTable();
string sql = null;
List parameters = new List();
try
{
using (IDataSession session = AppDataFactory.CreateMainSession())
{
//获取用户信息
sqlBuilder.Append(" SELECT * ");
sqlBuilder.Append(" FROM T_QM_USER WHERE LOGINUSERID = @LoginUserID AND PASSWORD = @PASSWORD ");
if (login.LoginUserID != "admin")
{
sqlBuilder.Append(" AND ACTIVATEFLG='1' AND FLGDEL = '0'");
}
parameters.Add(new DataParameter { ParameterName = "LOGINUSERID", DataType = DbType.String, Value = login.LoginUserID });
parameters.Add(new DataParameter { ParameterName = "PASSWORD", DataType = DbType.String, Value = login.PassWord });
sql = this.ChangeSqlByDB(sqlBuilder.ToString(), session);
login = session.Get(sql, parameters.ToArray());
if (login != null)
{
//获取用户权限
sqlBuilder.Clear();
sqlBuilder.Append(@"SELECT T1.AUTHORITYID
FROM T_QM_ORGAIZATIONAUTHORITY T1,T_QM_USERORGAIZATION T2
WHERE T1.ORGAID = T2.ORGAID AND T2.USERID = @USERID
UNION
SELECT T1.AUTHORITYID
FROM T_QM_ROLEAUTHORITY T1,T_QM_USERROLE T2
WHERE T1.ROLEID = T2.ROLEID AND T2.USERID = @USERID
UNION
SELECT AUTHORITYID FROM T_QM_USERAUTHORITY
WHERE USERID = @USERID");
parameters.Clear();
parameters.Add(new DataParameter("USERID", login.UserID));
sql = this.ChangeSqlByDB(sqlBuilder.ToString(), session);
session.FillTable(powerDt,sql, parameters.ToArray());
login.Powers = new List();
foreach (DataRow row in powerDt.Rows)
{
login.Powers.Add(row["AUTHORITYID"].ToString());
}
//获取委托权限
powerDt = new DataTable();
sqlBuilder.Clear();
sqlBuilder.Append(@"SELECT AUTHORITYID FROM T_QM_ENTRUSTAUTHORITY T1,T_QM_USERENTRUST T2
WHERE T1.ENTRUSTPID=T2.PID
AND T2.AGENTUSERID=@USERID AND T2.STARTTIME <= @NOWDATE AND T2.ENDTIME >= @NOWDATE");
parameters.Clear();
parameters.Add(new DataParameter("USERID", login.UserID));
parameters.Add(new DataParameter("NOWDATE", DateTime.Now));
sql = this.ChangeSqlByDB(sqlBuilder.ToString(), session);
session.FillTable(powerDt, sql, parameters.ToArray());
foreach (DataRow row in powerDt.Rows)
{
login.Powers.Add(row["AUTHORITYID"].ToString());
}
////获取用户所属的组织机构
//sqlBuilder.Clear();
//sqlBuilder.Append(" SELECT * ");
//sqlBuilder.Append(" FROM T_QM_USERORGAIZATION AS A WHERE USERID = @USERID");
//parameters.Clear();
//parameters.Add(new DataParameter { ParameterName = "USERID", DataType = DbType.String, Value = login.UserID });
//login.Orgas = session.GetList(sqlBuilder.ToString(), parameters.ToArray()).ToList();
}
}
return login;
}
catch (Exception ex)
{
throw;
}
}
#endregion
#region 获取嵌入式客户端菜单
///
/// 获取嵌入式客户端菜单
///
/// 系统标识
/// 用户主键
/// 客户端菜单
public DataTable GetEmbeddedMenus(string systemID, string userID)
{
DataTable dt = null;
string sql = null;
List parameters = new List();
try
{
sql = "SELECT T1.* FROM T_QM_SYSMENU_EMB T1 WHERE T1.SYSTEMID = @SYSTEMID";
parameters.Add(new DataParameter("SYSTEMID",systemID));
using (IDataSession session = AppDataFactory.CreateMainSession())
{
sql = this.ChangeSqlByDB(sql, session);
dt = session.GetTable(sql, parameters.ToArray());
}
return dt;
}
catch (Exception ex)
{
throw ex;
}
}
#endregion
///
/// 获取用户POWER
///
///
///
public List GetPower(LoginInfo login)
{
List powers = new List();
StringBuilder sqlBuilder = new StringBuilder();
List parameters = new List();
string sql = "";
DataTable powerDt = new DataTable();
using (IDataSession session = AppDataFactory.CreateMainSession())
{
if (login != null)
{
//获取用户权限
sqlBuilder.Clear();
sqlBuilder.Append(@"SELECT T1.AUTHORITYID
FROM T_QM_ORGAIZATIONAUTHORITY T1,T_QM_USERORGAIZATION T2
WHERE T1.ORGAID = T2.ORGAID AND T2.USERID = @USERID
UNION
SELECT T1.AUTHORITYID
FROM T_QM_ROLEAUTHORITY T1,T_QM_USERROLE T2
WHERE T1.ROLEID = T2.ROLEID AND T2.USERID = @USERID
UNION
SELECT AUTHORITYID FROM T_QM_USERAUTHORITY
WHERE USERID = @USERID");
parameters.Clear();
parameters.Add(new DataParameter("USERID", login.UserID));
sql = this.ChangeSqlByDB(sqlBuilder.ToString(), session);
session.FillTable(powerDt, sql, parameters.ToArray());
login.Powers = new List();
foreach (DataRow row in powerDt.Rows)
{
powers.Add(row["AUTHORITYID"].ToString());
}
//获取委托权限
powerDt = new DataTable();
sqlBuilder.Clear();
sqlBuilder.Append(@"SELECT AUTHORITYID FROM T_QM_ENTRUSTAUTHORITY T1,T_QM_USERENTRUST T2
WHERE T1.ENTRUSTPID=T2.PID
AND T2.AGENTUSERID=@USERID AND T2.STARTTIME <= @NOWDATE AND T2.ENDTIME >= @NOWDATE");
parameters.Clear();
parameters.Add(new DataParameter("USERID", login.UserID));
parameters.Add(new DataParameter("NOWDATE", DateTime.Now));
sql = this.ChangeSqlByDB(sqlBuilder.ToString(), session);
session.FillTable(powerDt, sql, parameters.ToArray());
foreach (DataRow row in powerDt.Rows)
{
powers.Add(row["AUTHORITYID"].ToString());
}
}
return powers;
}
}
}
}