using System; using System.Data; using System.Configuration; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.HtmlControls; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using DSWeb.Models; using System.Data.SqlClient; using WebSqlHelper; namespace DSWeb.EntityDA { public class UserMessageSettingDA { private const string PARM_USER_MESSAGE_SETTING_GID = "@gid"; private const string PARM_USER_MESSAGE_SETTING_USER_ID = "@user_id"; private const string PARM_USER_MESSAGE_SETTING_CREATE_TIME = "@create_time"; private const string PARM_USER_MESSAGE_SETTING_MODIFIED_TIME = "@modified_time"; private const string PARM_USER_MESSAGE_SETTING_INTER_VAL = "@inter_val"; private const string PARM_USER_MESSAGE_SETTING_IS_READ_SYS = "@is_readsys"; private const string PARM_USER_MESSAGE_SETTING_IS_READ_APPLY = "@is_readapply"; private const string PARM_USER_MESSAGE_SETTING_IS_READ_AUDIT = "@is_readaudit"; private const string SQL_SELECT_USER_MESSAGE_SETTING_BY_USERID = " SELECT GID, USERID, CREATETIME, MODIFIEDTIME, MESSAGEINTERVAL,ISREADSYS,ISREADAPPLY,ISREADAUDIT " + " FROM user_message_setting WHERE USERID = @user_id "; private const string SQL_INSERT_USER_MESSAGE_SETTING = " INSERT user_message_setting(GID,USERID,CREATETIME,MESSAGEINTERVAL,ISREADSYS,ISREADAPPLY,ISREADAUDIT) " + " VALUES(@gid,@user_id,GETDATE(),@inter_val,@is_readsys,@is_readapply,@is_readaudit) "; private const string SQL_UPDATE_USER_MESSAGE_SETTING = " UPDATE user_message_setting SET MODIFIEDTIME = GETDATE(),MESSAGEINTERVAL = @inter_val,ISREADSYS = @is_readsys, " + " ISREADAPPLY = @is_readapply,ISREADAUDIT = @is_readaudit WHERE USERID = @user_id "; private const string SQL_DELETE_USER_MESSAGE_SETTING = " DELETE FROM user_message_setting WHERE USERID = @user_id "; #region 删除用户消息设置信息 /// /// 删除用户消息设置信息 /// /// 用户GID /// 值1表示删除成功 值不等于1表示删除失败 public int DeleteUserMsgSetting(string tempUserID) { int iResult = 0; SqlParameter parm = new SqlParameter(PARM_USER_MESSAGE_SETTING_USER_ID, SqlDbType.VarChar, 36); parm.Value = tempUserID; using (SqlConnection sqlConnection = new SqlConnection(SqlHelper.ConnectionStringLocalTransaction)) { try { SqlHelper.ExecuteNonQuery(sqlConnection, CommandType.Text, SQL_DELETE_USER_MESSAGE_SETTING, parm); iResult = 1; } catch { iResult = -1;//执行异常失败 } } return iResult; } #endregion #region 通过用户GID获取用户设置参数 /// /// 通过用户GID获取用户设置参数 /// /// 用户GID /// 返回实体类用户消息参数 public UserMessageSettingEntity GetUserMsgSettingByUserID(string tempUserID) { UserMessageSettingEntity userMsgSettingEntity = null; SqlParameter parm = new SqlParameter(PARM_USER_MESSAGE_SETTING_USER_ID, SqlDbType.VarChar, 36); parm.Value = tempUserID; using (SqlDataReader sqlRead = SqlHelper.ExecuteReader(SqlHelper.ConnectionStringLocalTransaction, CommandType.Text, SQL_SELECT_USER_MESSAGE_SETTING_BY_USERID, parm)) { try { while (sqlRead.Read()) { userMsgSettingEntity = new UserMessageSettingEntity(); if (!sqlRead.IsDBNull(0)) { userMsgSettingEntity.GID = sqlRead.GetString(0); } if (!sqlRead.IsDBNull(1)) { userMsgSettingEntity.UserID = sqlRead.GetString(1); } if (!sqlRead.IsDBNull(2)) { userMsgSettingEntity.CreateTime = sqlRead.GetDateTime(2); } if (!sqlRead.IsDBNull(3)) { userMsgSettingEntity.ModifiedTime = sqlRead.GetDateTime(3); } if (!sqlRead.IsDBNull(4)) { userMsgSettingEntity.MessageInterVal = sqlRead.GetInt32(4); } if (!sqlRead.IsDBNull(5)) { userMsgSettingEntity.IsReadSystem = sqlRead.GetBoolean(5); } if (!sqlRead.IsDBNull(6)) { userMsgSettingEntity.IsReadApply = sqlRead.GetBoolean(6); } if (!sqlRead.IsDBNull(7)) { userMsgSettingEntity.IsReadAudit = sqlRead.GetBoolean(7); } } } catch (Exception execError) { throw execError; } } return userMsgSettingEntity; } #endregion #region 插入用户消息设置信息 /// /// 插入用户消息设置信息 /// /// 用户信息设置实体类 /// 值1表示插入成功 值不等于1表示插入失败 public int InsertUserMsgSetting(UserMessageSettingEntity tempUserMsgSettingEntity) { int iResult = 0; SqlParameter[] parms = new SqlParameter[]{ new SqlParameter(PARM_USER_MESSAGE_SETTING_GID, SqlDbType.VarChar, 36), new SqlParameter(PARM_USER_MESSAGE_SETTING_USER_ID, SqlDbType.VarChar, 36), new SqlParameter(PARM_USER_MESSAGE_SETTING_INTER_VAL,SqlDbType.Int), new SqlParameter(PARM_USER_MESSAGE_SETTING_IS_READ_SYS,SqlDbType.Bit), new SqlParameter(PARM_USER_MESSAGE_SETTING_IS_READ_APPLY,SqlDbType.Bit), new SqlParameter(PARM_USER_MESSAGE_SETTING_IS_READ_AUDIT,SqlDbType.Bit) }; parms[0].Value = tempUserMsgSettingEntity.GID; parms[1].Value = tempUserMsgSettingEntity.UserID; parms[2].Value = tempUserMsgSettingEntity.MessageInterVal; parms[3].Value = tempUserMsgSettingEntity.IsReadSystem; parms[4].Value = tempUserMsgSettingEntity.IsReadApply; parms[5].Value = tempUserMsgSettingEntity.IsReadAudit; using (SqlConnection sqlConnection = new SqlConnection(SqlHelper.ConnectionStringLocalTransaction)) { try { SqlHelper.ExecuteNonQuery(sqlConnection, CommandType.Text, SQL_INSERT_USER_MESSAGE_SETTING, parms); iResult = 1; } catch { iResult = -1;//执行异常失败 } } return iResult; } #endregion #region 更新用户消息设置信息 /// /// 更新用户消息设置信息 /// /// 用户信息设置实体类 /// 值1表示更新成功 值不等于1表示更新失败 public int UpdateUserMsgSetting(UserMessageSettingEntity tempUserMsgSettingEntity) { int iResult = 0; SqlParameter[] parms = new SqlParameter[]{ new SqlParameter(PARM_USER_MESSAGE_SETTING_USER_ID, SqlDbType.VarChar, 36), new SqlParameter(PARM_USER_MESSAGE_SETTING_INTER_VAL,SqlDbType.Int), new SqlParameter(PARM_USER_MESSAGE_SETTING_IS_READ_SYS,SqlDbType.Bit), new SqlParameter(PARM_USER_MESSAGE_SETTING_IS_READ_APPLY,SqlDbType.Bit), new SqlParameter(PARM_USER_MESSAGE_SETTING_IS_READ_AUDIT,SqlDbType.Bit) }; parms[0].Value = tempUserMsgSettingEntity.UserID; parms[1].Value = tempUserMsgSettingEntity.MessageInterVal; parms[2].Value = tempUserMsgSettingEntity.IsReadSystem; parms[3].Value = tempUserMsgSettingEntity.IsReadApply; parms[4].Value = tempUserMsgSettingEntity.IsReadAudit; using (SqlConnection sqlConnection = new SqlConnection(SqlHelper.ConnectionStringLocalTransaction)) { try { SqlHelper.ExecuteNonQuery(sqlConnection, CommandType.Text, SQL_UPDATE_USER_MESSAGE_SETTING, parms); iResult = 1; } catch { iResult = -1;//执行异常失败 } } return iResult; } #endregion } }