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

212 lines
8.9 KiB

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
{
/// <summary>
/// 登录管理
/// 创建者:李炳海
/// 创建日期:2013.1.29
/// </summary>
public class LoginDAL:BaseDAL
{
#region 检验登录信息
/// <summary>
/// 获取用户和密码是否正确
/// </summary>
/// <param name="user">条件</param>
/// <returns>用户信息</returns>
public LoginInfo IsLogin(LoginInfo login)
{
StringBuilder sqlBuilder = new StringBuilder();
DataTable powerDt = new DataTable();
string sql = null;
List<DataParameter> parameters = new List<DataParameter>();
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<LoginInfo>(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<string>();
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<UserOrgaization>(sqlBuilder.ToString(), parameters.ToArray()).ToList();
}
}
return login;
}
catch (Exception ex)
{
throw;
}
}
#endregion
#region 获取嵌入式客户端菜单
/// <summary>
/// 获取嵌入式客户端菜单
/// </summary>
/// <param name="systemID">系统标识</param>
/// <param name="userID">用户主键</param>
/// <returns>客户端菜单</returns>
public DataTable GetEmbeddedMenus(string systemID, string userID)
{
DataTable dt = null;
string sql = null;
List<DataParameter> parameters = new List<DataParameter>();
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
/// <summary>
/// 获取用户POWER
/// </summary>
/// <param name="login"></param>
/// <returns></returns>
public List<string> GetPower(LoginInfo login)
{
List<string> powers = new List<string>();
StringBuilder sqlBuilder = new StringBuilder();
List<DataParameter> parameters = new List<DataParameter>();
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<string>();
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;
}
}
}
}