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.

406 lines
17 KiB
C#

using System;
using System.Data;
using System.Configuration;
using System.Data.SqlClient;
using DSWeb.Models;
using WebSqlHelper;
namespace DSWeb.EntityDA
{
public class UserSettingDA
{
private const string PARM_SETTING_GID = "@gid";
private const string PARM_SETTING_NAME = "@name";
private const string PARM_SETTING_DESCRIPTION = "@description";
private const string PARM_SETTING_TYPE = "@type";
private const string PARM_SETTING_URL = "@url";
private const string PARM_SETTING_PAGE = "@page";
private const string PARM_SETTING_XML = "@xml";
private const string PARM_SETTING_USER_ID = "@user_id";
private const string PARM_SETTING_CREATE_USER = "@create_user";
private const string PARM_SETTING_CREATE_TIME = "@create_time";
private const string PARM_SETTING_MODIFIED_USER = "@modified_user";
private const string PARM_SETTING_MODIFIED_TIME = "@modified_time";
private const string SQL_SELECT_SETTING_BY_GID = " SELECT GID, NAME, DESCRIPTION, TYPE, URL, PAGE, XML, USERID, CREATEUSER, "
+ " CREATETIME, MODIFIEDUSER, MODIFIEDTIME FROM user_setting where GID = @gid ";
private const string SQL_SELECT_SETTING_BY_USER_ID = " SELECT GID, NAME, DESCRIPTION, TYPE, URL, PAGE, XML, USERID, CREATEUSER, "
+ " CREATETIME, MODIFIEDUSER, MODIFIEDTIME FROM user_setting where USERID = @user_id ";
private const string SQL_SELECT_SETTING_BY_USER_ID_TYPE = " SELECT GID, NAME, DESCRIPTION, TYPE, URL, PAGE, XML, USERID, CREATEUSER, "
+ " CREATETIME, MODIFIEDUSER, MODIFIEDTIME FROM user_setting where USERID = @user_id and TYPE = @type";
private const string SQL_INSERT_SETTING = " INSERT INTO user_setting (GID, NAME, DESCRIPTION, TYPE, URL, PAGE, XML, USERID, CREATEUSER )"
+ " VALUES(@gid,@name,@description,@type,@url,@page,@xml,@user_id,@create_user) ";
private const string SQL_UPDATE_SETTING = " UPDATE user_setting SET XML = @xml,MODIFIEDUSER = @modified_user,MODIFIEDTIME = GETDATE() WHERE USERID = @user_id AND TYPE = @type";
#region 根据用户设置表GID获取用户设置信息
/// <summary>
/// 根据用户设置表GID获取用户设置信息
/// </summary>
/// <param name="strGID">用户设置表GID</param>
/// <returns>返回用户设置实体类 UserSettingEntity</returns>
public UserSettingEntity GetUserSettingByGID(string strGID)
{
UserSettingEntity userSettingEntity = null;
SqlParameter parm = new SqlParameter(PARM_SETTING_GID, SqlDbType.NVarChar, 36);
parm.Value = strGID;
using (SqlDataReader sqlRead = SqlHelper.ExecuteReader(SqlHelper.ConnectionStringLocalTransaction, CommandType.Text, SQL_SELECT_SETTING_BY_GID, parm))
{
userSettingEntity = new UserSettingEntity();
try
{
while (sqlRead.Read())
{
if (!sqlRead.IsDBNull(0))
{
userSettingEntity.GID = sqlRead.GetString(0);
}
if (!sqlRead.IsDBNull(1))
{
userSettingEntity.Name = sqlRead.GetString(1);
}
if (!sqlRead.IsDBNull(2))
{
userSettingEntity.Description = sqlRead.GetString(2);
}
if (!sqlRead.IsDBNull(3))
{
userSettingEntity.Type = sqlRead.GetInt32(3);
}
if (!sqlRead.IsDBNull(4))
{
userSettingEntity.Url = sqlRead.GetString(4);
}
if (!sqlRead.IsDBNull(5))
{
userSettingEntity.Page = sqlRead.GetString(5);
}
if (!sqlRead.IsDBNull(6))
{
userSettingEntity.Xml = sqlRead.GetString(6);
}
if (!sqlRead.IsDBNull(7))
{
userSettingEntity.UserID = sqlRead.GetString(7);
}
if (!sqlRead.IsDBNull(8))
{
userSettingEntity.CreateUser = sqlRead.GetString(8);
}
if (!sqlRead.IsDBNull(9))
{
userSettingEntity.CreateTime = sqlRead.GetDateTime(9);
}
if (!sqlRead.IsDBNull(10))
{
userSettingEntity.ModifiedUser = sqlRead.GetString(10);
}
if (!sqlRead.IsDBNull(11))
{
userSettingEntity.ModifiedTime = sqlRead.GetDateTime(11);
}
}
}
catch (Exception error)
{
throw error;
}
}
return userSettingEntity;
}
#endregion
#region 根据用户GID获取用户设置信息
/// <summary>
/// 根据用户设置表GID获取用户设置信息
/// </summary>
/// <param name="strGID">用户GID</param>
/// <returns>返回用户设置实体类 UserSettingEntity</returns>
public UserSettingEntity GetUserSettingByUserID(string strUserGID)
{
UserSettingEntity userSettingEntity = null;
SqlParameter parm = new SqlParameter(PARM_SETTING_USER_ID, SqlDbType.NVarChar, 36);
parm.Value = strUserGID;
using (SqlDataReader sqlRead = SqlHelper.ExecuteReader(SqlHelper.ConnectionStringLocalTransaction, CommandType.Text, SQL_SELECT_SETTING_BY_USER_ID, parm))
{
userSettingEntity = new UserSettingEntity();
try
{
while (sqlRead.Read())
{
if (!sqlRead.IsDBNull(0))
{
userSettingEntity.GID = sqlRead.GetString(0);
}
if (!sqlRead.IsDBNull(1))
{
userSettingEntity.Name = sqlRead.GetString(1);
}
if (!sqlRead.IsDBNull(2))
{
userSettingEntity.Description = sqlRead.GetString(2);
}
if (!sqlRead.IsDBNull(3))
{
userSettingEntity.Type = sqlRead.GetInt32(3);
}
if (!sqlRead.IsDBNull(4))
{
userSettingEntity.Url = sqlRead.GetString(4);
}
if (!sqlRead.IsDBNull(5))
{
userSettingEntity.Page = sqlRead.GetString(5);
}
if (!sqlRead.IsDBNull(6))
{
userSettingEntity.Xml = sqlRead.GetString(6);
}
if (!sqlRead.IsDBNull(7))
{
userSettingEntity.UserID = sqlRead.GetString(7);
}
if (!sqlRead.IsDBNull(8))
{
userSettingEntity.CreateUser = sqlRead.GetString(8);
}
if (!sqlRead.IsDBNull(9))
{
userSettingEntity.CreateTime = sqlRead.GetDateTime(9);
}
if (!sqlRead.IsDBNull(10))
{
userSettingEntity.ModifiedUser = sqlRead.GetString(10);
}
if (!sqlRead.IsDBNull(11))
{
userSettingEntity.ModifiedTime = sqlRead.GetDateTime(11);
}
}
}
catch (Exception error)
{
throw error;
}
}
return userSettingEntity;
}
#endregion
#region 根据用户ID和type值获取用户设置信息
/// <summary>
/// 根据用户设置表GID获取用户设置信息
/// </summary>
/// <param name="strUserGID">用户GID</param>
/// <param name="strType">type值</param>
/// <returns>返回用户设置实体类 UserSettingEntity</returns>
public UserSettingEntity GetUserSettingByUserIDType(string strUserGID,string strType)
{
UserSettingEntity userSettingEntity = null;
SqlParameter[] parms = new SqlParameter[]{
new SqlParameter(PARM_SETTING_USER_ID, SqlDbType.NVarChar, 36),
new SqlParameter(PARM_SETTING_TYPE, SqlDbType.Int)
};
parms[0].Value = strUserGID;
parms[1].Value = strType;
using (SqlDataReader sqlRead = SqlHelper.ExecuteReader(SqlHelper.ConnectionStringLocalTransaction, CommandType.Text, SQL_SELECT_SETTING_BY_USER_ID_TYPE, parms))
{
userSettingEntity = new UserSettingEntity();
try
{
while (sqlRead.Read())
{
if (!sqlRead.IsDBNull(0))
{
userSettingEntity.GID = sqlRead.GetString(0);
}
if (!sqlRead.IsDBNull(1))
{
userSettingEntity.Name = sqlRead.GetString(1);
}
if (!sqlRead.IsDBNull(2))
{
userSettingEntity.Description = sqlRead.GetString(2);
}
if (!sqlRead.IsDBNull(3))
{
userSettingEntity.Type = sqlRead.GetInt32(3);
}
if (!sqlRead.IsDBNull(4))
{
userSettingEntity.Url = sqlRead.GetString(4);
}
if (!sqlRead.IsDBNull(5))
{
userSettingEntity.Page = sqlRead.GetString(5);
}
if (!sqlRead.IsDBNull(6))
{
userSettingEntity.Xml = sqlRead.GetString(6);
}
if (!sqlRead.IsDBNull(7))
{
userSettingEntity.UserID = sqlRead.GetString(7);
}
if (!sqlRead.IsDBNull(8))
{
userSettingEntity.CreateUser = sqlRead.GetString(8);
}
if (!sqlRead.IsDBNull(9))
{
userSettingEntity.CreateTime = sqlRead.GetDateTime(9);
}
if (!sqlRead.IsDBNull(10))
{
userSettingEntity.ModifiedUser = sqlRead.GetString(10);
}
if (!sqlRead.IsDBNull(11))
{
userSettingEntity.ModifiedTime = sqlRead.GetDateTime(11);
}
}
}
catch (Exception error)
{
throw error;
}
}
return userSettingEntity;
}
#endregion
#region 将用户设置的Grid写入记录表
/// <summary>
/// 将用户设置的Grid写入记录表
/// </summary>
/// <param name="tempUserSettingEntity"></param>
/// <returns></returns>
public int InsertUserSetting(UserSettingEntity tempUserSettingEntity)
{
int iResult = 0;
if (tempUserSettingEntity != null)
{
using (SqlConnection conn = new SqlConnection(SqlHelper.ConnectionStringLocalTransaction))
{
SqlParameter[] parms = GetParams();
parms[0].Value = tempUserSettingEntity.GID;
parms[1].Value = tempUserSettingEntity.Name;
parms[2].Value = tempUserSettingEntity.Description;
parms[3].Value = tempUserSettingEntity.Type;
parms[4].Value = tempUserSettingEntity.Url;
parms[5].Value = tempUserSettingEntity.Page;
parms[6].Value = tempUserSettingEntity.Xml;
parms[7].Value = tempUserSettingEntity.UserID;
parms[8].Value = tempUserSettingEntity.CreateUser;
try
{
iResult = SqlHelper.ExecuteNonQuery(conn, CommandType.Text, SQL_INSERT_SETTING, parms);
}
catch (Exception)
{
iResult = -2;//执行异常
}
}
}
else
{
iResult = -1;//参数错误
}
return iResult;
}
#endregion
#region 将用户设置的Grid更新入记录表
/// <summary>
/// 将用户设置的Grid更新入记录表
/// </summary>
/// <param name="tempUserSettingEntity"></param>
/// <returns></returns>
public int UpdateUserSetting(UserSettingEntity tempUserSettingEntity)
{
int iResult = 0;
if (tempUserSettingEntity != null)
{
using (SqlConnection conn = new SqlConnection(SqlHelper.ConnectionStringLocalTransaction))
{
SqlParameter[] parms = GetUpdateParams();
parms[0].Value = tempUserSettingEntity.Xml;
parms[1].Value = tempUserSettingEntity.ModifiedUser;
parms[2].Value = tempUserSettingEntity.UserID;
parms[3].Value = tempUserSettingEntity.Type;
try
{
iResult = SqlHelper.ExecuteNonQuery(conn, CommandType.Text, SQL_UPDATE_SETTING, parms);
}
catch (Exception)
{
iResult = -2;//执行异常
}
}
}
else
{
iResult = -1;//参数错误
}
return iResult;
}
#endregion
#region 获取参数组
private SqlParameter[] GetUpdateParams()
{
SqlParameter[] parms = new SqlParameter[] {
new SqlParameter(PARM_SETTING_XML,SqlDbType.NVarChar,4000),
new SqlParameter(PARM_SETTING_MODIFIED_USER,SqlDbType.NVarChar,36),
new SqlParameter(PARM_SETTING_USER_ID,SqlDbType.NVarChar,36),
new SqlParameter(PARM_SETTING_TYPE,SqlDbType.Int),
};
return parms;
}
#endregion
#region 获取更新参数组
private SqlParameter[] GetParams()
{
SqlParameter[] parms = new SqlParameter[] {
new SqlParameter(PARM_SETTING_GID,SqlDbType.NVarChar,36),
new SqlParameter(PARM_SETTING_NAME,SqlDbType.NVarChar,50),
new SqlParameter(PARM_SETTING_DESCRIPTION,SqlDbType.NVarChar,50),
new SqlParameter(PARM_SETTING_TYPE,SqlDbType.Int),
new SqlParameter(PARM_SETTING_URL,SqlDbType.NVarChar,300),
new SqlParameter(PARM_SETTING_PAGE,SqlDbType.NVarChar,100),
new SqlParameter(PARM_SETTING_XML,SqlDbType.NVarChar,4000),
new SqlParameter(PARM_SETTING_USER_ID,SqlDbType.NVarChar,36),
new SqlParameter(PARM_SETTING_CREATE_USER,SqlDbType.NVarChar,36)
};
return parms;
}
#endregion
}
}