Exemplo n.º 1
0
        /// <summary>删除一条数据
        ///
        /// </summary>
        public bool Delete(int Id)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("delete from CacheConfig ");
            strSql.Append(" where Id=@Id ");
            IDbHelper h = GlobalHelp.GetDataAccessHelper();

            #region 缓存配置行
            h.CreateCommand("select * from  CacheConfig where id =" + Id + "");
            DataTable dt = h.ExecuteQuery();
            dt.TableName = "CacheConfig";
            #endregion

            h.CreateCommand(strSql.ToString());
            h.AddParameter("@Id", Id);
            bool blnReturn = h.ExecuteNonQuery();
            if (blnReturn)
            {
                #region 修改缓存配置:如果是则需要推送更新缓存的消息。即是发消息告诉服务端我修改了缓存配置,让服务端统一向所有在线客户端发送更新缓存消息
                string             strCacheTableName = dt.Rows[0]["CacheTableName"].ToString();
                CacheMessageEntity messageEntity     = new CacheMessageEntity {
                    CacheKey = strCacheTableName, Operation = "Delete", DataTableCache = dt
                };
                CacheListener.AddMessage(messageEntity);
                #endregion
            }
            return(blnReturn);
        }
Exemplo n.º 2
0
        /// <summary>增加一条数据
        ///
        /// </summary>
        public int Add(Nikita.Base.CacheStore.Model.CacheConfig model)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("insert into CacheConfig(");
            strSql.Append("ConnectionString, TableName, Filter, CacheTableName, CacheChekGuid, CacheVersion, CreateUser, CreateDate, Remark, Status  )");
            strSql.Append(" values (");
            strSql.Append("@ConnectionString, @TableName, @Filter, @CacheTableName, @CacheChekGuid, @CacheVersion, @CreateUser, @CreateDate, @Remark, @Status  )");
            strSql.Append(";select @@IDENTITY");
            IDbHelper h = GlobalHelp.GetDataAccessHelper();

            h.CreateCommand(strSql.ToString());
            if (model.ConnectionString == null)
            {
                h.AddParameter("@ConnectionString", DBNull.Value);
            }
            else
            {
                h.AddParameter("@ConnectionString", model.ConnectionString);
            }
            if (model.TableName == null)
            {
                h.AddParameter("@TableName", DBNull.Value);
            }
            else
            {
                h.AddParameter("@TableName", model.TableName);
            }
            if (model.Filter == null)
            {
                h.AddParameter("@Filter", DBNull.Value);
            }
            else
            {
                h.AddParameter("@Filter", model.Filter);
            }
            if (model.CacheTableName == null)
            {
                h.AddParameter("@CacheTableName", DBNull.Value);
            }
            else
            {
                h.AddParameter("@CacheTableName", model.CacheTableName);
            }
            if (model.CacheChekGuid == null)
            {
                h.AddParameter("@CacheChekGuid", DBNull.Value);
            }
            else
            {
                h.AddParameter("@CacheChekGuid", model.CacheChekGuid);
            }
            if (model.CacheVersion == null)
            {
                h.AddParameter("@CacheVersion", DBNull.Value);
            }
            else
            {
                h.AddParameter("@CacheVersion", model.CacheVersion);
            }
            if (model.CreateUser == null)
            {
                h.AddParameter("@CreateUser", DBNull.Value);
            }
            else
            {
                h.AddParameter("@CreateUser", model.CreateUser);
            }
            if (model.CreateDate == null)
            {
                h.AddParameter("@CreateDate", DBNull.Value);
            }
            else
            {
                h.AddParameter("@CreateDate", model.CreateDate);
            }
            if (model.Remark == null)
            {
                h.AddParameter("@Remark", DBNull.Value);
            }
            else
            {
                h.AddParameter("@Remark", model.Remark);
            }
            if (model.Status == null)
            {
                h.AddParameter("@Status", DBNull.Value);
            }
            else
            {
                h.AddParameter("@Status", model.Status);
            }
            model.CacheChekGuid = Guid.NewGuid().ToString();
            int    intResult;
            string obj = h.ExecuteScalar();

            if (!int.TryParse(obj, out intResult))
            {
                return(0);
            }
            #region 新增缓存配置:如果是则需要推送更新缓存的消息。。即是发消息告诉服务端我修改了缓存配置,让服务端统一向所有在线客户端发送更新缓存消息

            h.CreateCommand("select * from  CacheConfig where id =" + intResult + "");
            DataTable dt = h.ExecuteQuery();
            dt.TableName = "CacheConfig";
            CacheMessageEntity messageEntity = new CacheMessageEntity {
                CacheKey = model.CacheTableName, Operation = "Add", DataTableCache = dt
            };
            CacheListener.AddMessage(messageEntity);
            #endregion
            return(intResult);
        }