You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

96 lines
3.9 KiB
C#

using System;
using System.Data;
using DSWeb.Models;
using System.Data.SqlClient;
using System.Collections;
using System.Collections.Generic;
using WebSqlHelper;
namespace DSWeb.EntityDA
{
public class UserSessionDA
{
//private string PARM_USER_SESSION_GID = "@gid";
//private string PARM_USER_SESSION_SESSION_ID = "@session_id";
private string PARM_USER_SESSION_CREATE_USER = "@create_user";
//private string PARM_USER_SESSION_CREATE_TIME = "@create_time";
//private string PARM_USER_SESSION_IS_DELETE = "@is_delete";
//private string PARM_USER_SESSION_DELETE_TIME = "@delete_time";
//private string PARM_USER_SESSION_EXPIRES_MINUTES = "@expires_minutes";
private string PARM_USER_SEESION_TYPE = "@type";
private string SQL_SELECT_USER_SESSION_BY_USERID = "SELECT GID, SESSIONID, CREATETIME, CREATEUSER, ISDELETE, DELETETIME, EXPIRESMINS, TYPE FROM user_session WHERE USERID = @user_id";
//private string SQL_SELECT_USER_SESSION_BY_USERID_AND_TYPE = "SELECT GID, SESSIONID, CREATETIME, CREATEUSER, ISDELETE, DELETETIME, EXPIRESMINS, TYPE FROM user_session WHERE USERID = @user_id AND TYPE = @type ";
public UserSessionDA()
{
}
public IList<UserSessionEntity> GetUserSessionByUserID(string tempUserID, int tempType)
{
IList<UserSessionEntity> userSessionEntities = new List<UserSessionEntity>();
SqlParameter[] parms = new SqlParameter[]{
new SqlParameter(PARM_USER_SESSION_CREATE_USER, SqlDbType.VarChar, 36),
new SqlParameter(PARM_USER_SEESION_TYPE,SqlDbType.Int)
};
parms[0].Value = tempUserID;
parms[1].Value = tempType;
using (SqlDataReader sqlRead = SqlHelper.ExecuteReader(SqlHelper.ConnectionStringLocalTransaction, CommandType.Text, SQL_SELECT_USER_SESSION_BY_USERID, parms))
{
try
{
UserSessionEntity userSessionEntity = new UserSessionEntity();
//读取字段值
while (sqlRead.Read())
{
if (!sqlRead.IsDBNull(0))
{
userSessionEntity.GID = sqlRead.GetString(0);
}
if (!sqlRead.IsDBNull(1))
{
userSessionEntity.SessionID = sqlRead.GetString(1);
}
if (!sqlRead.IsDBNull(2))
{
userSessionEntity.CreateTime = sqlRead.GetDateTime(2);
}
if (!sqlRead.IsDBNull(3))
{
userSessionEntity.CreateUser = sqlRead.GetString(3);
}
if (!sqlRead.IsDBNull(4))
{
userSessionEntity.IsDelete = sqlRead.GetBoolean(4);
}
if (!sqlRead.IsDBNull(5))
{
userSessionEntity.DeleteTime = sqlRead.GetDateTime(5);
}
if (!sqlRead.IsDBNull(6))
{
userSessionEntity.ExpiresMinutes = sqlRead.GetInt32(6);
}
if (!sqlRead.IsDBNull(7))
{
userSessionEntity.Type = sqlRead.GetInt32(7);
}
}
userSessionEntities.Add(userSessionEntity);
}
catch (Exception exceError)
{
//抛出异常
throw exceError;
}
}
return userSessionEntities;
}
}
}